void write_runs_dump(const serve_state_t state, FILE *f, const unsigned char *url, unsigned char const *charset) { int total_runs, i, j; struct run_entry re; struct tm *pts; time_t start_time, dur; unsigned char *s; unsigned char statstr[128]; time_t tmp_time; if (url && *url) { fprintf(f, "Content-type: text/plain; charset=%s\n\n", charset); } fprintf(f, "Run_Id" ";Time;Nsec;Time2;Date;Year;Mon;Day;Hour;Min;Sec" ";Dur;Dur_Day;Dur_Hour;Dur_Min;Dur_Sec" ";Size" ";IPV6_Flag;IP;SSL_Flag" ";Sha1" ";User_Id;User_Login;User_Name" ";User_Inv;User_Ban;User_Lock" ";Prob;Variant" ";Lang;Content_Type" ";Stat_Short;Status;Score;Score_Adj;Test" ";Import_Flag;Hidden_Flag;RO_Flag;Locale_Id;Pages;Judge_Id" "\n"); total_runs = run_get_total(state->runlog_state); start_time = run_get_start_time(state->runlog_state); for (i = 0; i < total_runs; i++) { if (run_get_entry(state->runlog_state, i, &re) < 0) { fprintf(f, "%d;Cannot read entry!\n", i); continue; } if (!run_is_valid_status(re.status)) { fprintf(f, "%d;Invalid status %d!\n", i, re.status); continue; } if (re.status == RUN_EMPTY) continue; fprintf(f, "%d;", i); fprintf(f, "%lld;%09d;", re.time, re.nsec); tmp_time = re.time; pts = localtime(&tmp_time); fprintf(f, "%04d%02d%02d%02d%02d%02d;", pts->tm_year + 1900, pts->tm_mon + 1, pts->tm_mday, pts->tm_hour, pts->tm_min, pts->tm_sec); fprintf(f, "%04d%02d%02d;", pts->tm_year + 1900, pts->tm_mon + 1, pts->tm_mday); fprintf(f, "%04d;%02d;%02d;%02d;%02d;%02d;", pts->tm_year + 1900, pts->tm_mon + 1, pts->tm_mday, pts->tm_hour, pts->tm_min, pts->tm_sec); if (state->global->is_virtual) { start_time = run_get_virtual_start_time(state->runlog_state, re.user_id); } dur = re.time - start_time; if (dur < 0) dur = 0; fprintf(f, "%ld;", dur); pts->tm_sec = dur % 60; dur /= 60; pts->tm_min = dur % 60; dur /= 60; pts->tm_hour = dur % 24; dur /= 24; fprintf(f, "%ld;%02d;%02d;%02d;", dur, pts->tm_hour, pts->tm_min, pts->tm_sec); fprintf(f, "%u;", re.size); fprintf(f, "%d;%s;%d;", re.ipv6_flag, xml_unparse_ip(re.a.ip), re.ssl_flag); s = (unsigned char*) re.sha1; for (j = 0; j < 20; j++) fprintf(f, "%02x", *s++); fprintf(f, ";"); fprintf(f, "%d;", re.user_id); if (!(s = teamdb_get_login(state->teamdb_state, re.user_id))) { fprintf(f, "!INVALID TEAM!;"); } else { fprintf(f, "%s;", s); } if (!(s = teamdb_get_name(state->teamdb_state, re.user_id))) { fprintf(f, "!INVALID TEAM!;"); } else { fprintf(f, "%s;", s); } j = teamdb_get_flags(state->teamdb_state, re.user_id); s = ""; if ((j & TEAM_INVISIBLE)) s = "I"; fprintf(f, "%s;", s); s = ""; if ((j & TEAM_BANNED)) s = "B"; fprintf(f, "%s;", s); s = ""; if ((j & TEAM_LOCKED)) s = "L"; fprintf(f, "%s;", s); if (re.status == RUN_VIRTUAL_START || re.status == RUN_VIRTUAL_STOP) { //fprintf(f, "<problem>;<variant>;<lang_short>;<mime_type>;<short_status>;<status>;<score>;<score_adj>;<test>;<is_imported>;<is_hidden>;<is_readonly>;<locale_id>;<pages>;<judge_id>\n"); fprintf(f, ";;;;"); run_status_to_str_short(statstr, sizeof(statstr), re.status); fprintf(f, "%s;", statstr); run_status_str(re.status, statstr, sizeof(statstr), 0, 0); fprintf(f, "%s;", statstr); fprintf(f, ";;;;;;;;\n"); continue; } if (re.prob_id > 0 && re.prob_id <= state->max_prob && state->probs[re.prob_id] && state->probs[re.prob_id]->short_name) { fprintf(f, "%s;", state->probs[re.prob_id]->short_name); } else { fprintf(f, "!INVALID PROBLEM %d!;", re.prob_id); } fprintf(f, "%d;", re.variant); if (!re.lang_id) { fprintf(f, ";%s;", mime_type_get_type(re.mime_type)); } else if (re.lang_id > 0 && re.lang_id <= state->max_lang && state->langs[re.lang_id] && state->langs[re.lang_id]->short_name) { fprintf(f, "%s;;", state->langs[re.lang_id]->short_name); } else { fprintf(f, "!INVALID LANGUAGE %d!;", re.lang_id); } run_status_to_str_short(statstr, sizeof(statstr), re.status); fprintf(f, "%s;", statstr); run_status_str(re.status, statstr, sizeof(statstr), 0, 0); fprintf(f, "%s;", statstr); fprintf(f, "%d;%d;", re.score, re.score_adj); fprintf(f, "%d;", re.test); fprintf(f, "%d;", (re.passed_mode > 0)); fprintf(f, "%d;", re.is_imported); fprintf(f, "%d;", re.is_hidden); fprintf(f, "%d;", re.is_readonly); fprintf(f, "%d;%d;%d", re.locale_id, re.pages, re.judge_id); fprintf(f, "\n"); } }
static int print_banner_page(const serve_state_t state, const unsigned char *banner_path, int run_id, int user_id, int is_privileged) { struct run_entry info; FILE *f = 0; time_t start_time; unsigned char *s; int i, variant, virt_variant; struct teamdb_export teaminfo; if (run_id < 0 || run_id >= run_get_total(state->runlog_state)) goto cleanup; run_get_entry(state->runlog_state, run_id, &info); if (info.status == RUN_VIRTUAL_START || info.status == RUN_VIRTUAL_STOP || info.status == RUN_EMPTY) { return -1; } if (teamdb_export_team(state->teamdb_state, info.user_id, &teaminfo) < 0) return -1; start_time = run_get_start_time(state->runlog_state); if (!(f = fopen(banner_path, "w"))) goto cleanup; fprintf(f, "\n\n\n\n\n\n\n\n\n\n"); fprintf(f, "Run ID: %d\n", info.run_id); fprintf(f, "Submission time: %s\n", duration_str(1, info.time, start_time, 0, 0)); fprintf(f, "Contest time: %s\n", duration_str(0, info.time, start_time, 0, 0)); if (is_privileged) { fprintf(f, "Originator IP: %s\n", xml_unparse_ip(info.a.ip)); } fprintf(f, "Size: %u\n", info.size); if (is_privileged) { fprintf(f, "Hash code (SHA1): "); s = (unsigned char *) &info.sha1; for (i = 0; i < 20; i++) fprintf(f, "%02x", *s++); fprintf(f, "\n"); } fprintf(f, "User ID: %d\n", info.user_id); fprintf(f, "User login: %s\n", teamdb_get_login(state->teamdb_state, info.user_id)); fprintf(f, "User name: %s\n", teamdb_get_name(state->teamdb_state, info.user_id)); fprintf(f, "Problem: %s\n", state->probs[info.prob_id]->short_name); if (state->probs[info.prob_id]->variant_num > 0) { variant = info.variant; if (!variant) { variant = find_variant(state, info.user_id, info.prob_id, &virt_variant); } if (is_privileged && virt_variant != variant) { fprintf(f, "Variant: %d (%d)\n", virt_variant, variant); } else { fprintf(f, "Variant: %d\n", virt_variant); } } fprintf(f, "Language: %s\n", (state->langs[info.lang_id])?((char*)state->langs[info.lang_id]->short_name):""); if (teaminfo.user && teaminfo.user->cnts0 && teaminfo.user->cnts0->location) { fprintf(f, "Location: %s\n", teaminfo.user->cnts0->location); } fprintf(f, "Status: %s\n", run_status_str(info.status, 0, 0, 0, 0)); fclose(f); return 0; cleanup: if (f) fclose(f); return -1; }
int write_xml_tests_report( FILE *f, int user_mode, unsigned char const *txt, ej_cookie_t sid, unsigned char const *self_url, unsigned char const *extra_args, const unsigned char *class1, const unsigned char *class2) { unsigned char *cl1 = " border=\"1\""; unsigned char *cl2 = ""; testing_report_xml_t r = 0; struct html_armor_buffer ab = HTML_ARMOR_INITIALIZER; const unsigned char *font_color = ""; const unsigned char *bgcolor = ""; const unsigned char *fail_str = ""; int i, j; struct testing_report_row *trr = 0; struct testing_report_cell *trc = 0; unsigned char buf[64]; if (class1 && *class1) { cl1 = (unsigned char *) alloca(strlen(class1) + 16); sprintf(cl1, " class=\"%s\"", class1); } if (class2 && *class2) { cl2 = (unsigned char*) alloca(strlen(class2) + 16); sprintf(cl2, " class=\"%s\"", class2); } if (!(r = testing_report_parse_xml(txt))) { fprintf(f, "<p><big>Cannot parse XML file!</big></p>\n"); fprintf(f, "<pre>%s</pre>\n", ARMOR(txt)); goto done; } if (r->compile_error) { fprintf(f, "<h2><font color=\"red\">%s</font></h2>\n", run_status_str(r->status, 0, 0, 0, 0)); if (r->compiler_output) { fprintf(f, "<pre>%s</pre>\n", ARMOR(r->compiler_output)); } goto done; } if (!r->tests_mode) { fprintf(f, "<p><big>Invalid XML file!</big></p>\n"); fprintf(f, "<pre>%s</pre>\n", ARMOR(txt)); goto done; } if (r->status == RUN_CHECK_FAILED) { font_color = " color=\"magenta\""; } else if (r->status == RUN_OK || r->status == RUN_ACCEPTED || r->status == RUN_PENDING_REVIEW) { font_color = " color=\"green\""; } else { font_color = " color=\"red\""; } fprintf(f, "<h2><font%s>%s</font></h2>\n", font_color, run_status_str(r->status, 0, 0, 0, 0)); if (user_mode && r->status == RUN_CHECK_FAILED) { goto done; } if (r->comment) { fprintf(f, "<h3>%s</h3>\n", _("Testing comments")); fprintf(f, "<pre>%s</pre>\n", ARMOR(r->comment)); } if (r->errors) { fprintf(f, "<h3>%s</h3>\n", _("Testing messages")); fprintf(f, "<pre>%s</pre>\n", ARMOR(r->errors)); } if (r->valuer_comment || r->valuer_judge_comment || r->valuer_errors) { fprintf(f, "<h3>%s</h3>\n", _("Valuer information")); if (r->valuer_comment) { fprintf(f, "<b><u>%s</u></b><br/><pre>%s</pre>\n", _("Valuer comments"), ARMOR(r->valuer_comment)); } if (r->valuer_judge_comment) { fprintf(f, "<b><u>%s</u></b><br/><pre>%s</pre>\n", _("Valuer judge comments"), ARMOR(r->valuer_judge_comment)); } if (r->valuer_errors) { fprintf(f, "<b><u>%s</u></b><br/><pre><font color=\"red\">%s</font></pre>\n", _("Valuer errors"), ARMOR(r->valuer_errors)); } } if (r->host && !user_mode) { fprintf(f, "<p><big>Tested on host: %s</big></p>\n", r->host); } if (r->cpu_model && !user_mode) { fprintf(f, "<p>CPU model: %s</p>\n", r->cpu_model); } if (r->cpu_mhz && !user_mode) { fprintf(f, "<p>CPU MHz: %s</p>\n", r->cpu_mhz); } if (r->tt_row_count <= 0 || r->tt_column_count <= 0) { fprintf(f, "<p>%s</p>\n", _("Further testing information is not available")); goto done; } fprintf(f, "<p>%s: %d.</p>\n", _("Total number of sample programs in the test suite"), r->tt_row_count); fprintf(f, "<p>%s: %d.</p>\n", _("Total number of submitted tests"), r->tt_column_count); fprintf(f, "<table%s>\n", cl1); fprintf(f, "<tr>"); fprintf(f, "<th%s width=\"30px\">NN</td>", cl1); fprintf(f, "<th%s width=\"120px\">Prog. name</td>", cl1); fprintf(f, "<th%s width=\"50px\" align=\"center\">Goodness</td>", cl1); for (j = 0; j < r->tt_column_count; ++j) { fprintf(f, "<th%s width=\"40px\" align=\"center\">%d</td>", cl1, j + 1); } fprintf(f, "</tr>\n"); for (i = 0; i < r->tt_row_count; ++i) { fprintf(f, "<tr>"); trr = r->tt_rows[i]; if (trr->status == RUN_CHECK_FAILED) { bgcolor = BGCOLOR_CHECK_FAILED; } else if (trr->status == RUN_OK) { if (trr->must_fail) { bgcolor = BGCOLOR_FAIL; } else { bgcolor = BGCOLOR_PASS; } } else { if (trr->must_fail) { bgcolor = BGCOLOR_PASS; } else { bgcolor = BGCOLOR_FAIL; } } fail_str = "PASS"; font_color = " color=\"green\""; if (trr->must_fail) { fail_str = "FAIL"; font_color = " color=\"red\""; } fprintf(f, "<td%s%s>%d</td>", cl1, bgcolor, i + 1); fprintf(f, "<td%s%s><tt>%s</tt></td>", cl1, bgcolor, ARMOR(trr->name)); fprintf(f, "<td%s%s align=\"center\"><font%s><b>%s</b></font></td>", cl1, bgcolor, font_color, fail_str); for (j = 0; j < r->tt_column_count; ++j) { trc = r->tt_cells[i][j]; if (trc->status == RUN_CHECK_FAILED) { font_color = ""; } else if (trc->status == RUN_OK) { font_color = " color=\"green\""; } else { font_color = " color=\"red\""; } run_status_to_str_short(buf, sizeof(buf), trc->status); fprintf(f, "<td%s%s align=\"center\"><tt><font%s>%s</font></tt></td>", cl1, bgcolor, font_color, buf); } fprintf(f, "</tr>\n"); } fprintf(f, "</table>\n"); done: testing_report_free(r); html_armor_free(&ab); return 0; }