libonion
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Functions
Codecs. Some basic web codecs support: base64, url encoding...

Functions

char * onion_base64_decode (const char *orig, int *length)
 Decodes a base64 into a new char* (must be freed later).At length, if not NULL we set the final length of the decoded base.
char * onion_base64_encode (const char *orig, int length)
 Encodes a byte array to a base64 into a new char* (must be freed later).
void onion_unquote_inplace (char *str)
 Performs unquote inplace.It can be inplace as char position is always at least in the same on the destination than in the origin.
char * onion_quote_new (const char *str)
 Performs URL quoting, memory is allocated and has to be freed.As size neccesary is difficult to measure, it first check how many should be encoded, and on a second round it encodes it.
int onion_quote (const char *str, char *res, int maxlength)
char * onion_c_quote_new (const char *str)
 Performs C quotation: changes " for \". Usefull when sending data to be interpreted as JSON.
char * onion_c_quote (const char *str, char *ret, int l)
void onion_sha1 (const char *data, int length, char *result)
 Calculates the SHA1 checksum of a given data.
char * onion_html_add_enc (char c, char *p)
int onion_html_encoding_size (char c)
char * onion_html_quote (const char *str)
 Calculates the HTML encoding of a given stringIf needs encoding returns a new string that should be deallocated, if not, returns NULL.
const char * onion_html_quote_dup (const char *str)
 Calculates as a freshly allocated string the HTML encoding of a given stringReturns a new string that should be freed, or else NULL when given a null argument.
void onion_json_quote_add (onion_block *block, const char *str)
 Generates JSON string encoding and adds it to an existing blockConverts from "\n" to "\\n".
ssize_t onion_json_unquote_add (onion_block *block, const char *str)
 Adds to the block the quoted string; converts "\\n" to "\n"If the str starts with ", expects a " to finish, else \0.

Detailed Description

Function Documentation

char* onion_base64_decode ( const char *  orig,
int *  length 
)

Decodes a base64 into a new char* (must be freed later).At length, if not NULL we set the final length of the decoded base.

Decodes a base64 into a new char* (must be freed later).

The buffer might be sligthly bigger (up to 3 bytes), but length is always right.

References onion_low_scalar_malloc().

Referenced by onion_handler_auth_pam_handler().

char* onion_base64_encode ( const char *  orig,
int  length 
)

Encodes a byte array to a base64 into a new char* (must be freed later).

that chars +
one per every 57 +
\0 at end, and maybe two '='

References onion_low_malloc().

Referenced by onion_websocket_t::onion_websocket_new().

char* onion_c_quote ( const char *  str,
char *  ret,
int  l 
)

Performs the C quotation on the ret str. Max length is l.

Referenced by onion_c_quote_new().

char* onion_c_quote_new ( const char *  str)

Performs C quotation: changes " for \". Usefull when sending data to be interpreted as JSON.

Performs C quotation: changes " for \". Usefull when sending data to be interpreted as JSON. Returned data must be freed.

References onion_c_quote(), and onion_low_scalar_malloc().

char* onion_html_add_enc ( char  c,
char *  p 
)

At p inserts the proper encoding of c, and returns the new string cursor (end of inserted symbols).

Referenced by onion_html_quote().

int onion_html_encoding_size ( char  c)

Returns the encoding for minimal set

Referenced by onion_html_quote().

char* onion_html_quote ( const char *  str)

Calculates the HTML encoding of a given stringIf needs encoding returns a new string that should be deallocated, if not, returns NULL.

Calculates the HTML encoding of a string. Returned value must be freed. If no encoding needed, returns NULL.

first calculate size

References onion_html_add_enc(), onion_html_encoding_size(), and onion_low_scalar_malloc().

Referenced by onion_html_quote_dup(), and onion_response_write_html_safe().

const char* onion_html_quote_dup ( const char *  str)

Calculates as a freshly allocated string the HTML encoding of a given stringReturns a new string that should be freed, or else NULL when given a null argument.

Always return a freshly allocated string, to be later freed.

References onion_html_quote(), and onion_low_strdup().

void onion_json_quote_add ( onion_block block,
const char *  str 
)

Generates JSON string encoding and adds it to an existing blockConverts from "\n" to "\\n".

Generates JSON string encoding and adds it to an existing block.

References onion_block_t::onion_block_add_char(), onion_block_t::onion_block_add_data(), onion_block_t::onion_block_min_maxsize(), and onion_block_t::onion_block_size().

ssize_t onion_json_unquote_add ( onion_block block,
const char *  str 
)

Adds to the block the quoted string; converts "\\n" to "\n"If the str starts with ", expects a " to finish, else \0.

Adds to the block the quoted string; converts "\\n" to "\n".

Returns the byte count read from str, or -1 on error.

On error block will be modified, so if need safe manipulation with error management, use a temporary block before calling here.

References onion_block_t::onion_block_add_char(), and ONION_DEBUG.

int onion_quote ( const char *  str,
char *  res,
int  maxlength 
)

Performs URL quoting, uses auxiliary res, with maxlength size. If more, do up to where I can, and cut it with \0.

Referenced by onion_quote_new().

char* onion_quote_new ( const char *  str)

Performs URL quoting, memory is allocated and has to be freed.As size neccesary is difficult to measure, it first check how many should be encoded, and on a second round it encodes it.

Performs URL quoting, memory is allocated and has to be freed.

References onion_low_scalar_malloc(), and onion_quote().

void onion_sha1 ( const char *  data,
int  length,
char *  result 
)

Calculates the SHA1 checksum of a given data.

Calculates the sha1 checksum.

References ONION_ERROR.

Referenced by onion_websocket_t::onion_websocket_new().

void onion_unquote_inplace ( char *  str)

Performs unquote inplace.It can be inplace as char position is always at least in the same on the destination than in the origin.

Performs URL unquoting.