All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Functions
print.c File Reference
#include <freeradius-devel/libradius.h>
#include <ctype.h>
+ Include dependency graph for print.c:

Go to the source code of this file.

Functions

char * fr_asprint (TALLOC_CTX *ctx, char const *in, ssize_t inlen, char quote)
 Escape string that may contain binary data, and write it to a new buffer. More...
 
size_t fr_snprint (char *out, size_t outlen, char const *in, ssize_t inlen, char quote)
 Escape any non printable or non-UTF8 characters in the input string. More...
 
size_t fr_snprint_len (char const *in, ssize_t inlen, char quote)
 Find the length of the buffer required to fully escape a string with fr_prints. More...
 
int fr_utf8_char (uint8_t const *str, ssize_t inlen)
 Checks for utf-8, taken from http://www.w3.org/International/questions/qa-forms-utf-8. More...
 
char const * fr_utf8_strchr (int *chr_len, char const *str, char const *chr)
 Return a pointer to the first UTF8 char in a string. More...
 

Function Documentation

char* fr_asprint ( TALLOC_CTX *  ctx,
char const *  in,
ssize_t  inlen,
char  quote 
)

Escape string that may contain binary data, and write it to a new buffer.

This is useful in situations where we expect printable strings as input, but under some conditions may get binary data. A good example is libldap and the arrays of struct berval ldap_get_values_len returns.

Parameters
[in]ctxTo allocate new buffer in.
[in]inString to escape.
[in]inlenLength of string. Should be >= 0 if the data may contain embedded \0s. Must be >= 0 if data may not be \0 terminated. If < 0 inlen will be calculated using strlen.
[in]quotethe quotation character.
Returns
new buffer holding the escaped string.

Definition at line 390 of file print.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t fr_snprint ( char *  out,
size_t  outlen,
char const *  in,
ssize_t  inlen,
char  quote 
)

Escape any non printable or non-UTF8 characters in the input string.

Note
Return value should be checked with is_truncated
Will always \0 terminate unless outlen == 0.
Parameters
[in]instring to escape.
[in]inlenlength of string to escape (lets us deal with embedded NULs)
[out]outwhere to write the escaped string.
[out]outlenthe length of the buffer pointed to by out.
[in]quotethe quotation character
Returns
  • The number of bytes written to the out buffer.
  • A number >= outlen if truncation has occurred.

Definition at line 179 of file print.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t fr_snprint_len ( char const *  in,
ssize_t  inlen,
char  quote 
)

Find the length of the buffer required to fully escape a string with fr_prints.

Were assuming here that's it's cheaper to figure out the length and do one alloc than repeatedly expand the buffer when we find extra chars which need to be added.

Parameters
instring to calculate the escaped length for.
inlenlength of the input string, if < 0 strlen will be used to check the length.
[in]quotethe quotation character.
Returns
the size of buffer required to hold the escaped string including the NUL byte.

Definition at line 371 of file print.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int fr_utf8_char ( uint8_t const *  str,
ssize_t  inlen 
)

Checks for utf-8, taken from http://www.w3.org/International/questions/qa-forms-utf-8.

Parameters
strinput string.
inlenlength of input string. May be -1 if str is \0 terminated.

Definition at line 34 of file print.c.

+ Here is the caller graph for this function:

char const* fr_utf8_strchr ( int *  chr_len,
char const *  str,
char const *  chr 
)

Return a pointer to the first UTF8 char in a string.

Parameters
[out]chr_lenWhere to write the length of the multibyte char passed in chr (may be NULL).
[in]strHaystack.
[in]chrMultibyte needle.
Returns
  • Position of chr in str.
  • NULL if not found.

Definition at line 140 of file print.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function: