-#define DEFINE_ACTION_STRING(name, bit, index) \
- DEFINE_ACTION_BOOL(name, bit); \
- mapped_param = 0;
-
-#define DEFINE_CGI_PARAM_RADIO(name, bit, index, value, is_default) \
- if (add & bit) \
- { \
- checked = !strcmp(action->string[index], value); \
- } \
- else \
- { \
- checked = is_default; \
- } \
- mapped_param |= checked; \
- if (map(exports, name "-param-" value, 1, (checked ? "checked" : ""), 1)) \
- { \
- return JB_ERR_MEMORY; \
- }
-
-#define DEFINE_CGI_PARAM_CUSTOM(name, bit, index, default_val) \
- if (map(exports, name "-param-custom", 1, \
- ((!mapped_param) ? "checked" : ""), 1)) \
- { \
- return JB_ERR_MEMORY; \
- } \
- if (map(exports, name "-param", 1, \
- (((add & bit) && !mapped_param) ? \
- action->string[index] : default_val), 1)) \
- { \
- return JB_ERR_MEMORY; \
- }
-
-#define DEFINE_CGI_PARAM_NO_RADIO(name, bit, index, default_val) \
- if (map(exports, name "-param", 1, \
- ((add & bit) ? action->string[index] : default_val), 1)) \
- { \
- return JB_ERR_MEMORY; \
- }
-
-#define DEFINE_ACTION_MULTI(name, index) \
- if (action->multi_add[index]->first) \
- { \
- current_mode = 'y'; \
- } \
- else if (action->multi_remove_all[index]) \
- { \
- current_mode = 'n'; \
- } \
- else if (action->multi_remove[index]->first) \
- { \
- current_mode = 'y'; \
- } \
- else \
- { \
- current_mode = 'x'; \
- } \
- if (map_radio(exports, name, "ynx", current_mode)) \
- { \
- return JB_ERR_MEMORY; \
- }
-
-#define DEFINE_ACTION_ALIAS 0 /* No aliases for output */
-
-#include "actionlist.h"
-
-#undef DEFINE_ACTION_MULTI
-#undef DEFINE_ACTION_STRING
-#undef DEFINE_ACTION_BOOL
-#undef DEFINE_ACTION_ALIAS
-#undef DEFINE_CGI_PARAM_CUSTOM
-#undef DEFINE_CGI_PARAM_RADIO
-#undef DEFINE_CGI_PARAM_NO_RADIO
-
- return JB_ERR_OK;
-}
-
-
-/*********************************************************************
- *
- * Function : actions_from_radio
- *
- * Description : Converts a map of parameters passed to a CGI function
- * into an actionsfile entry.
- *
- * Parameters :
- * 1 : parameters = parameters to the CGI call
- * 2 : action = Action to change. Must be valid before
- * the call, actions not specified will be
- * left unchanged.
- *
- * Returns : JB_ERR_OK on success
- * JB_ERR_MEMORY on out-of-memory
- *
- *********************************************************************/
-static jb_err actions_from_radio(const struct map * parameters,
- struct action_spec *action)
-{
- const char * param;
- char * param_dup;
- char ch;
-
- assert(parameters);
- assert(action);
-
-#define DEFINE_ACTION_BOOL(name, bit) \
- if (NULL != (param = lookup(parameters, name))) \
- { \
- ch = toupper((int)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) \
- if (NULL != (param = lookup(parameters, name))) \
- { \
- ch = toupper((int)param[0]); \
- if (ch == 'Y') \
- { \
- param = lookup(parameters, name "-mode"); \
- if ((*param == '\0') || (0 == strcmp(param, "CUSTOM"))) \
- { \
- param = lookup(parameters, name "-param"); \
- } \
- 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) \
- if (NULL != (param = lookup(parameters, name))) \
- { \
- ch = 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_CGI_PARAM_CUSTOM(name, bit, index, default_val)
-#define DEFINE_CGI_PARAM_RADIO(name, bit, index, value, is_default)
-#define DEFINE_CGI_PARAM_NO_RADIO(name, bit, index, default_val)
-
-#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 DEFINE_CGI_PARAM_CUSTOM
-#undef DEFINE_CGI_PARAM_RADIO
-#undef DEFINE_CGI_PARAM_NO_RADIO
-
- 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);
- err = err || map(exports, "parse-error", 1, file->parse_error_text, 1);
-
- cur_line = file->parse_error;
- assert(cur_line);
-
- err = err || map(exports, "line-raw", 1, html_encode(cur_line->raw), 0);
- 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);
-}