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 5387 2023-02-20 22:50:13Z wini $
14 *
15 * COPYRIGHT: Real Time Logic LLC, 2008 - 2023
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
244 int jsonString(const char* str);
245#endif
246 BufPrint_Flush flushCB;
247 void *userData;
248 char* buf;
249 int cursor;
250 int bufSize;
252
253#define BufPrint_putcMacro(o, c) do { \
254 if((o)->cursor == (o)->bufSize) \
255 { \
256 if((o)->flushCB(o, 1)) \
257 return -1; \
258 } \
259 (o)->buf[(o)->cursor++] = c; \
260} while(0)
261
262#ifdef __cplusplus
263extern "C" {
264#endif
265#define BufPrint_getUserData(o) (o)->userData
266#define BufPrint_erase(o) (o)->cursor=0
267#define BufPrint_getBuf(o) (o)->buf
268#define BufPrint_setBuf(o, b, size) (o)->buf=b,(o)->bufSize=size,(o)->cursor=0
269#define BufPrint_getBufSize(o) (o)->cursor
270BA_API void BufPrint_constructor(
271 BufPrint* o,void* userData,BufPrint_Flush flush);
272BA_API void BufPrint_constructor2(
273 BufPrint* o, char* buf,int size,void* userData,BufPrint_Flush flush);
274#define BufPrint_destructor(o)
275BA_API int BufPrint_vprintf(BufPrint* o, const char* fmt, va_list argList);
276BA_API int BufPrint_printf(BufPrint* o, const char* fmt, ...);
277BA_API int BufPrint_write(BufPrint* o, const void* data, int len);
278BA_API int BufPrint_putc(BufPrint* o, int c);
279BA_API int BufPrint_flush(BufPrint* o);
280#define BufPrint_write2(o, data) BufPrint_write(o, data, -1)
281BA_API int BufPrint_b64Encode(BufPrint* o, const void* source, S32 slen);
282BA_API int BufPrint_b64urlEncode(
283 BufPrint* o, const void* source, S32 slen, BaBool padding);
284
285BA_API int BufPrint_jsonString(BufPrint* o, const char* str);
286#ifdef __cplusplus
287}
288inline void* BufPrint::getUserData() {
289 return BufPrint_getUserData(this);
290}
291inline BufPrint::BufPrint(void* userData, BufPrint_Flush flush) {
292 BufPrint_constructor(this, userData,flush); }
294 char* buf,int size,void* userData,BufPrint_Flush flush) {
295 BufPrint_constructor2(this,buf,size,userData,flush); }
296inline int BufPrint::vprintf(const char* fmt, va_list argList) {
297 return BufPrint_vprintf(this, fmt, argList); }
298inline int BufPrint::printf(const char* fmt, ...) {
299 int retv; va_list varg;
300 va_start(varg, fmt);
301 retv = BufPrint_vprintf(this, fmt, varg);
302 va_end(varg);
303 return retv;
304}
305inline char* BufPrint::getBuf() {
306 return BufPrint_getBuf(this); }
307inline void BufPrint::setBuf(char* buffer, int size) {
308 BufPrint_setBuf(this, buffer, size); }
310 return BufPrint_getBufSize(this); }
311inline void BufPrint::erase() {
312 BufPrint_erase(this); }
313inline int BufPrint::baputc(int c) {
314 return BufPrint_putc(this, c); }
315inline int BufPrint::write(const void* data, int len) {
316 return BufPrint_write(this, data, len); }
317inline int BufPrint::write(const char* data) {
318 return BufPrint_write2(this, data); }
319inline int BufPrint::flush() {
320 return BufPrint_flush(this);
321}
322inline int BufPrint::b64Encode(const void* source, S32 slen){
323 return BufPrint_b64Encode(this, source, slen);
324}
325inline int BufPrint::b64urlEncode(const void* source, S32 slen, bool padding){
326 return BufPrint_b64urlEncode(this, source, slen, padding?TRUE:FALSE);
327}
328inline int BufPrint::jsonString(const char* str){
329 return BufPrint_jsonString(this, str);
330}
331#endif
332 /* end of BufPrint */
334
335
336#endif
void erase()
resets the cursor, thus erasing the data in the buffer
Definition: BufPrint.h:311
U32 getBufSize()
Returns current size of internal formatted data.
Definition: BufPrint.h:309
void * getUserData()
Returns the user data pointer set in the constructor.
Definition: BufPrint.h:288
char * getBuf()
Returns a pointer to the internal buffer.
Definition: BufPrint.h:305
BufPrint(void *userData=0, BufPrint_Flush flush=0)
BufPrint constructor.
Definition: BufPrint.h:291
int baputc(int c)
print character (wrapper for BufPrint_putc)
Definition: BufPrint.h:313
int write(const void *data, int len)
Write data to the buffer.
Definition: BufPrint.h:315
int vprintf(const char *fmt, va_list argList)
The printf function's format is identical to the standard ANSI vprintf function.
Definition: BufPrint.h:296
int jsonString(const char *str)
Print and escape a string such that a browser can run the JavaScript 'eval' function and produce a st...
Definition: BufPrint.h:328
int flush()
Flush buffer.
Definition: BufPrint.h:319
int b64urlEncode(const void *source, S32 slen, bool padding)
Encode binary data as Base64url.
Definition: BufPrint.h:325
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:298
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:307
int b64Encode(const void *data, S32 slen)
Encode binary data as Base64.
Definition: BufPrint.h:322
The BufPrint class, which implements an ANSI compatible printf method, is a base class used by severa...
Definition: BufPrint.h:122