Adding winehq to prevent-compression from bug report #764609
[privoxy.git] / cgiedit.c
index 0f0e46d..0477211 100644 (file)
--- a/cgiedit.c
+++ b/cgiedit.c
@@ -1,7 +1,7 @@
-const char cgiedit_rcs[] = "$Id: cgiedit.c,v 1.40 2002/05/19 11:34:35 jongfoster Exp $";
+const char cgiedit_rcs[] = "$Id: cgiedit.c,v 1.41.2.3 2002/11/12 15:01:41 oes Exp $";
 /*********************************************************************
  *
- * File        :  $Source: /cvsroot/ijbswa/current/cgiedit.c,v $
+ * File        :  $Source: /cvsroot/ijbswa/current/Attic/cgiedit.c,v $
  *
  * Purpose     :  CGI-based actionsfile editor.
  *
@@ -42,6 +42,20 @@ const char cgiedit_rcs[] = "$Id: cgiedit.c,v 1.40 2002/05/19 11:34:35 jongfoster
  *
  * Revisions   :
  *    $Log: cgiedit.c,v $
+ *    Revision 1.41.2.3  2002/11/12 15:01:41  oes
+ *    Fix: Don't free uninitialized struct editable_file
+ *
+ *    Revision 1.41.2.2  2002/08/05 20:02:59  oes
+ *    Bugfix: "Insert new section at top" did not work properly if first non-comment line in file was of type FILE_LINE_ACTION
+ *
+ *    Revision 1.41.2.1  2002/08/02 12:43:14  oes
+ *    Fixed bug #588514: first_time now set on a per-string basis in actions_from_radio; javascriptify now called on copies
+ *
+ *    Revision 1.41  2002/05/21 19:09:45  oes
+ *     - Made Add/Edit/Remove URL Submit and Cancel
+ *       buttons jump back to relevant section in eal
+ *     - Bugfix: remove-url-form needs p export
+ *
  *    Revision 1.40  2002/05/19 11:34:35  jongfoster
  *    Handling read-only actions files better - report the actual
  *    error, not "Out of memory"!
@@ -281,7 +295,7 @@ const char cgiedit_rcs[] = "$Id: cgiedit.c,v 1.40 2002/05/19 11:34:35 jongfoster
 #include "errlog.h"
 #include "loaders.h"
 #include "loadcfg.h"
-/* loadcfg.h is for g_bToggleIJB only */
+/* loadcfg.h is for global_toggle_state only */
 #include "urlmatch.h"
 
 const char cgiedit_h_rcs[] = CGIEDIT_H_VERSION;
@@ -2510,7 +2524,6 @@ jb_err cgi_edit_actions_list(struct client_state *csp,
 
    if (NULL == (exports = default_exports(csp, NULL)))
    {
-      edit_free_file(file);
       return JB_ERR_MEMORY;
    }
 
@@ -2872,12 +2885,13 @@ jb_err cgi_edit_actions_list(struct client_state *csp,
 
       /* Could also do section-specific exports here, but it wouldn't be as fast */
 
+      snprintf(buf, 150, "%d", line_number);
+      if (!err) err = map(section_exports, "s-next", 1, buf, 1);
+
       if ( (cur_line != NULL)
         && (cur_line->type == FILE_LINE_ACTION))
       {
          /* Not last section */
-         snprintf(buf, 150, "%d", line_number);
-         if (!err) err = map(section_exports, "s-next", 1, buf, 1);
          if (!err) err = map_block_keep(section_exports, "s-next-exists");
       }
       else
@@ -3994,10 +4008,10 @@ jb_err cgi_edit_actions_section_add(struct client_state *csp,
    line_number = 1;
    cur_line = file->lines;
 
-   if (sectionid < 1U)
+   if (sectionid <= 1U)
    {
       /* Add to start of file */
-      if (cur_line != NULL)
+      if (cur_line != NULL && cur_line->type != FILE_LINE_ACTION)
       {
          /* There's something in the file, find the line before the first
           * action.
@@ -4009,6 +4023,11 @@ jb_err cgi_edit_actions_section_add(struct client_state *csp,
             line_number++;
          }
       }
+      else
+      {
+         /* File starts with action line, so insert at top */
+         cur_line = NULL;
+      }
    }
    else
    {
@@ -4362,17 +4381,17 @@ jb_err cgi_toggle(struct client_state *csp,
    if (mode == 'E')
    {
       /* Enable */
-      g_bToggleIJB = 1;
+      global_toggle_state = 1;
    }
    else if (mode == 'D')
    {
       /* Disable */
-      g_bToggleIJB = 0;
+      global_toggle_state = 0;
    }
    else if (mode == 'T')
    {
       /* Toggle */
-      g_bToggleIJB = !g_bToggleIJB;
+      global_toggle_state = !global_toggle_state;
    }
 
    if (NULL == (exports = default_exports(csp, "toggle")))
@@ -4575,7 +4594,6 @@ static jb_err actions_to_radio(struct map * exports,
 static jb_err actions_from_radio(const struct map * parameters,
                                  struct action_spec *action)
 {
-   static int first_time = 1;
    const char * param;
    char * param_dup;
    char ch;
@@ -4589,16 +4607,22 @@ static jb_err actions_from_radio(const struct map * parameters,
     * but in this case we're safe and don't need semaphores.
     * Be careful if you modify this function.
     * - Jon
+    * The js_name_arr's are never free()d, but this is no
+    * problem, since they will only be created once and
+    * used by all threads thereafter. -oes
     */
 
 #define JAVASCRIPTIFY(dest_var, string)               \
    {                                                  \
-      static char js_name_arr[] = string;             \
+     static int first_time = 1;                       \
+     static char *js_name_arr;                        \
       if (first_time)                                 \
       {                                               \
+         js_name_arr = strdup(string);                \
          javascriptify(js_name_arr);                  \
       }                                               \
       dest_var = js_name_arr;                         \
+      first_time = 0;                                 \
    }                                                  \
 
 #define DEFINE_ACTION_BOOL(name, bit)                 \
@@ -4694,8 +4718,6 @@ static jb_err actions_from_radio(const struct map * parameters,
 #undef DEFINE_ACTION_ALIAS
 #undef JAVASCRIPTIFY
 
-   first_time = 0;
-
    return err;
 }