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 5412 2023-03-17 01:49:04Z wini $
15 *
16 * COPYRIGHT: Real Time Logic LLC, 2003 - 2023
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 "5523"
40#define BASLIB_VER_NO 5523
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
118 for HTTP cons.: this pointer is not used for anything else for a
119 non secure socket con.. */
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);
141BA_API char* httpUnescape(char* from);
145BA_API char* httpEscape(char* out, const char* in);
146#ifdef __cplusplus
147}
148#endif
149
150
151typedef void (*UserDefinedErrHandler)(BaFatalErrorCodes ecode1,
152 unsigned int ecode2,
153 const char* file,
154 int line);
155
156
182typedef void (*CspInit)(
183 struct HttpDir* cspRoot,struct CspReader* reader);
184 /* end of CSP */
186
187/* no longer used. included for compatibility.
188 */
189struct z_stream_s;
190typedef int (*ZlibInflateInit2)(struct z_stream_s* s, int windowBits,
191 const char *version, int stream_size);
192
193typedef int (*ZlibInflate)(struct z_stream_s* s, int flush);
194typedef int (*ZlibInflateEnd)(struct z_stream_s* s);
195
196
197#ifndef __DOXYGEN__
198
199typedef struct
200{
201 char* buf;
202 U16 size;
203 U16 index;
204} HttpAllocator;
205
206
209typedef struct HttpHeader
210{
211#ifdef __cplusplus
212 const char* name(HttpRequest* req);
213 const char* value(HttpRequest* req);
214#endif
215 U16 nameI;
216 U16 valueI;
217}HttpHeader;
218
219#ifdef __cplusplus
220extern "C" {
221#endif
222BA_API const char* HttpHeader_name(HttpHeader* o, struct HttpRequest* req);
223BA_API const char* HttpHeader_value(HttpHeader* o, struct HttpRequest* req);
224#ifdef __cplusplus
225}
226inline const char* HttpHeader::name(HttpRequest* req) {
227 return HttpHeader_name(this, req); }
228inline const char* HttpHeader::value(HttpRequest* req) {
229 return HttpHeader_value(this, req); }
230#endif
231
232#endif
233
234
235
236
237
238/*===========================================================================
239 *
240 * HttpInData
241 *---------------------------------------------------------------------------
242 * Description:
243 */
244
245#ifndef __DOXYGEN__
246
247typedef enum {
248 HttpInData_ParseHeader,
249 HttpInData_ReadBody,
250 HttpInData_ReadBodyAndParseUrlEncData
251} HttpInData_ParseState;
252#endif
253
254
257typedef struct HttpInData
258{
259#ifdef __cplusplus
262 const char* getBuf();
263
270 S32 getBufSize();
271#endif
272 HttpAllocator allocator;
273 struct HttpRequest* request;
274 U16 lineStartI;
275 U16 lineEndI;
276 S16 maxRequest;
277 U8 parseState; /* HttpInData_ParseState */
278 U8 overflow; /* Used for pipelined requests */
279} HttpInData;
280
281#define HttpAllocator_2Ptr(o, index) ((&(o)->buf[index]))
282#define HttpInData_lineStartPtr(o) \
283 HttpAllocator_2Ptr(&(o)->allocator,(o)->lineStartI)
284
285#define HttpInData_getBufSize(o) \
286 ((o)->lineStartI < (o)->allocator.index ? \
287 (o)->allocator.index-(o)->lineStartI : 0)
288
289#define HttpInData_getBuf(o) HttpInData_lineStartPtr(o)
290BaBool HttpInData_hasMoreData(HttpInData* o);
291
292#ifdef __cplusplus
293inline const char* HttpInData::getBuf() {
294 return HttpInData_getBuf(this); }
296 return HttpInData_getBufSize(this); }
297#endif
298
299
300
356typedef struct HttpParameter
357{
358#ifdef __cplusplus
361 static U32 calculateSize(struct HttpRequest* req);
362
366 static HttpParameter* clone(void* buf, struct HttpRequest* req);
367
376 const char* getParameter(const char* paramName);
377
378 private:
379 HttpParameter() {}
380#endif
381 U16 formLen;
383
384
385#ifdef __cplusplus
386extern "C" {
387#endif
388BA_API U32 HttpParameter_calculateSize(struct HttpRequest* req);
389BA_API HttpParameter* HttpParameter_clone(void* buf, struct HttpRequest* req);
390BA_API const char* HttpParameter_getParameter(
391 HttpParameter* o,const char* paramName);
392
393#ifdef __cplusplus
394}
396 return HttpParameter_calculateSize(req); }
397inline HttpParameter* HttpParameter::clone(void* buf, struct HttpRequest* req){
398 return HttpParameter_clone(buf, req); }
399inline const char* HttpParameter::getParameter(const char* paramName) {
400 return HttpParameter_getParameter(this, paramName); }
401#endif
402
403
432{
433#ifdef __cplusplus
438
445
447 void nextElement();
449 bool hasMoreElements();
451 const char* getName() const { return name; }
453 const char* getValue() const { return value; }
454 private:
455#endif
456 void* formElemBase;
457 U8* dataEntry;
458 U16 pos;
459 U16 formLen;
460 const char* name;
461 const char* value;
462
464
465#ifdef __cplusplus
466extern "C" {
467#endif
468
469BA_API int HttpParameterIterator_constructor(
470 HttpParameterIterator* o, struct HttpRequest* req);
471BA_API int HttpParameterIterator_constructor2(HttpParameterIterator* o,
472 HttpParameter* param);
473BA_API void HttpParameterIterator_nextElement(HttpParameterIterator* o);
474#define HttpParameterIterator_hasMoreElements(o) ((o)->name != 0)
475#define HttpParameterIterator_getName(o) (o)->name
476#define HttpParameterIterator_getValue(o) (o)->value
477
478
479#ifdef __cplusplus
480}
481inline HttpParameterIterator::HttpParameterIterator(HttpRequest* req) {
482 HttpParameterIterator_constructor(this, req); }
483inline HttpParameterIterator::HttpParameterIterator(HttpParameter* param) {
484 HttpParameterIterator_constructor2(this, param); }
486 HttpParameterIterator_nextElement(this); }
487#endif
488
489
515typedef struct HttpCookie
516{
517#ifdef __cplusplus
518 ~HttpCookie();
519
522 const char* getComment() const { return comment; }
523
525 const char* getDomain() const { return domain; }
526
530 BaTime getMaxAge() const { return maxAge; }
531
533 const char* getName() const { return name; }
534
537 const char* getPath() const { return path; }
538
542 bool getSecure() const { return secure ? true : false; }
543
547 bool getHttpOnly() const { return httpOnly ? true : false; }
548
550 const char* getValue() const { return value; }
551
553 void setComment(const char* purpose);
554
556 void setDomain(const char* pattern);
557
565 void setMaxAge(BaTime expiry);
574 void deleteCookie();
575
577 void setPath(const char* uri);
578
582 void setSecure(bool flag);
583
593 void setHttpOnly(bool flag);
594
596 void setValue(const char* newValue);
597
598#if 0
600 int getVersion() const { return version; }
601 /* Sets the version of the cookie protocol this cookie complies with. */
602 void setVersion(int v);
603#endif
604
610 void activate();
611 private:
612 HttpCookie();
613#endif
614 struct HttpCookie* next;
615 char* comment;
616 char* domain;
617 char* name;
618 char* path;
619 char* value;
620 BaTime maxAge;
621 int version;
622 BaBool secure;
623 BaBool httpOnly;
624 BaBool deleteCookieFlag;
625 BaBool activateFlag; /* The cookie will be sent to the client
626 * if this flag is true */
628
629#ifdef __cplusplus
630extern "C" {
631#endif
632BA_API void HttpCookie_destructor(HttpCookie* o);
633BA_API const char* HttpCookie_getComment(HttpCookie* o);
634BA_API const char* HttpCookie_getDomain(HttpCookie* o);
635BA_API BaTime HttpCookie_getMaxAge(HttpCookie* o);
636BA_API const char* HttpCookie_getName(HttpCookie* o);
637BA_API const char* HttpCookie_getPath(HttpCookie* o);
638BA_API BaBool HttpCookie_getSecure(HttpCookie* o);
639BA_API BaBool HttpCookie_getHttpOnly(HttpCookie* o);
640BA_API const char* HttpCookie_getValue(HttpCookie* o);
641BA_API void HttpCookie_setComment(HttpCookie* o, const char* purpose);
642BA_API void HttpCookie_setDomain(HttpCookie* o, const char* pattern);
643BA_API void HttpCookie_setMaxAge(HttpCookie* o, BaTime expiry);
644#define HttpCookie_deleteCookie(o) (o)->deleteCookieFlag = TRUE;
645BA_API void HttpCookie_setPath(HttpCookie* o, const char* uri);
646BA_API void HttpCookie_setSecure(HttpCookie* o, BaBool flag);
647BA_API void HttpCookie_setHttpOnly(HttpCookie* o, BaBool flag);
648BA_API void HttpCookie_setValue(HttpCookie* o, const char* newValue);
649
650#if 0
651int HttpCookie_getVersion(HttpCookie* o);
652void HttpCookie_setVersion(HttpCookie* o, int v);
653#endif
654
655BA_API void HttpCookie_activate(HttpCookie* o);
656#ifdef __cplusplus
657}
658inline HttpCookie::HttpCookie() { baAssert(0); }
659inline HttpCookie::~HttpCookie() { HttpCookie_destructor(this); }
660inline void HttpCookie::setComment(const char* purpose) {
661 HttpCookie_setComment(this, purpose); }
662inline void HttpCookie::setDomain(const char* pattern) {
663 HttpCookie_setDomain(this, pattern); }
664inline void HttpCookie::setMaxAge(BaTime expiry) {
665 HttpCookie_setMaxAge(this, expiry); }
667 HttpCookie_deleteCookie(this); }
668inline void HttpCookie::setPath(const char* uri) {
669 HttpCookie_setPath(this, uri); }
670inline void HttpCookie::setSecure(bool flag) {
671 HttpCookie_setSecure(this, flag ? TRUE : FALSE); }
672inline void HttpCookie::setHttpOnly(bool flag) {
673 HttpCookie_setHttpOnly(this, flag ? TRUE : FALSE); }
674inline void HttpCookie::setValue(const char* newValue) {
675 HttpCookie_setValue(this, newValue); }
676#if 0
677inline void HttpCookie::setVersion(int v) {
678 HttpCookie_setVersion(this, v); }
679#endif
680inline void HttpCookie::activate() {
681 HttpCookie_activate(this); }
682#endif
683
684
688typedef struct HttpStdHeaders
689{
690#ifdef __cplusplus
694 const char* getConnection();
695
703 const char* getHost();
704
710 const char* getDomain();
711
715 const char* getContentType();
716
719 SBaFileSize getContentLength();
720#endif
721 HttpInData* inData;
722 char* domain;
723 BaFileSize contentLength;
724 U16 connectionHOffs;
725 U16 hostHOffs;
726 U16 contentTypeHOffs;
728
729#ifdef __cplusplus
730extern "C" {
731#endif
732BA_API const char* HttpStdHeaders_zzGetValFromOffs(
733 HttpStdHeaders* o, U16 offset);
734BA_API const char* HttpStdHeaders_getDomain(HttpStdHeaders* o);
735#define HttpStdHeaders_getConnection(o) \
736 HttpStdHeaders_zzGetValFromOffs(o,(o)->connectionHOffs)
737#define HttpStdHeaders_getHost(o) \
738 HttpStdHeaders_zzGetValFromOffs(o,(o)->hostHOffs)
739#define HttpStdHeaders_getContentType(o) \
740 HttpStdHeaders_zzGetValFromOffs(o,(o)->contentTypeHOffs)
741#define HttpStdHeaders_getContentLength(o) (o)->contentLength
742
743#ifdef __cplusplus
744}
745inline const char* HttpStdHeaders::getConnection() {
746 return HttpStdHeaders_getConnection(this); }
747inline const char* HttpStdHeaders::getHost() {
748 return HttpStdHeaders_getHost(this); }
749inline const char* HttpStdHeaders::getDomain() {
750 return HttpStdHeaders_getDomain(this); }
751inline const char* HttpStdHeaders::getContentType() {
752 return HttpStdHeaders_getContentType(this); }
754 return HttpStdHeaders_getContentLength(this); }
755
756#endif
757
758
759
760 /*Do not change the HttpMethod type without checking tables in Httpserver.c*/
761
772typedef enum {
773 HttpMethod_Connect =0x00001,
774 HttpMethod_Get =0x00002,
775 HttpMethod_Head =0x00004,
776 HttpMethod_Options =0x00008,
777
778 HttpMethod_Patch =0x00010,
779 HttpMethod_Post =0x00020,
780 HttpMethod_Put =0x00040,
781 HttpMethod_Trace =0x00080,
782
783 /* WebDAV */
784 HttpMethod_Copy =0x00100,
785 HttpMethod_Delete =0x00200,
786 HttpMethod_Lock =0x00400,
787 HttpMethod_Move =0x00800,
788
789 HttpMethod_Mkcol =0x01000,
790 HttpMethod_Propfind =0x02000,
791 HttpMethod_Proppatch =0x04000,
792 HttpMethod_Unlock =0x08000,
793
794 HttpMethod_Unknown =0x10000 /* Must be last */
795} HttpMethod;
796
797
798/* Convert a HTTP method from string value to the type HttpMethod */
799BA_API HttpMethod HttpMethod_a2m(const char* str);
800
801
802
807typedef struct HttpRequest
808{
809#ifdef __cplusplus
810
862 int checkMethods(HttpResponse* resp, U32 methods, bool addDefault=TRUE);
863
876 BaBool checkTime(struct HttpResponse* resp, BaTime time);
877
881
884 const char* getRequestURI();
885
898 const char* getRequestURL(bool forceHttps=false);
899
904
906 const char* getVersion();
907
915 const char* getHeaderValue(const char* name);
916
920 HttpCookie* getCookie(const char* name);
921
928
933 const char* getMethod();
934
938 static const char* getMethod(HttpMethod method);
939
950 const char* getParameter(const char* paramName);
951
956 int wsUpgrade();
957
973 HttpHeader* getHeaders(int* len);
974
975
976
1011#ifndef NO_HTTP_SESSION
1012 HttpSession* getSession(BaBool create=true);
1013#endif
1017
1021
1025
1029
1032
1033
1034 int setUserObj(void* userObj, bool overwrite=false);
1035 void* getUserObj();
1036
1037#endif
1038 HttpStdHeaders stdH;
1039 HttpAllocator headerAlloc;
1040 HttpAllocator formAlloc;
1041 HttpInData inData;
1042 struct HttpServer* server;
1043 void* userObj;
1044 struct HttpSession* session;
1045 HttpMethod methodType;
1046 U16 pathI;
1047 U16 versionI;
1048 U16 headersI;
1049 U16 headerLen;
1050 U16 formsI;
1051 U16 formLen;
1052 BaBool postDataConsumed; /* Set by MultipartUpload and HttpRecData */
1054
1055#ifdef __cplusplus
1056extern "C" {
1057#endif
1058BA_API int HttpRequest_checkMethods(HttpRequest* o, struct HttpResponse* resp,
1059 U32 methods, BaBool addDefault);
1060BA_API int HttpRequest_checkOptions(
1061 HttpRequest* o, struct HttpResponse* resp, int optLen, ...);
1062#define HttpRequest_getAuthenticatedUser(o) \
1063 AuthenticatedUser_get2(HttpRequest_getSession(o,FALSE))
1064#define HttpRequest_getConnection(o) HttpRequest_getCommand(o)->con
1065#define HttpRequest_getMethodType(o) (o)->methodType
1066#define HttpRequest_getMethod(o) HttpRequest_getMethod2((o)->methodType)
1067BA_API const char* HttpRequest_getMethod2(HttpMethod method);
1068#define HttpRequest_getServer(o) (o)->server
1069#define HttpRequest_getResponse(o) (&HttpRequest_getCommand(o)->response)
1070BA_API struct HttpCommand* HttpRequest_getCommand(HttpRequest*);
1071BA_API BaBool HttpRequest_checkTime(
1072 HttpRequest* o, struct HttpResponse* resp, BaTime time);
1073BA_API const char* HttpRequest_getRequestURI(HttpRequest* o);
1074BA_API const char* HttpRequest_getRequestURL(HttpRequest* o,BaBool forceHttps);
1075#define HttpRequest_getStdHeaders(o) (&(o)->stdH)
1076BA_API const char* HttpRequest_getVersion(HttpRequest* o);
1077BA_API const char* HttpRequest_getHeaderValue(HttpRequest* o,const char* name);
1078#define HttpRequest_getNoOfParameters(o) (o)->formLen
1079BA_API HttpCookie* HttpRequest_getCookie(HttpRequest* o, const char* name);
1080#define HttpRequest_getUserObj(o) (o)->userObj
1081BA_API int HttpRequest_setUserObj(
1082 HttpRequest* o, void* userObj, BaBool overwrite);
1083#define HttpRequest_getBuffer(o) (&(o)->inData)
1084BA_API const char* HttpRequest_getParameter(
1085 HttpRequest* o, const char* paramName);
1086BA_API HttpHeader* HttpRequest_getHeaders(HttpRequest* o, int* len);
1087BA_API int HttpRequest_wsUpgrade(HttpRequest* o);
1088BA_API BaBool HttpRequest_enableKeepAlive(HttpRequest* o);
1089BA_API int HttpRequest_pushBackData(HttpRequest* o);
1090#ifndef NO_HTTP_SESSION
1091BA_API struct HttpSession* HttpRequest_getSession(
1092 HttpRequest* o, BaBool create);
1093BA_API struct HttpSession* HttpRequest_session(
1094 HttpRequest* o, const char* val, size_t len, int set);
1095#endif
1096#ifdef __cplusplus
1097}
1098
1100 U32 methods, bool addDefault){
1101 return HttpRequest_checkMethods(this,resp,
1102 methods, addDefault ? TRUE : FALSE);}
1103
1104inline BaBool HttpRequest::checkTime(struct HttpResponse* resp, BaTime time) {
1105 return HttpRequest_checkTime(this, resp, time); }
1107 return HttpRequest_getAuthenticatedUser(this); }
1109 return HttpRequest_getMethodType(this); }
1110inline const char* HttpRequest::getMethod() {
1111 return HttpRequest_getMethod(this); }
1112inline const char* HttpRequest::getMethod(HttpMethod method) {
1113 return HttpRequest_getMethod2(method); }
1115 return HttpRequest_getServer(this); }
1116inline const char* HttpRequest::getRequestURI() {
1117 return HttpRequest_getRequestURI(this); }
1118inline const char* HttpRequest::getRequestURL(bool forceHttps) {
1119 return HttpRequest_getRequestURL(this, forceHttps); }
1121 return HttpRequest_getStdHeaders(this); }
1122inline const char* HttpRequest::getVersion() {
1123 return HttpRequest_getVersion(this); }
1124inline const char* HttpRequest::getHeaderValue(const char* name) {
1125 return HttpRequest_getHeaderValue(this, name); }
1126inline HttpCookie* HttpRequest::getCookie(const char* name) {
1127 return HttpRequest_getCookie(this, name); }
1128inline const char* HttpRequest::getParameter(const char* paramName) {
1129 return HttpRequest_getParameter(this, paramName); }
1131 return HttpRequest_wsUpgrade(this);
1132}
1133inline HttpHeader* HttpRequest::getHeaders(int* len) {
1134 return HttpRequest_getHeaders(this, len); }
1135inline int HttpRequest::setUserObj(void* userObj, bool overwrite) {
1136 return HttpRequest_setUserObj(this, userObj, overwrite); }
1137inline void* HttpRequest::getUserObj() {
1138 return HttpRequest_getUserObj(this); }
1139#ifndef NO_HTTP_SESSION
1140inline HttpSession* HttpRequest::getSession(BaBool create) {
1141 return HttpRequest_getSession(this, create); }
1142#endif
1144 return HttpParameterIterator_hasMoreElements(this); }
1146 return HttpRequest_getBuffer(this); }
1147#endif
1148
1149
1150#ifndef __DOXYGEN__
1151
1152typedef struct
1153{
1154 HttpAllocator data;
1155 U16 maxResponseHeader;
1156} NameValMM;
1157
1158
1159typedef struct
1160{
1161 U8 major;
1162 U8 minor;
1163} HttpProtocol;
1164
1165#endif
1166
1177typedef struct HttpResponse
1178{
1179#ifdef __cplusplus
1180
1183 U32 byteCount();
1184
1185
1189 HttpCookie* createCookie(const char* name);
1190
1201 const char* containsHeader(const char* name);
1202
1211 const char* encodeRedirectURL(const char* pathName);
1212
1222 const char* encodeRedirectURLWithParam(const char* pathName);
1223
1230 const char* encodeUrl(const char* path);
1231
1236 int flush();
1237
1263 int forward(const char* path);
1264
1285 int redirect(const char* path);
1286
1287
1291
1295
1296
1312 int include(const char* path);
1313
1318 bool committed() const;
1319
1323 bool isForward() const;
1324
1327 bool isInclude() const;
1328
1332 bool initial() const;
1333
1337 int resetHeaders();
1338
1343 int resetBuffer();
1344
1356 int sendError(int eCode);
1357
1371 int sendError(int eCode, const char* msg);
1372
1378 int sendBufAsError(int eCode);
1379
1385 int sendBufAsTxtError(int eCode);
1386
1387
1394 int fmtError(int eCode, const char* fmt, ...);
1395
1413 int sendRedirect(const char* url);
1414
1426 int redirect2TLS();
1427
1433 int setContentLength(BaFileSize len);
1434
1440 int setContentType(const char* type);
1441
1451 int setDateHeader(const char* name, BaTime time);
1452
1473 int setHeader(const char* name, const char* value, bool replace=true);
1474
1480 int setMaxAge(BaTime seconds);
1481
1482
1515 char* fmtHeader(const char* name, int valueLen, bool replace=true);
1516
1517
1532 void setStatus(int statusCode);
1533
1537 int printf(const char* fmt, ...);
1538
1546
1555 int write(const void* data, int len, int useBuffering=TRUE);
1556
1564 int write(const char* data, int useBuffering=TRUE);
1565
1570 int send(const void* data, int len);
1571
1578 int setDefaultHeaders();
1579
1599 int setResponseBuf(BufPrint* buf, bool useDefBuffer=true);
1600
1604 int removeResponseBuf();
1605
1606
1607 int setUserObj(void* userObj, bool overwrite=false);
1608#endif
1609 NameValMM nameValMM;
1610 BufPrint headerPrint;
1611 BufPrint defaultBodyPrint;
1612 BufPrint* bodyPrint;
1613 struct HttpDir* currentDir;
1614 char* encodedURL;
1615 char* encodedRedirectURL;
1616 HttpCookie* cookieList;
1617 void* userObj;
1618 int statusCode;
1619 U32 msgLen; /* Used if request is of type HEAD, count total msg len */
1620 HttpProtocol protocol;
1621 U16 includeCounter;
1622 U16 forwardCounter;
1623 char headerSent;
1624 char printAndWriteInitialized;
1625 char useChunkTransfer;
1627
1628#ifdef __cplusplus
1629extern "C" {
1630#endif
1631BA_API HttpCookie* HttpResponse_createCookie(
1632 struct HttpResponse* o,const char* name);
1633BA_API const char* HttpResponse_containsHeader(
1634 HttpResponse* o, const char* name);
1635BA_API int HttpResponse_dataAdded(HttpResponse* o, U32 size);
1636#define HttpResponse_byteCount(o) ((o)->msgLen + (o)->bodyPrint->cursor)
1637BA_API const char* HttpResponse_encodeRedirectURL(
1638 HttpResponse* o, const char* pathName);
1639BA_API const char* HttpResponse_encodeRedirectURLWithParamOrSessionURL(
1640 HttpResponse* o,const char* path,BaBool setUrlCookie);
1641#define HttpResponse_encodeRedirectURLWithParam(o, path) \
1642 HttpResponse_encodeRedirectURLWithParamOrSessionURL(o, path, FALSE)
1643#define HttpResponse_encodeSessionURL(o, path) \
1644 HttpResponse_encodeRedirectURLWithParamOrSessionURL(o, path, TRUE)
1645BA_API const char* HttpResponse_encodeUrl(HttpResponse* o, const char* path);
1646BA_API int HttpResponse_flush(HttpResponse* o);
1647#define HttpResponse_forward(o,path) HttpResponse_incOrForward(o,path,FALSE)
1648#define HttpResponse_getConnection(o) HttpResponse_getCommand(o)->con
1649#define HttpResponse_getRequest(o) (&HttpResponse_getCommand(o)->request)
1650BA_API struct HttpCommand* HttpResponse_getCommand(HttpResponse*);
1651#define HttpResponse_getBuf(o) (o)->bodyPrint->buf
1652#define HttpResponse_getBufSize(o) (o)->bodyPrint->bufSize
1653#define HttpResponse_getBufOffs(o) \
1654 ((o)->bodyPrint->buf + (o)->bodyPrint->cursor)
1655#define HttpResponse_getRemBufSize(o) \
1656 ((o)->bodyPrint->bufSize - (o)->bodyPrint->cursor)
1657#define HttpResponse_getUserObj(o) (o)->userObj
1658BA_API int HttpResponse_incOrForward(
1659 HttpResponse* o, const char* path, BaBool isInc);
1660BA_API int HttpResponse_redirect(HttpResponse* o, const char* path);
1661#define HttpResponse_include(o,path) HttpResponse_incOrForward(o,path,TRUE)
1662#define HttpResponse_isChunkTransfer(o) (o)->useChunkTransfer
1663#define HttpResponse_committed(o) (o)->headerSent
1664#define HttpResponse_isForward(o) ((o)->forwardCounter != 0)
1665#define HttpResponse_isInclude(o) ((o)->includeCounter != 0)
1666#define HttpResponse_initial(o) (!HttpResponse_isForward(o) && \
1667 !HttpResponse_isInclude(o))
1668BA_API int HttpResponse_setResponseBuf(
1669 HttpResponse* o,BufPrint* buf,BaBool useDefBuffer);
1670BA_API int HttpResponse_removeResponseBuf(HttpResponse* o);
1671
1672BA_API int HttpResponse_resetHeaders(HttpResponse* o);
1673BA_API int HttpResponse_resetBuffer(HttpResponse* o);
1674BA_API int HttpResponse_sendError1(HttpResponse* o, int eCode);
1675BA_API int HttpResponse_sendError2(HttpResponse* o,int eCode,const char* msg);
1676BA_API int HttpResponse_sendBufAsError(HttpResponse* o,int eCode);
1677BA_API int HttpResponse_sendBufAsTxtError(HttpResponse* o,int eCode);
1678BA_API int HttpResponse_fmtVError(
1679 HttpResponse* response,
1680 int eCode,
1681 const char* fmt,
1682 va_list varg);
1683BA_API int HttpResponse_fmtError(
1684 HttpResponse* response,
1685 int eCode,
1686 const char* fmt, ...);
1687BA_API int HttpResponse_sendRedirect(HttpResponse* o, const char* url);
1688BA_API int HttpResponse_sendRedirectI(
1689 HttpResponse* o, const char* url, int status);
1690BA_API int HttpResponse_redirect2TLS(HttpResponse* o);
1691#define HttpResponse_forceHttps HttpResponse_redirect2TLS /* Backw. comp. */
1692
1693#define HttpResponse_setBufPos(o, pos) (o)->bodyPrint->cursor = pos
1694BA_API int HttpResponse_setContentLength(HttpResponse* o, BaFileSize len);
1695BA_API int HttpResponse_setContentType(HttpResponse* o, const char* type);
1696BA_API int HttpResponse_checkContentType(HttpResponse* o, const char* type);
1697BA_API int HttpResponse_setDateHeader(
1698 HttpResponse* o, const char* name, BaTime t);
1699BA_API int HttpResponse_setHeader(
1700 HttpResponse* o,const char* name,const char* value, BaBool replace);
1701BA_API int HttpResponse_setMaxAge(HttpResponse* response, BaTime seconds);
1702BA_API char* HttpResponse_fmtHeader(
1703 HttpResponse* o, const char* name, int valueLen, BaBool replace);
1704BA_API int HttpResponse_setStatus(HttpResponse* o, int eCode);
1705BA_API int HttpResponse_vprintf(
1706 HttpResponse* o, const char* fmt, va_list argList);
1707BA_API int HttpResponse_printf(HttpResponse* o, const char* fmt, ...);
1708BA_API int HttpResponse_write(HttpResponse* o, const void* data, int len,
1709 int useBuffering);
1710BA_API BufPrint* HttpResponse_getWriter(HttpResponse* o);
1711BA_API int HttpResponse_send(HttpResponse* o, const void* data, int len);
1712BA_API int HttpResponse_setDefaultHeaders(HttpResponse* o);
1713BA_API int HttpResponse_downgrade(HttpResponse* o);
1714BA_API int HttpResponse_setUserObj(
1715 HttpResponse* o,void* userObj,BaBool overwrite);
1716BA_API int HttpResponse_printAndWriteInit(HttpResponse* o);
1717BA_API int HttpResponse_send100Continue(HttpResponse* o);
1718BA_API int HttpResponse_setChunkEncoding(HttpResponse* o);
1719BA_API const char* HttpResponse_getRespData(HttpResponse* o, int* len);
1720#define HttpResponse_getStatus(o) (o)->statusCode
1721#ifdef __cplusplus
1722}
1723inline HttpCookie* HttpResponse::createCookie(const char* name) {
1724 return HttpResponse_createCookie(this, name); }
1725inline const char* HttpResponse::containsHeader(const char* name) {
1726 return HttpResponse_containsHeader(this, name); }
1728 return HttpResponse_byteCount(this); }
1729inline const char* HttpResponse::encodeRedirectURL(const char* pathName) {
1730 return HttpResponse_encodeRedirectURL(this, pathName); }
1731inline const char* HttpResponse::encodeRedirectURLWithParam(const char* p) {
1732 return HttpResponse_encodeRedirectURLWithParam(this, p); }
1733inline const char* HttpResponse::encodeUrl(const char* path) {
1734 return HttpResponse_encodeUrl(this, path); }
1736 return HttpResponse_flush(this); }
1737inline int HttpResponse::forward(const char* path) {
1738 return HttpResponse_forward(this, path); }
1739inline int HttpResponse::redirect(const char* path) {
1740 return HttpResponse_redirect(this, path); }
1741inline int HttpResponse::include(const char* path) {
1742 return HttpResponse_include(this, path); }
1743inline bool HttpResponse::committed() const {
1744 return HttpResponse_committed(this) ? true : false; }
1745inline bool HttpResponse::isForward() const {
1746 return HttpResponse_isForward(this) ? true : false; }
1747inline bool HttpResponse::isInclude() const {
1748 return HttpResponse_isInclude(this) ? true : false; }
1749inline bool HttpResponse::initial() const {
1750 return HttpResponse_initial(this) ? true : false; }
1751inline int HttpResponse::setResponseBuf(BufPrint* buf, bool useDefBuffer) {
1752 return HttpResponse_setResponseBuf(this, buf, useDefBuffer?TRUE:FALSE); }
1754 return HttpResponse_removeResponseBuf(this); }
1756 return HttpResponse_resetHeaders(this); }
1758 return HttpResponse_resetBuffer(this); }
1759inline int HttpResponse::sendError(int eCode) {
1760 return HttpResponse_sendError1(this, eCode); }
1761inline int HttpResponse::sendError(int eCode, const char* msg) {
1762 return HttpResponse_sendError2(this, eCode, msg); }
1763inline int HttpResponse::sendBufAsError(int eCode) {
1764 return HttpResponse_sendBufAsError(this, eCode); }
1765inline int HttpResponse::sendBufAsTxtError(int eCode) {
1766 return HttpResponse_sendBufAsTxtError(this,eCode);}
1767inline int HttpResponse::fmtError(int eCode,const char* fmt,...) {
1768 int retv; va_list varg;
1769 va_start(varg, fmt);
1770 retv = HttpResponse_fmtVError(this, eCode, fmt, varg);
1771 va_end(varg);
1772 return retv; }
1773inline int HttpResponse::sendRedirect(const char* url) {
1774 return HttpResponse_sendRedirect(this, url); }
1776 return HttpResponse_redirect2TLS(this); }
1777inline int HttpResponse::setContentLength(BaFileSize len) {
1778 return HttpResponse_setContentLength(this, len); }
1779inline int HttpResponse::setContentType(const char* type) {
1780 return HttpResponse_setContentType(this, type); }
1781inline int HttpResponse::setDateHeader(const char* name, BaTime t) {
1782 return HttpResponse_setDateHeader(this, name, t); }
1784 const char* name, const char* value, bool replace) {
1785 return HttpResponse_setHeader(this,name, value, replace?TRUE:FALSE); }
1786inline int HttpResponse::setMaxAge(BaTime seconds) {
1787 return HttpResponse_setMaxAge(this, seconds); }
1789 const char* name, int valueLen, bool replace) {
1790 return HttpResponse_fmtHeader(this, name, valueLen, replace?TRUE:FALSE); }
1791inline void HttpResponse::setStatus(int eCode) {
1792 HttpResponse_setStatus(this, eCode);}
1793
1794inline int HttpResponse::printf(const char* fmt, ...) {
1795 int retv; va_list varg; va_start(varg, fmt);
1796 retv = HttpResponse_vprintf(this, fmt, varg); va_end(varg); return retv;}
1797inline int HttpResponse::write(const char* data, int useBuffering) {
1798 return HttpResponse_write(this, data, iStrlen(data), useBuffering); }
1800 return HttpResponse_getWriter(this); }
1801inline int HttpResponse::write(const void* data, int len, int useBuffering){
1802 return HttpResponse_write(this, data, len, useBuffering); }
1803inline int HttpResponse::send(const void* data, int len) {
1804 return HttpResponse_send(this, data, len); }
1806 return HttpResponse_setDefaultHeaders(this); }
1807inline int HttpResponse::setUserObj(void* userObj, bool overwrite) {
1808 return HttpResponse_setUserObj(this, userObj, overwrite); }
1809
1810#endif
1811
1817typedef struct HttpCommand
1818{
1819#ifdef __cplusplus
1820
1824
1828
1832 struct HttpConnection* getConnection();
1833
1835 struct HttpServer* getServer();
1836
1837 HttpCommand() {}
1838#endif
1839 DoubleLink super;
1840#ifdef __cplusplus
1841 public:
1842#endif
1843 HttpRequest request;
1844 HttpResponse response;
1845 struct HttpConnection* con;
1846 struct LHttpCommand* lcmd; /* Used by LSP plugin */
1847 BaTime requestTime;
1848 BaBool runningInThread;
1850
1851#define HttpCommand_getRequest(o) (&(o)->request)
1852#define HttpCommand_getResponse(o) (&(o)->response)
1853#define HttpCommand_getConnection(o) (o)->con
1854#define HttpCommand_getServer(o) HttpConnection_getServer((o)->con)
1855#ifdef __cplusplus
1857 return HttpCommand_getRequest(this); }
1859 return HttpCommand_getResponse(this); }
1861 return HttpCommand_getConnection(this); }
1863 return HttpCommand_getServer(this);
1864}
1865#endif
1866
1867
1868#ifndef NO_HTTP_SESSION
1869
1870#ifndef __DOXYGEN__
1873#endif
1874
1882 struct HttpSessionAttribute* o);
1883
1912{
1913#ifdef __cplusplus
1919 HttpSessionAttribute(const char* name,
1921
1925#endif
1926 struct HttpSessionAttribute* next;
1927 struct HttpSession* session;
1929 char* name;
1931
1932#ifdef __cplusplus
1933extern "C" {
1934#endif
1935
1936BA_API void HttpSessionAttribute_constructor(
1938 const char* name,
1940BA_API void HttpSessionAttribute_destructor(HttpSessionAttribute* o);
1941#define HttpSessionAttribute_getSession(o) (o)->session
1942#ifdef __cplusplus
1943}
1945 const char* name,
1947 HttpSessionAttribute_constructor(this, name, d); }
1949 return HttpSessionAttribute_getSession(this); }
1950
1951#endif
1952
1958typedef struct HttpSession
1959{
1960#ifdef __cplusplus
1961
1962 void *operator new(size_t s) { return ::baMalloc(s); }
1963 void operator delete(void* d) { if(d) ::baFree(d); }
1964 void *operator new(size_t, void *place) { return place; }
1965 void operator delete(void*, void *) { }
1966
1981 void terminate();
1982
1986 HttpSessionAttribute* getAttribute(const char* name);
1987
1992
1998
2003
2006
2009 int removeAttribute(const char* name);
2010
2014
2018 void setMaxInactiveInterval(BaTime interval);
2019
2025 void incrRefCntr();
2026
2032 void decrRefCntr();
2033
2037 U32 getId();
2038
2042
2045 U32 getUseCounter();
2046
2047
2048 void incrementLock();
2049 void decrementLock();
2050
2051 HttpSession() {}
2052 private:
2053#endif
2054 SplayTreeNode super; /* inherits from SplayTreeNode */
2055 DoubleLink dlink;
2056 HttpSockaddr peer;
2057 HttpSessionAttribute* attrList;
2058 struct HttpSessionContainer* container;
2059 BaTime creationTime;
2060 BaTime lastAccessedTime;
2061 BaTime maxInactiveInterval;
2062 U32 sesrnd1; /* Session random number 1 & 2 */
2063 U32 sesrnd2; /* entropy id+sesrnd1+sesrnd2=96 bits */
2064 U32 useCounter;
2065 int refCounter;
2066 U16 lockCounter;
2067 U8 termPending; /* TRUE if in termination list */
2069
2070
2071#ifdef __cplusplus
2072extern "C" {
2073#endif
2074BA_API HttpSessionAttribute* HttpSession_getAttribute(HttpSession* o,
2075 const char* name);
2076BA_API BaTime HttpSession_getCreationTime(HttpSession* o);
2077BA_API BaTime HttpSession_getLastAccessedTime(HttpSession* o);
2078BA_API BaTime HttpSession_getMaxInactiveInterval(HttpSession* o);
2079BA_API struct HttpServer* HttpSession_getServer(HttpSession* o);
2080BA_API void HttpSession_terminate(HttpSession* o);
2081BA_API BaBool HttpSession_isNew(HttpSession* o);
2082BA_API int HttpSession_removeAttribute(HttpSession* o, const char* name);
2083BA_API int HttpSession_setAttribute(HttpSession* o,
2084 HttpSessionAttribute* value);
2085BA_API void HttpSession_setMaxInactiveInterval(HttpSession* o,BaTime interval);
2086#define HttpSession_incrRefCntr(o) (o)->refCounter++
2087BA_API void HttpSession_decrRefCntr(HttpSession* o);
2088#define HttpSession_incrementLock(o) (o)->lockCounter++
2089#define HttpSession_decrementLock(o) do {\
2090 baAssert((o)->lockCounter > 0);\
2091 (o)->lockCounter--; } while(0)
2092BA_API int HttpSession_fmtSessionId(HttpSession* o, U8* buf, size_t bufSize);
2093#define HttpSession_getId(o) \
2094 ((U32)((ptrdiff_t)SplayTreeNode_getKey((SplayTreeNode*)(o))))
2095#define HttpSession_getAuthenticatedUser(o) AuthenticatedUser_get2((o))
2096#define HttpSession_getUseCounter(o) (o)->useCounter
2097#define HttpSession_getPeerName(o) (&(o)->peer)
2098#ifdef __cplusplus
2099}
2101 return HttpSession_getAttribute(this, name); }
2103 return HttpSession_getCreationTime(this); }
2105 return HttpSession_getLastAccessedTime(this); }
2107 return HttpSession_getMaxInactiveInterval(this); }
2109 return HttpSession_getServer(this); }
2111 HttpSession_terminate(this); }
2112inline int HttpSession::removeAttribute(const char* name) {
2113 return HttpSession_removeAttribute(this, name); }
2115 return HttpSession_setAttribute(this, value); }
2117 HttpSession_setMaxInactiveInterval(this, interval); }
2119 HttpSession_incrRefCntr(this); }
2121 HttpSession_decrRefCntr(this); }
2122inline U32 HttpSession::getId() { return HttpSession_getId(this); }
2124 return HttpSession_getUseCounter(this); }
2126 return HttpSession_getAuthenticatedUser(this); }
2127inline void HttpSession::incrementLock() {HttpSession_incrementLock(this);}
2128inline void HttpSession::decrementLock() {HttpSession_decrementLock(this);}
2129
2130#endif /* __cplusplus */
2131
2132typedef enum {
2133 HttpSessionContainer_OK = 0,
2134 HttpSessionContainer_NoMemory,
2135 HttpSessionContainer_TooManySessions,
2136 HttpSessionContainer_NoPeerAddress
2137} HttpSessionContainer_ECode;
2138
2139
2144{
2145#ifdef __cplusplus
2152 void setMaxSessions(int max);
2153 private:
2154#endif
2155 SplayTree sessionTree;
2156 DoubleList sessionList;
2157 DoubleList sessionTermList;
2158 DoubleLink* sessionLinkIter;
2159 struct HttpServer* server;
2160 int noOfSessions; /* Current number of active sessions */
2161 int maxSessions;
2162 HttpSessionContainer_ECode eCode;
2164
2165#ifdef __cplusplus
2166extern "C" {
2167#endif
2168void HttpSessionContainer_constructor(struct HttpSessionContainer* o,
2169 struct HttpServer* server,
2170 U16 maxSessions);
2171void HttpSessionContainer_destructor(struct HttpSessionContainer* o);
2172void HttpSessionContainer_sessionTimer(struct HttpSessionContainer* o);
2173#define HttpSessionContainer_setMaxSessions(o,max) (o)->maxSessions = max
2174#ifdef __cplusplus
2175}
2177 HttpSessionContainer_setMaxSessions(this, max); }
2178#endif
2179
2180#endif /* NO_HTTP_SESSION */
2181
2182
2190typedef void (*HttpPage_Service)(struct HttpPage* page,
2191 HttpRequest* request,
2192 HttpResponse* response);
2193
2194
2195#define HttpPageType_HttpPageSE 0x00020
2196
2197#ifndef __DOXYGEN__
2198typedef struct HttpPageNode
2199{
2200 struct HttpPageNode* next;
2201} HttpPageNode;
2202#endif
2203
2255typedef struct HttpPage
2256{
2257#ifdef __cplusplus
2258 void *operator new(size_t s) { return ::baMalloc(s); }
2259 void operator delete(void* d) { if(d) ::baFree(d); }
2260 void *operator new(size_t, void *place) { return place; }
2261 void operator delete(void*, void *) { }
2262 HttpPage() {}
2271 HttpPage(HttpPage_Service service, const char* name);
2272
2275 ~HttpPage();
2276
2279 const char* getName() const { return name; }
2280
2285 void service(HttpRequest* request, HttpResponse* response);
2286
2290 bool isLinked();
2291
2294 int unlink();
2295#endif
2296 HttpPageNode super; /* As if inherited */
2297 HttpPage_Service serviceCB;
2298 const char* name;
2300
2301#ifdef __cplusplus
2302extern "C" {
2303#endif
2304void
2305BA_API HttpPage_constructor(
2306 HttpPage* o, HttpPage_Service service, const char* name);
2307BA_API void HttpPage_destructor(HttpPage* o);
2308#define HttpPage_getName(o) (o)->name
2309#define HttpPage_isLinked(o) ((HttpPageNode*)(o))->next
2310BA_API int HttpPage_unlink(HttpPage* o);
2311#define HttpPage_service(o, request, response) \
2312 (o)->serviceCB(o, request, response)
2313#ifdef __cplusplus
2314}
2315inline HttpPage::HttpPage(HttpPage_Service service, const char* name) {
2316 HttpPage_constructor(this, service, name); }
2318 HttpPage_destructor(this); }
2319inline bool HttpPage::isLinked() {
2320 return HttpPage_isLinked(this) ? true : false;
2321}
2322inline int HttpPage::unlink() {return HttpPage_unlink(this); }
2323inline void HttpPage::service(HttpRequest* request, HttpResponse* response) {
2324 HttpPage_service(this, request, response);
2325}
2326#endif
2327
2328
2334typedef int (*HttpDir_Service)(struct HttpDir* o,
2335 const char* relPath,
2336 HttpCommand* cmd);
2337
2338#define HttpDirType_EhDir 0x00001
2339#define HttpDirType_HttpResRdr 0x00002
2340#define HttpDirType_AuthenticateDir 0x00008
2341#define HttpDirType_AuthenticateDirWrapper 0x00010
2342
2343
2367typedef struct HttpDir
2368{
2369#ifdef __cplusplus
2370 void *operator new(size_t s) { return ::baMalloc(s); }
2371 void operator delete(void* d) { if(d) ::baFree(d); }
2372 void *operator new(size_t, void *place) { return place; }
2373 void operator delete(void*, void *) { }
2375 HttpDir();
2376
2393 HttpDir(const char* name, S8 priority=0);
2394 ~HttpDir();
2395
2399 int insertDir(HttpDir* dir);
2400
2404 int insertPage(HttpPage* page);
2405
2409
2413
2416 HttpDir* getDir(const char* name);
2417
2420 HttpPage* getPage(const char* name);
2421
2424 HttpDir* getNext();
2425
2435 HttpPage* findPage(HttpPage* iter, const char* name);
2436
2448 static HttpDir* findDir(HttpDir* iter, const char* name,
2449 unsigned int nameLen);
2450
2457 HttpDir* createOrGet(const char* name);
2458
2461 const char* getName() const { return name; }
2462
2465 HttpDir* getParent() const { return parent; }
2466
2489 char* makeAbsPath(const char* relPath, int relPathLen);
2490
2502 char* getRootPath();
2503
2504
2509
2519 void p403(const char* p403);
2520
2524 bool isLinked();
2525
2528 int unlink();
2529
2534 void setAuthenticator(
2535 struct AuthenticatorIntf* authenticator,
2536 struct AuthorizerIntf* authorizer=0);
2537
2558 bool authenticateAndAuthorize(HttpCommand* cmd,const char* path);
2559
2560
2561#endif
2562 HttpDir_Service service;
2563 struct HttpDir* parent; /* owner */
2564 struct HttpDir* next; /* next sibling */
2565 const char* name; /* e.g. /mydir/ */
2566 struct HttpDir* dirList; /* list of httpdirs (children) */
2567 struct AuthorizerIntf* realm; /* If we have authorization */
2568 struct AuthenticatorIntf* authenticator; /* If we have authentic. */
2569 char* _p403; /* If we have a 403 denied response page. */
2570 HttpPageNode pageList; /* pages for this dir */
2571 /* U8 type; */
2572 S8 priority;
2574
2575#ifdef __cplusplus
2576extern "C" {
2577#endif
2578BA_API void HttpDir_constructor(HttpDir* o, const char* name, S8 priority);
2579BA_API void HttpDir_destructor(HttpDir* o);
2580BA_API char* HttpDir_makeAbsPath(
2581 HttpDir* o, const char* relPath, int relPathLen);
2582#define HttpDir_getRootPath(o) HttpDir_makeAbsPath(o,"",0)
2583BA_API int HttpDir_insertDir(HttpDir* o, HttpDir* dir);
2584#define HttpDir_getFirstPage(o) \
2585 (o)->pageList.next != &(o)->pageList ? ((HttpPage*)(o)->pageList.next) : 0
2586#define HttpDir_getFirstDir(o) (o)->dirList
2587BA_API HttpDir* HttpDir_getDir(HttpDir* o, const char* name);
2588BA_API HttpPage* HttpDir_getPage(HttpDir* o, const char* name);
2589#define HttpDir_getNext(o) (o)->next
2590#define HttpDir_getName(o) (o)->name
2591#define HttpDir_getParent(o) (o)->parent
2592BA_API int HttpDir_insertPage(HttpDir* o, HttpPage* page);
2593BA_API HttpPage* HttpDir_findPage(
2594 HttpDir* o, HttpPage* iter, const char* name);
2595BA_API HttpDir* HttpDir_findDir(
2596 HttpDir* iter, const char* name,unsigned int nameLen);
2597BA_API HttpDir* HttpDir_createOrGet(HttpDir* o, const char* name);
2598BA_API void HttpDir_p403(HttpDir* o, const char* p403);
2599BA_API HttpDir_Service HttpDir_overloadService(HttpDir*o, HttpDir_Service s);
2600#define HttpDir_isLinked(o) (o)->parent
2601BA_API int HttpDir_unlink(HttpDir* o);
2602#define HttpDir_setAuthenticator(o,authenticatorMA,authorizerMA) \
2603 (o)->authenticator = authenticatorMA,(o)->realm = authorizerMA
2604BA_API int HttpDir_authenticateAndAuthorize(
2605 HttpDir* o,HttpCommand* cmd,const char* path);
2606#define HttpDir_isAuthorized(o,user,method,path) \
2607 ((o)->realm ? \
2608 (user ? AuthorizerIntf_authorize((o)->realm,user,method,path) : FALSE) : \
2609 TRUE)
2610#ifdef __cplusplus
2611}
2613 HttpDir_constructor(this, 0, 0); }
2614inline HttpDir::HttpDir(const char* name, S8 priority) {
2615 HttpDir_constructor(this, name, priority); }
2616inline HttpDir::~HttpDir() {
2617 HttpDir_destructor(this); }
2618inline char* HttpDir::makeAbsPath(const char* relPath, int relPathLen) {
2619 return HttpDir_makeAbsPath(this, relPath, relPathLen); }
2620inline char* HttpDir::getRootPath() {
2621 return HttpDir_getRootPath(this); }
2622inline int HttpDir::insertDir(HttpDir* dir) {
2623 return HttpDir_insertDir(this, dir); }
2625 return HttpDir_insertPage(this, page); }
2626inline HttpPage* HttpDir::getFirstPage() { return HttpDir_getFirstPage(this); }
2627inline HttpDir* HttpDir::getFirstDir() { return HttpDir_getFirstDir(this); }
2628inline HttpDir* HttpDir::getDir(const char* name) {
2629 return HttpDir_getDir(this,name); }
2630inline HttpPage* HttpDir::getPage(const char* name) {
2631 return HttpDir_getPage(this,name); }
2632inline HttpDir* HttpDir::getNext() { return HttpDir_getNext(this); }
2633inline HttpPage* HttpDir::findPage(HttpPage* iter, const char* name) {
2634 return HttpDir_findPage(this, iter, name); }
2635inline HttpDir* HttpDir::findDir(HttpDir* iter, const char* name,
2636 unsigned int nameLen) {
2637 return HttpDir_findDir(iter, name, nameLen); }
2638inline HttpDir* HttpDir::createOrGet(const char* name) {
2639 return HttpDir_createOrGet(this, name); }
2641 return HttpDir_overloadService(this, s); }
2642inline void HttpDir::p403(const char* p403) {
2643 HttpDir_p403(this, p403); }
2644inline int HttpDir::unlink() {return HttpDir_unlink(this); }
2645inline bool HttpDir::isLinked() {
2646 return HttpDir_isLinked(this) ? true : false; }
2647inline void HttpDir::setAuthenticator(struct AuthenticatorIntf* authenticator,
2648 struct AuthorizerIntf* authorizer){
2649 HttpDir_setAuthenticator(this,authenticator,authorizer);
2650}
2652 HttpCommand* cmd, const char* path) {
2653 return HttpDir_authenticateAndAuthorize(this,cmd,path) ? true : false; }
2654#endif
2655
2656#ifndef __DOXYGEN__
2657
2658typedef struct HttpLinkCon
2659{
2660 HttpConnection con; /* Inherits from HttpConnection */
2661 DoubleLink link;
2662} HttpLinkCon;
2663
2664
2665typedef struct
2666{
2667 HttpDir super; /* inherit */
2668 HttpDir_Service superServiceFunc;
2669 char* page404;
2670 BaBool page404InProgress;
2671} HttpRootDir;
2672
2673#endif
2674
2683typedef struct HttpServerConfig
2684{
2685#ifdef __cplusplus
2692
2722 int setRequest(S16 min, S16 max);
2723
2735 int setResponseHeader(U16 min, U16 max);
2736
2749 int setResponseData(U16 size);
2750
2764 int setCommit(U16 size);
2765
2778 int setNoOfHttpCommands(U16 size);
2779
2801 int setNoOfHttpConnections(U16 size);
2802
2808 int setMaxSessions(U16 size);
2809#endif
2810 S16 minRequest;
2811 S16 maxRequest;
2812 U16 minResponseHeader;
2813 U16 maxResponseHeader;
2814 U16 commit;
2815 U16 responseData;
2816 U16 noOfHttpCommands;
2817 U16 noOfHttpConnections;
2818 U16 maxSessions;
2820
2821#ifdef __cplusplus
2822extern "C" {
2823#endif
2824BA_API void HttpServerConfig_constructor(HttpServerConfig* o);
2825BA_API int HttpServerConfig_setRequest(HttpServerConfig* o, S16 min, S16 max);
2826BA_API int HttpServerConfig_setResponseHeader(
2827 HttpServerConfig* o, U16 min, U16 max);
2828BA_API int HttpServerConfig_setResponseData(HttpServerConfig* o, U16 size);
2829BA_API int HttpServerConfig_setCommit(HttpServerConfig* o, U16 size);
2830BA_API int HttpServerConfig_setNoOfHttpCommands(HttpServerConfig* o, U16 size);
2831BA_API int HttpServerConfig_setNoOfHttpConnections(
2832 HttpServerConfig* o, U16 size);
2833BA_API int HttpServerConfig_setMaxSessions(HttpServerConfig* o, U16 size);
2834#ifdef __cplusplus
2835}
2837 HttpServerConfig_constructor(this); }
2838inline int HttpServerConfig::setRequest(S16 min, S16 max) {
2839 return HttpServerConfig_setRequest(this, min, max); }
2840inline int HttpServerConfig::setResponseHeader(U16 min, U16 max) {
2841 return HttpServerConfig_setResponseHeader(this, min, max); }
2843 return HttpServerConfig_setResponseData(this, size); }
2844inline int HttpServerConfig::setCommit(U16 size) {
2845 return HttpServerConfig_setCommit(this, size); }
2847 return HttpServerConfig_setNoOfHttpCommands(this, size); }
2849 return HttpServerConfig_setNoOfHttpConnections(this, size); }
2851 return HttpServerConfig_setMaxSessions(this, size); }
2852
2853#endif
2854
2855
2856typedef DoubleList HttpLinkConList;
2857
2858/* Used by LSP plugin */
2859typedef void (*LspOnTerminateRequest)(struct LHttpCommand* lcmd);
2860
2863typedef struct HttpServer
2864{
2865#ifdef __cplusplus
2866 void *operator new(size_t s) { return ::baMalloc(s); }
2867 void operator delete(void* d) { if(d) ::baFree(d); }
2868 void *operator new(size_t, void *place) { return place; }
2869 void operator delete(void*, void *) { }
2876 HttpServer(SoDisp* dispatcher, HttpServerConfig* cfg=0);
2877
2878 ~HttpServer();
2879
2891 int insertRootDir(HttpDir* dir);
2892
2914 int insertDir(const char* virtualDirRootPath, HttpDir* dir);
2915
2955 int insertCSP(CspInit cspInit,
2956 const char* virtualDirRootPath,
2957 struct CspReader* reader);
2958
2959 struct AuthUserList* getAuthUserList(const char* name);
2960
2963
2966
2972
2976
2977#ifndef NO_HTTP_SESSION
2987 HttpSession* getSession(U32 id);
2988#endif
2989
2998 void set404Page(const char* page404);
2999
3001 const char* get404Page();
3002
3003 int setUserObj(void* userObj, bool overwrite=false);
3004
3010 static void initStatic(void);
3011
3022 static void setErrHnd(UserDefinedErrHandler e);
3023
3024 /* No longer used */
3025 static int setZlib(ZlibInflateInit2 init,
3026 ZlibInflate inflate,
3027 ZlibInflateEnd end){
3028 (void)init; (void)inflate; (void)end;
3029 return 0; }
3032 static const char* getStatusCode(int code);
3033
3034
3035#endif
3036 DoubleList commandPool;
3037 DoubleList cmdReqList;
3038 HttpConnection noOpCon;
3039 HttpLinkConList freeList;
3040 HttpLinkConList readyList;
3041 HttpLinkConList connectedList;
3042 HttpRootDir rootDirContainer;
3043 SplayTree authUserTree; /* Used by AuthenticatedUser.c */
3044 struct HttpCmdThreadPoolIntf* threadPoolIntf;
3045 HttpLinkCon* connections;
3046 SoDisp* dispatcher;
3047 void* userObj;
3048 void* waitForConClose; /* See HttpServer_doLingeringClose */
3049 LspOnTerminateRequest lspOnTerminateRequest;
3050 int commandPoolSize;
3051 U16 noOfConnections;
3052 S16 maxHttpRequestLen;
3053#ifndef NO_HTTP_SESSION
3054 HttpSessionContainer sessionContainer;
3055#endif
3057
3058
3059/* Used exclusively by HttpCmdThreadPool */
3060void HttpServer_AsynchProcessDir(HttpServer* o,
3061 HttpDir* dir,
3062 HttpCommand* cmd);
3063/* Used exclusively by HttpCmdThreadPool */
3064#define HttpServer_setThreadPoolIntf(o, intf) (o)->threadPoolIntf=intf
3065#define HttpServer_luaenv(o) (o)->luaenv
3066
3067#ifdef __cplusplus
3068extern "C" {
3069#endif
3070BA_API void HttpServer_constructor(HttpServer*,SoDisp*, HttpServerConfig*);
3071BA_API void HttpServer_destructor(HttpServer* o);
3072BA_API int HttpServer_insertRootDir(HttpServer* o, HttpDir* dir);
3073BA_API int HttpServer_insertDir(HttpServer* o,
3074 const char* virtualDirRootPath,
3075 HttpDir* dir);
3076BA_API int HttpServer_insertCSP(HttpServer* o,
3077 CspInit cspInit,
3078 const char* virtualDirRootPath,
3079 struct CspReader* reader);
3080#define HttpServer_getAuthUserList(o, name) \
3081 (AuthUserList*)SplayTree_find(&(o)->authUserTree, name)
3082#define HttpServer_getDispatcher(o) (o)->dispatcher
3083#define HttpServer_getFirstRootDir(o) \
3084 HttpDir_getFirstDir((HttpDir*)&(o)->rootDirContainer)
3085#define HttpServer_getUserObj(o) (o)->userObj
3086#define HttpServer_getSessionContainer(o) (&(o)->sessionContainer)
3087#define HttpServer_getMutex(o) SoDisp_getMutex((o)->dispatcher)
3088BA_API const char* HttpServer_getStatusCode(int code);
3089void HttpServer_addCon2ConnectedList(HttpServer* o, HttpConnection* con);
3090void HttpServer_doLingeringClose(
3091 HttpServer* o, HttpConnection* con, BaFileSize contLen);
3092
3093#ifndef NO_HTTP_SESSION
3094BA_API HttpSession* HttpServer_getSession(HttpServer* o, U32 id);
3095#endif
3096BA_API HttpConnection* HttpServer_getFreeCon(HttpServer* o);
3097void HttpServer_returnFreeCon(HttpServer* o, HttpConnection* con);
3098BA_API void HttpServer_installNewCon(HttpServer* o, HttpConnection* con);
3099BA_API void HttpServer_setErrHnd(UserDefinedErrHandler e);
3100void HttpServer_initStatic(void);
3101int HttpServer_termOldestIdleCon(HttpServer* o);
3102BA_API void HttpServer_set404Page(HttpServer*o, const char* page404);
3103#define HttpServer_get404Page(o) (o)->rootDirContainer.page404
3104BA_API int HttpServer_setUserObj(
3105 HttpServer* o, void* userObj, BaBool overwrite);
3106#define HttpServer_termAllSessions(o) \
3107 HttpSessionContainer_destructor(&(o)->sessionContainer)
3108/* No longer used */
3109#define HttpServer_setZlib(init,inflate,end);
3110#ifdef __cplusplus
3111}
3113 HttpServer_constructor(this, disp, cfg); }
3114inline HttpServer::~HttpServer() {
3115 HttpServer_destructor(this); }
3117 return HttpServer_insertRootDir(this, dir); }
3119 return HttpServer_getMutex(this);
3120}
3121inline int HttpServer::insertDir(const char* virtualDirRootPath,HttpDir* dir){
3122 return HttpServer_insertDir(this, virtualDirRootPath, dir); }
3124 const char* virtualDirRootPath,
3125 struct CspReader* reader) {
3126 return HttpServer_insertCSP(this, cspInit, virtualDirRootPath, reader); }
3127inline struct AuthUserList* HttpServer::getAuthUserList(const char* name) {
3128 return HttpServer_getAuthUserList(this,name); }
3130 return HttpServer_getDispatcher(this); }
3132 return HttpServer_getFirstRootDir(this); }
3134 return HttpServer_getSessionContainer(this); }
3135#ifndef NO_HTTP_SESSION
3137 return HttpServer_getSession(this, id); }
3138inline void HttpServer::initStatic(void) {
3139 HttpServer_initStatic(); }
3140inline void HttpServer::setErrHnd(UserDefinedErrHandler e) {
3141 HttpServer_setErrHnd(e); }
3142inline void HttpServer::set404Page(const char* page404) {
3143 HttpServer_set404Page(this, page404); }
3144inline const char* HttpServer::get404Page() {
3145 return HttpServer_get404Page(this); }
3146inline int HttpServer::setUserObj(void* userObj, bool overwrite) {
3147 return HttpServer_setUserObj(this, userObj, overwrite); }
3148inline const char* HttpServer::getStatusCode(int code) {
3149 return HttpServer_getStatusCode(code);
3150}
3151#endif
3152
3153
3155 return HttpRequest_getResponse(this); }
3157 return HttpRequest_getConnection(this); }
3159 return HttpResponse_getRequest(this); }
3161 return HttpResponse_getCommand(this); }
3163 return HttpRequest_getCommand(this); }
3165 return HttpConnection_getServer(this); }
3166
3167#endif /* __cplusplus */
3168 /* end of StdWebServer */
3170
3171/* Internal use */
3172#ifdef NO_SHARKSSL
3173
3174#define SHARKSSL_MD5_HASH_LEN 16
3175#define SHARKSSL_SHA1_HASH_LEN 20
3176
3177typedef struct SharkSslMd5Ctx
3178{
3179 U32 total[2];
3180 U32 state[4];
3181 U8 buffer[64];
3182} SharkSslMd5Ctx;
3183
3184SHARKSSL_API void SharkSslMd5Ctx_constructor(SharkSslMd5Ctx* ctx);
3185SHARKSSL_API void SharkSslMd5Ctx_append(SharkSslMd5Ctx* ctx, const U8* data, U32 len);
3186SHARKSSL_API void SharkSslMd5Ctx_finish(SharkSslMd5Ctx* ctx, U8 digest[]);
3187SHARKSSL_API int sharkssl_md5(const U8*, U16, U8*);
3188
3189typedef struct SharkSslSha1Ctx
3190{
3191 U32 total[2];
3192 U32 state[5];
3193 U8 buffer[64];
3194} SharkSslSha1Ctx;
3195
3196SHARKSSL_API void SharkSslSha1Ctx_constructor(SharkSslSha1Ctx* ctx);
3197SHARKSSL_API void SharkSslSha1Ctx_append(SharkSslSha1Ctx* ctx, const U8* data, U32 len);
3198SHARKSSL_API void SharkSslSha1Ctx_finish(SharkSslSha1Ctx*, U8 digest[]);
3199
3200typedef void SharkSsl;
3201
3202#endif
3203
3204#endif /* __httpServer_h */
void(* CspInit)(struct HttpDir *cspRoot, struct CspReader *reader)
Function prototype for the "initialize function" generated by CspLink.
Definition: HttpServer.h:182
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:2104
void deleteCookie()
Specifies a path for the cookie to which the client should return the cookie.
Definition: HttpServer.h:666
HttpHeader * getHeaders(int *len)
Return a HTTP header iterator that can iterate and fetch all the HTTP headers.
Definition: HttpServer.h:1133
int include(const char *path)
Includes the content of a resource (servlet, CSP page, HTML file) in the response.
Definition: HttpServer.h:1741
BaTime getCreationTime()
Returns the time when this session was created, measured in seconds since midnight January 1,...
Definition: HttpServer.h:2102
int setMaxAge(BaTime seconds)
Sets header "Cache-Control: max-age=seconds".
Definition: HttpServer.h:1786
int setDateHeader(const char *name, BaTime time)
Sets a response header with the given name and date-value.
Definition: HttpServer.h:1781
HttpDir * getNext()
Returns the next dir in the parent list.
Definition: HttpServer.h:2632
const char * getRequestURI()
Returns the pathname.
Definition: HttpServer.h:1116
const char * containsHeader(const char *name)
Searches the internal response header database for a header with the specified name.
Definition: HttpServer.h:1725
const char * getContentType()
Returns the content type, for example: "application/x-www-form-urlencoded".
Definition: HttpServer.h:751
const char * getHost()
Returns the host header.
Definition: HttpServer.h:747
int flush()
Forces any content in the buffer to be written to the client.
Definition: HttpServer.h:1735
void(* HttpSessionAttribute_Destructor)(struct HttpSessionAttribute *o)
HttpSessionAttribute termination callback function.
Definition: HttpServer.h:1881
int sendError(int eCode)
Sends an error response as a simple HTML page to the client using the specified status code.
Definition: HttpServer.h:1759
int forward(const char *path)
Forwards a request from a servlet to another resource (servlet, CSP file, or HTML file).
Definition: HttpServer.h:1737
void setHttpOnly(bool flag)
Marks or unmarks this Cookie as HttpOnly.
Definition: HttpServer.h:672
int setContentLength(BaFileSize len)
Sets the "Content-Length" parameter value.
Definition: HttpServer.h:1777
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:670
HttpPage * findPage(HttpPage *iter, const char *name)
Searches for a page in this directory node.
Definition: HttpServer.h:2633
HttpServer * getServer()
Returns the web server object.
Definition: HttpServer.h:1114
int resetHeaders()
Removes all HTTP headers.
Definition: HttpServer.h:1755
struct HttpServer * getServer()
Get the web-server object.
Definition: HttpServer.h:1862
HttpRequest * getRequest()
Get the request object.
Definition: HttpServer.h:1856
int insertPage(HttpPage *page)
Insert a page in the directory.
Definition: HttpServer.h:2624
int setAttribute(HttpSessionAttribute *value)
Binds an object to this session, using the name specified.
Definition: HttpServer.h:2114
HttpMethod getMethodType()
Returns the method type.
Definition: HttpServer.h:1108
int send(const void *data, int len)
Used when sending raw data to the client.
Definition: HttpServer.h:1803
HttpResponse * getResponse()
Get the response object.
Definition: HttpServer.h:1858
int removeResponseBuf()
Remove buffer set by using setResponseBuf.
Definition: HttpServer.h:1753
HttpMethod
HTTP method types.
Definition: HttpServer.h:772
HttpConnection * getConnection()
Returns the connection object associated with this request.
Definition: HttpServer.h:3156
const char * getDomain()
Returns the host header without any port number.
Definition: HttpServer.h:749
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/or the optional AuthorizerIntf.
Definition: HttpServer.h:2647
struct HttpConnection * getConnection()
Get the current connection object that the HttpCommand instance is bound with.
Definition: HttpServer.h:1860
int sendBufAsTxtError(int eCode)
Sends the data formatted into the HttpResponse buffer as an error message to the client.
Definition: HttpServer.h:1765
bool isForward() const
Returns true if this is a forward request from another servlet or CSP file.
Definition: HttpServer.h:1745
AuthenticatedUser * getAuthenticatedUser()
Returns the authenticated user or NULL if user is not authenticated.
Definition: HttpServer.h:1106
int unlink()
Unlinks/removes the page from the parent directory.
Definition: HttpServer.h:2322
HttpServer * getServer()
Get the server object.
Definition: HttpServer.h:2108
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:2838
bool hasMoreElements()
Returns true if more elements.
Definition: HttpServer.h:1143
HttpStdHeaders * getStdHeaders()
Returns an object containing standard HTTP headers.
Definition: HttpServer.h:1120
const char * getHeaderValue(const char *name)
Returns the value of the specified request header.
Definition: HttpServer.h:1124
int setDefaultHeaders()
Sets the most common header values in servlet and CSP files.
Definition: HttpServer.h:1805
int resetBuffer()
Clears the content of the underlying buffer in the response without clearing headers or status code.
Definition: HttpServer.h:1757
int insertCSP(CspInit cspInit, const char *virtualDirRootPath, struct CspReader *reader)
Insert and initialize a CSP Virtual Directory.
Definition: HttpServer.h:3123
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:1729
bool initial() const
Returns true if this is the initial page.
Definition: HttpServer.h:1749
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:3140
void terminate()
Unbinds any objects bound to this session object, runs the HttpSession destructor,...
Definition: HttpServer.h:2110
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:2317
void nextElement()
Advance to the next element.
Definition: HttpServer.h:485
SBaFileSize getContentLength()
Returns the content length if request contains a body.
Definition: HttpServer.h:753
HttpDir_Service overloadService(HttpDir_Service s)
Replace the original service function in HttpDir with your own.
Definition: HttpServer.h:2640
U32 byteCount()
Returns number of bytes sent thus far.
Definition: HttpServer.h:1727
int setCommit(U16 size)
Set the size of the HTTP response commit buffer.
Definition: HttpServer.h:2844
HttpDir()
Constructor for creating a root dir, a root dir has no name.
Definition: HttpServer.h:2612
struct HttpServer HttpServer
The Web Server.
HttpCookie * getCookie(const char *name)
Returns the requested cookie or NULL if no cookie matches the name.
Definition: HttpServer.h:1126
ThreadMutex * getMutex()
Get the dispatcher mutex.
Definition: HttpServer.h:3118
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:2323
void setMaxAge(BaTime expiry)
Sets the maximum age of the cookie in seconds.
Definition: HttpServer.h:664
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:1751
HttpSessionContainer * getSessionContainer()
Get the HttpSessionContainer.
Definition: HttpServer.h:3133
HttpDir * getFirstRootDir()
Returns the first root directory.
Definition: HttpServer.h:3131
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:2100
AuthenticatedUser * getAuthenticatedUser()
Returns the AuthenticatedUser if user is authenticated.
Definition: HttpServer.h:2125
int setContentType(const char *type)
Sets the "Content-Type" parameter value.
Definition: HttpServer.h:1779
void(* HttpPage_Service)(struct HttpPage *page, HttpRequest *request, HttpResponse *response)
The HttpPage service function.
Definition: HttpServer.h:2190
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:2122
int setResponseHeader(U16 min, U16 max)
Set the size of the HTTP response header buffer.
Definition: HttpServer.h:2840
void set404Page(const char *page404)
Set a more user friendly 404 page.
Definition: HttpServer.h:3142
const char * encodeRedirectURLWithParam(const char *pathName)
This method is similar to HttpResponse::encodeRedirectURL, but this method also includes all URL-enco...
Definition: HttpServer.h:1731
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:3138
struct HttpServer * getServer()
Fetch the HttpServer object.
Definition: HttpServer.h:3164
BufPrint * getWriter()
Returns a BufPrint object that can send any type of data to the client.
Definition: HttpServer.h:1799
int write(const void *data, int len, int useBuffering=TRUE)
Used for sending pre-formatted data to the client.
Definition: HttpServer.h:1801
int setMaxSessions(U16 size)
Maximum allowed active HttpSession objects.
Definition: HttpServer.h:2850
HttpInData * getBuffer()
Get the internal rec buffer.
Definition: HttpServer.h:1145
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:1733
int setNoOfHttpCommands(U16 size)
The number of HttpCommand instances created by the web-server.
Definition: HttpServer.h:2846
HttpDir * createOrGet(const char *name)
Returns a sub-directory with the given name.
Definition: HttpServer.h:2638
bool authenticateAndAuthorize(HttpCommand *cmd, const char *path)
Authenticate and authorize the user.
Definition: HttpServer.h:2651
int(* HttpDir_Service)(struct HttpDir *o, const char *relPath, HttpCommand *cmd)
The HttpDir service callback function.
Definition: HttpServer.h:2334
HttpServer(SoDisp *dispatcher, HttpServerConfig *cfg=0)
Create a Web Server object.
Definition: HttpServer.h:3112
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:1788
bool isInclude() const
Returns true if this is an include from another servlet or CSP file.
Definition: HttpServer.h:1747
int unlink()
Unlinks/removes the directory from the parent directory.
Definition: HttpServer.h:2644
char * getRootPath()
Calculates the root of where the HttpDir instance is installed in the virtual file system.
Definition: HttpServer.h:2620
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:1099
const char * getVersion()
Returns the HTTP version as a string, normally "1.1".
Definition: HttpServer.h:1122
int printf(const char *fmt,...)
printf is used for sending formatted data to the client.
Definition: HttpServer.h:1794
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:1775
HttpPage * getFirstPage()
Returns the first page.
Definition: HttpServer.h:2626
SoDisp * getDispatcher()
Returns the dispatcher object.
Definition: HttpServer.h:3129
HttpDir * getDir(const char *name)
Returns the first directory with the name given or NULL if not found.
Definition: HttpServer.h:2628
int wsUpgrade()
Activate a WebSocket handshake.
Definition: HttpServer.h:1130
void setPath(const char *uri)
Set the cookie path.
Definition: HttpServer.h:668
static const char * getStatusCode(int code)
Return a short description for common HTTP error codes.
Definition: HttpServer.h:3148
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:2618
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:3136
U32 getUseCounter()
Get the session usage counter.
Definition: HttpServer.h:2123
bool committed() const
Returns a boolean indicating if the response has been committed.
Definition: HttpServer.h:1743
int redirect(const char *path)
Internally redirects the request to another resource.
Definition: HttpServer.h:1739
void incrRefCntr()
Increments the session reference counter.
Definition: HttpServer.h:2118
const char * getConnection()
Returns the connection type for HTTP 1.1 connections, returns "Close" or "Keep-Alive.
Definition: HttpServer.h:745
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:1128
void decrRefCntr()
Decrements the session reference counter.
Definition: HttpServer.h:2120
const char * getRequestURL(bool forceHttps=false)
Reconstructs the URL the client used to make the request.
Definition: HttpServer.h:1118
HttpCommand * getCommand()
Get the HttpCommand object.
Definition: HttpServer.h:3162
int insertDir(HttpDir *dir)
Insert a sub-directory.
Definition: HttpServer.h:2622
void setMaxInactiveInterval(BaTime interval)
Specifies the time, in seconds, between client requests before the session container will invalidate ...
Definition: HttpServer.h:2116
void setMaxSessions(int max)
Set the maximum number of session objects.
Definition: HttpServer.h:2176
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:2319
const char * get404Page()
Returns a pointer to the current 404 page, if any.
Definition: HttpServer.h:3144
HttpCommand * getCommand()
Get the HttpCommand object.
Definition: HttpServer.h:3160
static HttpDir * findDir(HttpDir *iter, const char *name, unsigned int nameLen)
Searches for a sub-directory in this directory node.
Definition: HttpServer.h:2635
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:1140
HttpServerConfig()
The constructor sets up the default parameters.
Definition: HttpServer.h:2836
const char * getMethod()
Returns a string representation of the value returned by HttpRequest::getMethodType.
Definition: HttpServer.h:1110
void setValue(const char *newValue)
Assigns a new value to a cookie after the cookie is created.
Definition: HttpServer.h:674
BaTime getMaxInactiveInterval()
Returns the maximum time interval, in seconds, that the session container will keep this session open...
Definition: HttpServer.h:2106
HttpCookie * createCookie(const char *name)
Create a cookie.
Definition: HttpServer.h:1723
HttpPage * getPage(const char *name)
Returns the page with the name given or NULL if not found.
Definition: HttpServer.h:2630
int fmtError(int eCode, const char *fmt,...)
This method implements a printf like implementation for formatting and sending an error message.
Definition: HttpServer.h:1767
struct HttpPage HttpPage
An HttpPage, which is typically created by the CSP compiler, is similar to a Java servlet.
HttpDir * getFirstDir()
Returns the first sub-directory.
Definition: HttpServer.h:2627
bool isLinked()
Returns true if this directory node is installed into a parent directory.
Definition: HttpServer.h:2645
HttpResponse * getResponse()
Returns the HttpResponse object.
Definition: HttpServer.h:3154
int insertDir(const char *virtualDirRootPath, HttpDir *dir)
Insert a directory node into the virtual file system.
Definition: HttpServer.h:3121
void setStatus(int statusCode)
Sets the status code for this response.
Definition: HttpServer.h:1791
int insertRootDir(HttpDir *dir)
Insert a root directory node.
Definition: HttpServer.h:3116
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:1783
HttpRequest * getRequest()
Get the HttpRequest object.
Definition: HttpServer.h:3158
void p403(const char *p403)
Set a 403 denied request handler.
Definition: HttpServer.h:2642
HttpSession * getSession()
Get the session object.
Definition: HttpServer.h:1948
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:1104
void activate()
Activates the cookie.
Definition: HttpServer.h:680
int sendRedirect(const char *url)
Sends a temporary redirect (302) response to the client using the specified redirect location URL.
Definition: HttpServer.h:1773
int setResponseData(U16 size)
The HttpResponse object stores formatted data in the response data buffer.
Definition: HttpServer.h:2842
int removeAttribute(const char *name)
Removes the object bound with the specified name from this session.
Definition: HttpServer.h:2112
void setDomain(const char *pattern)
Specifies the domain within which this cookie should be presented.
Definition: HttpServer.h:662
int setNoOfHttpConnections(U16 size)
Number of HttpConnection instances.
Definition: HttpServer.h:2848
void setComment(const char *purpose)
Specifies a comment that describes a cookie's purpose.
Definition: HttpServer.h:660
int sendBufAsError(int eCode)
Sends the data formatted into the HttpResponse buffer as an error message to the client.
Definition: HttpServer.h:1763
HttpSessionAttribute(const char *name, HttpSessionAttribute_Destructor terminate)
Create a session attribute.
Definition: HttpServer.h:1944
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:243
Abstract interface class implemented by DigestAuthenticator, FormAuthenticator and DigestAuthenticato...
Definition: AuthenticatedUser.h:395
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 byHttpLink.
Definition: CspRunTm.h:119
The HttpCommand class is a container class for the HttpRequest and HttpResponse command pair.
Definition: HttpServer.h:1818
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:516
const char * getComment() const
Returns the comment set for this cookie or null if the cookie comment is not set.
Definition: HttpServer.h:522
const char * getPath() const
Returns the path on the server to which the browser returns this cookie.
Definition: HttpServer.h:537
BaTime getMaxAge() const
Returns the maximum age of the cookie, specified in seconds; by default, 0 indicating the cookie will...
Definition: HttpServer.h:530
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:542
const char * getDomain() const
Returns the domain name set for this cookie.
Definition: HttpServer.h:525
const char * getValue() const
Returns the value of the cookie.
Definition: HttpServer.h:550
bool getHttpOnly() const
Return the HttpOnly attribute.
Definition: HttpServer.h:547
const char * getName() const
Returns the name of the cookie.
Definition: HttpServer.h:533
An instance of the HttpDir class, which is a collection of zero or more resources,...
Definition: HttpServer.h:2368
HttpDir * getParent() const
Returns the parent directory or NULL if no parent.
Definition: HttpServer.h:2465
const char * getName() const
Returns the directory name.
Definition: HttpServer.h:2461
The web-server "Request Data" container.
Definition: HttpServer.h:258
const char * getBuf()
Get pointer to start of PUT/POST data.
Definition: HttpServer.h:293
S32 getBufSize()
Get size of internal buffer.
Definition: HttpServer.h:295
An HttpPage, which is typically created by the CSP compiler, is similar to a Java servlet.
Definition: HttpServer.h:2256
const char * getName() const
Returns the page name.
Definition: HttpServer.h:2279
The HttpParameterIterator is used for iterating through the form elements parsed by the HttpServer ob...
Definition: HttpServer.h:432
const char * getValue() const
Returns the form value.
Definition: HttpServer.h:453
const char * getName() const
Return the form name.
Definition: HttpServer.h:451
A persistent container object for HTTP parameters.
Definition: HttpServer.h:357
static U32 calculateSize(struct HttpRequest *req)
Calculate the HttpParameter size.
Definition: HttpServer.h:395
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:399
static HttpParameter * clone(void *buf, struct HttpRequest *req)
Copy HTTP parameters to buf and return as a HttpParameter object.
Definition: HttpServer.h:397
The HttpServer creates an HttpRequest object when the HttpServer parses a client request.
Definition: HttpServer.h:808
This object is used when sending response messages back to the client.
Definition: HttpServer.h:1178
Use an instance of this class if you want to override the default web-server parameters.
Definition: HttpServer.h:2684
The Web Server.
Definition: HttpServer.h:2864
The interface to an HttpSession attribute.
Definition: HttpServer.h:1912
The HttpSession container class.
Definition: HttpServer.h:2144
Provides a way to identify a user across more than one page request or visit to a web site,...
Definition: HttpServer.h:1959
Standard HTTP header values.
Definition: HttpServer.h:689
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
Interface class used by the Authentication classes.
Definition: AuthenticatedUser.h:174