Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
STRINGS: replacement to char *strings with dynamic resizing and boundary checking

Data Structures

struct  N_STR
 A box including a string and his lenght. More...
 

Macros

#define free_nstr(__ptr)
 free a N_STR structure and set the pointer to NULL
 
#define local_strdup(__src_)
 Do tar(1) matching rules, which ignore a trailing slash?
 
#define n_remove_ending_cr(__nstr_var)
 Remove carriage return (backslash r) if there is one in the last position of the string.
 
#define n_replace_cr(__nstr_var, __replacement)
 Find and replace all occurences of carriage return (backslash r) in the string.
 
#define nstrcat(__nstr_dst, __nstr_src)
 Macro to quickly concatenate two N_STR.
 
#define nstrcat_bytes(__nstr_dst, __void_src)    nstrcat_bytes_ex(&(__nstr_dst), __void_src, strlen(__void_src))
 Macro to quickly concatenate a '\0' ended byte stream to a N_STR.
 
#define nstrprintf(__nstr_var, __format, ...)    nstrprintf_ex(&(__nstr_var), (__format), ##__VA_ARGS__)
 Macro to quickly allocate and sprintf to N_STR.
 
#define nstrprintf_cat(__nstr_var, __format, ...)    nstrprintf_cat_ex(&(__nstr_var), (__format), ##__VA_ARGS__)
 Macro to quickly allocate and sprintf and cat to a N_STR.
 
#define strprintf(__n_var, ...)
 Macro to quickly allocate and sprintf to a char.
 
#define WILDMAT_ABORT   -2
 Abort code to sped up pattern matching.
 
#define WILDMAT_NEGATE_CLASS   '^'
 What character marks an inverted character class?
 

Typedefs

typedef size_t NSTRBYTE
 N_STR base unit.
 

Functions

int _free_nstr (N_STR **ptr)
 free a N_STR and set the pointer to NULL
 
N_STRchar_to_nstr (const char *src)
 convert a char into a N_STR, shorter version
 
int char_to_nstr_ex (const char *from, NSTRBYTE nboct, N_STR **to)
 convert a char into a N_STR
 
N_STRchar_to_nstr_nocopy (char *src)
 convert a char into a N_STR without copying, shorter version
 
int char_to_nstr_nocopy_ex (char *from, NSTRBYTE nboct, N_STR **to)
 convert a char into a N_STR without copying
 
int empty_nstr (N_STR *nstr)
 reinitialize a nstr
 
N_STRfile_to_nstr (char *filename)
 load a whole file into a N_STR
 
int free_nstr_nolog (N_STR **ptr)
 free a N_STR and set to NULL without logging
 
void free_nstr_ptr (void *ptr)
 free a N_STR without setting the pointer to NULL
 
void free_nstr_ptr_nolog (void *ptr)
 free a N_STR without logging or setting to NULL
 
int free_split_result (char ***tab)
 free a char **tab and set it to NULL
 
char * join (char **splitresult, const char *delim)
 join a split result into a string
 
N_STRn_str_template_expand (const char *tmpl, struct HASH_TABLE *vars)
 Expand double-brace tokens in a template using a hash table.
 
N_STRn_str_url_encode (const char *src)
 Percent-encode a string per RFC 3986 (unreserved chars kept).
 
N_STRnew_nstr (NSTRBYTE size)
 create a new string
 
char * nfgets (char *buffer, NSTRBYTE size, FILE *stream)
 N_STR wrapper around fgets.
 
int nstr_to_fd (N_STR *str, FILE *out, int lock)
 write a whole N_STR into an open file descriptor
 
int nstr_to_file (N_STR *n_str, char *filename)
 write a whole N_STR into a file
 
N_STRnstrcat_bytes_ex (N_STR **dest, void *src, NSTRBYTE size)
 wrapper to nstrcat_ex to concatenate void *data
 
N_STRnstrcat_ex (N_STR **dest, void *src, NSTRBYTE size, int resize_flag)
 concatenate data inside a N_STR
 
N_STRnstrdup (N_STR *msg)
 make a copy of a N_STR
 
N_STRnstrprintf_cat_ex (N_STR **nstr_var, const char *format,...)
 concatenate printf on a N_STR
 
N_STRnstrprintf_ex (N_STR **nstr_var, const char *format,...)
 printf on a N_STR
 
int resize_nstr (N_STR *nstr, size_t size)
 resize a N_STR
 
int scan_dir (const char *dir, LIST *result, const int recurse)
 get a list of files in a directory
 
int scan_dir_ex (const char *dir, const char *pattern, LIST *result, const int recurse, const int mode)
 get a list of files in a directory, extended N_STR version
 
int skipu (const char *string, char toskip, NSTRBYTE *iterator, int inc)
 skip characters in string until string[iterator] == toskip
 
int skipw (const char *string, char toskip, NSTRBYTE *iterator, int inc)
 skip characters in string while string[iterator] == toskip
 
char ** split (const char *str, const char *delim, int empty)
 return an array of char pointers to the split sections
 
int split_count (char **split_result)
 count split elements
 
char * str_replace (const char *string, const char *substr, const char *replacement)
 return a new string with all occurrences of substr replaced
 
