Incorporate modified version of Roland Rosenfeld's patch to
authorFabian Keil <fk@fabiankeil.de>
Wed, 6 Sep 2006 18:45:03 +0000 (18:45 +0000)
committerFabian Keil <fk@fabiankeil.de>
Wed, 6 Sep 2006 18:45:03 +0000 (18:45 +0000)
optionally access the user-manual via Privoxy. Closes patch 679075.

Formatting changed to Privoxy style, added call to
cgi_error_no_template if the requested file doesn't
exist and modified check whether or not Privoxy itself
should serve the manual. Should work cross-platform now.

cgi.c
cgisimple.c
cgisimple.h
loadcfg.c

diff --git a/cgi.c b/cgi.c
index 0c7c004..3eec387 100644 (file)
--- a/cgi.c
+++ b/cgi.c
@@ -1,4 +1,4 @@
-const char cgi_rcs[] = "$Id: cgi.c,v 1.72 2006/07/18 14:48:45 david__schmidt Exp $";
+const char cgi_rcs[] = "$Id: cgi.c,v 1.73 2006/08/03 02:46:41 david__schmidt Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/cgi.c,v $
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/cgi.c,v $
@@ -38,6 +38,9 @@ const char cgi_rcs[] = "$Id: cgi.c,v 1.72 2006/07/18 14:48:45 david__schmidt Exp
  *
  * Revisions   :
  *    $Log: cgi.c,v $
  *
  * Revisions   :
  *    $Log: cgi.c,v $
+ *    Revision 1.73  2006/08/03 02:46:41  david__schmidt
+ *    Incorporate Fabian Keil's patch work:\rhttp://www.fabiankeil.de/sourcecode/privoxy/
+ *
  *    Revision 1.72  2006/07/18 14:48:45  david__schmidt
  *    Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
  *    with what was really the latest development (the v_3_0_branch branch)
  *    Revision 1.72  2006/07/18 14:48:45  david__schmidt
  *    Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
  *    with what was really the latest development (the v_3_0_branch branch)
