Barracuda Application Server C/C++ Reference
Native APIs, integration guides, and platform interfaces
BaServerLib.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: BaServerLib.h 6056 2026-09-20 05:09:33Z wini $
15 *
16 * COPYRIGHT: Real Time Logic LLC, 2002 - 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
39
42#ifndef __httpServerLib_h
43#define __httpServerLib_h
44
45#include <TargConfig.h>
46#include <AllocatorIntf.h>
47#include <ctype.h>
48#include <stddef.h>
49
50
51#ifdef __cplusplus
52extern "C" {
53#endif
54
55/* Internal HTTP framing helper. Parse [ptr,end), excluding CRLF.
56 Returns the chunk length, or -1 for invalid syntax/overflow. */
57BA_API SBaFileSize httpParseChunkSize(const U8* ptr, const U8* end);
58
59/* Internal HTTP-date parser. Returns TRUE and sets *result on success, including
60 epoch zero; returns FALSE without changing *result for NULL/invalid input. */
61BA_API BaBool httpParseDate(const char* str, BaTime* result);
62
63
77#ifdef INL_baConvBin2Hex
78
79extern const char baBin2HexTable[]; /* =
80 {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
81 'a', 'b', 'c', 'd', 'e', 'f'}; */
82
83#define baConvBin2Hex(hexOutData, binIn) \
84 hexOutData[0] = baBin2HexTable[((U8)binIn) >> 4], \
85 hexOutData[1] = baBin2HexTable[((U8)binIn) & 0x0f]
86
87#else
88
92BA_API void baConvBin2Hex(void* hexOutData, U8 binIn);
93
94#endif
95
96
100BA_API U8 baConvHex2Bin( U8 c );
106BA_API void baConvU32ToHex(void* to, U32 from);
112BA_API U32 baConvHexToU32(const void* from);
113
114
119BA_API char* baStrdup(const char* str);
120
132BA_API const void* baBSearch(const void* key, const void* base, int num,
133 int size, int (*cmp)(const void*,const void*));
134
141BA_API int baStrCaseCmp(const char *a, const char *b);
142
149BA_API int baStrnCaseCmp(const char *a, const char *b, size_t len);
150
160const char* baGetToken(const char** str, const char* set);
161
172BA_API BaTime baParseDate(const char* str);
173
174
185BA_API int baB64Decode(
186 unsigned char* outStr,int outStrSize,const char* b64EncStr,
187 BaBool* overflow);
188
195BA_API int baElideDotDot(char* str);
196
203BA_API void baXmlUnescape(char* f);
204
205#if defined(_WIN32) && !defined(NDEBUG)
206/* Bug in VC++ */
207#undef bIsspace
208#define bIsspace(c) (c == ' ' || c == '\f' || c == '\n' || c == '\r' ||\
209 c == '\t' || c == '\v')
210#endif
211
212#define httpEatWhiteSpace(ptr) while(bIsspace((U8)*ptr)) (ptr)++
213#define httpEatNonWhiteSpace(ptr) while(!bIsspace((U8)*ptr)) (ptr)++
214#define httpEatCharacters(ptr, delimiter) \
215 while(*ptr && *ptr != delimiter) (ptr)++
216
222struct BaTm
223{
240
242 int nsec;
245};
246
251BA_API U8 baDaysInMonth(U16 y, U16 m);
252
259BA_API int baTime2tm(struct BaTm *tmP, BaTime t);
269BA_API int baTime2tmEx(const BaTimeEx* tex, const BaBool local, struct BaTm* tm);
270
271
280BA_API BaTime baTm2Time(struct BaTm* tmP);
292BA_API int baTm2TimeEx(struct BaTm* tm, BaBool local, BaTimeEx* tex);
293
305BA_API int baISO8601ToTime(const char *str, size_t len, BaTimeEx *tex);
306
307
317BA_API int baTime2ISO8601(const BaTimeEx* tex, char* str, size_t len);
318
319 /* end of UtilityFunctions */
321
322
323#ifdef __cplusplus
324}
325#endif
326
327
334#ifdef __DOXYGEN__
335/* For documentation only */
336
340void* baMalloc(size_t size);
341
349void* baRealloc(void* p, size_t size);
350
351
355void baFree(void* p);
356
357#endif /* __DOXYGEN__ */
358
359 /* end of DynamicMemory */
361
362#endif
void * baRealloc(void *p, size_t size)
Resize storage using the target's configured allocator.
void * baMalloc(size_t size)
Allocate uninitialized storage using the target's configured allocator.
void baFree(void *p)
Release storage using the target's configured allocator.
BA_API U8 baConvHex2Bin(U8 c)
Decode one hexadecimal digit.
uint16_t U16
Unsigned 16-bit integer.
Definition: GenPrimT.h:91
BA_API void baConvU32ToHex(void *to, U32 from)
Encode four bytes as eight lowercase hexadecimal characters.
BA_API int baTm2TimeEx(struct BaTm *tm, BaBool local, BaTimeEx *tex)
Convert calendar fields and an optional timezone offset to a timestamp.
const char * baGetToken(const char **str, const char *set)
Locate a token separated by characters in set.
S32 SBaFileSize
Signed file-size value in bytes; 32 bits without BA_FILESIZE64.
Definition: GenPrimT.h:138
BA_API int baElideDotDot(char *str)
Normalize a slash-separated path in place.
S64 BaTime
An arithmetic type representing calendar time with epoch of 1970-01-01 00:00:00 UTC,...
Definition: GenPrimT.h:103
BA_API int baTime2tmEx(const BaTimeEx *tex, const BaBool local, struct BaTm *tm)
Convert a timestamp to UTC or offset-adjusted calendar fields.
BA_API void baConvBin2Hex(void *hexOutData, U8 binIn)
Encode one byte as two lowercase hexadecimal characters.
BA_API BaTime baParseDate(const char *str)
Parse an HTTP date string as UTC.
uint32_t U32
Unsigned 32-bit integer.
Definition: GenPrimT.h:93
BA_API char * baStrdup(const char *str)
Allocate a NUL-terminated copy of a string using baMalloc.
BA_API U32 baConvHexToU32(const void *from)
Decode eight hexadecimal characters into a U32.
BA_API int baISO8601ToTime(const char *str, size_t len, BaTimeEx *tex)
Parse an ISO 8601 calendar timestamp with an explicit timezone.
BA_API BaTime baTm2Time(struct BaTm *tmP)
Convert calendar fields to UTC epoch seconds.
uint8_t U8
Unsigned 8-bit integer.
Definition: GenPrimT.h:89
BA_API int baStrCaseCmp(const char *a, const char *b)
Compare two NUL-terminated strings using bTolower for case folding.
BA_API int baB64Decode(unsigned char *outStr, int outStrSize, const char *b64EncStr, BaBool *overflow)
Decode base64 or base64url into a caller buffer.
BA_API void baXmlUnescape(char *f)
Decode selected XML entity spellings in place.
BA_API const void * baBSearch(const void *key, const void *base, int num, int size, int(*cmp)(const void *, const void *))
Find a key in a sorted array without modifying it.
BA_API U8 baDaysInMonth(U16 y, U16 m)
Return the number of days in a Gregorian calendar month.
BA_API int baTime2ISO8601(const BaTimeEx *tex, char *str, size_t len)
Format a timestamp as ISO 8601 using its timezone offset.
BA_API int baStrnCaseCmp(const char *a, const char *b, size_t len)
Compare at most len bytes, using bTolower for case folding.
U8 BaBool
Boolean stored in an unsigned byte; FALSE is zero and TRUE is one.
Definition: GenPrimT.h:118
BA_API int baTime2tm(struct BaTm *tmP, BaTime t)
Convert UTC epoch seconds to calendar fields.
UTC timestamp with a fractional second and an explicit timezone offset.
Definition: GenPrimT.h:108
Represents the components of calendar time.
Definition: BaServerLib.h:223
int tm_yday
Days since January 1 [0,365]; output of the time-to-calendar functions.
Definition: BaServerLib.h:239
int tm_wday
days since Sunday [0,6]
Definition: BaServerLib.h:237
int tm_mon
months since January [0,11]
Definition: BaServerLib.h:233
int tm_sec
seconds after the minute [0,59]
Definition: BaServerLib.h:225
int tm_year
Years since 0000 (baTime2tmEx) or since 1900 (baTime2tm)
Definition: BaServerLib.h:235
int offset
Minutes east of UTC [-1439,1439]; negative means west.
Definition: BaServerLib.h:244
int tm_hour
hours since midnight [0,23]
Definition: BaServerLib.h:229
int tm_min
minutes after the hour [0,59]
Definition: BaServerLib.h:227
int tm_mday
day of the month [1,31], valid for the selected month
Definition: BaServerLib.h:231
int nsec
Fractional second in nanoseconds [0,999999999].
Definition: BaServerLib.h:242