commit 1b4e458e9c63f638eb44adeb8d8ff7b7a9b4dd19 from: Sergey Bronnikov date: Wed Apr 29 22:29:46 2020 UTC Fix testres.cgi commit - 6e17db5d70280e5d38e43301b6283d8be0f3b510 commit + 1b4e458e9c63f638eb44adeb8d8ff7b7a9b4dd19 blob - 7781170e4ab07fdf803a5646758c8fdd455977a9 blob + 6e5e69749d75a533dbb40b1051e69db748ba5b8f --- src/testres.cgi.c +++ src/testres.cgi.c @@ -40,39 +40,22 @@ struct config { typedef struct config config; -int cgi_parse(char *query_string, struct config *conf); +void cgi_parse(char *query_string, struct config *conf); -int cgi_parse(char *query_string, struct config *conf) { - if (query_string == NULL) { - conf->cgi_action = (char*)"/"; - return 0; - } +void cgi_parse(char *query_string, struct config *conf) { + conf->cgi_action = NULL; + conf->cgi_args = NULL; conf->cgi_action = strtok(query_string, "="); - conf->cgi_args = strtok(NULL, "="); - if (conf->cgi_action == NULL) { - return 1; - } - return 0; + if (conf->cgi_action) + conf->cgi_args = strtok(NULL, "="); } int main(void) { - print_html_headers(); - printf("Hello!\n"); - print_html_footer(); - config *conf = calloc(1, sizeof(config)); - if (conf == NULL) { - perror("calloc"); - return 1; - } - - char *query_string = getenv("QUERY_STRING"); - if (!cgi_parse(query_string, conf)) { + if (!conf) { print_html_headers(); - printf("wrong a http request: %s\n", query_string); + printf("calloc\n"); print_html_footer(); - free(query_string); - free(conf); return 1; } @@ -81,41 +64,33 @@ int main(void) { print_html_headers(); printf("no reports found\n"); print_html_footer(); - return 0; + return 1; } - if (strcmp(conf->cgi_action, "/") == 0) { - print_html_headers(); + + char *query_string = getenv("QUERY_STRING"); + cgi_parse(query_string, conf); + + print_html_headers(); + if (!(conf->cgi_action && conf->cgi_args)) { print_html_reports(reports); - print_html_footer(); - free(conf); - free_reports(reports); - return 0; - } else if (strcmp(conf->cgi_action, "show")) { - tailq_report *report; - if ((report = is_report_exists(reports, conf->cgi_args)) != NULL) { - print_html_headers(); - print_html_report(report); - print_html_footer(); + } else { + if (!strcmp(conf->cgi_action, "show")) { + tailq_report *report; + if ((report = is_report_exists(reports, conf->cgi_args))) { + print_html_report(report); + free_report(report); + } + } else if (!strcmp(conf->cgi_action, "q")) { + struct reportq *filtered = NULL; + filtered = filter_reports(reports, conf->cgi_args); + print_html_reports(filtered); + free_reports(filtered); } else { - print_html_headers(); - printf("report not found\n"); - print_html_footer(); + print_html_reports(reports); } - free_report(report); - return 0; - } else if (strcmp(conf->cgi_action, "q") == 0) { - struct reportq *filtered = NULL; - filtered = filter_reports(reports, conf->cgi_args); - print_html_headers(); - print_html_reports(filtered); - print_html_footer(); - free_reports(reports); - free_reports(filtered); - return 0; - } else { - print_html_headers(); - printf("unknown action\n"); - print_html_footer(); } + print_html_footer(); + free(conf); + free_reports(reports); return 0; } blob - fd176665cb2d64ee6f379be2bf624843c265a695 blob + 9474d09e36bf1d2297fdf982070a620d05304445 --- src/testres.h +++ src/testres.h @@ -1,5 +1,5 @@ /* - * Copyright © 2019 Sergey Bronnikov + * Copyright © 2019-2020 Sergey Bronnikov * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -29,9 +29,9 @@ #ifndef TESTRES_H #define TESTRES_H -#define SCRIPT_NAME "testres.cgi" -#define STYLESHEET "testres.css" -#define VERSION "0.1.0" -#define SLOWEST_THRESHOLD 5 +#define SCRIPT_NAME "cgi-bin/testres.cgi" +#define STYLESHEET "/testres.css" +#define VERSION "0.1.0" +#define SLOWEST_THRESHOLD 5 -#endif /* TESTRES_H */ +#endif /* TESTRES_H */ blob - 1ba93c8ea848033593eb1be781853d04c087608a blob + 16cd8b2e7beacef628837ac33feb2c62deba9d10 --- src/ui_http.c +++ src/ui_http.c @@ -1,5 +1,5 @@ /* - * Copyright © 2018-2019 Sergey Bronnikov + * Copyright © 2018-2020 Sergey Bronnikov * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -58,7 +58,7 @@ void print_html_headers() { void print_html_footer() { printf("
"); - printf("generated by testres (%s)", VERSION); + printf("generated by testres (%s)", VERSION); printf("
\n"); printf("\n"); printf("\n"); @@ -66,7 +66,7 @@ void print_html_footer() { void print_html_search() { printf("
"); - printf("
\n", SCRIPT_NAME); + printf("\n", SCRIPT_NAME); printf(" \n"); printf(" \n"); printf("
\n"); @@ -87,8 +87,8 @@ print_html_reports(struct reportq * reports) { time_t prev_time = {0}; char datestr[128]; TAILQ_FOREACH(report_item, reports, entries) { - printf("%s\n", - report_item->id, report_item->id); + printf("%s\n", + SCRIPT_NAME, report_item->id, report_item->id); double perc = metric_pass_rate(report_item); if (perc >= 50) { printf("%0.0f\n", perc); @@ -149,9 +149,9 @@ print_html_suites(struct suiteq * suites) { printf("Time\n"); printf("\n"); TAILQ_FOREACH(suite_item, suites, entries) { - if (!TAILQ_EMPTY(suite_item->tests)) { - print_html_tests(suite_item->tests); - } + if (!TAILQ_EMPTY(suite_item->tests)) { + print_html_tests(suite_item->tests); + } } printf("\n"); }