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 5765 2026-04-14 08:27:48Z 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 "5766"
40#define BASLIB_VER_NO 5766
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);
137
139#define httpUnescape(s) httpUnescapeInternal(s,FALSE)
140
142#define httpFormUnescape(s) httpUnescapeInternal(s,TRUE)
143
148BA_API char* httpUnescapeInternal(char* from, BaBool plusAsSpace);
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
561 void setComment(const char* purpose);
562
564 void setDomain(const char* pattern);
565
573 void setMaxAge(BaTime expiry);
582 void deleteCookie();
583
585 void setPath(const char* uri);
586
590 void setSecure(bool flag);
591
601 void setHttpOnly(bool flag);
602
604 void setValue(const char* newValue);
605
606#if 0
608 int getVersion() const { return version; }
609 /* Sets the version of the cookie protocol this cookie complies with. */
610 void setVersion(int v);
611#endif
612
618 void activate();
619 private:
620 HttpCookie();
621#endif
622 struct HttpCookie* next;
623 char* comment;
624 char* domain;
625 char* name;
626 char* path;
627 char* value;
628 BaTime maxAge;
629 int version;
630 BaBool secure;
631 BaBool httpOnly;
632 BaBool deleteCookieFlag;
633 BaBool activateFlag; /* The cookie will be sent to the client
634 * if this flag is true */
636
637#ifdef __cplusplus
638extern "C" {
639#endif
640BA_API void HttpCookie_destructor(HttpCookie* o);
641BA_API const char* HttpCookie_getComment(HttpCookie* o);
642BA_API const char* HttpCookie_getDomain(HttpCookie* o);
643BA_API BaTime HttpCookie_getMaxAge(HttpCookie* o);
644BA_API const char* HttpCookie_getName(HttpCookie* o);
645BA_API const char* HttpCookie_getPath(HttpCookie* o);
646BA_API BaBool HttpCookie_getSecure(HttpCookie* o);
647BA_API BaBool HttpCookie_getHttpOnly(HttpCookie* o);
648BA_API const char* HttpCookie_getValue(HttpCookie* o);
649BA_API void HttpCookie_setComment(HttpCookie* o, const char* purpose);
650BA_API void HttpCookie_setDomain(HttpCookie* o, const char* pattern);
651BA_API void HttpCookie_setMaxAge(HttpCookie* o, BaTime expiry);
652#define HttpCookie_deleteCookie(o) (o)->deleteCookieFlag = TRUE;
653BA_API void HttpCookie_setPath(HttpCookie* o, const char* uri);
654BA_API void HttpCookie_setSecure(HttpCookie* o, BaBool flag);
655BA_API void HttpCookie_setHttpOnly(HttpCookie* o, BaBool flag);
656BA_API void HttpCookie_setValue(HttpCookie* o, const char* newValue);
657
658#if 0
659int HttpCookie_getVersion(HttpCookie* o);
660void HttpCookie_setVersion(HttpCookie* o, int v);
661#endif
662
663BA_API void HttpCookie_activate(HttpCookie* o);
664#ifdef __cplusplus
665}
666inline HttpCookie::HttpCookie() { baAssert(0); }
667inline HttpCookie::~HttpCookie() { HttpCookie_destructor(this); }
668inline void HttpCookie::setComment(const char* purpose) {
669 HttpCookie_setComment(this, purpose); }
670inline void HttpCookie::setDomain(const char* pattern) {
671 HttpCookie_setDomain(this, pattern); }
672inline void HttpCookie::setMaxAge(BaTime expiry) {
673 HttpCookie_setMaxAge(this, expiry); }
675 HttpCookie_deleteCookie(this); }
676inline void HttpCookie::setPath(const char* uri) {
677 HttpCookie_setPath(this, uri); }
678inline void HttpCookie::setSecure(bool flag) {
679 HttpCookie_setSecure(this, flag ? TRUE : FALSE); }
680inline void HttpCookie::setHttpOnly(bool flag) {
681 HttpCookie_setHttpOnly(this, flag ? TRUE : FALSE); }
682inline void HttpCookie::setValue(const char* newValue) {
683 HttpCookie_setValue(this, newValue); }
684#if 0
685inline void HttpCookie::setVersion(int v) {
686 HttpCookie_setVersion(this, v); }
687#endif
688inline void HttpCookie::activate() {
689 HttpCookie_activate(this); }
690#endif
691
692
696typedef struct HttpStdHeaders
697{
698#ifdef __cplusplus
702 const char* getConnection();
703
711 const char* getHost();
712
718 const char* getDomain();
719
723 const char* getContentType();
724
727 SBaFileSize getContentLength();
728#endif
729 HttpInData* inData;
730 char* domain;
731 BaFileSize contentLength;
732 U16 connectionHOffs;
733 U16 hostHOffs;
734 U16 contentTypeHOffs;
736
737#ifdef __cplusplus
738extern "C" {
739#endif
740BA_API const char* HttpStdHeaders_zzGetValFromOffs(
741 HttpStdHeaders* o, U16 offset);
742BA_API const char* HttpStdHeaders_getDomain(HttpStdHeaders* o);
743#define HttpStdHeaders_getConnection(o) \
744 HttpStdHeaders_zzGetValFromOffs(o,(o)->connectionHOffs)
745#define HttpStdHeaders_getHost(o) \
746 HttpStdHeaders_zzGetValFromOffs(o,(o)->hostHOffs)
747#define HttpStdHeaders_getContentType(o) \
748 HttpStdHeaders_zzGetValFromOffs(o,(o)->contentTypeHOffs)
749#define HttpStdHeaders_getContentLength(o) (o)->contentLength
750
751#ifdef __cplusplus
752}
753inline const char* HttpStdHeaders::getConnection() {
754 return HttpStdHeaders_getConnection(this); }
755inline const char* HttpStdHeaders::getHost() {
756 return HttpStdHeaders_getHost(this); }
757inline const char* HttpStdHeaders::getDomain() {
758 return HttpStdHeaders_getDomain(this); }
759inline const char* HttpStdHeaders::getContentType() {
760 return HttpStdHeaders_getContentType(this); }
762 return HttpStdHeaders_getContentLength(this); }
763
764#endif
765
766
767
768 /*Do not change the HttpMethod type without checking tables in Httpserver.c*/
769
780typedef enum {
781 HttpMethod_Connect =0x00001,
782 HttpMethod_Get =0x00002,
783 HttpMethod_Head =0x00004,
784 HttpMethod_Options =0x00008,
785
786 HttpMethod_Patch =0x00010,
787 HttpMethod_Post =0x00020,
788 HttpMethod_Put =0x00040,
789 HttpMethod_Trace =0x00080,
790
791 /* WebDAV */
792 HttpMethod_Copy =0x00100,
793 HttpMethod_Delete =0x00200,
794 HttpMethod_Lock =0x00400,
795 HttpMethod_Move =0x00800,
796
797 HttpMethod_Mkcol =0x01000,
798 HttpMethod_Propfind =0x02000,
799 HttpMethod_Proppatch =0x04000,
800 HttpMethod_Unlock =0x08000,
801
802 HttpMethod_Unknown =0x10000 /* Must be last */
803} HttpMethod;
804
805
806/* Convert a HTTP method from string value to the type HttpMethod */
807BA_API HttpMethod HttpMethod_a2m(const char* str);
808
809
810
815typedef struct HttpRequest
816{
817#ifdef __cplusplus
818
870 int checkMethods(HttpResponse* resp, U32 methods, bool addDefault=TRUE);
871
884 BaBool checkTime(struct HttpResponse* resp, BaTime time);
885
889
892 const char* getRequestURI();
893
906 const char* getRequestURL(bool forceHttps=false);
907
912
914 const char* getVersion();
915
923 const char* getHeaderValue(const char* name);
924
928 HttpCookie* getCookie(const char* name);
929
936
941 const char* getMethod();
942
946 static const char* getMethod(HttpMethod method);
947
958 const char* getParameter(const char* paramName);
959
964 int wsUpgrade();
965
981 HttpHeader* getHeaders(int* len);
982
983
984
1019#ifndef NO_HTTP_SESSION
1020 HttpSession* getSession(BaBool create=true);
1021#endif
1025
1029
1033
1037
1040
1041
1042 int setUserObj(void* userObj, bool overwrite=false);
1043 void* getUserObj();
1044
1045#endif
1046 HttpStdHeaders stdH;
1047 HttpAllocator headerAlloc;
1048 HttpAllocator formAlloc;
1049 HttpInData inData;
1050 struct HttpServer* server;
1051 void* userObj;
1052 struct HttpSession* session;
1053 HttpMethod methodType;
1054 U16 pathI;
1055 U16 versionI;
1056 U16 headersI;
1057 U16 headerLen;
1058 U16 formsI;
1059 U16 formLen;
1060 BaBool postDataConsumed; /* Set by MultipartUpload and HttpRecData */
1062
1063#ifdef __cplusplus
1064extern "C" {
1065#endif
1066BA_API int HttpRequest_checkMethods(HttpRequest* o, struct HttpResponse* resp,
1067 U32 methods, BaBool addDefault);
1068BA_API int HttpRequest_checkOptions(
1069 HttpRequest* o, struct HttpResponse* resp, int optLen, ...);
1070#define HttpRequest_getAuthenticatedUser(o) \
1071 AuthenticatedUser_get2(HttpRequest_getSession(o,FALSE))
1072#define HttpRequest_getConnection(o) HttpRequest_getCommand(o)->con
1073#define HttpRequest_getMethodType(o) (o)->methodType
1074#define HttpRequest_getMethod(o) HttpRequest_getMethod2((o)->methodType)
1075BA_API const char* HttpRequest_getMethod2(HttpMethod method);
1076#define HttpRequest_getServer(o) (o)->server
1077#define HttpRequest_getResponse(o) (&HttpRequest_getCommand(o)->response)
1078BA_API struct HttpCommand* HttpRequest_getCommand(HttpRequest*);
1079BA_API BaBool HttpRequest_checkTime(
1080 HttpRequest* o, struct HttpResponse* resp, BaTime time);
1081BA_API const char* HttpRequest_getRequestURI(HttpRequest* o);
1082BA_API const char* HttpRequest_getRequestURL(HttpRequest* o,BaBool forceHttps);
1083#define HttpRequest_getStdHeaders(o) (&(o)->stdH)
1084BA_API const char* HttpRequest_getVersion(HttpRequest* o);
1085BA_API const char* HttpRequest_getHeaderValue(HttpRequest* o,const char* name);
1086#define HttpRequest_getNoOfParameters(o) (o)->formLen
1087BA_API HttpCookie* HttpRequest_getCookie(HttpRequest* o, const char* name);
1088#define HttpRequest_getUserObj(o) (o)->userObj
1089BA_API int HttpRequest_setUserObj(
1090 HttpRequest* o, void* userObj, BaBool overwrite);
1091#define HttpRequest_getBuffer(o) (&(o)->inData)
1092BA_API const char* HttpRequest_getParameter(
1093 HttpRequest* o, const char* paramName);
1094BA_API HttpHeader* HttpRequest_getHeaders(HttpRequest* o, int* len);
1095BA_API int HttpRequest_wsUpgrade(HttpRequest* o);
1096BA_API BaBool HttpRequest_enableKeepAlive(HttpRequest* o);
1097BA_API int HttpRequest_pushBackData(HttpRequest* o);
1098#ifndef NO_HTTP_SESSION
1099BA_API struct HttpSession* HttpRequest_getSession(
1100 HttpRequest* o, BaBool create);
1101BA_API struct HttpSession* HttpRequest_session(
1102 HttpRequest* o, const char* val, size_t len, int set);
1103#endif
1104#ifdef __cplusplus
1105}
1106
1108 U32 methods, bool addDefault){
1109 return HttpRequest_checkMethods(this,resp,
1110 methods, addDefault ? TRUE : FALSE);}
1111
1112inline BaBool HttpRequest::checkTime(struct HttpResponse* resp, BaTime time) {
1113 return HttpRequest_checkTime(this, resp, time); }
1115 return HttpRequest_getAuthenticatedUser(this); }
1117 return HttpRequest_getMethodType(this); }
1118inline const char* HttpRequest::getMethod() {
1119 return HttpRequest_getMethod(this); }
1120inline const char* HttpRequest::getMethod(HttpMethod method) {
1121 return HttpRequest_getMethod2(method); }
1123 return HttpRequest_getServer(this); }
1124inline const char* HttpRequest::getRequestURI() {
1125 return HttpRequest_getRequestURI(this); }
1126inline const char* HttpRequest::getRequestURL(bool forceHttps) {
1127 return HttpRequest_getRequestURL(this, forceHttps); }
1129 return HttpRequest_getStdHeaders(this); }
1130inline const char* HttpRequest::getVersion() {
1131 return HttpRequest_getVersion(this); }
1132inline const char* HttpRequest::getHeaderValue(const char* name) {
1133 return HttpRequest_getHeaderValue(this, name); }
1134inline HttpCookie* HttpRequest::getCookie(const char* name) {
1135 return HttpRequest_getCookie(this, name); }
1136inline const char* HttpRequest::getParameter(const char* paramName) {
1137 return HttpRequest_getParameter(this, paramName); }
1139 return HttpRequest_wsUpgrade(this);
1140}
1141inline HttpHeader* HttpRequest::getHeaders(int* len) {
1142 return HttpRequest_getHeaders(this, len); }
1143inline int HttpRequest::setUserObj(void* userObj, bool overwrite) {
1144 return HttpRequest_setUserObj(this, userObj, overwrite); }
1145inline void* HttpRequest::getUserObj() {
1146 return HttpRequest_getUserObj(this); }
1147#ifndef NO_HTTP_SESSION
1148inline HttpSession* HttpRequest::getSession(BaBool create) {
1149 return HttpRequest_getSession(this, create); }
1150#endif
1152 return HttpParameterIterator_hasMoreElements(this); }
1154 return HttpRequest_getBuffer(this); }
1155#endif
1156
1157
1158#ifndef __DOXYGEN__
1159
1160typedef struct
1161{
1162 HttpAllocator data;
1163 U16 maxResponseHeader;
1164} NameValMM;
1165
1166
1167typedef struct
1168{
1169 U8 major;
1170 U8 minor;
1171} HttpProtocol;
1172
1173#endif
1174
1185typedef struct HttpResponse
1186{
1187#ifdef __cplusplus
1188
1191 U32 byteCount();
1192
1193
1197 HttpCookie* createCookie(const char* name);
1198
1209 const char* containsHeader(const char* name);
1210
1219 const char* encodeRedirectURL(const char* pathName);
1220
1230 const char* encodeRedirectURLWithParam(const char* pathName);
1231
1238 const char* encodeUrl(const char* path);
1239
1244 int flush();
1245
1271 int forward(const char* path);
1272
1293 int redirect(const char* path);
1294
1295
1299
1303
1304
1320 int include(const char* path);
1321
1326 bool committed() const;
1327
1331 bool isForward() const;
1332
1335 bool isInclude() const;
1336
1340 bool initial() const;
1341
1345 int resetHeaders();
1346
1351 int resetBuffer();
1352
1364 int sendError(int eCode);
1365
1379 int sendError(int eCode, const char* msg);
1380
1386 int sendBufAsError(int eCode);
1387
1393 int sendBufAsTxtError(int eCode);
1394
1395
1402 int fmtError(int eCode, const char* fmt, ...);
1403
1421 int sendRedirect(const char* url);
1422
1434 int redirect2TLS();
1435
1441 int setContentLength(BaFileSize len);
1442
1448 int setContentType(const char* type);
1449
1459 int setDateHeader(const char* name, BaTime time);
1460
1481 int setHeader(const char* name, const char* value, bool replace=true);
1482
1488 int setMaxAge(BaTime seconds);
1489
1490
1523 char* fmtHeader(const char* name, int valueLen, bool replace=true);
1524
1525
1540 void setStatus(int statusCode);
1541
1545 int printf(const char* fmt, ...);
1546
1554
1563 int write(const void* data, int len, int useBuffering=TRUE);
1564
1572 int write(const char* data, int useBuffering=TRUE);
1573
1578 int send(const void* data, int len);
1579
1586 int setDefaultHeaders();
1587
1607 int setResponseBuf(BufPrint* buf, bool useDefBuffer=true);
1608
1612 int removeResponseBuf();
1613
1614
1615 int setUserObj(void* userObj, bool overwrite=false);
1616#endif
1617 NameValMM nameValMM;
1618 BufPrint headerPrint;
1619 BufPrint defaultBodyPrint;
1620 BufPrint* bodyPrint;
1621 struct HttpDir* currentDir;
1622 char* encodedURL;
1623 char* encodedRedirectURL;
1624 HttpCookie* cookieList;
1625 void* userObj;
1626 int statusCode;
1627 U32 msgLen; /* Used if request is of type HEAD, count total msg len */
1628 HttpProtocol protocol;
1629 U16 includeCounter;
1630 U16 forwardCounter;
1631 char headerSent;
1632 char printAndWriteInitialized;
1633 char useChunkTransfer;
1635
1636#ifdef __cplusplus
1637extern "C" {
1638#endif
1639BA_API HttpCookie* HttpResponse_createCookie(
1640 struct HttpResponse* o,const char* name);
1641BA_API const char* HttpResponse_containsHeader(
1642 HttpResponse* o, const char* name);
1643BA_API int HttpResponse_dataAdded(HttpResponse* o, U32 size);
1644#define HttpResponse_byteCount(o) ((o)->msgLen + (o)->bodyPrint->cursor)
1645BA_API const char* HttpResponse_encodeRedirectURL(
1646 HttpResponse* o, const char* pathName);
1647BA_API const char* HttpResponse_encodeRedirectURLWithParamOrSessionURL(
1648 HttpResponse* o,const char* path,BaBool setUrlCookie);
1649#define HttpResponse_encodeRedirectURLWithParam(o, path) \
1650 HttpResponse_encodeRedirectURLWithParamOrSessionURL(o, path, FALSE)
1651#define HttpResponse_encodeSessionURL(o, path) \
1652 HttpResponse_encodeRedirectURLWithParamOrSessionURL(o, path, TRUE)
1653BA_API const char* HttpResponse_encodeUrl(HttpResponse* o, const char* path);
1654BA_API int HttpResponse_flush(HttpResponse* o);
1655#define HttpResponse_forward(o,path) HttpResponse_incOrForward(o,path,FALSE)
1656#define HttpResponse_getConnection(o) HttpResponse_getCommand(o)->con
1657#define HttpResponse_getRequest(o) (&HttpResponse_getCommand(o)->request)
1658BA_API struct HttpCommand* HttpResponse_getCommand(HttpResponse*);
1659#define HttpResponse_getBuf(o) (o)->bodyPrint->buf
1660#define HttpResponse_getBufSize(o) (o)->bodyPrint->bufSize
1661#define HttpResponse_getBufOffs(o) \
1662 ((o)->bodyPrint->buf + (o)->bodyPrint->cursor)
1663#define HttpResponse_getRemBufSize(o) \
1664 ((o)->bodyPrint->bufSize - (o)->bodyPrint->cursor)
1665#define HttpResponse_getUserObj(o) (o)->userObj
1666BA_API int HttpResponse_incOrForward(
1667 HttpResponse* o, const char* path, BaBool isInc);
1668BA_API int HttpResponse_redirect(HttpResponse* o, const char* path);
1669#define HttpResponse_include(o,path) HttpResponse_incOrForward(o,path,TRUE)
1670#define HttpResponse_isChunkTransfer(o) (o)->useChunkTransfer
1671#define HttpResponse_committed(o) (o)->headerSent
1672#define HttpResponse_isForward(o) ((o)->forwardCounter != 0)
1673#define HttpResponse_isInclude(o) ((o)->includeCounter != 0)
1674#define HttpResponse_initial(o) (!HttpResponse_isForward(o) && \
1675 !HttpResponse_isInclude(o))
1676BA_API int HttpResponse_setResponseBuf(
1677 HttpResponse* o,BufPrint* buf,BaBool useDefBuffer);
1678BA_API int HttpResponse_removeResponseBuf(HttpResponse* o);
1679
1680BA_API int HttpResponse_resetHeaders(HttpResponse* o);
1681BA_API int HttpResponse_resetBuffer(HttpResponse* o);
1682BA_API int HttpResponse_sendError1(HttpResponse* o, int eCode);
1683BA_API int HttpResponse_sendError2(HttpResponse* o,int eCode,const char* msg);
1684BA_API int HttpResponse_sendBufAsError(HttpResponse* o,int eCode);
1685BA_API int HttpResponse_sendBufAsTxtError(HttpResponse* o,int eCode);
1686BA_API int HttpResponse_fmtVError(
1687 HttpResponse* response,
1688 int eCode,
1689 const char* fmt,
1690 va_list varg);
1691BA_API int HttpResponse_fmtError(
1692 HttpResponse* response,
1693 int eCode,
1694 const char* fmt, ...);
1695BA_API int HttpResponse_sendRedirect(HttpResponse* o, const char* url);
1696BA_API int HttpResponse_sendRedirectI(
1697 HttpResponse* o, const char* url, int status);
1698BA_API int HttpResponse_redirect2TLS(HttpResponse* o);
1699#define HttpResponse_forceHttps HttpResponse_redirect2TLS /* Backw. comp. */
1700
1701#define HttpResponse_setBufPos(o, pos) (o)->bodyPrint->cursor = pos
1702BA_API int HttpResponse_setContentLength(HttpResponse* o, BaFileSize len);
1703BA_API int HttpResponse_setContentType(HttpResponse* o, const char* type);
1704BA_API int HttpResponse_checkContentType(HttpResponse* o, const char* type);
1705BA_API int HttpResponse_setDateHeader(
1706 HttpResponse* o, const char* name, BaTime t);
1707BA_API int HttpResponse_setHeader(
1708 HttpResponse* o,const char* name,const char* value, BaBool replace);
1709BA_API int HttpResponse_setMaxAge(HttpResponse* response, BaTime seconds);
1710BA_API char* HttpResponse_fmtHeader(
1711 HttpResponse* o, const char* name, int valueLen, BaBool replace);
1712BA_API int HttpResponse_setStatus(HttpResponse* o, int eCode);
1713BA_API int HttpResponse_vprintf(
1714 HttpResponse* o, const char* fmt, va_list argList);
1715BA_API int HttpResponse_printf(HttpResponse* o, const char* fmt, ...);
1716BA_API int HttpResponse_write(HttpResponse* o, const void* data, int len,
1717 int useBuffering);
1718BA_API BufPrint* HttpResponse_getWriter(HttpResponse* o);
1719BA_API int HttpResponse_send(HttpResponse* o, const void* data, int len);
1720BA_API int HttpResponse_setDefaultHeaders(HttpResponse* o);
1721BA_API int HttpResponse_downgrade(HttpResponse* o);
1722BA_API int HttpResponse_setUserObj(
1723 HttpResponse* o,void* userObj,BaBool overwrite);
1724BA_API int HttpResponse_printAndWriteInit(HttpResponse* o);
1725BA_API int HttpResponse_send100Continue(HttpResponse* o);
1726BA_API int HttpResponse_setChunkEncoding(HttpResponse* o);
1727BA_API const char* HttpResponse_getRespData(HttpResponse* o, int* len);
1728#define HttpResponse_getStatus(o) (o)->statusCode
1729#ifdef __cplusplus
1730}
1731inline HttpCookie* HttpResponse::createCookie(const char* name) {
1732 return HttpResponse_createCookie(this, name); }
1733inline const char* HttpResponse::containsHeader(const char* name) {
1734 return HttpResponse_containsHeader(this, name); }
1736 return HttpResponse_byteCount(this); }
1737inline const char* HttpResponse::encodeRedirectURL(const char* pathName) {
1738 return HttpResponse_encodeRedirectURL(this, pathName); }
1739inline const char* HttpResponse::encodeRedirectURLWithParam(const char* p) {
1740 return HttpResponse_encodeRedirectURLWithParam(this, p); }
1741inline const char* HttpResponse::encodeUrl(const char* path) {
1742 return HttpResponse_encodeUrl(this, path); }
1744 return HttpResponse_flush(this); }
1745inline int HttpResponse::forward(const char* path) {
1746 return HttpResponse_forward(this, path); }
1747inline int HttpResponse::redirect(const char* path) {
1748 return HttpResponse_redirect(this, path); }
1749inline int HttpResponse::include(const char* path) {
1750 return HttpResponse_include(this, path); }
1751inline bool HttpResponse::committed() const {
1752 return HttpResponse_committed(this) ? true : false; }
1753inline bool HttpResponse::isForward() const {
1754 return HttpResponse_isForward(this) ? true : false; }
1755inline bool HttpResponse::isInclude() const {
1756 return HttpResponse_isInclude(this) ? true : false; }
1757inline bool HttpResponse::initial() const {
1758 return HttpResponse_initial(this) ? true : false; }
1759inline int HttpResponse::setResponseBuf(BufPrint* buf, bool useDefBuffer) {
1760 return HttpResponse_setResponseBuf(this, buf, useDefBuffer?TRUE:FALSE); }
1762 return HttpResponse_removeResponseBuf(this); }
1764 return HttpResponse_resetHeaders(this); }
1766 return HttpResponse_resetBuffer(this); }
1767inline int HttpResponse::sendError(int eCode) {
1768 return HttpResponse_sendError1(this, eCode); }
1769inline int HttpResponse::sendError(int eCode, const char* msg) {
1770 return HttpResponse_sendError2(this, eCode, msg); }
1771inline int HttpResponse::sendBufAsError(int eCode) {
1772 return HttpResponse_sendBufAsError(this, eCode); }
1773inline int HttpResponse::sendBufAsTxtError(int eCode) {
1774 return HttpResponse_sendBufAsTxtError(this,eCode);}
1775inline int HttpResponse::fmtError(int eCode,const char* fmt,...) {
1776 int retv; va_list varg;
1777 va_start(varg, fmt);
1778 retv = HttpResponse_fmtVError(this, eCode, fmt, varg);
1779 va_end(varg);
1780 return retv; }
1781inline int HttpResponse::sendRedirect(const char* url) {
1782 return HttpResponse_sendRedirect(this, url); }
1784 return HttpResponse_redirect2TLS(this); }
1785inline int HttpResponse::setContentLength(BaFileSize len) {
1786 return HttpResponse_setContentLength(this, len); }
1787inline int HttpResponse::setContentType(const char* type) {
1788 return HttpResponse_setContentType(this, type); }
1789inline int HttpResponse::setDateHeader(const char* name, BaTime t) {
1790 return HttpResponse_setDateHeader(this, name, t); }
1792 const char* name, const char* value, bool replace) {
1793 return HttpResponse_setHeader(this,name, value, replace?TRUE:FALSE); }
1794inline int HttpResponse::setMaxAge(BaTime seconds) {
1795 return HttpResponse_setMaxAge(this, seconds); }
1797 const char* name, int valueLen, bool replace) {
1798 return HttpResponse_fmtHeader(this, name, valueLen, replace?TRUE:FALSE); }
1799inline void HttpResponse::setStatus(int eCode) {
1800 HttpResponse_setStatus(this, eCode);}
1801
1802inline int HttpResponse::printf(const char* fmt, ...) {
1803 int retv; va_list varg; va_start(varg, fmt);
1804 retv = HttpResponse_vprintf(this, fmt, varg); va_end(varg); return retv;}
1805inline int HttpResponse::write(const char* data, int useBuffering) {
1806 return HttpResponse_write(this, data, iStrlen(data), useBuffering); }
1808 return HttpResponse_getWriter(this); }
1809inline int HttpResponse::write(const void* data, int len, int useBuffering){
1810 return HttpResponse_write(this, data, len, useBuffering); }
1811inline int HttpResponse::send(const void* data, int len) {
1812 return HttpResponse_send(this, data, len); }
1814 return HttpResponse_setDefaultHeaders(this); }
1815inline int HttpResponse::setUserObj(void* userObj, bool overwrite) {
1816 return HttpResponse_setUserObj(this, userObj, overwrite); }
1817
1818#endif
1819
1825typedef struct HttpCommand
1826{
1827#ifdef __cplusplus
1828
1832
1836
1840 struct HttpConnection* getConnection();
1841
1843 struct HttpServer* getServer();
1844
1845 HttpCommand() {}
1846#endif
1847 DoubleLink super;
1848#ifdef __cplusplus
1849 public:
1850#endif
1851 HttpRequest request;
1852 HttpResponse response;
1853 struct HttpConnection* con;
1854 struct LHttpCommand* lcmd; /* Used by LSP plugin */
1855 BaTime requestTime;
1856 BaBool runningInThread;
1858
1859#define HttpCommand_getRequest(o) (&(o)->request)
1860#define HttpCommand_getResponse(o) (&(o)->response)
1861#define HttpCommand_getConnection(o) (o)->con
1862#define HttpCommand_getServer(o) HttpConnection_getServer((o)->con)
1863#ifdef __cplusplus
1865 return HttpCommand_getRequest(this); }
1867 return HttpCommand_getResponse(this); }
1869 return HttpCommand_getConnection(this); }
1871 return HttpCommand_getServer(this);
1872}
1873#endif
1874
1875
1876#ifndef NO_HTTP_SESSION
1877
1878#ifndef __DOXYGEN__
1881#endif
1882
1890 struct HttpSessionAttribute* o);
1891
1920{
1921#ifdef __cplusplus
1927 HttpSessionAttribute(const char* name,
1929
1933#endif
1934 struct HttpSessionAttribute* next;
1935 struct HttpSession* session;
1937 char* name;
1939
1940#ifdef __cplusplus
1941extern "C" {
1942#endif
1943
1944BA_API void HttpSessionAttribute_constructor(
1946 const char* name,
1948BA_API void HttpSessionAttribute_destructor(HttpSessionAttribute* o);
1949#define HttpSessionAttribute_getSession(o) (o)->session
1950#ifdef __cplusplus
1951}
1953 const char* name,
1955 HttpSessionAttribute_constructor(this, name, d); }
1957 return HttpSessionAttribute_getSession(this); }
1958
1959#endif
1960
1966typedef struct HttpSession
1967{
1968#ifdef __cplusplus
1969
1970 void *operator new(size_t s) { return ::baMalloc(s); }
1971 void operator delete(void* d) { if(d) ::baFree(d); }
1972 void *operator new(size_t, void *place) { return place; }
1973 void operator delete(void*, void *) { }
1974
1989 void terminate();
1990
1994 HttpSessionAttribute* getAttribute(const char* name);
1995
2000
2006
2011
2014
2017 int removeAttribute(const char* name);
2018
2022
2026 void setMaxInactiveInterval(BaTime interval);
2027
2033 void incrRefCntr();
2034
2040 void decrRefCntr();
2041
2045 U32 getId();
2046
2050
2053 U32 getUseCounter();
2054
2055
2056 void incrementLock();
2057 void decrementLock();
2058
2059 HttpSession() {}
2060 private:
2061#endif
2062 SplayTreeNode super; /* inherits from SplayTreeNode */
2063 DoubleLink dlink;
2064 HttpSockaddr peer;
2065 HttpSessionAttribute* attrList;
2066 struct HttpSessionContainer* container;
2067 BaTime creationTime;
2068 BaTime lastAccessedTime;
2069 BaTime maxInactiveInterval;
2070 U32 sesrnd1; /* Session random number 1 & 2 */
2071 U32 sesrnd2; /* entropy id+sesrnd1+sesrnd2=96 bits */
2072 U32 useCounter;
2073 int refCounter;
2074 U16 lockCounter;
2075 U8 termPending; /* TRUE if in termination list */
2077
2078
2079#ifdef __cplusplus
2080extern "C" {
2081#endif
2082BA_API HttpSessionAttribute* HttpSession_getAttribute(HttpSession* o,
2083 const char* name);
2084BA_API BaTime HttpSession_getCreationTime(HttpSession* o);
2085BA_API BaTime HttpSession_getLastAccessedTime(HttpSession* o);
2086BA_API BaTime HttpSession_getMaxInactiveInterval(HttpSession* o);
2087BA_API struct HttpServer* HttpSession_getServer(HttpSession* o);
2088BA_API void HttpSession_terminate(HttpSession* o);
2089BA_API BaBool HttpSession_isNew(HttpSession* o);
2090BA_API int HttpSession_removeAttribute(HttpSession* o, const char* name);
2091BA_API int HttpSession_setAttribute(HttpSession* o,
2092 HttpSessionAttribute* value);
2093BA_API void HttpSession_setMaxInactiveInterval(HttpSession* o,BaTime interval);
2094#define HttpSession_incrRefCntr(o) (o)->refCounter++
2095BA_API void HttpSession_decrRefCntr(HttpSession* o);
2096#define HttpSession_incrementLock(o) (o)->lockCounter++
2097#define HttpSession_decrementLock(o) do {\
2098 baAssert((o)->lockCounter > 0);\
2099 (o)->lockCounter--; } while(0)
2100BA_API int HttpSession_fmtSessionId(HttpSession* o, U8* buf, size_t bufSize);
2101#define HttpSession_getId(o) \
2102 ((U32)((ptrdiff_t)SplayTreeNode_getKey((SplayTreeNode*)(o))))
2103#define HttpSession_getAuthenticatedUser(o) AuthenticatedUser_get2((o))
2104#define HttpSession_getUseCounter(o) (o)->useCounter
2105#define HttpSession_getPeerName(o) (&(o)->peer)
2106#ifdef __cplusplus
2107}
2109 return HttpSession_getAttribute(this, name); }
2111 return HttpSession_getCreationTime(this); }
2113 return HttpSession_getLastAccessedTime(this); }
2115 return HttpSession_getMaxInactiveInterval(this); }
2117 return HttpSession_getServer(this); }
2119 HttpSession_terminate(this); }
2120inline int HttpSession::removeAttribute(const char* name) {
2121 return HttpSession_removeAttribute(this, name); }
2123 return HttpSession_setAttribute(this, value); }
2125 HttpSession_setMaxInactiveInterval(this, interval); }
2127 HttpSession_incrRefCntr(this); }
2129 HttpSession_decrRefCntr(this); }
2130inline U32 HttpSession::getId() { return HttpSession_getId(this); }
2132 return HttpSession_getUseCounter(this); }
2134 return HttpSession_getAuthenticatedUser(this); }
2135inline void HttpSession::incrementLock() {HttpSession_incrementLock(this);}
2136inline void HttpSession::decrementLock() {HttpSession_decrementLock(this);}
2137
2138#endif /* __cplusplus */
2139
2140typedef enum {
2141 HttpSessionContainer_OK = 0,
2142 HttpSessionContainer_NoMemory,
2143 HttpSessionContainer_TooManySessions,
2144 HttpSessionContainer_NoPeerAddress
2145} HttpSessionContainer_ECode;
2146
2147
2152{
2153#ifdef __cplusplus
2160 void setMaxSessions(int max);
2161 private:
2162#endif
2163 SplayTree sessionTree;
2164 DoubleList sessionList;
2165 DoubleList sessionTermList;
2166 DoubleLink* sessionLinkIter;
2167 struct HttpServer* server;
2168 int noOfSessions; /* Current number of active sessions */
2169 int maxSessions;
2170 HttpSessionContainer_ECode eCode;
2172
2173#ifdef __cplusplus
2174extern "C" {
2175#endif
2176void HttpSessionContainer_constructor(struct HttpSessionContainer* o,
2177 struct HttpServer* server,
2178 U16 maxSessions);
2179void HttpSessionContainer_destructor(struct HttpSessionContainer* o);
2180void HttpSessionContainer_sessionTimer(struct HttpSessionContainer* o);
2181#define HttpSessionContainer_setMaxSessions(o,max) (o)->maxSessions = max
2182#ifdef __cplusplus
2183}
2185 HttpSessionContainer_setMaxSessions(this, max); }
2186#endif
2187
2188#endif /* NO_HTTP_SESSION */
2189
2190
2198typedef void (*HttpPage_Service)(struct HttpPage* page,
2199 HttpRequest* request,
2200 HttpResponse* response);
2201
2202
2203#define HttpPageType_HttpPageSE 0x00020
2204
2205#ifndef __DOXYGEN__
2206typedef struct HttpPageNode
2207{
2208 struct HttpPageNode* next;
2209} HttpPageNode;
2210#endif
2211
2263typedef struct HttpPage
2264{
2265#ifdef __cplusplus
2266 void *operator new(size_t s) { return ::baMalloc(s); }
2267 void operator delete(void* d) { if(d) ::baFree(d); }
2268 void *operator new(size_t, void *place) { return place; }
2269 void operator delete(void*, void *) { }
2270 HttpPage() {}
2279 HttpPage(HttpPage_Service service, const char* name);
2280
2283 ~HttpPage();
2284
2287 const char* getName() const { return name; }
2288
2293 void service(HttpRequest* request, HttpResponse* response);
2294
2298 bool isLinked();
2299
2302 int unlink();
2303#endif
2304 HttpPageNode super; /* As if inherited */
2305 HttpPage_Service serviceCB;
2306 const char* name;
2308
2309#ifdef __cplusplus
2310extern "C" {
2311#endif
2312void
2313BA_API HttpPage_constructor(
2314 HttpPage* o, HttpPage_Service service, const char* name);
2315BA_API void HttpPage_destructor(HttpPage* o);
2316#define HttpPage_getName(o) (o)->name
2317#define HttpPage_isLinked(o) ((HttpPageNode*)(o))->next
2318BA_API int HttpPage_unlink(HttpPage* o);
2319#define HttpPage_service(o, request, response) \
2320 (o)->serviceCB(o, request, response)
2321#ifdef __cplusplus
2322}
2323inline HttpPage::HttpPage(HttpPage_Service service, const char* name) {
2324 HttpPage_constructor(this, service, name); }
2326 HttpPage_destructor(this); }
2327inline bool HttpPage::isLinked() {
2328 return HttpPage_isLinked(this) ? true : false;
2329}
2330inline int HttpPage::unlink() {return HttpPage_unlink(this); }
2331inline void HttpPage::service(HttpRequest* request, HttpResponse* response) {
2332 HttpPage_service(this, request, response);
2333}
2334#endif
2335
2336
2342typedef int (*HttpDir_Service)(struct HttpDir* o,
2343 const char* relPath,
2344 HttpCommand* cmd);
2345
2346#define HttpDirType_EhDir 0x00001
2347#define HttpDirType_HttpResRdr 0x00002
2348#define HttpDirType_AuthenticateDir 0x00008
2349#define HttpDirType_AuthenticateDirWrapper 0x00010
2350
2351
2371typedef struct HttpDir
2372{
2373#ifdef __cplusplus
2374 void *operator new(size_t s) { return ::baMalloc(s); }
2375 void operator delete(void* d) { if(d) ::baFree(d); }
2376 void *operator new(size_t, void *place) { return place; }
2377 void operator delete(void*, void *) { }
2379 HttpDir();
2380
2397 HttpDir(const char* name, S8 priority=0);
2398 ~HttpDir();
2399
2403 int insertDir(HttpDir* dir);
2404
2408 int insertPage(HttpPage* page);
2409
2413
2417
2420 HttpDir* getDir(const char* name);
2421
2424 HttpPage* getPage(const char* name);
2425
2428 HttpDir* getNext();
2429
2439 HttpPage* findPage(HttpPage* iter, const char* name);
2440
2452 static HttpDir* findDir(HttpDir* iter, const char* name,
2453 unsigned int nameLen);
2454
2461 HttpDir* createOrGet(const char* name);
2462
2465 const char* getName() const { return name; }
2466
2469 HttpDir* getParent() const { return parent; }
2470
2493 char* makeAbsPath(const char* relPath, int relPathLen);
2494
2506 char* getRootPath();
2507
2508
2513
2523 void p403(const char* p403);
2524
2528 bool isLinked();
2529
2532 int unlink();
2533
2538 void setAuthenticator(
2539 struct AuthenticatorIntf* authenticator,
2540 struct AuthorizerIntf* authorizer=0);
2541
2562 bool authenticateAndAuthorize(HttpCommand* cmd,const char* path);
2563
2564
2565#endif
2566 HttpDir_Service service;
2567 struct HttpDir* parent; /* owner */
2568 struct HttpDir* next; /* next sibling */
2569 const char* name; /* e.g. /mydir/ */
2570 struct HttpDir* dirList; /* list of httpdirs (children) */
2571 struct AuthorizerIntf* realm; /* If we have authorization */
2572 struct AuthenticatorIntf* authenticator; /* If we have authentic. */
2573 char* _p403; /* If we have a 403 denied response page. */
2574 HttpPageNode pageList; /* pages for this dir */
2575 /* U8 type; */
2576 S8 priority;
2578
2579#ifdef __cplusplus
2580extern "C" {
2581#endif
2582BA_API void HttpDir_constructor(HttpDir* o, const char* name, S8 priority);
2583BA_API void HttpDir_destructor(HttpDir* o);
2584BA_API char* HttpDir_makeAbsPath(
2585 HttpDir* o, const char* relPath, int relPathLen);
2586#define HttpDir_getRootPath(o) HttpDir_makeAbsPath(o,"",0)
2587BA_API int HttpDir_insertDir(HttpDir* o, HttpDir* dir);
2588#define HttpDir_getFirstPage(o) \
2589 (o)->pageList.next != &(o)->pageList ? ((HttpPage*)(o)->pageList.next) : 0
2590#define HttpDir_getFirstDir(o) (o)->dirList
2591BA_API HttpDir* HttpDir_getDir(HttpDir* o, const char* name);
2592BA_API HttpPage* HttpDir_getPage(HttpDir* o, const char* name);
2593#define HttpDir_getNext(o) (o)->next
2594#define HttpDir_getName(o) (o)->name
2595#define HttpDir_getParent(o) (o)->parent
2596BA_API int HttpDir_insertPage(HttpDir* o, HttpPage* page);
2597BA_API HttpPage* HttpDir_findPage(
2598 HttpDir* o, HttpPage* iter, const char* name);
2599BA_API HttpDir* HttpDir_findDir(
2600 HttpDir* iter, const char* name,unsigned int nameLen);
2601BA_API HttpDir* HttpDir_createOrGet(HttpDir* o, const char* name);
2602BA_API void HttpDir_p403(HttpDir* o, const char* p403);
2603#define HttpDir_overloadService HttpDir_setService
2604BA_API HttpDir_Service HttpDir_setService(HttpDir*o, HttpDir_Service s);
2605#define HttpDir_isLinked(o) (o)->parent
2606BA_API int HttpDir_unlink(HttpDir* o);
2607#define HttpDir_setAuthenticator(o,authenticatorMA,authorizerMA) \
2608 (o)->authenticator = authenticatorMA,(o)->realm = authorizerMA
2609BA_API int HttpDir_authenticateAndAuthorize(
2610 HttpDir* o,HttpCommand* cmd,const char* path);
2611#define HttpDir_isAuthorized(o,user,method,path) \
2612 ((o)->realm ? \
2613 (user ? AuthorizerIntf_authorize((o)->realm,user,method,path) : FALSE) : \
2614 TRUE)
2615#ifdef __cplusplus
2616}
2618 HttpDir_constructor(this, 0, 0); }
2619inline HttpDir::HttpDir(const char* name, S8 priority) {
2620 HttpDir_constructor(this, name, priority); }
2621inline HttpDir::~HttpDir() {
2622 HttpDir_destructor(this); }
2623inline char* HttpDir::makeAbsPath(const char* relPath, int relPathLen) {
2624 return HttpDir_makeAbsPath(this, relPath, relPathLen); }
2625inline char* HttpDir::getRootPath() {
2626 return HttpDir_getRootPath(this); }
2627inline int HttpDir::insertDir(HttpDir* dir) {
2628 return HttpDir_insertDir(this, dir); }
2630 return HttpDir_insertPage(this, page); }
2631inline HttpPage* HttpDir::getFirstPage() { return HttpDir_getFirstPage(this); }
2632inline HttpDir* HttpDir::getFirstDir() { return HttpDir_getFirstDir(this); }
2633inline HttpDir* HttpDir::getDir(const char* name) {
2634 return HttpDir_getDir(this,name); }
2635inline HttpPage* HttpDir::getPage(const char* name) {
2636 return HttpDir_getPage(this,name); }
2637inline HttpDir* HttpDir::getNext() { return HttpDir_getNext(this); }
2638inline HttpPage* HttpDir::findPage(HttpPage* iter, const char* name) {
2639 return HttpDir_findPage(this, iter, name); }
2640inline HttpDir* HttpDir::findDir(HttpDir* iter, const char* name,
2641 unsigned int nameLen) {
2642 return HttpDir_findDir(iter, name, nameLen); }
2643inline HttpDir* HttpDir::createOrGet(const char* name) {
2644 return HttpDir_createOrGet(this, name); }
2646 return HttpDir_setService(this, s); }
2647inline void HttpDir::p403(const char* p403) {
2648 HttpDir_p403(this, p403); }
2649inline int HttpDir::unlink() {return HttpDir_unlink(this); }
2650inline bool HttpDir::isLinked() {
2651 return HttpDir_isLinked(this) ? true : false; }
2652inline void HttpDir::setAuthenticator(struct AuthenticatorIntf* authenticator,
2653 struct AuthorizerIntf* authorizer){
2654 HttpDir_setAuthenticator(this,authenticator,authorizer);
2655}
2657 HttpCommand* cmd, const char* path) {
2658 return HttpDir_authenticateAndAuthorize(this,cmd,path) ? true : false; }
2659#endif
2660
2661#ifndef __DOXYGEN__
2662
2663typedef struct HttpLinkCon
2664{
2665 HttpConnection con; /* Inherits from HttpConnection */
2666 DoubleLink link;
2667} HttpLinkCon;
2668
2669
2670typedef struct
2671{
2672 HttpDir super; /* inherit */
2673 HttpDir_Service superServiceFunc;
2674 char* page404;
2675 BaBool page404InProgress;
2676} HttpRootDir;
2677
2678#endif
2679
2688typedef struct HttpServerConfig
2689{
2690#ifdef __cplusplus
2697
2727 int setRequest(S16 min, S16 max);
2728
2740 int setResponseHeader(U16 min, U16 max);
2741
2754 int setResponseData(U16 size);
2755
2769 int setCommit(U16 size);
2770
2783 int setNoOfHttpCommands(U16 size);
2784
2806 int setNoOfHttpConnections(U16 size);
2807
2813 int setMaxSessions(U16 size);
2814#endif
2815 S16 minRequest;
2816 S16 maxRequest;
2817 U16 minResponseHeader;
2818 U16 maxResponseHeader;
2819 U16 commit;
2820 U16 responseData;
2821 U16 noOfHttpCommands;
2822 U16 noOfHttpConnections;
2823 U16 maxSessions;
2825
2826#ifdef __cplusplus
2827extern "C" {
2828#endif
2829BA_API void HttpServerConfig_constructor(HttpServerConfig* o);
2830BA_API int HttpServerConfig_setRequest(HttpServerConfig* o, S16 min, S16 max);
2831BA_API int HttpServerConfig_setResponseHeader(
2832 HttpServerConfig* o, U16 min, U16 max);
2833BA_API int HttpServerConfig_setResponseData(HttpServerConfig* o, U16 size);
2834BA_API int HttpServerConfig_setCommit(HttpServerConfig* o, U16 size);
2835BA_API int HttpServerConfig_setNoOfHttpCommands(HttpServerConfig* o, U16 size);
2836BA_API int HttpServerConfig_setNoOfHttpConnections(
2837 HttpServerConfig* o, U16 size);
2838BA_API int HttpServerConfig_setMaxSessions(HttpServerConfig* o, U16 size);
2839#ifdef __cplusplus
2840}
2842 HttpServerConfig_constructor(this); }
2843inline int HttpServerConfig::setRequest(S16 min, S16 max) {
2844 return HttpServerConfig_setRequest(this, min, max); }
2845inline int HttpServerConfig::setResponseHeader(U16 min, U16 max) {
2846 return HttpServerConfig_setResponseHeader(this, min, max); }
2848 return HttpServerConfig_setResponseData(this, size); }
2849inline int HttpServerConfig::setCommit(U16 size) {
2850 return HttpServerConfig_setCommit(this, size); }
2852 return HttpServerConfig_setNoOfHttpCommands(this, size); }
2854 return HttpServerConfig_setNoOfHttpConnections(this, size); }
2856 return HttpServerConfig_setMaxSessions(this, size); }
2857
2858#endif
2859
2860
2861typedef DoubleList HttpLinkConList;
2862
2863/* Used by LSP plugin */
2864typedef void (*LspOnTerminateRequest)(struct LHttpCommand* lcmd);
2865
2868typedef struct HttpServer
2869{
2870#ifdef __cplusplus
2871 void *operator new(size_t s) { return ::baMalloc(s); }
2872 void operator delete(void* d) { if(d) ::baFree(d); }
2873 void *operator new(size_t, void *place) { return place; }
2874 void operator delete(void*, void *) { }
2881 HttpServer(SoDisp* dispatcher, HttpServerConfig* cfg=0);
2882
2883 ~HttpServer();
2884
2896 int insertRootDir(HttpDir* dir);
2897
2919 int insertDir(const char* virtualDirRootPath, HttpDir* dir);
2920
2960 int insertCSP(CspInit cspInit,
2961 const char* virtualDirRootPath,
2962 struct CspReader* reader);
2963
2964 struct AuthUserList* getAuthUserList(const char* name);
2965
2968
2971
2977
2981
2982#ifndef NO_HTTP_SESSION
2992 HttpSession* getSession(U32 id);
2993#endif
2994
3003 void set404Page(const char* page404);
3004
3006 const char* get404Page();
3007
3008 int setUserObj(void* userObj, bool overwrite=false);
3009
3015 static void initStatic(void);
3016
3027 static void setErrHnd(UserDefinedErrHandler e);
3028
3029 /* No longer used */
3030 static int setZlib(ZlibInflateInit2 init,
3031 ZlibInflate inflate,
3032 ZlibInflateEnd end){
3033 (void)init; (void)inflate; (void)end;
3034 return 0; }
3037 static const char* getStatusCode(int code);
3038
3039
3040#endif
3041 DoubleList commandPool;
3042 DoubleList cmdReqList;
3043 HttpConnection noOpCon;
3044 HttpLinkConList freeList;
3045 HttpLinkConList readyList;
3046 HttpLinkConList connectedList;
3047 HttpRootDir rootDirContainer;
3048 SplayTree authUserTree; /* Used by AuthenticatedUser.c */
3049 struct HttpCmdThreadPoolIntf* threadPoolIntf;
3050 HttpLinkCon* connections;
3051 SoDisp* dispatcher;
3052 void* userObj;
3053 void* waitForConClose; /* See HttpServer_doLingeringClose */
3054 LspOnTerminateRequest lspOnTerminateRequest;
3055 int commandPoolSize;
3056 U16 noOfConnections;
3057 S16 maxHttpRequestLen;
3058#ifndef NO_HTTP_SESSION
3059 HttpSessionContainer sessionContainer;
3060#endif
3062
3063
3064/* Used exclusively by HttpCmdThreadPool */
3065void HttpServer_AsynchProcessDir(HttpServer* o,
3066 HttpDir* dir,
3067 HttpCommand* cmd);
3068/* Used exclusively by HttpCmdThreadPool */
3069#define HttpServer_setThreadPoolIntf(o, intf) (o)->threadPoolIntf=intf
3070#define HttpServer_luaenv(o) (o)->luaenv
3071
3072#ifdef __cplusplus
3073extern "C" {
3074#endif
3075BA_API void HttpServer_constructor(HttpServer*,SoDisp*, HttpServerConfig*);
3076BA_API void HttpServer_destructor(HttpServer* o);
3077BA_API int HttpServer_insertRootDir(HttpServer* o, HttpDir* dir);
3078BA_API int HttpServer_insertDir(HttpServer* o,
3079 const char* virtualDirRootPath,
3080 HttpDir* dir);
3081BA_API int HttpServer_insertCSP(HttpServer* o,
3082 CspInit cspInit,
3083 const char* virtualDirRootPath,
3084 struct CspReader* reader);
3085#define HttpServer_getAuthUserList(o, name) \
3086 (AuthUserList*)SplayTree_find(&(o)->authUserTree, name)
3087#define HttpServer_getDispatcher(o) (o)->dispatcher
3088#define HttpServer_getFirstRootDir(o) \
3089 HttpDir_getFirstDir((HttpDir*)&(o)->rootDirContainer)
3090#define HttpServer_getUserObj(o) (o)->userObj
3091#define HttpServer_getSessionContainer(o) (&(o)->sessionContainer)
3092#define HttpServer_getMutex(o) SoDisp_getMutex((o)->dispatcher)
3093BA_API const char* HttpServer_getStatusCode(int code);
3094void HttpServer_addCon2ConnectedList(HttpServer* o, HttpConnection* con);
3095void HttpServer_doLingeringClose(
3096 HttpServer* o, HttpConnection* con, BaFileSize contLen);
3097
3098#ifndef NO_HTTP_SESSION
3099BA_API HttpSession* HttpServer_getSession(HttpServer* o, U32 id);
3100#endif
3101BA_API HttpConnection* HttpServer_getFreeCon(HttpServer* o);
3102void HttpServer_returnFreeCon(HttpServer* o, HttpConnection* con);
3103BA_API void HttpServer_installNewCon(HttpServer* o, HttpConnection* con);
3104BA_API void HttpServer_setErrHnd(UserDefinedErrHandler e);
3105void HttpServer_initStatic(void);
3106int HttpServer_termOldestIdleCon(HttpServer* o);
3107BA_API void HttpServer_set404Page(HttpServer*o, const char* page404);
3108#define HttpServer_get404Page(o) (o)->rootDirContainer.page404
3109BA_API int HttpServer_setUserObj(
3110 HttpServer* o, void* userObj, BaBool overwrite);
3111#define HttpServer_termAllSessions(o) \
3112 HttpSessionContainer_destructor(&(o)->sessionContainer)
3113/* No longer used */
3114#define HttpServer_setZlib(init,inflate,end);
3115#ifdef __cplusplus
3116}
3118 HttpServer_constructor(this, disp, cfg); }
3119inline HttpServer::~HttpServer() {
3120 HttpServer_destructor(this); }
3122 return HttpServer_insertRootDir(this, dir); }
3124 return HttpServer_getMutex(this);
3125}
3126inline int HttpServer::insertDir(const char* virtualDirRootPath,HttpDir* dir){
3127 return HttpServer_insertDir(this, virtualDirRootPath, dir); }
3129 const char* virtualDirRootPath,
3130 struct CspReader* reader) {
3131 return HttpServer_insertCSP(this, cspInit, virtualDirRootPath, reader); }
3132inline struct AuthUserList* HttpServer::getAuthUserList(const char* name) {
3133 return HttpServer_getAuthUserList(this,name); }
3135 return HttpServer_getDispatcher(this); }
3137 return HttpServer_getFirstRootDir(this); }
3139 return HttpServer_getSessionContainer(this); }
3140#ifndef NO_HTTP_SESSION
3142 return HttpServer_getSession(this, id); }
3143inline void HttpServer::initStatic(void) {
3144 HttpServer_initStatic(); }
3145inline void HttpServer::setErrHnd(UserDefinedErrHandler e) {
3146 HttpServer_setErrHnd(e); }
3147inline void HttpServer::set404Page(const char* page404) {
3148 HttpServer_set404Page(this, page404); }
3149inline const char* HttpServer::get404Page() {
3150 return HttpServer_get404Page(this); }
3151inline int HttpServer::setUserObj(void* userObj, bool overwrite) {
3152 return HttpServer_setUserObj(this, userObj, overwrite); }
3153inline const char* HttpServer::getStatusCode(int code) {
3154 return HttpServer_getStatusCode(code);
3155}
3156#endif
3157
3158
3160 return HttpRequest_getResponse(this); }
3162 return HttpRequest_getConnection(this); }
3164 return HttpResponse_getRequest(this); }
3166 return HttpResponse_getCommand(this); }
3168 return HttpRequest_getCommand(this); }
3170 return HttpConnection_getServer(this); }
3171
3172#endif /* __cplusplus */
3173 /* end of StdWebServer */
3175
3176/* Internal use */
3177#ifdef NO_SHARKSSL
3178
3179#define SHARKSSL_MD5_HASH_LEN 16
3180#define SHARKSSL_SHA1_HASH_LEN 20
3181
3182typedef struct SharkSslMd5Ctx
3183{
3184 U32 total[2];
3185 U32 state[4];
3186 U8 buffer[64];
3187} SharkSslMd5Ctx;
3188
3189SHARKSSL_API void SharkSslMd5Ctx_constructor(SharkSslMd5Ctx* ctx);
3190SHARKSSL_API void SharkSslMd5Ctx_append(SharkSslMd5Ctx* ctx, const U8* data, U32 len);
3191SHARKSSL_API void SharkSslMd5Ctx_finish(SharkSslMd5Ctx* ctx, U8 digest[]);
3192SHARKSSL_API int sharkssl_md5(const U8*, U16, U8*);
3193
3194typedef struct SharkSslSha1Ctx
3195{
3196 U32 total[2];
3197 U32 state[5];
3198 U8 buffer[64];
3199} SharkSslSha1Ctx;
3200
3201SHARKSSL_API void SharkSslSha1Ctx_constructor(SharkSslSha1Ctx* ctx);
3202SHARKSSL_API void SharkSslSha1Ctx_append(SharkSslSha1Ctx* ctx, const U8* data, U32 len);
3203SHARKSSL_API void SharkSslSha1Ctx_finish(SharkSslSha1Ctx*, U8 digest[]);
3204
3205typedef void SharkSsl;
3206
3207#endif
3208
3209#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:2112
void deleteCookie()
Specifies a path for the cookie to which the client should return the cookie.
Definition: HttpServer.h:674
HttpHeader * getHeaders(int *len)
Return a HTTP header iterator that can iterate and fetch all the HTTP headers.
Definition: HttpServer.h:1141
int include(const char *path)
Includes the content of a resource (servlet, CSP page, HTML file) in the response.
Definition: HttpServer.h:1749
BaTime getCreationTime()
Returns the time when this session was created, measured in seconds since midnight January 1,...
Definition: HttpServer.h:2110
int setMaxAge(BaTime seconds)
Sets header "Cache-Control: max-age=seconds".
Definition: HttpServer.h:1794
int setDateHeader(const char *name, BaTime time)
Sets a response header with the given name and date-value.
Definition: HttpServer.h:1789
HttpDir * getNext()
Returns the next dir in the parent list.
Definition: HttpServer.h:2637
const char * getRequestURI()
Returns the pathname.
Definition: HttpServer.h:1124
const char * containsHeader(const char *name)
Searches the internal response header database for a header with the specified name.
Definition: HttpServer.h:1733
const char * getContentType()
Returns the content type, for example: "application/x-www-form-urlencoded".
Definition: HttpServer.h:759
const char * getHost()
Returns the host header.
Definition: HttpServer.h:755
int flush()
Forces any content in the buffer to be written to the client.
Definition: HttpServer.h:1743
void(* HttpSessionAttribute_Destructor)(struct HttpSessionAttribute *o)
HttpSessionAttribute termination callback function.
Definition: HttpServer.h:1889
int sendError(int eCode)
Sends an error response as a simple HTML page to the client using the specified status code.
Definition: HttpServer.h:1767
int forward(const char *path)
Forwards a request from a servlet to another resource (servlet, CSP file, or HTML file).
Definition: HttpServer.h:1745
void setHttpOnly(bool flag)
Marks or unmarks this Cookie as HttpOnly.
Definition: HttpServer.h:680
int setContentLength(BaFileSize len)
Sets the "Content-Length" parameter value.
Definition: HttpServer.h:1785
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:678
HttpPage * findPage(HttpPage *iter, const char *name)
Searches for a page in this directory node.
Definition: HttpServer.h:2638
HttpServer * getServer()
Returns the web server object.
Definition: HttpServer.h:1122
int resetHeaders()
Removes all HTTP headers.
Definition: HttpServer.h:1763
struct HttpServer * getServer()
Get the web-server object.
Definition: HttpServer.h:1870
HttpRequest * getRequest()
Get the request object.
Definition: HttpServer.h:1864
int insertPage(HttpPage *page)
Insert a page in the directory.
Definition: HttpServer.h:2629
int setAttribute(HttpSessionAttribute *value)
Binds an object to this session, using the name specified.
Definition: HttpServer.h:2122
HttpMethod getMethodType()
Returns the method type.
Definition: HttpServer.h:1116
int send(const void *data, int len)
Used when sending raw data to the client.
Definition: HttpServer.h:1811
HttpResponse * getResponse()
Get the response object.
Definition: HttpServer.h:1866
int removeResponseBuf()
Remove buffer set by using setResponseBuf.
Definition: HttpServer.h:1761
HttpMethod
HTTP method types.
Definition: HttpServer.h:780
HttpConnection * getConnection()
Returns the connection object associated with this request.
Definition: HttpServer.h:3161
const char * getDomain()
Returns the host header without any port number.
Definition: HttpServer.h:757
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:2652
struct HttpConnection * getConnection()
Get the current connection object that the HttpCommand instance is bound with.
Definition: HttpServer.h:1868
int sendBufAsTxtError(int eCode)
Sends the data formatted into the HttpResponse buffer as an error message to the client.
Definition: HttpServer.h:1773
bool isForward() const
Returns true if this is a forward request from another servlet or CSP file.
Definition: HttpServer.h:1753
AuthenticatedUser * getAuthenticatedUser()
Returns the authenticated user or NULL if user is not authenticated.
Definition: HttpServer.h:1114
int unlink()
Unlinks/removes the page from the parent directory.
Definition: HttpServer.h:2330
HttpServer * getServer()
Get the server object.
Definition: HttpServer.h:2116
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:2843
bool hasMoreElements()
Returns true if more elements.
Definition: HttpServer.h:1151
HttpStdHeaders * getStdHeaders()
Returns an object containing standard HTTP headers.
Definition: HttpServer.h:1128
const char * getHeaderValue(const char *name)
Returns the value of the specified request header.
Definition: HttpServer.h:1132
int setDefaultHeaders()
Sets the most common header values in servlet and CSP files.
Definition: HttpServer.h:1813
int resetBuffer()
Clears the content of the underlying buffer in the response without clearing headers or status code.
Definition: HttpServer.h:1765
int insertCSP(CspInit cspInit, const char *virtualDirRootPath, struct CspReader *reader)
Insert and initialize a CSP Virtual Directory.
Definition: HttpServer.h:3128
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:1737
bool initial() const
Returns true if this is the initial page.
Definition: HttpServer.h:1757
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:3145
void terminate()
Unbinds any objects bound to this session object, runs the HttpSession destructor,...
Definition: HttpServer.h:2118
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:2325
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:761
U32 byteCount()
Returns number of bytes sent thus far.
Definition: HttpServer.h:1735
int setCommit(U16 size)
Set the size of the HTTP response commit buffer.
Definition: HttpServer.h:2849
HttpDir()
Constructor for creating a root dir, a root dir has no name.
Definition: HttpServer.h:2617
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:1134
ThreadMutex * getMutex()
Get the dispatcher mutex.
Definition: HttpServer.h:3123
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:2331
void setMaxAge(BaTime expiry)
Sets the maximum age of the cookie in seconds.
Definition: HttpServer.h:672
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:1759
HttpSessionContainer * getSessionContainer()
Get the HttpSessionContainer.
Definition: HttpServer.h:3138
HttpDir * getFirstRootDir()
Returns the first root directory.
Definition: HttpServer.h:3136
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:2108
AuthenticatedUser * getAuthenticatedUser()
Returns the AuthenticatedUser if user is authenticated.
Definition: HttpServer.h:2133
int setContentType(const char *type)
Sets the "Content-Type" parameter value.
Definition: HttpServer.h:1787
void(* HttpPage_Service)(struct HttpPage *page, HttpRequest *request, HttpResponse *response)
The HttpPage service function.
Definition: HttpServer.h:2198
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:2130
int setResponseHeader(U16 min, U16 max)
Set the size of the HTTP response header buffer.
Definition: HttpServer.h:2845
void set404Page(const char *page404)
Set a more user friendly 404 page.
Definition: HttpServer.h:3147
const char * encodeRedirectURLWithParam(const char *pathName)
This method is similar to HttpResponse::encodeRedirectURL, but this method also includes all URL-enco...
Definition: HttpServer.h:1739
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:3143
struct HttpServer * getServer()
Fetch the HttpServer object.
Definition: HttpServer.h:3169
BufPrint * getWriter()
Returns a BufPrint object that can send any type of data to the client.
Definition: HttpServer.h:1807
int write(const void *data, int len, int useBuffering=TRUE)
Used for sending pre-formatted data to the client.
Definition: HttpServer.h:1809
int setMaxSessions(U16 size)
Maximum allowed active HttpSession objects.
Definition: HttpServer.h:2855
HttpInData * getBuffer()
Get the internal rec buffer.
Definition: HttpServer.h:1153
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:1741
int setNoOfHttpCommands(U16 size)
The number of HttpCommand instances created by the web-server.
Definition: HttpServer.h:2851
HttpDir * createOrGet(const char *name)
Returns a sub-directory with the given name.
Definition: HttpServer.h:2643
bool authenticateAndAuthorize(HttpCommand *cmd, const char *path)
Authenticate and authorize the user.
Definition: HttpServer.h:2656
int(* HttpDir_Service)(struct HttpDir *o, const char *relPath, HttpCommand *cmd)
The HttpDir service callback function.
Definition: HttpServer.h:2342
HttpServer(SoDisp *dispatcher, HttpServerConfig *cfg=0)
Create a Web Server object.
Definition: HttpServer.h:3117
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:1796
bool isInclude() const
Returns true if this is an include from another servlet or CSP file.
Definition: HttpServer.h:1755
int unlink()
Unlinks/removes the directory from the parent directory.
Definition: HttpServer.h:2649
char * getRootPath()
Calculates the root of where the HttpDir instance is installed in the virtual file system.
Definition: HttpServer.h:2625
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:1107
const char * getVersion()
Returns the HTTP version as a string, normally "1.1".
Definition: HttpServer.h:1130
int printf(const char *fmt,...)
printf is used for sending formatted data to the client.
Definition: HttpServer.h:1802
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:1783
HttpPage * getFirstPage()
Returns the first page.
Definition: HttpServer.h:2631
SoDisp * getDispatcher()
Returns the dispatcher object.
Definition: HttpServer.h:3134
HttpDir * getDir(const char *name)
Returns the first directory with the name given or NULL if not found.
Definition: HttpServer.h:2633
int wsUpgrade()
Activate a WebSocket handshake.
Definition: HttpServer.h:1138
void setPath(const char *uri)
Set the cookie path.
Definition: HttpServer.h:676
static const char * getStatusCode(int code)
Return a short description for common HTTP error codes.
Definition: HttpServer.h:3153
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:2623
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:3141
U32 getUseCounter()
Get the session usage counter.
Definition: HttpServer.h:2131
bool committed() const
Returns a boolean indicating if the response has been committed.
Definition: HttpServer.h:1751
int redirect(const char *path)
Internally redirects the request to another resource.
Definition: HttpServer.h:1747
void incrRefCntr()
Increments the session reference counter.
Definition: HttpServer.h:2126
const char * getConnection()
Returns the connection type for HTTP 1.1 connections, returns "Close" or "Keep-Alive.
Definition: HttpServer.h:753
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:1136
void decrRefCntr()
Decrements the session reference counter.
Definition: HttpServer.h:2128
const char * getRequestURL(bool forceHttps=false)
Reconstructs the URL the client used to make the request.
Definition: HttpServer.h:1126
HttpCommand * getCommand()
Get the HttpCommand object.
Definition: HttpServer.h:3167
int insertDir(HttpDir *dir)
Insert a sub-directory.
Definition: HttpServer.h:2627
void setMaxInactiveInterval(BaTime interval)
Specifies the time, in seconds, between client requests before the session container will invalidate ...
Definition: HttpServer.h:2124
void setMaxSessions(int max)
Set the maximum number of session objects.
Definition: HttpServer.h:2184
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:2327
const char * get404Page()
Returns a pointer to the current 404 page, if any.
Definition: HttpServer.h:3149
HttpCommand * getCommand()
Get the HttpCommand object.
Definition: HttpServer.h:3165
static HttpDir * findDir(HttpDir *iter, const char *name, unsigned int nameLen)
Searches for a sub-directory in this directory node.
Definition: HttpServer.h:2640
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:1148
HttpServerConfig()
The constructor sets up the default parameters.
Definition: HttpServer.h:2841
const char * getMethod()
Returns a string representation of the value returned by HttpRequest::getMethodType.
Definition: HttpServer.h:1118
void setValue(const char *newValue)
Assigns a new value to a cookie after the cookie is created.
Definition: HttpServer.h:682
BaTime getMaxInactiveInterval()
Returns the maximum time interval, in seconds, that the session container will keep this session open...
Definition: HttpServer.h:2114
HttpCookie * createCookie(const char *name)
Create a cookie.
Definition: HttpServer.h:1731
HttpPage * getPage(const char *name)
Returns the page with the name given or NULL if not found.
Definition: HttpServer.h:2635
int fmtError(int eCode, const char *fmt,...)
This method implements a printf like implementation for formatting and sending an error message.
Definition: HttpServer.h:1775
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:2645
HttpDir * getFirstDir()
Returns the first sub-directory.
Definition: HttpServer.h:2632
bool isLinked()
Returns true if this directory node is installed into a parent directory.
Definition: HttpServer.h:2650
HttpResponse * getResponse()
Returns the HttpResponse object.
Definition: HttpServer.h:3159
int insertDir(const char *virtualDirRootPath, HttpDir *dir)
Insert a directory node into the virtual file system.
Definition: HttpServer.h:3126
void setStatus(int statusCode)
Sets the status code for this response.
Definition: HttpServer.h:1799
int insertRootDir(HttpDir *dir)
Insert a root directory node.
Definition: HttpServer.h:3121
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:1791
HttpRequest * getRequest()
Get the HttpRequest object.
Definition: HttpServer.h:3163
void p403(const char *p403)
Set a 403 denied request handler.
Definition: HttpServer.h:2647
HttpSession * getSession()
Get the session object.
Definition: HttpServer.h:1956
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:1112
void activate()
Activates the cookie.
Definition: HttpServer.h:688
int sendRedirect(const char *url)
Sends a temporary redirect (302) response to the client using the specified redirect location URL.
Definition: HttpServer.h:1781
int setResponseData(U16 size)
The HttpResponse object stores formatted data in the response data buffer.
Definition: HttpServer.h:2847
int removeAttribute(const char *name)
Removes the object bound with the specified name from this session.
Definition: HttpServer.h:2120
void setDomain(const char *pattern)
Specifies the domain within which this cookie should be presented.
Definition: HttpServer.h:670
int setNoOfHttpConnections(U16 size)
Number of HttpConnection instances.
Definition: HttpServer.h:2853
void setComment(const char *purpose)
Specifies a comment that describes a cookie's purpose.
Definition: HttpServer.h:668
int sendBufAsError(int eCode)
Sends the data formatted into the HttpResponse buffer as an error message to the client.
Definition: HttpServer.h:1771
HttpSessionAttribute(const char *name, HttpSessionAttribute_Destructor terminate)
Create a session attribute.
Definition: HttpServer.h:1952
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 by HttpLink.
Definition: CspRunTm.h:118
The HttpCommand class is a container class for the HttpRequest and HttpResponse command pair.
Definition: HttpServer.h:1826
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:2372
HttpDir * getParent() const
Returns the parent directory or NULL if no parent.
Definition: HttpServer.h:2469
const char * getName() const
Returns the directory name.
Definition: HttpServer.h:2465
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:2264
const char * getName() const
Returns the page name.
Definition: HttpServer.h:2287
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:816
This object is used when sending response messages back to the client.
Definition: HttpServer.h:1186
Use an instance of this class if you want to override the default web-server parameters.
Definition: HttpServer.h:2689
The Web Server.
Definition: HttpServer.h:2869
The interface to an HttpSession attribute.
Definition: HttpServer.h:1920
The HttpSession container class.
Definition: HttpServer.h:2152
Provides a way to identify a user across more than one page request or visit to a web site,...
Definition: HttpServer.h:1967
Standard HTTP header values.
Definition: HttpServer.h:697
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