From a78616318e30fa48a06b1b8b7c07cb2b8b8d5222 Mon Sep 17 00:00:00 2001 From: jongfoster Date: Fri, 3 May 2002 23:00:38 +0000 Subject: [PATCH] Support for templates for "standard actions" buttons. See bug #549871 --- cgiedit.c | 64 +++++++++++++++++++++++++----- templates/edit-actions-list-button | 37 +++++++++++++++++ 2 files changed, 91 insertions(+), 10 deletions(-) create mode 100644 templates/edit-actions-list-button diff --git a/cgiedit.c b/cgiedit.c index 1547518f..87b3cb5a 100644 --- a/cgiedit.c +++ b/cgiedit.c @@ -1,4 +1,4 @@ -const char cgiedit_rcs[] = "$Id: cgiedit.c,v 1.36 2002/04/26 21:53:30 jongfoster Exp $"; +const char cgiedit_rcs[] = "$Id: cgiedit.c,v 1.37 2002/04/30 11:14:52 oes Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/cgiedit.c,v $ @@ -42,6 +42,9 @@ const char cgiedit_rcs[] = "$Id: cgiedit.c,v 1.36 2002/04/26 21:53:30 jongfoster * * Revisions : * $Log: cgiedit.c,v $ + * Revision 1.37 2002/04/30 11:14:52 oes + * Made csp the first parameter in *action_to_html + * * Revision 1.36 2002/04/26 21:53:30 jongfoster * Fixing a memory leak. (Near, but not caused by, my earlier commit). * @@ -2393,12 +2396,31 @@ jb_err cgi_edit_actions_list(struct client_state *csp, { /* * Generate string with buttons to set actions for "/" to - * any predefined set of actions (named standard.*, propably + * any predefined set of actions (named standard.*, probably * residing in standard.action). - * FIXME: Shouldn't include hardwired HTML here, use line template instead! */ - buttons = strdup(" "); + err = template_load(csp, §ion_template, "edit-actions-list-button", 0); + if (err) + { + edit_free_file(file); + free_map(exports); + if (err == JB_ERR_FILE) + { + return cgi_error_no_template(csp, rsp, "edit-actions-list-button"); + } + return err; + } + + err = template_fill(§ion_template, exports); + if (err) + { + edit_free_file(file); + free_map(exports); + return err; + } + + buttons = strdup(""); for (i = 0; i < MAX_ACTION_FILES; i++) { if (((fl = csp->actions_list[i]) != NULL) && ((b = fl->f) != NULL)) @@ -2407,20 +2429,42 @@ jb_err cgi_edit_actions_list(struct client_state *csp, { if (!strncmp(b->url->spec, "standard.", 9) && *(b->url->spec + 9) != '\0') { - snprintf(buf, 150, "

Set" - " to %s

", b->url->spec + 9, b->url->spec + 9); - if (!err) err = string_append(&buttons, buf); + if (err || (NULL == (section_exports = new_map()))) + { + freez(buttons); + free(section_template); + edit_free_file(file); + free_map(exports); + return JB_ERR_MEMORY; + } + + err = map(section_exports, "button-name", 1, b->url->spec + 9, 1); + + if (err || (NULL == (s = strdup(section_template)))) + { + free_map(section_exports); + freez(buttons); + free(section_template); + edit_free_file(file); + free_map(exports); + return JB_ERR_MEMORY; + } + + if (!err) err = template_fill(&s, section_exports); + free_map(section_exports); + if (!err) err = string_join(&buttons, s); } } } } + freez(section_template); if (!err) err = map(exports, "all-urls-buttons", 1, buttons, 0); /* * 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); + if (!err) err = map_conditional(exports, "all-urls-present", 1); snprintf(buf, 150, "%d", line_number); if (!err) err = map(exports, "all-urls-s", 1, buf, 1); @@ -2447,12 +2491,12 @@ jb_err cgi_edit_actions_list(struct client_state *csp, * Non-standard actions file - does not begin with * the "All URLs" section. */ - err = map_conditional(exports, "all-urls-present", 0); + if (!err) err = map_conditional(exports, "all-urls-present", 0); } /* Set up global exports */ - err = map(exports, "f", 1, file->identifier, 1); + if (!err) err = map(exports, "f", 1, file->identifier, 1); if (!err) err = map(exports, "v", 1, file->version_str, 1); /* Discourage private additions to default.action */ diff --git a/templates/edit-actions-list-button b/templates/edit-actions-list-button new file mode 100644 index 00000000..1b130d42 --- /dev/null +++ b/templates/edit-actions-list-button @@ -0,0 +1,37 @@ +############################################################################## +# +# File : $Source: /cvsroot/ijbswa/current/templates/edit-actions-list-url,v $ +# +# Purpose : Template which forms part of edit-actions-list +# +# +# Copyright : Written by and Copyright (C) 2001 the SourceForge +# Privoxy team. http://www.privoxy.org/ +# +# Original Author: Copyright (C) 2001 Jonathan Foster +# http://www.jon-foster.co.uk/ +# +# This program is free software; you can redistribute it +# and/or modify it under the terms of the GNU General +# Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will +# be useful, but WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public +# License for more details. +# +# The GNU General Public License should be included with +# this file. If not, you can view it at +# http://www.gnu.org/copyleft/gpl.html +# or write to the Free Software Foundation, Inc., 59 +# Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +# Revisions : +# $Log: edit-actions-list-url,v $ +# +############################################################################# +

Set to @button-name@

+ -- 2.39.2