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 6657 2026-10-28 18:19:39Z wini $
15 *
16 * COPYRIGHT: Real Time Logic LLC, 2004-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 __HttpTrace_h
42#define __HttpTrace_h
43
44#include <HttpServer.h>
45
46#ifdef __cplusplus
47#undef printf
48#endif
49
50#if BA_ENABLE_HTTP_TRACE
51#ifndef HTTP_TRACE
52#define HTTP_TRACE
53#endif
54#else
55#undef HTTP_TRACE
56#endif
57
58#define HttpTrace_doRequestMask 0x01
59#define HttpTrace_doRequestHeadersMask 0x02
60#define HttpTrace_doResponseHeadersMask 0x04
61#define HttpTrace_doResponseBodyMask 0x08
62#define HttpTrace_doHttp11StateMask 0x10
63#define HttpTrace_doReqBufOverflowMask 0x20
64
65
73typedef void (*HttpTrace_Flush)(char* buf, int bufLen);
74
94typedef struct HttpTrace
95{
96#ifdef __cplusplus
135 static void setFLushCallback(HttpTrace_Flush fcb);
136
144 static void vprintf(int prio, const char* fmt, va_list argList);
145
151 static void printf(int prio, const char* fmt, ...);
152
159 static void write(int prio, const char* buf, int len = -1);
160
169 static int setPrio(int prio);
170
178 static BufPrint* getWriter();
179
184 static void releaseWriter(void);
185
197 static void setRequest(bool cmd);
198
203 static void setRequestHeaders(bool cmd);
204
209 static void setResponseHeaders(bool cmd);
210
216 static void setResponseBody(bool cmd);
217
244 static void setHttp11State(bool cmd);
245
250 static void setReqBufOverflow(bool cmd);
251
261 static int setBufSize(int size);
262
265 static void flush();
266
270 static bool isRequestSet();
274 static bool isRequestHeadersSet();
278 static bool isResponseHeadersSet();
282 static bool isResponseBodySet();
286 static bool isHttp11StateSet();
287
288 private:
292 inline HttpTrace() {}
293#endif
294 BufPrint print; /* As if inherited */
295 int prio;
296 U8 traceCmds;
298
299#ifdef __cplusplus
300extern "C" {
301#endif
303BA_API int HttpTrace_setPrio(int prio);
310BA_API void HttpTrace_vprintf(int prio, const char* fmt, va_list argList);
312BA_API void HttpTrace_printf(int prio, const char* fmt, ...);
314BA_API void HttpTrace_write(int prio, const char* buf, int len);
316BA_API void HttpTrace_flush(void);
317
331BA_API int HttpTrace_setBufSize(int size);
335BA_API void HttpTrace_close(void);
336
337/* Internal funtion. Used by macros below */
338BA_API U8 HttpTrace_getTraceCmds(void);
340#define HttpTrace_isRequestSet() \
341 (HttpTrace_getTraceCmds() & HttpTrace_doRequestMask ? TRUE : FALSE)
343#define HttpTrace_isRequestHeadersSet() \
344 (HttpTrace_getTraceCmds() & HttpTrace_doRequestHeadersMask ? TRUE : FALSE)
346#define HttpTrace_isResponseHeadersSet() \
347 (HttpTrace_getTraceCmds() & HttpTrace_doResponseHeadersMask ? TRUE : FALSE)
349#define HttpTrace_isResponseBodySet() \
350 (HttpTrace_getTraceCmds() & HttpTrace_doResponseBodyMask ? TRUE : FALSE)
352#define HttpTrace_isHttp11StateSet() \
353 (HttpTrace_getTraceCmds() & HttpTrace_doHttp11StateMask ? TRUE : FALSE)
354
355/* Private Barracuda functions */
356
357#ifdef HTTP_TRACE
358#define TRPR(data) HttpTrace_TRPR data
359BA_API void HttpTrace_TRPR(const char* fmt, ...);
360#else
361#define TRPR(data)
362#endif
363BA_API HttpTrace* HttpTrace_get(void);
364#define HttpTrace_doRequest() \
365 (HttpTrace_get()->traceCmds & HttpTrace_doRequestMask)
366#define HttpTrace_doRequestHeaders() \
367 (HttpTrace_get()->traceCmds & HttpTrace_doRequestHeadersMask)
368#define HttpTrace_doResponseHeaders() \
369 (HttpTrace_get()->traceCmds & HttpTrace_doResponseHeadersMask)
370#define HttpTrace_doResponseBody() \
371 (HttpTrace_get()->traceCmds & HttpTrace_doResponseBodyMask)
372#define HttpTrace_doHttp11State() \
373 (HttpTrace_get()->traceCmds & HttpTrace_doHttp11StateMask)
374#define HttpTrace_doReqBufOverflow() \
375 (HttpTrace_get()->traceCmds & HttpTrace_doReqBufOverflowMask)
379BA_API void HttpTrace_releaseWriter(void);
380#ifdef __cplusplus
381}
382inline int HttpTrace::setPrio(int prio) {
383 return HttpTrace_setPrio(prio);
384}
387inline void HttpTrace::vprintf(int prio, const char* fmt, va_list argList) {
388 HttpTrace_vprintf(prio, fmt, argList); }
389inline void HttpTrace::printf(int prio, const char* fmt, ...) {
390 va_list varg;
391 va_start(varg, fmt);
392 HttpTrace_vprintf(prio, fmt, varg);
393 va_end(varg);
394}
395inline void HttpTrace::write(int prio, const char* buf, int len) {
396 HttpTrace_write(prio, buf, len); }
397
399 return HttpTrace_getWriter(); }
400inline void HttpTrace::releaseWriter(void) {
402inline void HttpTrace::setRequest(bool cmd) {
404inline void HttpTrace::setRequestHeaders(bool cmd) {
406inline void HttpTrace::setResponseHeaders(bool cmd) {
408inline void HttpTrace::setResponseBody(bool cmd) {
410inline void HttpTrace::setHttp11State(bool cmd) {
412inline void HttpTrace::setReqBufOverflow(bool cmd) {
414inline int HttpTrace::setBufSize(int size) {
415 return HttpTrace_setBufSize(size); }
416inline void HttpTrace::flush() {
418}
420 return HttpTrace_isRequestSet() ? true : false;
421}
423 return HttpTrace_isRequestHeadersSet() ? true : false;
424}
426 return HttpTrace_isResponseHeadersSet() ? true : false;
427}
429 return HttpTrace_isResponseBodySet() ? true : false;
430}
432 return HttpTrace_isHttp11StateSet() ? true : false;
433}
434#endif
435
436#ifdef __cplusplus
443{
446 _bufPrint = HttpTrace_getWriter();
447 }
450 release();
451 }
452
454 void release() {
455 if(_bufPrint) {_bufPrint=0; HttpTrace_releaseWriter(); }
456 }
457
459 void lock() {
460 if(!_bufPrint) {_bufPrint = HttpTrace_getWriter(); }
461 }
462
465 operator BufPrint*() { return _bufPrint; }
466
470 BufPrint* operator -> () { return _bufPrint; }
471 private:
472 BufPrint* _bufPrint;
473};
474#endif
475
476
477
478#endif
BA_API BufPrint * HttpTrace_getWriter(void)
Get and lock the trace BufPrint object.
#define HttpTrace_isRequestHeadersSet()
Definition: HttpTrace.h:343
BA_API int HttpTrace_setBufSize(int size)
Set trace buffer size.
#define HttpTrace_isResponseBodySet()
Definition: HttpTrace.h:349
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:73
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:346
#define HttpTrace_isHttp11StateSet()
Definition: HttpTrace.h:352
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:340
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:92
U8 BaBool
Boolean stored in an unsigned byte; FALSE is zero and TRUE is one.
Definition: GenPrimT.h:121
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:443
BufPrint * operator->()
Definition: HttpTrace.h:470
void release()
Release the trace if not already released.
Definition: HttpTrace.h:454
HttpTraceWriteLock()
Attempt to acquire the trace writer; conversion returns NULL if disabled.
Definition: HttpTrace.h:445
void lock()
Lock the trace if not already locked.
Definition: HttpTrace.h:459
~HttpTraceWriteLock()
Release any held writer lock.
Definition: HttpTrace.h:449
Buffered diagnostic output and optional HTTP protocol tracing.
Definition: HttpTrace.h:95
static bool isResponseBodySet()
Returns true if response-body tracing is enabled.
Definition: HttpTrace.h:428
static void printf(int prio, const char *fmt,...)
Write data to the trace buffer.
Definition: HttpTrace.h:389
static int setPrio(int prio)
Set the trace message priority filter.
Definition: HttpTrace.h:382
static void flush()
Force a flush on data in trace buffer; i.e., call the flush callback.
Definition: HttpTrace.h:416
static void releaseWriter(void)
Release a writer lock obtained by a successful getWriter call.
Definition: HttpTrace.h:400
static void setResponseHeaders(bool cmd)
If enabled, the web-server dumps the content of the response header to the trace buffer.
Definition: HttpTrace.h:406
static void setHttp11State(bool cmd)
If enabled, prints the status for each active client connection of the internal "HTTP 1....
Definition: HttpTrace.h:410
static BufPrint * getWriter()
Get and lock the trace BufPrint object.
Definition: HttpTrace.h:398
static void setFLushCallback(HttpTrace_Flush fcb)
The HTTP_TRACE compile time macro adds the trace library to the Barracuda library,...
Definition: HttpTrace.h:385
static int setBufSize(int size)
Set trace buffer size.
Definition: HttpTrace.h:414
static bool isHttp11StateSet()
Returns true if HTTP/1.1 connection-state tracing is enabled.
Definition: HttpTrace.h:431
static void write(int prio, const char *buf, int len=-1)
Write data to the trace buffer.
Definition: HttpTrace.h:395
static void vprintf(int prio, const char *fmt, va_list argList)
Write data to the trace buffer.
Definition: HttpTrace.h:387
static bool isRequestSet()
Returns true if request-line tracing is enabled.
Definition: HttpTrace.h:419
static bool isResponseHeadersSet()
Returns true if response-header tracing is enabled.
Definition: HttpTrace.h:425
static bool isRequestHeadersSet()
Returns true if request-header tracing is enabled.
Definition: HttpTrace.h:422
static void setResponseBody(bool cmd)
If enabled, the web-server dumps the content of the response body to the trace buffer.
Definition: HttpTrace.h:408
static void setRequest(bool cmd)
Enable or disable request-line tracing.
Definition: HttpTrace.h:402
static void setRequestHeaders(bool cmd)
If enabled, the web-server dumps the content of the request header to the trace buffer.
Definition: HttpTrace.h:404
static void setReqBufOverflow(bool cmd)
Report when an HTTP request exceeds the configured request buffer.
Definition: HttpTrace.h:412