23 #ifndef _ASTERISK_STRINGS_H
24 #define _ASTERISK_STRINGS_H
33 #if defined(DEBUG_OPAQUE)
34 #define __AST_STR_USED used2
35 #define __AST_STR_LEN len2
36 #define __AST_STR_STR str2
37 #define __AST_STR_TS ts2
39 #define __AST_STR_USED used
40 #define __AST_STR_LEN len
41 #define __AST_STR_STR str
42 #define __AST_STR_TS ts
47 #define AS_OR(a,b) (a && ast_str_strlen(a)) ? ast_str_buffer(a) : (b)
50 #define ast_strlen_zero(foo) _ast_strlen_zero(foo, __FILE__, __PRETTY_FUNCTION__, __LINE__)
51 static force_inline int _ast_strlen_zero(
const char *s,
const char *file,
const char *
function,
int line)
53 if (!s || (*s ==
'\0')) {
56 if (!strcmp(s,
"(null)")) {
57 ast_log(
__LOG_WARNING, file, line,
function,
"Possible programming error: \"(null)\" is not NULL!\n");
65 return (!s || (*s ==
'\0'));
70 #define ast_strlen_real(a) (a) ? strlen(a) : 0
71 #define ast_strlen_imaginary(a) ast_random()
77 #define S_OR(a, b) ({typeof(&((a)[0])) __x = (a); ast_strlen_zero(__x) ? (b) : __x;})
83 #define S_COR(a, b, c) ({typeof(&((b)[0])) __x = (b); (a) && !ast_strlen_zero(__x) ? (__x) : (c);})
93 while (*str && ((
unsigned char) *str) < 33)
110 work += strlen(work) - 1;
117 while ((work >= str) && ((
unsigned char) *work) < 33)
132 while (*str && ((
unsigned char) *str) > 32)
181 char *
ast_strip_quoted(
char *s,
const char *beg_quotes,
const char *end_quotes);
215 while (*src && size) {
219 if (__builtin_expect(!size, 0))
239 int ast_build_string(
char **buffer,
size_t *space,
const char *fmt, ...) __attribute__((
format(printf, 3, 4)));
253 int ast_build_string_va(
char **buffer,
size_t *space, const
char *fmt, va_list ap) __attribute__((
format(printf, 3, 0)));
289 void ast_join(
char *s,
size_t len, const
char * const w[]);
300 int ast_get_time_t(const
char *src, time_t *dst, time_t _default,
int *consumed);
310 int ast_get_timeval(const
char *src, struct timeval *
tv, struct timeval _default,
int *consumed);
368 #define DS_MALLOC ((struct ast_threadstorage *)1)
369 #define DS_ALLOCA ((struct ast_threadstorage *)2)
370 #define DS_STATIC ((struct ast_threadstorage *)3)
385 #if (defined(MALLOC_DEBUG) && !defined(STANDALONE))
386 #define ast_str_create(a) _ast_str_create(a,__FILE__,__LINE__,__PRETTY_FUNCTION__)
389 const char *file,
int lineno,
const char *func),
531 #
if defined(DEBUG_THREADLOCALS)
540 #if (defined(MALLOC_DEBUG) && !defined(STANDALONE))
542 int _ast_str_make_space(
struct ast_str **buf,
size_t new_len,
const char *file,
int lineno,
const char *
function),
544 struct ast_str *old_buf = *buf;
546 if (new_len <= (*buf)->__AST_STR_LEN)
556 pthread_setspecific((*buf)->__AST_STR_TS->key, *buf);
557 _DB1(__ast_threadstorage_object_replace(old_buf, *buf, new_len +
sizeof(
struct ast_str));)
560 (*buf)->__AST_STR_LEN = new_len;
564 #define
ast_str_make_space(a,b) _ast_str_make_space(a,b,__FILE__,__LINE__,__PRETTY_FUNCTION__)
569 struct ast_str *old_buf = *buf;
571 if (new_len <= (*buf)->__AST_STR_LEN)
581 pthread_setspecific((*buf)->__AST_STR_TS->key, *buf);
582 _DB1(__ast_threadstorage_object_replace(old_buf, *buf, new_len +
sizeof(
struct ast_str));)
585 (*buf)->__AST_STR_LEN = new_len;
602 memcpy((*dst)->__AST_STR_STR, src->__AST_STR_STR, src->__AST_STR_USED + 1);
603 (*dst)->__AST_STR_USED = src->__AST_STR_USED;
610 struct
ast_str *__ast_str_buf; \
611 __ast_str_buf =
ast_alloca(
sizeof(*__ast_str_buf) + init_len); \
612 __ast_str_buf->__AST_STR_LEN = init_len; \
613 __ast_str_buf->__AST_STR_USED = 0; \
614 __ast_str_buf->__AST_STR_TS =
DS_ALLOCA; \
615 __ast_str_buf->__AST_STR_STR[0] =
'\0'; \
650 #
if !defined(DEBUG_THREADLOCALS)
673 size_t init_len,
const char *file,
const char *
function,
unsigned int line),
677 buf = (
struct ast_str *)__ast_threadstorage_get(ts,
sizeof(*buf) + init_len, file,
function, line);
691 #define
ast_str_thread_get(ts, init_len) __ast_str_thread_get(ts, init_len, __FILE__, __PRETTY_FUNCTION__, __LINE__)
733 #if (defined(MALLOC_DEBUG) && !defined(STANDALONE))
734 int __attribute__((
format(printf, 4, 0))) __ast_debug_str_helper(struct
ast_str **buf, ssize_t max_len,
735 int append, const
char *fmt, va_list ap, const
char *file,
int lineno, const
char *func);
736 #define __ast_str_helper(a,b,c,d,e) __ast_debug_str_helper(a,b,c,d,e,__FILE__,__LINE__,__PRETTY_FUNCTION__)
739 int append, const
char *fmt, va_list ap);
742 const char *src,
size_t maxsrc,
int append,
int escapecommas);
863 struct
ast_str **buf, ssize_t max_len, const
char *fmt, ...),
889 struct
ast_str **buf, ssize_t max_len, const
char *fmt, ...),
912 if (*arg < '0' || *arg >
'9') {
930 if (!dev_str || !strchr(dev_str,
'/')) {
934 for (pos = dev_str; *pos && *pos !=
'/'; pos++) {
935 *pos = toupper(*pos);
954 hash = hash * 33 ^ *str++;
977 hash = hash * 33 ^ *str++;
994 hash = hash * 33 ^ tolower(*str++);
void * ast_threadstorage_get(struct ast_threadstorage *ts, size_t init_size)
Retrieve thread storage.
typedef typeof(tv.tv_sec) ast_time_t
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
size_t ast_str_size(const struct ast_str *buf)
Returns the current maximum length (without reallocation) of the current buffer.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
data for a thread locally stored variable
int ast_str_set_va(struct ast_str **buf, ssize_t max_len, const char *fmt, va_list ap)
Set a dynamic string from a va_list.
char * ast_str_append_escapecommas(struct ast_str **buf, ssize_t maxlen, const char *src, size_t maxsrc)
Append a non-NULL terminated substring to the end of a dynamic string, with escaping of commas...
void * __ast_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func)
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
struct ast_str * ast_str_create(size_t init_len)
Create a malloc'ed dynamic length string.
#define ast_str_alloca(init_len)
Definitions to aid in the use of thread local storage.
int ast_get_timeval(const char *src, struct timeval *tv, struct timeval _default, int *consumed)
get values from config variables.
char * ast_skip_nonblanks(const char *str)
Gets a pointer to first whitespace character in a string.
char * ast_str_truncate(struct ast_str *buf, ssize_t len)
Truncates the enclosed string to the given length.
static force_inline int ast_str_hash_add(const char *str, int hash)
Compute a hash value on a string.
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
int ast_get_time_t(const char *src, time_t *dst, time_t _default, int *consumed)
get values from config variables.
char * ast_strip_quoted(char *s, const char *beg_quotes, const char *end_quotes)
Strip leading/trailing whitespace and quotes from a string.
int ast_build_string(char **buffer, size_t *space, const char *fmt,...)
Build a string in a buffer, designed to be called repeatedly.
int ast_str_copy_string(struct ast_str **dst, struct ast_str *src)
int ast_str_make_space(struct ast_str **buf, size_t new_len)
static force_inline int attribute_pure ast_strlen_zero(const char *s)
char * ast_str_append_substr(struct ast_str **buf, ssize_t maxlen, const char *src, size_t maxsrc)
Append a non-NULL terminated substring to the end of a dynamic string.
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
char * ast_tech_to_upper(char *dev_str)
Convert the tech portion of a device string to upper case.
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true". This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1".
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
char * ast_skip_blanks(const char *str)
Gets a pointer to the first non-whitespace character in a string.
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
char * ast_trim_blanks(char *str)
Trims trailing whitespace characters from a string.
char * __ast_str_helper2(struct ast_str **buf, ssize_t max_len, const char *src, size_t maxsrc, int append, int escapecommas)
void * __ast_realloc(void *ptr, size_t size, const char *file, int lineno, const char *func)
void ast_join(char *s, size_t len, const char *const w[])
int ast_str_append_va(struct ast_str **buf, ssize_t max_len, const char *fmt, va_list ap)
Append to a dynamic string using a va_list.
int ast_build_string_va(char **buffer, size_t *space, const char *fmt, va_list ap)
Build a string in a buffer, designed to be called repeatedly.
if(yyss+yystacksize-1<=yyssp)
int ast_check_digits(const char *arg)
Check if a string is only digits.
char * ast_unescape_semicolon(char *s)
Strip backslash for "escaped" semicolons, the string to be stripped (will be modified).
char * ast_str_set_escapecommas(struct ast_str **buf, ssize_t maxlen, const char *src, size_t maxsrc)
Set a dynamic string to a non-NULL terminated substring, with escaping of commas. ...
void ast_str_reset(struct ast_str *buf)
Reset the content of a dynamic string. Useful before a series of ast_str_append.
struct ast_threadstorage * __AST_STR_TS
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
void ast_str_update(struct ast_str *buf)
Update the length of the buffer, after using ast_str merely as a buffer.
int attribute_pure ast_false(const char *val)
Make sure something is false. Determine if a string containing a boolean value is "false"...
#define ast_realloc(a, b)
char * ast_str_set_substr(struct ast_str **buf, ssize_t maxlen, const char *src, size_t maxsrc)
Set a dynamic string to a non-NULL terminated substring.
int __ast_str_helper(struct ast_str **buf, ssize_t max_len, int append, const char *fmt, va_list ap)
Core functionality of ast_str_(set|append)_va.
struct ast_str * ast_str_thread_get(struct ast_threadstorage *ts, size_t init_len)
Retrieve a thread locally stored dynamic string.
void ast_str_trim_blanks(struct ast_str *buf)
Trims trailing whitespace characters from an ast_str string.
static snd_pcm_format_t format
static force_inline int attribute_pure ast_str_case_hash(const char *str)
Compute a hash value on a case-insensitive string.
static force_inline int attribute_pure ast_str_hash(const char *str)
Compute a hash value on a string.
char * ast_unescape_c(char *s)
Convert some C escape sequences.
#define AST_INLINE_API(hdr, body)