+static jb_err map_copy_parameter_html(struct map *out,
+ const struct map *in,
+ const char *name);
+static jb_err map_copy_parameter_url(struct map *out,
+ const struct map *in,
+ const char *name);
+
+
+/*********************************************************************
+ *
+ * Function : map_copy_parameter_html
+ *
+ * Description : Copy a CGI parameter from one map to another, HTML
+ * encoding it.
+ *
+ * Parameters :
+ * 1 : out = target map
+ * 2 : in = source map
+ * 3 : name = name of cgi parameter to copy
+ *
+ * Returns : JB_ERR_OK on success
+ * JB_ERR_MEMORY on out-of-memory
+ * JB_ERR_CGI_PARAMS if the parameter doesn't exist
+ * in the source map
+ *
+ *********************************************************************/
+static jb_err map_copy_parameter_html(struct map *out,
+ const struct map *in,
+ const char *name)
+{
+ const char * value;
+ jb_err err;
+
+ assert(out);
+ assert(in);
+ assert(name);
+
+ value = lookup(in, name);
+ err = map(out, name, 1, html_encode(value), 0);
+
+ if (err)
+ {
+ /* Out of memory */
+ return err;
+ }
+ else if (*value == '\0')
+ {
+ return JB_ERR_CGI_PARAMS;
+ }
+ else
+ {
+ return JB_ERR_OK;
+ }
+}
+
+
+/*********************************************************************
+ *
+ * Function : map_copy_parameter_html
+ *
+ * Description : Copy a CGI parameter from one map to another, URL
+ * encoding it.
+ *
+ * Parameters :
+ * 1 : out = target map
+ * 2 : in = source map
+ * 3 : name = name of cgi parameter to copy
+ *
+ * Returns : JB_ERR_OK on success
+ * JB_ERR_MEMORY on out-of-memory
+ * JB_ERR_CGI_PARAMS if the parameter doesn't exist
+ * in the source map
+ *
+ *********************************************************************/
+static jb_err map_copy_parameter_url(struct map *out,
+ const struct map *in,
+ const char *name)
+{
+ const char * value;
+ jb_err err;
+
+ assert(out);
+ assert(in);
+ assert(name);
+
+ value = lookup(in, name);
+ err = map(out, name, 1, url_encode(value), 0);
+
+ if (err)
+ {
+ /* Out of memory */
+ return err;
+ }
+ else if (*value == '\0')
+ {
+ return JB_ERR_CGI_PARAMS;
+ }
+ else
+ {
+ return JB_ERR_OK;
+ }
+}
+
+
+/*********************************************************************
+ *
+ * Function : cgi_edit_actions_url_form
+ *
+ * Description : CGI function that displays a form for
+ * edit-actions-url
+ *
+ * Parameters :
+ * 1 : csp = Current client state (buffers, headers, etc...)
+ * 2 : rsp = http_response data structure for output
+ * 3 : parameters = map of cgi parameters
+ *
+ * CGI Parameters
+ * filename : Identifies the file to edit
+ * ver : File's last-modified time
+ * section : Line number of section to edit
+ * pattern : Line number of pattern to edit
+ * oldval : Current value for pattern
+ *
+ * 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.
+ *
+ *********************************************************************/
+jb_err cgi_edit_actions_url_form(struct client_state *csp,
+ struct http_response *rsp,
+ const struct map *parameters)
+{
+ struct map *exports;
+ jb_err err;
+
+ assert(csp);
+ assert(rsp);
+ assert(parameters);
+
+ if (0 == (csp->config->feature_flags & RUNTIME_FEATURE_CGI_EDIT_ACTIONS))
+ {
+ return cgi_error_disabled(csp, rsp);
+ }
+
+ if (NULL == (exports = default_exports(csp, NULL)))
+ {
+ return JB_ERR_MEMORY;
+ }
+
+ err = map_copy_parameter_html(exports, parameters, "section");
+ if (!err) err = map_copy_parameter_html(exports, parameters, "pattern");
+ if (!err) err = map_copy_parameter_html(exports, parameters, "ver");
+ if (!err) err = map_copy_parameter_html(exports, parameters, "filename");
+ if (!err) err = map_copy_parameter_html(exports, parameters, "oldval");
+
+ if (err)
+ {
+ free_map(exports);
+ return err;
+ }
+
+ return template_fill_for_cgi(csp, "edit-actions-url-form", exports, rsp);
+}
+
+
+/*********************************************************************
+ *
+ * Function : cgi_edit_actions_add_url_form
+ *
+ * Description : CGI function that displays a form for
+ * edit-actions-url
+ *
+ * Parameters :
+ * 1 : csp = Current client state (buffers, headers, etc...)
+ * 2 : rsp = http_response data structure for output
+ * 3 : parameters = map of cgi parameters
+ *
+ * CGI Parameters :
+ * filename : Identifies the file to edit
+ * ver : File's last-modified time
+ * section : Line number of section to edit
+ *
+ * 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.
+ *
+ *********************************************************************/
+jb_err cgi_edit_actions_add_url_form(struct client_state *csp,
+ struct http_response *rsp,
+ const struct map *parameters)
+{
+ struct map *exports;
+ jb_err err;
+
+ assert(csp);
+ assert(rsp);
+ assert(parameters);
+
+ if (0 == (csp->config->feature_flags & RUNTIME_FEATURE_CGI_EDIT_ACTIONS))
+ {
+ return cgi_error_disabled(csp, rsp);
+ }
+
+ if (NULL == (exports = default_exports(csp, NULL)))
+ {
+ return JB_ERR_MEMORY;
+ }
+
+ err = map_copy_parameter_html(exports, parameters, "section");
+ if (!err) err = map_copy_parameter_html(exports, parameters, "ver");
+ if (!err) err = map_copy_parameter_html(exports, parameters, "filename");
+
+ if (err)
+ {
+ free_map(exports);
+ return err;
+ }
+
+ return template_fill_for_cgi(csp, "edit-actions-add-url-form", exports, rsp);
+}
+
+
+/*********************************************************************
+ *
+ * Function : cgi_edit_actions_remove_url_form
+ *
+ * Description : CGI function that displays a form for
+ * edit-actions-url
+ *
+ * Parameters :
+ * 1 : csp = Current client state (buffers, headers, etc...)
+ * 2 : rsp = http_response data structure for output
+ * 3 : parameters = map of cgi parameters
+ *
+ * CGI Parameters :
+ * filename : Identifies the file to edit
+ * ver : File's last-modified time
+ * section : Line number of section to edit
+ * pattern : Line number of pattern to edit
+ * oldval : Current value for pattern
+ *
+ * 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.
+ *
+ *********************************************************************/
+jb_err cgi_edit_actions_remove_url_form(struct client_state *csp,
+ struct http_response *rsp,
+ const struct map *parameters)
+{
+ struct map *exports;
+ jb_err err;
+
+ assert(csp);
+ assert(rsp);
+ assert(parameters);
+
+ if (0 == (csp->config->feature_flags & RUNTIME_FEATURE_CGI_EDIT_ACTIONS))
+ {
+ return cgi_error_disabled(csp, rsp);
+ }
+
+ if (NULL == (exports = default_exports(csp, NULL)))
+ {
+ return JB_ERR_MEMORY;
+ }
+
+ err = map_copy_parameter_url(exports, parameters, "section");
+ if (!err) err = map_copy_parameter_url(exports, parameters, "pattern");
+ if (!err) err = map_copy_parameter_url(exports, parameters, "ver");
+ if (!err) err = map_copy_parameter_url(exports, parameters, "filename");
+ if (!err) err = map_copy_parameter_html(exports, parameters, "oldval");
+
+ if (err)
+ {
+ free_map(exports);
+ return err;
+ }
+
+ return template_fill_for_cgi(csp, "edit-actions-remove-url-form", exports, rsp);
+}
+
+