- Map variables that aren't guaranteed to be
[privoxy.git] / cgisimple.c
index 9504ef9..b82dbde 100644 (file)
@@ -1,4 +1,4 @@
-const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.45 2006/12/28 18:16:41 fabiankeil Exp $";
+const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.48 2007/01/20 15:31:31 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/cgisimple.c,v $
@@ -9,7 +9,7 @@ const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.45 2006/12/28 18:16:41 fabian
  *                Functions declared include:
  * 
  *
- * Copyright   :  Written by and Copyright (C) 2001-2006 the SourceForge
+ * Copyright   :  Written by and Copyright (C) 2001-2007 the SourceForge
  *                Privoxy team. http://www.privoxy.org/
  *
  *                Based on the Internet Junkbuster originally written
@@ -36,6 +36,17 @@ const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.45 2006/12/28 18:16:41 fabian
  *
  * Revisions   :
  *    $Log: cgisimple.c,v $
+ *    Revision 1.48  2007/01/20 15:31:31  fabiankeil
+ *    Display warning if show-url-info CGI page
+ *    is used while Privoxy is toggled off.
+ *
+ *    Revision 1.47  2007/01/12 15:07:10  fabiankeil
+ *    Use zalloc in cgi_send_user_manual.
+ *
+ *    Revision 1.46  2007/01/02 12:49:46  fabiankeil
+ *    Add FEATURE_ZLIB to the list of conditional
+ *    defines at the show-status page.
+ *
  *    Revision 1.45  2006/12/28 18:16:41  fabiankeil
  *    Fixed gcc43 compiler warnings, zero out cgi_send_user_manual's
  *    body memory before using it, replaced sprintf calls with snprintf.
@@ -274,6 +285,10 @@ const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.45 2006/12/28 18:16:41 fabian
 #include <string.h>
 #include <assert.h>
 
+#ifdef HAVE_ACCESS
+#include <unistd.h>
+#endif /* def HAVE_ACCESS */
+
 #ifdef _WIN32
 #define snprintf _snprintf
 #endif /* def _WIN32 */
@@ -788,14 +803,13 @@ jb_err cgi_send_user_manual(struct client_state *csp,
    fseek(fp, 0, SEEK_SET);
 
    /* Allocate memory and load the file directly into the body */
-   rsp->body = (char *)malloc(length+1);
+   rsp->body = (char *)zalloc(length+1);
    if (!rsp->body)
    {
       fclose(fp);
       free(full_path);
       return JB_ERR_MEMORY;
    }
-   memset(rsp->body, '\0', length+1);
    if (!fread(rsp->body, length, 1, fp))
    {
       /*
@@ -1072,8 +1086,20 @@ jb_err cgi_show_status(struct client_state *csp,
 #ifdef FEATURE_CGI_EDIT_ACTIONS
          if (NULL == strstr(csp->actions_list[i]->filename, "standard.action") && NULL != csp->config->actions_file_short[i])
          {
-            snprintf(buf, 100, "&nbsp;&nbsp;<a href=\"/edit-actions-list?f=%s\">Edit</a>", csp->config->actions_file_short[i]);
-            if (!err) err = string_append(&s, buf);
+#ifdef HAVE_ACCESS
+            if (access(csp->config->actions_file[i], W_OK) == 0)
+            {
+#endif /* def HAVE_ACCESS */
+               snprintf(buf, 100, "&nbsp;&nbsp;<a href=\"/edit-actions-list?f=%s\">Edit</a>",
+                  csp->config->actions_file_short[i]);
+               if (!err) err = string_append(&s, buf);
+#ifdef HAVE_ACCESS
+            }
+            else
+            {
+               if (!err) err = string_append(&s, "&nbsp;&nbsp;<strong>No write access.</strong>");
+            }
+#endif /* def HAVE_ACCESS */
          }
 #endif
 
@@ -1241,6 +1267,19 @@ jb_err cgi_show_url_info(struct client_state *csp,
       url_param = url_param_prefixed;
    }
 
+   /*
+    * Hide "toggle off" warning if Privoxy is toggled on.
+    */
+   if (
+#ifdef FEATURE_TOGGLE
+       (global_toggle_state == 1) &&
+#endif /* def FEATURE_TOGGLE */
+       map_block_killer(exports, "privoxy-is-toggled-off")
+      )
+   {
+      free_map(exports);
+      return JB_ERR_MEMORY;
+   }
 
    if (url_param[0] == '\0')
    {