From b40b327c533039d41b24d42d1c4639b67aa05ecd Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Sun, 3 Feb 2008 15:45:06 +0000 Subject: [PATCH] Add SOCKS5 support for "Forwarding failure" CGI page. --- cgi.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/cgi.c b/cgi.c index 0d7a0855..502d88e6 100644 --- a/cgi.c +++ b/cgi.c @@ -1,4 +1,4 @@ -const char cgi_rcs[] = "$Id: cgi.c,v 1.99 2007/08/05 13:42:22 fabiankeil Exp $"; +const char cgi_rcs[] = "$Id: cgi.c,v 1.100 2007/10/17 18:40:53 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/cgi.c,v $ @@ -38,6 +38,10 @@ const char cgi_rcs[] = "$Id: cgi.c,v 1.99 2007/08/05 13:42:22 fabiankeil Exp $"; * * Revisions : * $Log: cgi.c,v $ + * 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. * @@ -1429,6 +1433,7 @@ struct http_response *error_response(struct client_state *csp, else if (!strcmp(templatename, "forwarding-failed")) { const struct forward_spec * fwd = forward_url(csp->http, csp); + char *socks_type = NULL; if (fwd == NULL) { log_error(LOG_LEVEL_FATAL, "gateway spec is NULL. This shouldn't happen!"); @@ -1454,8 +1459,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) 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"); -- 2.39.2