![]() |
Home page |
Mailing list |
Docs
Asterisk developer's documentation :: Codename Pineapple
strings.h File Reference
Definition in file strings.h.
#include <string.h>
#include <stdarg.h>
#include "asterisk/inline_api.h"
#include "asterisk/compiler.h"
#include "asterisk/compat.h"
#include "asterisk/utils.h"
#include "asterisk/threadstorage.h"
Include dependency graph for strings.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.
Data Structures | |
| struct | ast_realloca |
| struct | ast_str |
| The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field to indicate the type of storage. Three special constants indicate malloc, alloca() or static variables, all other values indicate a struct ast_threadstorage pointer. More... | |
Defines | |
| #define | _DB1(x) |
| #define | ast_restrdupa(ra, s) |
| #define | ast_str_alloca(init_len) |
| #define | ast_str_append_va(buf, max_len, fmt, ap) |
| Append to a dynamic string using a va_list. | |
| #define | ast_str_set_va(buf, max_len, fmt, ap) |
| Set a dynamic string from a va_list. | |
| #define | DS_ALLOCA ((struct ast_threadstorage *)2) |
| #define | DS_MALLOC ((struct ast_threadstorage *)1) |
| #define | DS_STATIC ((struct ast_threadstorage *)3) |
| #define | S_OR(a, b) (!ast_strlen_zero(a) ? (a) : (b)) |
| returns the equivalent of logic or for strings: first one if not empty, otherwise second one. | |
Functions | |
| int | __ast_str_helper (struct ast_str **buf, size_t max_len, int append, const char *fmt, va_list ap) |
| Core functionality of ast_str_(set|append)_va. | |
| size_t const char | __attribute__ ((format(printf, 3, 4))) |
| 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. | |
| int | ast_false (const char *val) |
| int | ast_get_time_t (const char *src, time_t *dst, time_t _default, int *consumed) |
| get values from config variables. | |
| AST_INLINE_API (int __attribute__((format(printf, 3, 4))) ast_str_set(struct ast_str **buf, size_t max_len, const char *fmt,...),{int res;va_list ap;va_start(ap, fmt);res=ast_str_set_va(buf, max_len, fmt, ap);va_end(ap);return res;}) AST_INLINE_API(int __attribute__((format(printf | |
| Set a dynamic string using variable argumentsAppend to a thread local dynamic string. | |
| AST_INLINE_API (struct ast_str *attribute_malloc ast_str_create(size_t init_len),{struct ast_str *buf;buf=(struct ast_str *) ast_calloc(1, sizeof(*buf)+init_len);if(buf==NULL) return NULL;buf->len=init_len;buf->used=0;buf->ts=DS_MALLOC;return buf;}) AST_INLINE_API(void ast_str_reset(struct ast_str *buf) | |
| Create a malloc'ed dynamic length stringReset the content of a dynamic string. Useful before a series of ast_str_append. | |
| AST_INLINE_API (void ast_copy_string(char *dst, const char *src, size_t size),{while(*src &&size){*dst++=*src++;size--;}if(__builtin_expect(!size, 0)) dst--;*dst= '\0';}) int ast_build_string(char **buffer | |
| Size-limited null-terminating string copy. Build a string in a buffer, designed to be called repeatedly. | |
| AST_INLINE_API (char *ast_skip_blanks(const char *str),{while(*str &&*str< 33) str++;return(char *) str;}) AST_INLINE_API(char *ast_trim_blanks(char *str) | |
| Gets a pointer to the first non-whitespace character in a string. Trims trailing whitespace characters from a string. | |
| void | ast_join (char *s, size_t len, char *const w[]) |
| ast_str_append (struct ast_str **buf, size_t max_len, const char *fmt,...) | |
| static force_inline int | ast_strlen_zero (const char *s) |
| int | ast_true (const char *val) |
Variables | |
| size_t const char * | fmt |
| size_t * | space |
|
|
|
|
|
|
|
|
Referenced by __manager_event(), action_listcommands(), handle_showchan(), handle_showmancmd(), handle_showmancmds(), and print_uptimestr(). |
|
|
Append to a dynamic string using a va_list. Same as ast_str_set_va(), but append to the current content. Definition at line 568 of file strings.h. Referenced by __manager_event(). |
|
|
Set a dynamic string from a va_list.
AST_THREADSTORAGE(my_str, my_str_init); #define MY_STR_INIT_SIZE 128 ... void my_func(const char *fmt, ...) { struct ast_str *buf; va_list ap; if (!(buf = ast_str_thread_get(&my_str, MY_STR_INIT_SIZE))) return; ... va_start(fmt, ap); ast_str_set_va(&buf, 0, fmt, ap); va_end(ap); printf("This is the string we just built: %s\n", buf->str); ... }
Definition at line 552 of file strings.h. Referenced by ast_cli(), ast_log(), ast_verbose(), and astman_append(). |
|
|
|
|
|
|
|
|
|
|
|
||||||||||||||||||||||||
|
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 984 of file utils.c. References ast_verbose(), and offset. 00986 { 00987 int res, need; 00988 int offset = (append && (*buf)->len) ? (*buf)->used : 0; 00989 00990 if (max_len < 0) 00991 max_len = (*buf)->len; /* don't exceed the allocated space */ 00992 /* 00993 * Ask vsnprintf how much space we need. Remember that vsnprintf 00994 * does not count the final '\0' so we must add 1. 00995 */ 00996 res = vsnprintf((*buf)->str + offset, (*buf)->len - offset, fmt, ap); 00997 00998 need = res + offset + 1; 00999 /* 01000 * If there is not enough space and we are below the max length, 01001 * reallocate the buffer and return a message telling to retry. 01002 */ 01003 if (need > (*buf)->len && (max_len == 0 || (*buf)->len < max_len) ) { 01004 if (max_len && max_len < need) /* truncate as needed */ 01005 need = max_len; 01006 else if (max_len == 0) /* if unbounded, give more room for next time */ 01007 need += 16 + need/4; 01008 if (0) /* debugging */ 01009 ast_verbose("extend from %d to %d\n", (int)(*buf)->len, need); 01010 if (ast_str_make_space(buf, need)) { 01011 ast_verbose("failed to extend from %d to %d\n", (int)(*buf)->len, need); 01012 return AST_DYNSTR_BUILD_FAILED; 01013 } 01014 (*buf)->str[offset] = '\0'; /* Truncate the partial write. */ 01015 01016 /* va_end() and va_start() must be done before calling 01017 * vsnprintf() again. */ 01018 return AST_DYNSTR_BUILD_RETRY; 01019 } 01020 /* update space used, keep in mind the truncation */ 01021 (*buf)->used = (res + offset > (*buf)->len) ? (*buf)->len : res + offset; 01022 01023 return res; 01024 }
|
|
|
|
|
||||||||||||||||||||
|
Build a string in a buffer, designed to be called repeatedly. This is a wrapper for snprintf, that properly handles the buffer pointer and buffer space available.
Definition at line 667 of file utils.c. Referenced by ast_build_string(). 00668 { 00669 int result; 00670 00671 if (!buffer || !*buffer || !space || !*space) 00672 return -1; 00673 00674 result = vsnprintf(*buffer, *space, fmt, ap); 00675 00676 if (result < 0) 00677 return -1; 00678 else if (result > *space) 00679 result = *space; 00680 00681 *buffer += result; 00682 *space -= result; 00683 return 0; 00684 }
|
|
|
Determine if a string containing a boolean value is "false". This function checks to see whether a string passed to it is an indication of an "false" value. It checks to see if the string is "no", "false", "n", "f", "off" or "0". Returns 0 if val is a NULL pointer, -1 if "false", and 0 otherwise. Definition at line 715 of file utils.c. References ast_strlen_zero(). Referenced by aji_create_client(), aji_load_config(), ast_rtp_reload(), ast_udptl_reload(), build_device(), handle_common_options(), load_config(), reload_config(), and strings_to_mask(). 00716 { 00717 if (ast_strlen_zero(s)) 00718 return 0; 00719 00720 /* Determine if this is a false value */ 00721 if (!strcasecmp(s, "no") || 00722 !strcasecmp(s, "false") || 00723 !strcasecmp(s, "n") || 00724 !strcasecmp(s, "f") || 00725 !strcasecmp(s, "0") || 00726 !strcasecmp(s, "off")) 00727 return -1; 00728 00729 return 0; 00730 }
|
|
||||||||||||||||||||
|
get values from config variables.
Definition at line 952 of file utils.c. References ast_strlen_zero(). Referenced by build_device(), build_peer(), cache_lookup_internal(), handle_saydatetime(), and load_password(). 00953 { 00954 long t; 00955 int scanned; 00956 00957 if (dst == NULL) 00958 return -1; 00959 00960 *dst = _default; 00961 00962 if (ast_strlen_zero(src)) 00963 return -1; 00964 00965 /* only integer at the moment, but one day we could accept more formats */ 00966 if (sscanf(src, "%ld%n", &t, &scanned) == 1) { 00967 *dst = t; 00968 if (consumed) 00969 *consumed = scanned; 00970 return 0; 00971 } else 00972 return -1; 00973 }
|
|
|
Set a dynamic string using variable argumentsAppend to a thread local dynamic string. The arguments, return values, and usage of this function are the same as ast_str_set(), but the new data is appended to the current value. |
|
|
Create a malloc'ed dynamic length stringReset the content of a dynamic string. Useful before a series of ast_str_append.
|
|
|
Size-limited null-terminating string copy. Build a string in a buffer, designed to be called repeatedly.
|
|
|
Gets a pointer to the first non-whitespace character in a string. Trims trailing whitespace characters from a string.
|
|
||||||||||||||||
|
Definition at line 823 of file utils.c. Referenced by __ast_cli_generator(), console_sendtext(), handle_agidumphtml(), handle_help(), handle_showagi(), help1(), help_workhorse(), and set_full_cmd(). 00824 { 00825 int x, ofs = 0; 00826 const char *src; 00827 00828 /* Join words into a string */ 00829 if (!s) 00830 return; 00831 for (x = 0; ofs < len && w[x]; x++) { 00832 if (x > 0) 00833 s[ofs++] = ' '; 00834 for (src = w[x]; *src && ofs < len; src++) 00835 s[ofs++] = *src; 00836 } 00837 if (ofs == len) 00838 ofs--; 00839 s[ofs] = '\0'; 00840 }
|
|
||||||||||||||||||||
|
|
|
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". Returns 0 if val is a NULL pointer, -1 if "true", and 0 otherwise. Definition at line 698 of file utils.c. References ast_strlen_zero(). Referenced by __ast_http_load(), __login_exec(), _parse(), action_agent_logoff(), action_originate(), action_updateconfig(), aji_create_client(), aji_load_config(), apply_outgoing(), ast_jb_read_conf(), build_device(), build_gateway(), build_peer(), build_user(), do_reload(), get_encrypt_methods(), gtalk_load_config(), handle_common_options(), handle_save_dialplan(), init_logger_chain(), init_manager(), jingle_load_config(), load_config(), load_module(), load_moh_classes(), pbx_load_config(), pbx_load_users(), read_agent_config(), reload(), reload_config(), set_config(), start_monitor_action(), strings_to_mask(), and update_common_options(). 00699 { 00700 if (ast_strlen_zero(s)) 00701 return 0; 00702 00703 /* Determine if this is a true value */ 00704 if (!strcasecmp(s, "yes") || 00705 !strcasecmp(s, "true") || 00706 !strcasecmp(s, "y") || 00707 !strcasecmp(s, "t") || 00708 !strcasecmp(s, "1") || 00709 !strcasecmp(s, "on")) 00710 return -1; 00711 00712 return 0; 00713 }
|
|
|
|
|
|
Definition at line 191 of file strings.h. Referenced by ast_str2tos(), ast_tos2str(), dundi_decrypt(), phone_write_buf(), and xml_copy_escape(). |