From: jongfoster <jongfoster@users.sourceforge.net> Date: Thu, 18 Apr 2002 19:21:09 +0000 (+0000) Subject: Added code to detect "conventional" action files, that start X-Git-Tag: v_3_0_branchpoint~284 X-Git-Url: http://www.privoxy.org/gitweb/@default-cgi@/faq/%22https:/@proxy-info-url@?a=commitdiff_plain;h=620830b9b2271493be8ad082ca22f72d804250bd;p=privoxy.git 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. --- diff --git a/cgiedit.c b/cgiedit.c index 923f19a5..3bb0e9da 100644 --- a/cgiedit.c +++ b/cgiedit.c @@ -1,4 +1,4 @@ -const char cgiedit_rcs[] = "$Id: cgiedit.c,v 1.29 2002/04/08 16:59:08 oes Exp $"; +const char cgiedit_rcs[] = "$Id: cgiedit.c,v 1.30 2002/04/10 13:38:35 oes Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/cgiedit.c,v $ @@ -42,6 +42,9 @@ const char cgiedit_rcs[] = "$Id: cgiedit.c,v 1.29 2002/04/08 16:59:08 oes Exp $" * * Revisions : * $Log: cgiedit.c,v $ + * 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 * @@ -2534,6 +2537,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) { @@ -2541,6 +2545,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); @@ -2557,8 +2563,76 @@ 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 */ + /* Load templates */ + err = template_load(csp, §ion_template, "edit-actions-list-section", 0); if (err) { @@ -2603,15 +2677,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); diff --git a/templates/edit-actions-list b/templates/edit-actions-list index 683a806b..1d3121dd 100644 --- a/templates/edit-actions-list +++ b/templates/edit-actions-list @@ -31,6 +31,9 @@ # # Revisions : # $Log: edit-actions-list,v $ +# Revision 1.17 2002/04/10 13:32:53 oes +# Made templates modular +# # Revision 1.16 2002/04/08 17:08:14 oes # Cosmetic: make status in title lowercase # @@ -240,11 +243,55 @@ function rm_p(pattern,curtext) <td class="box"> <div class="buttons"> <h2>Editing Actions File</h2> + <!-- @if-all-urls-present-then@@else-not-all-urls-present@ --> <p><a class="cmd" href="edit-actions-section-add?f=@f@&v=@v@&s=0">Insert new section at top</a></p> + <!-- @endif-all-urls-present@ --> </div> </td> </tr> + <!-- @if-all-urls-present-then@ --> + <tr> + <td class="container"> + <div class="buttons"> +<table border="0" width="100%" cellspacing="0" cellpadding="3" class="framed"> +<tr class="actions" valign="top"> + <td class="header" align="right">Actions:</td> + <td align="center"><a name="l@s@" href="eas?f=@f@&v=@v@&s=@all-urls-s@">Edit</a></td> + <td class="action" align="left">@all-urls-actions@</td> +</tr> +<tr class="rule"> + <td colspan="3"><img src="t" width="2" height="1" alt="----"></td> +</tr> +<tr class="url1" valign="top"> + <td class="header" align="right">URLs:</td> + <td align="center"> </td> + <td align="left"><b>These actions affect all URLs</b></td> +</tr> +<tr class="rule"> + <td colspan="3"><img src="t" width="2" height="1" alt="-"></td> +</tr> +<tr class="adv" valign="top"> + <td class="header" align="right"><b>Advanced:</b></td> + <td colspan="2"> + <table border="0" cellspacing="0" cellpadding="4"> + <tr valign="middle" align="center"> + <td class="nbr"> </td> + <td class="nbr"> <a href="easa?f=@f@&v=@v@&s=@all-urls-s@#l@all-urls-s-next@">Insert new section below</a> </td> + </tr> + <tr valign="middle" align="center"> + <td class="nbr"> </td> + <td class="nbr"> </td> + </tr> + </table> + </td> +</tr> +</table> +</div> + </td> + </tr> + <!-- @else-not-all-urls-present@@endif-all-urls-present@ --> + <tr> <td class="container"> <div class="buttons">@sections@</div>