| 1 | /* |
|---|
| 2 | ** Copyright (c) 2002 Hughes Technologies Pty Ltd. All rights |
|---|
| 3 | ** reserved. |
|---|
| 4 | ** |
|---|
| 5 | ** Terms under which this software may be used or copied are |
|---|
| 6 | ** provided in the specific license associated with this product. |
|---|
| 7 | ** |
|---|
| 8 | ** Hughes Technologies disclaims all warranties with regard to this |
|---|
| 9 | ** software, including all implied warranties of merchantability and |
|---|
| 10 | ** fitness, in no event shall Hughes Technologies be liable for any |
|---|
| 11 | ** special, indirect or consequential damages or any damages whatsoever |
|---|
| 12 | ** resulting from loss of use, data or profits, whether in an action of |
|---|
| 13 | ** contract, negligence or other tortious action, arising out of or in |
|---|
| 14 | ** connection with the use or performance of this software. |
|---|
| 15 | ** |
|---|
| 16 | ** |
|---|
| 17 | ** $Id$ |
|---|
| 18 | ** |
|---|
| 19 | */ |
|---|
| 20 | |
|---|
| 21 | /* |
|---|
| 22 | ** libhttpd Header File |
|---|
| 23 | */ |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | /*********************************************************************** |
|---|
| 27 | ** Standard header preamble. Ensure singular inclusion, setup for |
|---|
| 28 | ** function prototypes and c++ inclusion |
|---|
| 29 | */ |
|---|
| 30 | |
|---|
| 31 | #ifndef LIB_HTTPD_H |
|---|
| 32 | |
|---|
| 33 | #define LIB_HTTPD_H 1 |
|---|
| 34 | |
|---|
| 35 | #if !defined(__ANSI_PROTO) |
|---|
| 36 | #if defined(_WIN32) || defined(__STDC__) || defined(__cplusplus) |
|---|
| 37 | # define __ANSI_PROTO(x) x |
|---|
| 38 | #else |
|---|
| 39 | # define __ANSI_PROTO(x) () |
|---|
| 40 | #endif |
|---|
| 41 | #endif |
|---|
| 42 | |
|---|
| 43 | #ifdef __cplusplus |
|---|
| 44 | extern "C" { |
|---|
| 45 | #endif |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | /*********************************************************************** |
|---|
| 50 | ** Macro Definitions |
|---|
| 51 | */ |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | #define HTTP_PORT 80 |
|---|
| 55 | #define HTTP_MAX_LEN 10240 |
|---|
| 56 | #define HTTP_MAX_URL 1024 |
|---|
| 57 | #define HTTP_MAX_HEADERS 1024 |
|---|
| 58 | #define HTTP_MAX_AUTH 128 |
|---|
| 59 | #define HTTP_IP_ADDR_LEN 17 |
|---|
| 60 | #define HTTP_TIME_STRING_LEN 40 |
|---|
| 61 | #define HTTP_READ_BUF_LEN 4096 |
|---|
| 62 | #define HTTP_ANY_ADDR NULL |
|---|
| 63 | |
|---|
| 64 | #define HTTP_GET 1 |
|---|
| 65 | #define HTTP_POST 2 |
|---|
| 66 | |
|---|
| 67 | #define HTTP_TRUE 1 |
|---|
| 68 | #define HTTP_FALSE 0 |
|---|
| 69 | |
|---|
| 70 | #define HTTP_FILE 1 |
|---|
| 71 | #define HTTP_C_FUNCT 2 |
|---|
| 72 | #define HTTP_EMBER_FUNCT 3 |
|---|
| 73 | #define HTTP_STATIC 4 |
|---|
| 74 | #define HTTP_WILDCARD 5 |
|---|
| 75 | #define HTTP_C_WILDCARD 6 |
|---|
| 76 | |
|---|
| 77 | #define HTTP_METHOD_ERROR "\n<B>ERROR : Method Not Implemented</B>\n\n" |
|---|
| 78 | |
|---|
| 79 | #define httpdRequestMethod(s) s->request.method |
|---|
| 80 | #define httpdRequestPath(s) s->request.path |
|---|
| 81 | #define httpdRequestContentType(s) s->request.contentType |
|---|
| 82 | #define httpdRequestContentLength(s) s->request.contentLength |
|---|
| 83 | |
|---|
| 84 | #define HTTP_ACL_PERMIT 1 |
|---|
| 85 | #define HTTP_ACL_DENY 2 |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | extern char LIBHTTPD_VERSION[], |
|---|
| 90 | LIBHTTPD_VENDOR[]; |
|---|
| 91 | |
|---|
| 92 | /*********************************************************************** |
|---|
| 93 | ** Type Definitions |
|---|
| 94 | */ |
|---|
| 95 | |
|---|
| 96 | typedef struct { |
|---|
| 97 | int method, |
|---|
| 98 | contentLength, |
|---|
| 99 | authLength; |
|---|
| 100 | char path[HTTP_MAX_URL], |
|---|
| 101 | userAgent[HTTP_MAX_URL], |
|---|
| 102 | referer[HTTP_MAX_URL], |
|---|
| 103 | ifModified[HTTP_MAX_URL], |
|---|
| 104 | contentType[HTTP_MAX_URL], |
|---|
| 105 | authUser[HTTP_MAX_AUTH], |
|---|
| 106 | authPassword[HTTP_MAX_AUTH]; |
|---|
| 107 | } httpReq; |
|---|
| 108 | |
|---|
| 109 | |
|---|
| 110 | typedef struct _httpd_var{ |
|---|
| 111 | char *name, |
|---|
| 112 | *value; |
|---|
| 113 | struct _httpd_var *nextValue, |
|---|
| 114 | *nextVariable; |
|---|
| 115 | } httpVar; |
|---|
| 116 | |
|---|
| 117 | typedef struct _httpd_content{ |
|---|
| 118 | char *name; |
|---|
| 119 | int type, |
|---|
| 120 | indexFlag; |
|---|
| 121 | void (*function)(); |
|---|
| 122 | char *data, |
|---|
| 123 | *path; |
|---|
| 124 | int (*preload)(); |
|---|
| 125 | struct _httpd_content *next; |
|---|
| 126 | } httpContent; |
|---|
| 127 | |
|---|
| 128 | typedef struct { |
|---|
| 129 | int responseLength; |
|---|
| 130 | httpContent *content; |
|---|
| 131 | char headersSent, |
|---|
| 132 | headers[HTTP_MAX_HEADERS], |
|---|
| 133 | response[HTTP_MAX_URL], |
|---|
| 134 | contentType[HTTP_MAX_URL]; |
|---|
| 135 | } httpRes; |
|---|
| 136 | |
|---|
| 137 | |
|---|
| 138 | typedef struct _httpd_dir{ |
|---|
| 139 | char *name; |
|---|
| 140 | struct _httpd_dir *children, |
|---|
| 141 | *next; |
|---|
| 142 | struct _httpd_content *entries; |
|---|
| 143 | } httpDir; |
|---|
| 144 | |
|---|
| 145 | |
|---|
| 146 | typedef struct ip_acl_s{ |
|---|
| 147 | int addr; |
|---|
| 148 | char len, |
|---|
| 149 | action; |
|---|
| 150 | struct ip_acl_s *next; |
|---|
| 151 | } httpAcl; |
|---|
| 152 | |
|---|
| 153 | typedef struct _httpd_404 { |
|---|
| 154 | void (*function)(); |
|---|
| 155 | } http404; |
|---|
| 156 | |
|---|
| 157 | typedef struct { |
|---|
| 158 | int port, |
|---|
| 159 | serverSock, |
|---|
| 160 | clientSock, |
|---|
| 161 | readBufRemain, |
|---|
| 162 | startTime; |
|---|
| 163 | char clientAddr[HTTP_IP_ADDR_LEN], |
|---|
| 164 | fileBasePath[HTTP_MAX_URL], |
|---|
| 165 | readBuf[HTTP_READ_BUF_LEN + 1], |
|---|
| 166 | *host, |
|---|
| 167 | *readBufPtr; |
|---|
| 168 | httpReq request; |
|---|
| 169 | httpRes response; |
|---|
| 170 | httpVar *variables; |
|---|
| 171 | httpDir *content; |
|---|
| 172 | httpAcl *defaultAcl; |
|---|
| 173 | http404 *handle404; |
|---|
| 174 | FILE *accessLog, |
|---|
| 175 | *errorLog; |
|---|
| 176 | } httpd; |
|---|
| 177 | |
|---|
| 178 | |
|---|
| 179 | |
|---|
| 180 | /*********************************************************************** |
|---|
| 181 | ** Function Prototypes |
|---|
| 182 | */ |
|---|
| 183 | |
|---|
| 184 | |
|---|
| 185 | int httpdAddCContent __ANSI_PROTO((httpd*,char*,char*,int,int(*)(),void(*)())); |
|---|
| 186 | int httpdAddFileContent __ANSI_PROTO((httpd*,char*,char*,int,int(*)(),char*)); |
|---|
| 187 | int httpdAddStaticContent __ANSI_PROTO((httpd*,char*,char*,int,int(*)(),char*)); |
|---|
| 188 | int httpdAddWildcardContent __ANSI_PROTO((httpd*,char*,int(*)(),char*)); |
|---|
| 189 | int httpdAddCWildcardContent __ANSI_PROTO((httpd*,char*,int(*)(),void(*)())); |
|---|
| 190 | int httpdAddVariable __ANSI_PROTO((httpd*,char*, char*)); |
|---|
| 191 | int httpdGetConnection __ANSI_PROTO((httpd*, struct timeval*)); |
|---|
| 192 | int httpdReadRequest __ANSI_PROTO((httpd*)); |
|---|
| 193 | int httpdCheckAcl __ANSI_PROTO((httpd*, httpAcl*)); |
|---|
| 194 | int httpdAddC404Content __ANSI_PROTO((httpd*,void(*)())); |
|---|
| 195 | |
|---|
| 196 | char *httpdRequestMethodName __ANSI_PROTO((httpd*)); |
|---|
| 197 | char *httpdUrlEncode __ANSI_PROTO((char *)); |
|---|
| 198 | |
|---|
| 199 | void httpdAddHeader __ANSI_PROTO((httpd*, char*)); |
|---|
| 200 | void httpdSetContentType __ANSI_PROTO((httpd*, char*)); |
|---|
| 201 | void httpdSetResponse __ANSI_PROTO((httpd*, char*)); |
|---|
| 202 | void httpdEndRequest __ANSI_PROTO((httpd*)); |
|---|
| 203 | |
|---|
| 204 | httpd *httpdCreate __ANSI_PROTO(()); |
|---|
| 205 | void httpdFreeVariables __ANSI_PROTO((httpd*)); |
|---|
| 206 | void httpdDumpVariables __ANSI_PROTO((httpd*)); |
|---|
| 207 | void httpdOutput __ANSI_PROTO((httpd*, char*)); |
|---|
| 208 | void httpdPrintf __ANSI_PROTO((httpd*, char*, ...)); |
|---|
| 209 | void httpdProcessRequest __ANSI_PROTO((httpd*)); |
|---|
| 210 | void httpdSendHeaders __ANSI_PROTO((httpd*)); |
|---|
| 211 | void httpdSetFileBase __ANSI_PROTO((httpd*, char*)); |
|---|
| 212 | void httpdSetCookie __ANSI_PROTO((httpd*, char*, char*)); |
|---|
| 213 | |
|---|
| 214 | void httpdSetErrorLog __ANSI_PROTO((httpd*, FILE*)); |
|---|
| 215 | void httpdSetAccessLog __ANSI_PROTO((httpd*, FILE*)); |
|---|
| 216 | void httpdSetDefaultAcl __ANSI_PROTO((httpd*, httpAcl*)); |
|---|
| 217 | |
|---|
| 218 | httpVar *httpdGetVariableByName __ANSI_PROTO((httpd*, char*)); |
|---|
| 219 | httpVar *httpdGetVariableByPrefix __ANSI_PROTO((httpd*, char*)); |
|---|
| 220 | httpVar *httpdGetVariableByPrefixedName __ANSI_PROTO((httpd*, char*, char*)); |
|---|
| 221 | httpVar *httpdGetNextVariableByPrefix __ANSI_PROTO((httpVar*, char*)); |
|---|
| 222 | |
|---|
| 223 | httpAcl *httpdAddAcl __ANSI_PROTO((httpd*, httpAcl*, char*, int)); |
|---|
| 224 | |
|---|
| 225 | |
|---|
| 226 | /*********************************************************************** |
|---|
| 227 | ** Standard header file footer. |
|---|
| 228 | */ |
|---|
| 229 | |
|---|
| 230 | #ifdef __cplusplus |
|---|
| 231 | } |
|---|
| 232 | #endif /* __cplusplus */ |
|---|
| 233 | #endif /* file inclusion */ |
|---|
| 234 | |
|---|
| 235 | |
|---|