current cgisimple.c,1.136,1.137
Fabian Keil <[email protected]>
| Newsgroups | gmane.comp.web.privoxy.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/ijbswa/current
In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv16346
Modified Files:
cgisimple.c
Log Message:
Use a proper HTML form to change the state of client tags
It's semantically correct and results in actual buttons to press.
Index: cgisimple.c
===================================================================
RCS file: /cvsroot/ijbswa/current/cgisimple.c,v
retrieving revision 1.136
retrieving revision 1.137
diff -C2 -d -r1.136 -r1.137
*** cgisimple.c 17 Mar 2016 10:40:53 -0000 1.136
--- cgisimple.c 4 Apr 2016 10:51:45 -0000 1.137
***************
*** 278,281 ****
--- 278,324 ----
/*********************************************************************
*
+ * 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,
+ "<form method=\"GET\" action=\"show-client-tags\" style=\"display: inline\">\n"
+ " <input type=\"hidden\" name=\"tag\" value=\"%s\">\n"
+ " <input type=\"hidden\" name=\"toggle-state\" value=\"%u\">\n"
+ " <input type=\"hidden\" name=\"expires\" value=\"%u\">\n"
+ " <input type=\"submit\" value=\"%s\">\n"
+ "</form>", tag, toggle_state, !expires, button_name);
+ }
+
+ /*********************************************************************
+ *
* Function : cgi_show_client_tags
*
***************
*** 364,376 ****
if (!err) err = string_append(&client_tags, "</td><td>");
if (!err) err = string_append(&client_tags, tag_state == 1 ? "Enabled" : "Disabled");
! snprintf(buf, sizeof(buf),
! "</td><td><a href=\"/show-client-tags?tag=%s&toggle-state=%d&expires=0\">%s</a>",
! this_tag->name, !tag_state, tag_state == 1 ? "Disable" : "Enable");
if (!err) err = string_append(&client_tags, buf);
if (tag_state == 0)
{
! snprintf(buf, sizeof(buf), ". <a href=\"/show-client-tags?"
! "tag=%s&toggle-state=1&expires=1\">Enable temporarily</a>",
! this_tag->name);
if (!err) err = string_append(&client_tags, buf);
}
--- 407,416 ----
if (!err) err = string_append(&client_tags, "</td><td>");
if (!err) err = string_append(&client_tags, tag_state == 1 ? "Enabled" : "Disabled");
! if (!err) err = string_append(&client_tags, "</td><td>");
! 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)
{
! cgi_create_client_tag_form(buf, sizeof(buf), this_tag->name, !tag_state, 0);
if (!err) err = string_append(&client_tags, buf);
}
------------------------------------------------------------------------------