00001 /* 00002 * Copyright (C) 2001-2003 by egnite Software GmbH. All rights reserved. 00003 * 00004 * Redistribution and use in source and binary forms, with or without 00005 * modification, are permitted provided that the following conditions 00006 * are met: 00007 * 00008 * 1. Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * 3. Neither the name of the copyright holders nor the names of 00014 * contributors may be used to endorse or promote products derived 00015 * from this software without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS 00018 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00019 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00020 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE 00021 * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00022 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00023 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 00024 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 00025 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00026 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 00027 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00028 * SUCH DAMAGE. 00029 * 00030 * For additional information see http://www.ethernut.de/ 00031 */ 00032 00033 /* 00034 * $Log: cgi.c,v $ 00035 * Revision 1.2 2006/10/08 16:48:22 haraldkipp 00036 * Documentation fixed 00037 * 00038 * Revision 1.1.1.1 2003/05/09 14:41:56 haraldkipp 00039 * Initial using 3.2.1 00040 * 00041 * Revision 1.7 2003/02/04 18:17:31 harald 00042 * Version 3 released 00043 * 00044 * Revision 1.6 2002/06/26 17:29:49 harald 00045 * First pre-release with 2.4 stack 00046 * 00047 */ 00048 00049 #include <string.h> 00050 #include <sys/heap.h> 00051 00052 #include <pro/httpd.h> 00053 00058 00059 CGIFUNCTION *volatile cgiFunctionList = 0; 00060 00072 int NutRegisterCgi(char *name, int (*func) (FILE *, REQUEST *)) 00073 { 00074 CGIFUNCTION *cgi; 00075 00076 if ((cgi = NutHeapAlloc(sizeof(CGIFUNCTION))) == 0) 00077 return -1; 00078 cgi->cgi_next = cgiFunctionList; 00079 cgi->cgi_name = name; 00080 cgi->cgi_func = func; 00081 cgiFunctionList = cgi; 00082 00083 return 0; 00084 } 00085 00096 void NutCgiProcessRequest(FILE * stream, REQUEST * req) 00097 { 00098 CGIFUNCTION *cgi; 00099 00100 if (req->req_method != METHOD_GET && req->req_method != METHOD_POST) { 00101 NutHttpSendError(stream, req, 501); 00102 return; 00103 } 00104 for (cgi = cgiFunctionList; cgi; cgi = cgi->cgi_next) { 00105 if (strcasecmp(cgi->cgi_name, req->req_url + 8) == 0) 00106 break; 00107 } 00108 if (cgi == 0) 00109 NutHttpSendError(stream, req, 404); 00110 else if ((*cgi->cgi_func) (stream, req)) 00111 NutHttpSendError(stream, req, 500); 00112 return; 00113 } 00114