|
C/C++ Reference
|
00001 /* 00002 * ____ _________ __ _ 00003 * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____ 00004 * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/ 00005 * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__ 00006 * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/ 00007 * /____/ 00008 * 00009 * Barracuda Embedded Web-Server 00010 * 00011 **************************************************************************** 00012 * HEADER 00013 * 00014 * $Id: HttpServer.h 2570 2012-02-06 20:58:28Z wini $ 00015 * 00016 * COPYRIGHT: Real Time Logic LLC, 2003 - 2008 00017 * http://www.realtimelogic.com 00018 * 00019 * The copyright to the program herein is the property of 00020 * Real Time Logic. The program may be used or copied only 00021 * with the written permission from Real Time Logic LLC or 00022 * in accordance with the terms and conditions stipulated in 00023 * the agreement under which the program has been supplied. 00024 **************************************************************************** 00025 * 00026 * 00027 */ 00028 00029 00062 #ifndef __HttpServer_h 00063 #define __HttpServer_h 00064 #include "TargConfig.h" 00065 #include "HttpConnection.h" 00066 #include "DoubleList.h" 00067 #include "SoDisp.h" 00068 #include "SplayTree.h" 00069 #include "BaErrorCodes.h" 00070 #include "SplayTree.h" 00071 #include "BufPrint.h" 00072 #include "IoIntf.h" 00073 #include <string.h> 00074 00075 #ifdef putc 00076 #undef putc 00077 #endif 00078 00079 /* This ID must match the ID in LoginKey.java */ 00080 #define BA_COOKIE_ID "z9ZAqJtI" 00081 00082 #ifndef __DOXYGEN__ 00083 struct HttpRequest; 00084 struct HttpResponse; 00085 struct HttpPage; 00086 struct HttpServer; 00087 struct HttpSession; 00088 struct HttpLinkCon; 00089 struct HttpDir; 00090 struct AuthenticatedUser; 00091 struct UserIntf; 00092 struct CspReader; 00093 struct HttpCmdThreadPoolIntf; 00094 struct AuthUserList; 00095 struct AuthorizerIntf; 00096 struct AuthenticatorIntf; 00097 struct LHttpCommand; 00098 #endif 00099 00100 00111 #ifdef __cplusplus 00112 extern "C" { 00113 #endif 00114 BA_API struct AuthenticatedUser* AuthenticatedUser_get2( 00115 struct HttpSession* session); 00118 BA_API void httpFmtDate(char* buf, U16 bufLen, BaTime t); 00123 BA_API char* httpUnescape(char* from); 00127 BA_API char* httpEscape(char* out, const char* in); 00128 #ifdef __cplusplus 00129 } 00130 #endif 00131 00132 00133 typedef void (*UserDefinedErrHandler)(BaFatalErrorCodes ecode1, 00134 unsigned int ecode2, 00135 const char* file, 00136 int line); 00137 00138 00159 typedef void (*CspInit)( 00160 struct HttpDir* cspRoot,struct CspReader* reader); 00161 /* end of CSP */ 00163 00164 /* no longer used. included for compatibility. 00165 */ 00166 struct z_stream_s; 00167 typedef int (*ZlibInflateInit2)(struct z_stream_s* s, int windowBits, 00168 const char *version, int stream_size); 00169 00170 typedef int (*ZlibInflate)(struct z_stream_s* s, int flush); 00171 typedef int (*ZlibInflateEnd)(struct z_stream_s* s); 00172 00173 00174 #ifndef __DOXYGEN__ 00175 00176 typedef struct 00177 { 00178 char* buf; 00179 U16 size; 00180 U16 index; 00181 } HttpAllocator; 00182 00183 00186 typedef struct 00187 { 00188 #ifdef __cplusplus 00189 const char* name(HttpRequest* req); 00190 const char* value(HttpRequest* req); 00191 #endif 00192 U16 nameI; 00193 U16 valueI; 00194 }HttpHeader; 00195 00196 #ifdef __cplusplus 00197 extern "C" { 00198 #endif 00199 BA_API const char* HttpHeader_name(HttpHeader* o, struct HttpRequest* req); 00200 BA_API const char* HttpHeader_value(HttpHeader* o, struct HttpRequest* req); 00201 #ifdef __cplusplus 00202 } 00203 inline const char* HttpHeader::name(HttpRequest* req) { 00204 return HttpHeader_name(this, req); } 00205 inline const char* HttpHeader::value(HttpRequest* req) { 00206 return HttpHeader_value(this, req); } 00207 #endif 00208 00209 #endif 00210 00211 00212 00213 00214 00215 /*=========================================================================== 00216 * 00217 * HttpInData 00218 *--------------------------------------------------------------------------- 00219 * Description: 00220 */ 00221 00222 #ifndef __DOXYGEN__ 00223 00224 typedef enum { 00225 HttpInData_ParseHeader, 00226 HttpInData_ReadBody, 00227 HttpInData_ReadBodyAndParseUrlEncData 00228 } HttpInData_ParseState; 00229 #endif 00230 00231 00234 typedef struct HttpInData 00235 { 00236 #ifdef __cplusplus 00237 00239 const char* getBuf(); 00240 00247 S32 getBufSize(); 00248 #endif 00249 HttpAllocator allocator; 00250 struct HttpRequest* request; 00251 U16 lineStartI; 00252 U16 lineEndI; 00253 S16 maxRequest; 00254 U8 parseState; /* HttpInData_ParseState */ 00255 U8 overflow; /* Used for pipelined requests */ 00256 } HttpInData; 00257 00258 #define HttpAllocator_2Ptr(o, index) ((&(o)->buf[index])) 00259 #define HttpInData_lineStartPtr(o) \ 00260 HttpAllocator_2Ptr(&(o)->allocator,(o)->lineStartI) 00261 00262 #define HttpInData_getBufSize(o) \ 00263 ((o)->lineStartI < (o)->allocator.index ? \ 00264 (o)->allocator.index-(o)->lineStartI : 0) 00265 00266 #define HttpInData_getBuf(o) HttpInData_lineStartPtr(o) 00267 BaBool HttpInData_hasMoreData(HttpInData* o); 00268 00269 #ifdef __cplusplus 00270 inline const char* HttpInData::getBuf() { 00271 return HttpInData_getBuf(this); } 00272 inline S32 HttpInData::getBufSize() { 00273 return HttpInData_getBufSize(this); } 00274 #endif 00275 00276 00277 00333 typedef struct HttpParameter 00334 { 00335 #ifdef __cplusplus 00336 00338 static U32 calculateSize(struct HttpRequest* req); 00339 00343 static HttpParameter* clone(void* buf, struct HttpRequest* req); 00344 00353 const char* getParameter(const char* paramName); 00354 00355 private: 00356 HttpParameter() {} 00357 #endif 00358 U16 formLen; 00359 } HttpParameter; 00360 00361 00362 #ifdef __cplusplus 00363 extern "C" { 00364 #endif 00365 BA_API U32 HttpParameter_calculateSize(struct HttpRequest* req); 00366 BA_API HttpParameter* HttpParameter_clone(void* buf, struct HttpRequest* req); 00367 BA_API const char* HttpParameter_getParameter( 00368 HttpParameter* o,const char* paramName); 00369 00370 #ifdef __cplusplus 00371 } 00372 inline U32 HttpParameter::calculateSize(struct HttpRequest* req) { 00373 return HttpParameter_calculateSize(req); } 00374 inline HttpParameter* HttpParameter::clone(void* buf, struct HttpRequest* req){ 00375 return HttpParameter_clone(buf, req); } 00376 inline const char* HttpParameter::getParameter(const char* paramName) { 00377 return HttpParameter_getParameter(this, paramName); } 00378 #endif 00379 00380 00408 typedef struct HttpParameterIterator 00409 { 00410 #ifdef __cplusplus 00411 HttpParameterIterator(){} 00414 HttpParameterIterator(HttpRequest* req); 00415 00421 HttpParameterIterator(HttpParameter* param); 00422 00424 void nextElement(); 00426 bool hasMoreElements(); 00428 const char* getName() const { return name; } 00430 const char* getValue() const { return value; } 00431 private: 00432 #endif 00433 void* formElemBase; 00434 U8* dataEntry; 00435 U16 pos; 00436 U16 formLen; 00437 const char* name; 00438 const char* value; 00439 00440 } HttpParameterIterator; 00441 00442 #ifdef __cplusplus 00443 extern "C" { 00444 #endif 00445 00446 BA_API int HttpParameterIterator_constructor( 00447 HttpParameterIterator* o, struct HttpRequest* req); 00448 BA_API int HttpParameterIterator_constructor2(HttpParameterIterator* o, 00449 HttpParameter* param); 00450 BA_API void HttpParameterIterator_nextElement(HttpParameterIterator* o); 00451 #define HttpParameterIterator_hasMoreElements(o) ((o)->name != 0) 00452 #define HttpParameterIterator_getName(o) (o)->name 00453 #define HttpParameterIterator_getValue(o) (o)->value 00454 00455 00456 #ifdef __cplusplus 00457 } 00458 inline HttpParameterIterator::HttpParameterIterator(HttpRequest* req) { 00459 HttpParameterIterator_constructor(this, req); } 00460 inline HttpParameterIterator::HttpParameterIterator(HttpParameter* param) { 00461 HttpParameterIterator_constructor2(this, param); } 00462 inline void HttpParameterIterator::nextElement() { 00463 HttpParameterIterator_nextElement(this); } 00464 #endif 00465 00466 00492 typedef struct HttpCookie 00493 { 00494 #ifdef __cplusplus 00495 ~HttpCookie(); 00496 00499 const char* getComment() const { return comment; } 00500 00502 const char* getDomain() const { return domain; } 00503 00507 BaTime getMaxAge() const { return maxAge; } 00508 00510 const char* getName() const { return name; } 00511 00514 const char* getPath() const { return path; } 00515 00519 bool getSecure() const { return secure ? true : false; } 00520 00522 const char* getValue() const { return value; } 00523 00525 void setComment(const char* purpose); 00526 00528 void setDomain(const char* pattern); 00529 00537 void setMaxAge(BaTime expiry); 00546 void deleteCookie(); 00547 00549 void setPath(const char* uri); 00550 00554 void setSecure(bool flag); 00555 00557 void setValue(const char* newValue); 00558 00559 #if 0 00560 00561 int getVersion() const { return version; } 00562 /* Sets the version of the cookie protocol this cookie complies with. */ 00563 void setVersion(int v); 00564 #endif 00565 00571 void activate(); 00572 private: 00573 HttpCookie(); 00574 #endif 00575 struct HttpCookie* next; 00576 char* comment; 00577 char* domain; 00578 char* name; 00579 char* path; 00580 char* value; 00581 U32 maxAge; 00582 int secure; 00583 int version; 00584 BaBool deleteCookieFlag; 00585 BaBool activateFlag; /* The cookie will be sent to the client 00586 * if this flag is true */ 00587 } HttpCookie; 00588 00589 #ifdef __cplusplus 00590 extern "C" { 00591 #endif 00592 BA_API void HttpCookie_destructor(HttpCookie* o); 00593 BA_API const char* HttpCookie_getComment(HttpCookie* o); 00594 BA_API const char* HttpCookie_getDomain(HttpCookie* o); 00595 BA_API BaTime HttpCookie_getMaxAge(HttpCookie* o); 00596 BA_API const char* HttpCookie_getName(HttpCookie* o); 00597 BA_API const char* HttpCookie_getPath(HttpCookie* o); 00598 BA_API int HttpCookie_getSecure(HttpCookie* o); 00599 BA_API const char* HttpCookie_getValue(HttpCookie* o); 00600 BA_API void HttpCookie_setComment(HttpCookie* o, const char* purpose); 00601 BA_API void HttpCookie_setDomain(HttpCookie* o, const char* pattern); 00602 BA_API void HttpCookie_setMaxAge(HttpCookie* o, BaTime expiry); 00603 #define HttpCookie_deleteCookie(o) (o)->deleteCookieFlag = TRUE; 00604 BA_API void HttpCookie_setPath(HttpCookie* o, const char* uri); 00605 BA_API void HttpCookie_setSecure(HttpCookie* o, int flag); 00606 BA_API void HttpCookie_setValue(HttpCookie* o, const char* newValue); 00607 00608 #if 0 00609 int HttpCookie_getVersion(HttpCookie* o); 00610 void HttpCookie_setVersion(HttpCookie* o, int v); 00611 #endif 00612 00613 BA_API void HttpCookie_activate(HttpCookie* o); 00614 #ifdef __cplusplus 00615 } 00616 inline HttpCookie::HttpCookie() { baAssert(0); } 00617 inline HttpCookie::~HttpCookie() { HttpCookie_destructor(this); } 00618 inline void HttpCookie::setComment(const char* purpose) { 00619 HttpCookie_setComment(this, purpose); } 00620 inline void HttpCookie::setDomain(const char* pattern) { 00621 HttpCookie_setDomain(this, pattern); } 00622 inline void HttpCookie::setMaxAge(BaTime expiry) { 00623 HttpCookie_setMaxAge(this, expiry); } 00624 inline void HttpCookie::deleteCookie() { 00625 HttpCookie_deleteCookie(this); } 00626 inline void HttpCookie::setPath(const char* uri) { 00627 HttpCookie_setPath(this, uri); } 00628 inline void HttpCookie::setSecure(bool flag) { 00629 HttpCookie_setSecure(this, flag); } 00630 inline void HttpCookie::setValue(const char* newValue) { 00631 HttpCookie_setValue(this, newValue); } 00632 #if 0 00633 inline void HttpCookie::setVersion(int v) { 00634 HttpCookie_setVersion(this, v); } 00635 #endif 00636 inline void HttpCookie::activate() { 00637 HttpCookie_activate(this); } 00638 #endif 00639 00640 00644 typedef struct 00645 { 00646 #ifdef __cplusplus 00647 00650 const char* getConnection(); 00651 00659 const char* getHost(); 00660 00666 const char* getDomain(); 00667 00671 const char* getContentType(); 00672 00675 SBaFileSize getContentLength(); 00676 #endif 00677 HttpInData* inData; 00678 char* domain; 00679 BaFileSize contentLength; 00680 U16 connectionHOffs; 00681 U16 hostHOffs; 00682 U16 contentTypeHOffs; 00683 } HttpStdHeaders; 00684 00685 #ifdef __cplusplus 00686 extern "C" { 00687 #endif 00688 BA_API const char* HttpStdHeaders_zzGetValFromOffs( 00689 HttpStdHeaders* o, U16 offset); 00690 BA_API const char* HttpStdHeaders_getDomain(HttpStdHeaders* o); 00691 #define HttpStdHeaders_getConnection(o) \ 00692 HttpStdHeaders_zzGetValFromOffs(o,(o)->connectionHOffs) 00693 #define HttpStdHeaders_getHost(o) \ 00694 HttpStdHeaders_zzGetValFromOffs(o,(o)->hostHOffs) 00695 #define HttpStdHeaders_getContentType(o) \ 00696 HttpStdHeaders_zzGetValFromOffs(o,(o)->contentTypeHOffs) 00697 #define HttpStdHeaders_getContentLength(o) (o)->contentLength 00698 00699 #ifdef __cplusplus 00700 } 00701 inline const char* HttpStdHeaders::getConnection() { 00702 return HttpStdHeaders_getConnection(this); } 00703 inline const char* HttpStdHeaders::getHost() { 00704 return HttpStdHeaders_getHost(this); } 00705 inline const char* HttpStdHeaders::getDomain() { 00706 return HttpStdHeaders_getDomain(this); } 00707 inline const char* HttpStdHeaders::getContentType() { 00708 return HttpStdHeaders_getContentType(this); } 00709 inline SBaFileSize HttpStdHeaders::getContentLength() { 00710 return HttpStdHeaders_getContentLength(this); } 00711 00712 #endif 00713 00714 00715 00716 /*Do not change the HttpMethod type without checking tables in Httpserver.c*/ 00717 00728 typedef enum { 00729 HttpMethod_Connect=0x1, 00730 HttpMethod_Get=0x2, 00731 HttpMethod_Head=0x4, 00732 HttpMethod_Options=0x8, 00733 HttpMethod_Post=0x10, 00734 HttpMethod_Put=0x20, 00735 HttpMethod_Trace=0x40, 00736 00737 /* WebDAV */ 00738 HttpMethod_Copy=0x80, 00739 HttpMethod_Delete=0x100, 00740 HttpMethod_Lock=0x200, 00741 HttpMethod_Move=0x400, 00742 HttpMethod_Mkcol=0x800, 00743 HttpMethod_Propfind=0x1000, 00744 HttpMethod_Proppatch=0x2000, 00745 HttpMethod_Unlock=0x4000, 00746 HttpMethod_Unknown=0x8000 /* Must be last */ 00747 } HttpMethod; 00748 00749 00750 /* Convert a HTTP method from string value to the type HttpMethod */ 00751 BA_API HttpMethod HttpMethod_a2m(const char* str); 00752 00753 00754 00759 typedef struct HttpRequest 00760 { 00761 #ifdef __cplusplus 00762 00814 int checkMethods(HttpResponse* resp, U32 methods, bool addDefault=TRUE); 00815 00828 BaBool checkTime(struct HttpResponse* resp, BaTime time); 00829 00832 AuthenticatedUser* getAuthenticatedUser(); 00833 00836 const char* getRequestURI(); 00837 00850 const char* getRequestURL(bool forceHttps=false); 00851 00855 HttpStdHeaders* getStdHeaders(); 00856 00858 const char* getVersion(); 00859 00867 const char* getHeaderValue(const char* name); 00868 00872 HttpCookie* getCookie(const char* name); 00873 00879 HttpMethod getMethodType(); 00880 00885 const char* getMethod(); 00886 00890 static const char* getMethod(HttpMethod method); 00891 00902 const char* getParameter(const char* paramName); 00903 00919 HttpHeader* getHeaders(int* len); 00920 00921 00922 00957 #ifndef NO_HTTP_SESSION 00958 HttpSession* getSession(BaBool create=true); 00959 #endif 00960 00962 HttpConnection* getConnection(); 00963 00966 HttpServer* getServer(); 00967 00970 HttpResponse* getResponse(); 00971 00974 HttpCommand* getCommand(); 00975 00977 HttpInData* getBuffer(); 00978 00979 00980 int setUserObj(void* userObj, bool overwrite=false); 00981 void* getUserObj(); 00982 00983 #endif 00984 HttpStdHeaders stdH; 00985 HttpAllocator headerAlloc; 00986 HttpAllocator formAlloc; 00987 HttpInData inData; 00988 struct HttpServer* server; 00989 void* userObj; 00990 struct HttpSession* session; 00991 HttpMethod methodType; 00992 U16 pathI; 00993 U16 versionI; 00994 U16 headersI; 00995 U16 headerLen; 00996 U16 formsI; 00997 U16 formLen; 00998 BaBool allPostDataRead; 00999 }HttpRequest; 01000 01001 #ifdef __cplusplus 01002 extern "C" { 01003 #endif 01004 BA_API int HttpRequest_checkMethods(HttpRequest* o, struct HttpResponse* resp, 01005 U32 methods, BaBool addDefault); 01006 BA_API int HttpRequest_checkOptions( 01007 HttpRequest* o, struct HttpResponse* resp, int optLen, ...); 01008 #define HttpRequest_getAuthenticatedUser(o) \ 01009 AuthenticatedUser_get2(HttpRequest_getSession(o,FALSE)) 01010 #define HttpRequest_getConnection(o) HttpRequest_getCommand(o)->con 01011 #define HttpRequest_getMethodType(o) (o)->methodType 01012 #define HttpRequest_getMethod(o) HttpRequest_getMethod2((o)->methodType) 01013 BA_API const char* HttpRequest_getMethod2(HttpMethod method); 01014 #define HttpRequest_getServer(o) (o)->server 01015 #define HttpRequest_getResponse(o) (&HttpRequest_getCommand(o)->response) 01016 BA_API struct HttpCommand* HttpRequest_getCommand(HttpRequest*); 01017 BA_API BaBool HttpRequest_checkTime( 01018 HttpRequest* o, struct HttpResponse* resp, BaTime time); 01019 BA_API const char* HttpRequest_getRequestURI(HttpRequest* o); 01020 BA_API const char* HttpRequest_getRequestURL(HttpRequest* o,BaBool forceHttps); 01021 #define HttpRequest_getStdHeaders(o) (&(o)->stdH) 01022 BA_API const char* HttpRequest_getVersion(HttpRequest* o); 01023 BA_API const char* HttpRequest_getHeaderValue(HttpRequest* o,const char* name); 01024 #define HttpRequest_getNoOfParameters(o) (o)->formLen 01025 BA_API HttpCookie* HttpRequest_getCookie(HttpRequest* o, const char* name); 01026 #define HttpRequest_getUserObj(o) (o)->userObj 01027 BA_API int HttpRequest_setUserObj( 01028 HttpRequest* o, void* userObj, BaBool overwrite); 01029 #define HttpRequest_getBuffer(o) (&(o)->inData) 01030 BA_API const char* HttpRequest_getParameter( 01031 HttpRequest* o, const char* paramName); 01032 BA_API HttpHeader* HttpRequest_getHeaders(HttpRequest* o, int* len); 01033 BA_API BaBool HttpRequest_enableKeepAlive(HttpRequest* o); 01034 BA_API int HttpRequest_pushBackData(HttpRequest* o); 01035 #ifndef NO_HTTP_SESSION 01036 BA_API struct HttpSession* HttpRequest_getSession( 01037 HttpRequest* o, BaBool create); 01038 BA_API struct HttpSession* HttpRequest_session( 01039 HttpRequest* o, const char* val, size_t len, int set); 01040 #define HttpRequest_setSession(o,val) \ 01041 (val ? HttpRequest_session(o,val,strlen(val),TRUE) : 0) 01042 #endif 01043 #ifdef __cplusplus 01044 } 01045 01046 inline int HttpRequest::checkMethods(HttpResponse* resp, 01047 U32 methods, bool addDefault){ 01048 return HttpRequest_checkMethods(this,resp, 01049 methods, addDefault ? TRUE : FALSE);} 01050 01051 inline BaBool HttpRequest::checkTime(struct HttpResponse* resp, BaTime time) { 01052 return HttpRequest_checkTime(this, resp, time); } 01053 inline AuthenticatedUser* HttpRequest::getAuthenticatedUser() { 01054 return HttpRequest_getAuthenticatedUser(this); } 01055 inline HttpMethod HttpRequest::getMethodType() { 01056 return HttpRequest_getMethodType(this); } 01057 inline const char* HttpRequest::getMethod() { 01058 return HttpRequest_getMethod(this); } 01059 inline const char* HttpRequest::getMethod(HttpMethod method) { 01060 return HttpRequest_getMethod2(method); } 01061 inline HttpServer* HttpRequest::getServer() { 01062 return HttpRequest_getServer(this); } 01063 inline const char* HttpRequest::getRequestURI() { 01064 return HttpRequest_getRequestURI(this); } 01065 inline const char* HttpRequest::getRequestURL(bool forceHttps) { 01066 return HttpRequest_getRequestURL(this, forceHttps); } 01067 inline HttpStdHeaders* HttpRequest::getStdHeaders() { 01068 return HttpRequest_getStdHeaders(this); } 01069 inline const char* HttpRequest::getVersion() { 01070 return HttpRequest_getVersion(this); } 01071 inline const char* HttpRequest::getHeaderValue(const char* name) { 01072 return HttpRequest_getHeaderValue(this, name); } 01073 inline HttpCookie* HttpRequest::getCookie(const char* name) { 01074 return HttpRequest_getCookie(this, name); } 01075 inline const char* HttpRequest::getParameter(const char* paramName) { 01076 return HttpRequest_getParameter(this, paramName); } 01077 inline HttpHeader* HttpRequest::getHeaders(int* len) { 01078 return HttpRequest_getHeaders(this, len); } 01079 inline int HttpRequest::setUserObj(void* userObj, bool overwrite) { 01080 return HttpRequest_setUserObj(this, userObj, overwrite); } 01081 inline void* HttpRequest::getUserObj() { 01082 return HttpRequest_getUserObj(this); } 01083 #ifndef NO_HTTP_SESSION 01084 inline HttpSession* HttpRequest::getSession(BaBool create) { 01085 return HttpRequest_getSession(this, create); } 01086 #endif 01087 inline bool HttpParameterIterator::hasMoreElements() { 01088 return HttpParameterIterator_hasMoreElements(this); } 01089 inline HttpInData* HttpRequest::getBuffer() { 01090 return HttpRequest_getBuffer(this); } 01091 #endif 01092 01093 01094 #ifndef __DOXYGEN__ 01095 01096 typedef struct 01097 { 01098 HttpAllocator data; 01099 U16 maxResponseHeader; 01100 } NameValMM; 01101 01102 01103 typedef struct 01104 { 01105 U8 major; 01106 U8 minor; 01107 } HttpProtocol; 01108 01109 #endif 01110 01121 typedef struct HttpResponse 01122 { 01123 #ifdef __cplusplus 01124 01127 U32 byteCount(); 01128 01129 01133 HttpCookie* createCookie(const char* name); 01134 01145 const char* containsHeader(const char* name); 01146 01155 const char* encodeRedirectURL(const char* pathName); 01156 01166 const char* encodeRedirectURLWithParam(const char* pathName); 01167 01174 const char* encodeUrl(const char* path); 01175 01180 int flush(); 01181 01207 int forward(const char* path); 01208 01229 int redirect(const char* path); 01230 01231 01234 HttpRequest* getRequest(); 01235 01238 HttpCommand* getCommand(); 01239 01240 01256 int include(const char* path); 01257 01262 bool committed() const; 01263 01267 bool isForward() const; 01268 01271 bool isInclude() const; 01272 01276 bool initial() const; 01277 01281 int resetHeaders(); 01282 01287 int resetBuffer(); 01288 01300 int sendError(int eCode); 01301 01315 int sendError(int eCode, const char* msg); 01316 01322 int sendBufAsError(int eCode); 01323 01329 int sendBufAsTxtError(int eCode); 01330 01331 01338 int fmtError(int eCode, const char* fmt, ...); 01339 01357 int sendRedirect(const char* url); 01358 01370 int forceHttps(); 01371 01377 int setContentLength(BaFileSize len); 01378 01384 int setContentType(const char* type); 01385 01395 int setDateHeader(const char* name, BaTime time); 01396 01417 int setHeader(const char* name, const char* value, bool replace=true); 01418 01424 int setMaxAge(BaTime seconds); 01425 01426 01459 char* fmtHeader(const char* name, int valueLen, bool replace=true); 01460 01461 01476 void setStatus(int statusCode); 01477 01481 int printf(const char* fmt, ...); 01482 01489 BufPrint* getWriter(); 01490 01499 int write(const void* data, int len, int useBuffering=TRUE); 01500 01508 int write(const char* data, int useBuffering=TRUE); 01509 01514 int send(const void* data, int len); 01515 01522 int setDefaultHeaders(); 01523 01543 int setResponseBuf(BufPrint* buf, bool useDefBuffer=true); 01544 01548 int removeResponseBuf(); 01549 01550 01551 int setUserObj(void* userObj, bool overwrite=false); 01552 #endif 01553 NameValMM nameValMM; 01554 BufPrint headerPrint; 01555 BufPrint defaultBodyPrint; 01556 BufPrint* bodyPrint; 01557 struct HttpDir* currentDir; 01558 char* encodedURL; 01559 char* encodedRedirectURL; 01560 HttpCookie* cookieList; 01561 void* userObj; 01562 int statusCode; 01563 U32 msgLen; /* Used if request is of type HEAD, count total msg len */ 01564 HttpProtocol protocol; 01565 U16 includeCounter; 01566 U16 forwardCounter; 01567 char headerSent; 01568 char printAndWriteInitialized; 01569 char useChunkTransfer; 01570 } HttpResponse; 01571 01572 #ifdef __cplusplus 01573 extern "C" { 01574 #endif 01575 BA_API HttpCookie* HttpResponse_createCookie( 01576 struct HttpResponse* o,const char* name); 01577 BA_API const char* HttpResponse_containsHeader( 01578 HttpResponse* o, const char* name); 01579 BA_API int HttpResponse_dataAdded(HttpResponse* o, U32 size); 01580 #define HttpResponse_byteCount(o) ((o)->msgLen + (o)->bodyPrint->cursor) 01581 BA_API const char* HttpResponse_encodeRedirectURL( 01582 HttpResponse* o, const char* pathName); 01583 BA_API const char* HttpResponse_encodeRedirectURLWithParamOrSessionURL( 01584 HttpResponse* o,const char* path,BaBool setUrlCookie); 01585 #define HttpResponse_encodeRedirectURLWithParam(o, path) \ 01586 HttpResponse_encodeRedirectURLWithParamOrSessionURL(o, path, FALSE) 01587 #define HttpResponse_encodeSessionURL(o, path) \ 01588 HttpResponse_encodeRedirectURLWithParamOrSessionURL(o, path, TRUE) 01589 BA_API const char* HttpResponse_encodeUrl(HttpResponse* o, const char* path); 01590 BA_API int HttpResponse_flush(HttpResponse* o); 01591 #define HttpResponse_forward(o,path) HttpResponse_incOrForward(o,path,FALSE) 01592 #define HttpResponse_getConnection(o) HttpResponse_getCommand(o)->con 01593 #define HttpResponse_getRequest(o) (&HttpResponse_getCommand(o)->request) 01594 BA_API struct HttpCommand* HttpResponse_getCommand(HttpResponse*); 01595 #define HttpResponse_getBuf(o) (o)->bodyPrint->buf 01596 #define HttpResponse_getBufSize(o) (o)->bodyPrint->bufSize 01597 #define HttpResponse_getBufOffs(o) \ 01598 ((o)->bodyPrint->buf + (o)->bodyPrint->cursor) 01599 #define HttpResponse_getRemBufSize(o) \ 01600 ((o)->bodyPrint->bufSize - (o)->bodyPrint->cursor) 01601 #define HttpResponse_getUserObj(o) (o)->userObj 01602 BA_API int HttpResponse_incOrForward( 01603 HttpResponse* o, const char* path, BaBool isInc); 01604 BA_API int HttpResponse_redirect(HttpResponse* o, const char* path); 01605 #define HttpResponse_include(o,path) HttpResponse_incOrForward(o,path,TRUE) 01606 #define HttpResponse_isChunkTransfer(o) (o)->useChunkTransfer 01607 #define HttpResponse_committed(o) (o)->headerSent 01608 #define HttpResponse_isForward(o) ((o)->forwardCounter != 0) 01609 #define HttpResponse_isInclude(o) ((o)->includeCounter != 0) 01610 #define HttpResponse_initial(o) (!HttpResponse_isForward(o) && \ 01611 !HttpResponse_isInclude(o)) 01612 BA_API int HttpResponse_setResponseBuf( 01613 HttpResponse* o,BufPrint* buf,BaBool useDefBuffer); 01614 BA_API int HttpResponse_removeResponseBuf(HttpResponse* o); 01615 01616 BA_API int HttpResponse_resetHeaders(HttpResponse* o); 01617 BA_API int HttpResponse_resetBuffer(HttpResponse* o); 01618 BA_API int HttpResponse_sendError1(HttpResponse* o, int eCode); 01619 BA_API int HttpResponse_sendError2(HttpResponse* o,int eCode,const char* msg); 01620 BA_API int HttpResponse_sendBufAsError(HttpResponse* o,int eCode); 01621 BA_API int HttpResponse_sendBufAsTxtError(HttpResponse* o,int eCode); 01622 BA_API int HttpResponse_fmtVError( 01623 HttpResponse* response, 01624 int eCode, 01625 const char* fmt, 01626 va_list varg); 01627 BA_API int HttpResponse_fmtError( 01628 HttpResponse* response, 01629 int eCode, 01630 const char* fmt, ...); 01631 BA_API int HttpResponse_sendRedirect(HttpResponse* o, const char* url); 01632 BA_API int HttpResponse_sendRedirectI( 01633 HttpResponse* o, const char* url, int status); 01634 BA_API int HttpResponse_forceHttps(HttpResponse* o); 01635 #define HttpResponse_setBufPos(o, pos) (o)->bodyPrint->cursor = pos 01636 BA_API int HttpResponse_setContentLength(HttpResponse* o, BaFileSize len); 01637 BA_API int HttpResponse_setContentType(HttpResponse* o, const char* type); 01638 BA_API int HttpResponse_setDateHeader( 01639 HttpResponse* o, const char* name, BaTime t); 01640 BA_API int HttpResponse_setHeader( 01641 HttpResponse* o,const char* name,const char* value, BaBool replace); 01642 BA_API int HttpResponse_setMaxAge(HttpResponse* response, BaTime seconds); 01643 BA_API char* HttpResponse_fmtHeader( 01644 HttpResponse* o, const char* name, int valueLen, BaBool replace); 01645 BA_API int HttpResponse_setStatus(HttpResponse* o, int eCode); 01646 BA_API int HttpResponse_vprintf( 01647 HttpResponse* o, const char* fmt, va_list argList); 01648 BA_API int HttpResponse_printf(HttpResponse* o, const char* fmt, ...); 01649 BA_API int HttpResponse_write(HttpResponse* o, const void* data, int len, 01650 int useBuffering); 01651 BA_API BufPrint* HttpResponse_getWriter(HttpResponse* o); 01652 BA_API int HttpResponse_send(HttpResponse* o, const void* data, int len); 01653 BA_API int HttpResponse_setDefaultHeaders(HttpResponse* o); 01654 BA_API int HttpResponse_downgrade(HttpResponse* o); 01655 BA_API int HttpResponse_setUserObj( 01656 HttpResponse* o,void* userObj,BaBool overwrite); 01657 BA_API int HttpResponse_printAndWriteInit(HttpResponse* o); 01658 BA_API int HttpResponse_send100Continue(HttpResponse* o); 01659 BA_API int HttpResponse_setChunkEncoding(HttpResponse* o); 01660 BA_API const char* HttpResponse_getRespData(HttpResponse* o, int* len); 01661 #define HttpResponse_getStatus(o) (o)->statusCode 01662 #ifdef __cplusplus 01663 } 01664 inline HttpCookie* HttpResponse::createCookie(const char* name) { 01665 return HttpResponse_createCookie(this, name); } 01666 inline const char* HttpResponse::containsHeader(const char* name) { 01667 return HttpResponse_containsHeader(this, name); } 01668 inline U32 HttpResponse::byteCount() { 01669 return HttpResponse_byteCount(this); } 01670 inline const char* HttpResponse::encodeRedirectURL(const char* pathName) { 01671 return HttpResponse_encodeRedirectURL(this, pathName); } 01672 inline const char* HttpResponse::encodeRedirectURLWithParam(const char* p) { 01673 return HttpResponse_encodeRedirectURLWithParam(this, p); } 01674 inline const char* HttpResponse::encodeUrl(const char* path) { 01675 return HttpResponse_encodeUrl(this, path); } 01676 inline int HttpResponse::flush() { 01677 return HttpResponse_flush(this); } 01678 inline int HttpResponse::forward(const char* path) { 01679 return HttpResponse_forward(this, path); } 01680 inline int HttpResponse::redirect(const char* path) { 01681 return HttpResponse_redirect(this, path); } 01682 inline int HttpResponse::include(const char* path) { 01683 return HttpResponse_include(this, path); } 01684 inline bool HttpResponse::committed() const { 01685 return HttpResponse_committed(this) ? true : false; } 01686 inline bool HttpResponse::isForward() const { 01687 return HttpResponse_isForward(this) ? true : false; } 01688 inline bool HttpResponse::isInclude() const { 01689 return HttpResponse_isInclude(this) ? true : false; } 01690 inline bool HttpResponse::initial() const { 01691 return HttpResponse_initial(this) ? true : false; } 01692 inline int HttpResponse::setResponseBuf(BufPrint* buf, bool useDefBuffer) { 01693 return HttpResponse_setResponseBuf(this, buf, useDefBuffer?TRUE:FALSE); } 01694 inline int HttpResponse::removeResponseBuf() { 01695 return HttpResponse_removeResponseBuf(this); } 01696 inline int HttpResponse::resetHeaders() { 01697 return HttpResponse_resetHeaders(this); } 01698 inline int HttpResponse::resetBuffer() { 01699 return HttpResponse_resetBuffer(this); } 01700 inline int HttpResponse::sendError(int eCode) { 01701 return HttpResponse_sendError1(this, eCode); } 01702 inline int HttpResponse::sendError(int eCode, const char* msg) { 01703 return HttpResponse_sendError2(this, eCode, msg); } 01704 inline int HttpResponse::sendBufAsError(int eCode) { 01705 return HttpResponse_sendBufAsError(this, eCode); } 01706 inline int HttpResponse::sendBufAsTxtError(int eCode) { 01707 return HttpResponse_sendBufAsTxtError(this,eCode);} 01708 inline int HttpResponse::fmtError(int eCode,const char* fmt,...) { 01709 int retv; va_list varg; 01710 va_start(varg, fmt); 01711 retv = HttpResponse_fmtVError(this, eCode, fmt, varg); 01712 va_end(varg); 01713 return retv; } 01714 inline int HttpResponse::sendRedirect(const char* url) { 01715 return HttpResponse_sendRedirect(this, url); } 01716 inline int HttpResponse::forceHttps() { 01717 return HttpResponse_forceHttps(this); } 01718 inline int HttpResponse::setContentLength(BaFileSize len) { 01719 return HttpResponse_setContentLength(this, len); } 01720 inline int HttpResponse::setContentType(const char* type) { 01721 return HttpResponse_setContentType(this, type); } 01722 inline int HttpResponse::setDateHeader(const char* name, BaTime t) { 01723 return HttpResponse_setDateHeader(this, name, t); } 01724 inline int HttpResponse::setHeader( 01725 const char* name, const char* value, bool replace) { 01726 return HttpResponse_setHeader(this,name, value, replace?TRUE:FALSE); } 01727 inline int HttpResponse::setMaxAge(BaTime seconds) { 01728 return HttpResponse_setMaxAge(this, seconds); } 01729 inline char* HttpResponse::fmtHeader( 01730 const char* name, int valueLen, bool replace) { 01731 return HttpResponse_fmtHeader(this, name, valueLen, replace?TRUE:FALSE); } 01732 inline void HttpResponse::setStatus(int eCode) { 01733 HttpResponse_setStatus(this, eCode);} 01734 01735 inline int HttpResponse::printf(const char* fmt, ...) { 01736 int retv; va_list varg; va_start(varg, fmt); 01737 retv = HttpResponse_vprintf(this, fmt, varg); va_end(varg); return retv;} 01738 inline int HttpResponse::write(const char* data, int useBuffering) { 01739 return HttpResponse_write(this, data, (int)strlen(data), useBuffering); } 01740 inline BufPrint* HttpResponse::getWriter() { 01741 return HttpResponse_getWriter(this); } 01742 inline int HttpResponse::write(const void* data, int len, int useBuffering){ 01743 return HttpResponse_write(this, data, len, useBuffering); } 01744 inline int HttpResponse::send(const void* data, int len) { 01745 return HttpResponse_send(this, data, len); } 01746 inline int HttpResponse::setDefaultHeaders() { 01747 return HttpResponse_setDefaultHeaders(this); } 01748 inline int HttpResponse::setUserObj(void* userObj, bool overwrite) { 01749 return HttpResponse_setUserObj(this, userObj, overwrite); } 01750 01751 #endif 01752 01758 typedef struct HttpCommand 01759 { 01760 #ifdef __cplusplus 01761 01764 HttpRequest* getRequest(); 01765 01768 HttpResponse* getResponse(); 01769 01773 struct HttpConnection* getConnection(); 01774 01776 struct HttpServer* getServer(); 01777 01778 HttpCommand() {} 01779 #endif 01780 DoubleLink super; 01781 #ifdef __cplusplus 01782 public: 01783 #endif 01784 HttpRequest request; 01785 HttpResponse response; 01786 struct HttpConnection* con; 01787 struct LHttpCommand* lcmd; /* Used by LSP plugin */ 01788 U32 requestTime; 01789 BaBool runningInThread; 01790 }HttpCommand; 01791 01792 #define HttpCommand_getRequest(o) (&(o)->request) 01793 #define HttpCommand_getResponse(o) (&(o)->response) 01794 #define HttpCommand_getConnection(o) (o)->con 01795 #define HttpCommand_getServer(o) HttpConnection_getServer((o)->con) 01796 #ifdef __cplusplus 01797 inline HttpRequest* HttpCommand::getRequest() { 01798 return HttpCommand_getRequest(this); } 01799 inline HttpResponse* HttpCommand::getResponse() { 01800 return HttpCommand_getResponse(this); } 01801 inline struct HttpConnection* HttpCommand::getConnection() { 01802 return HttpCommand_getConnection(this); } 01803 inline struct HttpServer* HttpCommand::getServer() { 01804 return HttpCommand_getServer(this); 01805 } 01806 #endif 01807 01808 01809 #ifndef NO_HTTP_SESSION 01810 01811 #ifndef __DOXYGEN__ 01812 struct HttpSessionAttribute; 01813 struct HttpSessionContainer; 01814 #endif 01815 01822 typedef void (*HttpSessionAttribute_Destructor)( 01823 struct HttpSessionAttribute* o); 01824 01852 typedef struct HttpSessionAttribute 01853 { 01854 #ifdef __cplusplus 01855 01860 HttpSessionAttribute(const char* name, 01861 HttpSessionAttribute_Destructor terminate); 01862 01865 HttpSession* getSession(); 01866 #endif 01867 struct HttpSessionAttribute* next; 01868 struct HttpSession* session; 01869 HttpSessionAttribute_Destructor destructor; 01870 char* name; 01871 } HttpSessionAttribute; 01872 01873 #ifdef __cplusplus 01874 extern "C" { 01875 #endif 01876 01877 BA_API void HttpSessionAttribute_constructor( 01878 HttpSessionAttribute* o, 01879 const char* name, 01880 HttpSessionAttribute_Destructor d); 01881 BA_API void HttpSessionAttribute_destructor(HttpSessionAttribute* o); 01882 #define HttpSessionAttribute_getSession(o) (o)->session 01883 #ifdef __cplusplus 01884 } 01885 inline HttpSessionAttribute::HttpSessionAttribute( 01886 const char* name, 01887 HttpSessionAttribute_Destructor d) { 01888 HttpSessionAttribute_constructor(this, name, d); } 01889 inline HttpSession* HttpSessionAttribute::getSession() { 01890 return HttpSessionAttribute_getSession(this); } 01891 01892 #endif 01893 01899 typedef struct HttpSession 01900 { 01901 #ifdef __cplusplus 01902 01903 void *operator new(size_t s) { return ::baMalloc(s); } 01904 void operator delete(void* d) { if(d) ::baFree(d); } 01905 void *operator new(size_t, void *place) { return place; } 01906 void operator delete(void*, void *) { } 01907 01922 void terminate(); 01923 01927 HttpSessionAttribute* getAttribute(const char* name); 01928 01932 BaTime getCreationTime(); 01933 01938 BaTime getLastAccessedTime(); 01939 01943 BaTime getMaxInactiveInterval(); 01944 01946 HttpServer* getServer(); 01947 01950 int removeAttribute(const char* name); 01951 01954 int setAttribute(HttpSessionAttribute* value); 01955 01959 void setMaxInactiveInterval(BaTime interval); 01960 01966 void incrRefCntr(); 01967 01973 void decrRefCntr(); 01974 01978 U32 getId(); 01979 01982 AuthenticatedUser* getAuthenticatedUser(); 01983 01986 U32 getUseCounter(); 01987 01988 01989 void incrementLock(); 01990 void decrementLock(); 01991 01992 HttpSession() {} 01993 private: 01994 #endif 01995 SplayTreeNode super; /* inherits from SplayTreeNode */ 01996 DoubleLink dlink; 01997 HttpSockaddr peer; 01998 HttpSessionAttribute* attrList; 01999 struct HttpSessionContainer* container; 02000 BaTime creationTime; 02001 BaTime lastAccessedTime; 02002 BaTime maxInactiveInterval; 02003 U32 useCounter; 02004 int refCounter; 02005 U16 lockCounter; 02006 U8 termPending; /* TRUE if in termination list */ 02007 } HttpSession; 02008 02009 02010 #ifdef __cplusplus 02011 extern "C" { 02012 #endif 02013 BA_API HttpSessionAttribute* HttpSession_getAttribute(HttpSession* o, 02014 const char* name); 02015 BA_API BaTime HttpSession_getCreationTime(HttpSession* o); 02016 BA_API BaTime HttpSession_getLastAccessedTime(HttpSession* o); 02017 BA_API BaTime HttpSession_getMaxInactiveInterval(HttpSession* o); 02018 BA_API struct HttpServer* HttpSession_getServer(HttpSession* o); 02019 BA_API void HttpSession_terminate(HttpSession* o); 02020 BA_API BaBool HttpSession_isNew(HttpSession* o); 02021 BA_API int HttpSession_removeAttribute(HttpSession* o, const char* name); 02022 BA_API int HttpSession_setAttribute(HttpSession* o, 02023 HttpSessionAttribute* value); 02024 BA_API void HttpSession_setMaxInactiveInterval(HttpSession* o,BaTime interval); 02025 #define HttpSession_incrRefCntr(o) (o)->refCounter++ 02026 BA_API void HttpSession_decrRefCntr(HttpSession* o); 02027 #define HttpSession_incrementLock(o) (o)->lockCounter++ 02028 #define HttpSession_decrementLock(o) do {\ 02029 baAssert((o)->lockCounter > 0);\ 02030 (o)->lockCounter--; } while(0) 02031 void HttpSession_fmtSessionId(HttpSession* o, U8* buf); 02032 #define HttpSession_getId(o) ((U32)SplayTreeNode_getKey((SplayTreeNode*)(o))) 02033 #define HttpSession_getAuthenticatedUser(o) AuthenticatedUser_get2((o)) 02034 #define HttpSession_getUseCounter(o) (o)->useCounter 02035 #define HttpSession_getPeerName(o) (&(o)->peer) 02036 #ifdef __cplusplus 02037 } 02038 inline HttpSessionAttribute* HttpSession::getAttribute(const char* name) { 02039 return HttpSession_getAttribute(this, name); } 02040 inline BaTime HttpSession::getCreationTime() { 02041 return HttpSession_getCreationTime(this); } 02042 inline BaTime HttpSession::getLastAccessedTime() { 02043 return HttpSession_getLastAccessedTime(this); } 02044 inline BaTime HttpSession::getMaxInactiveInterval() { 02045 return HttpSession_getMaxInactiveInterval(this); } 02046 inline HttpServer* HttpSession::getServer() { 02047 return HttpSession_getServer(this); } 02048 inline void HttpSession::terminate() { 02049 HttpSession_terminate(this); } 02050 inline int HttpSession::removeAttribute(const char* name) { 02051 return HttpSession_removeAttribute(this, name); } 02052 inline int HttpSession::setAttribute(HttpSessionAttribute* value) { 02053 return HttpSession_setAttribute(this, value); } 02054 inline void HttpSession::setMaxInactiveInterval(BaTime interval) { 02055 HttpSession_setMaxInactiveInterval(this, interval); } 02056 inline void HttpSession::incrRefCntr() { 02057 HttpSession_incrRefCntr(this); } 02058 inline void HttpSession::decrRefCntr() { 02059 HttpSession_decrRefCntr(this); } 02060 inline U32 HttpSession::getId() { return HttpSession_getId(this); } 02061 inline U32 HttpSession::getUseCounter() { 02062 return HttpSession_getUseCounter(this); } 02063 inline AuthenticatedUser* HttpSession::getAuthenticatedUser() { 02064 return HttpSession_getAuthenticatedUser(this); } 02065 inline void HttpSession::incrementLock() {HttpSession_incrementLock(this);} 02066 inline void HttpSession::decrementLock() {HttpSession_decrementLock(this);} 02067 02068 #endif /* __cplusplus */ 02069 02070 typedef enum { 02071 HttpSessionContainer_OK = 0, 02072 HttpSessionContainer_NoMemory, 02073 HttpSessionContainer_TooManySessions, 02074 HttpSessionContainer_NoPeerAddress 02075 } HttpSessionContainer_ECode; 02076 02077 02081 typedef struct HttpSessionContainer 02082 { 02083 #ifdef __cplusplus 02084 HttpSessionContainer() {} 02090 void setMaxSessions(int max); 02091 private: 02092 #endif 02093 SplayTree sessionTree; 02094 DoubleList sessionList; 02095 DoubleList sessionTermList; 02096 DoubleLink* sessionLinkIter; 02097 struct HttpServer* server; 02098 int noOfSessions; /* Current number of active sessions */ 02099 int maxSessions; 02100 HttpSessionContainer_ECode eCode; 02101 } HttpSessionContainer; 02102 02103 #ifdef __cplusplus 02104 extern "C" { 02105 #endif 02106 void HttpSessionContainer_constructor(struct HttpSessionContainer* o, 02107 struct HttpServer* server, 02108 U16 maxSessions); 02109 void HttpSessionContainer_destructor(struct HttpSessionContainer* o); 02110 void HttpSessionContainer_sessionTimer(struct HttpSessionContainer* o); 02111 #define HttpSessionContainer_setMaxSessions(o,max) (o)->maxSessions = max 02112 #ifdef __cplusplus 02113 } 02114 inline void HttpSessionContainer::setMaxSessions(int max) { 02115 HttpSessionContainer_setMaxSessions(this, max); } 02116 #endif 02117 02118 #endif /* NO_HTTP_SESSION */ 02119 02120 02128 typedef void (*HttpPage_Service)(struct HttpPage* page, 02129 HttpRequest* request, 02130 HttpResponse* response); 02131 02132 02133 #define HttpPageType_HttpPageSE 0x00020 02134 02135 #ifndef __DOXYGEN__ 02136 typedef struct HttpPageNode 02137 { 02138 struct HttpPageNode* next; 02139 } HttpPageNode; 02140 #endif 02141 02193 typedef struct HttpPage 02194 { 02195 #ifdef __cplusplus 02196 void *operator new(size_t s) { return ::baMalloc(s); } 02197 void operator delete(void* d) { if(d) ::baFree(d); } 02198 void *operator new(size_t, void *place) { return place; } 02199 void operator delete(void*, void *) { } 02200 HttpPage() {} 02209 HttpPage(HttpPage_Service service, const char* name); 02210 02213 ~HttpPage(); 02214 02217 const char* getName() const { return name; } 02218 02223 void service(HttpRequest* request, HttpResponse* response); 02224 02228 bool isLinked(); 02229 02232 int unlink(); 02233 #endif 02234 HttpPageNode super; /* As if inherited */ 02235 HttpPage_Service serviceCB; 02236 const char* name; 02237 } HttpPage; 02238 02239 #ifdef __cplusplus 02240 extern "C" { 02241 #endif 02242 void 02243 BA_API HttpPage_constructor( 02244 HttpPage* o, HttpPage_Service service, const char* name); 02245 BA_API void HttpPage_destructor(HttpPage* o); 02246 #define HttpPage_getName(o) (o)->name 02247 #define HttpPage_isLinked(o) ((HttpPageNode*)(o))->next 02248 BA_API int HttpPage_unlink(HttpPage* o); 02249 #define HttpPage_service(o, request, response) \ 02250 (o)->serviceCB(o, request, response) 02251 #ifdef __cplusplus 02252 } 02253 inline HttpPage::HttpPage(HttpPage_Service service, const char* name) { 02254 HttpPage_constructor(this, service, name); } 02255 inline HttpPage::~HttpPage() { 02256 HttpPage_destructor(this); } 02257 inline bool HttpPage::isLinked() { 02258 return HttpPage_isLinked(this) ? true : false; 02259 } 02260 inline int HttpPage::unlink() {return HttpPage_unlink(this); } 02261 inline void HttpPage::service(HttpRequest* request, HttpResponse* response) { 02262 HttpPage_service(this, request, response); 02263 } 02264 #endif 02265 02266 02267 02268 typedef int (*HttpDir_Service)(struct HttpDir* o, 02269 const char* relPath, 02270 HttpCommand* cmd); 02271 02272 #define HttpDirType_EhDir 0x00001 02273 #define HttpDirType_HttpResRdr 0x00002 02274 #define HttpDirType_AuthenticateDir 0x00008 02275 #define HttpDirType_AuthenticateDirWrapper 0x00010 02276 02277 02305 typedef struct HttpDir 02306 { 02307 #ifdef __cplusplus 02308 void *operator new(size_t s) { return ::baMalloc(s); } 02309 void operator delete(void* d) { if(d) ::baFree(d); } 02310 void *operator new(size_t, void *place) { return place; } 02311 void operator delete(void*, void *) { } 02313 HttpDir(); 02314 02331 HttpDir(const char* name, S8 priority=0); 02332 ~HttpDir(); 02333 02337 int insertDir(HttpDir* dir); 02338 02342 int insertPage(HttpPage* page); 02343 02346 HttpPage* getFirstPage(); 02347 02350 HttpDir* getFirstDir(); 02351 02354 HttpDir* getDir(const char* name); 02355 02358 HttpPage* getPage(const char* name); 02359 02362 HttpDir* getNext(); 02363 02373 HttpPage* findPage(HttpPage* iter, const char* name); 02374 02386 static HttpDir* findDir(HttpDir* iter, const char* name, 02387 unsigned int nameLen); 02388 02395 HttpDir* createOrGet(const char* name); 02396 02399 const char* getName() const { return name; } 02400 02403 HttpDir* getParent() const { return parent; } 02404 02427 char* makeAbsPath(const char* relPath, int relPathLen); 02428 02440 char* getRootPath(); 02441 02442 02446 HttpDir_Service overloadService(HttpDir_Service s); 02447 02457 void p403(const char* p403); 02458 02462 bool isLinked(); 02463 02466 int unlink(); 02467 02479 void setAuthenticator( 02480 struct AuthenticatorIntf* authenticator, 02481 struct AuthorizerIntf* authorizer=0); 02482 02503 bool authenticateAndAuthorize(HttpCommand* cmd,const char* path); 02504 02505 02506 #endif 02507 HttpDir_Service service; 02508 struct HttpDir* parent; /* owner */ 02509 struct HttpDir* next; /* next sibling */ 02510 const char* name; /* e.g. /mydir/ */ 02511 struct HttpDir* dirList; /* list of httpdirs (children) */ 02512 struct AuthorizerIntf* realm; /* If we have authorization */ 02513 struct AuthenticatorIntf* authenticator; /* If we have authentic. */ 02514 char* _p403; /* If we have a 403 denied response page. */ 02515 HttpPageNode pageList; /* pages for this dir */ 02516 U8 type; 02517 S8 priority; 02518 } HttpDir; 02519 02520 #ifdef __cplusplus 02521 extern "C" { 02522 #endif 02523 BA_API void HttpDir_constructor(HttpDir* o, const char* name, S8 priority); 02524 BA_API void HttpDir_destructor(HttpDir* o); 02525 BA_API char* HttpDir_makeAbsPath( 02526 HttpDir* o, const char* relPath, int relPathLen); 02527 #define HttpDir_getRootPath(o) HttpDir_makeAbsPath(o,"",0) 02528 BA_API int HttpDir_insertDir(HttpDir* o, HttpDir* dir); 02529 #define HttpDir_getFirstPage(o) \ 02530 (o)->pageList.next != &(o)->pageList ? ((HttpPage*)(o)->pageList.next) : 0 02531 #define HttpDir_getFirstDir(o) (o)->dirList 02532 BA_API HttpDir* HttpDir_getDir(HttpDir* o, const char* name); 02533 BA_API HttpPage* HttpDir_getPage(HttpDir* o, const char* name); 02534 #define HttpDir_getNext(o) (o)->next 02535 #define HttpDir_getName(o) (o)->name 02536 #define HttpDir_getParent(o) (o)->parent 02537 BA_API int HttpDir_insertPage(HttpDir* o, HttpPage* page); 02538 BA_API HttpPage* HttpDir_findPage( 02539 HttpDir* o, HttpPage* iter, const char* name); 02540 BA_API HttpDir* HttpDir_findDir( 02541 HttpDir* iter, const char* name,unsigned int nameLen); 02542 BA_API HttpDir* HttpDir_createOrGet(HttpDir* o, const char* name); 02543 BA_API void HttpDir_p403(HttpDir* o, const char* p403); 02544 BA_API HttpDir_Service HttpDir_overloadService(HttpDir*o, HttpDir_Service s); 02545 #define HttpDir_isLinked(o) (o)->parent 02546 BA_API int HttpDir_unlink(HttpDir* o); 02547 #define HttpDir_setAuthenticator(o,authenticatorMA,authorizerMA) \ 02548 (o)->authenticator = authenticatorMA,(o)->realm = authorizerMA 02549 BA_API int HttpDir_authenticateAndAuthorize( 02550 HttpDir* o,HttpCommand* cmd,const char* path); 02551 #define HttpDir_isAuthorized(o,user,method,path) \ 02552 ((o)->realm ? \ 02553 (user ? AuthorizerIntf_authorize((o)->realm,user,method,path) : FALSE) : \ 02554 TRUE) 02555 #ifdef __cplusplus 02556 } 02557 inline HttpDir::HttpDir() { 02558 HttpDir_constructor(this, 0, 0); } 02559 inline HttpDir::HttpDir(const char* name, S8 priority) { 02560 HttpDir_constructor(this, name, priority); } 02561 inline HttpDir::~HttpDir() { 02562 HttpDir_destructor(this); } 02563 inline char* HttpDir::makeAbsPath(const char* relPath, int relPathLen) { 02564 return HttpDir_makeAbsPath(this, relPath, relPathLen); } 02565 inline char* HttpDir::getRootPath() { 02566 return HttpDir_getRootPath(this); } 02567 inline int HttpDir::insertDir(HttpDir* dir) { 02568 return HttpDir_insertDir(this, dir); } 02569 inline int HttpDir::insertPage(HttpPage* page) { 02570 return HttpDir_insertPage(this, page); } 02571 inline HttpPage* HttpDir::getFirstPage() { return HttpDir_getFirstPage(this); } 02572 inline HttpDir* HttpDir::getFirstDir() { return HttpDir_getFirstDir(this); } 02573 inline HttpDir* HttpDir::getDir(const char* name) { 02574 return HttpDir_getDir(this,name); } 02575 inline HttpPage* HttpDir::getPage(const char* name) { 02576 return HttpDir_getPage(this,name); } 02577 inline HttpDir* HttpDir::getNext() { return HttpDir_getNext(this); } 02578 inline HttpPage* HttpDir::findPage(HttpPage* iter, const char* name) { 02579 return HttpDir_findPage(this, iter, name); } 02580 inline HttpDir* HttpDir::findDir(HttpDir* iter, const char* name, 02581 unsigned int nameLen) { 02582 return HttpDir_findDir(iter, name, nameLen); } 02583 inline HttpDir* HttpDir::createOrGet(const char* name) { 02584 return HttpDir_createOrGet(this, name); } 02585 inline HttpDir_Service HttpDir::overloadService(HttpDir_Service s) { 02586 return HttpDir_overloadService(this, s); } 02587 inline void HttpDir::p403(const char* p403) { 02588 HttpDir_p403(this, p403); } 02589 inline int HttpDir::unlink() {return HttpDir_unlink(this); } 02590 inline bool HttpDir::isLinked() { 02591 return HttpDir_isLinked(this) ? true : false; } 02592 inline void HttpDir::setAuthenticator(struct AuthenticatorIntf* authenticator, 02593 struct AuthorizerIntf* authorizer){ 02594 HttpDir_setAuthenticator(this,authenticator,authorizer); 02595 } 02596 inline bool HttpDir::authenticateAndAuthorize( 02597 HttpCommand* cmd, const char* path) { 02598 return HttpDir_authenticateAndAuthorize(this,cmd,path) ? true : false; } 02599 #endif 02600 02601 #ifndef __DOXYGEN__ 02602 02603 typedef struct HttpLinkCon 02604 { 02605 HttpConnection con; /* Inherits from HttpConnection */ 02606 DoubleLink link; 02607 } HttpLinkCon; 02608 02609 02610 typedef struct 02611 { 02612 HttpDir super; /* inherit */ 02613 HttpDir_Service superServiceFunc; 02614 char* page404; 02615 BaBool page404InProgress; 02616 } HttpRootDir; 02617 02618 #endif 02619 02628 typedef struct HttpServerConfig 02629 { 02630 #ifdef __cplusplus 02631 02636 HttpServerConfig(); 02637 02667 int setRequest(S16 min, S16 max); 02668 02680 int setResponseHeader(U16 min, U16 max); 02681 02694 int setResponseData(U16 size); 02695 02709 int setCommit(U16 size); 02710 02723 int setNoOfHttpCommands(U16 size); 02724 02743 int setNoOfHttpConnections(U16 size); 02744 02750 int setMaxSessions(U16 size); 02751 #endif 02752 S16 minRequest; 02753 S16 maxRequest; 02754 U16 minResponseHeader; 02755 U16 maxResponseHeader; 02756 U16 commit; 02757 U16 responseData; 02758 U16 noOfHttpCommands; 02759 U16 noOfHttpConnections; 02760 U16 maxSessions; 02761 } HttpServerConfig; 02762 02763 #ifdef __cplusplus 02764 extern "C" { 02765 #endif 02766 BA_API void HttpServerConfig_constructor(HttpServerConfig* o); 02767 BA_API int HttpServerConfig_setRequest(HttpServerConfig* o, S16 min, S16 max); 02768 BA_API int HttpServerConfig_setResponseHeader( 02769 HttpServerConfig* o, U16 min, U16 max); 02770 BA_API int HttpServerConfig_setResponseData(HttpServerConfig* o, U16 size); 02771 BA_API int HttpServerConfig_setCommit(HttpServerConfig* o, U16 size); 02772 BA_API int HttpServerConfig_setNoOfHttpCommands(HttpServerConfig* o, U16 size); 02773 BA_API int HttpServerConfig_setNoOfHttpConnections( 02774 HttpServerConfig* o, U16 size); 02775 BA_API int HttpServerConfig_setMaxSessions(HttpServerConfig* o, U16 size); 02776 #ifdef __cplusplus 02777 } 02778 inline HttpServerConfig::HttpServerConfig() { 02779 HttpServerConfig_constructor(this); } 02780 inline int HttpServerConfig::setRequest(S16 min, S16 max) { 02781 return HttpServerConfig_setRequest(this, min, max); } 02782 inline int HttpServerConfig::setResponseHeader(U16 min, U16 max) { 02783 return HttpServerConfig_setResponseHeader(this, min, max); } 02784 inline int HttpServerConfig::setResponseData(U16 size) { 02785 return HttpServerConfig_setResponseData(this, size); } 02786 inline int HttpServerConfig::setCommit(U16 size) { 02787 return HttpServerConfig_setCommit(this, size); } 02788 inline int HttpServerConfig::setNoOfHttpCommands(U16 size) { 02789 return HttpServerConfig_setNoOfHttpCommands(this, size); } 02790 inline int HttpServerConfig::setNoOfHttpConnections(U16 size) { 02791 return HttpServerConfig_setNoOfHttpConnections(this, size); } 02792 inline int HttpServerConfig::setMaxSessions(U16 size) { 02793 return HttpServerConfig_setMaxSessions(this, size); } 02794 02795 #endif 02796 02797 02798 typedef DoubleList HttpLinkConList; 02799 02800 /* Used by LSP plugin */ 02801 typedef void (*LspOnTerminateRequest)(struct LHttpCommand* lcmd); 02802 02805 typedef struct HttpServer 02806 { 02807 #ifdef __cplusplus 02808 void *operator new(size_t s) { return ::baMalloc(s); } 02809 void operator delete(void* d) { if(d) ::baFree(d); } 02810 void *operator new(size_t, void *place) { return place; } 02811 void operator delete(void*, void *) { } 02818 HttpServer(SoDisp* dispatcher, HttpServerConfig* cfg=0); 02819 02820 ~HttpServer(); 02821 02833 int insertRootDir(HttpDir* dir); 02834 02856 int insertDir(const char* virtualDirRootPath, HttpDir* dir); 02857 02897 int insertCSP(CspInit cspInit, 02898 const char* virtualDirRootPath, 02899 struct CspReader* reader); 02900 02901 struct AuthUserList* getAuthUserList(const char* name); 02902 02904 ThreadMutex* getMutex(); 02905 02907 SoDisp* getDispatcher(); 02908 02913 HttpDir* getFirstRootDir(); 02914 02917 HttpSessionContainer* getSessionContainer(); 02918 02919 #ifndef NO_HTTP_SESSION 02920 02929 HttpSession* getSession(U32 id); 02930 #endif 02931 02941 void set404Page(const char* page404); 02942 02944 const char* get404Page(); 02945 02946 int setUserObj(void* userObj, bool overwrite=false); 02947 02953 static void initStatic(void); 02954 02965 static void setErrHnd(UserDefinedErrHandler e); 02966 02967 /* No longer used */ 02968 static int setZlib(ZlibInflateInit2 init, 02969 ZlibInflate inflate, 02970 ZlibInflateEnd end){ 02971 (void)init; (void)inflate; (void)end; 02972 return 0; } 02975 static const char* getStatusCode(int code); 02976 02977 02978 #endif 02979 DoubleList commandPool; 02980 DoubleList cmdReqList; 02981 HttpConnection noOpCon; 02982 HttpLinkConList freeList; 02983 HttpLinkConList readyList; 02984 HttpLinkConList connectedList; 02985 HttpRootDir rootDirContainer; 02986 SplayTree authUserTree; /* Used by AuthenticatedUser.c */ 02987 struct HttpCmdThreadPoolIntf* threadPoolIntf; 02988 HttpLinkCon* connections; 02989 SoDisp* dispatcher; 02990 void* userObj; 02991 void* waitForConClose; /* See HttpServer_doLingeringClose */ 02992 LspOnTerminateRequest lspOnTerminateRequest; 02993 int commandPoolSize; 02994 U16 noOfConnections; 02995 S16 maxHttpRequestLen; 02996 #ifndef NO_HTTP_SESSION 02997 HttpSessionContainer sessionContainer; 02998 #endif 02999 } HttpServer; 03000 03001 03002 /* Used exclusively by HttpCmdThreadPool */ 03003 void HttpServer_AsynchProcessDir(HttpServer* o, 03004 HttpDir* dir, 03005 HttpCommand* cmd); 03006 /* Used exclusively by HttpCmdThreadPool */ 03007 #define HttpServer_setThreadPoolIntf(o, intf) (o)->threadPoolIntf=intf 03008 #define HttpServer_luaenv(o) (o)->luaenv 03009 03010 #ifdef __cplusplus 03011 extern "C" { 03012 #endif 03013 BA_API void HttpServer_constructor(HttpServer*,SoDisp*, HttpServerConfig*); 03014 BA_API void HttpServer_destructor(HttpServer* o); 03015 BA_API int HttpServer_insertRootDir(HttpServer* o, HttpDir* dir); 03016 BA_API int HttpServer_insertDir(HttpServer* o, 03017 const char* virtualDirRootPath, 03018 HttpDir* dir); 03019 BA_API int HttpServer_insertCSP(HttpServer* o, 03020 CspInit cspInit, 03021 const char* virtualDirRootPath, 03022 struct CspReader* reader); 03023 #define HttpServer_getAuthUserList(o, name) \ 03024 (AuthUserList*)SplayTree_find(&(o)->authUserTree, name) 03025 #define HttpServer_getDispatcher(o) (o)->dispatcher 03026 #define HttpServer_getFirstRootDir(o) \ 03027 HttpDir_getFirstDir((HttpDir*)&(o)->rootDirContainer) 03028 #define HttpServer_getUserObj(o) (o)->userObj 03029 #define HttpServer_getSessionContainer(o) (&(o)->sessionContainer) 03030 #define HttpServer_getMutex(o) SoDisp_getMutex((o)->dispatcher) 03031 BA_API const char* HttpServer_getStatusCode(int code); 03032 void HttpServer_addCon2ConnectedList(HttpServer* o, HttpConnection* con); 03033 void HttpServer_doLingeringClose( 03034 HttpServer* o, HttpConnection* con, BaFileSize contLen); 03035 03036 #ifndef NO_HTTP_SESSION 03037 BA_API HttpSession* HttpServer_getSession(HttpServer* o, U32 id); 03038 #endif 03039 BA_API HttpConnection* HttpServer_getFreeCon(HttpServer* o); 03040 void HttpServer_returnFreeCon(HttpServer* o, HttpConnection* con); 03041 BA_API void HttpServer_installNewCon(HttpServer* o, HttpConnection* con); 03042 BA_API void HttpServer_setErrHnd(UserDefinedErrHandler e); 03043 void HttpServer_initStatic(void); 03044 BA_API void HttpServer_set404Page(HttpServer*o, const char* page404); 03045 #define HttpServer_get404Page(o) (o)->rootDirContainer.page404 03046 BA_API int HttpServer_setUserObj( 03047 HttpServer* o, void* userObj, BaBool overwrite); 03048 /* No longer used */ 03049 #define HttpServer_setZlib(init,inflate,end); 03050 #ifdef __cplusplus 03051 } 03052 inline HttpServer::HttpServer(SoDisp* disp, HttpServerConfig* cfg){ 03053 HttpServer_constructor(this, disp, cfg); } 03054 inline HttpServer::~HttpServer() { 03055 HttpServer_destructor(this); } 03056 inline int HttpServer::insertRootDir(HttpDir* dir) { 03057 return HttpServer_insertRootDir(this, dir); } 03058 inline ThreadMutex* HttpServer::getMutex() { 03059 return HttpServer_getMutex(this); 03060 } 03061 inline int HttpServer::insertDir(const char* virtualDirRootPath,HttpDir* dir){ 03062 return HttpServer_insertDir(this, virtualDirRootPath, dir); } 03063 inline int HttpServer::insertCSP(CspInit cspInit, 03064 const char* virtualDirRootPath, 03065 struct CspReader* reader) { 03066 return HttpServer_insertCSP(this, cspInit, virtualDirRootPath, reader); } 03067 inline struct AuthUserList* HttpServer::getAuthUserList(const char* name) { 03068 return HttpServer_getAuthUserList(this,name); } 03069 inline SoDisp* HttpServer::getDispatcher() { 03070 return HttpServer_getDispatcher(this); } 03071 inline HttpDir* HttpServer::getFirstRootDir() { 03072 return HttpServer_getFirstRootDir(this); } 03073 inline HttpSessionContainer* HttpServer::getSessionContainer() { 03074 return HttpServer_getSessionContainer(this); } 03075 #ifndef NO_HTTP_SESSION 03076 inline HttpSession* HttpServer::getSession(U32 id) { 03077 return HttpServer_getSession(this, id); } 03078 inline void HttpServer::initStatic(void) { 03079 HttpServer_initStatic(); } 03080 inline void HttpServer::setErrHnd(UserDefinedErrHandler e) { 03081 HttpServer_setErrHnd(e); } 03082 inline void HttpServer::set404Page(const char* page404) { 03083 HttpServer_set404Page(this, page404); } 03084 inline const char* HttpServer::get404Page() { 03085 return HttpServer_get404Page(this); } 03086 inline int HttpServer::setUserObj(void* userObj, bool overwrite) { 03087 return HttpServer_setUserObj(this, userObj, overwrite); } 03088 inline const char* HttpServer::getStatusCode(int code) { 03089 return HttpServer_getStatusCode(code); 03090 } 03091 #endif 03092 03093 03094 inline HttpResponse* HttpRequest::getResponse() { 03095 return HttpRequest_getResponse(this); } 03096 inline HttpConnection* HttpRequest::getConnection() { 03097 return HttpRequest_getConnection(this); } 03098 inline HttpRequest* HttpResponse::getRequest() { 03099 return HttpResponse_getRequest(this); } 03100 inline HttpCommand* HttpResponse::getCommand() { 03101 return HttpResponse_getCommand(this); } 03102 inline HttpCommand* HttpRequest::getCommand() { 03103 return HttpRequest_getCommand(this); } 03104 inline struct HttpServer* HttpConnection::getServer() { 03105 return HttpConnection_getServer(this); } 03106 03107 #endif /* __cplusplus */ 03108 /* end of StdWebServer */ 03110 03111 03112 #endif /* __httpServer_h */