@@ -613,6 +616,9 @@ static const struct cgi_dispatcher cgi_dispatchers[] = {
    { "t",
          cgi_transparent_image, 
          NULL, TRUE /* Send a transparent image (short name) */ },
    { "t",
          cgi_transparent_image, 
          NULL, TRUE /* Send a transparent image (short name) */ },
+   { "user-manual",
+          cgi_send_user_manual,
+          NULL /* Send user-manual */ },
    { NULL, /* NULL Indicates end of list and default page */
          cgi_error_404,
          NULL, TRUE /* Unknown CGI page */ }
    { NULL, /* NULL Indicates end of list and default page */
          cgi_error_404,
          NULL, TRUE /* Unknown CGI page */ }
@@ -825,21 +831,30 @@ static struct http_response *dispatch_known_cgi(struct client_state * csp,
    {
       return cgi_error_memory();
    }
    {
       return cgi_error_memory();
    }
-
    query_args_start = path_copy;
    query_args_start = path_copy;
-   while (*query_args_start && *query_args_start != '?')
+   while (*query_args_start && *query_args_start != '?' && *query_args_start != '/')
    {
       query_args_start++;
    }
    {
       query_args_start++;
    }
-   if (*query_args_start == '?')
+   if (*query_args_start == '/') 
    {
       *query_args_start++ = '\0';
    {
       *query_args_start++ = '\0';
+      if ((param_list = new_map()))
+      {
+         map(param_list, "file", 1, url_decode(query_args_start), 0);
+      }
    }
    }
-
-   if (NULL == (param_list = parse_cgi_parameters(query_args_start)))
+   else
    {
    {
-      free(path_copy);
-      return cgi_error_memory();
+      if (*query_args_start == '?')
+      {
+         *query_args_start++ = '\0';
+      }
+      if (NULL == (param_list = parse_cgi_parameters(query_args_start)))
+      {
+         free(path_copy);
+         return cgi_error_memory();
+      }
    }
 
    /*
    }
 
    /*
@@ -1601,7 +1616,17 @@ char *add_help_link(const char *item,
    if (!item) return NULL;
 
    result = strdup("<a href=\"");
    if (!item) return NULL;
 
    result = strdup("<a href=\"");
-   string_append(&result, config->usermanual);
+   if (!strncmpic(config->usermanual, "file://", 7) ||
+       !strncmpic(config->usermanual, "http", 4))
+   {
+      string_append(&result, config->usermanual);
+   }
+   else
+   {
+      string_append(&result, "http://");
+      string_append(&result, CGI_SITE_2_HOST);
+      string_append(&result, "/user-manual/");
+   }
    string_append(&result, ACTIONS_HELP_PREFIX);
    string_join  (&result, string_toupper(item));
    string_append(&result, "\">");
    string_append(&result, ACTIONS_HELP_PREFIX);
    string_join  (&result, string_toupper(item));
    string_append(&result, "\">");
@@ -2190,7 +2215,15 @@ struct map *default_exports(const struct client_state *csp, const char *caller)
    if (!err) err = map(exports, "default-cgi",   1, html_encode(CGI_PREFIX), 0);
    if (!err) err = map(exports, "menu",          1, make_menu(caller), 0);
    if (!err) err = map(exports, "code-status",   1, CODE_STATUS, 1);
    if (!err) err = map(exports, "default-cgi",   1, html_encode(CGI_PREFIX), 0);
    if (!err) err = map(exports, "menu",          1, make_menu(caller), 0);
    if (!err) err = map(exports, "code-status",   1, CODE_STATUS, 1);
-   if (!err) err = map(exports, "user-manual",   1, csp->config->usermanual ,1);
+   if (!strncmpic(csp->config->usermanual, "file://", 7) ||
+       !strncmpic(csp->config->usermanual, "http", 4))
+   {
+      if (!err) err = map(exports, "user-manual", 1, csp->config->usermanual ,1);
+   }
+   else
+   {
+      if (!err) err = map(exports, "user-manual", 1, "http://"CGI_SITE_2_HOST"/user-manual/" ,1);
+   }
    if (!err) err = map(exports, "actions-help-prefix", 1, ACTIONS_HELP_PREFIX ,1);
 #ifdef FEATURE_TOGGLE
    if (!err) err = map_conditional(exports, "enabled-display", global_toggle_state);
    if (!err) err = map(exports, "actions-help-prefix", 1, ACTIONS_HELP_PREFIX ,1);
 #ifdef FEATURE_TOGGLE
    if (!err) err = map_conditional(exports, "enabled-display", global_toggle_state);
index 3db9ab1..ffa734e 100644 (file)
@@ -1,7 +1,7 @@
-const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.35.2.7 2006/01/29 23:10:56 david__schmidt Exp $";
+const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.37 2006/07/18 14:48:45 david__schmidt Exp $";
 /*********************************************************************
  *
 /*********************************************************************
  *
- * File        :  $Source: /cvsroot/ijbswa/current/Attic/cgisimple.c,v $
+ * File        :  $Source: /cvsroot/ijbswa/current/cgisimple.c,v $
  *
  * Purpose     :  Simple CGIs to get information about Privoxy's
  *                status.
  *
  * Purpose     :  Simple CGIs to get information about Privoxy's
  *                status.
@@ -36,6 +36,10 @@ const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.35.2.7 2006/01/29 23:10:56 da
  *
  * Revisions   :
  *    $Log: cgisimple.c,v $
  *
  * Revisions   :
  *    $Log: cgisimple.c,v $
+ *    Revision 1.37  2006/07/18 14:48:45  david__schmidt
+ *    Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
+ *    with what was really the latest development (the v_3_0_branch branch)
+ *
  *    Revision 1.35.2.7  2006/01/29 23:10:56  david__schmidt
  *    Multiple filter file support
  *
  *    Revision 1.35.2.7  2006/01/29 23:10:56  david__schmidt
  *    Multiple filter file support
  *
@@ -656,6 +660,91 @@ jb_err cgi_send_stylesheet(struct client_state *csp,
    return JB_ERR_OK;
 
 }
    return JB_ERR_OK;
 
 }
+/*********************************************************************
+ *
+ * Function    :  cgi_send_user_manual
+ *
+ * Description :  CGI function that sends a user manual HTML file
+ *
+ * Parameters  :
+ *          1  :  csp = Current client state (buffers, headers, etc...)
+ *          2  :  rsp = http_response data structure for output
+ *          3  :  parameters = map of cgi parameters
+ *
+ * CGI Parameters : file=name.html, the name of the HTML file
+ *                  (relative to user-manual from config)
+ *
+ * Returns     :  JB_ERR_OK on success
+ *                JB_ERR_MEMORY on out-of-memory error.  
+ *
+ *********************************************************************/
+jb_err cgi_send_user_manual(struct client_state *csp,
+                            struct http_response *rsp,
+                            const struct map *parameters)
+{
+   const char * filename;
+   char *full_path;
+   FILE *fp;
+   char buf[BUFFER_SIZE];
+   jb_err err = JB_ERR_OK;
+
+   assert(csp);
+   assert(rsp);
+   assert(parameters);
+
+   get_string_param(parameters, "file", &filename);
+   /* Check paramter for hack attempts */
+   if (filename && strchr(filename, '/'))
+   {
+      return JB_ERR_CGI_PARAMS;
+   }
+   if (filename && strstr(filename, ".."))
+   {
+      return JB_ERR_CGI_PARAMS;
+   }
+
+   full_path = make_path(csp->config->usermanual, filename ? filename : "index.html");
+   if (full_path == NULL)
+   {
+      return JB_ERR_MEMORY;
+   }
+
+   /* Allocate buffer */
+   rsp->body = strdup("");
+   if (rsp->body == NULL)
+   {
+      free(full_path);
+      return JB_ERR_MEMORY;
+   }
+
+   /* Open user-manual file */
+   if (NULL == (fp = fopen(full_path, "r")))
+   {
+      log_error(LOG_LEVEL_ERROR, "Cannot open user-manual file %s: %E", full_path);
+      err = cgi_error_no_template(csp, rsp, full_path);
+      free(full_path);
+      return err;
+   }
+   free(full_path);
+
+   /* Read file and write it out */
+   while (fgets(buf, BUFFER_SIZE, fp))
+   {
+      if (string_append(&rsp->body, buf))
+      {
+         fclose(fp);
+         return JB_ERR_MEMORY;
+      }
+   }
+   fclose(fp);
+
+   if (enlist(rsp->headers, "Content-Type: text/html"))
+   {
+      return JB_ERR_MEMORY;
+   }
+
+   return JB_ERR_OK;
+}
 
 
 /*********************************************************************
 
 
 /*********************************************************************
index 2bfe562..f0b5cd9 100644 (file)
@@ -1,9 +1,9 @@
 #ifndef CGISIMPLE_H_INCLUDED
 #define CGISIMPLE_H_INCLUDED
 #ifndef CGISIMPLE_H_INCLUDED
 #define CGISIMPLE_H_INCLUDED
-#define CGISIMPLE_H_VERSION "$Id: cgisimple.h,v 1.11 2002/04/05 15:50:53 oes Exp $"
+#define CGISIMPLE_H_VERSION "$Id: cgisimple.h,v 1.13 2006/07/18 14:48:45 david__schmidt Exp $"
 /*********************************************************************
  *
 /*********************************************************************
  *
- * File        :  $Source: /cvsroot/ijbswa/current/Attic/cgisimple.h,v $
+ * File        :  $Source: /cvsroot/ijbswa/current/cgisimple.h,v $
  *
  * Purpose     :  Declares functions to intercept request, generate
  *                html or gif answers, and to compose HTTP resonses.
  *
  * Purpose     :  Declares functions to intercept request, generate
  *                html or gif answers, and to compose HTTP resonses.
  *
  * Revisions   :
  *    $Log: cgisimple.h,v $
  *
  * Revisions   :
  *    $Log: cgisimple.h,v $
+ *    Revision 1.13  2006/07/18 14:48:45  david__schmidt
+ *    Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
+ *    with what was really the latest development (the v_3_0_branch branch)
+ *
  *    Revision 1.11  2002/04/05 15:50:53  oes
  *    added send-stylesheet CGI
  *
  *    Revision 1.11  2002/04/05 15:50:53  oes
  *    added send-stylesheet CGI
  *
@@ -128,6 +132,10 @@ extern jb_err cgi_transparent_image (struct client_state *csp,
 extern jb_err cgi_send_stylesheet(struct client_state *csp,
                                   struct http_response *rsp,
                                   const struct map *parameters);
 extern jb_err cgi_send_stylesheet(struct client_state *csp,
                                   struct http_response *rsp,
                                   const struct map *parameters);
+extern jb_err cgi_send_user_manual(struct client_state *csp,
+                                   struct http_response *rsp,
+                                   const struct map *parameters);
+
 
 #ifdef FEATURE_GRACEFUL_TERMINATION
 extern jb_err cgi_die (struct client_state *csp,
 
 #ifdef FEATURE_GRACEFUL_TERMINATION
 extern jb_err cgi_die (struct client_state *csp,
index 131e9bd..04ead0a 100644 (file)
--- a/loadcfg.c
+++ b/loadcfg.c
@@ -1,4 +1,4 @@
-const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.51 2006/09/06 09:23:37 fabiankeil Exp $";
+const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.52 2006/09/06 10:43:32 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/loadcfg.c,v $
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/loadcfg.c,v $
@@ -35,6 +35,12 @@ const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.51 2006/09/06 09:23:37 fabiankeil
  *
  * Revisions   :
  *    $Log: loadcfg.c,v $
  *
  * Revisions   :
  *    $Log: loadcfg.c,v $
+ *    Revision 1.52  2006/09/06 10:43:32  fabiankeil
+ *    Added config option enable-remote-http-toggle
+ *    to specify if Privoxy should recognize special
+ *    headers (currently only X-Filter) to change its
+ *    behaviour. Disabled by default.
+ *
  *    Revision 1.51  2006/09/06 09:23:37  fabiankeil
  *    Make number of retries in case of forwarded-connect problems
  *    a config file option (forwarded-connect-retries) and use 0 as
  *    Revision 1.51  2006/09/06 09:23:37  fabiankeil
  *    Make number of retries in case of forwarded-connect problems
  *    a config file option (forwarded-connect-retries) and use 0 as
@@ -1635,7 +1641,17 @@ static void savearg(char *command, char *argument, struct configuration_spec * c
     * link to it's section in the user-manual
     */
    buf = strdup("\n<br><a href=\"");
     * link to it's section in the user-manual
     */
    buf = strdup("\n<br><a href=\"");
-   string_append(&buf, config->usermanual);
+   if (!strncmpic(config->usermanual, "file://", 7) ||
+       !strncmpic(config->usermanual, "http", 4))
+   {
+      string_append(&buf, config->usermanual);
+   }
+   else
+   {
+      string_append(&buf, "http://");
+      string_append(&buf, CGI_SITE_2_HOST);
+      string_append(&buf, "/user-manual/");
+   }
    string_append(&buf, CONFIG_HELP_PREFIX);
    string_join  (&buf, string_toupper(command));
    string_append(&buf, "\">");
    string_append(&buf, CONFIG_HELP_PREFIX);
    string_join  (&buf, string_toupper(command));
    string_append(&buf, "\">");