summaryrefslogtreecommitdiffstats
path: root/src/httpd.c
diff options
context:
space:
mode:
authorAnton Luka Šijanec <anton@sijanec.eu>2021-12-26 19:52:31 +0100
committerAnton Luka Šijanec <anton@sijanec.eu>2021-12-26 19:52:31 +0100
commita10a8fb335e5a817e1a9add49ee179394eea67c4 (patch)
tree70ea95120f4390a6a5f32cda5a8bf1d45e4e0487 /src/httpd.c
parent0.0.16, read debian/changelog (diff)
downloadsear.c-a10a8fb335e5a817e1a9add49ee179394eea67c4.tar
sear.c-a10a8fb335e5a817e1a9add49ee179394eea67c4.tar.gz
sear.c-a10a8fb335e5a817e1a9add49ee179394eea67c4.tar.bz2
sear.c-a10a8fb335e5a817e1a9add49ee179394eea67c4.tar.lz
sear.c-a10a8fb335e5a817e1a9add49ee179394eea67c4.tar.xz
sear.c-a10a8fb335e5a817e1a9add49ee179394eea67c4.tar.zst
sear.c-a10a8fb335e5a817e1a9add49ee179394eea67c4.zip
Diffstat (limited to '')
-rw-r--r--src/httpd.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/httpd.c b/src/httpd.c
index 514f57a..39604ef 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 * add_form, size_t l) { /* remember to free returned string in the caller */ /* caller takes care of freeing */
+char * sc_queryhtml (const 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);
@@ -120,12 +120,12 @@ enum MHD_Result 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;
+ SC_OPT_TYPE opt = SC_OPT_INIT;
if (MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "i"))
opt |= SC_OPT_IMAGE;
if (!host)
host = "";
- struct sc_query * q = NULL;
+ const 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");
@@ -172,18 +172,30 @@ enum MHD_Result sc_httpd (void * cls,
}
} else {
int already_retried = 0;
+ const struct sc_query query_to_find = {
+ .string = (char *) query,
+ .opt = opt
+ };
retry:
SC_CRLE(c, c->queries_lock);
+#ifdef SC_OLD_STORAGE
for (size_t i = 0; i < c->queries_length; i++)
- if (!strcmp(c->queries[i]->string, query) && c->queries[i]->opt == opt)
+ if (!sc_query_compar(c->queries[i], &query_to_find))
q = c->queries[i];
+#else /* tfind(3) also requires a pointer to the variable that holds rootp! */
+ const struct sc_query ** i_am_retarded = tfind(&query_to_find, &c->qrp, SC_COMPAR_CAST sc_query_compar);
+ q = i_am_retarded ? *i_am_retarded : NULL;
+#endif
if (q) {
const char * l = MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "l");
- 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) {
+ mhdrmm = MHD_RESPMEM_PERSISTENT; /* no need to generate HTML if */
+ content_type = "text/plain"; /* we have a feeling of luck! */
+ response = SC_I18N_HORSESHOE_RESPONSE;
status_code = 307;
location = q->results[0]->url ? q->results[0]->url : SC_I18N_NO_HREFLINK;
- }
+ } else
+ response = sc_queryhtml(q, add_form, atoi(l ? l : "0")); /* MHD_create_response_from_buffer will free response (; */
SC_CUE(c, c->queries_lock);
} else {
SC_CUE(c, c->queries_lock);