Asterisk - The Open Source Telephony Project
18.5.0
|
String manipulation API. More...
#include "asterisk.h"
#include <regex.h>
#include "asterisk/strings.h"
#include "asterisk/pbx.h"
#include "asterisk/vector.h"
Go to the source code of this file.
Functions | |
int | __ast_str_helper (struct ast_str **buf, ssize_t max_len, int append, const char *fmt, va_list ap, const char *file, int lineno, const char *function) |
Core functionality of ast_str_(set|append)_va. More... | |
char * | __ast_str_helper2 (struct ast_str **buf, ssize_t maxlen, const char *src, size_t maxsrc, int append, int escapecommas) |
char * | ast_generate_random_string (char *buf, size_t size) |
Create a pseudo-random string of a fixed length. More... | |
char * | ast_read_line_from_buffer (char **buffer) |
Read lines from a string buffer. More... | |
int | ast_str_container_add (struct ao2_container *str_container, const char *add) |
Adds a string to a string container allocated by ast_str_container_alloc. More... | |
struct ao2_container * | ast_str_container_alloc_options (enum ao2_alloc_opts opts, int buckets) |
Allocates a hash container for bare strings. More... | |
void | ast_str_container_remove (struct ao2_container *str_container, const char *remove) |
Removes a string from a string container allocated by ast_str_container_alloc. More... | |
int | ast_strings_equal (const char *str1, const char *str2) |
Compare strings for equality checking for NULL. More... | |
int | ast_strings_match (const char *left, const char *op, const char *right) |
Compares 2 strings using realtime-style operators. More... | |
int | ast_vector_string_split (struct ast_vector_string *dest, const char *input, const char *delim, int flags, int(*excludes_cmp)(const char *s1, const char *s2)) |
Append a string vector by splitting a string. More... | |
static int | str_cmp (void *lhs, void *rhs, int flags) |
static int | str_hash (const void *obj, const int flags) |
static int | str_sort (const void *lhs, const void *rhs, int flags) |
String manipulation API.
Definition in file strings.c.
int __ast_str_helper | ( | struct ast_str ** | buf, |
ssize_t | max_len, | ||
int | append, | ||
const char * | fmt, | ||
va_list | ap, | ||
const char * | file, | ||
int | lineno, | ||
const char * | function | ||
) |
Core functionality of ast_str_(set|append)_va.
core handler for dynamic strings. This is not meant to be called directly, but rather through the various wrapper macros ast_str_set(...) ast_str_append(...) ast_str_set_va(...) ast_str_append_va(...)
Definition at line 55 of file strings.c.
References _ast_str_make_space(), AST_DYNSTR_BUILD_FAILED, ast_log_safe(), if(), and LOG_VERBOSE.
char* __ast_str_helper2 | ( | struct ast_str ** | buf, |
ssize_t | maxlen, | ||
const char * | src, | ||
size_t | maxsrc, | ||
int | append, | ||
int | escapecommas | ||
) |
Definition at line 129 of file strings.c.
References ast_str::__AST_STR_LEN, ast_str_make_space, and if().
Referenced by ast_str_append_substr(), ast_str_append_va(), ast_str_set_escapecommas(), and ast_str_set_substr().
char* ast_generate_random_string | ( | char * | buf, |
size_t | size | ||
) |
Create a pseudo-random string of a fixed length.
This function is useful for generating a string whose randomness does not need to be across all time and space, does not need to be cryptographically secure, and needs to fit in a limited space.
This function will write a null byte at the final position in the buffer (buf[size - 1]). So if you pass in a size of 10, then this will generate a random 9-character string.
buf | Buffer to write random string into. |
size | The size of the buffer. |
Definition at line 227 of file strings.c.
References ast_random(), and buf.
Referenced by add_rlmi_resource(), create_multipart_body(), generate_content_id_hdr(), and sip_outbound_registration_regc_alloc().
char* ast_read_line_from_buffer | ( | char ** | buffer | ) |
Read lines from a string buffer.
buffer | [IN/OUT] A pointer to a char * string with either Unix or Windows line endings |
Both '
' and '
' are treated as single delimiters but consecutive occurrances of the delimiters are NOT considered to be a single delimiter. This preserves blank lines in the input.
MacOS line endings ('') are not supported at this time.
Definition at line 372 of file strings.c.
References NULL.
Referenced by parse_simple_message_summary().
int ast_str_container_add | ( | struct ao2_container * | str_container, |
const char * | add | ||
) |
Adds a string to a string container allocated by ast_str_container_alloc.
str_container | The container to which to add a string |
add | The string to add to the container |
zero | on success |
non-zero | if the operation failed |
Definition at line 206 of file strings.c.
References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_link, ao2_ref, and NULL.
Referenced by add_media_cb(), add_variant_cb(), append_name(), apps_handler(), ast_bridge_snapshot_create(), ast_dns_get_nameservers(), ast_endpoint_add_channel(), AST_TEST_DEFINE(), complete_ari_app(), custom_nameserver_handler(), declined_handler(), event_session_alloc(), get_languages(), ip_identify_match_handler(), load_module(), test_cel_peer_strings_match(), and topic_add_subscription().
struct ao2_container* ast_str_container_alloc_options | ( | enum ao2_alloc_opts | opts, |
int | buckets | ||
) |
Allocates a hash container for bare strings.
opts | Options to be provided to the container |
buckets | The number of buckets to use for the hash container |
AO2 | container for strings |
NULL | if allocation failed |
Definition at line 201 of file strings.c.
References ao2_container_alloc_hash, str_cmp(), str_hash(), and str_sort().
Referenced by ast_dns_get_nameservers(), custom_nameserver_handler(), endpoint_internal_create(), and ip_identify_match_handler().
void ast_str_container_remove | ( | struct ao2_container * | str_container, |
const char * | remove | ||
) |
Removes a string from a string container allocated by ast_str_container_alloc.
str_container | The container from which to remove a string |
remove | The string to remove from the container |
Definition at line 222 of file strings.c.
References ao2_find, OBJ_NODATA, OBJ_SEARCH_KEY, and OBJ_UNLINK.
Referenced by endpoint_cache_clear(), test_cel_peer_strings_match(), and topic_remove_subscription().
int ast_strings_equal | ( | const char * | str1, |
const char * | str2 | ||
) |
Compare strings for equality checking for NULL.
This function considers NULL values as non-strings, thus a false condition. This means that it will return false if one, or both of the given values are NULL (i.e. two NULLs are not equal strings).
str1 | The string to compare to str2 |
str2 | The string to compare to str1 |
Definition at line 239 of file strings.c.
Referenced by app_event_filter_matched(), is_media_state_valid(), load_realtime_musiconhold(), resolve_refresh_media_states(), and set_outbound_authentication_credentials().
int ast_strings_match | ( | const char * | left, |
const char * | op, | ||
const char * | right | ||
) |
Compares 2 strings using realtime-style operators.
left | The left side of the equation |
op | The operator to apply |
right | The right side of the equation |
1 | matches |
0 | doesn't match |
Operators: "=", "!=", "<", "<=", ">", ">=": If both left and right can be converted to float, then they will be compared as such. Otherwise the result will be derived from strcmp(left, right). "regex": The right value will be compiled as a regular expression and matched against the left value. "like": Any '' character in the right value will be converted to '.*' and the resulting string will be handled as a regex. NULL , "": If the right value starts and ends with a '/' then it will be processed as a regex. Otherwise, same as "=".
Definition at line 248 of file strings.c.
References ast_str_alloca, ast_str_append(), ast_str_buffer(), ast_str_set(), ast_strdupa, ast_strlen_zero, NULL, regex(), and strsep().
Referenced by AST_TEST_DEFINE(), and ast_variables_match().
int ast_vector_string_split | ( | struct ast_vector_string * | dest, |
const char * | input, | ||
const char * | delim, | ||
int | flags, | ||
int(*)(const char *s1, const char *s2) | excludes_cmp | ||
) |
Append a string vector by splitting a string.
dest | Pointer to an initialized vector. |
input | String buffer to split. |
delim | String delimeter passed to strsep. |
flags | Processing options defined by enum ast_vector_string_split_flags. |
excludes_cmp | NULL or a function like strcmp to exclude duplicate strings. |
0 | Success |
-1 | Failure |
Definition at line 393 of file strings.c.
References ast_assert, ast_free, ast_strdup, ast_strdupa, ast_strip(), ast_strlen_zero, AST_VECTOR_APPEND, AST_VECTOR_GET_CMP, AST_VECTOR_STRING_SPLIT_ALLOW_EMPTY, AST_VECTOR_STRING_SPLIT_NO_TRIM, buf, NULL, and strsep().
Referenced by module_post_register().
|
static |
Definition at line 187 of file strings.c.
References CMP_MATCH, OBJ_SEARCH_MASK, and OBJ_SEARCH_PARTIAL_KEY.
Referenced by ast_str_container_alloc_options().
|
static |
Definition at line 173 of file strings.c.
References ast_str_hash().
Referenced by ast_str_container_alloc_options().
|
static |
Definition at line 178 of file strings.c.
References OBJ_SEARCH_MASK, and OBJ_SEARCH_PARTIAL_KEY.
Referenced by ast_str_container_alloc_options().