diff options
Diffstat (limited to '')
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | debian/changelog | 8 | ||||
-rw-r--r-- | src/hp.html | 91 | ||||
-rw-r--r-- | src/httpd.c | 21 |
4 files changed, 22 insertions, 101 deletions
@@ -3,9 +3,8 @@ DESTDIR=/ .NOTPARALLEL: default: mkdir tmp -p - cp src/hp.html tmp/hp.html -[ ! -f tmp/hp.css ] && wget -c https://sijanec.eu/assets/css/styles.css?ref=sear.c-make -Otmp/hp.css - php -r "file_put_contents('tmp/hp.html', str_replace('INSERT-STYLESHEET-HERE', str_replace('%', '%%', file_get_contents('tmp/hp.css')), file_get_contents('tmp/hp.html')));" + php src/hp.php > tmp/hp.html xxd -i < tmp/hp.html > tmp/hp.xxd echo ', 0' >> tmp/hp.xxd xxd -i < src/osdd.xml > tmp/osdd.xxd diff --git a/debian/changelog b/debian/changelog index d9f43ee..f3ee604 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,8 +1,14 @@ +sear.c (0.0.14-1) stable; urgency=low + + * beautified how PHP scripting is done and how l and h are resent + + -- Anton Luka Šijanec <anton@sijanec.eu> Sat, 28 Aug 2021 20:00:00 +0200 + sear.c (0.0.13-1) stable; urgency=low * replaced systemd service User=nobody with DynamicUser=yes - -- Anton Luka Šijanec <anton@sijanec.eu> Pon, 23 Aug 2021 20:00:00 +0200 + -- Anton Luka Šijanec <anton@sijanec.eu> Mon, 23 Aug 2021 20:00:00 +0200 sear.c (0.0.12-1) stable; urgency=low diff --git a/src/hp.html b/src/hp.html deleted file mode 100644 index e1ab301..0000000 --- a/src/hp.html +++ /dev/null @@ -1,91 +0,0 @@ -<!DOCTYPE html> -<html lang=sl> - <!-- this file is a printf format. be sure to escape percent signs with percent percent. --> - <!-- this format requires the following types (in order): query string, query string, additional form elements, result info string, results html string --> - <head> - <meta charset=UTF-8 /> - <title> - %s :: sear.c - </title> - <meta name=viewport content="width=device-width, initial-scale=1.0"> - <style> - INSERT-STYLESHEET-HERE - </style> - <link rel="shortcut icon" href=data:image/x-icon;, type=image/x-icon> <!-- prevents favicon lookups --> - <link rel=icon href=data:;base64,iVBORw0KGgo=> - <link rel=search type=application/opensearchdescription+xml href=/osdd.xml> - <style> - input[type=password], input[type=text], input[type=submit], input[type=button] { - height: 1cm; - font-size: large; - } - .result:hover { - background: var(--bgc2); - } - .container { - display: flex; - flex-direction: row; - flex-wrap: nowrap; - justify-content: center; - align-items: stretch; - } - input[name=q] { - flex-grow: 4; - } - input[type=submit] { - flex-basis: 12.5%%; - } - .SC_LOG_ERROR { - color: red; - } - .SC_LOG_WARNING { - color: orange; - } - .SC_LOG_INFO { - color: lightgreen; - } - .SC_LOG_DEBUG { - color: magenta; - } - .breadcrumb { - color: var(--fgc2); - font-size: small; /* small is relative to parent (h4) size */ - } - .result h4 { - white-space: nowrap; - overflow: hidden; - text-overflow: ellipsis; - margin-bottom: 0.314159265358em; - } - .result p { - margin-top: 0.314159265358em; - } - .result img { - height: 10em; - } - .result img:hover { - height: 20em; /* biggah pictah onah hovrah */ - } - </style> - </head> - <body> - <form class=container action=.> - <input accesskey=4 type=text name=q value="%s" placeholder="sear.c ..." /> <!-- see www.standardaccesskeys.com --> - <input type=submit value=🔍 /> <!-- magnifying glass emoji --> - <input type=submit name=f value=Ʊ /> <!-- horseshoe unicode character --> - <input type=submit name=i value=🖼 /> <!-- framed picture emoji - img search --> - <!-- <input type=submit name=v value=🎬/> --> <!-- that thing they use in movies - vid search N/I --> - %s - </form> - <h3> - %s - </h3> - %s - <hr> - <h4 align=center> - <a href=//git.sijanec.eu/sijanec/sear.c > - sear.c - </a> - </h4> - </body> -</html> 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; |