Reuse directive_hash and don't hash the same directive twice.
[privoxy.git] / cgi.c
diff --git a/cgi.c b/cgi.c
index 9171737..1916108 100644 (file)
--- a/cgi.c
+++ b/cgi.c
@@ -1,4 +1,4 @@
-const char cgi_rcs[] = "$Id: cgi.c,v 1.103 2008/03/21 11:13:57 fabiankeil Exp $";
+const char cgi_rcs[] = "$Id: cgi.c,v 1.105 2008/04/17 14:40:47 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/cgi.c,v $
@@ -38,6 +38,13 @@ const char cgi_rcs[] = "$Id: cgi.c,v 1.103 2008/03/21 11:13:57 fabiankeil Exp $"
  *
  * Revisions   :
  *    $Log: cgi.c,v $
+ *    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
@@ -1548,7 +1555,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;
@@ -1651,7 +1658,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)
 {
@@ -1738,7 +1745,7 @@ jb_err cgi_error_no_template(struct client_state *csp,
  *                JB_ERR_MEMORY on out-of-memory error.  
  *
  *********************************************************************/
-jb_err cgi_error_unknown(struct client_state *csp,
+jb_err cgi_error_unknown(const struct client_state *csp,
                          struct http_response *rsp,
                          jb_err error_to_report)
 {
@@ -1817,7 +1824,7 @@ jb_err cgi_error_unknown(struct client_state *csp,
  *                JB_ERR_MEMORY on out-of-memory error.  
  *
  *********************************************************************/
-jb_err cgi_error_bad_param(struct client_state *csp,
+jb_err cgi_error_bad_param(const struct client_state *csp,
                            struct http_response *rsp)
 {
    struct map *exports;
@@ -1929,19 +1936,18 @@ char *add_help_link(const char *item,
  *                HTTP header - e.g.:
  *                "Sun, 06 Nov 1994 08:49:37 GMT"
  *
- *                XXX: Should probably get a third parameter for
- *                the buffer size.
- *
  * Parameters  :  
  *          1  :  time_offset = Time returned will be current time
  *                              plus this number of seconds.
- *          2  :  buf = Destination for result.  Must be long enough
- *                      to hold 29 characters plus a trailing zero.
+ *          2  :  buf = Destination for result.
+ *          3  :  buffer_size = Size of the buffer above. Must be big
+ *                              enough to hold 29 characters plus a
+ *                              trailing zero.
  *
  * Returns     :  N/A
  *
  *********************************************************************/
-void get_http_time(int time_offset, char *buf)
+void get_http_time(int time_offset, char *buf, size_t buffer_size)
 {
    static const char day_names[7][4] =
       { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
@@ -1962,6 +1968,7 @@ void get_http_time(int time_offset, char *buf)
 #endif
 
    assert(buf);
+   assert(buffer_size > 29);
 
    time(&current_time); /* get current time */
 
@@ -1981,7 +1988,7 @@ void get_http_time(int time_offset, char *buf)
    }
 
    /* Format: "Sun, 06 Nov 1994 08:49:37 GMT" */
-   snprintf(buf, 30,
+   snprintf(buf, buffer_size,
       "%s, %02d %s %4d %02d:%02d:%02d GMT",
       day_names[t->tm_wday],
       t->tm_mday,
@@ -2093,7 +2100,7 @@ struct http_response *finish_http_response(const struct client_state *csp, struc
 
       if (!err)
       {
-         get_http_time(0, buf);
+         get_http_time(0, buf, sizeof(buf));
          err = enlist_unique_header(rsp->headers, "Date", buf);
       }
 
@@ -2102,13 +2109,13 @@ struct http_response *finish_http_response(const struct client_state *csp, struc
 
       if (!err)
       {
-         get_http_time(10 * 60, buf); /* 10 * 60sec = 10 minutes */
+         get_http_time(10 * 60, buf, sizeof(buf)); /* 10 * 60sec = 10 minutes */
          err = enlist_unique_header(rsp->headers, "Expires", buf);
       }
    }
    else if (!strncmpic(rsp->status, "302", 3))
    {
-      get_http_time(0, buf);
+      get_http_time(0, buf, sizeof(buf));
       if (!err) err = enlist_unique_header(rsp->headers, "Date", buf);
    }
    else
@@ -2134,7 +2141,7 @@ struct http_response *finish_http_response(const struct client_state *csp, struc
        */
       if (!err) err = enlist_unique_header(rsp->headers, "Cache-Control", "no-cache");
 
-      get_http_time(0, buf);
+      get_http_time(0, buf, sizeof(buf));
       if (!err) err = enlist_unique_header(rsp->headers, "Date", buf);
       if (!strncmpic(rsp->status, "403", 3)
        || !strncmpic(rsp->status, "404", 3)
@@ -2242,7 +2249,7 @@ void free_http_response(struct http_response *rsp)
  *                JB_ERR_FILE if the template file cannot be read
  *
  *********************************************************************/
-jb_err template_load(struct client_state *csp, char **template_ptr, 
+jb_err template_load(const struct client_state *csp, char **template_ptr, 
                      const char *templatename, int recursive)
 {
    jb_err err;
@@ -2521,7 +2528,7 @@ jb_err template_fill(char **template_ptr, const struct map *exports)
  *                JB_ERR_MEMORY on out-of-memory error
  *
  *********************************************************************/
-jb_err template_fill_for_cgi(struct client_state *csp,
+jb_err template_fill_for_cgi(const struct client_state *csp,
                              const char *templatename,
                              struct map *exports,
                              struct http_response *rsp)