httpd.h

00001 /*
00002 ** Copyright (c) 2002  Hughes Technologies Pty Ltd.  All rights
00003 ** reserved.
00004 **
00005 ** Terms under which this software may be used or copied are
00006 ** provided in the  specific license associated with this product.
00007 **
00008 ** hUghes Technologies disclaims all warranties with regard to this
00009 ** software, including all implied warranties of merchantability and
00010 ** fitness, in no event shall Hughes Technologies be liable for any
00011 ** special, indirect or consequential damages or any damages whatsoever
00012 ** resulting from loss of use, data or profits, whether in an action of
00013 ** contract, negligence or other tortious action, arising out of or in
00014 ** connection with the use or performance of this software.
00015 **
00016 **
00017 ** $Id: httpd.h 1239 2007-05-30 19:21:21Z david $
00018 **
00019 */
00020 
00021 /*
00022 **  libhttpd Header File
00023 */
00024 
00025 
00026 /***********************************************************************
00027 ** Standard header preamble.  Ensure singular inclusion, setup for
00028 ** function prototypes and c++ inclusion
00029 */
00030 
00031 #ifndef LIB_HTTPD_H
00032 
00033 #define LIB_HTTPD_H 1
00034 
00035 #if !defined(__ANSI_PROTO)
00036 #if defined(_WIN32) || defined(__STDC__) || defined(__cplusplus)
00037 #  define __ANSI_PROTO(x)       x
00038 #else
00039 #  define __ANSI_PROTO(x)       ()
00040 #endif
00041 #endif
00042 
00043 #ifdef __cplusplus
00044 extern "C" {
00045 #endif
00046 
00047 
00048 
00049 /***********************************************************************
00050 ** Macro Definitions
00051 */
00052 
00053 
00054 #define HTTP_PORT               80
00055 #define HTTP_MAX_LEN            10240
00056 #define HTTP_MAX_URL            1024
00057 #define HTTP_MAX_HEADERS        1024
00058 #define HTTP_MAX_AUTH           128
00059 #define HTTP_IP_ADDR_LEN        17
00060 #define HTTP_TIME_STRING_LEN    40
00061 #define HTTP_READ_BUF_LEN       4096
00062 #define HTTP_ANY_ADDR           NULL
00063 
00064 #define HTTP_GET                1
00065 #define HTTP_POST               2
00066 
00067 #define HTTP_TRUE               1
00068 #define HTTP_FALSE              0
00069 
00070 #define HTTP_FILE               1
00071 #define HTTP_C_FUNCT            2
00072 #define HTTP_EMBER_FUNCT        3
00073 #define HTTP_STATIC             4
00074 #define HTTP_WILDCARD           5
00075 #define HTTP_C_WILDCARD         6
00076 
00077 #define HTTP_METHOD_ERROR "\n<B>ERROR : Method Not Implemented</B>\n\n"
00078 
00079 #define httpdRequestMethod(s)           s->request.method
00080 #define httpdRequestPath(s)             s->request.path
00081 #define httpdRequestContentType(s)      s->request.contentType
00082 #define httpdRequestContentLength(s)    s->request.contentLength
00083 
00084 #define HTTP_ACL_PERMIT         1
00085 #define HTTP_ACL_DENY           2
00086 
00087 
00088 
00089 extern char     LIBHTTPD_VERSION[],
00090                 LIBHTTPD_VENDOR[];
00091 
00092 /***********************************************************************
00093 ** Type Definitions
00094 */
00095 
00096 typedef struct {
00097         int     method,
00098                 contentLength,
00099                 authLength;
00100         char    path[HTTP_MAX_URL],
00101                 query[HTTP_MAX_URL],
00102                 host[HTTP_MAX_URL], /* acv@acv.ca/wifidog: Added decoding
00103                                        of host: header if present. */
00104                 ifModified[HTTP_MAX_URL];
00105 #if(0)
00106                 userAgent[HTTP_MAX_URL],
00107                 referer[HTTP_MAX_URL],
00108                 contentType[HTTP_MAX_URL],
00109                 authUser[HTTP_MAX_AUTH],
00110                 authPassword[HTTP_MAX_AUTH];
00111 #endif
00112 } httpReq;
00113 
00114 
00115 typedef struct _httpd_var{
00116         char    *name,
00117                 *value;
00118         struct  _httpd_var      *nextValue,
00119                                 *nextVariable;
00120 } httpVar;
00121 
00122 typedef struct _httpd_content{
00123         char    *name;
00124         int     type,
00125                 indexFlag;
00126         void    (*function)();
00127         char    *data,
00128                 *path;
00129         int     (*preload)();
00130         struct  _httpd_content  *next;
00131 } httpContent;
00132 
00133 typedef struct {
00134         int             responseLength;
00135         httpContent     *content;
00136         char            headersSent,
00137                         headers[HTTP_MAX_HEADERS],
00138                         response[HTTP_MAX_URL],
00139                         contentType[HTTP_MAX_URL];
00140 } httpRes;
00141 
00142 
00143 typedef struct _httpd_dir{
00144         char    *name;
00145         struct  _httpd_dir *children,
00146                         *next;
00147         struct  _httpd_content *entries;
00148 } httpDir;
00149 
00150 
00151 typedef struct ip_acl_s{
00152         int     addr;
00153         char    len,
00154                 action;
00155         struct  ip_acl_s *next;
00156 } httpAcl;
00157 
00158 typedef struct _httpd_404 {
00159         void    (*function)();
00160 } http404;
00161 
00162 typedef struct {
00163         int     port,
00164                 serverSock,
00165                 startTime,
00166                 lastError;
00167         char    fileBasePath[HTTP_MAX_URL],
00168                 *host;
00169         httpDir *content;
00170         httpAcl *defaultAcl;
00171         http404  *handle404;
00172         FILE    *accessLog,
00173                 *errorLog;
00174 } httpd;
00175 
00176 typedef struct {
00177         int     clientSock,
00178                 readBufRemain;
00179         httpReq request;
00180         httpRes response;
00181         httpVar *variables;
00182         char    readBuf[HTTP_READ_BUF_LEN + 1],
00183                 *readBufPtr,
00184                 clientAddr[HTTP_IP_ADDR_LEN];
00185 } request;
00186 
00187 /***********************************************************************
00188 ** Function Prototypes
00189 */
00190 
00191 
00192 int httpdAddCContent __ANSI_PROTO((httpd*,char*,char*,int,int(*)(),void(*)()));
00193 int httpdAddFileContent __ANSI_PROTO((httpd*,char*,char*,int,int(*)(),char*));
00194 int httpdAddStaticContent __ANSI_PROTO((httpd*,char*,char*,int,int(*)(),char*));
00195 int httpdAddWildcardContent __ANSI_PROTO((httpd*,char*,int(*)(),char*));
00196 int httpdAddCWildcardContent __ANSI_PROTO((httpd*,char*,int(*)(),void(*)()));
00197 int httpdAddVariable __ANSI_PROTO((request*, char*, char*));
00198 request *httpdGetConnection __ANSI_PROTO((httpd*, struct timeval*));
00199 int httpdReadRequest __ANSI_PROTO((httpd*, request*));
00200 int httpdCheckAcl __ANSI_PROTO((httpd*, request *, httpAcl*));
00201 int httpdAddC404Content __ANSI_PROTO((httpd*,void(*)()));
00202 
00203 char *httpdRequestMethodName __ANSI_PROTO((request*));
00204 char *httpdUrlEncode __ANSI_PROTO((char *));
00205 
00206 void httpdAddHeader __ANSI_PROTO((request*, char*));
00207 void httpdSetContentType __ANSI_PROTO((request*, char*));
00208 void httpdSetResponse __ANSI_PROTO((request*, char*));
00209 void httpdEndRequest __ANSI_PROTO((request*));
00210 
00211 httpd *httpdCreate __ANSI_PROTO(());
00212 void httpdFreeVariables __ANSI_PROTO((request*));
00213 void httpdDumpVariables __ANSI_PROTO((request*));
00214 void httpdOutput __ANSI_PROTO((request*, char*));
00215 void httpdPrintf __ANSI_PROTO((request*, char*, ...));
00216 void httpdProcessRequest __ANSI_PROTO((httpd*, request *));
00217 void httpdSendHeaders __ANSI_PROTO((request*));
00218 void httpdSetFileBase __ANSI_PROTO((httpd*, char*));
00219 void httpdSetCookie __ANSI_PROTO((request*, char*, char*));
00220 
00221 void httpdSetErrorLog __ANSI_PROTO((httpd*, FILE*));
00222 void httpdSetAccessLog __ANSI_PROTO((httpd*, FILE*));
00223 void httpdSetDefaultAcl __ANSI_PROTO((httpd*, httpAcl*));
00224 
00225 httpVar *httpdGetVariableByName __ANSI_PROTO((request*, char*));
00226 httpVar *httpdGetVariableByPrefix __ANSI_PROTO((request*, char*));
00227 httpVar *httpdGetVariableByPrefixedName __ANSI_PROTO((request*, char*, char*));
00228 httpVar *httpdGetNextVariableByPrefix __ANSI_PROTO((httpVar*, char*));
00229 
00230 httpAcl *httpdAddAcl __ANSI_PROTO((httpd*, httpAcl*, char*, int));
00231 
00232 
00233 /***********************************************************************
00234 ** Standard header file footer.  
00235 */
00236 
00237 #ifdef __cplusplus
00238         }
00239 #endif /* __cplusplus */
00240 #endif /* file inclusion */
00241 
00242 

Generated on Sun Jun 24 00:29:52 2007 for WifiDog by  doxygen 1.5.1