summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/hp.html91
-rw-r--r--src/httpd.c21
2 files changed, 14 insertions, 98 deletions
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;