Moving file version information to a separate CGI page.
[privoxy.git] / cgi.c
diff --git a/cgi.c b/cgi.c
index 727b455..83bd2cb 100644 (file)
--- a/cgi.c
+++ b/cgi.c
@@ -1,4 +1,4 @@
-const char cgi_rcs[] = "$Id: cgi.c,v 1.11 2001/07/18 17:24:37 oes Exp $";
+const char cgi_rcs[] = "$Id: cgi.c,v 1.14 2001/08/01 00:19:03 jongfoster Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/cgi.c,v $
@@ -36,6 +36,19 @@ const char cgi_rcs[] = "$Id: cgi.c,v 1.11 2001/07/18 17:24:37 oes Exp $";
  *
  * Revisions   :
  *    $Log: cgi.c,v $
+ *    Revision 1.14  2001/08/01 00:19:03  jongfoster
+ *    New function: map_conditional() for an if-then-else syntax.
+ *    Changing to use new version of show_defines()
+ *
+ *    Revision 1.13  2001/07/30 22:08:36  jongfoster
+ *    Tidying up #defines:
+ *    - All feature #defines are now of the form FEATURE_xxx
+ *    - Permanently turned off WIN_GUI_EDIT
+ *    - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
+ *
+ *    Revision 1.12  2001/07/29 18:47:05  jongfoster
+ *    Adding missing #include "loadcfg.h"
+ *
  *    Revision 1.11  2001/07/18 17:24:37  oes
  *    Changed to conform to new pcrs interface
  *
@@ -150,10 +163,13 @@ const char cgi_h_rcs[] = CGI_H_VERSION;
 const struct cgi_dispatcher cgi_dispatcher[] = {
    { "show-status", 
          11, cgi_show_status,  
-         "Show information about the version and configuration" }, 
+         "Show information about the current configuration" }, 
    { "show-url-info",
          13, cgi_show_url_info, 
          "Show which actions apply to a URL and why"  },
+   { "show-version", 
+         12, cgi_show_version,  
+         "Show the source code version numbers" }, 
    { "send-banner",
          11, cgi_send_banner, 
          "HIDE Send the transparent or \"Junkbuster\" gif" },
@@ -376,6 +392,39 @@ int cgi_send_banner(struct client_state *csp, struct http_response *rsp,
 }
 
 
+/*********************************************************************
+ *
+ * Function    :  cgi_show_version
+ *
+ * Description :  CGI function that returns a a web page describing the
+ *                file versions of IJB.
+ *
+ * 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 :
+ *           type : Selects the type of banner between "trans" and "jb".
+ *                  Defaults to "jb" if absent or != "trans".
+ *
+ * Returns     :  0
+ *
+ *********************************************************************/
+int cgi_show_version(struct client_state *csp, struct http_response *rsp,
+                     struct map *parameters)
+{
+   struct map *exports = default_exports(csp, "show-version");
+
+   exports = map(exports, "sourceversions", 1, show_rcs(), 0);  
+
+   rsp->body = fill_template(csp, "show-version", exports);
+   free_map(exports);
+   return(0);
+
+}
+
 /*********************************************************************
  *
  * Function    :  cgi_show_status
@@ -402,7 +451,6 @@ int cgi_show_status(struct client_state *csp, struct http_response *rsp,
    int i;
    struct map *exports = default_exports(csp, "show-status");
 
-#ifdef SPLIT_PROXY_ARGS
    FILE * fp;
    char buf[BUFFER_SIZE];
    char * p;
@@ -429,7 +477,7 @@ int cgi_show_status(struct client_state *csp, struct http_response *rsp,
       }
       break;
 
-#ifdef TRUST_FILES
+#ifdef FEATURE_TRUST
    case 't':
       if (csp->tlist)
       {
@@ -437,7 +485,7 @@ int cgi_show_status(struct client_state *csp, struct http_response *rsp,
          file_description = "Trust List";
       }
       break;
-#endif /* def TRUST_FILES */
+#endif /* def FEATURE_TRUST */
    }
 
    if (NULL != filename)
@@ -470,8 +518,6 @@ int cgi_show_status(struct client_state *csp, struct http_response *rsp,
 
    }
 
-#endif /* def SPLIT_PROXY_ARGS */
-
    exports = map(exports, "redirect-url", 1, REDIRECT_URL, 1);
    
    s = NULL;
