Barracuda Application Server C/C++ Reference
NO
HttpTrace.h
1/*
2 * ____ _________ __ _
3 * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____
4 * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/
5 * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__
6 * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/
7 * /____/
8 *
9 * Barracuda Embedded Web-Server
10 *
11 ****************************************************************************
12 * HEADER
13 *
14 * $Id: HttpTrace.h 4915 2021-12-01 18:26:55Z 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
39#ifndef __HttpTrace_h
40#define __HttpTrace_h
41
42#include <HttpServer.h>
43
44#ifdef __cplusplus
45#undef printf
46#endif
47
48#ifndef NO_HTTP_TRACE
49#ifndef HTTP_TRACE
50#define HTTP_TRACE
51#endif
52#endif
53
54#define HttpTrace_doRequestMask 0x01
55#define HttpTrace_doRequestHeadersMask 0x02
56#define HttpTrace_doResponseHeadersMask 0x04
57#define HttpTrace_doResponseBodyMask 0x08
58#define HttpTrace_doHttp11StateMask 0x10
59#define HttpTrace_doReqBufOverflowMask 0x20
60
61
62typedef void (*HttpTrace_Flush)(char* buf, int bufLen);
63
123typedef struct HttpTrace
124{
125#ifdef __cplusplus
163 static void setFLushCallback(HttpTrace_Flush fcb);
164
172 static void vprintf(int prio, const char* fmt, va_list argList);
173
179 static void printf(int prio, const char* fmt, ...);
180
186 static void write(int prio, const char* buf, int len = -1);
187
196 static int setPrio(int prio);
197
202 static BufPrint* getWriter();
203
207 static void releaseWriter(void);
208
219 static void setRequest(bool cmd);
220
224 static void setRequestHeaders(bool cmd);
225
229 static void setResponseHeaders(bool cmd);
230
235 static void setResponseBody(bool cmd);
236
262 static void setHttp11State(bool cmd);
263
273 static void setReqBufOverflow(bool cmd);
274
279 static int setBufSize(int size);
280
283 static void flush();
284
285 static bool isRequestSet();
286 static bool isRequestHeadersSet();
287 static bool isResponseHeadersSet();
288 static bool isResponseBodySet();
289 static bool isHttp11StateSet();
290
291 private:
295 inline HttpTrace() {}
296#endif
297 BufPrint print; /* As if inherited */
298 int prio;
299 U8 traceCmds;
300}HttpTrace;
301
302#ifdef __cplusplus
303extern "C" {
304#endif
305BA_API int HttpTrace_setPrio(int prio);
306BA_API void HttpTrace_setFLushCallback(HttpTrace_Flush fcb);
307BA_API HttpTrace_Flush HttpTrace_getFLushCallback(void);
308BA_API void HttpTrace_vprintf(int prio, const char* fmt, va_list argList);
309BA_API void HttpTrace_printf(int prio, const char* fmt, ...);
310BA_API void HttpTrace_write(int prio, const char* buf, int len);
311BA_API void HttpTrace_flush(void);
312
313BA_API void HttpTrace_setRequest(BaBool cmd);
314BA_API void HttpTrace_setRequestHeaders(BaBool cmd);
315BA_API void HttpTrace_setResponseHeaders(BaBool cmd);
316BA_API void HttpTrace_setResponseBody(BaBool cmd);
317BA_API void HttpTrace_setHttp11State(BaBool cmd);
318BA_API void HttpTrace_setReqBufOverflow(BaBool cmd);
319BA_API int HttpTrace_setBufSize(int size);
320BA_API void HttpTrace_close(void);
321
322/* Internal funtion. Used by macros below */
323BA_API U8 HttpTrace_getTraceCmds(void);
324#define HttpTrace_isRequestSet() \
325 (HttpTrace_getTraceCmds() & HttpTrace_doRequestMask ? TRUE : FALSE)
326#define HttpTrace_isRequestHeadersSet() \
327 (HttpTrace_getTraceCmds() & HttpTrace_doRequestHeadersMask ? TRUE : FALSE)
328#define HttpTrace_isResponseHeadersSet() \
329 (HttpTrace_getTraceCmds() & HttpTrace_doResponseHeadersMask ? TRUE : FALSE)
330#define HttpTrace_isResponseBodySet() \
331 (HttpTrace_getTraceCmds() & HttpTrace_doResponseBodyMask ? TRUE : FALSE)
332#define HttpTrace_isHttp11StateSet() \
333 (HttpTrace_getTraceCmds() & HttpTrace_doHttp11StateMask ? TRUE : FALSE)
334
335/* Private Barracuda functions */
336
337#ifdef HTTP_TRACE
338#define TRPR(data) HttpTrace_TRPR data
339BA_API void HttpTrace_TRPR(const char* fmt, ...);
340#else
341#define TRPR(data)
342#endif
343BA_API HttpTrace* HttpTrace_get(void);
344#define HttpTrace_doRequest() \
345 (HttpTrace_get()->traceCmds & HttpTrace_doRequestMask)
346#define HttpTrace_doRequestHeaders() \
347 (HttpTrace_get()->traceCmds & HttpTrace_doRequestHeadersMask)
348#define HttpTrace_doResponseHeaders() \
349 (HttpTrace_get()->traceCmds & HttpTrace_doResponseHeadersMask)
350#define HttpTrace_doResponseBody() \
351 (HttpTrace_get()->traceCmds & HttpTrace_doResponseBodyMask)
352#define HttpTrace_doHttp11State() \
353 (HttpTrace_get()->traceCmds & HttpTrace_doHttp11StateMask)
354#define HttpTrace_doReqBufOverflow() \
355 (HttpTrace_get()->traceCmds & HttpTrace_doReqBufOverflowMask)
356BA_API BufPrint* HttpTrace_getWriter(void);
357BA_API void HttpTrace_releaseWriter(void);
358#ifdef __cplusplus
359}
360inline int HttpTrace::setPrio(int prio) {
361 return HttpTrace_setPrio(prio);
362}
363inline void HttpTrace::setFLushCallback(HttpTrace_Flush fcb) {
364 HttpTrace_setFLushCallback(fcb); }
365inline void HttpTrace::vprintf(int prio, const char* fmt, va_list argList) {
366 HttpTrace_vprintf(prio, fmt, argList); }
367inline void HttpTrace::printf(int prio, const char* fmt, ...) {
368 va_list varg;
369 va_start(varg, fmt);
370 HttpTrace_vprintf(prio, fmt, varg);
371 va_end(varg);
372}
373inline void HttpTrace::write(int prio, const char* buf, int len) {
374 HttpTrace_write(prio, buf, len); }
375
377 return HttpTrace_getWriter(); }
378inline void HttpTrace::releaseWriter(void) {
379 HttpTrace_releaseWriter(); }
380inline void HttpTrace::setRequest(bool cmd) {
381 HttpTrace_setRequest(cmd); }
382inline void HttpTrace::setRequestHeaders(bool cmd) {
383 HttpTrace_setRequestHeaders(cmd); }
384inline void HttpTrace::setResponseHeaders(bool cmd) {
385 HttpTrace_setResponseHeaders(cmd); }
386inline void HttpTrace::setResponseBody(bool cmd) {
387 HttpTrace_setResponseBody(cmd); }
388inline void HttpTrace::setHttp11State(bool cmd) {
389 HttpTrace_setHttp11State(cmd); }
390inline void HttpTrace::setReqBufOverflow(bool cmd) {
391 HttpTrace_setReqBufOverflow(cmd); }
392inline int HttpTrace::setBufSize(int size) {
393 return HttpTrace_setBufSize(size); }
394inline void HttpTrace::flush() {
395 HttpTrace_flush();
396}
397inline bool HttpTrace::isRequestSet() {
398 return HttpTrace_isRequestSet() ? true : false;
399}
400inline bool HttpTrace::isRequestHeadersSet() {
401 return HttpTrace_isRequestHeadersSet() ? true : false;
402}
403inline bool HttpTrace::isResponseHeadersSet() {
404 return HttpTrace_isResponseHeadersSet() ? true : false;
405}
406inline bool HttpTrace::isResponseBodySet() {
407 return HttpTrace_isResponseBodySet() ? true : false;
408}
409inline bool HttpTrace::isHttp11StateSet() {
410 return HttpTrace_isHttp11StateSet() ? true : false;
411}
412#endif
413
414#ifdef __cplusplus
421{
423 _bufPrint = HttpTrace_getWriter();
424 }
426 release();
427 }
428
430 void release() {
431 if(_bufPrint) {_bufPrint=0; HttpTrace_releaseWriter(); }
432 }
433
435 void lock() {
436 if(!_bufPrint) {_bufPrint = HttpTrace_getWriter(); }
437 }
438
441 operator BufPrint*() { return _bufPrint; }
442
445 BufPrint* operator -> () { return _bufPrint; }
446 private:
447 BufPrint* _bufPrint;
448};
449#endif
450
451
452
453#endif
The BufPrint class, which implements an ANSI compatible printf method, is a base class used by severa...
Definition: BufPrint.h:122
HttpTraceWriteLock is a C++ class that makes it easier to lock the trace by using method HttpTrace::g...
Definition: HttpTrace.h:421
BufPrint * operator->()
Operator that makes it possible to do myLock->printf("hi");.
Definition: HttpTrace.h:445
void release()
Release the trace if not already released.
Definition: HttpTrace.h:430
void lock()
Lock the trace if not already locked.
Definition: HttpTrace.h:435
Trace the communication between a client and the server.
Definition: HttpTrace.h:124
static void printf(int prio, const char *fmt,...)
Write data to the trace buffer.
Definition: HttpTrace.h:367
static int setPrio(int prio)
Set the trace message priority filter.
Definition: HttpTrace.h:360
static void flush()
Force a flush on data in trace buffer; i.e., call the flush callback.
Definition: HttpTrace.h:394
static void releaseWriter(void)
Release the trace.
Definition: HttpTrace.h:378
static void setResponseHeaders(bool cmd)
If enabled, the web-server dumps the content of the response header to the trace buffer.
Definition: HttpTrace.h:384
static void setHttp11State(bool cmd)
If enabled, prints the status for each active client connection of the internal "HTTP 1....
Definition: HttpTrace.h:388
static BufPrint * getWriter()
Get and lock the trace BufPrint object.
Definition: HttpTrace.h:376
static void setFLushCallback(HttpTrace_Flush fcb)
The HTTP_TRACE compile time macro adds the trace library to the Barracuda library,...
Definition: HttpTrace.h:363
static int setBufSize(int size)
Set trace buffer.
Definition: HttpTrace.h:392
static void write(int prio, const char *buf, int len=-1)
Write data to the trace buffer.
Definition: HttpTrace.h:373
static void vprintf(int prio, const char *fmt, va_list argList)
Write data to the trace buffer.
Definition: HttpTrace.h:365
static void setResponseBody(bool cmd)
If enabled, the web-server dumps the content of the response body to the trace buffer.
Definition: HttpTrace.h:386
static void setRequest(bool cmd)
If enabled, the web-server prints the first line in the request header to the trace buffer.
Definition: HttpTrace.h:380
static void setRequestHeaders(bool cmd)
If enabled, the web-server dumps the content of the request header to the trace buffer.
Definition: HttpTrace.h:382
static void setReqBufOverflow(bool cmd)
Prints "ReqBufOverflow" if enabled and the HttpRequest buffer overflows.
Definition: HttpTrace.h:390