Adding support for a 404 error when an invalid CGI page is requested.
[privoxy.git] / cgisimple.c
index 058faa1..fcf71e7 100644 (file)
@@ -1,7 +1,7 @@
-const char cgisimple_rcs[] = "$Id: cgi.c,v 1.26 2001/09/16 15:47:37 jongfoster Exp $";
+const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.5 2001/10/07 15:30:41 oes Exp $";
 /*********************************************************************
  *
- * File        :  $Source: /cvsroot/ijbswa/current/cgi.c,v $
+ * File        :  $Source: /cvsroot/ijbswa/current/cgisimple.c,v $
  *
  * Purpose     :  Simple CGIs to get information about JunkBuster's
  *                status.
@@ -35,7 +35,22 @@ const char cgisimple_rcs[] = "$Id: cgi.c,v 1.26 2001/09/16 15:47:37 jongfoster E
  *                Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
  * Revisions   :
- *    $Log: cgi.c,v $
+ *    $Log: cgisimple.c,v $
+ *    Revision 1.5  2001/10/07 15:30:41  oes
+ *    Removed FEATURE_DENY_GZIP
+ *
+ *    Revision 1.4  2001/10/02 15:31:12  oes
+ *    Introduced show-request cgi
+ *
+ *    Revision 1.3  2001/09/22 16:34:44  jongfoster
+ *    Removing unneeded #includes
+ *
+ *    Revision 1.2  2001/09/19 18:01:11  oes
+ *    Fixed comments; cosmetics
+ *
+ *    Revision 1.1  2001/09/16 17:08:54  jongfoster
+ *    Moving simple CGI functions from cgi.c to new file cgisimple.c
+ *
  *
  **********************************************************************/
 \f
@@ -58,13 +73,12 @@ const char cgisimple_rcs[] = "$Id: cgi.c,v 1.26 2001/09/16 15:47:37 jongfoster E
 #include "cgisimple.h"
 #include "list.h"
 #include "encode.h"
-#include "ssplit.h"
 #include "jcc.h"
 #include "filters.h"
 #include "actions.h"
-#include "errlog.h"
 #include "miscutil.h"
 #include "loadcfg.h"
+#include "parsers.h"
 
 const char cgisimple_h_rcs[] = CGISIMPLE_H_VERSION;
 
@@ -93,7 +107,7 @@ int cgi_default(struct client_state *csp, struct http_response *rsp,
 {
    char *p;
    char *tmp = NULL;
-   struct map * exports = default_exports(csp, "");
+   struct map *exports = default_exports(csp, "");
 
    /* If there were other parameters, export a dump as "cgi-parameters" */
    if(parameters)
@@ -118,6 +132,81 @@ int cgi_default(struct client_state *csp, struct http_response *rsp,
 }
 
 
+
+
+/*********************************************************************
+ *
+ * Function    :  cgi_error_404
+ *
+ * Description :  CGI function that is called if an unknow action was
+ *                given.
+ *               
+ * Parameters  :
+ *           1 :  csp = Current client state (buffers, headers, etc...)
+ *           2 :  rsp = http_response data structure for output
+ *           3 :  parameters = map of cgi parameters
+ *
+ * Returns     :  0
+ *
+ *********************************************************************/
+int cgi_error_404(struct client_state *csp,
+                  struct http_response *rsp,
+                  struct map *parameters)
+{
+   struct map *exports = default_exports(csp, NULL);
+
+   rsp->status = strdup("404 JunkBuster configuration page not found");
+   rsp->body = template_load(csp, "cgi-error-404");
+   template_fill(&rsp->body, exports);
+   free_map(exports);
+   return 0;
+}
+
+
+/*********************************************************************
+ *
+ * Function    :  cgi_show_request
+ *
+ * Description :  Show the client's request and what sed() would have
+ *                made of it.
+ *               
+ * Parameters  :
+ *           1 :  csp = Current client state (buffers, headers, etc...)
+ *           2 :  rsp = http_response data structure for output
+ *           3 :  parameters = map of cgi parameters
+ *
+ * Returns     :  0
+ *
+ *********************************************************************/
+int cgi_show_request(struct client_state *csp, struct http_response *rsp,
+                struct map *parameters)
+{
+   char *p;
+   struct map *exports = default_exports(csp, "show-request");
+   
+   /*
+    * Repair the damage done to the IOB by get_header()
+    */
+   for (p = csp->iob->buf; p < csp->iob->eod; p++)
+   {
+      if (*p == '\0') *p = '\n';
+   }
+
+   /*
+    * Export the original client's request and the one we would
+    * be sending to the server if this wasn't a CGI call
+    */
+   map(exports, "client-request", 1, csp->iob->buf, 1);
+   map(exports, "processed-request", 1, sed(client_patterns, add_client_headers, csp), 0);
+   
+   rsp->body = template_load(csp, "show-request");
+   template_fill(&rsp->body, exports);
+   free_map(exports);
+   return(0);
+}
+
+
 /*********************************************************************
  *
  * Function    :  cgi_send_banner
@@ -170,9 +259,7 @@ int cgi_send_banner(struct client_state *csp, struct http_response *rsp,
  *           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".
+ * CGI Parameters : none
  *
  * Returns     :  0
  *
@@ -187,6 +274,7 @@ int cgi_show_version(struct client_state *csp, struct http_response *rsp,
    rsp->body = template_load(csp, "show-version");
    template_fill(&rsp->body, exports);
    free_map(exports);
+
    return(0);
 
 }
@@ -204,9 +292,7 @@ int cgi_show_version(struct client_state *csp, struct http_response *rsp,
  *           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".
+ * CGI Parameters : none
  *
  * Returns     :  0
  *
@@ -588,6 +674,7 @@ int cgi_robots_txt(struct client_state *csp, struct http_response *rsp,
    enlist_unique_header(rsp->headers, "Expires", buf);
 
    return 0;
+
 }
 
 
@@ -618,12 +705,6 @@ static void show_defines(struct map *exports)
    map_conditional(exports, "FEATURE_COOKIE_JAR", 0);
 #endif /* ndef FEATURE_COOKIE_JAR */
 
-#ifdef FEATURE_DENY_GZIP
-   map_conditional(exports, "FEATURE_DENY_GZIP", 1);
-#else /* ifndef FEATURE_DENY_GZIP */
-   map_conditional(exports, "FEATURE_DENY_GZIP", 0);
-#endif /* ndef FEATURE_DENY_GZIP */
-
 #ifdef FEATURE_FAST_REDIRECTS
    map_conditional(exports, "FEATURE_FAST_REDIRECTS", 1);
 #else /* ifndef FEATURE_FAST_REDIRECTS */
@@ -703,6 +784,7 @@ static void show_defines(struct map *exports)
 #endif /* ndef STATIC_PCRS */
 
    map(exports, "FORCE_PREFIX", 1, FORCE_PREFIX, 1);
+
 }
 
 
@@ -800,6 +882,7 @@ static char *show_rcs(void)
 #undef SHOW_RCS
 
    return(b);
+
 }