httpd.h

Go to the documentation of this file.
00001 #ifndef _PRO_HTTPD_H_
00002 #define _PRO_HTTPD_H_
00003 
00004 /*
00005  * Copyright (C) 2001-2007 by egnite Software GmbH. All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions
00009  * are met:
00010  *
00011  * 1. Redistributions of source code must retain the above copyright
00012  *    notice, this list of conditions and the following disclaimer.
00013  * 2. Redistributions in binary form must reproduce the above copyright
00014  *    notice, this list of conditions and the following disclaimer in the
00015  *    documentation and/or other materials provided with the distribution.
00016  * 3. Neither the name of the copyright holders nor the names of
00017  *    contributors may be used to endorse or promote products derived
00018  *    from this software without specific prior written permission.
00019  *
00020  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00021  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00022  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00023  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00024  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00025  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00026  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00027  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00028  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00029  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00030  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00031  * SUCH DAMAGE.
00032  *
00033  * For additional information see http://www.ethernut.de/
00034  */
00035 
00074 #include <stdio.h>
00075 #include <time.h>
00076 
00081 
00082 #define METHOD_GET  1
00083 #define METHOD_POST 2
00084 #define METHOD_HEAD 3
00085 
00086 #define HTTP_CONN_CLOSE         1
00087 #define HTTP_CONN_KEEP_ALIVE    2
00088 
00089 #define HTTP_OF_USE_HOST_TIME   0x00000001UL
00090 #define HTTP_OF_USE_FILE_TIME   0x00000002UL
00091 
00092 typedef struct _REQUEST REQUEST;
00097 struct _REQUEST {
00098     int req_method;             
00099     int req_version;            
00100     long req_length;            
00101     char *req_url;              
00102     char *req_query;            
00103     char *req_type;             
00104     char *req_cookie;           
00105     char *req_auth;             
00106     char *req_agent;            
00107     char **req_qptrs;           
00108     int req_numqptrs;           
00109     time_t req_ims;             
00110     char *req_referer;          
00111     char *req_host;             
00112     int req_connection;         
00113 };
00114 
00115 typedef struct _MIMETYPES MIMETYPES;
00116 
00117 struct _MIMETYPES {
00118     char *mtyp_ext;
00119     char *mtyp_type;
00120     void (*mtyp_handler)(FILE *stream, int fd, int file_len, char *http_root, REQUEST *req);
00121 };
00122 
00123 __BEGIN_DECLS
00124 
00125 extern void NutHttpProcessRequest(FILE * stream);
00126 extern void NutHttpProcessQueryString(REQUEST * req);
00127 extern void NutHttpSendHeaderTop(FILE * stream, REQUEST * req, int status, char *title);
00128 extern void NutHttpSendHeaderBottom(FILE * stream, REQUEST * req, char *mime_type, long bytes);
00129 extern void NutHttpSendHeaderBot(FILE * stream, char *mime_type, long bytes);
00130 extern void NutHttpSendError(FILE * stream, REQUEST * req, int status);
00131 extern char *NutGetMimeType(char *name);
00132 extern void *NutGetMimeHandler(char *name);
00133 extern u_char NutSetMimeHandler(char *extension, void (*handler)(FILE *stream, int fd, int file_len, char *http_root, REQUEST *req));
00134 
00135 __END_DECLS
00136 
00137 /*
00138  * Authorization
00139  */
00140 typedef struct _AUTHINFO AUTHINFO;
00141 
00146 struct _AUTHINFO {
00147     AUTHINFO *auth_next;    
00148     char *auth_dirname;     
00149     char *auth_login;       
00150 };
00151 
00152 __BEGIN_DECLS
00153 
00154 extern int NutHttpAuthValidate(REQUEST * req);
00155 extern int NutRegisterAuth(CONST char *dirname, CONST char *login);
00156 extern void NutClearAuth(void);
00157 
00158 __END_DECLS
00159 
00160 /*
00161  * CGI
00162  */
00163 typedef struct _CGIFUNCTION CGIFUNCTION;
00164 
00169 struct _CGIFUNCTION {
00170     CGIFUNCTION *cgi_next;      
00171     CONST char *cgi_name;       
00172     int (*cgi_func) (FILE *, REQUEST *);        
00173 };
00174 
00177 __BEGIN_DECLS
00178 
00179 /* Function prototypes. */
00180 extern void NutHttpSetOptionFlags(u_long flags);
00181 extern u_long NutHttpGetOptionFlags(void);
00182 extern int NutRegisterHttpRoot(char *path);
00183 extern int NutRegisterCgi(char *name, int (*func) (FILE *, REQUEST *));
00184 extern void NutCgiProcessRequest(FILE * stream, REQUEST * req);
00185 extern void NutHttpProcessPostQuery(FILE *stream, REQUEST * req);
00186 extern char *NutHttpURLEncode(char *str);
00187 extern void NutHttpURLDecode(char *str);
00188 extern char *NutHttpGetParameter(REQUEST * req, char *name);
00189 extern int NutHttpGetParameterCount(REQUEST * req);
00190 extern char *NutHttpGetParameterName(REQUEST * req, int index);
00191 extern char *NutHttpGetParameterValue(REQUEST * req, int index);
00192 
00193 
00194 __END_DECLS
00195 /* */
00196 #endif

© 2000-2007 by egnite Software GmbH - visit http://www.ethernut.de/