X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=blobdiff_plain;f=cgi.c;h=2f238e11c595a54ddae3566448a4ccc3bae95bee;hp=e377ad2931899e12434c2784688b50f8afbef874;hb=360fc9826de0a9df4f737a1d7d8bc7b7456dbf48;hpb=f5e468e33c017f857da32b17e2940b9e79c8f202
diff --git a/cgi.c b/cgi.c
index e377ad29..2f238e11 100644
--- a/cgi.c
+++ b/cgi.c
@@ -1,4 +1,4 @@
-const char cgi_rcs[] = "$Id: cgi.c,v 1.91 2007/01/27 13:09:16 fabiankeil Exp $";
+const char cgi_rcs[] = "$Id: cgi.c,v 1.108 2008/05/26 17:30:53 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/cgi.c,v $
@@ -11,7 +11,7 @@ const char cgi_rcs[] = "$Id: cgi.c,v 1.91 2007/01/27 13:09:16 fabiankeil Exp $";
* Functions declared include:
*
*
- * Copyright : Written by and Copyright (C) 2001-2004, 2006-2007
+ * Copyright : Written by and Copyright (C) 2001-2004, 2006-2008
* the SourceForge Privoxy team. http://www.privoxy.org/
*
* Based on the Internet Junkbuster originally written
@@ -38,6 +38,70 @@ const char cgi_rcs[] = "$Id: cgi.c,v 1.91 2007/01/27 13:09:16 fabiankeil Exp $";
*
* Revisions :
* $Log: cgi.c,v $
+ * Revision 1.108 2008/05/26 17:30:53 fabiankeil
+ * Provide an OpenSearch Description to access the
+ * show-url-info page through "search engine plugins".
+ *
+ * Revision 1.107 2008/05/26 16:23:19 fabiankeil
+ * - Fix spelling in template-not-found message.
+ * - Declare referrer_is_safe()'s alternative_prefix[] static.
+ *
+ * Revision 1.106 2008/05/21 15:24:38 fabiankeil
+ * Mark csp as immutable for a bunch of functions.
+ *
+ * Revision 1.105 2008/04/17 14:40:47 fabiankeil
+ * Provide get_http_time() with the buffer size so it doesn't
+ * have to blindly assume that the buffer is big enough.
+ *
+ * Revision 1.104 2008/03/26 18:07:06 fabiankeil
+ * Add hostname directive. Closes PR#1918189.
+ *
+ * Revision 1.103 2008/03/21 11:13:57 fabiankeil
+ * Only gather host information if it's actually needed.
+ * Also move the code out of accept_connection() so it's less likely
+ * to delay other incoming connections if the host is misconfigured.
+ *
+ * Revision 1.102 2008/02/23 16:33:43 fabiankeil
+ * Let forward_url() use the standard parameter ordering
+ * and mark its second parameter immutable.
+ *
+ * Revision 1.101 2008/02/03 15:45:06 fabiankeil
+ * Add SOCKS5 support for "Forwarding failure" CGI page.
+ *
+ * Revision 1.100 2007/10/17 18:40:53 fabiankeil
+ * - Send CGI pages as HTTP/1.1 unless the client asked for HTTP/1.0.
+ * - White space fix.
+ *
+ * Revision 1.99 2007/08/05 13:42:22 fabiankeil
+ * #1763173 from Stefan Huehner: declare some more functions static.
+ *
+ * Revision 1.98 2007/05/14 10:33:51 fabiankeil
+ * - Use strlcpy() and strlcat() instead of strcpy() and strcat().
+ *
+ * Revision 1.97 2007/04/09 18:11:35 fabiankeil
+ * Don't mistake VC++'s _snprintf() for a snprintf() replacement.
+ *
+ * Revision 1.96 2007/03/08 17:41:05 fabiankeil
+ * Use sizeof() more often.
+ *
+ * Revision 1.95 2007/02/10 17:01:37 fabiankeil
+ * Don't overlook map result for the forwarding-type.
+ *
+ * Revision 1.94 2007/02/08 19:44:49 fabiankeil
+ * Use a transparent background for the PNG replacement pattern.
+ *
+ * Revision 1.93 2007/02/07 10:45:22 fabiankeil
+ * - Save the reason for generating http_responses.
+ * - Fix --disable-toggle (again).
+ * - Use TBL birthday hack for 403 responses as well.
+ * - Uglify the @menu@ again to fix JavaScript
+ * errors on the "blocked" template.
+ * - Escape an ampersand in cgi_error_unknown().
+ *
+ * Revision 1.92 2007/01/28 13:41:17 fabiankeil
+ * - Add HEAD support to finish_http_response.
+ * - Add error favicon to internal HTML error messages.
+ *
* Revision 1.91 2007/01/27 13:09:16 fabiankeil
* Add new config option "templdir" to
* change the templates directory.
@@ -562,10 +626,6 @@ const char cgi_rcs[] = "$Id: cgi.c,v 1.91 2007/01/27 13:09:16 fabiankeil Exp $";
#include
#include
-#ifdef _WIN32
-#define snprintf _snprintf
-#endif /* def _WIN32 */
-
#include "project.h"
#include "cgi.h"
#include "list.h"
@@ -575,6 +635,7 @@ const char cgi_rcs[] = "$Id: cgi.c,v 1.91 2007/01/27 13:09:16 fabiankeil Exp $";
#include "filters.h"
#include "miscutil.h"
#include "cgisimple.h"
+#include "jbsockets.h"
#ifdef FEATURE_CGI_EDIT_ACTIONS
#include "cgiedit.h"
#endif /* def FEATURE_CGI_EDIT_ACTIONS */
@@ -715,6 +776,9 @@ static const struct cgi_dispatcher cgi_dispatchers[] = {
{ "t",
cgi_transparent_image,
NULL, TRUE /* Send a transparent image (short name) */ },
+ { "url-info-osd.xml",
+ cgi_send_url_info_osd,
+ NULL, TRUE /* Send templates/url-info-osd.xml */ },
{ "user-manual",
cgi_send_user_manual,
NULL, TRUE /* Send user-manual */ },
@@ -738,12 +802,12 @@ static const struct cgi_dispatcher cgi_dispatchers[] = {
*/
const char image_pattern_data[] =
"\211\120\116\107\015\012\032\012\000\000\000\015\111\110\104"
- "\122\000\000\000\004\000\000\000\004\010\002\000\000\000\046"
- "\223\011\051\000\000\000\006\142\113\107\104\000\310\000\310"
- "\000\310\052\045\225\037\000\000\000\032\111\104\101\124\170"
- "\332\143\070\161\342\304\377\377\377\041\044\003\234\165\342"
- "\304\011\006\234\062\000\125\200\052\251\125\174\360\223\000"
- "\000\000\000\111\105\116\104\256\102\140\202";
+ "\122\000\000\000\004\000\000\000\004\010\006\000\000\000\251"
+ "\361\236\176\000\000\000\006\142\113\107\104\000\000\000\000"
+ "\000\000\371\103\273\177\000\000\000\033\111\104\101\124\010"
+ "\327\143\140\140\140\060\377\377\377\077\003\234\106\341\060"
+ "\060\230\063\020\124\001\000\161\021\031\241\034\364\030\143"
+ "\000\000\000\000\111\105\116\104\256\102\140\202";
/*
* 1x1 transparant PNG.
@@ -878,7 +942,7 @@ struct http_response *dispatch_cgi(struct client_state *csp)
* Returns : pointer to value (no copy!), or NULL if none found.
*
*********************************************************************/
-char *grep_cgi_referrer(const struct client_state *csp)
+static char *grep_cgi_referrer(const struct client_state *csp)
{
struct list_entry *p;
@@ -910,10 +974,10 @@ char *grep_cgi_referrer(const struct client_state *csp)
* FALSE if the referrer is unsafe or not set.
*
*********************************************************************/
-int referrer_is_safe (const struct client_state *csp)
+static int referrer_is_safe(const struct client_state *csp)
{
char *referrer;
- const char alternative_prefix[] = "http://" CGI_SITE_1_HOST "/";
+ static const char alternative_prefix[] = "http://" CGI_SITE_1_HOST "/";
referrer = grep_cgi_referrer(csp);
@@ -1017,10 +1081,6 @@ static struct http_response *dispatch_known_cgi(struct client_state * csp,
return cgi_error_memory();
}
- log_error(LOG_LEVEL_GPC, "%s%s cgi call", csp->http->hostport, csp->http->path);
- log_error(LOG_LEVEL_CLF, "%s - - [%T] \"%s\" 200 3",
- csp->ip_addr_str, csp->http->cmd);
-
/*
* Find and start the right CGI function
*/
@@ -1070,6 +1130,7 @@ static struct http_response *dispatch_known_cgi(struct client_state * csp,
if (!err)
{
/* It worked */
+ rsp->reason = RSP_REASON_CGI_CALL;
return finish_http_response(csp, rsp);
}
else
@@ -1357,11 +1418,13 @@ struct http_response *error_response(struct client_state *csp,
return cgi_error_memory();
}
+#ifdef FEATURE_FORCE_LOAD
if (csp->flags & CSP_FLAG_FORCED)
{
path = strdup(FORCE_PREFIX);
}
else
+#endif /* def FEATURE_FORCE_LOAD */
{
path = strdup("");
}
@@ -1399,10 +1462,12 @@ struct http_response *error_response(struct client_state *csp,
free_http_response(rsp);
return cgi_error_memory();
}
+ rsp->reason = RSP_REASON_NO_SUCH_DOMAIN;
}
else if (!strcmp(templatename, "forwarding-failed"))
{
- const struct forward_spec * fwd = forward_url(csp->http, csp);
+ const struct forward_spec *fwd = forward_url(csp, csp->http);
+ char *socks_type = NULL;
if (fwd == NULL)
{
log_error(LOG_LEVEL_FATAL, "gateway spec is NULL. This shouldn't happen!");
@@ -1428,8 +1493,27 @@ struct http_response *error_response(struct client_state *csp,
csp->error_message = strdup("Failure reason missing. Check the log file for details.");
}
if (!err) err = map(exports, "gateway", 1, fwd->gateway_host, 1);
- if (!err) map(exports, "forwarding-type", 1, (fwd->type == SOCKS_4) ?
- "socks4-" : "socks4a-", 1);
+
+ /*
+ * XXX: this is almost the same code as in cgi_show_url_info()
+ * and thus should be factored out and shared.
+ */
+ switch (fwd->type)
+ {
+ case SOCKS_4:
+ socks_type = "socks4-";
+ break;
+ case SOCKS_4A:
+ socks_type = "socks4a-";
+ break;
+ case SOCKS_5:
+ socks_type = "socks5-";
+ break;
+ default:
+ log_error(LOG_LEVEL_FATAL, "Unknown socks type: %d.", fwd->type);
+ }
+
+ if (!err) err = map(exports, "forwarding-type", 1, socks_type, 1);
if (!err) err = map(exports, "error-message", 1, html_encode(csp->error_message), 0);
if (!err) rsp->status = strdup("503 Forwarding failure");
@@ -1439,6 +1523,7 @@ struct http_response *error_response(struct client_state *csp,
free_http_response(rsp);
return cgi_error_memory();
}
+ rsp->reason = RSP_REASON_FORWARDING_FAILED;
}
else if (!strcmp(templatename, "connect-failed"))
{
@@ -1449,6 +1534,7 @@ struct http_response *error_response(struct client_state *csp,
free_http_response(rsp);
return cgi_error_memory();
}
+ rsp->reason = RSP_REASON_CONNECT_FAILED;
}
err = template_fill_for_cgi(csp, templatename, exports, rsp);
@@ -1483,7 +1569,7 @@ struct http_response *error_response(struct client_state *csp,
* JB_ERR_MEMORY on out-of-memory error.
*
*********************************************************************/
-jb_err cgi_error_disabled(struct client_state *csp,
+jb_err cgi_error_disabled(const struct client_state *csp,
struct http_response *rsp)
{
struct map *exports;
@@ -1541,6 +1627,7 @@ void cgi_init_error_messages(void)
strlen(cgi_error_memory_response->head);
cgi_error_memory_response->content_length =
strlen(cgi_error_memory_response->body);
+ cgi_error_memory_response->reason = RSP_REASON_OUT_OF_MEMORY;
}
@@ -1585,7 +1672,7 @@ struct http_response *cgi_error_memory(void)
* JB_ERR_MEMORY on out-of-memory error.
*
*********************************************************************/
-jb_err cgi_error_no_template(struct client_state *csp,
+jb_err cgi_error_no_template(const struct client_state *csp,
struct http_response *rsp,
const char *template_name)
{
@@ -1602,7 +1689,7 @@ jb_err cgi_error_no_template(struct client_state *csp,
"Privoxy encountered an error while processing your request:
\r\n"
"Could not load template file ";
static const char body_suffix[] =
- "
or one of it's included components.
\r\n"
+ " or one of its included components.
\r\n"
"Please contact your proxy administrator.
\r\n"
"If you are the proxy administrator, please put the required file(s)"
"in the (confdir)/templates
directory. The "
@@ -1615,6 +1702,7 @@ jb_err cgi_error_no_template(struct client_state *csp,
").
\r\n"
"