+/*********************************************************************
+ *
+ * Function : cgi_edit_process_string_action
+ *
+ * Description : Helper CGI function that actually edits the Actions list for
+ * the action string parameters.
+ *
+ * Parameters :
+ * 1 : csp = Current client state (buffers, headers, etc...)
+ * 2 : rsp = http_response data structure for output
+ * 3 : parameters = map of cgi parameters
+ * 4 : cur_line = current config file line
+ * 5 : action_type = string filter type to process
+ *
+ * Returns : JB_ERR_OK on success
+ * JB_ERR_MEMORY on out-of-memory
+ * JB_ERR_CGI_PARAMS if the CGI parameters are not
+ * specified or not valid.
+ *
+ *********************************************************************/
+static jb_err cgi_edit_process_string_action(struct client_state *csp,
+ struct http_response *rsp,
+ const struct map *parameters,
+ struct file_line *cur_line,
+ enum filter_type action_type)
+{
+ jb_err err = JB_ERR_OK;
+ const char *abbr_type = action_type_info[action_type].abbr_type;
+ int action_identifier = 0;
+
+ /* process existing string filter actions */
+ for (action_identifier = 0; !err; action_identifier++)
+ {
+ char key_value[30];
+ char key_name[30];
+ char old_name[30];
+ char key_type[30];
+ const char *name, *new_name;
+ char value; /*
+ * Action state. Valid states are: 'Y' (active),
+ * 'N' (inactive) and 'X' (no change).
+ * XXX: bad name.
+ */
+ char type; /*
+ * Abbreviated filter type. Valid types are: 'U' (suppress tag), 'H' (add header)
+ */
+ int multi_action_index = 0;
+
+ /* Generate the keys */
+ snprintf(key_value, sizeof(key_value), "string_action_%s_r%x", abbr_type, action_identifier);
+ snprintf(key_name, sizeof(key_name), "string_action_%s_n%x", abbr_type, action_identifier);
+ snprintf(old_name, sizeof(old_name), "string_action_%s_o%x", abbr_type, action_identifier);
+ snprintf(key_type, sizeof(key_type), "string_action_%s_t%x", abbr_type, action_identifier);
+
+ err = get_string_param(parameters, old_name, &name);
+ if (err) break;
+
+ if (name == NULL)
+ {
+ /* The action identifier isn't present: we're done! */
+ break;
+ }
+
+ err = get_string_param(parameters, key_name, &new_name);
+ if (err) break;
+ if (new_name == NULL) new_name = name;
+
+ type = get_char_param(parameters, key_type);
+ switch (type)
+ {
+ case 'U':
+ multi_action_index = ACTION_MULTI_SUPPRESS_TAG;
+ break;
+ case 'H':
+ multi_action_index = ACTION_MULTI_ADD_HEADER;
+ break;
+ default:
+ log_error(LOG_LEVEL_ERROR,
+ "Unknown filter type: %c for filter %s. Filter ignored.", type, name);
+ continue;
+ }
+
+ value = get_char_param(parameters, key_value);
+ if (value == 'X' || value == 'Y' || value == 'N')
+ {
+ list_remove_item(cur_line->data.action->multi_add[multi_action_index], name);
+ list_remove_item(cur_line->data.action->multi_remove[multi_action_index], name);
+ }
+
+ if (value == 'Y')
+ {
+ err = enlist(cur_line->data.action->multi_add[multi_action_index], new_name);
+ }
+ else if (value == 'N')
+ {
+ err = enlist(cur_line->data.action->multi_remove[multi_action_index], new_name);
+ }
+ }
+
+ /* process new string filter actions */
+ for (action_identifier = 0; !err; action_identifier++)
+ {
+ char key_value[30];
+ char key_name[30];
+ char key_type[30];
+ const char *name;
+ char value; /*
+ * Action state. Valid states are: 'Y' (active),
+ * 'N' (inactive) and 'X' (no change).
+ * XXX: bad name.
+ */
+ char type; /*
+ * Abbreviated filter type. Valid types are: 'U' (suppress tag), 'H' (add header)
+ */
+ int multi_action_index = 0;
+
+ /* Generate the keys */
+ snprintf(key_value, sizeof(key_value), "new_string_action_%s_r%x", abbr_type, action_identifier);
+ snprintf(key_name, sizeof(key_name), "new_string_action_%s_n%x", abbr_type, action_identifier);
+ snprintf(key_type, sizeof(key_type), "new_string_action_%s_t%x", abbr_type, action_identifier);
+
+ err = get_string_param(parameters, key_name, &name);
+ if (err) break;
+
+ if (name == NULL)
+ {
+ /* The action identifier isn't present: we've done! */
+ break;
+ }
+
+ type = get_char_param(parameters, key_type);
+ switch (type)
+ {
+ case 'U':
+ multi_action_index = ACTION_MULTI_SUPPRESS_TAG;
+ break;
+ case 'H':
+ multi_action_index = ACTION_MULTI_ADD_HEADER;
+ break;
+ default:
+ log_error(LOG_LEVEL_ERROR,
+ "Unknown filter type: %c for filter %s. Filter ignored.", type, name);
+ continue;
+ }
+
+ value = get_char_param(parameters, key_value);
+ if (value == 'Y')
+ {
+ list_remove_item(cur_line->data.action->multi_add[multi_action_index], name);
+ if (!err) err = enlist(cur_line->data.action->multi_add[multi_action_index], name);
+ list_remove_item(cur_line->data.action->multi_remove[multi_action_index], name);
+ }
+ else if (value == 'N')
+ {
+ list_remove_item(cur_line->data.action->multi_add[multi_action_index], name);
+ list_remove_item(cur_line->data.action->multi_remove[multi_action_index], name);
+ if (!err) err = enlist(cur_line->data.action->multi_remove[multi_action_index], name);
+ }
+ /* nothing to do if the value is 'X' */
+ }
+ return err;
+}
+
+