X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=blobdiff_plain;f=cgiedit.c;h=2de990736517e639c517cee3ca4299d836b067bc;hp=85f258603bd149968de68ac46740f58176f47975;hb=7ee754dbd6237cdb224bc9cf5876c9dd6aa0be87;hpb=b3ee70e4ee07171ad5cc5050748d53db7228f232 diff --git a/cgiedit.c b/cgiedit.c index 85f25860..2de99073 100644 --- a/cgiedit.c +++ b/cgiedit.c @@ -1,4 +1,4 @@ -const char cgiedit_rcs[] = "$Id: cgiedit.c,v 1.21 2002/03/22 18:02:48 jongfoster Exp $"; +const char cgiedit_rcs[] = "$Id: cgiedit.c,v 1.31 2002/04/18 19:21:08 jongfoster Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/cgiedit.c,v $ @@ -16,7 +16,7 @@ const char cgiedit_rcs[] = "$Id: cgiedit.c,v 1.21 2002/03/22 18:02:48 jongfoster * Stick to the short names in this file for consistency. * * Copyright : Written by and Copyright (C) 2001 the SourceForge - * Privoxy team. http://ijbswa.sourceforge.net + * Privoxy team. http://www.privoxy.org/ * * Based on the Internet Junkbuster originally written * by and Copyright (C) 1997 Anonymous Coders and @@ -42,6 +42,39 @@ const char cgiedit_rcs[] = "$Id: cgiedit.c,v 1.21 2002/03/22 18:02:48 jongfoster * * Revisions : * $Log: cgiedit.c,v $ + * Revision 1.31 2002/04/18 19:21:08 jongfoster + * Added code to detect "conventional" action files, that start + * with a set of actions for all URLs (the pattern "/"). + * These are special-cased in the "edit-actions-list" CGI, so + * that a special UI can be written for them. + * + * Revision 1.30 2002/04/10 13:38:35 oes + * load_template signature changed + * + * Revision 1.29 2002/04/08 16:59:08 oes + * Fixed comment + * + * Revision 1.28 2002/03/27 12:30:29 oes + * Deleted unsused variable + * + * Revision 1.27 2002/03/26 23:06:04 jongfoster + * Removing duplicate @ifs on the toggle page + * + * Revision 1.26 2002/03/26 22:59:17 jongfoster + * Fixing /toggle to display status consistently. + * + * Revision 1.25 2002/03/26 22:29:54 swa + * we have a new homepage! + * + * Revision 1.24 2002/03/24 15:23:33 jongfoster + * Name changes + * + * Revision 1.23 2002/03/24 13:32:41 swa + * name change related issues + * + * Revision 1.22 2002/03/24 13:25:43 swa + * name change related issues + * * Revision 1.21 2002/03/22 18:02:48 jongfoster * Fixing remote toggle * @@ -263,7 +296,7 @@ struct file_line struct editable_file { struct file_line * lines; - const char * filename; /* Full pathname - e.g. "/etc/junkbuster/wibble.action" */ + const char * filename; /* Full pathname - e.g. "/etc/privoxy/wibble.action" */ const char * identifier; /* Filename stub - e.g. "wibble". Use for CGI param. */ /* Pre-encoded with url_encode() for ease of use. */ const char * version_str; /* Last modification time, as a string. For CGI param */ @@ -740,11 +773,7 @@ jb_err edit_write_file(struct editable_file * file) assert(file); assert(file->filename); -#if defined(AMIGA) || defined(__OS2__) - if (NULL == (fp = fopen(file->filename, "w"))) -#else - if (NULL == (fp = fopen(file->filename, "wt"))) -#endif /* def AMIGA */ + if (NULL == (fp = fopen(file->filename, "wb"))) { return JB_ERR_FILE; } @@ -1571,11 +1600,7 @@ jb_err edit_read_file(struct client_state *csp, } } -#if defined(AMIGA) || defined(__OS2__) - if (NULL == (fp = fopen(filename,"r"))) -#else - if (NULL == (fp = fopen(filename,"rt"))) -#endif /* def AMIGA */ + if (NULL == (fp = fopen(filename,"rb"))) { free(filename); return JB_ERR_FILE; @@ -2385,10 +2410,10 @@ jb_err cgi_error_file(struct client_state *csp, /********************************************************************* * - * Function : cgi_error_bad_param + * Function : cgi_error_disabled * - * Description : CGI function that is called if the parameters - * (query string) for a CGI were wrong. + * Description : CGI function that is called if the actions editor + * is called although it's disabled in config * * Parameters : * 1 : csp = Current client state (buffers, headers, etc...) @@ -2446,13 +2471,13 @@ jb_err cgi_edit_actions(struct client_state *csp, } /* FIXME: Incomplete */ - rsp->status = strdup("302 Local Redirect from Junkbuster"); + rsp->status = strdup("302 Local Redirect from Privoxy"); if (rsp->status == NULL) { return JB_ERR_MEMORY; } if (enlist_unique_header(rsp->headers, "Location", - CGI_PREFIX "edit-actions-list?f=ijb")) + CGI_PREFIX "edit-actions-list?f=default")) { free(rsp->status); rsp->status = NULL; @@ -2510,6 +2535,7 @@ jb_err cgi_edit_actions_list(struct client_state *csp, return cgi_error_disabled(csp, rsp); } + /* Load actions file */ err = edit_read_actions_file(csp, rsp, parameters, 0, &file); if (err) { @@ -2517,6 +2543,8 @@ jb_err cgi_edit_actions_list(struct client_state *csp, return (err == JB_ERR_FILE ? JB_ERR_OK : err); } + /* Set up global exports */ + if (NULL == (exports = default_exports(csp, NULL))) { edit_free_file(file); @@ -2533,9 +2561,77 @@ jb_err cgi_edit_actions_list(struct client_state *csp, return err; } + /* Find start of actions in file */ + cur_line = file->lines; + line_number = 1; + while ((cur_line != NULL) && (cur_line->type != FILE_LINE_ACTION)) + { + cur_line = cur_line->next; + line_number++; + } + + /* + * Conventional actions files should have a match all block + * at the start: + * cur_line = {...global actions...} + * cur_line->next = / + * cur_line->next->next = {...actions...} or EOF + */ + if ( (cur_line != NULL) + && (cur_line->type == FILE_LINE_ACTION) + && (cur_line->next != NULL) + && (cur_line->next->type == FILE_LINE_URL) + && (0 == strcmp(cur_line->next->unprocessed, "/")) + && ( (cur_line->next->next == NULL) + || (cur_line->next->next->type != FILE_LINE_URL) + ) ) + { + /* + * Conventional actions file, supply extra editing help. + * (e.g. don't allow them to make it an unconventional one). + */ + err = map_conditional(exports, "all-urls-present", 1); + + snprintf(buf, 50, "%d", line_number); + if (!err) err = map(exports, "all-urls-s", 1, buf, 1); + snprintf(buf, 50, "%d", line_number + 2); + if (!err) err = map(exports, "all-urls-s-next", 1, buf, 1); + if (!err) err = map(exports, "all-urls-actions", 1, + actions_to_html(cur_line->data.action), 0); + + /* Skip the 2 lines */ + cur_line = cur_line->next->next; + line_number += 2; + + /* + * Note that prev_section_line_number is NOT set here. + * This is deliberate and not a bug. It stops a "Move up" + * option appearing on the next section. Clicking "Move + * up" would make the actions file unconventional, which + * we don't want, so we hide this option. + */ + } + else + { + /* + * Non-standard actions file - does not begin with + * the "All URLs" section. + */ + err = map_conditional(exports, "all-urls-present", 0); + } + + if (err) + { + edit_free_file(file); + free_map(exports); + return err; + } + /* Should do all global exports above this point */ - err = template_load(csp, §ion_template, "edit-actions-list-section"); + /* Load templates */ + + err = template_load(csp, §ion_template, "edit-actions-list-section", 0); if (err) { edit_free_file(file); @@ -2547,7 +2643,7 @@ jb_err cgi_edit_actions_list(struct client_state *csp, return err; } - err = template_load(csp, &url_template, "edit-actions-list-url"); + err = template_load(csp, &url_template, "edit-actions-list-url", 0); if (err) { free(section_template); @@ -2579,15 +2675,6 @@ jb_err cgi_edit_actions_list(struct client_state *csp, return err; } - /* Find start of actions in file */ - cur_line = file->lines; - line_number = 1; - while ((cur_line != NULL) && (cur_line->type != FILE_LINE_ACTION)) - { - cur_line = cur_line->next; - line_number++; - } - if (NULL == (sections = strdup(""))) { free(section_template); @@ -2921,7 +3008,7 @@ jb_err cgi_edit_actions_for_url(struct client_state *csp, int index = 0; char * filter_template; - err = template_load(csp, &filter_template, "edit-actions-for-url-filter"); + err = template_load(csp, &filter_template, "edit-actions-for-url-filter", 0); if (err) { edit_free_file(file); @@ -3218,7 +3305,7 @@ jb_err cgi_edit_actions_submit(struct client_state *csp, return JB_ERR_MEMORY; } - rsp->status = strdup("302 Local Redirect from Junkbuster"); + rsp->status = strdup("302 Local Redirect from Privoxy"); if (rsp->status == NULL) { free(target); @@ -3340,7 +3427,7 @@ jb_err cgi_edit_actions_url(struct client_state *csp, return JB_ERR_MEMORY; } - rsp->status = strdup("302 Local Redirect from Junkbuster"); + rsp->status = strdup("302 Local Redirect from Privoxy"); if (rsp->status == NULL) { free(target); @@ -3479,7 +3566,7 @@ jb_err cgi_edit_actions_add_url(struct client_state *csp, return JB_ERR_MEMORY; } - rsp->status = strdup("302 Local Redirect from Junkbuster"); + rsp->status = strdup("302 Local Redirect from Privoxy"); if (rsp->status == NULL) { free(target); @@ -3595,7 +3682,7 @@ jb_err cgi_edit_actions_remove_url(struct client_state *csp, return JB_ERR_MEMORY; } - rsp->status = strdup("302 Local Redirect from Junkbuster"); + rsp->status = strdup("302 Local Redirect from Privoxy"); if (rsp->status == NULL) { free(target); @@ -3727,7 +3814,7 @@ jb_err cgi_edit_actions_section_remove(struct client_state *csp, return JB_ERR_MEMORY; } - rsp->status = strdup("302 Local Redirect from Junkbuster"); + rsp->status = strdup("302 Local Redirect from Privoxy"); if (rsp->status == NULL) { free(target); @@ -3901,7 +3988,7 @@ jb_err cgi_edit_actions_section_add(struct client_state *csp, return JB_ERR_MEMORY; } - rsp->status = strdup("302 Local Redirect from Junkbuster"); + rsp->status = strdup("302 Local Redirect from Privoxy"); if (rsp->status == NULL) { free(target); @@ -4100,7 +4187,7 @@ jb_err cgi_edit_actions_section_swap(struct client_state *csp, return JB_ERR_MEMORY; } - rsp->status = strdup("302 Local Redirect from Junkbuster"); + rsp->status = strdup("302 Local Redirect from Privoxy"); if (rsp->status == NULL) { free(target); @@ -4141,7 +4228,6 @@ jb_err cgi_toggle(struct client_state *csp, struct map *exports; char mode; const char *template_name; - jb_err err; assert(csp); assert(rsp); @@ -4152,11 +4238,6 @@ jb_err cgi_toggle(struct client_state *csp, return cgi_error_disabled(csp, rsp); } - if (NULL == (exports = default_exports(csp, "toggle"))) - { - return JB_ERR_MEMORY; - } - mode = get_char_param(parameters, "set"); if (mode == 'E') @@ -4175,11 +4256,9 @@ jb_err cgi_toggle(struct client_state *csp, g_bToggleIJB = !g_bToggleIJB; } - err = map_conditional(exports, "enabled", g_bToggleIJB); - if (err) + if (NULL == (exports = default_exports(csp, "toggle"))) { - free_map(exports); - return err; + return JB_ERR_MEMORY; } template_name = (get_char_param(parameters, "mini")