Asterisk - The Open Source Telephony Project GIT-master-f36a736
|
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... | |
int | ast_in_delimited_string (const char *needle, const char *haystack, char delim) |
Check if there is an exact match for 'needle' between delimiters in 'haystack'. 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(), buf, make_ari_stubs::file, 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_make_space, buf, 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 226 of file strings.c.
References ast_random(), and buf.
Referenced by add_eprofile_to_tdata(), add_rlmi_resource(), create_multipart_body(), generate_content_id_hdr(), and sip_outbound_registration_regc_alloc().
int ast_in_delimited_string | ( | const char * | needle, |
const char * | haystack, | ||
char | delim | ||
) |
Check if there is an exact match for 'needle' between delimiters in 'haystack'.
needle | The string to search for |
haystack | The string searched in |
delim | The haystack delimiter |
true | If an exact match for needle is in haystack. |
false | otherwise |
Definition at line 433 of file strings.c.
References ast_assert, ast_skip_blanks(), end, and NULL.
Referenced by __manager_event_sessions_va(), ast_json_object_create_vars(), and AST_TEST_DEFINE().
char * ast_read_line_from_buffer | ( | char ** | buffer | ) |
Read lines from a string buffer.
[in,out] | buffer | A pointer to a char * string with either Unix or Windows line endings |
Both '\n' and '\r\n' are treated as single delimiters but consecutive occurrences of the delimiters are NOT considered to be a single delimiter. This preserves blank lines in the input.
macOS line endings ('\r') are not supported at this time.
Definition at line 371 of file strings.c.
References NULL.
Referenced by crypto_get_cert_subject(), filter_cmp_fn(), and 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 205 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(), coreshowchannelmap_add_to_map(), 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 |
NULL | if allocation failed |
Definition at line 200 of file strings.c.
References ao2_container_alloc_hash, str_cmp(), str_hash(), and str_sort().
Referenced by action_coreshowchannelmap(), 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 221 of file strings.c.
References ao2_find, OBJ_NODATA, OBJ_SEARCH_KEY, OBJ_UNLINK, and remove.
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 |
true | if valid strings and equal. |
false | otherwise. |
Definition at line 238 of file strings.c.
Referenced by app_event_filter_matched(), ast_geoloc_gml_validate_varlist(), check_x5u_url(), config_object_cli_show(), geoloc_civicaddr_list_to_xml(), geoloc_gml_list_to_xml(), geoloc_profile_read(), geoloc_profile_write(), is_media_state_valid(), is_pidf_lo(), load_realtime_musiconhold(), resolve_refresh_media_states(), set_outbound_authentication_credentials(), and uom_validator().
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 247 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 ast_vector_string_split_flags. |
excludes_cmp | NULL or a function like strcmp to exclude duplicate strings. |
0 | Success |
-1 | Failure |
Definition at line 392 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, input(), 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().