Show FEATURE_COMPRESSION on the show-status page
[privoxy.git] / cgisimple.c
index 7a4e03e..3ab3428 100644 (file)
@@ -1,4 +1,4 @@
-const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.102 2011/02/14 16:05:37 fabiankeil Exp $";
+const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.109 2011/04/19 13:00:47 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/cgisimple.c,v $
@@ -181,6 +181,20 @@ jb_err cgi_die (struct client_state *csp,
                 struct http_response *rsp,
                 const struct map *parameters)
 {
+   static const char status[] = "200 OK Privoxy shutdown request received";
+   static const char body[] =
+      "<html>\n"
+      "<head>\n"
+      " <title>Privoxy shutdown request received</title>\n"
+      " <link rel=\"shortcut icon\" href=\"" CGI_PREFIX "error-favicon.ico\" type=\"image/x-icon\">\n"
+      " <link rel=\"stylesheet\" type=\"text/css\" href=\"http://config.privoxy.org/send-stylesheet\">\n"
+      "</head>\n"
+      "<body>\n"
+      "<h1>Privoxy shutdown request received</h1>\n"
+      "<p>Privoxy is going to shut down after the next request.</p>\n"
+      "</body>\n"
+      "</html>\n";
+
    assert(csp);
    assert(rsp);
    assert(parameters);
@@ -188,12 +202,21 @@ jb_err cgi_die (struct client_state *csp,
    /* quit */
    g_terminate = 1;
 
-   /*
-    * I don't really care what gets sent back to the browser.
-    * Take the easy option - "out of memory" page.
-    */
+   csp->flags &= ~CSP_FLAG_CLIENT_CONNECTION_KEEP_ALIVE;
+
+   rsp->content_length = 0;
+   rsp->head_length = 0;
+   rsp->is_static = 0;
+
+   rsp->body = strdup(body);
+   rsp->status = strdup(status);
+
+   if ((rsp->body == NULL) || (rsp->status == NULL))
+   {
+      return JB_ERR_MEMORY;
+   }
 
-   return JB_ERR_MEMORY;
+   return JB_ERR_OK;
 }
 #endif /* def FEATURE_GRACEFUL_TERMINATION */
 
@@ -684,6 +707,8 @@ static const char *get_content_type(const char *filename)
    {
       {".css",  "text/css"},
       {".jpg",  "image/jpeg"},
+      {".jpeg", "image/jpeg"},
+      {".png",  "image/png"},
    };
 
    for (i = 0; i < SZ(content_types); i++)
@@ -721,9 +746,10 @@ jb_err cgi_send_user_manual(struct client_state *csp,
                             struct http_response *rsp,
                             const struct map *parameters)
 {
-   const char * filename;
+   const char *filename;
    char *full_path;
    jb_err err = JB_ERR_OK;
+   const char *content_type;
 
    assert(csp);
    assert(rsp);
@@ -752,7 +778,7 @@ jb_err cgi_send_user_manual(struct client_state *csp,
    {
       /*
        * We currently only support a flat file
-       * hierachy for the documentation.
+       * hierarchy for the documentation.
        */
       log_error(LOG_LEVEL_ERROR,
          "Rejecting the request to serve '%s' as it contains '/' or '..'",
@@ -779,20 +805,12 @@ jb_err cgi_send_user_manual(struct client_state *csp,
    }
    freez(full_path);
 
-   /* Guess correct Content-Type based on the filename's ending */
-   if (filename)
-   {
-      const char *content_type = get_content_type(filename);
-      log_error(LOG_LEVEL_CGI,
-         "Content-Type guessed for %s: %s", filename, content_type);
-      err = enlist_unique_header(rsp->headers, "Content-Type", content_type);
-   }
-   else
-   {
-      /* XXX: why should this happen */
-   } 
+   content_type = get_content_type(filename);
+   log_error(LOG_LEVEL_CGI,
+      "Content-Type guessed for %s: %s", filename, content_type);
+
+   return enlist_unique_header(rsp->headers, "Content-Type", content_type);
 
-   return err;
 }
 
 
@@ -1558,6 +1576,12 @@ static jb_err show_defines(struct map *exports)
    if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 0);
 #endif /* ndef FEATURE_CGI_EDIT_ACTIONS */
 
+#ifdef FEATURE_COMPRESSION
+   if (!err) err = map_conditional(exports, "FEATURE_COMPRESSION", 1);
+#else /* ifndef FEATURE_COMPRESSION */
+   if (!err) err = map_conditional(exports, "FEATURE_COMPRESSION", 0);
+#endif /* ndef FEATURE_COMPRESSION */
+
 #ifdef FEATURE_CONNECTION_KEEP_ALIVE
    if (!err) err = map_conditional(exports, "FEATURE_CONNECTION_KEEP_ALIVE", 1);
 #else /* ifndef FEATURE_CONNECTION_KEEP_ALIVE */