@@ -483,20 +529,13 @@ int cgi_show_status(struct client_state *csp, struct http_response *rsp,
    exports = map(exports, "invocation", 1, s, 0);
 
    exports = map(exports, "options", 1, csp->config->proxy_args, 1);
-   s =   show_rcs();
-   exports = map(exports, "sourceversions", 1, s, 0);  
-   s =   show_defines();
-   exports = map(exports, "defines", 1, s, 0); 
+   exports = show_defines(exports);
 
-#ifdef STATISTICS
+#ifdef FEATURE_STATISTICS
    exports = add_stats(exports);
-#else
+#else /* ndef FEATURE_STATISTICS */
    exports = map_block_killer(exports, "statistics");
-#endif /* ndef STATISTICS */
-
-#ifdef SPLIT_PROXY_ARGS
-
-   exports = map_block_killer(exports, "no-split-args");
+#endif /* ndef FEATURE_STATISTICS */
 
    if (csp->actions_list)
    {
@@ -516,7 +555,7 @@ int cgi_show_status(struct client_state *csp, struct http_response *rsp,
       exports = map(exports, "re-filter-filename", 1, "None specified", 1);
    }
 
-#ifdef TRUST_FILES
+#ifdef FEATURE_TRUST
    if (csp->tlist)
    {
       exports = map(exports, "trust-filename", 1,  csp->tlist->filename, 1);
@@ -527,29 +566,7 @@ int cgi_show_status(struct client_state *csp, struct http_response *rsp,
    }
 #else
    exports = map_block_killer(exports, "trust-support");
-#endif /* ndef TRUST_FILES */
-
-#else /* ifndef SPLIT_PROXY_ARGS */
-   exports = map_block_killer(exports, "split-args");
-
-   if (csp->clist)
-   {
-      map(exports, "clist", 1, csp->clist->proxy_args , 1);
-   }
-
-   if (csp->rlist)
-   {
-      map(exports, "rlist", 1, csp->rlist->proxy_args , 1);
-   }
-
-#ifdef TRUST_FILES
-    if (csp->tlist)
-   {
-      map(exports, "tlist", 1, csp->tlist->proxy_args , 1);
-   }
-#endif /* def TRUST_FILES */
-
-#endif /* ndef SPLIT_PROXY_ARGS */
+#endif /* ndef FEATURE_TRUST */
 
    rsp->body = fill_template(csp, "show-status", exports);
    free_map(exports);
@@ -807,6 +824,15 @@ struct http_response *finish_http_response(struct http_response *rsp)
 
    /* 
     * Fill in the default headers FIXME: Are these correct? sequence OK? check rfc!
+    * FIXME: Should have:
+    *   "JunkBuster" GIF: Last-Modified: any *fixed* date in the past (as now).
+    *                     Expires: 5 minutes after the time when reply sent
+    *   CGI, "blocked", & all other requests:
+    *        Last-Modified: Time when reply sent
+    *        Expires:       Time when reply sent
+    *       "Cache-Control: no-cache"
+    *        
+    * See http://www.w3.org/Protocols/rfc2068/rfc2068
     */
    enlist_unique(rsp->headers, "Last-Modified: Thu Jul 31, 1997 07:42:22 pm GMT", 14);
    enlist_unique(rsp->headers, "Expires:       Thu Jul 31, 1997 07:42:22 pm GMT", 8);
@@ -1033,6 +1059,48 @@ struct map *map_block_killer(struct map *exports, char *name)
 }
 
 
+/*********************************************************************
+ *
+ * Function    :  map_conditional
+ *
+ * Description :  Convenience function.
+ *                Adds an "if-then-else" for the conditional HTML-template
+ *                block <name>, i.e. a substitution of the form:
+ *                @if-<name>-then@
+ *                   True text
+ *                @else-not-<name>@
+ *                   False text
+ *                @endif-<name>@
+ *
+ *                The control structure and one of the alternatives
+ *                will be hidden.
+ *
+ * Parameters  :  
+ *          1  :  exports = map to extend
+ *          2  :  name = name of conditional block
+ *          3  :  choose_first = nonzero for first, zero for second.
+ *
+ * Returns     :  extended map
+ *
+ *********************************************************************/
+struct map *map_conditional(struct map *exports, char *name, int choose_first)
+{
+   char buf[1000]; /* Will do, since the names are hardwired */
+
+   snprintf(buf, 1000, (choose_first
+      ? "else-not-%s@.*@endif-%s"
+      : "if-%s-then@.*@else-not-%s"),
+      name, name);
+   exports = map(exports, buf, 1, "", 1);
+
+   snprintf(buf, 1000, (choose_first ? "if-%s-then" : "endif-%s"), name);
+   exports = map(exports, buf, 1, "", 1);
+
+   return(exports);
+
+}
+
+
 /*********************************************************************
  *
  * Function    :  make_menu
@@ -1102,7 +1170,7 @@ char *dump_map(struct map *map)
 }
 
 
-#ifdef STATISTICS
+#ifdef FEATURE_STATISTICS
 /*********************************************************************
  *
  * Function    :  add_stats
@@ -1156,7 +1224,7 @@ struct map *add_stats(struct map *exports)
    return(exports);
 
 }
-#endif /* def STATISTICS */
+#endif /* def FEATURE_STATISTICS */
 
 /*
   Local Variables: