Barracuda Application Server C/C++ Reference
Native APIs, integration guides, and platform interfaces
HttpTrace.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: HttpTrace.h 5978 2026-09-11 16:13:48Z wini $
15 *
16 * COPYRIGHT: Real Time Logic LLC, 2004-2021
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 __HttpTrace_h
42#define __HttpTrace_h
43
44#include <HttpServer.h>
45
46#ifdef __cplusplus
47#undef printf
48#endif
49
50#ifndef NO_HTTP_TRACE
51#ifndef HTTP_TRACE
52#define HTTP_TRACE
53#endif
54#endif
55
56#define HttpTrace_doRequestMask 0x01
57#define HttpTrace_doRequestHeadersMask 0x02
58#define HttpTrace_doResponseHeadersMask 0x04
59#define HttpTrace_doResponseBodyMask 0x08
60#define HttpTrace_doHttp11StateMask 0x10
61#define HttpTrace_doReqBufOverflowMask 0x20
62
63
71typedef void (*HttpTrace_Flush)(char* buf, int bufLen);
72
92typedef struct HttpTrace
93{
94#ifdef __cplusplus
133 static void setFLushCallback(HttpTrace_Flush fcb);
134
142 static void vprintf(int prio, const char* fmt, va_list argList);
143
149 static void printf(int prio, const char* fmt, ...);
150
157 static void write(int prio, const char* buf, int len = -1);
158
167 static int setPrio(int prio);
168
176 static BufPrint* getWriter();
177
182 static void releaseWriter(void);
183
195 static void setRequest(bool cmd);
196
201 static void setRequestHeaders(bool cmd);
202
207 static void setResponseHeaders(bool cmd);
208
214 static void setResponseBody(bool cmd);
215
242 static void setHttp11State(bool cmd);
243
248 static void setReqBufOverflow(bool cmd);
249
259 static int setBufSize(int size);
260
263 static void flush();
264
266 static bool isRequestSet();
268 static bool isRequestHeadersSet();
270 static bool isResponseHeadersSet();
272 static bool isResponseBodySet();
274 static bool isHttp11StateSet();
275
276 private:
280 inline HttpTrace() {}
281#endif
282 BufPrint print; /* As if inherited */
283 int prio;
284 U8 traceCmds;
286
287#ifdef __cplusplus
288extern "C" {
289#endif
291BA_API int HttpTrace_setPrio(int prio);
298BA_API void HttpTrace_vprintf(int prio, const char* fmt, va_list argList);
300BA_API void HttpTrace_printf(int prio, const char* fmt, ...);
302BA_API void HttpTrace_write(int prio, const char* buf, int len);
304BA_API void HttpTrace_flush(void);
305
319BA_API int HttpTrace_setBufSize(int size);
323BA_API void HttpTrace_close(void);
324
325/* Internal funtion. Used by macros below */
326BA_API U8 HttpTrace_getTraceCmds(void);
328#define HttpTrace_isRequestSet() \
329 (HttpTrace_getTraceCmds() & HttpTrace_doRequestMask ? TRUE : FALSE)
331#define HttpTrace_isRequestHeadersSet() \
332 (HttpTrace_getTraceCmds() & HttpTrace_doRequestHeadersMask ? TRUE : FALSE)
334#define HttpTrace_isResponseHeadersSet() \
335 (HttpTrace_getTraceCmds() & HttpTrace_doResponseHeadersMask ? TRUE : FALSE)
337#define HttpTrace_isResponseBodySet() \
338 (HttpTrace_getTraceCmds() & HttpTrace_doResponseBodyMask ? TRUE : FALSE)
340#define HttpTrace_isHttp11StateSet() \
341 (HttpTrace_getTraceCmds() & HttpTrace_doHttp11StateMask ? TRUE : FALSE)
342
343/* Private Barracuda functions */
344
345#ifdef HTTP_TRACE
346#define TRPR(data) HttpTrace_TRPR data
347BA_API void HttpTrace_TRPR(const char* fmt, ...);
348#else
349#define TRPR(data)
350#endif
351BA_API HttpTrace* HttpTrace_get(void);
352#define HttpTrace_doRequest() \
353 (HttpTrace_get()->traceCmds & HttpTrace_doRequestMask)
354#define HttpTrace_doRequestHeaders() \
355 (HttpTrace_get()->traceCmds & HttpTrace_doRequestHeadersMask)
356#define HttpTrace_doResponseHeaders() \
357 (HttpTrace_get()->traceCmds & HttpTrace_doResponseHeadersMask)
358#define HttpTrace_doResponseBody() \
359 (HttpTrace_get()->traceCmds & HttpTrace_doResponseBodyMask)
360#define HttpTrace_doHttp11State() \
361 (HttpTrace_get()->traceCmds & HttpTrace_doHttp11StateMask)
362#define HttpTrace_doReqBufOverflow() \
363 (HttpTrace_get()->traceCmds & HttpTrace_doReqBufOverflowMask)
367BA_API void HttpTrace_releaseWriter(void);
368#ifdef __cplusplus
369}
370inline int HttpTrace::setPrio(int prio) {
371 return HttpTrace_setPrio(prio);
372}
375inline void HttpTrace::vprintf(int prio, const char* fmt, va_list argList) {
376 HttpTrace_vprintf(prio, fmt, argList); }
377inline void HttpTrace::printf(int prio, const char* fmt, ...) {
378 va_list varg;
379 va_start(varg, fmt);
380 HttpTrace_vprintf(prio, fmt, varg);
381 va_end(varg);
382}
383inline void HttpTrace::write(int prio, const char* buf, int len) {
384 HttpTrace_write(prio, buf, len); }
385
387 return HttpTrace_getWriter(); }
388inline void HttpTrace::releaseWriter(void) {
390inline void HttpTrace::setRequest(bool cmd) {
392inline void HttpTrace::setRequestHeaders(bool cmd) {
394inline void HttpTrace::setResponseHeaders(bool cmd) {
396inline void HttpTrace::setResponseBody(bool cmd) {
398inline void HttpTrace::setHttp11State(bool cmd) {
400inline void HttpTrace::setReqBufOverflow(bool cmd) {
402inline int HttpTrace::setBufSize(int size) {
403 return HttpTrace_setBufSize(size); }
404inline void HttpTrace::flush() {
406}
408 return HttpTrace_isRequestSet() ? true : false;
409}
411 return HttpTrace_isRequestHeadersSet() ? true : false;
412}
414 return HttpTrace_isResponseHeadersSet() ? true : false;
415}
417 return HttpTrace_isResponseBodySet() ? true : false;
418}
420 return HttpTrace_isHttp11StateSet() ? true : false;
421}
422#endif
423
424#ifdef __cplusplus
431{
434 _bufPrint = HttpTrace_getWriter();
435 }
438 release();
439 }
440
442 void release() {
443 if(_bufPrint) {_bufPrint=0; HttpTrace_releaseWriter(); }
444 }
445
447 void lock() {
448 if(!_bufPrint) {_bufPrint = HttpTrace_getWriter(); }
449 }
450
453 operator BufPrint*() { return _bufPrint; }
454
458 BufPrint* operator -> () { return _bufPrint; }
459 private:
460 BufPrint* _bufPrint;
461};
462#endif
463
464
465
466#endif
BA_API BufPrint * HttpTrace_getWriter(void)
Get and lock the trace BufPrint object.
#define HttpTrace_isRequestHeadersSet()
Definition: HttpTrace.h:331
BA_API int HttpTrace_setBufSize(int size)
Set trace buffer size.
#define HttpTrace_isResponseBodySet()
Definition: HttpTrace.h:337
BA_API void HttpTrace_setResponseBody(BaBool cmd)
If enabled, the web-server dumps the content of the response body to the trace buffer.
BA_API void HttpTrace_setHttp11State(BaBool cmd)
If enabled, prints the status for each active client connection of the internal "HTTP 1....
BA_API void HttpTrace_write(int prio, const char *buf, int len)
Write data to the trace buffer.
BA_API void HttpTrace_releaseWriter(void)
Release a writer lock obtained by a successful getWriter call.
struct HttpTrace HttpTrace
Buffered diagnostic output and optional HTTP protocol tracing.
void(* HttpTrace_Flush)(char *buf, int bufLen)
Consume buffered trace output synchronously.
Definition: HttpTrace.h:71
BA_API void HttpTrace_flush(void)
Force a flush on data in trace buffer; i.e., call the flush callback.
BA_API HttpTrace_Flush HttpTrace_getFLushCallback(void)
BA_API void HttpTrace_setReqBufOverflow(BaBool cmd)
Report when an HTTP request exceeds the configured request buffer.
BA_API int HttpTrace_setPrio(int prio)
Set the trace message priority filter.
BA_API void HttpTrace_setRequestHeaders(BaBool cmd)
If enabled, the web-server dumps the content of the request header to the trace buffer.
BA_API void HttpTrace_setFLushCallback(HttpTrace_Flush fcb)
The HTTP_TRACE compile time macro adds the trace library to the Barracuda library,...
BA_API void HttpTrace_close(void)
Release the trace buffer and disable output without flushing pending bytes.
BA_API void HttpTrace_setRequest(BaBool cmd)
Enable or disable request-line tracing.
#define HttpTrace_isResponseHeadersSet()
Definition: HttpTrace.h:334
#define HttpTrace_isHttp11StateSet()
Definition: HttpTrace.h:340
BA_API void HttpTrace_printf(int prio, const char *fmt,...)
Write data to the trace buffer.
BA_API void HttpTrace_setResponseHeaders(BaBool cmd)
If enabled, the web-server dumps the content of the response header to the trace buffer.
#define HttpTrace_isRequestSet()
Definition: HttpTrace.h:328
BA_API void HttpTrace_vprintf(int prio, const char *fmt, va_list argList)
Write data to the trace buffer.
uint8_t U8
Unsigned 8-bit integer.
Definition: GenPrimT.h:89
U8 BaBool
Boolean stored in an unsigned byte; FALSE is zero and TRUE is one.
Definition: GenPrimT.h:118
The BufPrint class, which implements a compact printf-style formatter, is a base class used by severa...
Definition: BufPrint.h:132
HttpTraceWriteLock is a C++ class that makes it easier to lock the trace by using method HttpTrace::g...
Definition: HttpTrace.h:431
BufPrint * operator->()
Definition: HttpTrace.h:458
void release()
Release the trace if not already released.
Definition: HttpTrace.h:442
HttpTraceWriteLock()
Attempt to acquire the trace writer; conversion returns NULL if disabled.
Definition: HttpTrace.h:433
void lock()
Lock the trace if not already locked.
Definition: HttpTrace.h:447
~HttpTraceWriteLock()
Release any held writer lock.
Definition: HttpTrace.h:437
Buffered diagnostic output and optional HTTP protocol tracing.
Definition: HttpTrace.h:93
static bool isResponseBodySet()
Returns true if response-body tracing is enabled.
Definition: HttpTrace.h:416
static void printf(int prio, const char *fmt,...)
Write data to the trace buffer.
Definition: HttpTrace.h:377
static int setPrio(int prio)
Set the trace message priority filter.
Definition: HttpTrace.h:370
static void flush()
Force a flush on data in trace buffer; i.e., call the flush callback.
Definition: HttpTrace.h:404
static void releaseWriter(void)
Release a writer lock obtained by a successful getWriter call.
Definition: HttpTrace.h:388
static void setResponseHeaders(bool cmd)
If enabled, the web-server dumps the content of the response header to the trace buffer.
Definition: HttpTrace.h:394
static void setHttp11State(bool cmd)
If enabled, prints the status for each active client connection of the internal "HTTP 1....
Definition: HttpTrace.h:398
static BufPrint * getWriter()
Get and lock the trace BufPrint object.
Definition: HttpTrace.h:386
static void setFLushCallback(HttpTrace_Flush fcb)
The HTTP_TRACE compile time macro adds the trace library to the Barracuda library,...
Definition: HttpTrace.h:373
static int setBufSize(int size)
Set trace buffer size.
Definition: HttpTrace.h:402
static bool isHttp11StateSet()
Returns true if HTTP/1.1 connection-state tracing is enabled.
Definition: HttpTrace.h:419
static void write(int prio, const char *buf, int len=-1)
Write data to the trace buffer.
Definition: HttpTrace.h:383
static void vprintf(int prio, const char *fmt, va_list argList)
Write data to the trace buffer.
Definition: HttpTrace.h:375
static bool isRequestSet()
Returns true if request-line tracing is enabled.
Definition: HttpTrace.h:407
static bool isResponseHeadersSet()
Returns true if response-header tracing is enabled.
Definition: HttpTrace.h:413
static bool isRequestHeadersSet()
Returns true if request-header tracing is enabled.
Definition: HttpTrace.h:410
static void setResponseBody(bool cmd)
If enabled, the web-server dumps the content of the response body to the trace buffer.
Definition: HttpTrace.h:396
static void setRequest(bool cmd)
Enable or disable request-line tracing.
Definition: HttpTrace.h:390
static void setRequestHeaders(bool cmd)
If enabled, the web-server dumps the content of the request header to the trace buffer.
Definition: HttpTrace.h:392
static void setReqBufOverflow(bool cmd)
Report when an HTTP request exceeds the configured request buffer.
Definition: HttpTrace.h:400