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 5970 2026-09-11 08:41:16Z wini $
15 *
16 * COPYRIGHT: Real Time Logic LLC, 2003 - 2026
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 "5977"
40#define BASLIB_VER_NO 5977
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 24000
91#endif
92
93
94/* This ID must match the ID in LoginKey.java */
95#define BA_COOKIE_ID "z9ZAqJtI"
96
97#ifndef __DOXYGEN__
98struct HttpRequest;
99struct HttpResponse;
100struct HttpPage;
101struct HttpServer;
102struct HttpSession;
103struct HttpLinkCon;
104struct HttpDir;
105struct AuthenticatedUser;
106struct UserIntf;
107struct CspReader;
108struct HttpCmdThreadPoolIntf;
109struct AuthUserList;
110struct AuthorizerIntf;
111struct AuthenticatorIntf;
112struct 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 for
118 HTTP connections; this pointer is not used for anything else for a
119 non-secure socket connection. */
120typedef struct
121{
122 int cursor;
123 int bufLen;
124 int maxBufLen;
125 char buf[1];
126} NonBlockingSendBuf;
127
128
129#ifdef __cplusplus
130extern "C" {
131#endif
132BA_API struct AuthenticatedUser* AuthenticatedUser_get2(
133 struct HttpSession* session);
136BA_API void httpFmtDate(char* buf, U16 bufLen, BaTime t);
137
139#define httpUnescape(s) httpUnescapeInternal(s,FALSE)
140
142#define httpFormUnescape(s) httpUnescapeInternal(s,TRUE)
143
148BA_API char* httpUnescapeInternal(char* from, BaBool isForm);
149
153BA_API char* httpEscape(char* out, const char* in);
154#ifdef __cplusplus
155}
156#endif
157
158
159typedef void (*UserDefinedErrHandler)(BaFatalErrorCodes ecode1,
160 unsigned int ecode2,
161 const char* file,
162 int line);
163
164
190typedef void (*CspInit)(
191 struct HttpDir* cspRoot,struct CspReader* reader);
192 /* end of CSP */
194
195/* no longer used. included for compatibility.
196 */
197struct z_stream_s;
198typedef int (*ZlibInflateInit2)(struct z_stream_s* s, int windowBits,
199 const char *version, int stream_size);
200
201typedef int (*ZlibInflate)(struct z_stream_s* s, int flush);
202typedef int (*ZlibInflateEnd)(struct z_stream_s* s);
203
204
205#ifndef __DOXYGEN__
206
207typedef struct
208{
209 char* buf;
210 U16 size;
211 U16 index;
212} HttpAllocator;
213
214
217typedef struct HttpHeader
218{
219#ifdef __cplusplus
220 const char* name(HttpRequest* req);
221 const char* value(HttpRequest* req);
222#endif
223 U16 nameI;
224 U16 valueI;
225}HttpHeader;
226
227#ifdef __cplusplus
228extern "C" {
229#endif
230BA_API const char* HttpHeader_name(HttpHeader* o, struct HttpRequest* req);
231BA_API const char* HttpHeader_value(HttpHeader* o, struct HttpRequest* req);
232#ifdef __cplusplus
233}
234inline const char* HttpHeader::name(HttpRequest* req) {
235 return HttpHeader_name(this, req); }
236inline const char* HttpHeader::value(HttpRequest* req) {
237 return HttpHeader_value(this, req); }
238#endif
239
240#endif
241
242
243
244
245
246/*===========================================================================
247 *
248 * HttpInData
249 *---------------------------------------------------------------------------
250 * Description:
251 */
252
253#ifndef __DOXYGEN__
254
255typedef enum {
256 HttpInData_ParseHeader,
257 HttpInData_ReadBody,
258 HttpInData_ReadBodyAndParseUrlEncData
259} HttpInData_ParseState;
260#endif
261
262
265typedef struct HttpInData
266{
267#ifdef __cplusplus
270 const char* getBuf();
271
278 S32 getBufSize();
279#endif
280 HttpAllocator allocator;
281 struct HttpRequest* request;
282 U16 lineStartI;
283 U16 lineEndI;
284 S16 maxRequest;
285 U8 parseState; /* HttpInData_ParseState */
286 U8 overflow; /* Used for pipelined requests */
287} HttpInData;
288
289#define HttpAllocator_2Ptr(o, index) ((&(o)->buf[index]))
290#define HttpInData_lineStartPtr(o) \
291 HttpAllocator_2Ptr(&(o)->allocator,(o)->lineStartI)
292
293#define HttpInData_getBufSize(o) \
294 ((o)->lineStartI < (o)->allocator.index ? \
295 (o)->allocator.index-(o)->lineStartI : 0)
296
297#define HttpInData_getBuf(o) HttpInData_lineStartPtr(o)
298BaBool HttpInData_hasMoreData(HttpInData* o);
299
300#ifdef __cplusplus
301inline const char* HttpInData::getBuf() {
302 return HttpInData_getBuf(this); }
304 return HttpInData_getBufSize(this); }
305#endif
306
307
308
364typedef struct HttpParameter
365{
366#ifdef __cplusplus
369 static U32 calculateSize(struct HttpRequest* req);
370
374 static HttpParameter* clone(void* buf, struct HttpRequest* req);
375
384 const char* getParameter(const char* paramName);
385
386 private:
387 HttpParameter() {}
388#endif
389 U16 formLen;
391
392
393#ifdef __cplusplus
394extern "C" {
395#endif
396BA_API U32 HttpParameter_calculateSize(struct HttpRequest* req);
397BA_API HttpParameter* HttpParameter_clone(void* buf, struct HttpRequest* req);
398BA_API const char* HttpParameter_getParameter(
399 HttpParameter* o,const char* paramName);
400
401#ifdef __cplusplus
402}
404 return HttpParameter_calculateSize(req); }
405inline HttpParameter* HttpParameter::clone(void* buf, struct HttpRequest* req){
406 return HttpParameter_clone(buf, req); }
407inline const char* HttpParameter::getParameter(const char* paramName) {
408 return HttpParameter_getParameter(this, paramName); }
409#endif
410
411
440{
441#ifdef __cplusplus
446
453
455 void nextElement();
457 bool hasMoreElements();
459 const char* getName() const { return name; }
461 const char* getValue() const { return value; }
462 private:
463#endif
464 void* formElemBase;
465 U8* dataEntry;
466 U16 pos;
467 U16 formLen;
468 const char* name;
469 const char* value;
470
472
473#ifdef __cplusplus
474extern "C" {
475#endif
476
477BA_API int HttpParameterIterator_constructor(
478 HttpParameterIterator* o, struct HttpRequest* req);
479BA_API int HttpParameterIterator_constructor2(HttpParameterIterator* o,
480 HttpParameter* param);
481BA_API void HttpParameterIterator_nextElement(HttpParameterIterator* o);
482#define HttpParameterIterator_hasMoreElements(o) ((o)->name != 0)
483#define HttpParameterIterator_getName(o) (o)->name
484#define HttpParameterIterator_getValue(o) (o)->value
485
486
487#ifdef __cplusplus
488}
489inline HttpParameterIterator::HttpParameterIterator(HttpRequest* req) {
490 HttpParameterIterator_constructor(this, req); }
491inline HttpParameterIterator::HttpParameterIterator(HttpParameter* param) {
492 HttpParameterIterator_constructor2(this, param); }
494 HttpParameterIterator_nextElement(this); }
495#endif
496
497
523typedef struct HttpCookie
524{
525#ifdef __cplusplus
526 ~HttpCookie();
527
530 const char* getComment() const { return comment; }
531
533 const char* getDomain() const { return domain; }
534
538 BaTime getMaxAge() const { return maxAge; }
539
541 const char* getName() const { return name; }
542
545 const char* getPath() const { return path; }
546
550 bool getSecure() const { return secure ? true : false; }
551
555 bool getHttpOnly() const { return httpOnly ? true : false; }
556
558 const char* getValue() const { return value; }
559
563 int setComment(const char* purpose);
564
568 int setDomain(const char* pattern);
569
577 void setMaxAge(BaTime expiry);
586 void deleteCookie();
587
591 int setPath(const char* uri);
592
596 void setSecure(bool flag);
597
607 void setHttpOnly(bool flag);
608
612 int setValue(const char* newValue);
613
614#if 0
616 int getVersion() const { return version; }
617 /* Sets the version of the cookie protocol this cookie complies with. */
618 void setVersion(int v);
619#endif
620
626 void activate();
627 private:
628 HttpCookie();
629#endif
630 struct HttpCookie* next;
631 char* comment;
632 char* domain;
633 char* name;
634 char* path;
635 char* value;
636 BaTime maxAge;
637 int version;
638 BaBool secure;
639 BaBool httpOnly;
640 BaBool deleteCookieFlag;
641 BaBool activateFlag; /* The cookie will be sent to the client
642 * if this flag is true */
644
645#ifdef __cplusplus
646extern "C" {
647#endif
648BA_API void HttpCookie_destructor(HttpCookie* o);
649BA_API const char* HttpCookie_getComment(HttpCookie* o);
650BA_API const char* HttpCookie_getDomain(HttpCookie* o);
651BA_API BaTime HttpCookie_getMaxAge(HttpCookie* o);
652BA_API const char* HttpCookie_getName(HttpCookie* o);
653BA_API const char* HttpCookie_getPath(HttpCookie* o);
654BA_API BaBool HttpCookie_getSecure(HttpCookie* o);
655BA_API BaBool HttpCookie_getHttpOnly(HttpCookie* o);
656BA_API const char* HttpCookie_getValue(HttpCookie* o);
657BA_API int HttpCookie_setComment(HttpCookie* o, const char* purpose);
658BA_API int HttpCookie_setDomain(HttpCookie* o, const char* pattern);
659BA_API void HttpCookie_setMaxAge(HttpCookie* o, BaTime expiry);
660#define HttpCookie_deleteCookie(o) (o)->deleteCookieFlag = TRUE;
661BA_API int HttpCookie_setPath(HttpCookie* o, const char* uri);
662BA_API void HttpCookie_setSecure(HttpCookie* o, BaBool flag);
663BA_API void HttpCookie_setHttpOnly(HttpCookie* o, BaBool flag);
664BA_API int HttpCookie_setValue(HttpCookie* o, const char* newValue);
665
666#if 0
667int HttpCookie_getVersion(HttpCookie* o);
668void HttpCookie_setVersion(HttpCookie* o, int v);
669#endif
670
671BA_API void HttpCookie_activate(HttpCookie* o);
672#ifdef __cplusplus
673}
674inline HttpCookie::HttpCookie() { baAssert(0); }
675inline HttpCookie::~HttpCookie() { HttpCookie_destructor(this); }
676inline int HttpCookie::setComment(const char* purpose) {
677 return HttpCookie_setComment(this, purpose); }
678inline int HttpCookie::setDomain(const char* pattern) {
679 return HttpCookie_setDomain(this, pattern); }
680inline void HttpCookie::setMaxAge(BaTime expiry) {
681 HttpCookie_setMaxAge(this, expiry); }
683 HttpCookie_deleteCookie(this); }
684inline int HttpCookie::setPath(const char* uri) {
685 return HttpCookie_setPath(this, uri); }
686inline void HttpCookie::setSecure(bool flag) {
687 HttpCookie_setSecure(this, flag ? TRUE : FALSE); }
688inline void HttpCookie::setHttpOnly(bool flag) {
689 HttpCookie_setHttpOnly(this, flag ? TRUE : FALSE); }
690inline int HttpCookie::setValue(const char* newValue) {
691 return HttpCookie_setValue(this, newValue); }
692#if 0
693inline void HttpCookie::setVersion(int v) {
694 HttpCookie_setVersion(this, v); }
695#endif
696inline void HttpCookie::activate() {
697 HttpCookie_activate(this); }
698#endif
699
700
704typedef struct HttpStdHeaders
705{
706#ifdef __cplusplus
710 const char* getConnection();
711
719 const char* getHost();
720
726 const char* getDomain();
727
731 const char* getContentType();
732
735 SBaFileSize getContentLength();
736#endif
737 HttpInData* inData;
738 char* domain;
739 BaFileSize contentLength;
740 U16 connectionHOffs;
741 U16 hostHOffs;
742 U16 contentTypeHOffs;
744
745#ifdef __cplusplus
746extern "C" {
747#endif
748BA_API const char* HttpStdHeaders_zzGetValFromOffs(
749 HttpStdHeaders* o, U16 offset);
750BA_API const char* HttpStdHeaders_getDomain(HttpStdHeaders* o);
751#define HttpStdHeaders_getConnection(o) \
752 HttpStdHeaders_zzGetValFromOffs(o,(o)->connectionHOffs)
753#define HttpStdHeaders_getHost(o) \
754 HttpStdHeaders_zzGetValFromOffs(o,(o)->hostHOffs)
755#define HttpStdHeaders_getContentType(o) \
756 HttpStdHeaders_zzGetValFromOffs(o,(o)->contentTypeHOffs)
757#define HttpStdHeaders_getContentLength(o) (o)->contentLength
758
759#ifdef __cplusplus
760}
761inline const char* HttpStdHeaders::getConnection() {
762 return HttpStdHeaders_getConnection(this); }
763inline const char* HttpStdHeaders::getHost() {
764 return HttpStdHeaders_getHost(this); }
765inline const char* HttpStdHeaders::getDomain() {
766 return HttpStdHeaders_getDomain(this); }
767inline const char* HttpStdHeaders::getContentType() {
768 return HttpStdHeaders_getContentType(this); }
770 return HttpStdHeaders_getContentLength(this); }
771
772#endif
773
774
775
776 /*Do not change the HttpMethod type without checking tables in Httpserver.c*/
777
788typedef enum {
789 HttpMethod_Connect =0x00001,
790 HttpMethod_Get =0x00002,
791 HttpMethod_Head =0x00004,
792 HttpMethod_Options =0x00008,
793
794 HttpMethod_Patch =0x00010,
795 HttpMethod_Post =0x00020,
796 HttpMethod_Put =0x00040,
797 HttpMethod_Trace =0x00080,
798
799 /* WebDAV */
800 HttpMethod_Copy =0x00100,
801 HttpMethod_Delete =0x00200,
802 HttpMethod_Lock =0x00400,
803 HttpMethod_Move =0x00800,
804
805 HttpMethod_Mkcol =0x01000,
806 HttpMethod_Propfind =0x02000,
807 HttpMethod_Proppatch =0x04000,
808 HttpMethod_Unlock =0x08000,
809
810 HttpMethod_Unknown =0x10000 /* Must be last */
811} HttpMethod;
812
813
814/* Convert an HTTP method from string value to the type HttpMethod */
815BA_API HttpMethod HttpMethod_a2m(const char* str);
816
817
818
823typedef struct HttpRequest
824{
825#ifdef __cplusplus
826
878 int checkMethods(HttpResponse* resp, U32 methods, bool addDefault=TRUE);
879
892 BaBool checkTime(struct HttpResponse* resp, BaTime time);
893
897
900 const char* getRequestURI();
901
914 const char* getRequestURL(bool forceHttps=false);
915
920
922 const char* getVersion();
923
931 const char* getHeaderValue(const char* name);
932
936 HttpCookie* getCookie(const char* name);
937
944
949 const char* getMethod();
950
954 static const char* getMethod(HttpMethod method);
955
966 const char* getParameter(const char* paramName);
967
972 int wsUpgrade();
973
989 HttpHeader* getHeaders(int* len);
990
991
992
1027#ifndef NO_HTTP_SESSION
1028 HttpSession* getSession(BaBool create=true);
1029#endif
1033
1037
1041
1045
1048
1049
1050 int setUserObj(void* userObj, bool overwrite=false);
1051 void* getUserObj();
1052
1053#endif
1054 HttpStdHeaders stdH;
1055 HttpAllocator headerAlloc;
1056 HttpAllocator formAlloc;
1057 HttpInData inData;
1058 struct HttpServer* server;
1059 void* userObj;
1060 struct HttpSession* session;
1061 HttpMethod methodType;
1062 U16 pathI;
1063 U16 versionI;
1064 U16 headersI;
1065 U16 headerLen;
1066 U16 formsI;
1067 U16 formLen;
1068 BaBool postDataConsumed; /* Set by MultipartUpload and HttpRecData */
1070
1071#ifdef __cplusplus
1072extern "C" {
1073#endif
1074BA_API int HttpRequest_checkMethods(HttpRequest* o, struct HttpResponse* resp,
1075 U32 methods, BaBool addDefault);
1076BA_API int HttpRequest_checkOptions(
1077 HttpRequest* o, struct HttpResponse* resp, int optLen, ...);
1078#define HttpRequest_getAuthenticatedUser(o) \
1079 AuthenticatedUser_get2(HttpRequest_getSession(o,FALSE))
1080#define HttpRequest_getConnection(o) HttpRequest_getCommand(o)->con
1081#define HttpRequest_getMethodType(o) (o)->methodType
1082#define HttpRequest_getMethod(o) HttpRequest_getMethod2((o)->methodType)
1083BA_API const char* HttpRequest_getMethod2(HttpMethod method);
1084#define HttpRequest_getServer(o) (o)->server
1085#define HttpRequest_getResponse(o) (&HttpRequest_getCommand(o)->response)
1086BA_API struct HttpCommand* HttpRequest_getCommand(HttpRequest*);
1087BA_API BaBool HttpRequest_checkTime(
1088 HttpRequest* o, struct HttpResponse* resp, BaTime time);
1089BA_API const char* HttpRequest_getRequestURI(HttpRequest* o);
1090BA_API const char* HttpRequest_getRequestURL(HttpRequest* o,BaBool forceHttps);
1091#define HttpRequest_getStdHeaders(o) (&(o)->stdH)
1092BA_API const char* HttpRequest_getVersion(HttpRequest* o);
1093BA_API const char* HttpRequest_getHeaderValue(HttpRequest* o,const char* name);
1094#define HttpRequest_getNoOfParameters(o) (o)->formLen
1095BA_API HttpCookie* HttpRequest_getCookie(HttpRequest* o, const char* name);
1096#define HttpRequest_getUserObj(o) (o)->userObj
1097BA_API int HttpRequest_setUserObj(
1098 HttpRequest* o, void* userObj, BaBool overwrite);
1099#define HttpRequest_getBuffer(o) (&(o)->inData)
1100BA_API const char* HttpRequest_getParameter(
1101 HttpRequest* o, const char* paramName);
1102BA_API HttpHeader* HttpRequest_getHeaders(HttpRequest* o, int* len);
1103BA_API int HttpRequest_wsUpgrade(HttpRequest* o);
1104BA_API BaBool HttpRequest_enableKeepAlive(HttpRequest* o);
1105BA_API int HttpRequest_pushBackData(HttpRequest* o);
1106#ifndef NO_HTTP_SESSION
1107BA_API struct HttpSession* HttpRequest_getSession(
1108 HttpRequest* o, BaBool create);
1109BA_API struct HttpSession* HttpRequest_session(
1110 HttpRequest* o, const char* val, size_t len, int set);
1111#endif
1112#ifdef __cplusplus
1113}
1114
1116 U32 methods, bool addDefault){
1117 return HttpRequest_checkMethods(this,resp,
1118 methods, addDefault ? TRUE : FALSE);}
1119
1120inline BaBool HttpRequest::checkTime(struct HttpResponse* resp, BaTime time) {
1121 return HttpRequest_checkTime(this, resp, time); }
1123 return HttpRequest_getAuthenticatedUser(this); }
1125 return HttpRequest_getMethodType(this); }
1126inline const char* HttpRequest::getMethod() {
1127 return HttpRequest_getMethod(this); }
1128inline const char* HttpRequest::getMethod(HttpMethod method) {
1129 return HttpRequest_getMethod2(method); }
1131 return HttpRequest_getServer(this); }
1132inline const char* HttpRequest::getRequestURI() {
1133 return HttpRequest_getRequestURI(this); }
1134inline const char* HttpRequest::getRequestURL(bool forceHttps) {
1135 return HttpRequest_getRequestURL(this, forceHttps); }
1137 return HttpRequest_getStdHeaders(this); }
1138inline const char* HttpRequest::getVersion() {
1139 return HttpRequest_getVersion(this); }
1140inline const char* HttpRequest::getHeaderValue(const char* name) {
1141 return HttpRequest_getHeaderValue(this, name); }
1142inline HttpCookie* HttpRequest::getCookie(const char* name) {
1143 return HttpRequest_getCookie(this, name); }
1144inline const char* HttpRequest::getParameter(const char* paramName) {
1145 return HttpRequest_getParameter(this, paramName); }
1147 return HttpRequest_wsUpgrade(this);
1148}
1149inline HttpHeader* HttpRequest::getHeaders(int* len) {
1150 return HttpRequest_getHeaders(this, len); }
1151inline int HttpRequest::setUserObj(void* userObj, bool overwrite) {
1152 return HttpRequest_setUserObj(this, userObj, overwrite); }
1153inline void* HttpRequest::getUserObj() {
1154 return HttpRequest_getUserObj(this); }
1155#ifndef NO_HTTP_SESSION
1156inline 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
1168typedef struct
1169{
1170 HttpAllocator data;
1171 U16 maxResponseHeader;
1172} NameValMM;
1173
1174
1175typedef struct
1176{
1177 U8 major;
1178 U8 minor;
1179} HttpProtocol;
1180
1181#endif
1182
1193typedef struct HttpResponse
1194{
1195#ifdef __cplusplus
1196
1199 U32 byteCount();
1200
1201
1207 HttpCookie* createCookie(const char* name);
1208
1219 const char* containsHeader(const char* name);
1220
1229 const char* encodeRedirectURL(const char* pathName);
1230
1240 const char* encodeRedirectURLWithParam(const char* pathName);
1241
1248 const char* encodeUrl(const char* path);
1249
1254 int flush();
1255
1280 int forward(const char* path);
1281
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
1445 int redirect2TLS();
1446
1452 int setContentLength(BaFileSize len);
1453
1459 int setContentType(const char* type);
1460
1470 int setDateHeader(const char* name, BaTime time);
1471
1498 int setHeader(const char* name, const char* value, bool replace=true);
1499
1505 int setMaxAge(BaTime seconds);
1506
1507
1540 char* fmtHeader(const char* name, int valueLen, bool replace=true);
1541
1542
1557 void setStatus(int statusCode);
1558
1562 int printf(const char* fmt, ...);
1563
1571
1580 int write(const void* data, int len, int useBuffering=TRUE);
1581
1589 int write(const char* data, int useBuffering=TRUE);
1590
1595 int send(const void* data, int len);
1596
1603 int setDefaultHeaders();
1604
1624 int setResponseBuf(BufPrint* buf, bool useDefBuffer=true);
1625
1629 int removeResponseBuf();
1630
1631
1632 int setUserObj(void* userObj, bool overwrite=false);
1633#endif
1634 NameValMM nameValMM;
1635 BufPrint headerPrint;
1636 BufPrint defaultBodyPrint;
1637 BufPrint* bodyPrint;
1638 struct HttpDir* currentDir;
1639 char* encodedURL;
1640 char* encodedRedirectURL;
1641 HttpCookie* cookieList;
1642 void* userObj;
1643 int statusCode;
1644 U32 msgLen; /* Used if request is of type HEAD, count total msg len */
1645 HttpProtocol protocol;
1646 U16 includeCounter;
1647 U16 forwardCounter;
1648 char headerSent;
1649 char printAndWriteInitialized;
1650 char useChunkTransfer;
1652
1653#ifdef __cplusplus
1654extern "C" {
1655#endif
1656BA_API HttpCookie* HttpResponse_createCookie(
1657 struct HttpResponse* o,const char* name);
1658BA_API const char* HttpResponse_containsHeader(
1659 HttpResponse* o, const char* name);
1660BA_API int HttpResponse_dataAdded(HttpResponse* o, U32 size);
1661#define HttpResponse_byteCount(o) ((o)->msgLen + (o)->bodyPrint->cursor)
1662BA_API const char* HttpResponse_encodeRedirectURL(
1663 HttpResponse* o, const char* pathName);
1664BA_API const char* HttpResponse_encodeRedirectURLWithParamOrSessionURL(
1665 HttpResponse* o,const char* path,BaBool setUrlCookie);
1666#define HttpResponse_encodeRedirectURLWithParam(o, path) \
1667 HttpResponse_encodeRedirectURLWithParamOrSessionURL(o, path, FALSE)
1668#define HttpResponse_encodeSessionURL(o, path) \
1669 HttpResponse_encodeRedirectURLWithParamOrSessionURL(o, path, TRUE)
1670BA_API const char* HttpResponse_encodeUrl(HttpResponse* o, const char* path);
1671BA_API int HttpResponse_flush(HttpResponse* o);
1672#define HttpResponse_forward(o,path) HttpResponse_incOrForward(o,path,FALSE)
1673#define HttpResponse_getConnection(o) HttpResponse_getCommand(o)->con
1674#define HttpResponse_getRequest(o) (&HttpResponse_getCommand(o)->request)
1675BA_API struct HttpCommand* HttpResponse_getCommand(HttpResponse*);
1676#define HttpResponse_getBuf(o) (o)->bodyPrint->buf
1677#define HttpResponse_getBufSize(o) (o)->bodyPrint->bufSize
1678#define HttpResponse_getBufOffs(o) \
1679 ((o)->bodyPrint->buf + (o)->bodyPrint->cursor)
1680#define HttpResponse_getRemBufSize(o) \
1681 ((o)->bodyPrint->bufSize - (o)->bodyPrint->cursor)
1682#define HttpResponse_getUserObj(o) (o)->userObj
1683BA_API int HttpResponse_incOrForward(
1684 HttpResponse* o, const char* path, BaBool isInc);
1685BA_API int HttpResponse_redirect(HttpResponse* o, const char* path);
1686#define HttpResponse_include(o,path) HttpResponse_incOrForward(o,path,TRUE)
1687#define HttpResponse_isChunkTransfer(o) (o)->useChunkTransfer
1688#define HttpResponse_committed(o) (o)->headerSent
1689#define HttpResponse_isForward(o) ((o)->forwardCounter != 0)
1690#define HttpResponse_isInclude(o) ((o)->includeCounter != 0)
1691#define HttpResponse_initial(o) (!HttpResponse_isForward(o) && \
1692 !HttpResponse_isInclude(o))
1693BA_API int HttpResponse_setResponseBuf(
1694 HttpResponse* o,BufPrint* buf,BaBool useDefBuffer);
1695BA_API int HttpResponse_removeResponseBuf(HttpResponse* o);
1696
1697BA_API int HttpResponse_resetHeaders(HttpResponse* o);
1698BA_API int HttpResponse_resetBuffer(HttpResponse* o);
1699BA_API int HttpResponse_sendError1(HttpResponse* o, int eCode);
1700BA_API int HttpResponse_sendError2(HttpResponse* o,int eCode,const char* msg);
1701BA_API int HttpResponse_sendBufAsError(HttpResponse* o,int eCode);
1702BA_API int HttpResponse_sendBufAsTxtError(HttpResponse* o,int eCode);
1703BA_API int HttpResponse_fmtVError(
1704 HttpResponse* response,
1705 int eCode,
1706 const char* fmt,
1707 va_list varg);
1708BA_API int HttpResponse_fmtError(
1709 HttpResponse* response,
1710 int eCode,
1711 const char* fmt, ...);
1712BA_API int HttpResponse_sendRedirect(HttpResponse* o, const char* url);
1713BA_API int HttpResponse_sendRedirectI(
1714 HttpResponse* o, const char* url, int status);
1715BA_API int HttpResponse_redirect2TLS(HttpResponse* o);
1716#define HttpResponse_forceHttps HttpResponse_redirect2TLS /* Backw. comp. */
1717
1718#define HttpResponse_setBufPos(o, pos) (o)->bodyPrint->cursor = pos
1719BA_API int HttpResponse_setContentLength(HttpResponse* o, BaFileSize len);
1720BA_API int HttpResponse_setContentType(HttpResponse* o, const char* type);
1721BA_API int HttpResponse_checkContentType(HttpResponse* o, const char* type);
1722BA_API int HttpResponse_setDateHeader(
1723 HttpResponse* o, const char* name, BaTime t);
1724BA_API int HttpResponse_setHeader(
1725 HttpResponse* o,const char* name,const char* value, BaBool replace);
1726BA_API int HttpResponse_setMaxAge(HttpResponse* response, BaTime seconds);
1727BA_API char* HttpResponse_fmtHeader(
1728 HttpResponse* o, const char* name, int valueLen, BaBool replace);
1729BA_API int HttpResponse_setStatus(HttpResponse* o, int eCode);
1730BA_API int HttpResponse_vprintf(
1731 HttpResponse* o, const char* fmt, va_list argList);
1732BA_API int HttpResponse_printf(HttpResponse* o, const char* fmt, ...);
1733BA_API int HttpResponse_write(HttpResponse* o, const void* data, int len,
1734 int useBuffering);
1735BA_API BufPrint* HttpResponse_getWriter(HttpResponse* o);
1736BA_API int HttpResponse_send(HttpResponse* o, const void* data, int len);
1737BA_API int HttpResponse_setDefaultHeaders(HttpResponse* o);
1738BA_API int HttpResponse_downgrade(HttpResponse* o);
1739BA_API int HttpResponse_setUserObj(
1740 HttpResponse* o,void* userObj,BaBool overwrite);
1741BA_API int HttpResponse_printAndWriteInit(HttpResponse* o);
1742BA_API int HttpResponse_send100Continue(HttpResponse* o);
1743BA_API int HttpResponse_setChunkEncoding(HttpResponse* o);
1744BA_API const char* HttpResponse_getRespData(HttpResponse* o, int* len);
1745#define HttpResponse_getStatus(o) (o)->statusCode
1746#ifdef __cplusplus
1747}
1748inline HttpCookie* HttpResponse::createCookie(const char* name) {
1749 return HttpResponse_createCookie(this, name); }
1750inline const char* HttpResponse::containsHeader(const char* name) {
1751 return HttpResponse_containsHeader(this, name); }
1753 return HttpResponse_byteCount(this); }
1754inline const char* HttpResponse::encodeRedirectURL(const char* pathName) {
1755 return HttpResponse_encodeRedirectURL(this, pathName); }
1756inline const char* HttpResponse::encodeRedirectURLWithParam(const char* p) {
1757 return HttpResponse_encodeRedirectURLWithParam(this, p); }
1758inline const char* HttpResponse::encodeUrl(const char* path) {
1759 return HttpResponse_encodeUrl(this, path); }
1761 return HttpResponse_flush(this); }
1762inline int HttpResponse::forward(const char* path) {
1763 return HttpResponse_forward(this, path); }
1764inline int HttpResponse::redirect(const char* path) {
1765 return HttpResponse_redirect(this, path); }
1766inline int HttpResponse::include(const char* path) {
1767 return HttpResponse_include(this, path); }
1768inline bool HttpResponse::committed() const {
1769 return HttpResponse_committed(this) ? true : false; }
1770inline bool HttpResponse::isForward() const {
1771 return HttpResponse_isForward(this) ? true : false; }
1772inline bool HttpResponse::isInclude() const {
1773 return HttpResponse_isInclude(this) ? true : false; }
1774inline bool HttpResponse::initial() const {
1775 return HttpResponse_initial(this) ? true : false; }
1776inline int HttpResponse::setResponseBuf(BufPrint* buf, bool useDefBuffer) {
1777 return HttpResponse_setResponseBuf(this, buf, useDefBuffer?TRUE:FALSE); }
1779 return HttpResponse_removeResponseBuf(this); }
1781 return HttpResponse_resetHeaders(this); }
1783 return HttpResponse_resetBuffer(this); }
1784inline int HttpResponse::sendError(int eCode) {
1785 return HttpResponse_sendError1(this, eCode); }
1786inline int HttpResponse::sendError(int eCode, const char* msg) {
1787 return HttpResponse_sendError2(this, eCode, msg); }
1788inline int HttpResponse::sendBufAsError(int eCode) {
1789 return HttpResponse_sendBufAsError(this, eCode); }
1790inline int HttpResponse::sendBufAsTxtError(int eCode) {
1791 return HttpResponse_sendBufAsTxtError(this,eCode);}
1792inline int HttpResponse::fmtError(int eCode,const char* fmt,...) {
1793 int retv; va_list varg;
1794 va_start(varg, fmt);
1795 retv = HttpResponse_fmtVError(this, eCode, fmt, varg);
1796 va_end(varg);
1797 return retv; }
1798inline int HttpResponse::sendRedirect(const char* url) {
1799 return HttpResponse_sendRedirect(this, url); }
1801 return HttpResponse_redirect2TLS(this); }
1802inline int HttpResponse::setContentLength(BaFileSize len) {
1803 return HttpResponse_setContentLength(this, len); }
1804inline int HttpResponse::setContentType(const char* type) {
1805 return HttpResponse_setContentType(this, type); }
1806inline int HttpResponse::setDateHeader(const char* name, BaTime t) {
1807 return HttpResponse_setDateHeader(this, name, t); }
1809 const char* name, const char* value, bool replace) {
1810 return HttpResponse_setHeader(this,name, value, replace?TRUE:FALSE); }
1811inline int HttpResponse::setMaxAge(BaTime seconds) {
1812 return HttpResponse_setMaxAge(this, seconds); }
1814 const char* name, int valueLen, bool replace) {
1815 return HttpResponse_fmtHeader(this, name, valueLen, replace?TRUE:FALSE); }
1816inline void HttpResponse::setStatus(int eCode) {
1817 HttpResponse_setStatus(this, eCode);}
1818
1819inline int HttpResponse::printf(const char* fmt, ...) {
1820 int retv; va_list varg; va_start(varg, fmt);
1821 retv = HttpResponse_vprintf(this, fmt, varg); va_end(varg); return retv;}
1822inline int HttpResponse::write(const char* data, int useBuffering) {
1823 return HttpResponse_write(this, data, iStrlen(data), useBuffering); }
1825 return HttpResponse_getWriter(this); }
1826inline int HttpResponse::write(const void* data, int len, int useBuffering){
1827 return HttpResponse_write(this, data, len, useBuffering); }
1828inline int HttpResponse::send(const void* data, int len) {
1829 return HttpResponse_send(this, data, len); }
1831 return HttpResponse_setDefaultHeaders(this); }
1832inline int HttpResponse::setUserObj(void* userObj, bool overwrite) {
1833 return HttpResponse_setUserObj(this, userObj, overwrite); }
1834
1835#endif
1836
1842typedef struct HttpCommand
1843{
1844#ifdef __cplusplus
1845
1849
1853
1857 struct HttpConnection* getConnection();
1858
1860 struct HttpServer* getServer();
1861
1862 HttpCommand() {}
1863#endif
1864 DoubleLink super;
1865#ifdef __cplusplus
1866 public:
1867#endif
1868 HttpRequest request;
1869 HttpResponse response;
1870 struct HttpConnection* con;
1871 struct LHttpCommand* lcmd; /* Used by LSP plugin */
1872 BaTime requestTime;
1873 BaBool runningInThread;
1875
1876#define HttpCommand_getRequest(o) (&(o)->request)
1877#define HttpCommand_getResponse(o) (&(o)->response)
1878#define HttpCommand_getConnection(o) (o)->con
1879#define HttpCommand_getServer(o) HttpConnection_getServer((o)->con)
1880#ifdef __cplusplus
1882 return HttpCommand_getRequest(this); }
1884 return HttpCommand_getResponse(this); }
1886 return HttpCommand_getConnection(this); }
1888 return HttpCommand_getServer(this);
1889}
1890#endif
1891
1892
1893#ifndef NO_HTTP_SESSION
1894
1895#ifndef __DOXYGEN__
1898#endif
1899
1907 struct HttpSessionAttribute* o);
1908
1937{
1938#ifdef __cplusplus
1944 HttpSessionAttribute(const char* name,
1946
1950#endif
1951 struct HttpSessionAttribute* next;
1952 struct HttpSession* session;
1954 char* name;
1956
1957#ifdef __cplusplus
1958extern "C" {
1959#endif
1960
1961BA_API void HttpSessionAttribute_constructor(
1963 const char* name,
1965BA_API void HttpSessionAttribute_destructor(HttpSessionAttribute* o);
1966#define HttpSessionAttribute_getSession(o) (o)->session
1967#ifdef __cplusplus
1968}
1970 const char* name,
1972 HttpSessionAttribute_constructor(this, name, d); }
1974 return HttpSessionAttribute_getSession(this); }
1975
1976#endif
1977
1983typedef struct HttpSession
1984{
1985#ifdef __cplusplus
1986
1987 void *operator new(size_t s) { return ::baMalloc(s); }
1988 void operator delete(void* d) { if(d) ::baFree(d); }
1989 void *operator new(size_t, void *place) { return place; }
1990 void operator delete(void*, void *) { }
1991
2006 void terminate();
2007
2011 HttpSessionAttribute* getAttribute(const char* name);
2012
2017
2023
2028
2031
2034 int removeAttribute(const char* name);
2035
2039
2043 void setMaxInactiveInterval(BaTime interval);
2044
2050 void incrRefCntr();
2051
2057 void decrRefCntr();
2058
2062 U32 getId();
2063
2067
2070 U32 getUseCounter();
2071
2072
2073 void incrementLock();
2074 void decrementLock();
2075
2076 HttpSession() {}
2077 private:
2078#endif
2079 SplayTreeNode super; /* inherits from SplayTreeNode */
2080 DoubleLink dlink;
2081 HttpSockaddr peer;
2082 HttpSessionAttribute* attrList;
2083 struct HttpSessionContainer* container;
2084 BaTime creationTime;
2085 BaTime lastAccessedTime;
2086 BaTime maxInactiveInterval;
2087 U32 sesrnd1; /* Session random number 1 & 2 */
2088 U32 sesrnd2; /* entropy id+sesrnd1+sesrnd2=96 bits */
2089 U32 useCounter;
2090 int refCounter;
2091 U16 lockCounter;
2092 U8 termPending; /* TRUE if in termination list */
2094
2095
2096#ifdef __cplusplus
2097extern "C" {
2098#endif
2099BA_API HttpSessionAttribute* HttpSession_getAttribute(HttpSession* o,
2100 const char* name);
2101BA_API BaTime HttpSession_getCreationTime(HttpSession* o);
2102BA_API BaTime HttpSession_getLastAccessedTime(HttpSession* o);
2103BA_API BaTime HttpSession_getMaxInactiveInterval(HttpSession* o);
2104BA_API struct HttpServer* HttpSession_getServer(HttpSession* o);
2105BA_API void HttpSession_terminate(HttpSession* o);
2106BA_API BaBool HttpSession_isNew(HttpSession* o);
2107BA_API int HttpSession_removeAttribute(HttpSession* o, const char* name);
2108BA_API int HttpSession_setAttribute(HttpSession* o,
2109 HttpSessionAttribute* value);
2110BA_API void HttpSession_setMaxInactiveInterval(HttpSession* o,BaTime interval);
2111#define HttpSession_incrRefCntr(o) (o)->refCounter++
2112BA_API void HttpSession_decrRefCntr(HttpSession* o);
2113#define HttpSession_incrementLock(o) (o)->lockCounter++
2114#define HttpSession_decrementLock(o) do {\
2115 baAssert((o)->lockCounter > 0);\
2116 (o)->lockCounter--; } while(0)
2117BA_API int HttpSession_fmtSessionId(HttpSession* o, U8* buf, size_t bufSize);
2118#define HttpSession_getId(o) \
2119 ((U32)((ptrdiff_t)SplayTreeNode_getKey((SplayTreeNode*)(o))))
2120#define HttpSession_getAuthenticatedUser(o) AuthenticatedUser_get2((o))
2121#define HttpSession_getUseCounter(o) (o)->useCounter
2122#define HttpSession_getPeerName(o) (&(o)->peer)
2123#ifdef __cplusplus
2124}
2126 return HttpSession_getAttribute(this, name); }
2128 return HttpSession_getCreationTime(this); }
2130 return HttpSession_getLastAccessedTime(this); }
2132 return HttpSession_getMaxInactiveInterval(this); }
2134 return HttpSession_getServer(this); }
2136 HttpSession_terminate(this); }
2137inline int HttpSession::removeAttribute(const char* name) {
2138 return HttpSession_removeAttribute(this, name); }
2140 return HttpSession_setAttribute(this, value); }
2142 HttpSession_setMaxInactiveInterval(this, interval); }
2144 HttpSession_incrRefCntr(this); }
2146 HttpSession_decrRefCntr(this); }
2147inline U32 HttpSession::getId() { return HttpSession_getId(this); }
2149 return HttpSession_getUseCounter(this); }
2151 return HttpSession_getAuthenticatedUser(this); }
2152inline void HttpSession::incrementLock() {HttpSession_incrementLock(this);}
2153inline void HttpSession::decrementLock() {HttpSession_decrementLock(this);}
2154
2155#endif /* __cplusplus */
2156
2157typedef enum {
2158 HttpSessionContainer_OK = 0,
2159 HttpSessionContainer_NoMemory,
2160 HttpSessionContainer_TooManySessions,
2161 HttpSessionContainer_NoPeerAddress
2162} HttpSessionContainer_ECode;
2163
2164
2169{
2170#ifdef __cplusplus
2177 void setMaxSessions(int max);
2178 private:
2179#endif
2180 SplayTree sessionTree;
2181 DoubleList sessionList;
2182 DoubleList sessionTermList;
2183 DoubleLink* sessionLinkIter;
2184 struct HttpServer* server;
2185 int noOfSessions; /* Current number of active sessions */
2186 int maxSessions;
2187 HttpSessionContainer_ECode eCode;
2189
2190#ifdef __cplusplus
2191extern "C" {
2192#endif
2193void HttpSessionContainer_constructor(struct HttpSessionContainer* o,
2194 struct HttpServer* server,
2195 U16 maxSessions);
2196void HttpSessionContainer_destructor(struct HttpSessionContainer* o);
2197void HttpSessionContainer_sessionTimer(struct HttpSessionContainer* o);
2198#define HttpSessionContainer_setMaxSessions(o,max) (o)->maxSessions = max
2199#ifdef __cplusplus
2200}
2202 HttpSessionContainer_setMaxSessions(this, max); }
2203#endif
2204
2205#endif /* NO_HTTP_SESSION */
2206
2207
2215typedef void (*HttpPage_Service)(struct HttpPage* page,
2216 HttpRequest* request,
2217 HttpResponse* response);
2218
2219
2220#define HttpPageType_HttpPageSE 0x00020
2221
2222#ifndef __DOXYGEN__
2223typedef struct HttpPageNode
2224{
2225 struct HttpPageNode* next;
2226} HttpPageNode;
2227#endif
2228
2280typedef struct HttpPage
2281{
2282#ifdef __cplusplus
2283 void *operator new(size_t s) { return ::baMalloc(s); }
2284 void operator delete(void* d) { if(d) ::baFree(d); }
2285 void *operator new(size_t, void *place) { return place; }
2286 void operator delete(void*, void *) { }
2287 HttpPage() {}
2296 HttpPage(HttpPage_Service service, const char* name);
2297
2300 ~HttpPage();
2301
2304 const char* getName() const { return name; }
2305
2310 void service(HttpRequest* request, HttpResponse* response);
2311
2315 bool isLinked();
2316
2319 int unlink();
2320#endif
2321 HttpPageNode super; /* As if inherited */
2322 HttpPage_Service serviceCB;
2323 const char* name;
2325
2326#ifdef __cplusplus
2327extern "C" {
2328#endif
2329void
2330BA_API HttpPage_constructor(
2331 HttpPage* o, HttpPage_Service service, const char* name);
2332BA_API void HttpPage_destructor(HttpPage* o);
2333#define HttpPage_getName(o) (o)->name
2334#define HttpPage_isLinked(o) ((HttpPageNode*)(o))->next
2335BA_API int HttpPage_unlink(HttpPage* o);
2336#define HttpPage_service(o, request, response) \
2337 (o)->serviceCB(o, request, response)
2338#ifdef __cplusplus
2339}
2340inline HttpPage::HttpPage(HttpPage_Service service, const char* name) {
2341 HttpPage_constructor(this, service, name); }
2343 HttpPage_destructor(this); }
2344inline bool HttpPage::isLinked() {
2345 return HttpPage_isLinked(this) ? true : false;
2346}
2347inline int HttpPage::unlink() {return HttpPage_unlink(this); }
2348inline void HttpPage::service(HttpRequest* request, HttpResponse* response) {
2349 HttpPage_service(this, request, response);
2350}
2351#endif
2352
2353
2359typedef int (*HttpDir_Service)(struct HttpDir* o,
2360 const char* relPath,
2361 HttpCommand* cmd);
2362
2363#define HttpDirType_EhDir 0x00001
2364#define HttpDirType_HttpResRdr 0x00002
2365#define HttpDirType_AuthenticateDir 0x00008
2366#define HttpDirType_AuthenticateDirWrapper 0x00010
2367
2368
2388typedef struct HttpDir
2389{
2390#ifdef __cplusplus
2391 void *operator new(size_t s) { return ::baMalloc(s); }
2392 void operator delete(void* d) { if(d) ::baFree(d); }
2393 void *operator new(size_t, void *place) { return place; }
2394 void operator delete(void*, void *) { }
2396 HttpDir();
2397
2414 HttpDir(const char* name, S8 priority=0);
2415 ~HttpDir();
2416
2420 int insertDir(HttpDir* dir);
2421
2425 int insertPage(HttpPage* page);
2426
2430
2434
2437 HttpDir* getDir(const char* name);
2438
2441 HttpPage* getPage(const char* name);
2442
2445 HttpDir* getNext();
2446
2456 HttpPage* findPage(HttpPage* iter, const char* name);
2457
2469 static HttpDir* findDir(HttpDir* iter, const char* name,
2470 unsigned int nameLen);
2471
2478 HttpDir* createOrGet(const char* name);
2479
2482 const char* getName() const { return name; }
2483
2486 HttpDir* getParent() const { return parent; }
2487
2510 char* makeAbsPath(const char* relPath, int relPathLen);
2511
2523 char* getRootPath();
2524
2525
2530
2540 void p403(const char* p403);
2541
2545 bool isLinked();
2546
2549 int unlink();
2550
2555 void setAuthenticator(
2556 struct AuthenticatorIntf* authenticator,
2557 struct AuthorizerIntf* authorizer=0);
2558
2579 bool authenticateAndAuthorize(HttpCommand* cmd,const char* path);
2580
2581
2582#endif
2583 HttpDir_Service service;
2584 struct HttpDir* parent; /* owner */
2585 struct HttpDir* next; /* next sibling */
2586 const char* name; /* e.g. /mydir/ */
2587 struct HttpDir* dirList; /* list of httpdirs (children) */
2588 struct AuthorizerIntf* realm; /* If we have authorization */
2589 struct AuthenticatorIntf* authenticator; /* If we have authentic. */
2590 char* _p403; /* If we have a 403 denied response page. */
2591 HttpPageNode pageList; /* pages for this dir */
2592 /* U8 type; */
2593 S8 priority;
2595
2596#ifdef __cplusplus
2597extern "C" {
2598#endif
2599BA_API void HttpDir_constructor(HttpDir* o, const char* name, S8 priority);
2600BA_API void HttpDir_destructor(HttpDir* o);
2601BA_API char* HttpDir_makeAbsPath(
2602 HttpDir* o, const char* relPath, int relPathLen);
2603#define HttpDir_getRootPath(o) HttpDir_makeAbsPath(o,"",0)
2604BA_API int HttpDir_insertDir(HttpDir* o, HttpDir* dir);
2605#define HttpDir_getFirstPage(o) \
2606 (o)->pageList.next != &(o)->pageList ? ((HttpPage*)(o)->pageList.next) : 0
2607#define HttpDir_getFirstDir(o) (o)->dirList
2608BA_API HttpDir* HttpDir_getDir(HttpDir* o, const char* name);
2609BA_API HttpPage* HttpDir_getPage(HttpDir* o, const char* name);
2610#define HttpDir_getNext(o) (o)->next
2611#define HttpDir_getName(o) (o)->name
2612#define HttpDir_getParent(o) (o)->parent
2613BA_API int HttpDir_insertPage(HttpDir* o, HttpPage* page);
2614BA_API HttpPage* HttpDir_findPage(
2615 HttpDir* o, HttpPage* iter, const char* name);
2616BA_API HttpDir* HttpDir_findDir(
2617 HttpDir* iter, const char* name,unsigned int nameLen);
2618BA_API HttpDir* HttpDir_createOrGet(HttpDir* o, const char* name);
2619BA_API void HttpDir_p403(HttpDir* o, const char* p403);
2620#define HttpDir_overloadService HttpDir_setService
2621BA_API HttpDir_Service HttpDir_setService(HttpDir*o, HttpDir_Service s);
2622#define HttpDir_isLinked(o) (o)->parent
2623BA_API int HttpDir_unlink(HttpDir* o);
2624#define HttpDir_setAuthenticator(o,authenticatorMA,authorizerMA) \
2625 (o)->authenticator = authenticatorMA,(o)->realm = authorizerMA
2626BA_API int HttpDir_authenticateAndAuthorize(
2627 HttpDir* o,HttpCommand* cmd,const char* path);
2628#define HttpDir_isAuthorized(o,user,method,path) \
2629 ((o)->realm ? \
2630 (user ? AuthorizerIntf_authorize((o)->realm,user,method,path) : FALSE) : \
2631 TRUE)
2632#ifdef __cplusplus
2633}
2635 HttpDir_constructor(this, 0, 0); }
2636inline HttpDir::HttpDir(const char* name, S8 priority) {
2637 HttpDir_constructor(this, name, priority); }
2638inline HttpDir::~HttpDir() {
2639 HttpDir_destructor(this); }
2640inline char* HttpDir::makeAbsPath(const char* relPath, int relPathLen) {
2641 return HttpDir_makeAbsPath(this, relPath, relPathLen); }
2642inline char* HttpDir::getRootPath() {
2643 return HttpDir_getRootPath(this); }
2644inline int HttpDir::insertDir(HttpDir* dir) {
2645 return HttpDir_insertDir(this, dir); }
2647 return HttpDir_insertPage(this, page); }
2648inline HttpPage* HttpDir::getFirstPage() { return HttpDir_getFirstPage(this); }
2649inline HttpDir* HttpDir::getFirstDir() { return HttpDir_getFirstDir(this); }
2650inline HttpDir* HttpDir::getDir(const char* name) {
2651 return HttpDir_getDir(this,name); }
2652inline HttpPage* HttpDir::getPage(const char* name) {
2653 return HttpDir_getPage(this,name); }
2654inline HttpDir* HttpDir::getNext() { return HttpDir_getNext(this); }
2655inline HttpPage* HttpDir::findPage(HttpPage* iter, const char* name) {
2656 return HttpDir_findPage(this, iter, name); }
2657inline HttpDir* HttpDir::findDir(HttpDir* iter, const char* name,
2658 unsigned int nameLen) {
2659 return HttpDir_findDir(iter, name, nameLen); }
2660inline HttpDir* HttpDir::createOrGet(const char* name) {
2661 return HttpDir_createOrGet(this, name); }
2663 return HttpDir_setService(this, s); }
2664inline void HttpDir::p403(const char* p403) {
2665 HttpDir_p403(this, p403); }
2666inline int HttpDir::unlink() {return HttpDir_unlink(this); }
2667inline bool HttpDir::isLinked() {
2668 return HttpDir_isLinked(this) ? true : false; }
2669inline void HttpDir::setAuthenticator(struct AuthenticatorIntf* authenticator,
2670 struct AuthorizerIntf* authorizer){
2671 HttpDir_setAuthenticator(this,authenticator,authorizer);
2672}
2674 HttpCommand* cmd, const char* path) {
2675 return HttpDir_authenticateAndAuthorize(this,cmd,path) ? true : false; }
2676#endif
2677
2678#ifndef __DOXYGEN__
2679
2680typedef struct HttpLinkCon
2681{
2682 HttpConnection con; /* Inherits from HttpConnection */
2683 DoubleLink link;
2684} HttpLinkCon;
2685
2686
2687typedef struct
2688{
2689 HttpDir super; /* inherit */
2690 HttpDir_Service superServiceFunc;
2691 char* page404;
2692 BaBool page404InProgress;
2693} HttpRootDir;
2694
2695#endif
2696
2705typedef struct HttpServerConfig
2706{
2707#ifdef __cplusplus
2714
2744 int setRequest(S16 min, S16 max);
2745
2757 int setResponseHeader(U16 min, U16 max);
2758
2771 int setResponseData(U16 size);
2772
2786 int setCommit(U16 size);
2787
2800 int setNoOfHttpCommands(U16 size);
2801
2823 int setNoOfHttpConnections(U16 size);
2824
2830 int setMaxSessions(U16 size);
2831#endif
2832 S16 minRequest;
2833 S16 maxRequest;
2834 U16 minResponseHeader;
2835 U16 maxResponseHeader;
2836 U16 commit;
2837 U16 responseData;
2838 U16 noOfHttpCommands;
2839 U16 noOfHttpConnections;
2840 U16 maxSessions;
2842
2843#ifdef __cplusplus
2844extern "C" {
2845#endif
2846BA_API void HttpServerConfig_constructor(HttpServerConfig* o);
2847BA_API int HttpServerConfig_setRequest(HttpServerConfig* o, S16 min, S16 max);
2848BA_API int HttpServerConfig_setResponseHeader(
2849 HttpServerConfig* o, U16 min, U16 max);
2850BA_API int HttpServerConfig_setResponseData(HttpServerConfig* o, U16 size);
2851BA_API int HttpServerConfig_setCommit(HttpServerConfig* o, U16 size);
2852BA_API int HttpServerConfig_setNoOfHttpCommands(HttpServerConfig* o, U16 size);
2853BA_API int HttpServerConfig_setNoOfHttpConnections(
2854 HttpServerConfig* o, U16 size);
2855BA_API int HttpServerConfig_setMaxSessions(HttpServerConfig* o, U16 size);
2856#ifdef __cplusplus
2857}
2859 HttpServerConfig_constructor(this); }
2860inline int HttpServerConfig::setRequest(S16 min, S16 max) {
2861 return HttpServerConfig_setRequest(this, min, max); }
2862inline int HttpServerConfig::setResponseHeader(U16 min, U16 max) {
2863 return HttpServerConfig_setResponseHeader(this, min, max); }
2865 return HttpServerConfig_setResponseData(this, size); }
2866inline int HttpServerConfig::setCommit(U16 size) {
2867 return HttpServerConfig_setCommit(this, size); }
2869 return HttpServerConfig_setNoOfHttpCommands(this, size); }
2871 return HttpServerConfig_setNoOfHttpConnections(this, size); }
2873 return HttpServerConfig_setMaxSessions(this, size); }
2874
2875#endif
2876
2877
2878typedef DoubleList HttpLinkConList;
2879
2880/* Used by LSP plugin */
2881typedef void (*LspOnTerminateRequest)(struct LHttpCommand* lcmd);
2882
2885typedef struct HttpServer
2886{
2887#ifdef __cplusplus
2888 void *operator new(size_t s) { return ::baMalloc(s); }
2889 void operator delete(void* d) { if(d) ::baFree(d); }
2890 void *operator new(size_t, void *place) { return place; }
2891 void operator delete(void*, void *) { }
2898 HttpServer(SoDisp* dispatcher, HttpServerConfig* cfg=0);
2899
2900 ~HttpServer();
2901
2913 int insertRootDir(HttpDir* dir);
2914
2936 int insertDir(const char* virtualDirRootPath, HttpDir* dir);
2937
2977 int insertCSP(CspInit cspInit,
2978 const char* virtualDirRootPath,
2979 struct CspReader* reader);
2980
2981 struct AuthUserList* getAuthUserList(const char* name);
2982
2985
2988
2994
2998
2999#ifndef NO_HTTP_SESSION
3009 HttpSession* getSession(U32 id);
3010#endif
3011
3020 void set404Page(const char* page404);
3021
3023 const char* get404Page();
3024
3025 int setUserObj(void* userObj, bool overwrite=false);
3026
3032 static void initStatic(void);
3033
3044 static void setErrHnd(UserDefinedErrHandler e);
3045
3046 /* No longer used */
3047 static int setZlib(ZlibInflateInit2 init,
3048 ZlibInflate inflate,
3049 ZlibInflateEnd end){
3050 (void)init; (void)inflate; (void)end;
3051 return 0; }
3054 static const char* getStatusCode(int code);
3055
3056
3057#endif
3058 DoubleList commandPool;
3059 DoubleList cmdReqList;
3060 HttpConnection noOpCon;
3061 HttpLinkConList freeList;
3062 HttpLinkConList readyList;
3063 HttpLinkConList connectedList;
3064 HttpRootDir rootDirContainer;
3065 SplayTree authUserTree; /* Used by AuthenticatedUser.c */
3066 struct HttpCmdThreadPoolIntf* threadPoolIntf;
3067 HttpLinkCon* connections;
3068 SoDisp* dispatcher;
3069 void* userObj;
3070 void* waitForConClose; /* See HttpServer_doLingeringClose */
3071 LspOnTerminateRequest lspOnTerminateRequest;
3072 int commandPoolSize;
3073 U16 noOfConnections;
3074 S16 maxHttpRequestLen;
3075#ifndef NO_HTTP_SESSION
3076 HttpSessionContainer sessionContainer;
3077#endif
3079
3080
3081/* Used exclusively by HttpCmdThreadPool */
3082void HttpServer_AsynchProcessDir(HttpServer* o,
3083 HttpDir* dir,
3084 HttpCommand* cmd);
3085/* Used exclusively by HttpCmdThreadPool */
3086#define HttpServer_setThreadPoolIntf(o, intf) (o)->threadPoolIntf=intf
3087#define HttpServer_luaenv(o) (o)->luaenv
3088
3089#ifdef __cplusplus
3090extern "C" {
3091#endif
3092BA_API void HttpServer_constructor(HttpServer*,SoDisp*, HttpServerConfig*);
3093BA_API void HttpServer_destructor(HttpServer* o);
3094BA_API int HttpServer_insertRootDir(HttpServer* o, HttpDir* dir);
3095BA_API int HttpServer_insertDir(HttpServer* o,
3096 const char* virtualDirRootPath,
3097 HttpDir* dir);
3098BA_API int HttpServer_insertCSP(HttpServer* o,
3099 CspInit cspInit,
3100 const char* virtualDirRootPath,
3101 struct CspReader* reader);
3102#define HttpServer_getAuthUserList(o, name) \
3103 (AuthUserList*)SplayTree_find(&(o)->authUserTree, name)
3104#define HttpServer_getDispatcher(o) (o)->dispatcher
3105#define HttpServer_getFirstRootDir(o) \
3106 HttpDir_getFirstDir((HttpDir*)&(o)->rootDirContainer)
3107#define HttpServer_getUserObj(o) (o)->userObj
3108#define HttpServer_getSessionContainer(o) (&(o)->sessionContainer)
3109#define HttpServer_getMutex(o) SoDisp_getMutex((o)->dispatcher)
3110BA_API const char* HttpServer_getStatusCode(int code);
3111void HttpServer_addCon2ConnectedList(HttpServer* o, HttpConnection* con);
3112void HttpServer_doLingeringClose(
3113 HttpServer* o, HttpConnection* con, BaFileSize contLen);
3114
3115#ifndef NO_HTTP_SESSION
3116BA_API HttpSession* HttpServer_getSession(HttpServer* o, U32 id);
3117#endif
3118BA_API HttpConnection* HttpServer_getFreeCon(HttpServer* o);
3119void HttpServer_returnFreeCon(HttpServer* o, HttpConnection* con);
3120BA_API void HttpServer_installNewCon(HttpServer* o, HttpConnection* con);
3121BA_API void HttpServer_setErrHnd(UserDefinedErrHandler e);
3122void HttpServer_initStatic(void);
3123int HttpServer_termOldestIdleCon(HttpServer* o);
3124BA_API void HttpServer_set404Page(HttpServer*o, const char* page404);
3125#define HttpServer_get404Page(o) (o)->rootDirContainer.page404
3126BA_API int HttpServer_setUserObj(
3127 HttpServer* o, void* userObj, BaBool overwrite);
3128#define HttpServer_termAllSessions(o) \
3129 HttpSessionContainer_destructor(&(o)->sessionContainer)
3130/* No longer used */
3131#define HttpServer_setZlib(init,inflate,end);
3132#ifdef __cplusplus
3133}
3135 HttpServer_constructor(this, disp, cfg); }
3136inline HttpServer::~HttpServer() {
3137 HttpServer_destructor(this); }
3139 return HttpServer_insertRootDir(this, dir); }
3141 return HttpServer_getMutex(this);
3142}
3143inline int HttpServer::insertDir(const char* virtualDirRootPath,HttpDir* dir){
3144 return HttpServer_insertDir(this, virtualDirRootPath, dir); }
3146 const char* virtualDirRootPath,
3147 struct CspReader* reader) {
3148 return HttpServer_insertCSP(this, cspInit, virtualDirRootPath, reader); }
3149inline struct AuthUserList* HttpServer::getAuthUserList(const char* name) {
3150 return HttpServer_getAuthUserList(this,name); }
3152 return HttpServer_getDispatcher(this); }
3154 return HttpServer_getFirstRootDir(this); }
3156 return HttpServer_getSessionContainer(this); }
3157#ifndef NO_HTTP_SESSION
3159 return HttpServer_getSession(this, id); }
3160inline void HttpServer::initStatic(void) {
3161 HttpServer_initStatic(); }
3162inline void HttpServer::setErrHnd(UserDefinedErrHandler e) {
3163 HttpServer_setErrHnd(e); }
3164inline void HttpServer::set404Page(const char* page404) {
3165 HttpServer_set404Page(this, page404); }
3166inline const char* HttpServer::get404Page() {
3167 return HttpServer_get404Page(this); }
3168inline int HttpServer::setUserObj(void* userObj, bool overwrite) {
3169 return HttpServer_setUserObj(this, userObj, overwrite); }
3170inline const char* HttpServer::getStatusCode(int code) {
3171 return HttpServer_getStatusCode(code);
3172}
3173#endif
3174
3175
3177 return HttpRequest_getResponse(this); }
3179 return HttpRequest_getConnection(this); }
3181 return HttpResponse_getRequest(this); }
3183 return HttpResponse_getCommand(this); }
3185 return HttpRequest_getCommand(this); }
3187 return HttpConnection_getServer(this); }
3188
3189#endif /* __cplusplus */
3190 /* end of StdWebServer */
3192
3193/* Internal use */
3194#ifdef NO_SHARKSSL
3195
3196#define SHARKSSL_MD5_HASH_LEN 16
3197#define SHARKSSL_SHA1_HASH_LEN 20
3198
3199typedef struct SharkSslMd5Ctx
3200{
3201 U32 total[2];
3202 U32 state[4];
3203 U8 buffer[64];
3204} SharkSslMd5Ctx;
3205
3206SHARKSSL_API void SharkSslMd5Ctx_constructor(SharkSslMd5Ctx* ctx);
3207SHARKSSL_API void SharkSslMd5Ctx_append(SharkSslMd5Ctx* ctx, const U8* data, U32 len);
3208SHARKSSL_API void SharkSslMd5Ctx_finish(SharkSslMd5Ctx* ctx, U8 digest[]);
3209SHARKSSL_API int sharkssl_md5(const U8*, U16, U8*);
3210
3211typedef struct SharkSslSha1Ctx
3212{
3213 U32 total[2];
3214 U32 state[5];
3215 U8 buffer[64];
3216} SharkSslSha1Ctx;
3217
3218SHARKSSL_API void SharkSslSha1Ctx_constructor(SharkSslSha1Ctx* ctx);
3219SHARKSSL_API void SharkSslSha1Ctx_append(SharkSslSha1Ctx* ctx, const U8* data, U32 len);
3220SHARKSSL_API void SharkSslSha1Ctx_finish(SharkSslSha1Ctx*, U8 digest[]);
3221
3222typedef void SharkSsl;
3223
3224#endif
3225
3226#endif /* __httpServer_h */
void(* CspInit)(struct HttpDir *cspRoot, struct CspReader *reader)
Function prototype for the "initialize function" generated by CspLink.
Definition: HttpServer.h:190
void * baMalloc(size_t size)
Returns pointer to uninitialized newly-allocated space for an object of size "size",...
void baFree(void *p)
Deallocates space to which it points.
BaTime getLastAccessedTime()
Returns the last time the client sent a request associated with this session, as the number of second...
Definition: HttpServer.h:2129
void deleteCookie()
Specifies a path for the cookie to which the client should return the cookie.
Definition: HttpServer.h:682
HttpHeader * getHeaders(int *len)
Return an HTTP header iterator that can iterate and fetch all the HTTP headers.
Definition: HttpServer.h:1149
int include(const char *path)
Includes the content of a resource (servlet, CSP page, HTML file) in the response.
Definition: HttpServer.h:1766
BaTime getCreationTime()
Returns the time when this session was created, measured in seconds since midnight January 1,...
Definition: HttpServer.h:2127
int setMaxAge(BaTime seconds)
Sets header "Cache-Control: max-age=seconds".
Definition: HttpServer.h:1811
int setDateHeader(const char *name, BaTime time)
Sets a response header with the given name and date-value.
Definition: HttpServer.h:1806
HttpDir * getNext()
Returns the next dir in the parent list.
Definition: HttpServer.h:2654
const char * getRequestURI()
Returns the pathname.
Definition: HttpServer.h:1132
const char * containsHeader(const char *name)
Searches the internal response header database for a header with the specified name.
Definition: HttpServer.h:1750
const char * getContentType()
Returns the content type, for example: "application/x-www-form-urlencoded".
Definition: HttpServer.h:767
const char * getHost()
Returns the host header.
Definition: HttpServer.h:763
int flush()
Forces any content in the buffer to be written to the client.
Definition: HttpServer.h:1760
void(* HttpSessionAttribute_Destructor)(struct HttpSessionAttribute *o)
HttpSessionAttribute termination callback function.
Definition: HttpServer.h:1906
int sendError(int eCode)
Sends an error response as a simple HTML page to the client using the specified status code.
Definition: HttpServer.h:1784
int forward(const char *path)
Forwards a request from a servlet to another resource (servlet, CSP file, or HTML file).
Definition: HttpServer.h:1762
void setHttpOnly(bool flag)
Marks or unmarks this Cookie as HttpOnly.
Definition: HttpServer.h:688
int setContentLength(BaFileSize len)
Sets the "Content-Length" parameter value.
Definition: HttpServer.h:1802
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:686
HttpPage * findPage(HttpPage *iter, const char *name)
Searches for a page in this directory node.
Definition: HttpServer.h:2655
HttpServer * getServer()
Returns the web server object.
Definition: HttpServer.h:1130
int resetHeaders()
Removes all HTTP headers.
Definition: HttpServer.h:1780
struct HttpServer * getServer()
Get the web-server object.
Definition: HttpServer.h:1887
HttpRequest * getRequest()
Get the request object.
Definition: HttpServer.h:1881
int insertPage(HttpPage *page)
Insert a page in the directory.
Definition: HttpServer.h:2646
int setAttribute(HttpSessionAttribute *value)
Binds an object to this session, using the name specified.
Definition: HttpServer.h:2139
HttpMethod getMethodType()
Returns the method type.
Definition: HttpServer.h:1124
int send(const void *data, int len)
Used when sending raw data to the client.
Definition: HttpServer.h:1828
HttpResponse * getResponse()
Get the response object.
Definition: HttpServer.h:1883
int removeResponseBuf()
Remove buffer set by using setResponseBuf.
Definition: HttpServer.h:1778
HttpMethod
HTTP method types.
Definition: HttpServer.h:788
HttpConnection * getConnection()
Returns the connection object associated with this request.
Definition: HttpServer.h:3178
const char * getDomain()
Returns the host header without any port number.
Definition: HttpServer.h:765
struct HttpRequest HttpRequest
The HttpServer creates an HttpRequest object when the HttpServer parses a client request.
void setAuthenticator(struct AuthenticatorIntf *authenticator, struct AuthorizerIntf *authorizer=0)
Set the optional authenticator and optional AuthorizerIntf.
Definition: HttpServer.h:2669
struct HttpConnection * getConnection()
Get the current connection object that the HttpCommand instance is bound with.
Definition: HttpServer.h:1885
int sendBufAsTxtError(int eCode)
Sends the data formatted into the HttpResponse buffer as an error message to the client.
Definition: HttpServer.h:1790
bool isForward() const
Returns true if this is a forward request from another servlet or CSP file.
Definition: HttpServer.h:1770
AuthenticatedUser * getAuthenticatedUser()
Returns the authenticated user or NULL if user is not authenticated.
Definition: HttpServer.h:1122
int unlink()
Unlinks/removes the page from the parent directory.
Definition: HttpServer.h:2347
HttpServer * getServer()
Get the server object.
Definition: HttpServer.h:2133
struct HttpSessionAttribute HttpSessionAttribute
The interface to an HttpSession attribute.
int setRequest(S16 min, S16 max)
Set the size of the HTTP request buffer.
Definition: HttpServer.h:2860
bool hasMoreElements()
Returns true if more elements.
Definition: HttpServer.h:1159
HttpStdHeaders * getStdHeaders()
Returns an object containing standard HTTP headers.
Definition: HttpServer.h:1136
const char * getHeaderValue(const char *name)
Returns the value of the specified request header.
Definition: HttpServer.h:1140
int setDefaultHeaders()
Sets the most common header values in servlet and CSP files.
Definition: HttpServer.h:1830
int resetBuffer()
Clears the content of the underlying buffer in the response without clearing headers or status code.
Definition: HttpServer.h:1782
int insertCSP(CspInit cspInit, const char *virtualDirRootPath, struct CspReader *reader)
Insert and initialize a CSP Virtual Directory.
Definition: HttpServer.h:3145
struct HttpServerConfig HttpServerConfig
Use an instance of this class if you want to override the default web-server parameters.
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:1754
bool initial() const
Returns true if this is the initial page.
Definition: HttpServer.h:1774
struct HttpStdHeaders HttpStdHeaders
Standard HTTP header values.
static void setErrHnd(UserDefinedErrHandler e)
You can set your own user defined error handler for the web-server.
Definition: HttpServer.h:3162
void terminate()
Unbinds any objects bound to this session object, runs the HttpSession destructor,...
Definition: HttpServer.h:2135
struct HttpResponse HttpResponse
This object is used when sending response messages back to the client.
~HttpPage()
The HttpPage destructor unlinks the page from the parent directory.
Definition: HttpServer.h:2342
void nextElement()
Advance to the next element.
Definition: HttpServer.h:493
SBaFileSize getContentLength()
Returns the content length if request contains a body.
Definition: HttpServer.h:769
U32 byteCount()
Returns number of bytes sent thus far.
Definition: HttpServer.h:1752
int setCommit(U16 size)
Set the size of the HTTP response commit buffer.
Definition: HttpServer.h:2866
HttpDir()
Constructor for creating a root dir, a root dir has no name.
Definition: HttpServer.h:2634
struct HttpServer HttpServer
The Web Server.
int setValue(const char *newValue)
Assigns a new value to a cookie after the cookie is created.
Definition: HttpServer.h:690
HttpCookie * getCookie(const char *name)
Returns the requested cookie or NULL if no cookie matches the name.
Definition: HttpServer.h:1142
ThreadMutex * getMutex()
Get the dispatcher mutex.
Definition: HttpServer.h:3140
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:2348
void setMaxAge(BaTime expiry)
Sets the maximum age of the cookie in seconds.
Definition: HttpServer.h:680
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:1776
HttpSessionContainer * getSessionContainer()
Get the HttpSessionContainer.
Definition: HttpServer.h:3155
HttpDir * getFirstRootDir()
Returns the first root directory.
Definition: HttpServer.h:3153
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:2125
AuthenticatedUser * getAuthenticatedUser()
Returns the AuthenticatedUser if user is authenticated.
Definition: HttpServer.h:2150
int setContentType(const char *type)
Sets the "Content-Type" parameter value.
Definition: HttpServer.h:1804
void(* HttpPage_Service)(struct HttpPage *page, HttpRequest *request, HttpResponse *response)
The HttpPage service function.
Definition: HttpServer.h:2215
struct HttpCookie HttpCookie
A cookie is used for exchanging a small amount of information between a HttpPage and a web browser.
U32 getId()
Returns a unique identifier assigned to this session.
Definition: HttpServer.h:2147
int setResponseHeader(U16 min, U16 max)
Set the size of the HTTP response header buffer.
Definition: HttpServer.h:2862
void set404Page(const char *page404)
Set a more user friendly 404 page.
Definition: HttpServer.h:3164
const char * encodeRedirectURLWithParam(const char *pathName)
This method is similar to HttpResponse::encodeRedirectURL, but this method also includes all URL-enco...
Definition: HttpServer.h:1756
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:3160
struct HttpServer * getServer()
Fetch the HttpServer object.
Definition: HttpServer.h:3186
BufPrint * getWriter()
Returns a BufPrint object that can send any type of data to the client.
Definition: HttpServer.h:1824
int write(const void *data, int len, int useBuffering=TRUE)
Used for sending pre-formatted data to the client.
Definition: HttpServer.h:1826
int setMaxSessions(U16 size)
Maximum allowed active HttpSession objects.
Definition: HttpServer.h:2872
HttpInData * getBuffer()
Get the internal rec buffer.
Definition: HttpServer.h:1161
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:1758
int setNoOfHttpCommands(U16 size)
The number of HttpCommand instances created by the web-server.
Definition: HttpServer.h:2868
HttpDir * createOrGet(const char *name)
Returns a sub-directory with the given name.
Definition: HttpServer.h:2660
bool authenticateAndAuthorize(HttpCommand *cmd, const char *path)
Authenticate and authorize the user.
Definition: HttpServer.h:2673
int(* HttpDir_Service)(struct HttpDir *o, const char *relPath, HttpCommand *cmd)
The HttpDir service callback function.
Definition: HttpServer.h:2359
HttpServer(SoDisp *dispatcher, HttpServerConfig *cfg=0)
Create a Web Server object.
Definition: HttpServer.h:3134
struct HttpCommand HttpCommand
The HttpCommand class is a container class for the HttpRequest and HttpResponse command pair.
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:1813
bool isInclude() const
Returns true if this is an include from another servlet or CSP file.
Definition: HttpServer.h:1772
int unlink()
Unlinks/removes the directory from the parent directory.
Definition: HttpServer.h:2666
char * getRootPath()
Calculates the root of where the HttpDir instance is installed in the virtual file system.
Definition: HttpServer.h:2642
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:1115
const char * getVersion()
Returns the HTTP version as a string, normally "1.1".
Definition: HttpServer.h:1138
int printf(const char *fmt,...)
printf is used for sending formatted data to the client.
Definition: HttpServer.h:1819
int redirect2TLS()
Prepares an HTTPS redirect (301) for a non-secure connection.
Definition: HttpServer.h:1800
HttpPage * getFirstPage()
Returns the first page.
Definition: HttpServer.h:2648
SoDisp * getDispatcher()
Returns the dispatcher object.
Definition: HttpServer.h:3151
HttpDir * getDir(const char *name)
Returns the first directory with the name given or NULL if not found.
Definition: HttpServer.h:2650
int wsUpgrade()
Activate a WebSocket handshake.
Definition: HttpServer.h:1146
static const char * getStatusCode(int code)
Return a short description for common HTTP error codes.
Definition: HttpServer.h:3170
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:2640
struct HttpSessionContainer HttpSessionContainer
The HttpSession container class.
HttpSession * getSession(U32 id)
Returns the HttpSession associated with id or NULL if not found.
Definition: HttpServer.h:3158
U32 getUseCounter()
Get the session usage counter.
Definition: HttpServer.h:2148
bool committed() const
Returns a boolean indicating if the response has been committed.
Definition: HttpServer.h:1768
int redirect(const char *path)
Internally redirects the request to another resource.
Definition: HttpServer.h:1764
void incrRefCntr()
Increments the session reference counter.
Definition: HttpServer.h:2143
const char * getConnection()
Returns the connection type for HTTP 1.1 connections, returns "Close" or "Keep-Alive.
Definition: HttpServer.h:761
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:1144
void decrRefCntr()
Decrements the session reference counter.
Definition: HttpServer.h:2145
const char * getRequestURL(bool forceHttps=false)
Reconstructs the URL the client used to make the request.
Definition: HttpServer.h:1134
HttpCommand * getCommand()
Get the HttpCommand object.
Definition: HttpServer.h:3184
int insertDir(HttpDir *dir)
Insert a sub-directory.
Definition: HttpServer.h:2644
void setMaxInactiveInterval(BaTime interval)
Specifies the time, in seconds, between client requests before the session container will invalidate ...
Definition: HttpServer.h:2141
void setMaxSessions(int max)
Set the maximum number of session objects.
Definition: HttpServer.h:2201
struct HttpSession HttpSession
Provides a way to identify a user across more than one page request or visit to a web site,...
bool isLinked()
Returns true if this page node is installed into a parent directory.
Definition: HttpServer.h:2344
const char * get404Page()
Returns a pointer to the current 404 page, if any.
Definition: HttpServer.h:3166
HttpCommand * getCommand()
Get the HttpCommand object.
Definition: HttpServer.h:3182
static HttpDir * findDir(HttpDir *iter, const char *name, unsigned int nameLen)
Searches for a sub-directory in this directory node.
Definition: HttpServer.h:2657
int setPath(const char *uri)
Set the cookie path.
Definition: HttpServer.h:684
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
HttpServerConfig()
The constructor sets up the default parameters.
Definition: HttpServer.h:2858
const char * getMethod()
Returns a string representation of the value returned by HttpRequest::getMethodType.
Definition: HttpServer.h:1126
BaTime getMaxInactiveInterval()
Returns the maximum time interval, in seconds, that the session container will keep this session open...
Definition: HttpServer.h:2131
HttpCookie * createCookie(const char *name)
Create a cookie.
Definition: HttpServer.h:1748
HttpPage * getPage(const char *name)
Returns the page with the name given or NULL if not found.
Definition: HttpServer.h:2652
int setComment(const char *purpose)
Specifies a comment that describes a cookie's purpose.
Definition: HttpServer.h:676
int fmtError(int eCode, const char *fmt,...)
This method implements a printf like implementation for formatting and sending an error message.
Definition: HttpServer.h:1792
struct HttpPage HttpPage
An HttpPage, which is typically created by the CSP compiler, is similar to a Java servlet.
HttpDir_Service setService(HttpDir_Service s)
Replace the original service function in HttpDir with your own.
Definition: HttpServer.h:2662
HttpDir * getFirstDir()
Returns the first sub-directory.
Definition: HttpServer.h:2649
int setDomain(const char *pattern)
Specifies the domain within which this cookie should be presented.
Definition: HttpServer.h:678
bool isLinked()
Returns true if this directory node is installed into a parent directory.
Definition: HttpServer.h:2667
HttpResponse * getResponse()
Returns the HttpResponse object.
Definition: HttpServer.h:3176
int insertDir(const char *virtualDirRootPath, HttpDir *dir)
Insert a directory node into the virtual file system.
Definition: HttpServer.h:3143
void setStatus(int statusCode)
Sets the status code for this response.
Definition: HttpServer.h:1816
int insertRootDir(HttpDir *dir)
Insert a root directory node.
Definition: HttpServer.h:3138
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:1808
HttpRequest * getRequest()
Get the HttpRequest object.
Definition: HttpServer.h:3180
void p403(const char *p403)
Set a 403 denied request handler.
Definition: HttpServer.h:2664
HttpSession * getSession()
Get the session object.
Definition: HttpServer.h:1973
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:1120
void activate()
Activates the cookie.
Definition: HttpServer.h:696
int sendRedirect(const char *url)
Sends a temporary redirect (302) response to the client using the specified redirect location URL.
Definition: HttpServer.h:1798
int setResponseData(U16 size)
The HttpResponse object stores formatted data in the response data buffer.
Definition: HttpServer.h:2864
int removeAttribute(const char *name)
Removes the object bound with the specified name from this session.
Definition: HttpServer.h:2137
int setNoOfHttpConnections(U16 size)
Number of HttpConnection instances.
Definition: HttpServer.h:2870
int sendBufAsError(int eCode)
Sends the data formatted into the HttpResponse buffer as an error message to the client.
Definition: HttpServer.h:1788
HttpSessionAttribute(const char *name, HttpSessionAttribute_Destructor terminate)
Create a session attribute.
Definition: HttpServer.h:1969
struct HttpDir HttpDir
An instance of the HttpDir class, which is a collection of zero or more resources,...
struct HttpParameterIterator HttpParameterIterator
The HttpParameterIterator is used for iterating through the form elements parsed by the HttpServer ob...
S64 BaTime
An arithmetic type representing calendar time with epoch of 1970-01-01 00:00:10 GMT – i....
Definition: GenPrimT.h:93
Abstract base class implemented by BasicAuthUser, FormAuthUser and DigestAuthUser.
Definition: AuthenticatedUser.h:246
Abstract interface class implemented by DigestAuthenticator, FormAuthenticator and DigestAuthenticato...
Definition: AuthenticatedUser.h:398
An abstract class, which you must implement, provides a method of authorizing an authenticated user.
Definition: AuthenticatedUser.h:112
The BufPrint class, which implements an ANSI compatible printf method, is a base class used by severa...
Definition: BufPrint.h:122
Abstract interface class for reading the "dat" file generated by HttpLink.
Definition: CspRunTm.h:118
The HttpCommand class is a container class for the HttpRequest and HttpResponse command pair.
Definition: HttpServer.h:1843
Contains information about the physical socket connection.
Definition: HttpConnection.h:76
A cookie is used for exchanging a small amount of information between a HttpPage and a web browser.
Definition: HttpServer.h:524
const char * getComment() const
Returns the comment set for this cookie or null if the cookie comment is not set.
Definition: HttpServer.h:530
const char * getPath() const
Returns the path on the server to which the browser returns this cookie.
Definition: HttpServer.h:545
BaTime getMaxAge() const
Returns the maximum age of the cookie, specified in seconds; by default, 0 indicating the cookie will...
Definition: HttpServer.h:538
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:550
const char * getDomain() const
Returns the domain name set for this cookie.
Definition: HttpServer.h:533
const char * getValue() const
Returns the value of the cookie.
Definition: HttpServer.h:558
bool getHttpOnly() const
Return the HttpOnly attribute.
Definition: HttpServer.h:555
const char * getName() const
Returns the name of the cookie.
Definition: HttpServer.h:541
An instance of the HttpDir class, which is a collection of zero or more resources,...
Definition: HttpServer.h:2389
HttpDir * getParent() const
Returns the parent directory or NULL if no parent.
Definition: HttpServer.h:2486
const char * getName() const
Returns the directory name.
Definition: HttpServer.h:2482
The web-server "Request Data" container.
Definition: HttpServer.h:266
const char * getBuf()
Get pointer to start of PUT/POST data.
Definition: HttpServer.h:301
S32 getBufSize()
Get size of internal buffer.
Definition: HttpServer.h:303
An HttpPage, which is typically created by the CSP compiler, is similar to a Java servlet.
Definition: HttpServer.h:2281
const char * getName() const
Returns the page name.
Definition: HttpServer.h:2304
The HttpParameterIterator is used for iterating through the form elements parsed by the HttpServer ob...
Definition: HttpServer.h:440
const char * getValue() const
Returns the form value.
Definition: HttpServer.h:461
const char * getName() const
Return the form name.
Definition: HttpServer.h:459
A persistent container object for HTTP parameters.
Definition: HttpServer.h:365
static U32 calculateSize(struct HttpRequest *req)
Calculate the HttpParameter size.
Definition: HttpServer.h:403
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:407
static HttpParameter * clone(void *buf, struct HttpRequest *req)
Copy HTTP parameters to buf and return as a HttpParameter object.
Definition: HttpServer.h:405
The HttpServer creates an HttpRequest object when the HttpServer parses a client request.
Definition: HttpServer.h:824
This object is used when sending response messages back to the client.
Definition: HttpServer.h:1194
Use an instance of this class if you want to override the default web-server parameters.
Definition: HttpServer.h:2706
The Web Server.
Definition: HttpServer.h:2886
The interface to an HttpSession attribute.
Definition: HttpServer.h:1937
The HttpSession container class.
Definition: HttpServer.h:2169
Provides a way to identify a user across more than one page request or visit to a web site,...
Definition: HttpServer.h:1984
Standard HTTP header values.
Definition: HttpServer.h:705
The SoDisp dispatches any socket connection that contains data by calling the SoDispCon::execute memb...
Definition: SoDisp.h:86
A mutual exclusion class.
Definition: ThreadLib.h:186
User database interface used by the authentication classes.
Definition: AuthenticatedUser.h:177