Barracuda Application Server C/C++ Reference
NO
HttpResRdr.h
1 /*
2  * ____ _________ __ _
3  * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____
4  * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/
5  * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__
6  * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/
7  * /____/
8  *
9  * Barracuda Embedded Web-Server
10  *
11  ****************************************************************************
12  * HEADER
13  *
14  * $Id: HttpResRdr.h 4915 2021-12-01 18:26:55Z wini $
15  *
16  * COPYRIGHT: Real Time Logic LLC, 2006-2008
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 #ifndef _HttpResRdr_h
40 #define _HttpResRdr_h
41 
42 #include "IoIntf.h"
43 #include "BaServerLib.h"
44 #include "HttpServer.h"
45 
46 
47 struct HttpRdFilter;
48 typedef void (*HttpRdFilter_Service)(struct HttpRdFilter* o,
49  const char* name,
50  IoStat* st,
51  HttpCommand* cmd);
52 
56 typedef struct HttpRdFilter
57 {
58  DoubleLink super;
59  HttpRdFilter_Service serviceFp;
60  const char* ext; /* File Extension */
61 } HttpRdFilter;
62 
63 BA_API void HttpRdFilter_constructor(
64  HttpRdFilter* o, const char* ext, HttpRdFilter_Service serviceFp);
65 
66 BA_API void HttpRdFilter_destructor(HttpRdFilter* o);
67 
68 /* Designed for LSP function dir:header(table)
69  The key and value indexes point to the key and value embedded as
70  part of the memory region below the struct.
71 */
72 typedef struct {
73  U16 keyIx;
74  U16 valIx;
76 
77 
141 typedef struct HttpResRdr
142 #ifdef __cplusplus
143 : public HttpDir
144 {
145  HttpResRdr() {}
155  HttpResRdr(IoIntf* io, const char* dirName,
156  AllocatorIntf* alloc=0, S8 priority=0);
157 
187  HttpResRdr(IoIntf* io, const char* domain, const char* p404,
188  AllocatorIntf* alloc=0, S8 priority=0);
189 
202  int insertPrologDir(HttpDir* dir);
203 
204  /* Terminate a HttpResRdr instance */
205  ~HttpResRdr();
206 
209  int installFilter(HttpRdFilter* filter);
210 
215  void setMaxAge(BaTime maxAge);
216 
228  static void sendFile(
229  IoIntf* io,const char* name, IoStat* st, HttpCommand* cmd);
230 
233  IoIntf* getIo();
234 #if 0
235 }
236 #endif
237 #else
238 {
239  HttpDir super; /* Inherits from HttpDir */
240 #endif
241  DoubleList filterList;
242  AllocatorIntf* alloc;
243  IoIntf* io;
244  HttpDir_Service superServiceFunc;
245  HttpDir* prologDirRoot;
246  HttpResRdrHeader* headers;
247  const char* domain;
248  const char* p404;
249  BaTime maxAge;
250  int maxFilterLen;
251 } HttpResRdr;
252 
253 
254 #ifdef __cplusplus
255 extern "C" {
256 #endif
257 BA_API void HttpResRdr_constructor(
258  HttpResRdr* o, IoIntf* io, const char* dirName,
259  AllocatorIntf* alloc, S8 priority);
260 BA_API void HttpResRdr_constructor2(
261  HttpResRdr* o,IoIntf* io,const char* domain,
262  const char* p404,AllocatorIntf* alloc,
263  S8 priority);
264 BA_API int HttpResRdr_insertPrologDir(HttpResRdr* o, HttpDir* dir);
265 BA_API void HttpResRdr_destructor(HttpResRdr* o);
266 BA_API int HttpResRdr_installFilter(HttpResRdr* o, HttpRdFilter* filter);
267 #define HttpResRdr_setMaxAge(o, maxAgeMA) (o)->maxAge=maxAgeMA
268 #define HttpResRdr_setAuthenticator(o, authenticator, realm) \
269  HttpDir_setAuthenticator((HttpDir*)o, authenticator, realm)
270 BA_API void HttpResRdr_sendFile(IoIntf* io,const char* name,
271  IoStat* st,HttpCommand* cmd);
272 BA_API void set_deflategzip(IoIntf_DeflateGzip ptr);
273 BA_API IoIntf_DeflateGzip get_deflategzip(void);
274 BA_API void HttpResRdr_setHeader(HttpResRdr* o, HttpResRdrHeader* headers);
275 
276 
277 #define HttpResRdr_getIo(o) (o)->io
278 #ifdef __cplusplus
279 }
280 inline HttpResRdr::HttpResRdr(IoIntf* io, const char* domain, const char* p404,
281  AllocatorIntf* alloc, S8 priority) {
282  HttpResRdr_constructor2(this, io, domain, p404, alloc, priority);
283 }
284 inline HttpResRdr::HttpResRdr(IoIntf* io, const char* dirName,
285  AllocatorIntf* alloc, S8 priority) {
286  HttpResRdr_constructor(this, io, dirName, alloc, priority);
287 }
288 
290  return HttpResRdr_insertPrologDir(this, dir);
291 }
292 
293 inline HttpResRdr::~HttpResRdr(){
294  HttpResRdr_destructor(this);
295 }
297  return HttpResRdr_installFilter(this, filter);
298 }
299 inline void HttpResRdr::setMaxAge(BaTime maxAge){
300  HttpResRdr_setMaxAge(this, maxAge);
301 }
303  IoIntf* io, const char* name, IoStat* st, HttpCommand* cmd){
304  HttpResRdr_sendFile(io,name,st,cmd);
305 }
307  return HttpResRdr_getIo(this);
308 }
309 #endif
310 
311 
312 #endif
AllocatorIntf
Memory allocation and deallocation Interface class.
Definition: AllocatorIntf.h:83
HttpDir_Service
int(* HttpDir_Service)(struct HttpDir *o, const char *relPath, HttpCommand *cmd)
The HttpDir service callback function.
Definition: HttpServer.h:2350
BaTime
S64 BaTime
An arithmetic type representing calendar time with epoch of 1970-01-01 00:00:10 GMT – i....
Definition: GenPrimT.h:93
HttpDir
An instance of the HttpDir class, which is a collection of zero or more resources,...
Definition: HttpServer.h:2384
IoIntf
The IoIntf class specifies an abstract file API, implementations include ZipIo, DiskIo,...
Definition: IoIntf.h:377
HttpRdFilter
Superclass for HttpResRdr filters.
Definition: HttpResRdr.h:57
HttpResRdr::getIo
IoIntf * getIo()
Returns the IoIntf used by the HttpResRdr.
Definition: HttpResRdr.h:306
HttpResRdr::setMaxAge
void setMaxAge(BaTime maxAge)
Makes the HttpResRdr instance set the HTTP header "Cache-Control: max-age" for all resources.
Definition: HttpResRdr.h:299
IoIntf_DeflateGzip
ResIntfPtr(* IoIntf_DeflateGzip)(ResIntfPtr resPtr, const char *name, ThreadMutex *m, BaFileSize *size, BaBool *isCompressed)
Deflate a file or portion of a file to temporary storage.
Definition: IoIntf.h:269
HttpCommand
The HttpCommand class is a container class for the HttpRequest and HttpResponse command pair.
Definition: HttpServer.h:1834
HttpResRdr
The HTTP resource reader searches and presents IoIntf resources to HTTP clients requesting such infor...
Definition: HttpResRdr.h:144
HttpResRdr::sendFile
static void sendFile(IoIntf *io, const char *name, IoStat *st, HttpCommand *cmd)
Send resource to a client.
Definition: HttpResRdr.h:302
HttpResRdrHeader
Definition: HttpResRdr.h:72
HttpResRdr::insertPrologDir
int insertPrologDir(HttpDir *dir)
Insert a prologue HttpDir.
Definition: HttpResRdr.h:289
IoStat
Resource information.
Definition: IoIntf.h:168
HttpResRdr::installFilter
int installFilter(HttpRdFilter *filter)
Install a filter.
Definition: HttpResRdr.h:296