diff options
Diffstat (limited to '')
-rw-r--r-- | src/httpd.c | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/src/httpd.c b/src/httpd.c index 656ad92..6e2c4bf 100644 --- a/src/httpd.c +++ b/src/httpd.c @@ -11,14 +11,24 @@ char * sc_queryhtml (struct sc_query * q) { /* remember to free returned string } #define SC_HRF "<div class=result id=result%lu><h4><a href=\"%s\" accesskey=%lu>%s</a> " \ "<span class=breadcrumb>%s</span></h4><p>%s</p></div>" -#define SC_HRA i, safeurl, i, safetitle, safebreadcrumbs, safebody - char * safetitle = htmlspecialchars(q->results[i]->title); +#define SC_HIF "<a class=result id=result%lu href=\"%s\" accesskey=%lu><img data-title=\"%s\"" \ + "data-breadcrumb=\"%s\" src=\"%s\" /></a>" +#define SC_HRA i, 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); char * safeurl = htmlspecialchars(q->results[i]->url); char * safebreadcrumbs = htmlspecialchars(q->results[i]->breadcrumbs); - size_t ws = snprintf(NULL, 0, SC_HRF, SC_HRA); - SC_HRC(resultshtml, ws); - resultshtml_written += sprintf(resultshtml+resultshtml_written, SC_HRF, SC_HRA); + size_t ws; + if (q->opt & SC_OPT_IMAGE) { + ws = snprintf(NULL, 0, SC_HIF, SC_HRA); + SC_HRC(resultshtml, ws); + resultshtml_written += sprintf(resultshtml+resultshtml_written, SC_HIF, SC_HRA); + } else { + ws = snprintf(NULL, 0, SC_HRF, SC_HRA); + SC_HRC(resultshtml, ws); + resultshtml_written += sprintf(resultshtml+resultshtml_written, SC_HRF, SC_HRA); + } free(safebreadcrumbs); free(safetitle); free(safebody); @@ -103,6 +113,9 @@ int sc_httpd (void * cls, char * location = "//git.sijanec.eu/sijanec/sear.c"; char * content_type = "text/html"; int status_code = MHD_HTTP_OK; + SC_OPT_TYPE opt = 0; + if (MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "i")) + opt |= SC_OPT_IMAGE; if (!host) host = ""; struct sc_query * q = NULL; @@ -143,18 +156,18 @@ int sc_httpd (void * cls, retry: SC_CRLE(c, c->queries_lock); for (size_t i = 0; i < c->queries_length; i++) - if (!strcmp(c->queries[i]->string, query)) + if (!strcmp(c->queries[i]->string, query) && c->queries[i]->opt == opt) q = c->queries[i]; if (q) { response = sc_queryhtml(q); /* 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; + location = q->results[0]->url ? q->results[0]->url : SC_I18N_NO_HREFLINK; } SC_CUE(c, c->queries_lock); } else { SC_CUE(c, c->queries_lock); - sc_query_google(query, c, NULL); + sc_query_google(query, c, NULL, opt); if (already_retried++) { char * safequery = htmlspecialchars(query); response = malloc(strlen((char*) sc_hp)+strlen(safequery)*2+strlen(SC_I18N_HP_ERROR_HEADING)+strlen(SC_I18N_HP_ERROR_BODY)); |