const char cgiedit_rcs[] = "$Id: cgiedit.c,v 1.1 2001/09/16 15:47:37 jongfoster Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/cgiedit.c,v $ * * Purpose : CGI-based actionsfile editor. * * Functions declared include: * * * Copyright : Written by and Copyright (C) 2001 the SourceForge * IJBSWA team. http://ijbswa.sourceforge.net * * Based on the Internet Junkbuster originally written * by and Copyright (C) 1997 Anonymous Coders and * Junkbusters Corporation. http://www.junkbusters.com * * This program is free software; you can redistribute it * and/or modify it under the terms of the GNU General * Public License as published by the Free Software * Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will * be useful, but WITHOUT ANY WARRANTY; without even the * implied warranty of MERCHANTABILITY or FITNESS FOR A * PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * The GNU General Public License should be included with * this file. If not, you can view it at * http://www.gnu.org/copyleft/gpl.html * or write to the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * Revisions : * $Log: cgiedit.c,v $ * Revision 1.1 2001/09/16 15:47:37 jongfoster * First version of CGI-based edit interface. This is very much a * work-in-progress, and you can't actually use it to edit anything * yet. You must #define FEATURE_CGI_EDIT_ACTIONS for these changes * to have any effect. * * **********************************************************************/ #include "config.h" /* * FIXME: Following includes copied from cgi.c - which are actually needed? */ #include #include #include #include #include #include #ifdef _WIN32 #define snprintf _snprintf #endif /* def _WIN32 */ #include "project.h" #include "cgi.h" #include "cgiedit.h" #include "list.h" #include "encode.h" #include "ssplit.h" #include "jcc.h" #include "filters.h" #include "actions.h" #include "errlog.h" #include "miscutil.h" #include "loadcfg.h" const char cgiedit_h_rcs[] = CGIEDIT_H_VERSION; #ifdef FEATURE_CGI_EDIT_ACTIONS /********************************************************************* * * Function : cgi_edit_actions_list * * Description : CGI function that edits the actions list. * * 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 : 0 * *********************************************************************/ int cgi_edit_actions_list(struct client_state *csp, struct http_response *rsp, struct map *parameters) { struct file_list *fl; struct url_actions *actions; char * actions_html; char * next_actions_html; char * section_template; char * url_template; char * sections; char * urls; struct map * exports = default_exports(csp, NULL); struct map * section_exports; struct map * url_exports; int urlid; char buf[50]; char * s; int url_1_2; if (((fl = csp->actions_list) == NULL) || ((actions = fl->f) == NULL)) { /* FIXME: Oops, no file to edit */ free_map(exports); return cgi_default(csp, rsp, parameters); } /* Should do all global exports above this point */ section_template = template_load(csp, "edit-actions-list-section"); url_template = template_load(csp, "edit-actions-list-url"); template_fill(§ion_template, exports); template_fill(&url_template, exports); urlid = 0; sections = strdup(""); ++urlid; actions = actions->next; if (actions != NULL) { actions_html = actions_to_html(actions->action); } while (actions != NULL) { section_exports = new_map(); snprintf(buf, 50, "%d", urlid); map(section_exports, "sectionid", 1, buf, 1); map(section_exports, "actions", 1, actions_html, 1); /* Should do all section-specific exports above this point */ urls = strdup(""); url_1_2 = 2; next_actions_html = NULL; do { freez(next_actions_html); url_exports = new_map(); snprintf(buf, 50, "%d", urlid); map(url_exports, "urlid", 1, buf, 1); snprintf(buf, 50, "%d", url_1_2); map(url_exports, "url-1-2", 1, buf, 1); s = html_encode(actions->url->spec); map(url_exports, "url", 1, s, 1); s = strdup(url_template); template_fill(&s, section_exports); template_fill(&s, url_exports); urls = strsav(urls, s); free_map(url_exports); ++urlid; url_1_2 = 3 - url_1_2; actions = actions->next; if (actions) { next_actions_html = actions_to_html(actions->action); } } while (actions && (0 == strcmp(actions_html, next_actions_html))); map(section_exports, "urls", 1, urls, 0); /* Could also do section-specific exports here, but it wouldn't be as fast */ s = strdup(section_template); template_fill(&s, section_exports); sections = strsav(sections, s); free_map(section_exports); freez(actions_html); actions_html = next_actions_html; } map(exports, "sections", 1, sections, 0); /* Could also do global exports here, but it wouldn't be as fast */ rsp->body = template_load(csp, "edit-actions-list"); template_fill(&rsp->body, exports); free_map(exports); return(0); } /********************************************************************* * * Function : map_radio * * Description : Map a set of radio button values. E.g. if you have * 3 radio buttons, declare them as: *