summaryrefslogtreecommitdiffstats
path: root/src/httpd.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/httpd.c')
-rw-r--r--src/httpd.c60
1 files changed, 49 insertions, 11 deletions
diff --git a/src/httpd.c b/src/httpd.c
index 39604ef..23f4b60 100644
--- a/src/httpd.c
+++ b/src/httpd.c
@@ -129,6 +129,7 @@ enum MHD_Result sc_httpd (void * cls,
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");
+ const char * f = MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "f");
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,
@@ -187,24 +188,61 @@ retry:
q = i_am_retarded ? *i_am_retarded : NULL;
#endif
if (q) {
- const char * l = MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "l");
- 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! */
+ if (f && q->results_length > 0) {
+ mhdrmm = MHD_RESPMEM_PERSISTENT;/* no need to gen HTML */
+ 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;
+#define LOCHORSE (q->results[0]->url ? q->results[0]->url : SC_I18N_NO_HREFLINK)
+ char * out = alloca(strlen(LOCHORSE)+1);
+ strcpy(out, LOCHORSE);
+ if (h)
+ sc_https2http(LOCHORSE);
+ location = out;
} 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);
- 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)+strlen(add_form));
- sprintf(response, (char *) sc_hp, safequery, safequery, add_form, SC_I18N_HP_ERROR_HEADING, SC_I18N_HP_ERROR_BODY);
- free(safequery);
+ enum sc_return r = sc_query_google(query, c, NULL, opt);
+ if (already_retried++ || r == SC_CAPTCHA) {
+ status_code = 570+ABS(r);
+ if (r == SC_CAPTCHA && strlen(query) < 4096) {
+ if (getenv("SC_FALLBACK")) {
+ status_code = 307;
+ location = alloca(strlen(getenv("SC_FALLBACK"))
+ + 256 + strlen(query)*3);
+ sprintf(location, "%sl=%d&q=", getenv("SC_FALLBACK"),
+ atoi(l ? l : ""));
+ urlencode(location+strlen(location), query);
+ if (opt & SC_OPT_IMAGE)
+ strcat(location, "&i=i");
+ if (h)
+ strcat(location, "&h=h");
+ if (f)
+ strcat(location, "&f=f");
+ }
+ char * safequery = htmlspecialchars(query);
+ response = malloc(strlen((char*) sc_hp)
+ + strlen(safequery) * 2
+ + strlen(SC_I18N_HP_CAPTCHA_HEADING)
+ + strlen(SC_I18N_HP_CAPTCHA_BODY)
+ + strlen(add_form));
+ sprintf(response, (char *) sc_hp, safequery,
+ safequery, add_form, SC_I18N_HP_CAPTCHA_HEADING,
+ SC_I18N_HP_CAPTCHA_BODY);
+ free(safequery);
+ } else {
+ 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)
+ + strlen(add_form));
+ sprintf(response, (char *) sc_hp, safequery, safequery,
+ add_form, SC_I18N_HP_ERROR_HEADING,
+ SC_I18N_HP_ERROR_BODY);
+ free(safequery);
+ }
} else goto retry;
}
}