Barracuda Application Server C/C++ Reference
Native APIs, integration guides, and platform interfaces
HttpResRdr.h
Go to the documentation of this file.
1/*
2 * ____ _________ __ _
3 * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____
4 * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/
5 * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__
6 * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/
7 * /____/
8 *
9 * Barracuda Embedded Web-Server
10 *
11 ****************************************************************************
12 * HEADER
13 *
14 * $Id: HttpResRdr.h 6056 2026-09-20 05:09:33Z wini $
15 *
16 * COPYRIGHT: Real Time Logic LLC, 2006 - 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
41#ifndef _HttpResRdr_h
42#define _HttpResRdr_h
43
44#include "IoIntf.h"
45#include "BaServerLib.h"
46#include "HttpServer.h"
47
48
49struct HttpRdFilter;
59typedef void (*HttpRdFilter_Service)(struct HttpRdFilter* o,
60 const char* name,
61 IoStat* st,
62 HttpCommand* cmd);
63
67typedef struct HttpRdFilter
68{
69 DoubleLink super;
70 HttpRdFilter_Service serviceFp;
71 const char* ext; /* File Extension */
73
81 HttpRdFilter* o, const char* ext, HttpRdFilter_Service serviceFp);
82
88
89/* Designed for LSP function dir:header(table)
90 The key and value indexes point to the key and value embedded as
91 part of the memory region below the struct.
92*/
93typedef struct {
94 U16 keyIx;
95 U16 valIx;
96} HttpResRdrHeader;
97
98
167typedef struct HttpResRdr
168#ifdef __cplusplus
169: public HttpDir
170{
182 HttpResRdr(IoIntf* io, const char* dirName,
183 AllocatorIntf* alloc=0, S8 priority=0);
184
215 HttpResRdr(IoIntf* io, const char* domain, const char* p404,
216 AllocatorIntf* alloc=0, S8 priority=0);
217
234 int insertPrologDir(HttpDir* dir);
235
240 ~HttpResRdr();
241
249 int installFilter(HttpRdFilter* filter);
250
256 void setMaxAge(BaTime maxAge);
257
269 static void sendFile(
270 IoIntf* io,const char* name, IoStat* st, HttpCommand* cmd);
271
275 IoIntf* getIo();
276#if 0
277}
278#endif
279#else
280{
281 HttpDir super; /* Inherits from HttpDir */
282#endif
283 DoubleList filterList;
284 AllocatorIntf* alloc;
285 IoIntf* io;
286 HttpDir_Service superServiceFunc;
287 HttpDir* prologDirRoot;
288 HttpResRdrHeader* headers;
289 const char* domain;
290 const char* p404;
291 BaTime maxAge;
292 int maxFilterLen;
294
295
296#ifdef __cplusplus
297extern "C" {
298#endif
303 HttpResRdr* o, IoIntf* io, const char* dirName,
304 AllocatorIntf* alloc, S8 priority);
309 HttpResRdr* o,IoIntf* io,const char* domain,
310 const char* p404,AllocatorIntf* alloc,
311 S8 priority);
328#define HttpResRdr_setMaxAge(o, maxAgeMA) (o)->maxAge=maxAgeMA
335#define HttpResRdr_setAuthenticator(o, authenticator, realm) \
336 HttpDir_setAuthenticator((HttpDir*)o, authenticator, realm)
339BA_API void HttpResRdr_sendFile(IoIntf* io,const char* name,
340 IoStat* st,HttpCommand* cmd);
341/* Shared resource/WebDAV helpers. Metadata is not a content revision, so the
342 NUL-terminated tag is weak; buf must hold HttpResRdr_ETagSize bytes. */
343#define HttpResRdr_ETagSize 38
344BA_API void HttpResRdr_fmtETag(char* buf, const IoStat* st);
345/* Return 0 to proceed or an HTTP status (304/400/412). st is NULL for a
346 nonexistent target; the caller performs normal method/access checks first. */
347BA_API int HttpResRdr_checkPreconditions(HttpRequest* req, const IoStat* st);
348BA_API void set_deflategzip(IoIntf_DeflateGzip ptr);
349BA_API IoIntf_DeflateGzip get_deflategzip(void);
350BA_API void HttpResRdr_setHeader(HttpResRdr* o, HttpResRdrHeader* headers);
351
352
356#define HttpResRdr_getIo(o) (o)->io
357#ifdef __cplusplus
358}
359inline HttpResRdr::HttpResRdr(IoIntf* io, const char* domain, const char* p404,
360 AllocatorIntf* alloc, S8 priority) {
361 HttpResRdr_constructor2(this, io, domain, p404, alloc, priority);
362}
363inline HttpResRdr::HttpResRdr(IoIntf* io, const char* dirName,
364 AllocatorIntf* alloc, S8 priority) {
365 HttpResRdr_constructor(this, io, dirName, alloc, priority);
366}
367
369 return HttpResRdr_insertPrologDir(this, dir);
370}
371
374}
376 return HttpResRdr_installFilter(this, filter);
377}
378inline void HttpResRdr::setMaxAge(BaTime maxAge){
379 HttpResRdr_setMaxAge(this, maxAge);
380}
382 IoIntf* io, const char* name, IoStat* st, HttpCommand* cmd){
383 HttpResRdr_sendFile(io,name,st,cmd);
384}
386 return HttpResRdr_getIo(this);
387}
388#endif
389
390
391#endif
BA_API void HttpResRdr_constructor2(HttpResRdr *o, IoIntf *io, const char *domain, const char *p404, AllocatorIntf *alloc, S8 priority)
Initialize a HttpResRdr for name based virtual hosting.
BA_API void HttpRdFilter_destructor(HttpRdFilter *o)
Unlink a filter from its reader if installed.
BA_API int HttpResRdr_installFilter(HttpResRdr *o, HttpRdFilter *filter)
Install a file-extension filter.
BA_API void HttpResRdr_sendFile(IoIntf *io, const char *name, IoStat *st, HttpCommand *cmd)
Send an IoIntf resource through the current response.
#define HttpResRdr_setMaxAge(o, maxAgeMA)
C form of HttpResRdr::setMaxAge.
Definition: HttpResRdr.h:328
void(* HttpRdFilter_Service)(struct HttpRdFilter *o, const char *name, IoStat *st, HttpCommand *cmd)
Process a resource selected by a reader's file-extension filter.
Definition: HttpResRdr.h:59
HttpResRdr HttpResRdr
The HTTP resource reader searches and presents IoIntf resources to HTTP clients requesting such infor...
#define HttpResRdr_getIo(o)
Access the filesystem supplied at construction.
Definition: HttpResRdr.h:356
BA_API void HttpResRdr_destructor(HttpResRdr *o)
Detach and destroy directory state, including the prologue root and owned custom-header storage.
BA_API void HttpRdFilter_constructor(HttpRdFilter *o, const char *ext, HttpRdFilter_Service serviceFp)
Initialize a filter without installing it.
BA_API int HttpResRdr_insertPrologDir(HttpResRdr *o, HttpDir *dir)
Insert a prologue HttpDir.
BA_API void HttpResRdr_constructor(HttpResRdr *o, IoIntf *io, const char *dirName, AllocatorIntf *alloc, S8 priority)
Initializes a HttpResRdr.
struct HttpRdFilter HttpRdFilter
Superclass for HttpResRdr filters.
ResIntfPtr(* IoIntf_DeflateGzip)(ResIntfPtr resPtr, const char *name, ThreadMutex *m, BaFileSize *size, BaBool *isCompressed)
Optionally compress an open resource or range into temporary gzip storage.
Definition: IoIntf.h:291
int(* HttpDir_Service)(struct HttpDir *o, const char *relPath, HttpCommand *cmd)
The HttpDir service callback function.
Definition: HttpServer.h:2747
uint16_t U16
Unsigned 16-bit integer.
Definition: GenPrimT.h:91
S64 BaTime
An arithmetic type representing calendar time with epoch of 1970-01-01 00:00:00 UTC,...
Definition: GenPrimT.h:103
int8_t S8
Signed 8-bit integer.
Definition: GenPrimT.h:81
Memory allocation and deallocation Interface class.
Definition: AllocatorIntf.h:98
The HttpCommand class is a container class for the HttpRequest and HttpResponse command pair.
Definition: HttpServer.h:2151
An instance of the HttpDir class, which is a collection of zero or more resources,...
Definition: HttpServer.h:2777
Superclass for HttpResRdr filters.
Definition: HttpResRdr.h:68
The HttpServer creates an HttpRequest object when the HttpServer parses a client request.
Definition: HttpServer.h:950
The HTTP resource reader searches and presents IoIntf resources to HTTP clients requesting such infor...
Definition: HttpResRdr.h:170
IoIntf * getIo()
Access the filesystem supplied at construction.
Definition: HttpResRdr.h:385
HttpResRdr()
Uninitialized storage; call a C constructor before use.
Definition: HttpResRdr.h:172
int insertPrologDir(HttpDir *dir)
Insert a prologue HttpDir.
Definition: HttpResRdr.h:368
int installFilter(HttpRdFilter *filter)
Install a file-extension filter.
Definition: HttpResRdr.h:375
~HttpResRdr()
Detach and destroy directory state, including the prologue root and owned custom-header storage.
Definition: HttpResRdr.h:372
static void sendFile(IoIntf *io, const char *name, IoStat *st, HttpCommand *cmd)
Send an IoIntf resource through the current response.
Definition: HttpResRdr.h:381
void setMaxAge(BaTime maxAge)
Configure Cache-Control max-age for ordinary static resources.
Definition: HttpResRdr.h:378
The IoIntf class specifies an abstract file API, implementations include ZipIo, DiskIo,...
Definition: IoIntf.h:482
Resource information.
Definition: IoIntf.h:170