From 28e77dd8f293afb067b6252cd3472c16bb92dcec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Sat, 28 Aug 2021 20:59:00 +0200 Subject: 0.0.14 --- src/httpd.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'src/httpd.c') diff --git a/src/httpd.c b/src/httpd.c index 61c775d..dfa06db 100644 --- a/src/httpd.c +++ b/src/httpd.c @@ -3,7 +3,7 @@ char * sc_https2http (char * i) { memmove(i+4, i+5, strlen(i)-3); return i; } -char * sc_queryhtml (struct sc_query * q, const char * h, size_t l) { /* remember to free returned string in the caller */ /* caller takes care of freeing */ +char * sc_queryhtml (struct sc_query * q, const char * add_form, size_t l) { /* remember to free returned string in the caller */ /* caller takes care of freeing */ size_t resultshtml_written = 0; size_t resultshtml_sizeof = SC_ALLOC_CHUNK; char * resultshtml = malloc(resultshtml_sizeof); @@ -18,7 +18,7 @@ char * sc_queryhtml (struct sc_query * q, const char * h, size_t l) { /* remembe "%s

%s

" #define SC_HIF "" -#define SC_HRA i, safeurl ? h ? sc_https2http(safeurl) : safeurl : SC_I18N_NO_HREFLINK, i, safetitle ? safetitle : SC_I18N_NO_TITLE, \ +#define SC_HRA i, safeurl ? strstr(add_form, "name=h") ? sc_https2http(safeurl) : safeurl : SC_I18N_NO_HREFLINK, i, safetitle ? safetitle : SC_I18N_NO_TITLE, \ safebreadcrumbs ? safebreadcrumbs : safeurl ? safeurl : SC_I18N_NO_HREFLINK, safebody ? safebody : SC_I18N_NO_DESCRIPTION char * safetitle = htmlspecialchars(q->results[i]->title); /* htmlspecialchars returns NULL if input is null */ char * safebody = htmlspecialchars(q->results[i]->desc); @@ -47,8 +47,8 @@ char * sc_queryhtml (struct sc_query * q, const char * h, size_t l) { /* remembe char queryinfo[256]; snprintf(queryinfo, 256, SC_HRS, q->results_length, formatted_time); char * safequery = htmlspecialchars(q->string); - char * response = malloc(strlen((char *) sc_hp)+2*strlen(safequery)+strlen(queryinfo)+strlen(resultshtml)+strlen("")); - sprintf(response, (char *) sc_hp, safequery, safequery, h ? "" : "", queryinfo, resultshtml); + char * response = malloc(strlen((char *) sc_hp)+2*strlen(safequery)+strlen(queryinfo)+strlen(resultshtml)+strlen(add_form)); + sprintf(response, (char *) sc_hp, safequery, safequery, add_form, queryinfo, resultshtml); free(safequery); free(resultshtml); return response; @@ -126,6 +126,13 @@ enum MHD_Result sc_httpd (void * cls, if (!host) host = ""; struct sc_query * q = NULL; + char add_form[128]; + const char * l = MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "l"); + const char * h = MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "h"); + snprintf(add_form, 128, "%s%s%d%s", h ? "" : "", + l ? "" : " -->"); if (!query) { if (url[0] == '/') switch (url[1]) { @@ -157,8 +164,8 @@ enum MHD_Result sc_httpd (void * cls, #endif } if (!response) { - response = malloc(strlen((char *) sc_hp)+strlen(SC_I18N_HP_HEADING)+strlen(SC_I18N_HP_BODY)+strlen("")); - sprintf(response, (char *) sc_hp, "", "", MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "h") ? "" : "", SC_I18N_HP_HEADING, SC_I18N_HP_BODY); + response = malloc(strlen((char *) sc_hp)+strlen(SC_I18N_HP_HEADING)+strlen(SC_I18N_HP_BODY)+strlen(add_form)); + sprintf(response, (char *) sc_hp, "", "", add_form, SC_I18N_HP_HEADING, SC_I18N_HP_BODY); } } else { int already_retried = 0; @@ -169,7 +176,7 @@ retry: q = c->queries[i]; if (q) { const char * l = MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "l"); - response = sc_queryhtml(q, MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "h" /* insecure http */), atoi(l ? l : "0")); /* MHD_create_response_from_buffer will free response (; */ + response = sc_queryhtml(q, add_form, atoi(l ? l : "0")); /* MHD_create_response_from_buffer will free response (; */ if (MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "f") && q->results_length > 0) { status_code = 307; location = q->results[0]->url ? q->results[0]->url : SC_I18N_NO_HREFLINK; -- cgit v1.2.3