int str_sanitize (char *string, const char *mask, const char replacement)
 in-place substitution of a set of chars by a single one
 
int str_sanitize_ex (char *string, const NSTRBYTE string_len, const char *mask, const NSTRBYTE masklen, const char replacement)
 sanitize a string using a character mask
 
int str_to_int (const char *s, int *i, const int base)
 string to integer, shorter version
 
int str_to_int_ex (const char *s, NSTRBYTE start, NSTRBYTE end, int *i, const int base)
 string to integer, with error checking
 
int str_to_int_nolog (const char *s, NSTRBYTE start, NSTRBYTE end, int *i, const int base, N_STR **infos)
 string to integer, with error checking and no logging
 
int str_to_long (const char *s, long int *i, const int base)
 string to long integer, shorter version
 
int str_to_long_ex (const char *s, NSTRBYTE start, NSTRBYTE end, long int *i, const int base)
 string to long integer, with error checking
 
int str_to_long_long (const char *s, long long int *i, const int base)
 string to long long integer, shorter version
 
int str_to_long_long_ex (const char *s, NSTRBYTE start, NSTRBYTE end, long long int *i, const int base)
 string to long long integer, with error checking
 
int strcpy_u (const char *from, char *to, NSTRBYTE to_size, char delim, NSTRBYTE *it)
 copy from string to dest until from[iterator] == delim
 
int strlo (const char *string, char *dest)
 lower case a string
 
int strup (const char *string, char *dest)
 upper case a string
 
char * trim (const char *s)
 trim and put a \0 at the end, return new char *
 
char * trim_nocopy (char *s)
 trim and put a \0 at the end, return new begin pointer
 
int wildmat (register const char *text, register const char *p)
 pattern matching
 
int wildmatcase (register const char *text, register const char *p)
 pattern matching, case insensitive
 
int write_and_fit (char **dest, NSTRBYTE *size, NSTRBYTE *written, const char *src)
 write and fit into the char array
 
int write_and_fit_ex (char **dest, NSTRBYTE *size, NSTRBYTE *written, const char *src, NSTRBYTE src_size, NSTRBYTE additional_padding)
 write and fit bytes into a dynamically sized buffer
 

Detailed Description


Data Structure Documentation

◆ N_STR

struct N_STR
+ Collaboration diagram for N_STR:
Data Fields
char * data the string
size_t length total allocation (in bytes) of the data buffer, padding included
size_t written number of meaningful bytes in data, excluding the null terminator; the size including the null terminator is written + 1.

Macro Definition Documentation

◆ free_nstr

#define free_nstr (   __ptr)
Value:
{ \
if ((*__ptr)) { \
_free_nstr(__ptr); \
} else { \
n_log(LOG_DEBUG, "%s is already NULL", #__ptr); \
} \
}
#define LOG_DEBUG
debug-level messages
Definition n_log.h:84

free a N_STR structure and set the pointer to NULL

Examples
ex_accept_pool_client.c, ex_base64.c, ex_common.c, ex_cookies.c, ex_crypto.c, ex_digest.c, ex_file.c, ex_fluid.c, ex_git.c, ex_gui_network.c, ex_gui_particles.c, ex_hash.c, ex_hex.c, ex_html.c, ex_list.c, ex_monolith.c, ex_network.c, ex_network.h, ex_network_reactor.c, ex_network_sni.c, ex_network_ssl.c, ex_network_ssl_hardened.c, ex_network_ws.c, ex_nstr.c, ex_pcre.c, ex_pretty.c, ex_random.c, ex_url.c, ex_x509.c, and ex_zlib.c.

Definition at line 203 of file n_str.h.

◆ local_strdup

#define local_strdup (   __src_)
Value:
({ \
char* __local_strdup_str = NULL; \
size_t __local_strdup_len = strlen((__src_)); \
Malloc(__local_strdup_str, char, __local_strdup_len + 1); \
if (!__local_strdup_str) { \
n_log(LOG_ERR, "Couldn't allocate %d byte for duplicating \"%s\"", (int)strlen((__src_)) + 1, (__src_)); \
} else { \
for (size_t __local_strdup_it = 0; __local_strdup_it <= __local_strdup_len; __local_strdup_it++) { \
__local_strdup_str[__local_strdup_it] = (__src_)[__local_strdup_it]; \
} \
} \
__local_strdup_str; \
})
#define LOG_ERR
error conditions
Definition n_log.h:76

Do tar(1) matching rules, which ignore a trailing slash?

local strdup

Examples
ex_kafka.c.

Definition at line 79 of file n_str.h.

◆ n_remove_ending_cr

#define n_remove_ending_cr (   __nstr_var)
Value:
do { \
if (__nstr_var && __nstr_var->data && __nstr_var->written > 0 && __nstr_var->data[__nstr_var->written - 1] == '\r') { \
__nstr_var->data[__nstr_var->written - 1] = '\0'; \
__nstr_var->written--; \
} \
} while (0)

Remove carriage return (backslash r) if there is one in the last position of the string.

Definition at line 139 of file n_str.h.

◆ n_replace_cr

#define n_replace_cr (   __nstr_var,
  __replacement 
)
Value:
do { \
if (__nstr_var && __nstr_var->data && __nstr_var->written > 0) { \
char* __replaced = str_replace(__nstr_var->data, "\r", __replacement); \
if (__replaced) { \
Free(__nstr_var->data); \
__nstr_var->data = __replaced; \
__nstr_var->written = strlen(__nstr_var->data); \
__nstr_var->length = __nstr_var->written + 1; \
} \
} \
} while (0)
char * str_replace(const char *string, const char *substr, const char *replacement)
return a new string with all occurrences of substr replaced
Definition n_str.c:1448

