summaryrefslogtreecommitdiffstats
path: root/src/httpd.c
diff options
context:
space:
mode:
authorAnton Luka Šijanec <anton@sijanec.eu>2021-08-28 20:59:00 +0200
committerAnton Luka Šijanec <anton@sijanec.eu>2021-08-28 20:59:00 +0200
commit28e77dd8f293afb067b6252cd3472c16bb92dcec (patch)
tree5e49f69ae2e878ffb2f8b090ded102d4e5d57bcc /src/httpd.c
parentupdated changelog and bumped to 0.0.13-1 (diff)
downloadsear.c-28e77dd8f293afb067b6252cd3472c16bb92dcec.tar
sear.c-28e77dd8f293afb067b6252cd3472c16bb92dcec.tar.gz
sear.c-28e77dd8f293afb067b6252cd3472c16bb92dcec.tar.bz2
sear.c-28e77dd8f293afb067b6252cd3472c16bb92dcec.tar.lz
sear.c-28e77dd8f293afb067b6252cd3472c16bb92dcec.tar.xz
sear.c-28e77dd8f293afb067b6252cd3472c16bb92dcec.tar.zst
sear.c-28e77dd8f293afb067b6252cd3472c16bb92dcec.zip
Diffstat (limited to '')
-rw-r--r--src/httpd.c21
1 files changed, 14 insertions, 7 deletions
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
"<span class=breadcrumb>%s</span></h4><p>%s</p></div>"
#define SC_HIF "<a class=result id=result%zu href=\"%s\" accesskey=%zu><img data-title=\"%s\"" \
"data-breadcrumb=\"%s\" src=\"%s\" /></a>"
-#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("<input type=hidden name=h value=h />"));
- sprintf(response, (char *) sc_hp, safequery, safequery, h ? "<input type=hidden name=h value=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 ? "<input type=hidden name=h value=h />" : "",
+ l ? "<input type=hidden name=l value=" : "<!-- Odgovor na dokončno vprašanje o Življenju, Vesolju in sploh Vsem je ",
+ l ? atoi(l) : 42,
+ 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("<input type=hidden name=h value=h />"));
- sprintf(response, (char *) sc_hp, "", "", MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "h") ? "<input type=hidden name=h value=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;