Barracuda Application Server C/C++ Reference
NO
HttpServer.h
1 /*
2  * ____ _________ __ _
3  * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____
4  * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/
5  * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__
6  * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/
7  * /____/
8  *
9  * Barracuda Embedded Web-Server
10  *
11  ****************************************************************************
12  * HEADER
13  *
14  * $Id: HttpServer.h 4915 2021-12-01 18:26:55Z wini $
15  *
16  * COPYRIGHT: Real Time Logic LLC, 2003 - 2019
17  *
18  * This software is copyrighted by and is the sole property of Real
19  * Time Logic LLC. All rights, title, ownership, or other interests in
20  * the software remain the property of Real Time Logic LLC. This
21  * software may only be used in accordance with the terms and
22  * conditions stipulated in the corresponding license agreement under
23  * which the software has been supplied. Any unauthorized use,
24  * duplication, transmission, distribution, or disclosure of this
25  * software is expressly forbidden.
26  *
27  * This Copyright notice may not be removed or modified without prior
28  * written consent of Real Time Logic LLC.
29  *
30  * Real Time Logic LLC. reserves the right to modify this software
31  * without notice.
32  *
33  * http://www.realtimelogic.com
34  ****************************************************************************
35  *
36  *
37  */
38 
39 #define BASLIB_VER "5166"
40 #define BASLIB_VER_NO 5166
41 
74 #ifndef __HttpServer_h
75 #define __HttpServer_h
76 #include "TargConfig.h"
77 #include "HttpConnection.h"
78 #include "DoubleList.h"
79 #include "SoDisp.h"
80 #include "SplayTree.h"
81 #include "BaErrorCodes.h"
82 #include "SplayTree.h"
83 #include "BufPrint.h"
84 #include "IoIntf.h"
85 #include <string.h>
86 #include <stddef.h>
87 
88 /* Used by examples */
89 #ifndef BA_STACKSZ
90 #define BA_STACKSZ 15000
91 #endif
92 
93 
94 /* This ID must match the ID in LoginKey.java */
95 #define BA_COOKIE_ID "z9ZAqJtI"
96 
97 #ifndef __DOXYGEN__
98 struct HttpRequest;
99 struct HttpResponse;
100 struct HttpPage;
101 struct HttpServer;
102 struct HttpSession;
103 struct HttpLinkCon;
104 struct HttpDir;
105 struct AuthenticatedUser;
106 struct UserIntf;
107 struct CspReader;
108 struct HttpCmdThreadPoolIntf;
109 struct AuthUserList;
110 struct AuthorizerIntf;
111 struct AuthenticatorIntf;
112 struct LHttpCommand;
113 #endif
114 
115 
116 /* NonBlockingSendBuf is used when sending asynchronous (non blocking
117  data). A pointer to this buffer is stored in SoDispCon.sslData
118  for HTTP cons.: this pointer is not used for anything else for a
119  non secure socket con.. */
120 typedef struct
121 {
122  int cursor;
123  int bufLen;
124  int maxBufLen;
125  char buf[1];
127 
128 
139 #ifdef __cplusplus
140 extern "C" {
141 #endif
142 BA_API struct AuthenticatedUser* AuthenticatedUser_get2(
143  struct HttpSession* session);
146 BA_API void httpFmtDate(char* buf, U16 bufLen, BaTime t);
151 BA_API char* httpUnescape(char* from);
155 BA_API char* httpEscape(char* out, const char* in);
156 #ifdef __cplusplus
157 }
158 #endif
159 
160 
161 typedef void (*UserDefinedErrHandler)(BaFatalErrorCodes ecode1,
162  unsigned int ecode2,
163  const char* file,
164  int line);
165 
166 
193 typedef void (*CspInit)(
194  struct HttpDir* cspRoot,struct CspReader* reader);
195  /* end of CSP */
197 
198 /* no longer used. included for compatibility.
199  */
200 struct z_stream_s;
201 typedef int (*ZlibInflateInit2)(struct z_stream_s* s, int windowBits,
202  const char *version, int stream_size);
203 
204 typedef int (*ZlibInflate)(struct z_stream_s* s, int flush);
205 typedef int (*ZlibInflateEnd)(struct z_stream_s* s);
206 
207 
208 #ifndef __DOXYGEN__
209 
210 typedef struct
211 {
212  char* buf;
213  U16 size;
214  U16 index;
215 } HttpAllocator;
216 
217 
220 typedef struct
221 {
222 #ifdef __cplusplus
223  const char* name(HttpRequest* req);
224  const char* value(HttpRequest* req);
225 #endif
226  U16 nameI;
227  U16 valueI;
228 }HttpHeader;
229 
230 #ifdef __cplusplus
231 extern "C" {
232 #endif
233 BA_API const char* HttpHeader_name(HttpHeader* o, struct HttpRequest* req);
234 BA_API const char* HttpHeader_value(HttpHeader* o, struct HttpRequest* req);
235 #ifdef __cplusplus
236 }
237 inline const char* HttpHeader::name(HttpRequest* req) {
238  return HttpHeader_name(this, req); }
239 inline const char* HttpHeader::value(HttpRequest* req) {
240  return HttpHeader_value(this, req); }
241 #endif
242 
243 #endif
244 
245 
246 
247 
248 
249 /*===========================================================================
250  *
251  * HttpInData
252  *---------------------------------------------------------------------------
253  * Description:
254  */
255 
256 #ifndef __DOXYGEN__
257 
258 typedef enum {
259  HttpInData_ParseHeader,
260  HttpInData_ReadBody,
261  HttpInData_ReadBodyAndParseUrlEncData
262 } HttpInData_ParseState;
263 #endif
264 
265 
268 typedef struct HttpInData
269 {
270 #ifdef __cplusplus
271 
273  const char* getBuf();
274 
281  S32 getBufSize();
282 #endif
283  HttpAllocator allocator;
284  struct HttpRequest* request;
285  U16 lineStartI;
286  U16 lineEndI;
287  S16 maxRequest;
288  U8 parseState; /* HttpInData_ParseState */
289  U8 overflow; /* Used for pipelined requests */
290 } HttpInData;
291 
292 #define HttpAllocator_2Ptr(o, index) ((&(o)->buf[index]))
293 #define HttpInData_lineStartPtr(o) \
294  HttpAllocator_2Ptr(&(o)->allocator,(o)->lineStartI)
295 
296 #define HttpInData_getBufSize(o) \
297  ((o)->lineStartI < (o)->allocator.index ? \
298  (o)->allocator.index-(o)->lineStartI : 0)
299 
300 #define HttpInData_getBuf(o) HttpInData_lineStartPtr(o)
301 BaBool HttpInData_hasMoreData(HttpInData* o);
302 
303 #ifdef __cplusplus
304 inline const char* HttpInData::getBuf() {
305  return HttpInData_getBuf(this); }
307  return HttpInData_getBufSize(this); }
308 #endif
309 
310 
311 
367 typedef struct HttpParameter
368 {
369 #ifdef __cplusplus
370 
372  static U32 calculateSize(struct HttpRequest* req);
373 
377  static HttpParameter* clone(void* buf, struct HttpRequest* req);
378 
387  const char* getParameter(const char* paramName);
388 
389  private:
390  HttpParameter() {}
391 #endif
392  U16 formLen;
393 } HttpParameter;
394 
395 
396 #ifdef __cplusplus
397 extern "C" {
398 #endif
399 BA_API U32 HttpParameter_calculateSize(struct HttpRequest* req);
400 BA_API HttpParameter* HttpParameter_clone(void* buf, struct HttpRequest* req);
401 BA_API const char* HttpParameter_getParameter(
402  HttpParameter* o,const char* paramName);
403 
404 #ifdef __cplusplus
405 }
406 inline U32 HttpParameter::calculateSize(struct HttpRequest* req) {
407  return HttpParameter_calculateSize(req); }
408 inline HttpParameter* HttpParameter::clone(void* buf, struct HttpRequest* req){
409  return HttpParameter_clone(buf, req); }
410 inline const char* HttpParameter::getParameter(const char* paramName) {
411  return HttpParameter_getParameter(this, paramName); }
412 #endif
413 
414 
442 typedef struct HttpParameterIterator
443 {
444 #ifdef __cplusplus
449 
456 
458  void nextElement();
460  bool hasMoreElements();
462  const char* getName() const { return name; }
464  const char* getValue() const { return value; }
465  private:
466 #endif
467  void* formElemBase;
468  U8* dataEntry;
469  U16 pos;
470  U16 formLen;
471  const char* name;
472  const char* value;
473 
475 
476 #ifdef __cplusplus
477 extern "C" {
478 #endif
479 
480 BA_API int HttpParameterIterator_constructor(
481  HttpParameterIterator* o, struct HttpRequest* req);
482 BA_API int HttpParameterIterator_constructor2(HttpParameterIterator* o,
483  HttpParameter* param);
484 BA_API void HttpParameterIterator_nextElement(HttpParameterIterator* o);
485 #define HttpParameterIterator_hasMoreElements(o) ((o)->name != 0)
486 #define HttpParameterIterator_getName(o) (o)->name
487 #define HttpParameterIterator_getValue(o) (o)->value
488 
489 
490 #ifdef __cplusplus
491 }
492 inline HttpParameterIterator::HttpParameterIterator(HttpRequest* req) {
493  HttpParameterIterator_constructor(this, req); }
494 inline HttpParameterIterator::HttpParameterIterator(HttpParameter* param) {
495  HttpParameterIterator_constructor2(this, param); }
497  HttpParameterIterator_nextElement(this); }
498 #endif
499 
500 
526 typedef struct HttpCookie
527 {
528 #ifdef __cplusplus
529  ~HttpCookie();
530 
533  const char* getComment() const { return comment; }
534 
536  const char* getDomain() const { return domain; }
537 
541  BaTime getMaxAge() const { return maxAge; }
542 
544  const char* getName() const { return name; }
545 
548  const char* getPath() const { return path; }
549 
553  bool getSecure() const { return secure ? true : false; }
554 
558  bool getHttpOnly() const { return httpOnly ? true : false; }
559 
561  const char* getValue() const { return value; }
562 
564  void setComment(const char* purpose);
565 
567  void setDomain(const char* pattern);
568 
576  void setMaxAge(BaTime expiry);
585  void deleteCookie();
586 
588  void setPath(const char* uri);
589 
593  void setSecure(bool flag);
594 
604  void setHttpOnly(bool flag);
605 
607  void setValue(const char* newValue);
608 
609 #if 0
610 
611  int getVersion() const { return version; }
612  /* Sets the version of the cookie protocol this cookie complies with. */
613  void setVersion(int v);
614 #endif
615 
621  void activate();
622  private:
623  HttpCookie();
624 #endif
625  struct HttpCookie* next;
626  char* comment;
627  char* domain;
628  char* name;
629  char* path;
630  char* value;
631  BaTime maxAge;
632  int version;
633  BaBool secure;
634  BaBool httpOnly;
635  BaBool deleteCookieFlag;
636  BaBool activateFlag; /* The cookie will be sent to the client
637  * if this flag is true */
639 
640 #ifdef __cplusplus
641 extern "C" {
642 #endif
643 BA_API void HttpCookie_destructor(HttpCookie* o);
644 BA_API const char* HttpCookie_getComment(HttpCookie* o);
645 BA_API const char* HttpCookie_getDomain(HttpCookie* o);
646 BA_API BaTime HttpCookie_getMaxAge(HttpCookie* o);
647 BA_API const char* HttpCookie_getName(HttpCookie* o);
648 BA_API const char* HttpCookie_getPath(HttpCookie* o);
649 BA_API BaBool HttpCookie_getSecure(HttpCookie* o);
650 BA_API BaBool HttpCookie_getHttpOnly(HttpCookie* o);
651 BA_API const char* HttpCookie_getValue(HttpCookie* o);
652 BA_API void HttpCookie_setComment(HttpCookie* o, const char* purpose);
653 BA_API void HttpCookie_setDomain(HttpCookie* o, const char* pattern);
654 BA_API void HttpCookie_setMaxAge(HttpCookie* o, BaTime expiry);
655 #define HttpCookie_deleteCookie(o) (o)->deleteCookieFlag = TRUE;
656 BA_API void HttpCookie_setPath(HttpCookie* o, const char* uri);
657 BA_API void HttpCookie_setSecure(HttpCookie* o, BaBool flag);
658 BA_API void HttpCookie_setHttpOnly(HttpCookie* o, BaBool flag);
659 BA_API void HttpCookie_setValue(HttpCookie* o, const char* newValue);
660 
661 #if 0
662 int HttpCookie_getVersion(HttpCookie* o);
663 void HttpCookie_setVersion(HttpCookie* o, int v);
664 #endif
665 
666 BA_API void HttpCookie_activate(HttpCookie* o);
667 #ifdef __cplusplus
668 }
669 inline HttpCookie::HttpCookie() { baAssert(0); }
670 inline HttpCookie::~HttpCookie() { HttpCookie_destructor(this); }
671 inline void HttpCookie::setComment(const char* purpose) {
672  HttpCookie_setComment(this, purpose); }
673 inline void HttpCookie::setDomain(const char* pattern) {
674  HttpCookie_setDomain(this, pattern); }
675 inline void HttpCookie::setMaxAge(BaTime expiry) {
676  HttpCookie_setMaxAge(this, expiry); }
678  HttpCookie_deleteCookie(this); }
679 inline void HttpCookie::setPath(const char* uri) {
680  HttpCookie_setPath(this, uri); }
681 inline void HttpCookie::setSecure(bool flag) {
682  HttpCookie_setSecure(this, flag ? TRUE : FALSE); }
683 inline void HttpCookie::setHttpOnly(bool flag) {
684  HttpCookie_setHttpOnly(this, flag ? TRUE : FALSE); }
685 inline void HttpCookie::setValue(const char* newValue) {
686  HttpCookie_setValue(this, newValue); }
687 #if 0
688 inline void HttpCookie::setVersion(int v) {
689  HttpCookie_setVersion(this, v); }
690 #endif
691 inline void HttpCookie::activate() {
692  HttpCookie_activate(this); }
693 #endif
694 
695 
699 typedef struct
700 {
701 #ifdef __cplusplus
702 
705  const char* getConnection();
706 
714  const char* getHost();
715 
721  const char* getDomain();
722 
726  const char* getContentType();
727 
730  SBaFileSize getContentLength();
731 #endif
732  HttpInData* inData;
733  char* domain;
734  BaFileSize contentLength;
735  U16 connectionHOffs;
736  U16 hostHOffs;
737  U16 contentTypeHOffs;
739 
740 #ifdef __cplusplus
741 extern "C" {
742 #endif
743 BA_API const char* HttpStdHeaders_zzGetValFromOffs(
744  HttpStdHeaders* o, U16 offset);
745 BA_API const char* HttpStdHeaders_getDomain(HttpStdHeaders* o);
746 #define HttpStdHeaders_getConnection(o) \
747  HttpStdHeaders_zzGetValFromOffs(o,(o)->connectionHOffs)
748 #define HttpStdHeaders_getHost(o) \
749  HttpStdHeaders_zzGetValFromOffs(o,(o)->hostHOffs)
750 #define HttpStdHeaders_getContentType(o) \
751  HttpStdHeaders_zzGetValFromOffs(o,(o)->contentTypeHOffs)
752 #define HttpStdHeaders_getContentLength(o) (o)->contentLength
753 
754 #ifdef __cplusplus
755 }
756 inline const char* HttpStdHeaders::getConnection() {
757  return HttpStdHeaders_getConnection(this); }
758 inline const char* HttpStdHeaders::getHost() {
759  return HttpStdHeaders_getHost(this); }
760 inline const char* HttpStdHeaders::getDomain() {
761  return HttpStdHeaders_getDomain(this); }
762 inline const char* HttpStdHeaders::getContentType() {
763  return HttpStdHeaders_getContentType(this); }
764 inline SBaFileSize HttpStdHeaders::getContentLength() {
765  return HttpStdHeaders_getContentLength(this); }
766 
767 #endif
768 
769 
770 
771  /*Do not change the HttpMethod type without checking tables in Httpserver.c*/
772 
783 typedef enum {
784  HttpMethod_Connect =0x00001,
785  HttpMethod_Get =0x00002,
786  HttpMethod_Head =0x00004,
787  HttpMethod_Options =0x00008,
788 
789  HttpMethod_Patch =0x00010,
790  HttpMethod_Post =0x00020,
791  HttpMethod_Put =0x00040,
792  HttpMethod_Trace =0x00080,
793 
794  /* WebDAV */
795  HttpMethod_Copy =0x00100,
796  HttpMethod_Delete =0x00200,
797  HttpMethod_Lock =0x00400,
798  HttpMethod_Move =0x00800,
799 
800  HttpMethod_Mkcol =0x01000,
801  HttpMethod_Propfind =0x02000,
802  HttpMethod_Proppatch =0x04000,
803  HttpMethod_Unlock =0x08000,
804 
805  HttpMethod_Unknown =0x10000 /* Must be last */
806 } HttpMethod;
807 
808 
809 /* Convert a HTTP method from string value to the type HttpMethod */
810 BA_API HttpMethod HttpMethod_a2m(const char* str);
811 
812 
813 
818 typedef struct HttpRequest
819 {
820 #ifdef __cplusplus
821 
873  int checkMethods(HttpResponse* resp, U32 methods, bool addDefault=TRUE);
874 
887  BaBool checkTime(struct HttpResponse* resp, BaTime time);
888 
892 
895  const char* getRequestURI();
896 
909  const char* getRequestURL(bool forceHttps=false);
910 
915 
917  const char* getVersion();
918 
926  const char* getHeaderValue(const char* name);
927 
931  HttpCookie* getCookie(const char* name);
932 
939 
944  const char* getMethod();
945 
949  static const char* getMethod(HttpMethod method);
950 
961  const char* getParameter(const char* paramName);
962 
967 #ifndef NO_SHARKSSL
968  int wsUpgrade();
969 #endif
970 
985  HttpHeader* getHeaders(int* len);
986 
987 
988 
1023 #ifndef NO_HTTP_SESSION
1024  HttpSession* getSession(BaBool create=true);
1025 #endif
1026 
1029 
1032  HttpServer* getServer();
1033 
1037 
1041 
1043  HttpInData* getBuffer();
1044 
1045 
1046  int setUserObj(void* userObj, bool overwrite=false);
1047  void* getUserObj();
1048 
1049 #endif
1050  HttpStdHeaders stdH;
1051  HttpAllocator headerAlloc;
1052  HttpAllocator formAlloc;
1053  HttpInData inData;
1054  struct HttpServer* server;
1055  void* userObj;
1056  struct HttpSession* session;
1057  HttpMethod methodType;
1058  U16 pathI;
1059  U16 versionI;
1060  U16 headersI;
1061  U16 headerLen;
1062  U16 formsI;
1063  U16 formLen;
1064  BaBool postDataConsumed; /* Set by MultipartUpload and HttpRecData */
1066 
1067 #ifdef __cplusplus
1068 extern "C" {
1069 #endif
1070 BA_API int HttpRequest_checkMethods(HttpRequest* o, struct HttpResponse* resp,
1071  U32 methods, BaBool addDefault);
1072 BA_API int HttpRequest_checkOptions(
1073  HttpRequest* o, struct HttpResponse* resp, int optLen, ...);
1074 #define HttpRequest_getAuthenticatedUser(o) \
1075  AuthenticatedUser_get2(HttpRequest_getSession(o,FALSE))
1076 #define HttpRequest_getConnection(o) HttpRequest_getCommand(o)->con
1077 #define HttpRequest_getMethodType(o) (o)->methodType
1078 #define HttpRequest_getMethod(o) HttpRequest_getMethod2((o)->methodType)
1079 BA_API const char* HttpRequest_getMethod2(HttpMethod method);
1080 #define HttpRequest_getServer(o) (o)->server
1081 #define HttpRequest_getResponse(o) (&HttpRequest_getCommand(o)->response)
1082 BA_API struct HttpCommand* HttpRequest_getCommand(HttpRequest*);
1083 BA_API BaBool HttpRequest_checkTime(
1084  HttpRequest* o, struct HttpResponse* resp, BaTime time);
1085 BA_API const char* HttpRequest_getRequestURI(HttpRequest* o);
1086 BA_API const char* HttpRequest_getRequestURL(HttpRequest* o,BaBool forceHttps);
1087 #define HttpRequest_getStdHeaders(o) (&(o)->stdH)
1088 BA_API const char* HttpRequest_getVersion(HttpRequest* o);
1089 BA_API const char* HttpRequest_getHeaderValue(HttpRequest* o,const char* name);
1090 #define HttpRequest_getNoOfParameters(o) (o)->formLen
1091 BA_API HttpCookie* HttpRequest_getCookie(HttpRequest* o, const char* name);
1092 #define HttpRequest_getUserObj(o) (o)->userObj
1093 BA_API int HttpRequest_setUserObj(
1094  HttpRequest* o, void* userObj, BaBool overwrite);
1095 #define HttpRequest_getBuffer(o) (&(o)->inData)
1096 BA_API const char* HttpRequest_getParameter(
1097  HttpRequest* o, const char* paramName);
1098 BA_API HttpHeader* HttpRequest_getHeaders(HttpRequest* o, int* len);
1099 #ifndef NO_SHARKSSL
1100 BA_API int HttpRequest_wsUpgrade(HttpRequest* o);
1101 #endif
1102 BA_API BaBool HttpRequest_enableKeepAlive(HttpRequest* o);
1103 BA_API int HttpRequest_pushBackData(HttpRequest* o);
1104 #ifndef NO_HTTP_SESSION
1105 BA_API struct HttpSession* HttpRequest_getSession(
1106  HttpRequest* o, BaBool create);
1107 BA_API struct HttpSession* HttpRequest_session(
1108  HttpRequest* o, const char* val, size_t len, int set);
1109 #endif
1110 #ifdef __cplusplus
1111 }
1112 
1114  U32 methods, bool addDefault){
1115  return HttpRequest_checkMethods(this,resp,
1116  methods, addDefault ? TRUE : FALSE);}
1117 
1118 inline BaBool HttpRequest::checkTime(struct HttpResponse* resp, BaTime time) {
1119  return HttpRequest_checkTime(this, resp, time); }
1121  return HttpRequest_getAuthenticatedUser(this); }
1123  return HttpRequest_getMethodType(this); }
1124 inline const char* HttpRequest::getMethod() {
1125  return HttpRequest_getMethod(this); }
1126 inline const char* HttpRequest::getMethod(HttpMethod method) {
1127  return HttpRequest_getMethod2(method); }
1129  return HttpRequest_getServer(this); }
1130 inline const char* HttpRequest::getRequestURI() {
1131  return HttpRequest_getRequestURI(this); }
1132 inline const char* HttpRequest::getRequestURL(bool forceHttps) {
1133  return HttpRequest_getRequestURL(this, forceHttps); }
1135  return HttpRequest_getStdHeaders(this); }
1136 inline const char* HttpRequest::getVersion() {
1137  return HttpRequest_getVersion(this); }
1138 inline const char* HttpRequest::getHeaderValue(const char* name) {
1139  return HttpRequest_getHeaderValue(this, name); }
1140 inline HttpCookie* HttpRequest::getCookie(const char* name) {
1141  return HttpRequest_getCookie(this, name); }
1142 inline const char* HttpRequest::getParameter(const char* paramName) {
1143  return HttpRequest_getParameter(this, paramName); }
1144 #ifndef NO_SHARKSSL
1146  return HttpRequest_wsUpgrade(this);
1147 }
1148 #endif
1149 inline HttpHeader* HttpRequest::getHeaders(int* len) {
1150  return HttpRequest_getHeaders(this, len); }
1151 inline int HttpRequest::setUserObj(void* userObj, bool overwrite) {
1152  return HttpRequest_setUserObj(this, userObj, overwrite); }
1153 inline void* HttpRequest::getUserObj() {
1154  return HttpRequest_getUserObj(this); }
1155 #ifndef NO_HTTP_SESSION
1156 inline HttpSession* HttpRequest::getSession(BaBool create) {
1157  return HttpRequest_getSession(this, create); }
1158 #endif
1160  return HttpParameterIterator_hasMoreElements(this); }
1162  return HttpRequest_getBuffer(this); }
1163 #endif
1164 
1165 
1166 #ifndef __DOXYGEN__
1167 
1168 typedef struct
1169 {
1170  HttpAllocator data;
1171  U16 maxResponseHeader;
1172 } NameValMM;
1173 
1174 
1175 typedef struct
1176 {
1177  U8 major;
1178  U8 minor;
1179 } HttpProtocol;
1180 
1181 #endif
1182 
1193 typedef struct HttpResponse
1194 {
1195 #ifdef __cplusplus
1196 
1199  U32 byteCount();
1200 
1201 
1205  HttpCookie* createCookie(const char* name);
1206 
1217  const char* containsHeader(const char* name);
1218 
1227  const char* encodeRedirectURL(const char* pathName);
1228 
1238  const char* encodeRedirectURLWithParam(const char* pathName);
1239 
1246  const char* encodeUrl(const char* path);
1247 
1252  int flush();
1253 
1279  int forward(const char* path);
1280 
1301  int redirect(const char* path);
1302 
1303 
1307 
1311 
1312 
1328  int include(const char* path);
1329 
1334  bool committed() const;
1335 
1339  bool isForward() const;
1340 
1343  bool isInclude() const;
1344 
1348  bool initial() const;
1349 
1353  int resetHeaders();
1354 
1359  int resetBuffer();
1360 
1372  int sendError(int eCode);
1373 
1387  int sendError(int eCode, const char* msg);
1388 
1394  int sendBufAsError(int eCode);
1395 
1401  int sendBufAsTxtError(int eCode);
1402 
1403 
1410  int fmtError(int eCode, const char* fmt, ...);
1411 
1429  int sendRedirect(const char* url);
1430 
1442  int redirect2TLS();
1443 
1449  int setContentLength(BaFileSize len);
1450 
1456  int setContentType(const char* type);
1457 
1467  int setDateHeader(const char* name, BaTime time);
1468 
1489  int setHeader(const char* name, const char* value, bool replace=true);
1490 
1496  int setMaxAge(BaTime seconds);
1497 
1498 
1531  char* fmtHeader(const char* name, int valueLen, bool replace=true);
1532 
1533 
1548  void setStatus(int statusCode);
1549 
1553  int printf(const char* fmt, ...);
1554 
1561  BufPrint* getWriter();
1562 
1571  int write(const void* data, int len, int useBuffering=TRUE);
1572 
1580  int write(const char* data, int useBuffering=TRUE);
1581 
1586  int send(const void* data, int len);
1587 
1594  int setDefaultHeaders();
1595 
1615  int setResponseBuf(BufPrint* buf, bool useDefBuffer=true);
1616 
1620  int removeResponseBuf();
1621 
1622 
1623  int setUserObj(void* userObj, bool overwrite=false);
1624 #endif
1625  NameValMM nameValMM;
1626  BufPrint headerPrint;
1627  BufPrint defaultBodyPrint;
1628  BufPrint* bodyPrint;
1629  struct HttpDir* currentDir;
1630  char* encodedURL;
1631  char* encodedRedirectURL;
1632  HttpCookie* cookieList;
1633  void* userObj;
1634  int statusCode;
1635  U32 msgLen; /* Used if request is of type HEAD, count total msg len */
1636  HttpProtocol protocol;
1637  U16 includeCounter;
1638  U16 forwardCounter;
1639  char headerSent;
1640  char printAndWriteInitialized;
1641  char useChunkTransfer;
1643 
1644 #ifdef __cplusplus
1645 extern "C" {
1646 #endif
1647 BA_API HttpCookie* HttpResponse_createCookie(
1648  struct HttpResponse* o,const char* name);
1649 BA_API const char* HttpResponse_containsHeader(
1650  HttpResponse* o, const char* name);
1651 BA_API int HttpResponse_dataAdded(HttpResponse* o, U32 size);
1652 #define HttpResponse_byteCount(o) ((o)->msgLen + (o)->bodyPrint->cursor)
1653 BA_API const char* HttpResponse_encodeRedirectURL(
1654  HttpResponse* o, const char* pathName);
1655 BA_API const char* HttpResponse_encodeRedirectURLWithParamOrSessionURL(
1656  HttpResponse* o,const char* path,BaBool setUrlCookie);
1657 #define HttpResponse_encodeRedirectURLWithParam(o, path) \
1658  HttpResponse_encodeRedirectURLWithParamOrSessionURL(o, path, FALSE)
1659 #define HttpResponse_encodeSessionURL(o, path) \
1660  HttpResponse_encodeRedirectURLWithParamOrSessionURL(o, path, TRUE)
1661 BA_API const char* HttpResponse_encodeUrl(HttpResponse* o, const char* path);
1662 BA_API int HttpResponse_flush(HttpResponse* o);
1663 #define HttpResponse_forward(o,path) HttpResponse_incOrForward(o,path,FALSE)
1664 #define HttpResponse_getConnection(o) HttpResponse_getCommand(o)->con
1665 #define HttpResponse_getRequest(o) (&HttpResponse_getCommand(o)->request)
1666 BA_API struct HttpCommand* HttpResponse_getCommand(HttpResponse*);
1667 #define HttpResponse_getBuf(o) (o)->bodyPrint->buf
1668 #define HttpResponse_getBufSize(o) (o)->bodyPrint->bufSize
1669 #define HttpResponse_getBufOffs(o) \
1670  ((o)->bodyPrint->buf + (o)->bodyPrint->cursor)
1671 #define HttpResponse_getRemBufSize(o) \
1672  ((o)->bodyPrint->bufSize - (o)->bodyPrint->cursor)
1673 #define HttpResponse_getUserObj(o) (o)->userObj
1674 BA_API int HttpResponse_incOrForward(
1675  HttpResponse* o, const char* path, BaBool isInc);
1676 BA_API int HttpResponse_redirect(HttpResponse* o, const char* path);
1677 #define HttpResponse_include(o,path) HttpResponse_incOrForward(o,path,TRUE)
1678 #define HttpResponse_isChunkTransfer(o) (o)->useChunkTransfer
1679 #define HttpResponse_committed(o) (o)->headerSent
1680 #define HttpResponse_isForward(o) ((o)->forwardCounter != 0)
1681 #define HttpResponse_isInclude(o) ((o)->includeCounter != 0)
1682 #define HttpResponse_initial(o) (!HttpResponse_isForward(o) && \
1683  !HttpResponse_isInclude(o))
1684 BA_API int HttpResponse_setResponseBuf(
1685  HttpResponse* o,BufPrint* buf,BaBool useDefBuffer);
1686 BA_API int HttpResponse_removeResponseBuf(HttpResponse* o);
1687 
1688 BA_API int HttpResponse_resetHeaders(HttpResponse* o);
1689 BA_API int HttpResponse_resetBuffer(HttpResponse* o);
1690 BA_API int HttpResponse_sendError1(HttpResponse* o, int eCode);
1691 BA_API int HttpResponse_sendError2(HttpResponse* o,int eCode,const char* msg);
1692 BA_API int HttpResponse_sendBufAsError(HttpResponse* o,int eCode);
1693 BA_API int HttpResponse_sendBufAsTxtError(HttpResponse* o,int eCode);
1694 BA_API int HttpResponse_fmtVError(
1695  HttpResponse* response,
1696  int eCode,
1697  const char* fmt,
1698  va_list varg);
1699 BA_API int HttpResponse_fmtError(
1700  HttpResponse* response,
1701  int eCode,
1702  const char* fmt, ...);
1703 BA_API int HttpResponse_sendRedirect(HttpResponse* o, const char* url);
1704 BA_API int HttpResponse_sendRedirectI(
1705  HttpResponse* o, const char* url, int status);
1706 BA_API int HttpResponse_redirect2TLS(HttpResponse* o);
1707 #define HttpResponse_forceHttps HttpResponse_redirect2TLS /* Backw. comp. */
1708 
1709 #define HttpResponse_setBufPos(o, pos) (o)->bodyPrint->cursor = pos
1710 BA_API int HttpResponse_setContentLength(HttpResponse* o, BaFileSize len);
1711 BA_API int HttpResponse_setContentType(HttpResponse* o, const char* type);
1712 BA_API int HttpResponse_checkContentType(HttpResponse* o, const char* type);
1713 BA_API int HttpResponse_setDateHeader(
1714  HttpResponse* o, const char* name, BaTime t);
1715 BA_API int HttpResponse_setHeader(
1716  HttpResponse* o,const char* name,const char* value, BaBool replace);
1717 BA_API int HttpResponse_setMaxAge(HttpResponse* response, BaTime seconds);
1718 BA_API char* HttpResponse_fmtHeader(
1719  HttpResponse* o, const char* name, int valueLen, BaBool replace);
1720 BA_API int HttpResponse_setStatus(HttpResponse* o, int eCode);
1721 BA_API int HttpResponse_vprintf(
1722  HttpResponse* o, const char* fmt, va_list argList);
1723 BA_API int HttpResponse_printf(HttpResponse* o, const char* fmt, ...);
1724 BA_API int HttpResponse_write(HttpResponse* o, const void* data, int len,
1725  int useBuffering);
1726 BA_API BufPrint* HttpResponse_getWriter(HttpResponse* o);
1727 BA_API int HttpResponse_send(HttpResponse* o, const void* data, int len);
1728 BA_API int HttpResponse_setDefaultHeaders(HttpResponse* o);
1729 BA_API int HttpResponse_downgrade(HttpResponse* o);
1730 BA_API int HttpResponse_setUserObj(
1731  HttpResponse* o,void* userObj,BaBool overwrite);
1732 BA_API int HttpResponse_printAndWriteInit(HttpResponse* o);
1733 BA_API int HttpResponse_send100Continue(HttpResponse* o);
1734 BA_API int HttpResponse_setChunkEncoding(HttpResponse* o);
1735 BA_API const char* HttpResponse_getRespData(HttpResponse* o, int* len);
1736 #define HttpResponse_getStatus(o) (o)->statusCode
1737 #ifdef __cplusplus
1738 }
1739 inline HttpCookie* HttpResponse::createCookie(const char* name) {
1740  return HttpResponse_createCookie(this, name); }
1741 inline const char* HttpResponse::containsHeader(const char* name) {
1742  return HttpResponse_containsHeader(this, name); }
1744  return HttpResponse_byteCount(this); }
1745 inline const char* HttpResponse::encodeRedirectURL(const char* pathName) {
1746  return HttpResponse_encodeRedirectURL(this, pathName); }
1747 inline const char* HttpResponse::encodeRedirectURLWithParam(const char* p) {
1748  return HttpResponse_encodeRedirectURLWithParam(this, p); }
1749 inline const char* HttpResponse::encodeUrl(const char* path) {
1750  return HttpResponse_encodeUrl(this, path); }
1751 inline int HttpResponse::flush() {
1752  return HttpResponse_flush(this); }
1753 inline int HttpResponse::forward(const char* path) {
1754  return HttpResponse_forward(this, path); }
1755 inline int HttpResponse::redirect(const char* path) {
1756  return HttpResponse_redirect(this, path); }
1757 inline int HttpResponse::include(const char* path) {
1758  return HttpResponse_include(this, path); }
1759 inline bool HttpResponse::committed() const {
1760  return HttpResponse_committed(this) ? true : false; }
1761 inline bool HttpResponse::isForward() const {
1762  return HttpResponse_isForward(this) ? true : false; }
1763 inline bool HttpResponse::isInclude() const {
1764  return HttpResponse_isInclude(this) ? true : false; }
1765 inline bool HttpResponse::initial() const {
1766  return HttpResponse_initial(this) ? true : false; }
1767 inline int HttpResponse::setResponseBuf(BufPrint* buf, bool useDefBuffer) {
1768  return HttpResponse_setResponseBuf(this, buf, useDefBuffer?TRUE:FALSE); }
1770  return HttpResponse_removeResponseBuf(this); }
1772  return HttpResponse_resetHeaders(this); }
1774  return HttpResponse_resetBuffer(this); }
1775 inline int HttpResponse::sendError(int eCode) {
1776  return HttpResponse_sendError1(this, eCode); }
1777 inline int HttpResponse::sendError(int eCode, const char* msg) {
1778  return HttpResponse_sendError2(this, eCode, msg); }
1779 inline int HttpResponse::sendBufAsError(int eCode) {
1780  return HttpResponse_sendBufAsError(this, eCode); }
1781 inline int HttpResponse::sendBufAsTxtError(int eCode) {
1782  return HttpResponse_sendBufAsTxtError(this,eCode);}
1783 inline int HttpResponse::fmtError(int eCode,const char* fmt,...) {
1784  int retv; va_list varg;
1785  va_start(varg, fmt);
1786  retv = HttpResponse_fmtVError(this, eCode, fmt, varg);
1787  va_end(varg);
1788  return retv; }
1789 inline int HttpResponse::sendRedirect(const char* url) {
1790  return HttpResponse_sendRedirect(this, url); }
1792  return HttpResponse_redirect2TLS(this); }
1793 inline int HttpResponse::setContentLength(BaFileSize len) {
1794  return HttpResponse_setContentLength(this, len); }
1795 inline int HttpResponse::setContentType(const char* type) {
1796  return HttpResponse_setContentType(this, type); }
1797 inline int HttpResponse::setDateHeader(const char* name, BaTime t) {
1798  return HttpResponse_setDateHeader(this, name, t); }
1800  const char* name, const char* value, bool replace) {
1801  return HttpResponse_setHeader(this,name, value, replace?TRUE:FALSE); }
1802 inline int HttpResponse::setMaxAge(BaTime seconds) {
1803  return HttpResponse_setMaxAge(this, seconds); }
1805  const char* name, int valueLen, bool replace) {
1806  return HttpResponse_fmtHeader(this, name, valueLen, replace?TRUE:FALSE); }
1807 inline void HttpResponse::setStatus(int eCode) {
1808  HttpResponse_setStatus(this, eCode);}
1809 
1810 inline int HttpResponse::printf(const char* fmt, ...) {
1811  int retv; va_list varg; va_start(varg, fmt);
1812  retv = HttpResponse_vprintf(this, fmt, varg); va_end(varg); return retv;}
1813 inline int HttpResponse::write(const char* data, int useBuffering) {
1814  return HttpResponse_write(this, data, iStrlen(data), useBuffering); }
1816  return HttpResponse_getWriter(this); }
1817 inline int HttpResponse::write(const void* data, int len, int useBuffering){
1818  return HttpResponse_write(this, data, len, useBuffering); }
1819 inline int HttpResponse::send(const void* data, int len) {
1820  return HttpResponse_send(this, data, len); }
1822  return HttpResponse_setDefaultHeaders(this); }
1823 inline int HttpResponse::setUserObj(void* userObj, bool overwrite) {
1824  return HttpResponse_setUserObj(this, userObj, overwrite); }
1825 
1826 #endif
1827 
1833 typedef struct HttpCommand
1834 {
1835 #ifdef __cplusplus
1836 
1840 
1844 
1848  struct HttpConnection* getConnection();
1849 
1851  struct HttpServer* getServer();
1852 
1853  HttpCommand() {}
1854 #endif
1855  DoubleLink super;
1856 #ifdef __cplusplus
1857  public:
1858 #endif
1859  HttpRequest request;
1860  HttpResponse response;
1861  struct HttpConnection* con;
1862  struct LHttpCommand* lcmd; /* Used by LSP plugin */
1863  BaTime requestTime;
1864  BaBool runningInThread;
1866 
1867 #define HttpCommand_getRequest(o) (&(o)->request)
1868 #define HttpCommand_getResponse(o) (&(o)->response)
1869 #define HttpCommand_getConnection(o) (o)->con
1870 #define HttpCommand_getServer(o) HttpConnection_getServer((o)->con)
1871 #ifdef __cplusplus
1873  return HttpCommand_getRequest(this); }
1875  return HttpCommand_getResponse(this); }
1877  return HttpCommand_getConnection(this); }
1879  return HttpCommand_getServer(this);
1880 }
1881 #endif
1882 
1883 
1884 #ifndef NO_HTTP_SESSION
1885 
1886 #ifndef __DOXYGEN__
1887 struct HttpSessionAttribute;
1888 struct HttpSessionContainer;
1889 #endif
1890 
1898  struct HttpSessionAttribute* o);
1899 
1927 typedef struct HttpSessionAttribute
1928 {
1929 #ifdef __cplusplus
1930 
1935  HttpSessionAttribute(const char* name,
1937 
1941 #endif
1942  struct HttpSessionAttribute* next;
1943  struct HttpSession* session;
1945  char* name;
1947 
1948 #ifdef __cplusplus
1949 extern "C" {
1950 #endif
1951 
1952 BA_API void HttpSessionAttribute_constructor(
1954  const char* name,
1956 BA_API void HttpSessionAttribute_destructor(HttpSessionAttribute* o);
1957 #define HttpSessionAttribute_getSession(o) (o)->session
1958 #ifdef __cplusplus
1959 }
1961  const char* name,
1963  HttpSessionAttribute_constructor(this, name, d); }
1965  return HttpSessionAttribute_getSession(this); }
1966 
1967 #endif
1968 
1974 typedef struct HttpSession
1975 {
1976 #ifdef __cplusplus
1977 
1978  void *operator new(size_t s) { return ::baMalloc(s); }
1979  void operator delete(void* d) { if(d) ::baFree(d); }
1980  void *operator new(size_t, void *place) { return place; }
1981  void operator delete(void*, void *) { }
1982 
1997  void terminate();
1998 
2002  HttpSessionAttribute* getAttribute(const char* name);
2003 
2008 
2014 
2019 
2021  HttpServer* getServer();
2022 
2025  int removeAttribute(const char* name);
2026 
2029  int setAttribute(HttpSessionAttribute* value);
2030 
2034  void setMaxInactiveInterval(BaTime interval);
2035 
2041  void incrRefCntr();
2042 
2048  void decrRefCntr();
2049 
2053  U32 getId();
2054 
2058 
2061  U32 getUseCounter();
2062 
2063 
2064  void incrementLock();
2065  void decrementLock();
2066 
2067  HttpSession() {}
2068  private:
2069 #endif
2070  SplayTreeNode super; /* inherits from SplayTreeNode */
2071  DoubleLink dlink;
2072  HttpSockaddr peer;
2073  HttpSessionAttribute* attrList;
2074  struct HttpSessionContainer* container;
2075  BaTime creationTime;
2076  BaTime lastAccessedTime;
2077  BaTime maxInactiveInterval;
2078  U32 sesrnd1; /* Session random number 1 & 2 */
2079  U32 sesrnd2; /* entropy id+sesrnd1+sesrnd2=96 bits */
2080  U32 useCounter;
2081  int refCounter;
2082  U16 lockCounter;
2083  U8 termPending; /* TRUE if in termination list */
2085 
2086 
2087 #ifdef __cplusplus
2088 extern "C" {
2089 #endif
2090 BA_API HttpSessionAttribute* HttpSession_getAttribute(HttpSession* o,
2091  const char* name);
2092 BA_API BaTime HttpSession_getCreationTime(HttpSession* o);
2093 BA_API BaTime HttpSession_getLastAccessedTime(HttpSession* o);
2094 BA_API BaTime HttpSession_getMaxInactiveInterval(HttpSession* o);
2095 BA_API struct HttpServer* HttpSession_getServer(HttpSession* o);
2096 BA_API void HttpSession_terminate(HttpSession* o);
2097 BA_API BaBool HttpSession_isNew(HttpSession* o);
2098 BA_API int HttpSession_removeAttribute(HttpSession* o, const char* name);
2099 BA_API int HttpSession_setAttribute(HttpSession* o,
2100  HttpSessionAttribute* value);
2101 BA_API void HttpSession_setMaxInactiveInterval(HttpSession* o,BaTime interval);
2102 #define HttpSession_incrRefCntr(o) (o)->refCounter++
2103 BA_API void HttpSession_decrRefCntr(HttpSession* o);
2104 #define HttpSession_incrementLock(o) (o)->lockCounter++
2105 #define HttpSession_decrementLock(o) do {\
2106  baAssert((o)->lockCounter > 0);\
2107  (o)->lockCounter--; } while(0)
2108 BA_API int HttpSession_fmtSessionId(HttpSession* o, U8* buf, size_t bufSize);
2109 #define HttpSession_getId(o) \
2110  ((U32)((ptrdiff_t)SplayTreeNode_getKey((SplayTreeNode*)(o))))
2111 #define HttpSession_getAuthenticatedUser(o) AuthenticatedUser_get2((o))
2112 #define HttpSession_getUseCounter(o) (o)->useCounter
2113 #define HttpSession_getPeerName(o) (&(o)->peer)
2114 #ifdef __cplusplus
2115 }
2117  return HttpSession_getAttribute(this, name); }
2119  return HttpSession_getCreationTime(this); }
2121  return HttpSession_getLastAccessedTime(this); }
2123  return HttpSession_getMaxInactiveInterval(this); }
2125  return HttpSession_getServer(this); }
2126 inline void HttpSession::terminate() {
2127  HttpSession_terminate(this); }
2128 inline int HttpSession::removeAttribute(const char* name) {
2129  return HttpSession_removeAttribute(this, name); }
2131  return HttpSession_setAttribute(this, value); }
2133  HttpSession_setMaxInactiveInterval(this, interval); }
2135  HttpSession_incrRefCntr(this); }
2137  HttpSession_decrRefCntr(this); }
2138 inline U32 HttpSession::getId() { return HttpSession_getId(this); }
2140  return HttpSession_getUseCounter(this); }
2142  return HttpSession_getAuthenticatedUser(this); }
2143 inline void HttpSession::incrementLock() {HttpSession_incrementLock(this);}
2144 inline void HttpSession::decrementLock() {HttpSession_decrementLock(this);}
2145 
2146 #endif /* __cplusplus */
2147 
2148 typedef enum {
2149  HttpSessionContainer_OK = 0,
2150  HttpSessionContainer_NoMemory,
2151  HttpSessionContainer_TooManySessions,
2152  HttpSessionContainer_NoPeerAddress
2153 } HttpSessionContainer_ECode;
2154 
2155 
2159 typedef struct HttpSessionContainer
2160 {
2161 #ifdef __cplusplus
2168  void setMaxSessions(int max);
2169  private:
2170 #endif
2171  SplayTree sessionTree;
2172  DoubleList sessionList;
2173  DoubleList sessionTermList;
2174  DoubleLink* sessionLinkIter;
2175  struct HttpServer* server;
2176  int noOfSessions; /* Current number of active sessions */
2177  int maxSessions;
2178  HttpSessionContainer_ECode eCode;
2180 
2181 #ifdef __cplusplus
2182 extern "C" {
2183 #endif
2184 void HttpSessionContainer_constructor(struct HttpSessionContainer* o,
2185  struct HttpServer* server,
2186  U16 maxSessions);
2187 void HttpSessionContainer_destructor(struct HttpSessionContainer* o);
2188 void HttpSessionContainer_sessionTimer(struct HttpSessionContainer* o);
2189 #define HttpSessionContainer_setMaxSessions(o,max) (o)->maxSessions = max
2190 #ifdef __cplusplus
2191 }
2193  HttpSessionContainer_setMaxSessions(this, max); }
2194 #endif
2195 
2196 #endif /* NO_HTTP_SESSION */
2197 
2198 
2206 typedef void (*HttpPage_Service)(struct HttpPage* page,
2207  HttpRequest* request,
2208  HttpResponse* response);
2209 
2210 
2211 #define HttpPageType_HttpPageSE 0x00020
2212 
2213 #ifndef __DOXYGEN__
2214 typedef struct HttpPageNode
2215 {
2216  struct HttpPageNode* next;
2217 } HttpPageNode;
2218 #endif
2219 
2271 typedef struct HttpPage
2272 {
2273 #ifdef __cplusplus
2274  void *operator new(size_t s) { return ::baMalloc(s); }
2275  void operator delete(void* d) { if(d) ::baFree(d); }
2276  void *operator new(size_t, void *place) { return place; }
2277  void operator delete(void*, void *) { }
2278  HttpPage() {}
2287  HttpPage(HttpPage_Service service, const char* name);
2288 
2291  ~HttpPage();
2292 
2295  const char* getName() const { return name; }
2296 
2301  void service(HttpRequest* request, HttpResponse* response);
2302 
2306  bool isLinked();
2307 
2310  int unlink();
2311 #endif
2312  HttpPageNode super; /* As if inherited */
2313  HttpPage_Service serviceCB;
2314  const char* name;
2316 
2317 #ifdef __cplusplus
2318 extern "C" {
2319 #endif
2320 void
2321 BA_API HttpPage_constructor(
2322  HttpPage* o, HttpPage_Service service, const char* name);
2323 BA_API void HttpPage_destructor(HttpPage* o);
2324 #define HttpPage_getName(o) (o)->name
2325 #define HttpPage_isLinked(o) ((HttpPageNode*)(o))->next
2326 BA_API int HttpPage_unlink(HttpPage* o);
2327 #define HttpPage_service(o, request, response) \
2328  (o)->serviceCB(o, request, response)
2329 #ifdef __cplusplus
2330 }
2331 inline HttpPage::HttpPage(HttpPage_Service service, const char* name) {
2332  HttpPage_constructor(this, service, name); }
2334  HttpPage_destructor(this); }
2335 inline bool HttpPage::isLinked() {
2336  return HttpPage_isLinked(this) ? true : false;
2337 }
2338 inline int HttpPage::unlink() {return HttpPage_unlink(this); }
2339 inline void HttpPage::service(HttpRequest* request, HttpResponse* response) {
2340  HttpPage_service(this, request, response);
2341 }
2342 #endif
2343 
2344 
2350 typedef int (*HttpDir_Service)(struct HttpDir* o,
2351  const char* relPath,
2352  HttpCommand* cmd);
2353 
2354 #define HttpDirType_EhDir 0x00001
2355 #define HttpDirType_HttpResRdr 0x00002
2356 #define HttpDirType_AuthenticateDir 0x00008
2357 #define HttpDirType_AuthenticateDirWrapper 0x00010
2358 
2359 
2383 typedef struct HttpDir
2384 {
2385 #ifdef __cplusplus
2386  void *operator new(size_t s) { return ::baMalloc(s); }
2387  void operator delete(void* d) { if(d) ::baFree(d); }
2388  void *operator new(size_t, void *place) { return place; }
2389  void operator delete(void*, void *) { }
2391  HttpDir();
2392 
2409  HttpDir(const char* name, S8 priority=0);
2410  ~HttpDir();
2411 
2415  int insertDir(HttpDir* dir);
2416 
2420  int insertPage(HttpPage* page);
2421 
2425 
2428  HttpDir* getFirstDir();
2429 
2432  HttpDir* getDir(const char* name);
2433 
2436  HttpPage* getPage(const char* name);
2437 
2440  HttpDir* getNext();
2441 
2451  HttpPage* findPage(HttpPage* iter, const char* name);
2452 
2464  static HttpDir* findDir(HttpDir* iter, const char* name,
2465  unsigned int nameLen);
2466 
2473  HttpDir* createOrGet(const char* name);
2474 
2477  const char* getName() const { return name; }
2478 
2481  HttpDir* getParent() const { return parent; }
2482 
2505  char* makeAbsPath(const char* relPath, int relPathLen);
2506 
2518  char* getRootPath();
2519 
2520 
2525 
2535  void p403(const char* p403);
2536 
2540  bool isLinked();
2541 
2544  int unlink();
2545 
2557  void setAuthenticator(
2558  struct AuthenticatorIntf* authenticator,
2559  struct AuthorizerIntf* authorizer=0);
2560 
2581  bool authenticateAndAuthorize(HttpCommand* cmd,const char* path);
2582 
2583 
2584 #endif
2585  HttpDir_Service service;
2586  struct HttpDir* parent; /* owner */
2587  struct HttpDir* next; /* next sibling */
2588  const char* name; /* e.g. /mydir/ */
2589  struct HttpDir* dirList; /* list of httpdirs (children) */
2590  struct AuthorizerIntf* realm; /* If we have authorization */
2591  struct AuthenticatorIntf* authenticator; /* If we have authentic. */
2592  char* _p403; /* If we have a 403 denied response page. */
2593  HttpPageNode pageList; /* pages for this dir */
2594  /* U8 type; */
2595  S8 priority;
2597 
2598 #ifdef __cplusplus
2599 extern "C" {
2600 #endif
2601 BA_API void HttpDir_constructor(HttpDir* o, const char* name, S8 priority);
2602 BA_API void HttpDir_destructor(HttpDir* o);
2603 BA_API char* HttpDir_makeAbsPath(
2604  HttpDir* o, const char* relPath, int relPathLen);
2605 #define HttpDir_getRootPath(o) HttpDir_makeAbsPath(o,"",0)
2606 BA_API int HttpDir_insertDir(HttpDir* o, HttpDir* dir);
2607 #define HttpDir_getFirstPage(o) \
2608  (o)->pageList.next != &(o)->pageList ? ((HttpPage*)(o)->pageList.next) : 0
2609 #define HttpDir_getFirstDir(o) (o)->dirList
2610 BA_API HttpDir* HttpDir_getDir(HttpDir* o, const char* name);
2611 BA_API HttpPage* HttpDir_getPage(HttpDir* o, const char* name);
2612 #define HttpDir_getNext(o) (o)->next
2613 #define HttpDir_getName(o) (o)->name
2614 #define HttpDir_getParent(o) (o)->parent
2615 BA_API int HttpDir_insertPage(HttpDir* o, HttpPage* page);
2616 BA_API HttpPage* HttpDir_findPage(
2617  HttpDir* o, HttpPage* iter, const char* name);
2618 BA_API HttpDir* HttpDir_findDir(
2619  HttpDir* iter, const char* name,unsigned int nameLen);
2620 BA_API HttpDir* HttpDir_createOrGet(HttpDir* o, const char* name);
2621 BA_API void HttpDir_p403(HttpDir* o, const char* p403);
2622 BA_API HttpDir_Service HttpDir_overloadService(HttpDir*o, HttpDir_Service s);
2623 #define HttpDir_isLinked(o) (o)->parent
2624 BA_API int HttpDir_unlink(HttpDir* o);
2625 #define HttpDir_setAuthenticator(o,authenticatorMA,authorizerMA) \
2626  (o)->authenticator = authenticatorMA,(o)->realm = authorizerMA
2627 BA_API int HttpDir_authenticateAndAuthorize(
2628  HttpDir* o,HttpCommand* cmd,const char* path);
2629 #define HttpDir_isAuthorized(o,user,method,path) \
2630  ((o)->realm ? \
2631  (user ? AuthorizerIntf_authorize((o)->realm,user,method,path) : FALSE) : \
2632  TRUE)
2633 #ifdef __cplusplus
2634 }
2636  HttpDir_constructor(this, 0, 0); }
2637 inline HttpDir::HttpDir(const char* name, S8 priority) {
2638  HttpDir_constructor(this, name, priority); }
2639 inline HttpDir::~HttpDir() {
2640  HttpDir_destructor(this); }
2641 inline char* HttpDir::makeAbsPath(const char* relPath, int relPathLen) {
2642  return HttpDir_makeAbsPath(this, relPath, relPathLen); }
2643 inline char* HttpDir::getRootPath() {
2644  return HttpDir_getRootPath(this); }
2645 inline int HttpDir::insertDir(HttpDir* dir) {
2646  return HttpDir_insertDir(this, dir); }
2647 inline int HttpDir::insertPage(HttpPage* page) {
2648  return HttpDir_insertPage(this, page); }
2649 inline HttpPage* HttpDir::getFirstPage() { return HttpDir_getFirstPage(this); }
2650 inline HttpDir* HttpDir::getFirstDir() { return HttpDir_getFirstDir(this); }
2651 inline HttpDir* HttpDir::getDir(const char* name) {
2652  return HttpDir_getDir(this,name); }
2653 inline HttpPage* HttpDir::getPage(const char* name) {
2654  return HttpDir_getPage(this,name); }
2655 inline HttpDir* HttpDir::getNext() { return HttpDir_getNext(this); }
2656 inline HttpPage* HttpDir::findPage(HttpPage* iter, const char* name) {
2657  return HttpDir_findPage(this, iter, name); }
2658 inline HttpDir* HttpDir::findDir(HttpDir* iter, const char* name,
2659  unsigned int nameLen) {
2660  return HttpDir_findDir(iter, name, nameLen); }
2661 inline HttpDir* HttpDir::createOrGet(const char* name) {
2662  return HttpDir_createOrGet(this, name); }
2664  return HttpDir_overloadService(this, s); }
2665 inline void HttpDir::p403(const char* p403) {
2666  HttpDir_p403(this, p403); }
2667 inline int HttpDir::unlink() {return HttpDir_unlink(this); }
2668 inline bool HttpDir::isLinked() {
2669  return HttpDir_isLinked(this) ? true : false; }
2670 inline void HttpDir::setAuthenticator(struct AuthenticatorIntf* authenticator,
2671  struct AuthorizerIntf* authorizer){
2672  HttpDir_setAuthenticator(this,authenticator,authorizer);
2673 }
2675  HttpCommand* cmd, const char* path) {
2676  return HttpDir_authenticateAndAuthorize(this,cmd,path) ? true : false; }
2677 #endif
2678 
2679 #ifndef __DOXYGEN__
2680 
2681 typedef struct HttpLinkCon
2682 {
2683  HttpConnection con; /* Inherits from HttpConnection */
2684  DoubleLink link;
2685 } HttpLinkCon;
2686 
2687 
2688 typedef struct
2689 {
2690  HttpDir super; /* inherit */
2691  HttpDir_Service superServiceFunc;
2692  char* page404;
2693  BaBool page404InProgress;
2694 } HttpRootDir;
2695 
2696 #endif
2697 
2706 typedef struct HttpServerConfig
2707 {
2708 #ifdef __cplusplus
2709 
2714  HttpServerConfig();
2715 
2745  int setRequest(S16 min, S16 max);
2746 
2758  int setResponseHeader(U16 min, U16 max);
2759 
2772  int setResponseData(U16 size);
2773 
2787  int setCommit(U16 size);
2788 
2801  int setNoOfHttpCommands(U16 size);
2802 
2824  int setNoOfHttpConnections(U16 size);
2825 
2831  int setMaxSessions(U16 size);
2832 #endif
2833  S16 minRequest;
2834  S16 maxRequest;
2835  U16 minResponseHeader;
2836  U16 maxResponseHeader;
2837  U16 commit;
2838  U16 responseData;
2839  U16 noOfHttpCommands;
2840  U16 noOfHttpConnections;
2841  U16 maxSessions;
2843 
2844 #ifdef __cplusplus
2845 extern "C" {
2846 #endif
2847 BA_API void HttpServerConfig_constructor(HttpServerConfig* o);
2848 BA_API int HttpServerConfig_setRequest(HttpServerConfig* o, S16 min, S16 max);
2849 BA_API int HttpServerConfig_setResponseHeader(
2850  HttpServerConfig* o, U16 min, U16 max);
2851 BA_API int HttpServerConfig_setResponseData(HttpServerConfig* o, U16 size);
2852 BA_API int HttpServerConfig_setCommit(HttpServerConfig* o, U16 size);
2853 BA_API int HttpServerConfig_setNoOfHttpCommands(HttpServerConfig* o, U16 size);
2854 BA_API int HttpServerConfig_setNoOfHttpConnections(
2855  HttpServerConfig* o, U16 size);
2856 BA_API int HttpServerConfig_setMaxSessions(HttpServerConfig* o, U16 size);
2857 #ifdef __cplusplus
2858 }
2860  HttpServerConfig_constructor(this); }
2861 inline int HttpServerConfig::setRequest(S16 min, S16 max) {
2862  return HttpServerConfig_setRequest(this, min, max); }
2863 inline int HttpServerConfig::setResponseHeader(U16 min, U16 max) {
2864  return HttpServerConfig_setResponseHeader(this, min, max); }
2866  return HttpServerConfig_setResponseData(this, size); }
2867 inline int HttpServerConfig::setCommit(U16 size) {
2868  return HttpServerConfig_setCommit(this, size); }
2870  return HttpServerConfig_setNoOfHttpCommands(this, size); }
2872  return HttpServerConfig_setNoOfHttpConnections(this, size); }
2873 inline int HttpServerConfig::setMaxSessions(U16 size) {
2874  return HttpServerConfig_setMaxSessions(this, size); }
2875 
2876 #endif
2877 
2878 
2879 typedef DoubleList HttpLinkConList;
2880 
2881 /* Used by LSP plugin */
2882 typedef void (*LspOnTerminateRequest)(struct LHttpCommand* lcmd);
2883 
2886 typedef struct HttpServer
2887 {
2888 #ifdef __cplusplus
2889  void *operator new(size_t s) { return ::baMalloc(s); }
2890  void operator delete(void* d) { if(d) ::baFree(d); }
2891  void *operator new(size_t, void *place) { return place; }
2892  void operator delete(void*, void *) { }
2899  HttpServer(SoDisp* dispatcher, HttpServerConfig* cfg=0);
2900 
2901  ~HttpServer();
2902 
2914  int insertRootDir(HttpDir* dir);
2915 
2937  int insertDir(const char* virtualDirRootPath, HttpDir* dir);
2938 
2978  int insertCSP(CspInit cspInit,
2979  const char* virtualDirRootPath,
2980  struct CspReader* reader);
2981 
2982  struct AuthUserList* getAuthUserList(const char* name);
2983 
2985  ThreadMutex* getMutex();
2986 
2988  SoDisp* getDispatcher();
2989 
2995 
2999 
3000 #ifndef NO_HTTP_SESSION
3001 
3010  HttpSession* getSession(U32 id);
3011 #endif
3012 
3022  void set404Page(const char* page404);
3023 
3025  const char* get404Page();
3026 
3027  int setUserObj(void* userObj, bool overwrite=false);
3028 
3034  static void initStatic(void);
3035 
3046  static void setErrHnd(UserDefinedErrHandler e);
3047 
3048  /* No longer used */
3049  static int setZlib(ZlibInflateInit2 init,
3050  ZlibInflate inflate,
3051  ZlibInflateEnd end){
3052  (void)init; (void)inflate; (void)end;
3053  return 0; }
3056  static const char* getStatusCode(int code);
3057 
3058 
3059 #endif
3060  DoubleList commandPool;
3061  DoubleList cmdReqList;
3062  HttpConnection noOpCon;
3063  HttpLinkConList freeList;
3064  HttpLinkConList readyList;
3065  HttpLinkConList connectedList;
3066  HttpRootDir rootDirContainer;
3067  SplayTree authUserTree; /* Used by AuthenticatedUser.c */
3068  struct HttpCmdThreadPoolIntf* threadPoolIntf;
3069  HttpLinkCon* connections;
3070  SoDisp* dispatcher;
3071  void* userObj;
3072  void* waitForConClose; /* See HttpServer_doLingeringClose */
3073  LspOnTerminateRequest lspOnTerminateRequest;
3074  int commandPoolSize;
3075  U16 noOfConnections;
3076  S16 maxHttpRequestLen;
3077 #ifndef NO_HTTP_SESSION
3078  HttpSessionContainer sessionContainer;
3079 #endif
3081 
3082 
3083 /* Used exclusively by HttpCmdThreadPool */
3084 void HttpServer_AsynchProcessDir(HttpServer* o,
3085  HttpDir* dir,
3086  HttpCommand* cmd);
3087 /* Used exclusively by HttpCmdThreadPool */
3088 #define HttpServer_setThreadPoolIntf(o, intf) (o)->threadPoolIntf=intf
3089 #define HttpServer_luaenv(o) (o)->luaenv
3090 
3091 #ifdef __cplusplus
3092 extern "C" {
3093 #endif
3094 BA_API void HttpServer_constructor(HttpServer*,SoDisp*, HttpServerConfig*);
3095 BA_API void HttpServer_destructor(HttpServer* o);
3096 BA_API int HttpServer_insertRootDir(HttpServer* o, HttpDir* dir);
3097 BA_API int HttpServer_insertDir(HttpServer* o,
3098  const char* virtualDirRootPath,
3099  HttpDir* dir);
3100 BA_API int HttpServer_insertCSP(HttpServer* o,
3101  CspInit cspInit,
3102  const char* virtualDirRootPath,
3103  struct CspReader* reader);
3104 #define HttpServer_getAuthUserList(o, name) \
3105  (AuthUserList*)SplayTree_find(&(o)->authUserTree, name)
3106 #define HttpServer_getDispatcher(o) (o)->dispatcher
3107 #define HttpServer_getFirstRootDir(o) \
3108  HttpDir_getFirstDir((HttpDir*)&(o)->rootDirContainer)
3109 #define HttpServer_getUserObj(o) (o)->userObj
3110 #define HttpServer_getSessionContainer(o) (&(o)->sessionContainer)
3111 #define HttpServer_getMutex(o) SoDisp_getMutex((o)->dispatcher)
3112 BA_API const char* HttpServer_getStatusCode(int code);
3113 void HttpServer_addCon2ConnectedList(HttpServer* o, HttpConnection* con);
3114 void HttpServer_doLingeringClose(
3115  HttpServer* o, HttpConnection* con, BaFileSize contLen);
3116 
3117 #ifndef NO_HTTP_SESSION
3118 BA_API HttpSession* HttpServer_getSession(HttpServer* o, U32 id);
3119 #endif
3120 BA_API HttpConnection* HttpServer_getFreeCon(HttpServer* o);
3121 void HttpServer_returnFreeCon(HttpServer* o, HttpConnection* con);
3122 BA_API void HttpServer_installNewCon(HttpServer* o, HttpConnection* con);
3123 BA_API void HttpServer_setErrHnd(UserDefinedErrHandler e);
3124 void HttpServer_initStatic(void);
3125 int HttpServer_termOldestIdleCon(HttpServer* o);
3126 BA_API void HttpServer_set404Page(HttpServer*o, const char* page404);
3127 #define HttpServer_get404Page(o) (o)->rootDirContainer.page404
3128 BA_API int HttpServer_setUserObj(
3129  HttpServer* o, void* userObj, BaBool overwrite);
3130 #define HttpServer_termAllSessions(o) \
3131  HttpSessionContainer_destructor(&(o)->sessionContainer)
3132 /* No longer used */
3133 #define HttpServer_setZlib(init,inflate,end);
3134 #ifdef __cplusplus
3135 }
3137  HttpServer_constructor(this, disp, cfg); }
3138 inline HttpServer::~HttpServer() {
3139  HttpServer_destructor(this); }
3141  return HttpServer_insertRootDir(this, dir); }
3143  return HttpServer_getMutex(this);
3144 }
3145 inline int HttpServer::insertDir(const char* virtualDirRootPath,HttpDir* dir){
3146  return HttpServer_insertDir(this, virtualDirRootPath, dir); }
3147 inline int HttpServer::insertCSP(CspInit cspInit,
3148  const char* virtualDirRootPath,
3149  struct CspReader* reader) {
3150  return HttpServer_insertCSP(this, cspInit, virtualDirRootPath, reader); }
3151 inline struct AuthUserList* HttpServer::getAuthUserList(const char* name) {
3152  return HttpServer_getAuthUserList(this,name); }
3154  return HttpServer_getDispatcher(this); }
3156  return HttpServer_getFirstRootDir(this); }
3158  return HttpServer_getSessionContainer(this); }
3159 #ifndef NO_HTTP_SESSION
3161  return HttpServer_getSession(this, id); }
3162 inline void HttpServer::initStatic(void) {
3163  HttpServer_initStatic(); }
3164 inline void HttpServer::setErrHnd(UserDefinedErrHandler e) {
3165  HttpServer_setErrHnd(e); }
3166 inline void HttpServer::set404Page(const char* page404) {
3167  HttpServer_set404Page(this, page404); }
3168 inline const char* HttpServer::get404Page() {
3169  return HttpServer_get404Page(this); }
3170 inline int HttpServer::setUserObj(void* userObj, bool overwrite) {
3171  return HttpServer_setUserObj(this, userObj, overwrite); }
3172 inline const char* HttpServer::getStatusCode(int code) {
3173  return HttpServer_getStatusCode(code);
3174 }
3175 #endif
3176 
3177 
3179  return HttpRequest_getResponse(this); }
3181  return HttpRequest_getConnection(this); }
3183  return HttpResponse_getRequest(this); }
3185  return HttpResponse_getCommand(this); }
3187  return HttpRequest_getCommand(this); }
3189  return HttpConnection_getServer(this); }
3190 
3191 #endif /* __cplusplus */
3192  /* end of StdWebServer */
3194 
3195 
3196 #endif /* __httpServer_h */
HttpServer::get404Page
const char * get404Page()
Returns a pointer to the current 404 page, if any.
Definition: HttpServer.h:3168
HttpStdHeaders::getConnection
const char * getConnection()
Returns the connection type for HTTP 1.1 connections, returns "Close" or "Keep-Alive.
Definition: HttpServer.h:756
HttpResponse::setMaxAge
int setMaxAge(BaTime seconds)
Sets header "Cache-Control: max-age=seconds".
Definition: HttpServer.h:1802
HttpRequest
The HttpServer creates an HttpRequest object when the HttpServer parses a client request.
Definition: HttpServer.h:819
HttpDir::unlink
int unlink()
Unlinks/removes the directory from the parent directory.
Definition: HttpServer.h:2667
HttpSession::setAttribute
int setAttribute(HttpSessionAttribute *value)
Binds an object to this session, using the name specified.
Definition: HttpServer.h:2130
HttpDir::getRootPath
char * getRootPath()
Calculates the root of where the HttpDir instance is installed in the virtual file system.
Definition: HttpServer.h:2643
SoDisp
The SoDisp dispatches any socket connection that contains data by calling the SoDispCon::execute memb...
Definition: SoDisp.h:86
HttpSession::incrRefCntr
void incrRefCntr()
Increments the session reference counter.
Definition: HttpServer.h:2134
HttpCommand::getRequest
HttpRequest * getRequest()
Get the request object.
Definition: HttpServer.h:1872
HttpRequest::getParameter
const char * getParameter(const char *paramName)
Returns the value of a request parameter as a const char* or null if the parameter does not exist.
Definition: HttpServer.h:1142
HttpCookie::setDomain
void setDomain(const char *pattern)
Specifies the domain within which this cookie should be presented.
Definition: HttpServer.h:673
HttpServer::insertDir
int insertDir(const char *virtualDirRootPath, HttpDir *dir)
Insert a directory node into the virtual file system.
Definition: HttpServer.h:3145
HttpServerConfig::HttpServerConfig
HttpServerConfig()
The constructor sets up the default parameters.
Definition: HttpServer.h:2859
HttpSession::getCreationTime
BaTime getCreationTime()
Returns the time when this session was created, measured in seconds since midnight January 1,...
Definition: HttpServer.h:2118
HttpRequest::getBuffer
HttpInData * getBuffer()
Get the internal rec buffer.
Definition: HttpServer.h:1161
HttpDir::insertDir
int insertDir(HttpDir *dir)
Insert a sub-directory.
Definition: HttpServer.h:2645
HttpServerConfig::setNoOfHttpConnections
int setNoOfHttpConnections(U16 size)
Number of HttpConnection instances.
Definition: HttpServer.h:2871
HttpServer
struct HttpServer HttpServer
The Web Server.
HttpSession::getServer
HttpServer * getServer()
Get the server object.
Definition: HttpServer.h:2124
HttpRequest::getMethod
const char * getMethod()
Returns a string representation of the value returned by HttpRequest::getMethodType.
Definition: HttpServer.h:1124
HttpResponse::sendError
int sendError(int eCode)
Sends an error response as a simple HTML page to the client using the specified status code.
Definition: HttpServer.h:1775
HttpCookie::setSecure
void setSecure(bool flag)
Inform the browser whether the cookie should be sent only using a secure protocol such as HTTPS – i....
Definition: HttpServer.h:681
HttpResponse::getCommand
HttpCommand * getCommand()
Get the HttpCommand object.
Definition: HttpServer.h:3184
HttpCookie::getValue
const char * getValue() const
Returns the value of the cookie.
Definition: HttpServer.h:561
HttpMethod
HttpMethod
HTTP method types.
Definition: HttpServer.h:783
HttpParameterIterator::hasMoreElements
bool hasMoreElements()
Returns true if more elements.
Definition: HttpServer.h:1159
AuthorizerIntf
An abstract class, which you must implement, provides a method of authorizing an authenticated user.
Definition: AuthenticatedUser.h:112
HttpResponse::getWriter
BufPrint * getWriter()
Returns a BufPrint object that can send any type of data to the client.
Definition: HttpServer.h:1815
HttpStdHeaders::getContentType
const char * getContentType()
Returns the content type, for example: "application/x-www-form-urlencoded".
Definition: HttpServer.h:762
HttpPage::isLinked
bool isLinked()
Returns true if this page node is installed into a parent directory.
Definition: HttpServer.h:2335
HttpResponse::redirect
int redirect(const char *path)
Internally redirects the request to another resource.
Definition: HttpServer.h:1755
HttpSession
Provides a way to identify a user across more than one page request or visit to a web site,...
Definition: HttpServer.h:1975
HttpResponse::include
int include(const char *path)
Includes the content of a resource (servlet, CSP page, HTML file) in the response.
Definition: HttpServer.h:1757
HttpParameter::calculateSize
static U32 calculateSize(struct HttpRequest *req)
Calculate the HttpParameter size.
Definition: HttpServer.h:406
HttpServerConfig
struct HttpServerConfig HttpServerConfig
Use an instance of this class if you want to override the default web-server parameters.
HttpResponse::setContentLength
int setContentLength(BaFileSize len)
Sets the "Content-Length" parameter value.
Definition: HttpServer.h:1793
HttpSession::terminate
void terminate()
Unbinds any objects bound to this session object, runs the HttpSession destructor,...
Definition: HttpServer.h:2126
HttpRequest::getStdHeaders
HttpStdHeaders * getStdHeaders()
Returns an object containing standard HTTP headers.
Definition: HttpServer.h:1134
HttpCookie::getSecure
bool getSecure() const
Returns true if the browser is sending cookies only over a secure protocol, or false if the browser c...
Definition: HttpServer.h:553
HttpSession::getAuthenticatedUser
AuthenticatedUser * getAuthenticatedUser()
Returns the AuthenticatedUser if user is authenticated.
Definition: HttpServer.h:2141
HttpServer::getSession
HttpSession * getSession(U32 id)
Returns the HttpSession associated with id or NULL if not found.
Definition: HttpServer.h:3160
HttpRequest::checkTime
BaBool checkTime(struct HttpResponse *resp, BaTime time)
Parses and checks if the "If-Modified-Since" time is equal or greater than "time".
Definition: HttpServer.h:1118
HttpCookie::activate
void activate()
Activates the cookie.
Definition: HttpServer.h:691
HttpPage_Service
void(* HttpPage_Service)(struct HttpPage *page, HttpRequest *request, HttpResponse *response)
The HttpPage service function.
Definition: HttpServer.h:2206
HttpResponse::isForward
bool isForward() const
Returns true if this is a forward request from another servlet or CSP file.
Definition: HttpServer.h:1761
HttpSession
struct HttpSession HttpSession
Provides a way to identify a user across more than one page request or visit to a web site,...
HttpDir::getNext
HttpDir * getNext()
Returns the next dir in the parent list.
Definition: HttpServer.h:2655
HttpStdHeaders::getHost
const char * getHost()
Returns the host header.
Definition: HttpServer.h:758
HttpCookie::getName
const char * getName() const
Returns the name of the cookie.
Definition: HttpServer.h:544
HttpResponse::sendBufAsTxtError
int sendBufAsTxtError(int eCode)
Sends the data formatted into the HttpResponse buffer as an error message to the client.
Definition: HttpServer.h:1781
HttpPage::~HttpPage
~HttpPage()
The HttpPage destructor unlinks the page from the parent directory.
Definition: HttpServer.h:2333
HttpInData
The web-server "Request Data" container.
Definition: HttpServer.h:269
HttpDir::makeAbsPath
char * makeAbsPath(const char *relPath, int relPathLen)
Makes an absolute path based on where the HttpDir instance is installed in the virtual file system an...
Definition: HttpServer.h:2641
HttpServer::getSessionContainer
HttpSessionContainer * getSessionContainer()
Get the HttpSessionContainer.
Definition: HttpServer.h:3157
HttpResponse::redirect2TLS
int redirect2TLS()
Converts the URL to HTTPS and sends a redirect (301) response to the client if this is a non secure c...
Definition: HttpServer.h:1791
HttpPage
An HttpPage, which is typically created by the CSP compiler, is similar to a Java servlet.
Definition: HttpServer.h:2272
HttpRequest::getCommand
HttpCommand * getCommand()
Get the HttpCommand object.
Definition: HttpServer.h:3186
HttpDir::insertPage
int insertPage(HttpPage *page)
Insert a page in the directory.
Definition: HttpServer.h:2647
HttpDir::p403
void p403(const char *p403)
Set a 403 denied request handler.
Definition: HttpServer.h:2665
HttpDir_Service
int(* HttpDir_Service)(struct HttpDir *o, const char *relPath, HttpCommand *cmd)
The HttpDir service callback function.
Definition: HttpServer.h:2350
HttpCookie::getDomain
const char * getDomain() const
Returns the domain name set for this cookie.
Definition: HttpServer.h:536
HttpCookie::deleteCookie
void deleteCookie()
Specifies a path for the cookie to which the client should return the cookie.
Definition: HttpServer.h:677
HttpServerConfig::setMaxSessions
int setMaxSessions(U16 size)
Maximum allowed active HttpSession objects.
Definition: HttpServer.h:2873
HttpCookie::setPath
void setPath(const char *uri)
Set the cookie path.
Definition: HttpServer.h:679
HttpParameterIterator::nextElement
void nextElement()
Advance to the next element.
Definition: HttpServer.h:496
HttpCommand::getServer
struct HttpServer * getServer()
Get the web-server object.
Definition: HttpServer.h:1878
HttpCookie::setMaxAge
void setMaxAge(BaTime expiry)
Sets the maximum age of the cookie in seconds.
Definition: HttpServer.h:675
HttpResponse::fmtHeader
char * fmtHeader(const char *name, int valueLen, bool replace=true)
Pre-allocate memory for a {name, value} pair in the response header database.
Definition: HttpServer.h:1804
HttpDir::authenticateAndAuthorize
bool authenticateAndAuthorize(HttpCommand *cmd, const char *path)
Authenticate and authorize the user.
Definition: HttpServer.h:2674
HttpResponse::fmtError
int fmtError(int eCode, const char *fmt,...)
This method implements a printf like implementation for formatting and sending an error message.
Definition: HttpServer.h:1783
HttpRequest::getHeaders
HttpHeader * getHeaders(int *len)
Return a HTTP header iterator that can iterate and fetch all the HTTP headers.
Definition: HttpServer.h:1149
HttpServer::insertCSP
int insertCSP(CspInit cspInit, const char *virtualDirRootPath, struct CspReader *reader)
Insert and initialize a CSP Virtual Directory.
Definition: HttpServer.h:3147
HttpResponse::write
int write(const void *data, int len, int useBuffering=TRUE)
Used for sending pre-formatted data to the client.
Definition: HttpServer.h:1817
HttpServerConfig::setResponseData
int setResponseData(U16 size)
The HttpResponse object stores formatted data in the response data buffer.
Definition: HttpServer.h:2865
HttpDir::getParent
HttpDir * getParent() const
Returns the parent directory or NULL if no parent.
Definition: HttpServer.h:2481
HttpResponse::setResponseBuf
int setResponseBuf(BufPrint *buf, bool useDefBuffer=true)
This is an advanced function that makes it possible to redirect the output, which is normally sent to...
Definition: HttpServer.h:1767
HttpRequest::getRequestURI
const char * getRequestURI()
Returns the pathname.
Definition: HttpServer.h:1130
HttpServer::setErrHnd
static void setErrHnd(UserDefinedErrHandler e)
You can set your own user defined error handler for the web-server.
Definition: HttpServer.h:3164
HttpResponse::setContentType
int setContentType(const char *type)
Sets the "Content-Type" parameter value.
Definition: HttpServer.h:1795
HttpRequest::getConnection
HttpConnection * getConnection()
Returns the connection object associated with this request.
Definition: HttpServer.h:3180
HttpSessionAttribute_Destructor
void(* HttpSessionAttribute_Destructor)(struct HttpSessionAttribute *o)
HttpSessionAttribute termination callback function.
Definition: HttpServer.h:1897
HttpResponse
struct HttpResponse HttpResponse
This object is used when sending response messages back to the client.
HttpRequest::getServer
HttpServer * getServer()
Returns the web server object.
Definition: HttpServer.h:1128
HttpCommand
struct HttpCommand HttpCommand
The HttpCommand class is a container class for the HttpRequest and HttpResponse command pair.
HttpServerConfig::setNoOfHttpCommands
int setNoOfHttpCommands(U16 size)
The number of HttpCommand instances created by the web-server.
Definition: HttpServer.h:2869
AuthenticatedUser
Abstract base class implemented by BasicAuthUser, FormAuthUser and DigestAuthUser.
Definition: AuthenticatedUser.h:243
HttpRequest::wsUpgrade
int wsUpgrade()
Activate a WebSocket handshake.
Definition: HttpServer.h:1145
HttpInData::getBuf
const char * getBuf()
Get pointer to start of PUT/POST data.
Definition: HttpServer.h:304
BaTime
S64 BaTime
An arithmetic type representing calendar time with epoch of 1970-01-01 00:00:10 GMT – i....
Definition: GenPrimT.h:93
HttpSessionContainer::setMaxSessions
void setMaxSessions(int max)
Set the maximum number of session objects.
Definition: HttpServer.h:2192
HttpServerConfig::setResponseHeader
int setResponseHeader(U16 min, U16 max)
Set the size of the HTTP response header buffer.
Definition: HttpServer.h:2863
HttpSessionContainer
struct HttpSessionContainer HttpSessionContainer
The HttpSession container class.
HttpRequest
struct HttpRequest HttpRequest
The HttpServer creates an HttpRequest object when the HttpServer parses a client request.
HttpDir::HttpDir
HttpDir()
Constructor for creating a root dir, a root dir has no name.
Definition: HttpServer.h:2635
HttpResponse::printf
int printf(const char *fmt,...)
printf is used for sending formatted data to the client.
Definition: HttpServer.h:1810
HttpDir::setAuthenticator
void setAuthenticator(struct AuthenticatorIntf *authenticator, struct AuthorizerIntf *authorizer=0)
Set the optional authenticator and/or the optional AuthorizerIntf.
Definition: HttpServer.h:2670
HttpSessionAttribute
The interface to an HttpSession attribute.
Definition: HttpServer.h:1928
HttpSession::setMaxInactiveInterval
void setMaxInactiveInterval(BaTime interval)
Specifies the time, in seconds, between client requests before the session container will invalidate ...
Definition: HttpServer.h:2132
HttpResponse::encodeRedirectURL
const char * encodeRedirectURL(const char *pathName)
Encodes the specified URL into an absolute URL, or if encoding is not needed, returns the URL unchang...
Definition: HttpServer.h:1745
HttpSession::decrRefCntr
void decrRefCntr()
Decrements the session reference counter.
Definition: HttpServer.h:2136
HttpDir::findDir
static HttpDir * findDir(HttpDir *iter, const char *name, unsigned int nameLen)
Searches for a sub-directory in this directory node.
Definition: HttpServer.h:2658
HttpSession::getAttribute
HttpSessionAttribute * getAttribute(const char *name)
Returns the object bound with the specified name in this session, or null if no object is bound under...
Definition: HttpServer.h:2116
HttpResponse::setDefaultHeaders
int setDefaultHeaders()
Sets the most common header values in servlet and CSP files.
Definition: HttpServer.h:1821
HttpResponse::byteCount
U32 byteCount()
Returns number of bytes sent thus far.
Definition: HttpServer.h:1743
HttpResponse::forward
int forward(const char *path)
Forwards a request from a servlet to another resource (servlet, CSP file, or HTML file).
Definition: HttpServer.h:1753
HttpCookie
struct HttpCookie HttpCookie
A cookie is used for exchanging a small amount of information between a HttpPage and a web browser.
HttpServer::initStatic
static void initStatic(void)
The only purpose with this function is to clean all static variables that are in the BSS section; i....
Definition: HttpServer.h:3162
HttpResponse
This object is used when sending response messages back to the client.
Definition: HttpServer.h:1194
HttpParameter::getParameter
const char * getParameter(const char *paramName)
Returns the value of a request parameter as a const char*, or null if the parameter does not exist.
Definition: HttpServer.h:410
HttpCookie
A cookie is used for exchanging a small amount of information between a HttpPage and a web browser.
Definition: HttpServer.h:527
HttpRequest::getAuthenticatedUser
AuthenticatedUser * getAuthenticatedUser()
Returns the authenticated user or NULL if user is not authenticated.
Definition: HttpServer.h:1120
HttpPage::unlink
int unlink()
Unlinks/removes the page from the parent directory.
Definition: HttpServer.h:2338
CspReader
Abstract interface class for reading the "dat" file generated by.
Definition: CspRunTm.h:118
HttpServer::set404Page
void set404Page(const char *page404)
Set a more user friendly 404 page.
Definition: HttpServer.h:3166
baFree
void baFree(void *p)
Deallocates space to which it points.
HttpStdHeaders::getContentLength
SBaFileSize getContentLength()
Returns the content length if request contains a body.
Definition: HttpServer.h:764
HttpServer::HttpServer
HttpServer(SoDisp *dispatcher, HttpServerConfig *cfg=0)
Create a Web Server object.
Definition: HttpServer.h:3136
HttpServer::getMutex
ThreadMutex * getMutex()
Get the dispatcher mutex.
Definition: HttpServer.h:3142
HttpResponse::initial
bool initial() const
Returns true if this is the initial page.
Definition: HttpServer.h:1765
HttpCookie::setComment
void setComment(const char *purpose)
Specifies a comment that describes a cookie's purpose.
Definition: HttpServer.h:671
HttpDir::getName
const char * getName() const
Returns the directory name.
Definition: HttpServer.h:2477
HttpParameterIterator::getName
const char * getName() const
Return the form name.
Definition: HttpServer.h:462
HttpConnection
Contains information about the physical socket connection.
Definition: HttpConnection.h:76
NonBlockingSendBuf
Definition: HttpServer.h:121
HttpSessionContainer
The HttpSession container class.
Definition: HttpServer.h:2160
HttpSession::getLastAccessedTime
BaTime getLastAccessedTime()
Returns the last time the client sent a request associated with this session, as the number of second...
Definition: HttpServer.h:2120
HttpResponse::removeResponseBuf
int removeResponseBuf()
Remove buffer set by using setResponseBuf.
Definition: HttpServer.h:1769
HttpConnection::getServer
struct HttpServer * getServer()
Fetch the HttpServer object.
Definition: HttpServer.h:3188
baMalloc
void * baMalloc(size_t size)
Returns pointer to uninitialized newly-allocated space for an object of size "size",...
HttpDir::isLinked
bool isLinked()
Returns true if this directory node is installed into a parent directory.
Definition: HttpServer.h:2668
HttpServerConfig::setCommit
int setCommit(U16 size)
Set the size of the HTTP response commit buffer.
Definition: HttpServer.h:2867
HttpResponse::sendBufAsError
int sendBufAsError(int eCode)
Sends the data formatted into the HttpResponse buffer as an error message to the client.
Definition: HttpServer.h:1779
CspInit
void(* CspInit)(struct HttpDir *cspRoot, struct CspReader *reader)
Function prototype for the "initialize function" generated by CspLink.
Definition: HttpServer.h:193
HttpDir::getDir
HttpDir * getDir(const char *name)
Returns the first directory with the name given or NULL if not found.
Definition: HttpServer.h:2651
HttpDir
An instance of the HttpDir class, which is a collection of zero or more resources,...
Definition: HttpServer.h:2384
HttpSessionAttribute::getSession
HttpSession * getSession()
Get the session object.
Definition: HttpServer.h:1964
HttpCookie::getComment
const char * getComment() const
Returns the comment set for this cookie or null if the cookie comment is not set.
Definition: HttpServer.h:533
HttpCookie::setValue
void setValue(const char *newValue)
Assigns a new value to a cookie after the cookie is created.
Definition: HttpServer.h:685
HttpPage::getName
const char * getName() const
Returns the page name.
Definition: HttpServer.h:2295
HttpResponse::isInclude
bool isInclude() const
Returns true if this is an include from another servlet or CSP file.
Definition: HttpServer.h:1763
HttpDir
struct HttpDir HttpDir
An instance of the HttpDir class, which is a collection of zero or more resources,...
BufPrint
The BufPrint class, which implements an ANSI compatible printf method, is a base class used by severa...
Definition: BufPrint.h:122
HttpSession::removeAttribute
int removeAttribute(const char *name)
Removes the object bound with the specified name from this session.
Definition: HttpServer.h:2128
HttpSessionAttribute::HttpSessionAttribute
HttpSessionAttribute(const char *name, HttpSessionAttribute_Destructor terminate)
Create a session attribute.
Definition: HttpServer.h:1960
HttpCookie::getMaxAge
BaTime getMaxAge() const
Returns the maximum age of the cookie, specified in seconds; by default, 0 indicating the cookie will...
Definition: HttpServer.h:541
UserIntf
Interface class used by the Authentication classes.
Definition: AuthenticatedUser.h:174
HttpResponse::resetBuffer
int resetBuffer()
Clears the content of the underlying buffer in the response without clearing headers or status code.
Definition: HttpServer.h:1773
HttpResponse::getRequest
HttpRequest * getRequest()
Get the HttpRequest object.
Definition: HttpServer.h:3182
HttpResponse::sendRedirect
int sendRedirect(const char *url)
Sends a temporary redirect (302) response to the client using the specified redirect location URL.
Definition: HttpServer.h:1789
HttpRequest::getRequestURL
const char * getRequestURL(bool forceHttps=false)
Reconstructs the URL the client used to make the request.
Definition: HttpServer.h:1132
HttpDir::getFirstDir
HttpDir * getFirstDir()
Returns the first sub-directory.
Definition: HttpServer.h:2650
HttpSession::getId
U32 getId()
Returns a unique identifier assigned to this session.
Definition: HttpServer.h:2138
HttpRequest::getMethodType
HttpMethod getMethodType()
Returns the method type.
Definition: HttpServer.h:1122
HttpServer::getStatusCode
static const char * getStatusCode(int code)
Return a short description for common HTTP error codes.
Definition: HttpServer.h:3172
HttpRequest::checkMethods
int checkMethods(HttpResponse *resp, U32 methods, bool addDefault=TRUE)
Checks the HTTP method type and sends a response message if condition met.
Definition: HttpServer.h:1113
AuthenticatorIntf
Abstract interface class implemented by DigestAuthenticator, FormAuthenticator and DigestAuthenticato...
Definition: AuthenticatedUser.h:394
HttpSession::getMaxInactiveInterval
BaTime getMaxInactiveInterval()
Returns the maximum time interval, in seconds, that the session container will keep this session open...
Definition: HttpServer.h:2122
HttpServer::insertRootDir
int insertRootDir(HttpDir *dir)
Insert a root directory node.
Definition: HttpServer.h:3140
HttpServer::getFirstRootDir
HttpDir * getFirstRootDir()
Returns the first root directory.
Definition: HttpServer.h:3155
HttpInData::getBufSize
S32 getBufSize()
Get size of internal buffer.
Definition: HttpServer.h:306
HttpParameter::clone
static HttpParameter * clone(void *buf, struct HttpRequest *req)
Copy HTTP parameters to buf and return as a HttpParameter object.
Definition: HttpServer.h:408
HttpSession::getUseCounter
U32 getUseCounter()
Get the session usage counter.
Definition: HttpServer.h:2139
HttpDir::overloadService
HttpDir_Service overloadService(HttpDir_Service s)
Replace the original service function in HttpDir with your own.
Definition: HttpServer.h:2663
HttpRequest::getVersion
const char * getVersion()
Returns the HTTP version as a string, normally "1.1".
Definition: HttpServer.h:1136
HttpCommand
The HttpCommand class is a container class for the HttpRequest and HttpResponse command pair.
Definition: HttpServer.h:1834
HttpCookie::getHttpOnly
bool getHttpOnly() const
Return the HttpOnly attribute.
Definition: HttpServer.h:558
HttpParameterIterator
struct HttpParameterIterator HttpParameterIterator
The HttpParameterIterator is used for iterating through the form elements parsed by the HttpServer ob...
HttpDir::getPage
HttpPage * getPage(const char *name)
Returns the page with the name given or NULL if not found.
Definition: HttpServer.h:2653
HttpResponse::encodeUrl
const char * encodeUrl(const char *path)
Encodes an absolute or relative URL, or if encoding is not needed, returns the URL unchanged.
Definition: HttpServer.h:1749
HttpDir::getFirstPage
HttpPage * getFirstPage()
Returns the first page.
Definition: HttpServer.h:2649
HttpCookie::setHttpOnly
void setHttpOnly(bool flag)
Marks or unmarks this Cookie as HttpOnly.
Definition: HttpServer.h:683
HttpCommand::getConnection
struct HttpConnection * getConnection()
Get the current connection object that the HttpCommand instance is bound with.
Definition: HttpServer.h:1876
HttpResponse::setStatus
void setStatus(int statusCode)
Sets the status code for this response.
Definition: HttpServer.h:1807
HttpResponse::createCookie
HttpCookie * createCookie(const char *name)
Create a cookie.
Definition: HttpServer.h:1739
HttpResponse::resetHeaders
int resetHeaders()
Removes all HTTP headers.
Definition: HttpServer.h:1771
HttpResponse::committed
bool committed() const
Returns a boolean indicating if the response has been committed.
Definition: HttpServer.h:1759
HttpServer::getDispatcher
SoDisp * getDispatcher()
Returns the dispatcher object.
Definition: HttpServer.h:3153
HttpRequest::getHeaderValue
const char * getHeaderValue(const char *name)
Returns the value of the specified request header.
Definition: HttpServer.h:1138
HttpRequest::getSession
HttpSession * getSession(BaBool create=true)
Returns the current HttpSession associated with this request, or if there is no current session and c...
Definition: HttpServer.h:1156
HttpResponse::flush
int flush()
Forces any content in the buffer to be written to the client.
Definition: HttpServer.h:1751
HttpRequest::getResponse
HttpResponse * getResponse()
Returns the HttpResponse object.
Definition: HttpServer.h:3178
HttpDir::findPage
HttpPage * findPage(HttpPage *iter, const char *name)
Searches for a page in this directory node.
Definition: HttpServer.h:2656
HttpResponse::setDateHeader
int setDateHeader(const char *name, BaTime time)
Sets a response header with the given name and date-value.
Definition: HttpServer.h:1797
HttpResponse::encodeRedirectURLWithParam
const char * encodeRedirectURLWithParam(const char *pathName)
This method is similar to HttpResponse::encodeRedirectURL, but this method also includes all URL-enco...
Definition: HttpServer.h:1747
HttpParameterIterator::getValue
const char * getValue() const
Returns the form value.
Definition: HttpServer.h:464
HttpCookie::getPath
const char * getPath() const
Returns the path on the server to which the browser returns this cookie.
Definition: HttpServer.h:548
ThreadMutex
A mutual exclusion class.
Definition: ThreadLib.h:186
HttpResponse::setHeader
int setHeader(const char *name, const char *value, bool replace=true)
Sets a HTTP response header with the given name and value.
Definition: HttpServer.h:1799
HttpResponse::send
int send(const void *data, int len)
Used when sending raw data to the client.
Definition: HttpServer.h:1819
HttpStdHeaders
Standard HTTP header values.
Definition: HttpServer.h:700
HttpRequest::getCookie
HttpCookie * getCookie(const char *name)
Returns the requested cookie or NULL if no cookie matches the name.
Definition: HttpServer.h:1140
HttpParameter
A persistent container object for HTTP parameters.
Definition: HttpServer.h:368
HttpSessionAttribute
struct HttpSessionAttribute HttpSessionAttribute
The interface to an HttpSession attribute.
HttpCommand::getResponse
HttpResponse * getResponse()
Get the response object.
Definition: HttpServer.h:1874
HttpServer
The Web Server.
Definition: HttpServer.h:2887
HttpPage
struct HttpPage HttpPage
An HttpPage, which is typically created by the CSP compiler, is similar to a Java servlet.
HttpParameterIterator
The HttpParameterIterator is used for iterating through the form elements parsed by the HttpServer ob...
Definition: HttpServer.h:443
HttpResponse::containsHeader
const char * containsHeader(const char *name)
Searches the internal response header database for a header with the specified name.
Definition: HttpServer.h:1741
HttpDir::createOrGet
HttpDir * createOrGet(const char *name)
Returns a sub-directory with the given name.
Definition: HttpServer.h:2661
HttpPage::service
void service(HttpRequest *request, HttpResponse *response)
The virtual service function (C callback function) is normally run by the parent directory when deleg...
Definition: HttpServer.h:2339
HttpStdHeaders::getDomain
const char * getDomain()
Returns the host header without any port number.
Definition: HttpServer.h:760
HttpServerConfig::setRequest
int setRequest(S16 min, S16 max)
Set the size of the HTTP request buffer.
Definition: HttpServer.h:2861
HttpServerConfig
Use an instance of this class if you want to override the default web-server parameters.
Definition: HttpServer.h:2707