Find and replace all occurences of carriage return (backslash r) in the string.

Definition at line 148 of file n_str.h.

◆ nstrcat

#define nstrcat (   __nstr_dst,
  __nstr_src 
)
Value:
({ \
N_STR* __nstrcat_ret = NULL; \
if (__nstr_src && __nstr_src->data) { \
__nstrcat_ret = nstrcat_ex(&(__nstr_dst), __nstr_src->data, __nstr_src->written, 1); \
} \
__nstrcat_ret; \
})
N_STR * nstrcat_ex(N_STR **dest, void *src, NSTRBYTE size, int resize_flag)
concatenate data inside a N_STR
Definition n_str.c:1089
A box including a string and his lenght.
Definition n_str.h:61

Macro to quickly concatenate two N_STR.

Examples
ex_monolith.c, and ex_nstr.c.

Definition at line 125 of file n_str.h.

◆ nstrcat_bytes

#define nstrcat_bytes (   __nstr_dst,
  __void_src 
)     nstrcat_bytes_ex(&(__nstr_dst), __void_src, strlen(__void_src))

Macro to quickly concatenate a '\0' ended byte stream to a N_STR.

Definition at line 135 of file n_str.h.

◆ nstrprintf

#define nstrprintf (   __nstr_var,
  __format,
  ... 
)     nstrprintf_ex(&(__nstr_var), (__format), ##__VA_ARGS__)

Macro to quickly allocate and sprintf to N_STR.

Examples
ex_base64.c, ex_crypto.c, ex_fluid.c, ex_gui_particles.c, ex_hash.c, ex_list.c, ex_monolith.c, ex_network_ssl.c, ex_network_ssl_hardened.c, and ex_nstr.c.

Definition at line 117 of file n_str.h.

◆ nstrprintf_cat

#define nstrprintf_cat (   __nstr_var,
  __format,
  ... 
)     nstrprintf_cat_ex(&(__nstr_var), (__format), ##__VA_ARGS__)

Macro to quickly allocate and sprintf and cat to a N_STR.

Examples
ex_html.c, ex_monolith.c, and ex_nstr.c.

Definition at line 121 of file n_str.h.

◆ strprintf

#define strprintf (   __n_var,
  ... 
)
Value:
({ \
char* __strprintf_ptr = NULL; \
if (!(__n_var)) { \
int __needed = snprintf(NULL, 0, __VA_ARGS__); \
if (__needed > 0) { \
Malloc(__n_var, char, (size_t)__needed + 1); \
if (__n_var) { \
snprintf(__n_var, (size_t)__needed + 1, __VA_ARGS__); \
__strprintf_ptr = __n_var; \
} else { \
n_log(LOG_ERR, "couldn't allocate %s with %d bytes", \
#__n_var, __needed + 1); \
} \
} \
} else { \
n_log(LOG_ERR, "%s is already allocated.", #__n_var); \
} \
__strprintf_ptr; \
})

Macro to quickly allocate and sprintf to a char.

Definition at line 95 of file n_str.h.

◆ WILDMAT_ABORT

#define WILDMAT_ABORT   -2

Abort code to sped up pattern matching.

Special thanks to Lars Mathiesen thori.nosp@m.nn@d.nosp@m.iku.d.nosp@m.k for the ABORT code.

Definition at line 72 of file n_str.h.

◆ WILDMAT_NEGATE_CLASS

#define WILDMAT_NEGATE_CLASS   '^'

What character marks an inverted character class?

Definition at line 74 of file n_str.h.

Typedef Documentation

◆ NSTRBYTE

typedef size_t NSTRBYTE

N_STR base unit.

Definition at line 58 of file n_str.h.

Function Documentation

◆ _free_nstr()

int _free_nstr ( N_STR **  ptr)

free a N_STR and set the pointer to NULL

free a N_STR and set the pointer to NULL

Parameters
ptrA N_STR *object to free
Returns
TRUE or FALSE

Definition at line 83 of file n_str.c.

References __n_assert, and FreeNoLog.

◆ char_to_nstr()

N_STR * char_to_nstr ( const char *  src)

convert a char into a N_STR, shorter version

convert a char into a N_STR, shorter version

Parameters
srcA char *string to convert
Returns
A N_STR copy of src or NULL

Definition at line 255 of file n_str.c.

References __n_assert, and char_to_nstr_ex().

Referenced by _n_html_push_link(), _n_mock_parse_request(), add_strdup_to_msg(), avro_file_to_json(), avro_nstr_avro_to_json(), client_worker_echo(), handle_request(), main(), main(), main(), n_proxy_connect_tunnel(), n_proxy_connect_tunnel_ssl(), n_sitemap_extract_urls(), n_sse_connect(), n_vigenere_quick_decode(), n_vigenere_quick_encode(), on_request(), and run_client().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ char_to_nstr_ex()

int char_to_nstr_ex ( const char *  from,
NSTRBYTE  nboct,
N_STR **  to 
)

convert a char into a N_STR

convert a char into a N_STR

Parameters
fromA char *string to convert
nboctThe size to copy, from 1 octet to nboctet (ustrsizez( from ) )
toA N_STR pointer who will be Malloced
Returns
True on success, FALSE on failure ( to will be set to NULL )

Definition at line 232 of file n_str.c.

References __n_assert, _str, Free, LOG_ERR, n_log, and new_nstr().

Referenced by bio_to_nstr(), char_to_nstr(), gz_compress(), n_html_extract_scripts(), n_html_to_text(), n_http_build_multipart(), n_http_inflate(), and npcre_replace().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ char_to_nstr_nocopy()

N_STR * char_to_nstr_nocopy ( char *  src)

convert a char into a N_STR without copying, shorter version

convert a char into a N_STR without copying, shorter version

Parameters
srcA char *string to use
Returns
A N_STR using src or NULL

Definition at line 268 of file n_str.c.

References __n_assert, data, length, new_nstr(), and written.

Referenced by _out_finish(), and n_pretty_json().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ char_to_nstr_nocopy_ex()

int char_to_nstr_nocopy_ex ( char *  from,
NSTRBYTE  nboct,
N_STR **  to 
)

convert a char into a N_STR without copying

◆ empty_nstr()

int empty_nstr ( N_STR nstr)

reinitialize a nstr

reinitialize a nstr

Parameters
nstrthe N_STR *str string to empty
Returns
TRUE or FALSE

Definition at line 192 of file n_str.c.

References __n_assert, data, length, and written.

Referenced by main().

+ Here is the caller graph for this function:

◆ file_to_nstr()

N_STR * file_to_nstr ( char *  filename)

load a whole file into a N_STR

load a whole file into a N_STR

Be aware of the NSTRBYTE addressing limit (2GB commonly)

Parameters
filenameThe filename to load inside a N_STR
Returns
A valid N_STR (an empty one for a 0-byte file) or NULL on error. An empty file is not an error: the returned N_STR has a valid NUL-terminated data buffer and written == 0.

Definition at line 288 of file n_str.c.

References __n_assert, data, free_nstr, LOG_DEBUG, LOG_ERR, n_log, new_nstr(), and written.

Referenced by avro_file_to_json(), avro_json_to_file(), handle_request(), main(), main(), n_json_parse_file(), n_kafka_load_config(), n_kafka_new_event_from_file(), n_vigenere_decode_file(), n_vigenere_decode_file_qa(), n_vigenere_encode_file(), and n_vigenere_encode_file_qa().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ free_nstr_nolog()

int free_nstr_nolog ( N_STR **  ptr)

free a N_STR and set to NULL without logging

free a N_STR and set to NULL without logging

Parameters
ptrA N_STR *object to free
Returns
TRUE or FALSE

Definition at line 97 of file n_str.c.

References FreeNoLog.

◆ free_nstr_ptr()

void free_nstr_ptr ( void *  ptr)

free a N_STR without setting the pointer to NULL

free a N_STR without setting the pointer to NULL

Parameters
ptrA N_STR *object to free

Definition at line 70 of file n_str.c.

References data, and FreeNoLog.

Referenced by _n_html_push_link(), add_bytes_to_msg(), add_nstrdup_to_msg(), add_nstrptr_to_msg(), add_strdup_to_msg(), main(), n_html_extract_scripts(), n_kafka_poll(), n_sitemap_extract_urls(), netw_add_msg(), netw_add_msg_ex(), netw_recv_func(), and scan_dir_ex().

+ Here is the caller graph for this function:

◆ free_nstr_ptr_nolog()

void free_nstr_ptr_nolog ( void *  ptr)

free a N_STR without logging or setting to NULL

free a N_STR without logging or setting to NULL

Parameters
ptrA N_STR *object to free

Definition at line 110 of file n_str.c.

References data, and FreeNoLog.

◆ free_split_result()

int free_split_result ( char ***  tab)

free a char **tab and set it to NULL

free a char **tab and set it to NULL

Parameters
tabA pointer to a split result to free
Returns
TRUE

Definition at line 1016 of file n_str.c.

References Free.

Referenced by handle_request(), load_config_file(), main(), n_kafka_delete(), n_kafka_delivery_message_callback(), and split().

+ Here is the caller graph for this function:

◆ join()

char * join ( char **  splitresult,
const char *  delim 
)

join a split result into a string

join a split result into a string

Parameters
splitresultthe split result to join
delimThe delimiter, one or more characters
Returns
the joined split result or NULL

Definition at line 1037 of file n_str.c.

References __n_assert, LOG_ERR, Malloc, and n_log.

Referenced by main(), n_kafka_load_config(), and n_kafka_polling_thread().

+ Here is the caller graph for this function:

◆ n_str_template_expand()

N_STR * n_str_template_expand ( const char *  tmpl,
struct HASH_TABLE vars 
)

Expand double-brace tokens in a template using a hash table.

Tokens not found in vars are left unchanged.

Parameters
tmplTemplate string with {{key}} tokens. Must not be NULL.
varsHash table mapping key to value. May be NULL.
Returns
Newly allocated N_STR with expanded result, or NULL on failure.

Definition at line 1681 of file n_str.c.

References ht_get_string(), key, new_nstr(), and nstrprintf_cat.

+ Here is the call graph for this function:

◆ n_str_url_encode()

N_STR * n_str_url_encode ( const char *  src)

Percent-encode a string per RFC 3986 (unreserved chars kept).

Letters, digits and -_.~ are written verbatim; all other bytes become HH. Uses explicit range checks (locale-independent). n_url_encode() in n_network.h is a convenience alias that delegates to this function. See the full parameter contract on the implementation in src/n_str.c.

Percent-encode a string per RFC 3986 (unreserved chars kept).

Letters, digits and the characters '-', '_', '.', '~' are written verbatim. Every other byte is written as HH using upper-case hex. The function is binary-safe in the sense that it never assumes UTF-8 boundaries; it only stops at the terminating NUL of src.

Parameters
srcNUL-terminated input string. NULL returns NULL.
Returns
Newly allocated N_STR with the encoded result, or NULL on invalid input or allocation failure. The caller must free it with free_nstr().

Definition at line 1725 of file n_str.c.

References free_nstr, new_nstr(), and nstrprintf_cat.

Referenced by main(), and n_url_encode().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ new_nstr()

◆ nfgets()

char * nfgets ( char *  buffer,
NSTRBYTE  size,
FILE *  stream 
)

N_STR wrapper around fgets.

N_STR wrapper around fgets.

Parameters
bufferThe string where to read the file
sizeSize of the string
streamThe file to read
Returns
NULL or the captured string

Definition at line 171 of file n_str.c.

References __n_assert, LOG_ERR, and n_log.

◆ nstr_to_fd()

int nstr_to_fd ( N_STR str,
FILE *  out,
int  lock 
)

write a whole N_STR into an open file descriptor

write a whole N_STR into an open file descriptor

Parameters
strThe N_STR *content to write down
outAn opened FILE *handler
locka write lock will be put if lock = 1
Returns
TRUE or FALSE

Definition at line 371 of file n_str.c.

References __n_assert, data, LOG_ERR, n_log, and written.

Referenced by nstr_to_file().

+ Here is the caller graph for this function:

◆ nstr_to_file()

int nstr_to_file ( N_STR str,
char *  filename 
)

write a whole N_STR into a file

write a whole N_STR into a file

Parameters
strThe N_STR *content to write down
filenameThe destination filename
Returns
TRUE or FALSE

Definition at line 424 of file n_str.c.

References __n_assert, _str, LOG_DEBUG, LOG_ERR, n_log, nstr_to_fd(), and written.

Referenced by avro_file_to_json(), avro_json_to_file(), main(), main(), n_kafka_dump_unprocessed(), n_vigenere_decode_file(), n_vigenere_decode_file_qa(), n_vigenere_encode_file(), and n_vigenere_encode_file_qa().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nstrcat_bytes_ex()

N_STR * nstrcat_bytes_ex ( N_STR **  dest,
void *  data,
NSTRBYTE  size 
)

wrapper to nstrcat_ex to concatenate void *data

wrapper to nstrcat_ex to concatenate void *data

Wrapper to nstrcat_ex, with resize_flag on and a block size one byte higher than size.

Parameters
destThe N_STR **destination (accumulator)
dataThe data to append
sizeThe number of octet of data we want to append in dest
Returns
TRUE or FALSE

Definition at line 1154 of file n_str.c.

References __n_assert, LOG_ERR, n_log, and nstrcat_ex().

+ Here is the call graph for this function:

◆ nstrcat_ex()

N_STR * nstrcat_ex ( N_STR **  dest,
void *  src,
NSTRBYTE  size,
int  resize_flag 
)

concatenate data inside a N_STR

concatenate data inside a N_STR

Parameters
destThe N_STR *destination (accumulator)
srcThe data to append
sizeThe number of octet of data we want to append in dest
resize_flagSet it to a positive non zero value to allow resizing, or to zero to forbid resizing
Returns
TRUE or FALSE

Definition at line 1089 of file n_str.c.

References __n_assert, free_nstr, LOG_ERR, n_log, new_nstr(), and Reallocz.

Referenced by avro_encode_bytes_raw(), avro_encode_container(), avro_encode_datum(), avro_encode_long(), and nstrcat_bytes_ex().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nstrdup()

N_STR * nstrdup ( N_STR str)

make a copy of a N_STR

make a copy of a N_STR

Parameters
strA N_STR *object to free
Returns
A valid N_STR or NULL

Definition at line 716 of file n_str.c.

References __n_assert, data, Free, length, LOG_ERR, n_log, new_nstr(), and written.

Referenced by add_nstrdup_to_msg(), main(), n_http_decompress_body(), n_vigenere_cypher(), netw_pool_broadcast(), on_send_click(), and userlist_add_msg_to_ex().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nstrprintf_cat_ex()

N_STR * nstrprintf_cat_ex ( N_STR **  nstr_var,
const char *  format,
  ... 
)

concatenate printf on a N_STR

concatenate printf on a N_STR

Parameters
nstr_varPointer to a pointer to the N_STR object to allocate/resize and concatenate.
formatThe format string (like printf).
...Variadic arguments for formatting.
Returns
The updated N_STR object.

Definition at line 1617 of file n_str.c.

References __n_assert, LOG_ERR, n_log, new_nstr(), and resize_nstr().

+ Here is the call graph for this function:

◆ nstrprintf_ex()

N_STR * nstrprintf_ex ( N_STR **  nstr_var,
const char *  format,
  ... 
)

printf on a N_STR

printf on a N_STR

Parameters
nstr_varPointer to a pointer to the N_STR object to allocate/resize.
formatThe format string (like printf).
...Arguments to be formatted.
Returns
The updated N_STR object.

Definition at line 1565 of file n_str.c.

References __n_assert, LOG_ERR, n_log, new_nstr(), and resize_nstr().

+ Here is the call graph for this function:

◆ resize_nstr()

int resize_nstr ( N_STR nstr,
size_t  size 
)

resize a N_STR

resize a N_STR

Warning: N_STR content will be reset if size = 0 !

Parameters
nstrtargeted N_STR *string
sizenew internal buffer size
Returns
TRUE or FALSE

Definition at line 1534 of file n_str.c.

References __n_assert, data, Free, length, Malloc, Reallocz, and written.

Referenced by main(), nstrprintf_cat_ex(), and nstrprintf_ex().

+ Here is the caller graph for this function:

◆ scan_dir()

int scan_dir ( const char *  dir,
LIST result,
const int  recurse 
)

get a list of files in a directory

get a list of files in a directory

Parameters
dirThe directory to scan
resultA pointer to a valid LIST for the results
recurseRecursive search if TRUE, directory only if FALSE
Returns
TRUE or FALSE

Definition at line 1240 of file n_str.c.

References scan_dir_ex().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ scan_dir_ex()

int scan_dir_ex ( const char *  dir,
const char *  pattern,
LIST result,
const int  recurse,
const int  mode 
)

get a list of files in a directory, extended N_STR version

get a list of files in a directory, extended N_STR version

Parameters
dirThe directory to scan
patternPattern that files must follow to figure in the list
resultA pointer to a valid LIST for the results
recurseRecursive search if TRUE, directory only if FALSE
mode0 for a list of char* , 1 for a list of N_STR *
Returns
TRUE or FALSE

Definition at line 1253 of file n_str.c.

References data, free_nstr, free_nstr_ptr(), list_push(), LOG_ERR, mode, n_log, nstrprintf, scan_dir_ex(), and wildmatcase().

Referenced by scan_dir(), and scan_dir_ex().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ skipu()

int skipu ( const char *  string,
char  toskip,
NSTRBYTE iterator,
int  inc 
)

skip characters in string until string[iterator] == toskip

skip characters in string until string[iterator] == toskip

The new iterator index is automatically stored, returning to it first value if an error append.

Parameters
stringa char *string to search in
toskipskipping while char character 'toskip' isnt found
iteratoran int iteraor position on the string
incan int to specify the step of skipping
Returns
TRUE if success FALSE or ABORT if not

Definition at line 794 of file n_str.c.

References __n_assert.

Referenced by load_config_file(), and main().

+ Here is the caller graph for this function:

◆ skipw()

int skipw ( const char *  string,
char  toskip,
NSTRBYTE iterator,
int  inc 
)

skip characters in string while string[iterator] == toskip

skip characters in string while string[iterator] == toskip

The new iterator index is automatically stored, returning to it first value if an error append.

Parameters
stringa char *string to search in
toskipskipping while char character 'toskip' is found
iteratoran int iteraor position on the string
incan int to specify the step of skipping
Returns
TRUE if success FALSE or ABORT if not

Definition at line 747 of file n_str.c.

References __n_assert.

Referenced by main().

+ Here is the caller graph for this function:

◆ split()

char ** split ( const char *  str,
const char *  delim,
int  empty 
)

return an array of char pointers to the split sections

return an array of char pointers to the split sections

Parameters
strThe char *str to split
delimThe delimiter, one or more characters
emptyEmpty flag. If 1, then empty delimited areas will be added as NULL entries, else they will be skipped.
Returns
An array of char *, ended by a NULL entry.

Definition at line 920 of file n_str.c.

References __n_assert, free_split_result(), and Malloc.

Referenced by handle_request(), main(), main(), n_kafka_delivery_message_callback(), and n_kafka_load_config().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ split_count()

int split_count ( char **  split_result)

count split elements

count split elements

Parameters
split_resultA char **result from a split call
Returns
a joined string using delimiter with The number of elements or -1 if errors

Definition at line 1000 of file n_str.c.

References __n_assert.

Referenced by load_config_file(), main(), n_kafka_delivery_message_callback(), and n_kafka_load_config().

+ Here is the caller graph for this function:

◆ str_replace()

char * str_replace ( const char *  string,
const char *  substr,
const char *  replacement 
)

return a new string with all occurrences of substr replaced

return a new string with all occurrences of substr replaced

Parameters
stringOriginal string to modify
substrString to search
replacementSubstitution string
Returns
A copy of the sustituted string or NULL

Definition at line 1448 of file n_str.c.

References LOG_ERR, Malloc, and n_log.

Referenced by load_config_file(), and main().

+ Here is the caller graph for this function:

◆ str_sanitize()

int str_sanitize ( char *  string,
const char *  mask,
const char  replacement 
)

in-place substitution of a set of chars by a single one

in-place substitution of a set of chars by a single one

Parameters
stringThe string to change
maskThe caracters to kill
replacementreplacement for mask
Returns
TRUE or FALSE

Definition at line 1524 of file n_str.c.

References str_sanitize_ex().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ str_sanitize_ex()

int str_sanitize_ex ( char *  string,
const NSTRBYTE  string_len,
const char *  mask,
const NSTRBYTE  masklen,
const char  replacement 
)

sanitize a string using a character mask

sanitize a string using a character mask

Parameters
stringThe string to change
string_lenSize of the data to treat
maskThe caracters to kill
masklensize of mask
replacementreplacement for mask
Returns
TRUE or FALSE

Definition at line 1501 of file n_str.c.

References __n_assert.

Referenced by str_sanitize().

+ Here is the caller graph for this function:

◆ str_to_int()

int str_to_int ( const char *  s,
int *  i,
const int  base 
)

string to integer, shorter version

string to integer, shorter version

Parameters
sString to convert
iA pointer to an integer variable which will receive the value.
baseBase for converting values
Returns
TRUE or FALSE

Definition at line 553 of file n_str.c.

References str_to_int_ex().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ str_to_int_ex()

int str_to_int_ex ( const char *  s,
NSTRBYTE  start,
NSTRBYTE  end,
int *  i,
const int  base 
)

string to integer, with error checking

string to integer, with error checking

Automatically add /0 for conversion. Leave values untouched if any error occur. Work on a copy of the chunk.

Parameters
sString to convert
startStart position of the chunk
endEnd position of the chunk
iA pointer to an integer variable which will receive the value.
baseBase for converting values
Returns
TRUE or FALSE

Definition at line 462 of file n_str.c.

References __n_assert, Free, LOG_ERR, Malloc, and n_log.

Referenced by str_to_int().

+ Here is the caller graph for this function:

◆ str_to_int_nolog()

int str_to_int_nolog ( const char *  s,
NSTRBYTE  start,
NSTRBYTE  end,
int *  i,
const int  base,
N_STR **  infos 
)

string to integer, with error checking and no logging

string to integer, with error checking and no logging

Automatically add /0 for conversion. Leave values untouched if any error occur. Work on a copy of the chunk.

Parameters
sString to convert
startStart position of the chunk
endEnd position of the chunk
iA pointer to an integer variable which will receive the value.
baseBase for converting values
infosIf not NULL , contain the errors. remember to free the pointer if returned !!
Returns
TRUE or FALSE

Definition at line 510 of file n_str.c.

References __n_assert, Free, LOG_ERR, Malloc, n_log, and nstrprintf.

◆ str_to_long()

int str_to_long ( const char *  s,
long int *  i,
const int  base 
)

string to long integer, shorter version

string to long integer, shorter version

Parameters
sString to convert
iA pointer to an integer variable which will receive the value.
baseBase for converting values
Returns
TRUE or FALSE

Definition at line 688 of file n_str.c.

References str_to_long_ex().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ str_to_long_ex()

int str_to_long_ex ( const char *  s,
NSTRBYTE  start,
NSTRBYTE  end,
long int *  i,
const int  base 
)

string to long integer, with error checking

string to long integer, with error checking

Automatically add /0 for conversion. Leave values untouched if any error occur. Work on a copy of the chunk.

Parameters
sString to convert
startStart position of the chunk
endEnd position of the chunk
iA pointer to an integer variable which will receive the value.
baseBase for converting values
Returns
TRUE or FALSE

Definition at line 572 of file n_str.c.

References __n_assert, Free, LOG_DEBUG, LOG_ERR, Malloc, and n_log.

Referenced by str_to_long().

+ Here is the caller graph for this function:

◆ str_to_long_long()

int str_to_long_long ( const char *  s,
long long int *  i,
const int  base 
)

string to long long integer, shorter version

string to long long integer, shorter version

Parameters
sString to convert
iA pointer to an integer variable which will receive the value.
baseBase for converting values
Returns
TRUE or FALSE

Definition at line 703 of file n_str.c.

References str_to_long_long_ex().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ str_to_long_long_ex()

int str_to_long_long_ex ( const char *  s,
NSTRBYTE  start,
NSTRBYTE  end,
long long int *  i,
const int  base 
)

string to long long integer, with error checking

string to long long integer, with error checking

Automatically add /0 for conversion. Leave values untouched if any error occur. Work on a copy of the chunk.

Parameters
sString to convert
startStart position of the chunk
endEnd position of the chunk
iA pointer to an integer variable which will receive the value.
baseBase for converting values
Returns
TRUE or FALSE

Definition at line 631 of file n_str.c.

References __n_assert, Free, LOG_DEBUG, LOG_ERR, Malloc, and n_log.

Referenced by str_to_long_long().

+ Here is the caller graph for this function:

◆ strcpy_u()

int strcpy_u ( const char *  from,
char *  to,
NSTRBYTE  to_size,
char  delim,
NSTRBYTE it 
)

copy from string to dest until from[iterator] == delim

copy from string to dest until from[iterator] == delim

Parameters
fromSource string
toDest string
to_sizethe maximum size to write
delimstopping character
itSave of iterator
Returns
TRUE or FALSE

Definition at line 884 of file n_str.c.

References __n_assert, LOG_DEBUG, and n_log.

◆ strlo()

int strlo ( const char *  string,
char *  dest 
)

lower case a string

lower case a string

Parameters
stringthe string to change to lower case
destthe string where storing result
Warning
string must be same size as dest
Returns
TRUE or FALSE

Definition at line 861 of file n_str.c.

References __n_assert.

Referenced by main().

+ Here is the caller graph for this function:

◆ strup()

int strup ( const char *  string,
char *  dest 
)

upper case a string

upper case a string

Parameters
stringthe string to change to upper case
destthe string where storing result
Warning
string must be same size as dest
Returns
TRUE or FALSE

Definition at line 840 of file n_str.c.

References __n_assert.

Referenced by main().

+ Here is the caller graph for this function:

◆ trim()

char * trim ( const char *  s)

trim and put a \0 at the end, return new char *

Parameters
sThe string to trim
Returns
the trimmed string or NULL

Definition at line 152 of file n_str.c.

References __n_assert, and trim_nocopy().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ trim_nocopy()

char * trim_nocopy ( char *  s)

trim and put a \0 at the end, return new begin pointer

trim and put a \0 at the end, return new begin pointer

Parameters
sThe string to trim
Returns
the trimmed string or NULL

Definition at line 123 of file n_str.c.

References __n_assert.

Referenced by load_config_file(), main(), and trim().

+ Here is the caller graph for this function:

◆ wildmat()

int wildmat ( register const char *  text,
register const char *  p 
)

pattern matching

pattern matching

Wildcard pattern matching .

Parameters
textThe source text to search
pThe text to search, with wildcards
Returns
return TRUE, FALSE, or WILDMAT_ABORT.

Definition at line 1318 of file n_str.c.

References wildmat(), WILDMAT_ABORT, and WILDMAT_NEGATE_CLASS.

Referenced by main(), and wildmat().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ wildmatcase()

int wildmatcase ( register const char *  text,
register const char *  p 
)

pattern matching, case insensitive

pattern matching, case insensitive

Wildcard pattern matching case insensitive.

Parameters
textThe source text to search
pThe text to search, with wildcards
Returns
return TRUE, FALSE, or WILDMAT_ABORT.

Definition at line 1382 of file n_str.c.

References WILDMAT_ABORT, WILDMAT_NEGATE_CLASS, and wildmatcase().

Referenced by main(), scan_dir_ex(), and wildmatcase().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ write_and_fit()

int write_and_fit ( char **  dest,
NSTRBYTE size,
NSTRBYTE written,
const char *  src 
)

write and fit into the char array

write and fit into the char array

Convenience wrapper over write_and_fit_ex with src_size = strlen(src) and 8 bytes of headroom on growth (so a few short appends after a resize don't each trigger their own realloc). Same post-call invariants as write_and_fit_ex (*size = total allocation, *written = bytes excluding '\0').

Parameters
destpointer to the destination buffer (in/out, may be reallocated)
sizepointer to the destination's total allocation, in bytes (in/out)
writtenpointer to the meaningful-byte count, excluding '\0' (in/out)
srcnull-terminated source string to append
Returns
TRUE on success, FALSE on allocation failure

Definition at line 1229 of file n_str.c.

References write_and_fit_ex().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ write_and_fit_ex()

int write_and_fit_ex ( char **  dest,
NSTRBYTE size,
NSTRBYTE written,
const char *  src,
NSTRBYTE  src_size,
NSTRBYTE  additional_padding 
)

write and fit bytes into a dynamically sized buffer

write and fit bytes into a dynamically sized buffer

Post-call invariants (matching N_STR semantics):

  • *size = total allocation of *dest, in bytes (>= *written + 1). Includes additional_padding when a realloc happened, so subsequent appends that fit within the padding skip further reallocations.
  • *written = number of meaningful bytes in *dest, excluding the trailing '\0'. Bytes used including '\0' = *written + 1.

If *dest is NULL it is allocated from scratch (with *size, *written reset to 0 first).

Parameters
destpointer to the destination buffer (in/out, may be reallocated)
sizepointer to the destination's total allocation, in bytes (in/out)
writtenpointer to the meaningful-byte count, excluding '\0' (in/out)
srcsource bytes to append (read-only, copied verbatim)
src_sizenumber of bytes to copy from src
additional_paddingextra bytes to over-allocate at realloc time
Returns
TRUE on success, FALSE on allocation failure

Definition at line 1187 of file n_str.c.

References LOG_ERR, n_log, and Reallocz.

Referenced by _out_mem(), main(), and write_and_fit().

+ Here is the caller graph for this function: