-#define DEFINE_ACTION_BOOL(name, bit) \
- JAVASCRIPTIFY(js_name, name); \
- param = lookup(parameters, js_name); \
- ch = ijb_toupper(param[0]); \
- if (ch == 'Y') \
- { \
- action->add |= bit; \
- action->mask |= bit; \
- } \
- else if (ch == 'N') \
- { \
- action->add &= ~bit; \
- action->mask &= ~bit; \
- } \
- else if (ch == 'X') \
- { \
- action->add &= ~bit; \
- action->mask |= bit; \
- } \
-
-#define DEFINE_ACTION_STRING(name, bit, index) \
- JAVASCRIPTIFY(js_name, name); \
- param = lookup(parameters, js_name); \
- ch = ijb_toupper(param[0]); \
- if (ch == 'Y') \
- { \
- JAVASCRIPTIFY(js_name, name "-mode"); \
- param = lookup(parameters, js_name); \
- if ((*param == '\0') || (0 == strcmp(param, "CUSTOM"))) \
- { \
- JAVASCRIPTIFY(js_name, name "-param"); \
- param = lookup(parameters, js_name); \
- } \
- if (*param != '\0') \
- { \
- if (NULL == (param_dup = strdup(param))) \
- { \
- return JB_ERR_MEMORY; \
- } \
- freez(action->string[index]); \
- action->add |= bit; \
- action->mask |= bit; \
- action->string[index] = param_dup; \
- } \
- } \
- else if (ch == 'N') \
- { \
- if (action->add & bit) \
- { \
- freez(action->string[index]); \
- } \
- action->add &= ~bit; \
- action->mask &= ~bit; \
- } \
- else if (ch == 'X') \
- { \
- if (action->add & bit) \
- { \
- freez(action->string[index]); \
- } \
- action->add &= ~bit; \
- action->mask |= bit; \
- } \
-
-#define DEFINE_ACTION_MULTI(name, index) \
- JAVASCRIPTIFY(js_name, name); \
- param = lookup(parameters, js_name); \
- ch = ijb_toupper((int)param[0]); \
- if (ch == 'Y') \
- { \
- /* FIXME */ \
- } \
- else if (ch == 'N') \
- { \
- list_remove_all(action->multi_add[index]); \
- list_remove_all(action->multi_remove[index]); \
- action->multi_remove_all[index] = 1; \
- } \
- else if (ch == 'X') \
- { \
- list_remove_all(action->multi_add[index]); \
- list_remove_all(action->multi_remove[index]); \
- action->multi_remove_all[index] = 0; \
- } \
-
-#define DEFINE_ACTION_ALIAS 0 /* No aliases for URL parsing */
-
-#include "actionlist.h"
-
-#undef DEFINE_ACTION_MULTI
-#undef DEFINE_ACTION_STRING
-#undef DEFINE_ACTION_BOOL
-#undef DEFINE_ACTION_ALIAS
-#undef JAVASCRIPTIFY
-
- first_time = 0;
-
- return JB_ERR_OK;
-}
-
-
-/*********************************************************************
- *
- * Function : cgi_error_modified
- *
- * Description : CGI function that is called when a file is modified
- * outside the CGI editor.
- *
- * Parameters :
- * 1 : csp = Current client state (buffers, headers, etc...)
- * 2 : rsp = http_response data structure for output
- * 3 : filename = The file that was modified.
- *
- * CGI Parameters : none
- *
- * Returns : JB_ERR_OK on success
- * JB_ERR_MEMORY on out-of-memory error.
- *
- *********************************************************************/
-jb_err cgi_error_modified(struct client_state *csp,
- struct http_response *rsp,
- const char *filename)
-{
- struct map *exports;
- jb_err err;
-
- assert(csp);
- assert(rsp);
- assert(filename);
-
- if (NULL == (exports = default_exports(csp, NULL)))
- {
- return JB_ERR_MEMORY;
- }
-
- err = map(exports, "filename", 1, filename, 1);
- if (err)
- {
- free_map(exports);
- return err;
- }
-
- return template_fill_for_cgi(csp, "cgi-error-modified", exports, rsp);
-}
-
-
-/*********************************************************************
- *
- * Function : cgi_error_parse
- *
- * Description : CGI function that is called when a file cannot
- * be parsed by the CGI editor.
- *
- * Parameters :
- * 1 : csp = Current client state (buffers, headers, etc...)
- * 2 : rsp = http_response data structure for output
- * 3 : file = The file that was modified.
- *
- * CGI Parameters : none
- *
- * Returns : JB_ERR_OK on success
- * JB_ERR_MEMORY on out-of-memory error.
- *
- *********************************************************************/
-jb_err cgi_error_parse(struct client_state *csp,
- struct http_response *rsp,
- struct editable_file *file)
-{
- struct map *exports;
- jb_err err;
- struct file_line *cur_line;
-
- assert(csp);
- assert(rsp);
- assert(file);
-
- if (NULL == (exports = default_exports(csp, NULL)))
- {
- return JB_ERR_MEMORY;
- }
-
- err = map(exports, "filename", 1, file->identifier, 1);
- if (!err) err = map(exports, "parse-error", 1, file->parse_error_text, 1);
-
- cur_line = file->parse_error;
- assert(cur_line);
-
- if (!err) err = map(exports, "line-raw", 1, html_encode(cur_line->raw), 0);
- if (!err) err = map(exports, "line-data", 1, html_encode(cur_line->unprocessed), 0);
-
- if (err)
- {
- free_map(exports);
- return err;
- }
-
- return template_fill_for_cgi(csp, "cgi-error-parse", exports, rsp);
-}
-
-
-/*********************************************************************
- *
- * Function : cgi_error_file
- *
- * Description : CGI function that is called when a file cannot be
- * opened by the CGI editor.
- *
- * Parameters :
- * 1 : csp = Current client state (buffers, headers, etc...)
- * 2 : rsp = http_response data structure for output
- * 3 : filename = The file that was modified.
- *
- * CGI Parameters : none
- *
- * Returns : JB_ERR_OK on success
- * JB_ERR_MEMORY on out-of-memory error.
- *
- *********************************************************************/
-jb_err cgi_error_file(struct client_state *csp,
- struct http_response *rsp,
- const char *filename)
-{
- struct map *exports;
- jb_err err;
-
- assert(csp);
- assert(rsp);
- assert(filename);
-
- if (NULL == (exports = default_exports(csp, NULL)))
- {
- return JB_ERR_MEMORY;
- }
-
- err = map(exports, "filename", 1, filename, 1);
- if (err)
- {
- free_map(exports);
- return err;
- }
-
- return template_fill_for_cgi(csp, "cgi-error-file", exports, rsp);
-}
-
-
-/*********************************************************************
- *
- * Function : cgi_error_bad_param
- *
- * Description : CGI function that is called if the parameters
- * (query string) for a CGI were wrong.
- *
- * Parameters :
- * 1 : csp = Current client state (buffers, headers, etc...)
- * 2 : rsp = http_response data structure for output
- *
- * CGI Parameters : none
- *
- * Returns : JB_ERR_OK on success
- * JB_ERR_MEMORY on out-of-memory error.
- *
- *********************************************************************/
-jb_err cgi_error_disabled(struct client_state *csp,
- struct http_response *rsp)
-{
- struct map *exports;
-
- assert(csp);
- assert(rsp);
-
- if (NULL == (exports = default_exports(csp, NULL)))
- {
- return JB_ERR_MEMORY;
- }
-
- return template_fill_for_cgi(csp, "cgi-error-disabled", exports, rsp);
-}
-
-
-/*********************************************************************
- *
- * Function : cgi_edit_actions
- *
- * Description : CGI function that allows the user to choose which
- * actions file to edit.
- *
- * 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 : None
- *
- * Returns : JB_ERR_OK on success
- * JB_ERR_MEMORY on out-of-memory error
- *
- *********************************************************************/
-jb_err cgi_edit_actions(struct client_state *csp,
- struct http_response *rsp,
- const struct map *parameters)
-{
-
- if (0 == (csp->config->feature_flags & RUNTIME_FEATURE_CGI_EDIT_ACTIONS))
- {
- return cgi_error_disabled(csp, rsp);
- }
-
- /* FIXME: Incomplete */
- rsp->status = strdup("302 Local Redirect from Junkbuster");
- if (rsp->status == NULL)
- {
- return JB_ERR_MEMORY;
- }
- if (enlist_unique_header(rsp->headers, "Location", "http://ijbswa.sourceforge.net/config/edit-actions-list?filename=ijb"))
- {
- free(rsp->status);
- rsp->status = NULL;
- return JB_ERR_MEMORY;
- }
-
- return JB_ERR_OK;
-}
-
-
-/*********************************************************************
- *
- * Function : cgi_edit_actions_list
- *
- * Description : CGI function that edits the actions list.
- * FIXME: This function shouldn't FATAL ever.
- * FIXME: This function doesn't check the retval of map()
- * 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
- *
- * Returns : JB_ERR_OK on success
- * JB_ERR_MEMORY on out-of-memory
- * JB_ERR_FILE if the file cannot be opened or
- * contains no data
- * JB_ERR_CGI_PARAMS if "filename" was not specified
- * or is not valid.
- *
- *********************************************************************/
-jb_err cgi_edit_actions_list(struct client_state *csp,
- struct http_response *rsp,
- const struct map *parameters)
-{
- char * section_template;
- char * url_template;
- char * sections;
- char * urls;
- char buf[50];
- char * s;
- struct map * exports;
- struct map * section_exports;
- struct map * url_exports;
- struct editable_file * file;
- struct file_line * cur_line;
- unsigned line_number = 0;
- int url_1_2;
- jb_err err;
-
- if (0 == (csp->config->feature_flags & RUNTIME_FEATURE_CGI_EDIT_ACTIONS))
- {
- return cgi_error_disabled(csp, rsp);
- }
-
- err = edit_read_actions_file(csp, rsp, parameters, 0, &file);
- if (err)
- {
- /* No filename specified, can't read file, or out of memory. */
- return (err == JB_ERR_FILE ? JB_ERR_OK : err);
- }
-
- if (NULL == (exports = default_exports(csp, NULL)))
- {
- edit_free_file(file);
- return JB_ERR_MEMORY;
- }
-
- err = map(exports, "filename", 1, file->identifier, 1);
- if (!err) err = map(exports, "ver", 1, file->version_str, 1);