Barracuda Application Server C/C++ Reference
NO
printf compatible function

Detailed Description

See also
Barracuda Introduction

Classes

struct  BufPrint
 The BufPrint class, which implements an ANSI compatible printf method, is a base class used by several other classes. More...
 

Typedefs

typedef int(* BufPrint_Flush) (struct BufPrint *o, int sizeRequired)
 BufPrint flush callback function. More...
 
typedef struct BufPrint BufPrint
 The BufPrint class, which implements an ANSI compatible printf method, is a base class used by several other classes. More...
 

Functions

void * BufPrint::getUserData ()
 Returns the user data pointer set in the constructor.
 
 BufPrint::BufPrint (void *userData=0, BufPrint_Flush flush=0)
 BufPrint constructor. More...
 
 BufPrint::BufPrint (char *buf, int size, void *userData=0, BufPrint_Flush flush=0)
 BufPrint constructor. More...
 
int BufPrint::vprintf (const char *fmt, va_list argList)
 The printf function's format is identical to the standard ANSI vprintf function. More...
 
int BufPrint::printf (const char *fmt,...)
 The printf function's format is identical to the standard ANSI printf function, but with the following extensions: More...
 
char * BufPrint::getBuf ()
 Returns a pointer to the internal buffer. More...
 
void BufPrint::setBuf (char *buf, int size)
 Set the buffer used by BufPrint. More...
 
U32 BufPrint::getBufSize ()
 Returns current size of internal formatted data.
 
void BufPrint::erase ()
 resets the cursor, thus erasing the data in the buffer
 
int BufPrint::baputc (int c)
 print character (wrapper for BufPrint_putc)
 
int BufPrint::write (const void *data, int len)
 Write data to the buffer. More...
 
int BufPrint::write (const char *buf)
 Used for sending a zero terminated string to the client. More...
 
int BufPrint::flush ()
 Flush buffer.
 
int BufPrint::b64Encode (const void *data, S32 slen)
 Encode binary data as Base64. More...
 
int BufPrint::b64urlEncode (const void *source, S32 slen, bool padding)
 Encode binary data as Base64url. More...
 
int BufPrint::jsonString (const char *str)
 Print and escape a string such that a browser can run the JavaScript 'eval' function and produce a string identical to the string the 'str' argument points to. More...
 

Typedef Documentation

◆ BufPrint

typedef struct BufPrint BufPrint

The BufPrint class, which implements an ANSI compatible printf method, is a base class used by several other classes.

This class does not allocate memory for the buffer. Thus, any class using BufPrint must provide a buffer BufPrint can use. The output from printf is formatted in the buffer passed into the constructor. BufPrint calls the callback function BufPrint_Flush when the buffer is full. See BufPrint_Flush for additional details.

◆ BufPrint_Flush

typedef int(* BufPrint_Flush) (struct BufPrint *o, int sizeRequired)

BufPrint flush callback function.

A BufPrint instance calls the flush callback function when the buffer is full or when BufPrint::flush is called. The callback can either extend the buffer or flush and reset the buffer.

The following default callback is set if no callback is installed when calling the BufPrint constructor:

BufPrint_defaultFlush(struct BufPrint* bp, int sizeRequired)
{
bp->cursor=0; // Reset
baAssert(sizeRequired == 0); // Program error in code calling BufPrint_xxx
return sizeRequired ? -1 : 0;
}
Parameters
othe object. BufPrint is typically upcasted to the derived object.
sizeRequiredthe minimum size the buffer must expand. Note that sizeRequired will be zero when the callback is called via BufPrint::flush

Function Documentation

◆ b64Encode()

int BufPrint::b64Encode ( const void *  data,
S32  slen 
)

Encode binary data as Base64.

See also
baB64Decode
Parameters
databinary data or string to be encoded as B64.
slenthe data size.

◆ b64urlEncode()

int BufPrint::b64urlEncode ( const void *  source,
S32  slen,
bool  padding 
)

Encode binary data as Base64url.

See also
baB64Decode
Parameters
databinary data or string to be encoded as B64.
slenthe data size.
paddingadd padding characters.

◆ BufPrint() [1/2]

BufPrint::BufPrint ( char *  buf,
int  size,
void *  userData = 0,
BufPrint_Flush  flush = 0 
)

BufPrint constructor.

When using this constructor, make sure to also call setBuf(). C constructor name: BufPrint_constructor2

Parameters
bufthe buffer
sizethe buffer size
userDataan optional argument stored in the BufPrint object and accessible in the flush callback.
flusha pointer to the flush callback function. See BufPrint_Flush for details.
See also
setBuf(), getUserData()

◆ BufPrint() [2/2]

BufPrint::BufPrint ( void *  userData = 0,
BufPrint_Flush  flush = 0 
)

BufPrint constructor.

When using this constructor, make sure to also call setBuf(). C constructor name: BufPrint_constructor

Parameters
userDataan optional argument stored in the BufPrint object and accessible in the flush callback.
flusha pointer to the flush callback function. See BufPrint_Flush for details.
See also
setBuf(), getUserData()

◆ getBuf()

char * BufPrint::getBuf ( )

Returns a pointer to the internal buffer.

Please note that the buffer returned by this method is not zero terminated.

See also
BufPrint::getBufSize

◆ jsonString()

int BufPrint::jsonString ( const char *  str)

Print and escape a string such that a browser can run the JavaScript 'eval' function and produce a string identical to the string the 'str' argument points to.

The string must be ASCII or UTF8. A UTF8 string is converted to JavaScript Unicode i.e. to \uxxxx.

The function can, for example, be used if the server generates a JSON response or generates dynamic JavaScript in a CSP page.

See also
BufPrint::printf with format flag j

◆ printf()

int BufPrint::printf ( const char *  fmt,
  ... 
)

The printf function's format is identical to the standard ANSI printf function, but with the following extensions:

  • %lld is for printing S64 or a signed representation of a U64.
  • %llu is for printing an unsigned U64.
  • %j is similar to %s, but the string is encoded by using BufPrint::jsonString
Parameters
fmtSee vprintf in the C Standard Library for more information.

◆ setBuf()

void BufPrint::setBuf ( char *  buf,
int  size 
)

Set the buffer used by BufPrint.

Parameters
bufthe buffer
sizethe buffer size

◆ vprintf()

int BufPrint::vprintf ( const char *  fmt,
va_list  argList 
)

The printf function's format is identical to the standard ANSI vprintf function.

See BufPrint::printf for the format flags.

Parameters
fmtSee vprintf in the C Standard Library for more information.
argListSee vprintf in the C Standard Library for more information.

◆ write() [1/2]

int BufPrint::write ( const char *  buf)

Used for sending a zero terminated string to the client.

C method name is BufPrint_write2.

Parameters
bufa reference to the string.

◆ write() [2/2]

int BufPrint::write ( const void *  data,
int  len 
)

Write data to the buffer.

Parameters
datapointer to data.
lensize of data.
BufPrint
The BufPrint class, which implements an ANSI compatible printf method, is a base class used by severa...
Definition: BufPrint.h:122