56 int append,
const char *fmt, va_list ap,
57 const char *
file,
int lineno,
const char *function)
62 int offset = (append && (*buf)->__AST_STR_LEN) ? (*buf)->__AST_STR_USED : 0;
66 max_len = (*buf)->__AST_STR_LEN;
71 res = vsnprintf((*buf)->__AST_STR_STR + offset, (*buf)->__AST_STR_LEN - offset, fmt, aq);
90 need = offset + added + 1;
91 if (need <= (*buf)->__AST_STR_LEN
92 || (max_len && max_len <= (*buf)->__AST_STR_LEN)) {
103 need += 16 + need / 4;
104 }
else if (max_len < need) {
111 (
int) (*buf)->__AST_STR_LEN, need);
119 (*buf)->__AST_STR_USED = ((*buf)->__AST_STR_LEN <= offset + added)
120 ? (*buf)->__AST_STR_LEN - 1
124 (*buf)->__AST_STR_STR[(*buf)->__AST_STR_USED] =
'\0';
132 char *ptr = append ? &((*buf)->__AST_STR_STR[(*buf)->__AST_STR_USED]) : (*buf)->__AST_STR_STR;
138 maxlen = (*buf)->__AST_STR_LEN;
141 while (*src && maxsrc && maxlen && (!escapecommas || (maxlen - 1))) {
142 if (escapecommas && (*src ==
'\\' || *src ==
',')) {
145 (*buf)->__AST_STR_USED++;
150 (*buf)->__AST_STR_USED++;
152 if ((ptr >= (*buf)->__AST_STR_STR + (*buf)->__AST_STR_LEN - 3) ||
153 (dynamic && (!maxlen || (escapecommas && !(maxlen - 1))))) {
154 char *oldbase = (*buf)->__AST_STR_STR;
155 size_t old = (*buf)->__AST_STR_LEN;
163 ptr += (*buf)->__AST_STR_STR - oldbase;
166 if (__builtin_expect(!maxlen, 0)) {
170 return (*buf)->__AST_STR_STR;
173static int str_hash(
const void *obj,
const int flags)
178static int str_sort(
const void *lhs,
const void *rhs,
int flags)
181 return strncmp(lhs, rhs, strlen(rhs));
183 return strcmp(lhs, rhs);
187static int str_cmp(
void *lhs,
void *rhs,
int flags)
192 cmp = strncmp(lhs, rhs, strlen(rhs));
194 cmp = strcmp(lhs, rhs);
214 strcpy(ao2_add, add);
230 for (i = 0; i < size - 1; ++i) {
240 if (!str1 || !str2) {
244 return str1 == str2 || !strcmp(str1, str2);
249 char *internal_op = (
char *)op;
250 char *internal_right = (
char *)right;
253 int scan_numeric = 0;
255 if (!(left && right)) {
264 if (strlen(right) >= 2 && right[0] ==
'/' && right[strlen(right) - 1] ==
'/') {
265 internal_op =
"regex";
269 internal_right[strlen(internal_right) - 1] =
'\0';
277 if (!strcasecmp(op,
"like")) {
281 if (!strchr(right,
'%')) {
282 return !strcmp(left, right);
284 internal_op =
"regex";
286 tok =
strsep(&internal_right,
"%");
289 while ((tok =
strsep(&internal_right,
"%"))) {
300 if (!strcasecmp(internal_op,
"regex")) {
304 if (regcomp(&expression, internal_right, REG_EXTENDED | REG_NOSUB)) {
308 rc = regexec(&expression, left, 0,
NULL, 0);
309 regfree(&expression);
314 scan_numeric = (sscanf(left,
"%lf", &left_num) > 0 && sscanf(internal_right,
"%lf", &right_num) > 0);
316 if (internal_op[0] ==
'=') {
322 return (left_num == right_num);
324 return (!strcmp(left, internal_right));
328 if (internal_op[0] ==
'!' && internal_op[1] ==
'=') {
330 return (left_num != right_num);
332 return !!strcmp(left, internal_right);
336 if (internal_op[0] ==
'<') {
338 if (internal_op[1] ==
'=') {
339 return (left_num <= right_num);
341 return (left_num < right_num);
344 if (internal_op[1] ==
'=') {
345 return strcmp(left, internal_right) <= 0;
347 return strcmp(left, internal_right) < 0;
352 if (internal_op[0] ==
'>') {
354 if (internal_op[1] ==
'=') {
355 return (left_num >= right_num);
357 return (left_num > right_num);
360 if (internal_op[1] ==
'=') {
361 return strcmp(left, internal_right) >= 0;
363 return strcmp(left, internal_right) > 0;
373 char *start = *buffer;
375 if (!buffer || !*buffer || *(*buffer) ==
'\0') {
379 while (*(*buffer) && *(*buffer) !=
'\n' ) {
384 if (*(*buffer - 1) ==
'\r') {
385 *(*buffer - 1) =
'\0';
393 const char *
input,
const char *delim,
int flags,
394 int (*excludes_cmp)(
const char *s1,
const char *s2))
436 unsigned long needle_size;
444 needle_size = strlen(needle);
447 while ((
end = strchr(haystack, delim))) {
448 if (needle_size ==
end - haystack && !strncmp(haystack, needle, needle_size)) {
454 return strcmp(haystack, needle) ? 0 : -1;
static int input(yyscan_t yyscanner)
Asterisk main include file. File version handling, generic pbx functions.
#define ast_strdup(str)
A wrapper for strdup()
#define ast_strdupa(s)
duplicate a string in memory from the stack
#define ao2_link(container, obj)
Add an object to a container.
ao2_alloc_opts
Options available when allocating an ao2 object.
@ AO2_ALLOC_OPT_LOCK_NOLOCK
#define ao2_find(container, arg, flags)
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
#define ao2_alloc_options(data_size, destructor_fn, options)
@ OBJ_SEARCH_PARTIAL_KEY
The arg parameter is a partial search key similar to OBJ_SEARCH_KEY.
@ OBJ_SEARCH_MASK
Search option field mask.
@ OBJ_SEARCH_KEY
The arg parameter is a search key, but is not an object.
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Allocate and initialize a hash container with the desired number of buckets.
static int regex(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
char * strsep(char **str, const char *delims)
void ast_log_safe(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message with protection against recursion.
Core PBX routines and definitions.
int ast_strings_equal(const char *str1, const char *str2)
Compare strings for equality checking for NULL.
static int str_sort(const void *lhs, const void *rhs, int flags)
int ast_strings_match(const char *left, const char *op, const char *right)
Compares 2 strings using realtime-style operators.
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'.
char * ast_read_line_from_buffer(char **buffer)
Read lines from a string buffer.
static int str_cmp(void *lhs, void *rhs, int flags)
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.
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.
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.
char * ast_generate_random_string(char *buf, size_t size)
Create a pseudo-random string of a fixed length.
struct ao2_container * ast_str_container_alloc_options(enum ao2_alloc_opts opts, int buckets)
Allocates a hash container for bare strings.
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.
static int str_hash(const void *obj, const int flags)
char * __ast_str_helper2(struct ast_str **buf, ssize_t maxlen, const char *src, size_t maxsrc, int append, int escapecommas)
String manipulation functions.
@ AST_DYNSTR_BUILD_FAILED
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
static force_inline int attribute_pure ast_str_hash(const char *str)
Compute a hash value on a string.
int _ast_str_make_space(struct ast_str **buf, size_t new_len, const char *file, int lineno, const char *function)
static force_inline int attribute_pure ast_strlen_zero(const char *s)
#define ast_str_alloca(init_len)
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
#define ast_str_make_space(buf, new_len)
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
char * ast_skip_blanks(const char *str)
Gets a pointer to the first non-whitespace character in a string.
Support for dynamic strings.
String vector definitions.
long int ast_random(void)
Vector container support.
#define AST_VECTOR_GET_CMP(vec, value, cmp)
Get an element from a vector that matches the given comparison.
@ AST_VECTOR_STRING_SPLIT_NO_TRIM
@ AST_VECTOR_STRING_SPLIT_ALLOW_EMPTY
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.