From: Fabian Keil Date: Mon, 4 Apr 2016 10:51:45 +0000 (+0000) Subject: Use a proper HTML form to change the state of client tags X-Git-Tag: v_3_0_25~85 X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=commitdiff_plain;h=ee8ba350d2365a7c464c4de364a7c2bdf6ddcd16 Use a proper HTML form to change the state of client tags It's semantically correct and results in actual buttons to press. --- diff --git a/cgisimple.c b/cgisimple.c index faa70da8..c9aa66a7 100644 --- a/cgisimple.c +++ b/cgisimple.c @@ -1,4 +1,4 @@ -const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.135 2016/03/04 13:22:22 fabiankeil Exp $"; +const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.136 2016/03/17 10:40:53 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/cgisimple.c,v $ @@ -275,6 +275,49 @@ jb_err cgi_show_request(struct client_state *csp, #ifdef FEATURE_CLIENT_TAGS +/********************************************************************* + * + * Function : cgi_create_client_tag_form + * + * Description : Creates a HTML form to enable or disable a given + * client tag. + * XXX: Could use a template. + * + * Parameters : + * 1 : form = Buffer to fill with the generated form + * 2 : size = Size of the form buffer + * 3 : tag = Name of the tag this form should affect + * 4 : toggle_state = Desired state after the button pressed 0 + * 5 : expires = Whether or not the tag should be enabled. + * Only checked if toggle_state is 1. + * + * Returns : void + * + *********************************************************************/ +static void cgi_create_client_tag_form(char *form, size_t size, + const char *tag, int toggle_state, int expires) +{ + char *button_name; + + if (toggle_state == 1) + { + button_name = (expires == 1) ? "Enable" : "Enable temporarily"; + } + else + { + assert(toggle_state == 0); + button_name = "Disable"; + } + + snprintf(form, size, + "
\n" + " \n" + " \n" + " \n" + " \n" + "
", tag, toggle_state, !expires, button_name); +} + /********************************************************************* * * Function : cgi_show_client_tags @@ -363,15 +406,12 @@ jb_err cgi_show_client_tags(struct client_state *csp, if (!err) err = string_append(&client_tags, this_tag->name); if (!err) err = string_append(&client_tags, ""); if (!err) err = string_append(&client_tags, tag_state == 1 ? "Enabled" : "Disabled"); - snprintf(buf, sizeof(buf), - "%s", - this_tag->name, !tag_state, tag_state == 1 ? "Disable" : "Enable"); + if (!err) err = string_append(&client_tags, ""); + cgi_create_client_tag_form(buf, sizeof(buf), this_tag->name, !tag_state, 1); if (!err) err = string_append(&client_tags, buf); if (tag_state == 0) { - snprintf(buf, sizeof(buf), ". Enable temporarily", - this_tag->name); + cgi_create_client_tag_form(buf, sizeof(buf), this_tag->name, !tag_state, 0); if (!err) err = string_append(&client_tags, buf); } if (!err) err = string_append(&client_tags, "");