Barracuda Application Server C/C++ Reference
NO
BufPrint.h
1/*
2 * ____ _________ __ _
3 * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____
4 * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/
5 * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__
6 * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/
7 * /____/
8 *
9 * Barracuda Embedded Web-Server
10 ****************************************************************************
11 * HEADER
12 *
13 * $Id: BufPrint.h 5839 2026-07-29 13:27:22Z wini $
14 *
15 * COPYRIGHT: Real Time Logic LLC, 2008 - 2026
16 *
17 * This software is copyrighted by and is the sole property of Real
18 * Time Logic LLC. All rights, title, ownership, or other interests in
19 * the software remain the property of Real Time Logic LLC. This
20 * software may only be used in accordance with the terms and
21 * conditions stipulated in the corresponding license agreement under
22 * which the software has been supplied. Any unauthorized use,
23 * duplication, transmission, distribution, or disclosure of this
24 * software is expressly forbidden.
25 *
26 * This Copyright notice may not be removed or modified without prior
27 * written consent of Real Time Logic LLC.
28 *
29 * Real Time Logic LLC. reserves the right to modify this software
30 * without notice.
31 *
32 * http://www.realtimelogic.com
33 ****************************************************************************
34 *
35 */
36
37#ifndef __BufPrint_h
38#define __BufPrint_h
39
40#include <TargConfig.h>
41
42#ifndef BA_API
43#define BA_API
44#endif
45
46#include <stdarg.h>
47#include <string.h>
48
49struct BufPrint;
50
51#ifdef __cplusplus
52extern "C" {
53#endif
54
62BA_API int basprintf(char* buf, const char* fmt, ...);
63
73BA_API int basnprintf(char* buf, int len, const char* fmt, ...);
74
75#ifdef __cplusplus
76#undef printf
77}
78#endif
79
110typedef int (*BufPrint_Flush)(struct BufPrint* o, int sizeRequired);
111
121typedef struct BufPrint
122{
123#ifdef __cplusplus
124
135 BufPrint(void* userData=0, BufPrint_Flush flush=0);
136
149 BufPrint(char* buf,int size,void* userData=0,BufPrint_Flush flush=0);
150
153 void* getUserData();
154
163 int vprintf(const char* fmt, va_list argList);
164
177 int printf(const char* fmt, ...);
178
180 int baputc(int c);
181
186 int write(const void* data, int len);
187
192 int write(const char* buf);
193
194
199 void setBuf(char* buf, int size);
200
201
206 char* getBuf();
207
209 U32 getBufSize();
210
211
213 void erase();
214
216 int flush();
217
223 int b64Encode(const void* data, S32 slen);
224
231 int b64urlEncode(const void* source, S32 slen, bool padding);
232
246 int jsonString(const char* str, size_t len);
247#endif
248 BufPrint_Flush flushCB;
249 void *userData;
250 char* buf;
251 int cursor;
252 int bufSize;
254
255#define BufPrint_putcMacro(o, c) do { \
256 if((o)->cursor == (o)->bufSize) \
257 { \
258 if((o)->flushCB(o, 1)) \
259 return -1; \
260 } \
261 (o)->buf[(o)->cursor++] = c; \
262} while(0)
263
264#ifdef __cplusplus
265extern "C" {
266#endif
267#define BufPrint_getUserData(o) (o)->userData
268#define BufPrint_erase(o) (o)->cursor=0
269#define BufPrint_getBuf(o) (o)->buf
270#define BufPrint_setBuf(o, b, size) (o)->buf=b,(o)->bufSize=size,(o)->cursor=0
271#define BufPrint_getBufSize(o) (o)->cursor
272BA_API void BufPrint_constructor(
273 BufPrint* o,void* userData,BufPrint_Flush flush);
274BA_API void BufPrint_constructor2(
275 BufPrint* o, char* buf,int size,void* userData,BufPrint_Flush flush);
276#define BufPrint_destructor(o)
277BA_API int BufPrint_vprintf(BufPrint* o, const char* fmt, va_list argList);
278BA_API int BufPrint_printf(BufPrint* o, const char* fmt, ...);
279BA_API int BufPrint_write(BufPrint* o, const void* data, int len);
280BA_API int BufPrint_putc(BufPrint* o, int c);
281BA_API int BufPrint_flush(BufPrint* o);
282#define BufPrint_write2(o, data) BufPrint_write(o, data, -1)
283BA_API int BufPrint_b64Encode(BufPrint* o, const void* source, S32 slen);
284BA_API int BufPrint_b64urlEncode(
285 BufPrint* o, const void* source, S32 slen, BaBool padding);
286
287BA_API int BufPrint_jsonString(BufPrint* o, const char* str, size_t len);
288#ifdef __cplusplus
289}
290inline void* BufPrint::getUserData() {
291 return BufPrint_getUserData(this);
292}
293inline BufPrint::BufPrint(void* userData, BufPrint_Flush flush) {
294 BufPrint_constructor(this, userData,flush); }
296 char* buf,int size,void* userData,BufPrint_Flush flush) {
297 BufPrint_constructor2(this,buf,size,userData,flush); }
298inline int BufPrint::vprintf(const char* fmt, va_list argList) {
299 return BufPrint_vprintf(this, fmt, argList); }
300inline int BufPrint::printf(const char* fmt, ...) {
301 int retv; va_list varg;
302 va_start(varg, fmt);
303 retv = BufPrint_vprintf(this, fmt, varg);
304 va_end(varg);
305 return retv;
306}
307inline char* BufPrint::getBuf() {
308 return BufPrint_getBuf(this); }
309inline void BufPrint::setBuf(char* buffer, int size) {
310 BufPrint_setBuf(this, buffer, size); }
312 return BufPrint_getBufSize(this); }
313inline void BufPrint::erase() {
314 BufPrint_erase(this); }
315inline int BufPrint::baputc(int c) {
316 return BufPrint_putc(this, c); }
317inline int BufPrint::write(const void* data, int len) {
318 return BufPrint_write(this, data, len); }
319inline int BufPrint::write(const char* data) {
320 return BufPrint_write2(this, data); }
321inline int BufPrint::flush() {
322 return BufPrint_flush(this);
323}
324inline int BufPrint::b64Encode(const void* source, S32 slen){
325 return BufPrint_b64Encode(this, source, slen);
326}
327inline int BufPrint::b64urlEncode(const void* source, S32 slen, bool padding){
328 return BufPrint_b64urlEncode(this, source, slen, padding?TRUE:FALSE);
329}
330inline int BufPrint::jsonString(const char* str, size_t len){
331 return BufPrint_jsonString(this, str, len);
332}
333#endif
334 /* end of BufPrint */
336
337
338#endif
void erase()
resets the cursor, thus erasing the data in the buffer
Definition: BufPrint.h:313
U32 getBufSize()
Returns current size of internal formatted data.
Definition: BufPrint.h:311
void * getUserData()
Returns the user data pointer set in the constructor.
Definition: BufPrint.h:290
char * getBuf()
Returns a pointer to the internal buffer.
Definition: BufPrint.h:307
BufPrint(void *userData=0, BufPrint_Flush flush=0)
BufPrint constructor.
Definition: BufPrint.h:293
int jsonString(const char *str, size_t len)
Print and escape a string such that a browser can run the JavaScript 'eval' function and produce a st...
Definition: BufPrint.h:330
int baputc(int c)
print character (wrapper for BufPrint_putc)
Definition: BufPrint.h:315
int write(const void *data, int len)
Write data to the buffer.
Definition: BufPrint.h:317
int vprintf(const char *fmt, va_list argList)
The printf function's format is identical to the standard ANSI vprintf function.
Definition: BufPrint.h:298
int flush()
Flush buffer.
Definition: BufPrint.h:321
int b64urlEncode(const void *source, S32 slen, bool padding)
Encode binary data as Base64url.
Definition: BufPrint.h:327
int(* BufPrint_Flush)(struct BufPrint *o, int sizeRequired)
BufPrint flush callback function.
Definition: BufPrint.h:110
int printf(const char *fmt,...)
The printf function's format is identical to the standard ANSI printf function, but with the followin...
Definition: BufPrint.h:300
struct BufPrint BufPrint
The BufPrint class, which implements an ANSI compatible printf method, is a base class used by severa...
void setBuf(char *buf, int size)
Set the buffer used by BufPrint.
Definition: BufPrint.h:309
int b64Encode(const void *data, S32 slen)
Encode binary data as Base64.
Definition: BufPrint.h:324
The BufPrint class, which implements an ANSI compatible printf method, is a base class used by severa...
Definition: BufPrint.h:122