#include "asterisk.h"
#include <regex.h>
#include <ctype.h>
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/utils.h"
#include "asterisk/app.h"
#include "asterisk/localtime.h"
#include "asterisk/test.h"
Go to the source code of this file.
Defines | |
#define | beginning (cmd[0] == 'U') |
#define | beginning (cmd[0] == 'S') |
#define | HASH_FORMAT HASH_PREFIX "%s~" |
#define | HASH_PREFIX "~HASH~%s~" |
Functions | |
static void | __init_result_buf (void) |
static void | __init_tmp_buf (void) |
static void | __reg_module (void) |
static void | __unreg_module (void) |
static int | acf_strftime (struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t buflen) |
static int | acf_strptime (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen) |
static int | array (struct ast_channel *chan, const char *cmd, char *var, const char *value) |
static void | clearvar_prefix (struct ast_channel *chan, const char *prefix) |
static int | csv_quote (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
static int | exec_clearhash (struct ast_channel *chan, const char *data) |
static int | filter (struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len) |
static int | function_eval (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen) |
static int | function_eval2 (struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t buflen) |
static int | function_fieldnum (struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len) |
static int | function_fieldnum_helper (struct ast_channel *chan, const char *cmd, char *parse, char *buf, struct ast_str **sbuf, ssize_t len) |
static int | function_fieldnum_str (struct ast_channel *chan, const char *cmd, char *parse, struct ast_str **buf, ssize_t len) |
static int | function_fieldqty (struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len) |
static int | function_fieldqty_helper (struct ast_channel *chan, const char *cmd, char *parse, char *buf, struct ast_str **sbuf, ssize_t len) |
static int | function_fieldqty_str (struct ast_channel *chan, const char *cmd, char *parse, struct ast_str **buf, ssize_t len) |
static int | hash_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
static int | hash_write (struct ast_channel *chan, const char *cmd, char *var, const char *value) |
static int | hashkeys_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
static int | hashkeys_read2 (struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len) |
static int | keypadhash (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen) |
static int | len (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen) |
static int | listfilter (struct ast_channel *chan, const char *cmd, char *parse, char *buf, struct ast_str **bufstr, ssize_t len) |
static int | listfilter_read (struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len) |
static int | listfilter_read2 (struct ast_channel *chan, const char *cmd, char *parse, struct ast_str **buf, ssize_t len) |
static int | load_module (void) |
static int | passthru (struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len) |
static int | quote (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
static int | regex (struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len) |
static int | replace (struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len) |
static int | shift_pop (struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len) |
static int | string_tolower (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen) |
static int | string_tolower2 (struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t buflen) |
static int | string_toupper (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen) |
static int | string_toupper2 (struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t buflen) |
static int | unload_module (void) |
static int | unshift_push (struct ast_channel *chan, const char *cmd, char *data, const char *new_value) |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "String handling dialplan functions" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "8586c2a7d357cb591cc3a6607a8f62d1" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } |
static char * | app_clearhash = "ClearHash" |
static struct ast_custom_function | array_function |
static struct ast_module_info * | ast_module_info = &__mod_info |
static struct ast_custom_function | csv_quote_function |
static struct ast_custom_function | eval_function |
static struct ast_custom_function | fieldnum_function |
static struct ast_custom_function | fieldqty_function |
static struct ast_custom_function | filter_function |
static struct ast_custom_function | hash_function |
static struct ast_custom_function | hashkeys_function |
static struct ast_custom_function | keypadhash_function |
static struct ast_custom_function | len_function |
static struct ast_custom_function | listfilter_function |
static struct ast_custom_function | passthru_function |
static struct ast_custom_function | pop_function |
static struct ast_custom_function | push_function |
static struct ast_custom_function | quote_function |
static struct ast_custom_function | regex_function |
static struct ast_custom_function | replace_function |
static struct ast_threadstorage | result_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_result_buf , .custom_init = NULL , } |
static struct ast_custom_function | shift_function |
static struct ast_custom_function | strftime_function |
static struct ast_custom_function | strptime_function |
static struct ast_threadstorage | tmp_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_tmp_buf , .custom_init = NULL , } |
static struct ast_custom_function | tolower_function |
static struct ast_custom_function | toupper_function |
static struct ast_custom_function | unshift_function |
Anothony Minessale II
Definition in file func_strings.c.
#define beginning (cmd[0] == 'U') |
#define beginning (cmd[0] == 'S') |
Referenced by shift_pop(), and unshift_push().
#define HASH_FORMAT HASH_PREFIX "%s~" |
Definition at line 881 of file func_strings.c.
Referenced by array(), hash_read(), and hash_write().
#define HASH_PREFIX "~HASH~%s~" |
Definition at line 880 of file func_strings.c.
Referenced by exec_clearhash(), hashkeys_read(), and hashkeys_read2().
static void __init_result_buf | ( | void | ) | [static] |
Definition at line 43 of file func_strings.c.
00061 : If ${example} contains <literal>ex-amp-le</literal>, then ${FIELDQTY(example,-)} returns 3.</para>
static void __init_tmp_buf | ( | void | ) | [static] |
Definition at line 44 of file func_strings.c.
00061 : If ${example} contains <literal>ex-amp-le</literal>, then ${FIELDQTY(example,-)} returns 3.</para>
static void __reg_module | ( | void | ) | [static] |
Definition at line 1712 of file func_strings.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 1712 of file func_strings.c.
static int acf_strftime | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | parse, | |||
char * | buf, | |||
size_t | buflen | |||
) | [static] |
Definition at line 1208 of file func_strings.c.
References args, AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_get_timeval(), ast_localtime(), ast_log(), AST_STANDARD_APP_ARGS, ast_strftime(), ast_tvnow(), format, and LOG_WARNING.
01210 { 01211 AST_DECLARE_APP_ARGS(args, 01212 AST_APP_ARG(epoch); 01213 AST_APP_ARG(timezone); 01214 AST_APP_ARG(format); 01215 ); 01216 struct timeval when; 01217 struct ast_tm tm; 01218 01219 buf[0] = '\0'; 01220 01221 AST_STANDARD_APP_ARGS(args, parse); 01222 01223 ast_get_timeval(args.epoch, &when, ast_tvnow(), NULL); 01224 ast_localtime(&when, &tm, args.timezone); 01225 01226 if (!args.format) 01227 args.format = "%c"; 01228 01229 if (ast_strftime(buf, buflen, args.format, &tm) <= 0) 01230 ast_log(LOG_WARNING, "C function strftime() output nothing?!!\n"); 01231 01232 buf[buflen - 1] = '\0'; 01233 01234 return 0; 01235 }
static int acf_strptime | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
char * | buf, | |||
size_t | buflen | |||
) | [static] |
Definition at line 1242 of file func_strings.c.
References args, AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_log(), ast_mktime(), AST_STANDARD_APP_ARGS, ast_strlen_zero(), ast_strptime(), format, LOG_ERROR, and LOG_WARNING.
01244 { 01245 AST_DECLARE_APP_ARGS(args, 01246 AST_APP_ARG(timestring); 01247 AST_APP_ARG(timezone); 01248 AST_APP_ARG(format); 01249 ); 01250 struct ast_tm tm; 01251 01252 buf[0] = '\0'; 01253 01254 if (!data) { 01255 ast_log(LOG_ERROR, 01256 "Asterisk function STRPTIME() requires an argument.\n"); 01257 return -1; 01258 } 01259 01260 AST_STANDARD_APP_ARGS(args, data); 01261 01262 if (ast_strlen_zero(args.format)) { 01263 ast_log(LOG_ERROR, 01264 "No format supplied to STRPTIME(<timestring>,<timezone>,<format>)"); 01265 return -1; 01266 } 01267 01268 if (!ast_strptime(args.timestring, args.format, &tm)) { 01269 ast_log(LOG_WARNING, "STRPTIME() found no time specified within the string\n"); 01270 } else { 01271 struct timeval when; 01272 when = ast_mktime(&tm, args.timezone); 01273 snprintf(buf, buflen, "%d", (int) when.tv_sec); 01274 } 01275 01276 return 0; 01277 }
static int array | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | var, | |||
const char * | value | |||
) | [static] |
Definition at line 907 of file func_strings.c.
References AST_APP_ARG, ast_autoservice_stop(), ast_debug, AST_DECLARE_APP_ARGS, AST_STANDARD_APP_ARGS, ast_strdupa, HASH_FORMAT, pbx_builtin_getvar_helper(), pbx_builtin_setvar_helper(), and S_OR.
Referenced by hash_write().
00909 { 00910 AST_DECLARE_APP_ARGS(arg1, 00911 AST_APP_ARG(var)[100]; 00912 ); 00913 AST_DECLARE_APP_ARGS(arg2, 00914 AST_APP_ARG(val)[100]; 00915 ); 00916 char *origvar = "", *value2, varname[256]; 00917 int i, ishash = 0; 00918 00919 value2 = ast_strdupa(value); 00920 if (!var || !value2) 00921 return -1; 00922 00923 if (!strcmp(cmd, "HASH")) { 00924 const char *var2 = pbx_builtin_getvar_helper(chan, "~ODBCFIELDS~"); 00925 origvar = var; 00926 if (var2) 00927 var = ast_strdupa(var2); 00928 else { 00929 if (chan) 00930 ast_autoservice_stop(chan); 00931 return -1; 00932 } 00933 ishash = 1; 00934 } 00935 00936 /* The functions this will generally be used with are SORT and ODBC_*, which 00937 * both return comma-delimited lists. However, if somebody uses literal lists, 00938 * their commas will be translated to vertical bars by the load, and I don't 00939 * want them to be surprised by the result. Hence, we prefer commas as the 00940 * delimiter, but we'll fall back to vertical bars if commas aren't found. 00941 */ 00942 ast_debug(1, "array (%s=%s)\n", var, S_OR(value2, "")); 00943 AST_STANDARD_APP_ARGS(arg1, var); 00944 00945 AST_STANDARD_APP_ARGS(arg2, value2); 00946 00947 for (i = 0; i < arg1.argc; i++) { 00948 ast_debug(1, "array set value (%s=%s)\n", arg1.var[i], 00949 S_OR(arg2.val[i], "")); 00950 if (i < arg2.argc) { 00951 if (ishash) { 00952 if (origvar[0] == '_') { 00953 if (origvar[1] == '_') { 00954 snprintf(varname, sizeof(varname), "__" HASH_FORMAT, origvar + 2, arg1.var[i]); 00955 } else { 00956 snprintf(varname, sizeof(varname), "_" HASH_FORMAT, origvar + 1, arg1.var[i]); 00957 } 00958 } else { 00959 snprintf(varname, sizeof(varname), HASH_FORMAT, origvar, arg1.var[i]); 00960 } 00961 00962 pbx_builtin_setvar_helper(chan, varname, arg2.val[i]); 00963 } else { 00964 pbx_builtin_setvar_helper(chan, arg1.var[i], arg2.val[i]); 00965 } 00966 } else { 00967 /* We could unset the variable, by passing a NULL, but due to 00968 * pushvar semantics, that could create some undesired behavior. */ 00969 if (ishash) { 00970 snprintf(varname, sizeof(varname), HASH_FORMAT, origvar, arg1.var[i]); 00971 pbx_builtin_setvar_helper(chan, varname, ""); 00972 } else { 00973 pbx_builtin_setvar_helper(chan, arg1.var[i], ""); 00974 } 00975 } 00976 } 00977 00978 return 0; 00979 }
static void clearvar_prefix | ( | struct ast_channel * | chan, | |
const char * | prefix | |||
) | [static] |
Definition at line 886 of file func_strings.c.
References ast_free, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_var_name(), ast_var_t::entries, len(), var, and ast_channel::varshead.
Referenced by exec_clearhash().
00887 { 00888 struct ast_var_t *var; 00889 int len = strlen(prefix); 00890 AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->varshead, var, entries) { 00891 if (strncasecmp(prefix, ast_var_name(var), len) == 0) { 00892 AST_LIST_REMOVE_CURRENT(entries); 00893 ast_free(var); 00894 } 00895 } 00896 AST_LIST_TRAVERSE_SAFE_END 00897 }
static int csv_quote | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
char * | buf, | |||
size_t | len | |||
) | [static] |
Definition at line 1155 of file func_strings.c.
References ast_copy_string(), ast_log(), ast_strlen_zero(), and LOG_ERROR.
01156 { 01157 char *bufptr = buf, *dataptr = data; 01158 01159 if (len < 3) { /* at least two for quotes and one for binary zero */ 01160 ast_log(LOG_ERROR, "Not enough buffer"); 01161 return -1; 01162 } 01163 01164 if (ast_strlen_zero(data)) { 01165 ast_copy_string(buf, "\"\"", len); 01166 return 0; 01167 } 01168 01169 *bufptr++ = '"'; 01170 for (; bufptr < buf + len - 3; dataptr++){ 01171 if (*dataptr == '"') { 01172 *bufptr++ = '"'; 01173 *bufptr++ = '"'; 01174 } else if (*dataptr == '\0') { 01175 break; 01176 } else { 01177 *bufptr++ = *dataptr; 01178 } 01179 } 01180 *bufptr++ = '"'; 01181 *bufptr='\0'; 01182 return 0; 01183 }
static int exec_clearhash | ( | struct ast_channel * | chan, | |
const char * | data | |||
) | [static] |
Definition at line 899 of file func_strings.c.
References clearvar_prefix(), HASH_PREFIX, and prefix.
Referenced by load_module().
00900 { 00901 char prefix[80]; 00902 snprintf(prefix, sizeof(prefix), HASH_PREFIX, data ? (char *)data : "null"); 00903 clearvar_prefix(chan, prefix); 00904 return 0; 00905 }
static int filter | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | parse, | |||
char * | buf, | |||
size_t | len | |||
) | [static] |
Definition at line 687 of file func_strings.c.
References args, AST_APP_ARG, ast_debug, AST_DECLARE_APP_ARGS, ast_get_encoded_char(), ast_log(), ast_opt_dont_warn, AST_STANDARD_RAW_ARGS, LOG_ERROR, LOG_WARNING, and string.
Referenced by __ast_data_add(), append_var_and_value_to_filter(), data_filter_destructor(), data_filter_generate(), data_filter_release(), data_result_generate(), data_result_generate_node(), manager_data_get(), realtime_ldap_base_ap(), set_egress_subscription(), update2_ldap(), and update_ldap().
00689 { 00690 AST_DECLARE_APP_ARGS(args, 00691 AST_APP_ARG(allowed); 00692 AST_APP_ARG(string); 00693 ); 00694 char *outbuf = buf; 00695 unsigned char ac; 00696 char allowed[256] = ""; 00697 size_t allowedlen = 0; 00698 int32_t bitfield[8] = { 0, }; /* 256 bits */ 00699 00700 AST_STANDARD_RAW_ARGS(args, parse); 00701 00702 if (!args.string) { 00703 ast_log(LOG_ERROR, "Usage: FILTER(<allowed-chars>,<string>)\n"); 00704 return -1; 00705 } 00706 00707 if (args.allowed[0] == '"' && !ast_opt_dont_warn) { 00708 ast_log(LOG_WARNING, "FILTER allowed characters includes the quote (\") character. This may not be what you want.\n"); 00709 } 00710 00711 /* Expand ranges */ 00712 for (; *(args.allowed);) { 00713 char c1 = 0, c2 = 0; 00714 size_t consumed = 0; 00715 00716 if (ast_get_encoded_char(args.allowed, &c1, &consumed)) 00717 return -1; 00718 args.allowed += consumed; 00719 00720 if (*(args.allowed) == '-') { 00721 if (ast_get_encoded_char(args.allowed + 1, &c2, &consumed)) 00722 c2 = c1; 00723 args.allowed += consumed + 1; 00724 00725 if ((unsigned char) c2 < (unsigned char) c1 && !ast_opt_dont_warn) { 00726 ast_log(LOG_WARNING, "Range wrapping in FILTER(%s,%s). This may not be what you want.\n", parse, args.string); 00727 } 00728 00729 /*!\note 00730 * Looks a little strange, until you realize that we can overflow 00731 * the size of a char. 00732 */ 00733 for (ac = (unsigned char) c1; ac != (unsigned char) c2; ac++) { 00734 bitfield[ac / 32] |= 1 << (ac % 32); 00735 } 00736 bitfield[ac / 32] |= 1 << (ac % 32); 00737 00738 ast_debug(4, "c1=%d, c2=%d\n", c1, c2); 00739 } else { 00740 ac = (unsigned char) c1; 00741 ast_debug(4, "c1=%d, consumed=%d, args.allowed=%s\n", c1, (int) consumed, args.allowed - consumed); 00742 bitfield[ac / 32] |= 1 << (ac % 32); 00743 } 00744 } 00745 00746 for (ac = 1; ac != 0; ac++) { 00747 if (bitfield[ac / 32] & (1 << (ac % 32))) { 00748 allowed[allowedlen++] = ac; 00749 } 00750 } 00751 00752 ast_debug(1, "Allowed: %s\n", allowed); 00753 00754 for (; *(args.string) && (buf + len - 1 > outbuf); (args.string)++) { 00755 if (strchr(allowed, *(args.string))) 00756 *outbuf++ = *(args.string); 00757 } 00758 *outbuf = '\0'; 00759 00760 return 0; 00761 }
static int function_eval | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
char * | buf, | |||
size_t | buflen | |||
) | [static] |
Definition at line 1284 of file func_strings.c.
References ast_log(), ast_strlen_zero(), LOG_WARNING, and pbx_substitute_variables_helper().
01286 { 01287 if (ast_strlen_zero(data)) { 01288 ast_log(LOG_WARNING, "EVAL requires an argument: EVAL(<string>)\n"); 01289 return -1; 01290 } 01291 01292 pbx_substitute_variables_helper(chan, data, buf, buflen - 1); 01293 01294 return 0; 01295 }
static int function_eval2 | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
struct ast_str ** | buf, | |||
ssize_t | buflen | |||
) | [static] |
Definition at line 1297 of file func_strings.c.
References ast_log(), ast_str_substitute_variables(), ast_strlen_zero(), and LOG_WARNING.
01299 { 01300 if (ast_strlen_zero(data)) { 01301 ast_log(LOG_WARNING, "EVAL requires an argument: EVAL(<string>)\n"); 01302 return -1; 01303 } 01304 01305 ast_str_substitute_variables(buf, buflen, chan, data); 01306 01307 return 0; 01308 }
static int function_fieldnum | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | parse, | |||
char * | buf, | |||
size_t | len | |||
) | [static] |
Definition at line 540 of file func_strings.c.
References function_fieldnum_helper().
00542 { 00543 return function_fieldnum_helper(chan, cmd, parse, buf, NULL, len); 00544 }
static int function_fieldnum_helper | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | parse, | |||
char * | buf, | |||
struct ast_str ** | sbuf, | |||
ssize_t | len | |||
) | [static] |
Definition at line 479 of file func_strings.c.
References args, AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_get_encoded_char(), ast_log(), AST_STANDARD_APP_ARGS, ast_str_buffer(), ast_str_set(), ast_str_strlen(), ast_str_substitute_variables(), ast_str_thread_get(), ast_strlen_zero(), LOG_ERROR, result_buf, str, and strsep().
Referenced by function_fieldnum(), and function_fieldnum_str().
00481 { 00482 char *varsubst, *field; 00483 struct ast_str *str = ast_str_thread_get(&result_buf, 16); 00484 int fieldindex = 0, res = 0; 00485 AST_DECLARE_APP_ARGS(args, 00486 AST_APP_ARG(varname); 00487 AST_APP_ARG(delim); 00488 AST_APP_ARG(field); 00489 ); 00490 char delim[2] = ""; 00491 size_t delim_used; 00492 00493 if (!str) { 00494 return -1; 00495 } 00496 00497 AST_STANDARD_APP_ARGS(args, parse); 00498 00499 if (args.argc < 3) { 00500 ast_log(LOG_ERROR, "Usage: FIELDNUM(<listname>,<delimiter>,<fieldvalue>)\n"); 00501 res = -1; 00502 } else { 00503 varsubst = alloca(strlen(args.varname) + 4); 00504 sprintf(varsubst, "${%s}", args.varname); 00505 00506 ast_str_substitute_variables(&str, 0, chan, varsubst); 00507 00508 if (ast_str_strlen(str) == 0 || ast_strlen_zero(args.delim)) { 00509 fieldindex = 0; 00510 } else if (ast_get_encoded_char(args.delim, delim, &delim_used) == -1) { 00511 res = -1; 00512 } else { 00513 char *varval = ast_str_buffer(str); 00514 00515 while ((field = strsep(&varval, delim)) != NULL) { 00516 fieldindex++; 00517 00518 if (!strcasecmp(field, args.field)) { 00519 break; 00520 } 00521 } 00522 00523 if (!field) { 00524 fieldindex = 0; 00525 } 00526 00527 res = 0; 00528 } 00529 } 00530 00531 if (sbuf) { 00532 ast_str_set(sbuf, len, "%d", fieldindex); 00533 } else { 00534 snprintf(buf, len, "%d", fieldindex); 00535 } 00536 00537 return res; 00538 }
static int function_fieldnum_str | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | parse, | |||
struct ast_str ** | buf, | |||
ssize_t | len | |||
) | [static] |
Definition at line 546 of file func_strings.c.
References function_fieldnum_helper().
00548 { 00549 return function_fieldnum_helper(chan, cmd, parse, NULL, buf, len); 00550 }
static int function_fieldqty | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | parse, | |||
char * | buf, | |||
size_t | len | |||
) | [static] |
Definition at line 461 of file func_strings.c.
References function_fieldqty_helper().
00463 { 00464 return function_fieldqty_helper(chan, cmd, parse, buf, NULL, len); 00465 }
static int function_fieldqty_helper | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | parse, | |||
char * | buf, | |||
struct ast_str ** | sbuf, | |||
ssize_t | len | |||
) | [static] |
Definition at line 416 of file func_strings.c.
References args, AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_get_encoded_char(), AST_STANDARD_APP_ARGS, ast_str_buffer(), ast_str_set(), ast_str_strlen(), ast_str_substitute_variables(), ast_str_thread_get(), result_buf, str, and strsep().
Referenced by function_fieldqty(), and function_fieldqty_str().
00418 { 00419 char *varsubst; 00420 struct ast_str *str = ast_str_thread_get(&result_buf, 16); 00421 int fieldcount = 0; 00422 AST_DECLARE_APP_ARGS(args, 00423 AST_APP_ARG(varname); 00424 AST_APP_ARG(delim); 00425 ); 00426 char delim[2] = ""; 00427 size_t delim_used; 00428 00429 if (!str) { 00430 return -1; 00431 } 00432 00433 AST_STANDARD_APP_ARGS(args, parse); 00434 if (args.delim) { 00435 ast_get_encoded_char(args.delim, delim, &delim_used); 00436 00437 varsubst = alloca(strlen(args.varname) + 4); 00438 00439 sprintf(varsubst, "${%s}", args.varname); 00440 ast_str_substitute_variables(&str, 0, chan, varsubst); 00441 if (ast_str_strlen(str) == 0) { 00442 fieldcount = 0; 00443 } else { 00444 char *varval = ast_str_buffer(str); 00445 while (strsep(&varval, delim)) { 00446 fieldcount++; 00447 } 00448 } 00449 } else { 00450 fieldcount = 1; 00451 } 00452 if (sbuf) { 00453 ast_str_set(sbuf, len, "%d", fieldcount); 00454 } else { 00455 snprintf(buf, len, "%d", fieldcount); 00456 } 00457 00458 return 0; 00459 }
static int function_fieldqty_str | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | parse, | |||
struct ast_str ** | buf, | |||
ssize_t | len | |||
) | [static] |
Definition at line 467 of file func_strings.c.
References function_fieldqty_helper().
00469 { 00470 return function_fieldqty_helper(chan, cmd, parse, NULL, buf, len); 00471 }
static int hash_read | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
char * | buf, | |||
size_t | len | |||
) | [static] |
Definition at line 1053 of file func_strings.c.
References AST_APP_ARG, ast_copy_string(), AST_DECLARE_APP_ARGS, AST_STANDARD_APP_ARGS, HASH_FORMAT, hashkeys_read(), pbx_builtin_getvar_helper(), and pbx_builtin_setvar_helper().
01054 { 01055 char varname[256]; 01056 const char *varvalue; 01057 AST_DECLARE_APP_ARGS(arg, 01058 AST_APP_ARG(hashname); 01059 AST_APP_ARG(hashkey); 01060 ); 01061 01062 AST_STANDARD_APP_ARGS(arg, data); 01063 if (arg.argc == 2) { 01064 snprintf(varname, sizeof(varname), HASH_FORMAT, arg.hashname, arg.hashkey); 01065 varvalue = pbx_builtin_getvar_helper(chan, varname); 01066 if (varvalue) 01067 ast_copy_string(buf, varvalue, len); 01068 else 01069 *buf = '\0'; 01070 } else if (arg.argc == 1) { 01071 char colnames[4096]; 01072 int i; 01073 AST_DECLARE_APP_ARGS(arg2, 01074 AST_APP_ARG(col)[100]; 01075 ); 01076 01077 /* Get column names, in no particular order */ 01078 hashkeys_read(chan, "HASHKEYS", arg.hashname, colnames, sizeof(colnames)); 01079 pbx_builtin_setvar_helper(chan, "~ODBCFIELDS~", colnames); 01080 01081 AST_STANDARD_APP_ARGS(arg2, colnames); 01082 *buf = '\0'; 01083 01084 /* Now get the corresponding column values, in exactly the same order */ 01085 for (i = 0; i < arg2.argc; i++) { 01086 snprintf(varname, sizeof(varname), HASH_FORMAT, arg.hashname, arg2.col[i]); 01087 varvalue = pbx_builtin_getvar_helper(chan, varname); 01088 strncat(buf, varvalue, len - strlen(buf) - 1); 01089 strncat(buf, ",", len - strlen(buf) - 1); 01090 } 01091 01092 /* Strip trailing comma */ 01093 buf[strlen(buf) - 1] = '\0'; 01094 } 01095 01096 return 0; 01097 }
static int hash_write | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | var, | |||
const char * | value | |||
) | [static] |
Definition at line 1025 of file func_strings.c.
References array(), AST_APP_ARG, AST_DECLARE_APP_ARGS, AST_STANDARD_APP_ARGS, HASH_FORMAT, and pbx_builtin_setvar_helper().
01026 { 01027 char varname[256]; 01028 AST_DECLARE_APP_ARGS(arg, 01029 AST_APP_ARG(hashname); 01030 AST_APP_ARG(hashkey); 01031 ); 01032 01033 if (!strchr(var, ',')) { 01034 /* Single argument version */ 01035 return array(chan, "HASH", var, value); 01036 } 01037 01038 AST_STANDARD_APP_ARGS(arg, var); 01039 if (arg.hashname[0] == '_') { 01040 if (arg.hashname[1] == '_') { 01041 snprintf(varname, sizeof(varname), "__" HASH_FORMAT, arg.hashname + 2, arg.hashkey); 01042 } else { 01043 snprintf(varname, sizeof(varname), "_" HASH_FORMAT, arg.hashname + 1, arg.hashkey); 01044 } 01045 } else { 01046 snprintf(varname, sizeof(varname), HASH_FORMAT, arg.hashname, arg.hashkey); 01047 } 01048 pbx_builtin_setvar_helper(chan, varname, value); 01049 01050 return 0; 01051 }
static int hashkeys_read | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
char * | buf, | |||
size_t | len | |||
) | [static] |
Definition at line 981 of file func_strings.c.
References AST_LIST_TRAVERSE, ast_str_alloca, ast_str_buffer(), ast_str_set(), ast_str_strlen(), ast_var_name(), HASH_PREFIX, prefix, and ast_channel::varshead.
Referenced by hash_read().
00982 { 00983 struct ast_var_t *newvar; 00984 struct ast_str *prefix = ast_str_alloca(80); 00985 00986 ast_str_set(&prefix, -1, HASH_PREFIX, data); 00987 memset(buf, 0, len); 00988 00989 AST_LIST_TRAVERSE(&chan->varshead, newvar, entries) { 00990 if (strncasecmp(ast_str_buffer(prefix), ast_var_name(newvar), ast_str_strlen(prefix)) == 0) { 00991 /* Copy everything after the prefix */ 00992 strncat(buf, ast_var_name(newvar) + ast_str_strlen(prefix), len - strlen(buf) - 1); 00993 /* Trim the trailing ~ */ 00994 buf[strlen(buf) - 1] = ','; 00995 } 00996 } 00997 /* Trim the trailing comma */ 00998 buf[strlen(buf) - 1] = '\0'; 00999 return 0; 01000 }
static int hashkeys_read2 | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
struct ast_str ** | buf, | |||
ssize_t | len | |||
) | [static] |
Definition at line 1002 of file func_strings.c.
References AST_LIST_TRAVERSE, ast_str_alloca, ast_str_append(), ast_str_buffer(), ast_str_set(), ast_str_strlen(), ast_var_name(), HASH_PREFIX, prefix, and ast_channel::varshead.
01003 { 01004 struct ast_var_t *newvar; 01005 struct ast_str *prefix = ast_str_alloca(80); 01006 char *tmp; 01007 01008 ast_str_set(&prefix, -1, HASH_PREFIX, data); 01009 01010 AST_LIST_TRAVERSE(&chan->varshead, newvar, entries) { 01011 if (strncasecmp(ast_str_buffer(prefix), ast_var_name(newvar), ast_str_strlen(prefix)) == 0) { 01012 /* Copy everything after the prefix */ 01013 ast_str_append(buf, len, "%s", ast_var_name(newvar) + ast_str_strlen(prefix)); 01014 /* Trim the trailing ~ */ 01015 tmp = ast_str_buffer(*buf); 01016 tmp[ast_str_strlen(*buf) - 1] = ','; 01017 } 01018 } 01019 /* Trim the trailing comma */ 01020 tmp = ast_str_buffer(*buf); 01021 tmp[ast_str_strlen(*buf) - 1] = '\0'; 01022 return 0; 01023 }
static int keypadhash | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
char * | buf, | |||
size_t | buflen | |||
) | [static] |
Definition at line 1316 of file func_strings.c.
01317 { 01318 char *bufptr, *dataptr; 01319 01320 for (bufptr = buf, dataptr = data; bufptr < buf + buflen - 1; dataptr++) { 01321 if (*dataptr == '\0') { 01322 *bufptr++ = '\0'; 01323 break; 01324 } else if (*dataptr == '1') { 01325 *bufptr++ = '1'; 01326 } else if (strchr("AaBbCc2", *dataptr)) { 01327 *bufptr++ = '2'; 01328 } else if (strchr("DdEeFf3", *dataptr)) { 01329 *bufptr++ = '3'; 01330 } else if (strchr("GgHhIi4", *dataptr)) { 01331 *bufptr++ = '4'; 01332 } else if (strchr("JjKkLl5", *dataptr)) { 01333 *bufptr++ = '5'; 01334 } else if (strchr("MmNnOo6", *dataptr)) { 01335 *bufptr++ = '6'; 01336 } else if (strchr("PpQqRrSs7", *dataptr)) { 01337 *bufptr++ = '7'; 01338 } else if (strchr("TtUuVv8", *dataptr)) { 01339 *bufptr++ = '8'; 01340 } else if (strchr("WwXxYyZz9", *dataptr)) { 01341 *bufptr++ = '9'; 01342 } else if (*dataptr == '0') { 01343 *bufptr++ = '0'; 01344 } 01345 } 01346 buf[buflen - 1] = '\0'; 01347 01348 return 0; 01349 }
static int len | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
char * | buf, | |||
size_t | buflen | |||
) | [static] |
Definition at line 1190 of file func_strings.c.
Referenced by __analog_ss_thread(), __ast_cli_register(), __ast_str_helper(), __get_header(), __rtp_recvfrom(), __rtp_sendto(), _parse(), _sip_tcp_helper_thread(), add_sdp(), ael_token_subst(), aji_io_recv(), aji_recv(), aji_send_header(), aji_send_raw(), aji_start_sasl(), alsa_write(), analog_ss_thread(), aoc_parse_ie(), append_interface(), append_var_and_value_to_filter(), ast_agi_register_multiple(), ast_agi_unregister_multiple(), ast_app_group_set_channel(), ast_callerid_vmwi_generate(), ast_cdr_appenduserfield(), ast_cli_complete(), ast_codec_get_len(), ast_complete_source_filename(), ast_dsp_noise(), ast_dsp_process(), ast_dsp_silence(), ast_event_cb(), ast_format_str_reduce(), ast_frdup(), ast_getformatname_multiple(), ast_http_send(), ast_http_uri_link(), ast_mkdir(), ast_pri_pack_hex_string(), ast_read_image(), ast_rtcp_write_rr(), ast_rtcp_write_sr(), ast_rtp_read(), ast_say_number_full_ka(), ast_smoother_read(), ast_sockaddr_resolve(), ast_str_substitute_variables_full(), ast_translate(), ast_udptl_write(), ast_xmldoc_printable(), authenticate(), build_device(), build_facility(), build_route(), callerid_generate(), cleaned_basedn(), clearvar_prefix(), cli_console_sendtext(), complete_agent_logoff_cmd(), complete_dialplan_add_extension(), complete_dialplan_add_ignorepat(), complete_dialplan_add_include(), complete_dialplan_remove_extension(), complete_dialplan_remove_ignorepat(), complete_dialplan_remove_include(), complete_meetmecmd(), complete_peer_helper(), complete_trans_path_choice(), conf_play(), config_jitterbuffer(), cops_getmsg(), copy(), create_video_frame(), dahdi_sendtext(), dahdi_setoption(), devstate_write(), dialgroup_refreshdb(), dictate_exec(), do_pktccops(), dundi_encrypt(), dundi_parse_ies(), dundi_send(), enc_ie_facility(), evt_event_deliver_cb(), expr2_token_subst(), ffmpeg_decode(), find_by_part(), get_body(), get_ip_and_port_from_sdp(), get_sdp(), get_sdp_iterate(), get_to_address(), gsm_write(), gsmtolin_framein(), h261_encap(), h263_encap(), h263_read(), h263_write(), h263p_encap(), h264_read(), h264_write(), handle_cli_core_show_translation(), handle_cli_devstate_change(), handle_commandmatchesarray(), handle_incoming(), handle_output(), handle_response(), handle_show_sysinfo(), help1(), iax_parse_ies(), iax_str2flags(), launch_monitor_thread(), listener(), load_file(), local_call(), lpc10tolin_framein(), message_template_parse_emailbody(), method_match(), mgcp_ss(), mgcpsock_read(), misdn_read(), monmp3thread(), mpeg4_encap(), newpvt(), ogg_vorbis_read(), parse_ie(), ParseBookmark(), pbx_load_users(), pbx_substitute_variables_helper_full(), phoneprov_callback(), pri_ss_thread(), process_sdp(), read_credentials(), readfile_exec(), red_t140_to_red(), reschedule_precache(), run_agi(), scan_thread(), set_egress_subscription(), sig_pri_set_subaddress(), sip_addheader(), sip_show_channel(), sip_show_history(), skinny_ss(), sms_messagetx(), socket_read(), static_callback(), term_filter_escapes(), transfer_exec(), udptl_build_packet(), unistim_sp(), unquote(), wav_write(), and xmldoc_get_syntax_fun().
01191 { 01192 int length = 0; 01193 01194 if (data) 01195 length = strlen(data); 01196 01197 snprintf(buf, buflen, "%d", length); 01198 01199 return 0; 01200 }
static int listfilter | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | parse, | |||
char * | buf, | |||
struct ast_str ** | bufstr, | |||
ssize_t | len | |||
) | [static] |
Definition at line 558 of file func_strings.c.
References args, AST_APP_ARG, ast_channel_lock, ast_channel_unlock, ast_copy_string(), AST_DECLARE_APP_ARGS, ast_get_encoded_str(), ast_log(), AST_STANDARD_APP_ARGS, ast_str_append(), ast_str_append_substr(), ast_str_buffer(), ast_str_make_space(), ast_str_reset(), ast_str_set(), ast_str_strlen(), ast_str_substitute_variables(), ast_str_thread_get(), first, LOG_ERROR, result_buf, and tmp_buf.
Referenced by listfilter_read(), and listfilter_read2().
00559 { 00560 AST_DECLARE_APP_ARGS(args, 00561 AST_APP_ARG(listname); 00562 AST_APP_ARG(delimiter); 00563 AST_APP_ARG(fieldvalue); 00564 ); 00565 const char *ptr; 00566 struct ast_str *orig_list = ast_str_thread_get(&tmp_buf, 16); 00567 const char *begin, *cur, *next; 00568 int dlen, flen, first = 1; 00569 struct ast_str *result, **result_ptr = &result; 00570 char *delim, *varsubst; 00571 00572 AST_STANDARD_APP_ARGS(args, parse); 00573 00574 if (buf) { 00575 if (!(result = ast_str_thread_get(&result_buf, 16))) { 00576 return -1; 00577 } 00578 } else { 00579 /* Place the result directly into the output buffer */ 00580 result_ptr = bufstr; 00581 } 00582 00583 if (args.argc < 3) { 00584 ast_log(LOG_ERROR, "Usage: LISTFILTER(<listname>,<delimiter>,<fieldvalue>)\n"); 00585 return -1; 00586 } 00587 00588 varsubst = alloca(strlen(args.listname) + 4); 00589 sprintf(varsubst, "${%s}", args.listname); 00590 00591 /* If we don't lock the channel, the variable could disappear out from underneath us. */ 00592 if (chan) { 00593 ast_channel_lock(chan); 00594 } 00595 ast_str_substitute_variables(&orig_list, 0, chan, varsubst); 00596 if (!ast_str_strlen(orig_list)) { 00597 ast_log(LOG_ERROR, "List variable '%s' not found\n", args.listname); 00598 if (chan) { 00599 ast_channel_unlock(chan); 00600 } 00601 return -1; 00602 } 00603 00604 /* If the string isn't there, just copy out the string and be done with it. */ 00605 if (!(ptr = strstr(ast_str_buffer(orig_list), args.fieldvalue))) { 00606 if (buf) { 00607 ast_copy_string(buf, ast_str_buffer(orig_list), len); 00608 } else { 00609 ast_str_set(result_ptr, len, "%s", ast_str_buffer(orig_list)); 00610 } 00611 if (chan) { 00612 ast_channel_unlock(chan); 00613 } 00614 return 0; 00615 } 00616 00617 dlen = strlen(args.delimiter); 00618 delim = alloca(dlen + 1); 00619 ast_get_encoded_str(args.delimiter, delim, dlen + 1); 00620 00621 if ((dlen = strlen(delim)) == 0) { 00622 delim = ","; 00623 dlen = 1; 00624 } 00625 00626 flen = strlen(args.fieldvalue); 00627 00628 ast_str_reset(*result_ptr); 00629 /* Enough space for any result */ 00630 if (len > -1) { 00631 ast_str_make_space(result_ptr, len ? len : ast_str_strlen(orig_list) + 1); 00632 } 00633 00634 begin = ast_str_buffer(orig_list); 00635 next = strstr(begin, delim); 00636 00637 do { 00638 /* Find next boundary */ 00639 if (next) { 00640 cur = next; 00641 next = strstr(cur + dlen, delim); 00642 } else { 00643 cur = strchr(begin + dlen, '\0'); 00644 } 00645 00646 if (flen == cur - begin && !strncmp(begin, args.fieldvalue, flen)) { 00647 /* Skip field */ 00648 begin += flen + dlen; 00649 } else { 00650 /* Copy field to output */ 00651 if (!first) { 00652 ast_str_append(result_ptr, len, "%s", delim); 00653 } 00654 00655 ast_str_append_substr(result_ptr, len, begin, cur - begin); 00656 first = 0; 00657 begin = cur + dlen; 00658 } 00659 } while (*cur != '\0'); 00660 if (chan) { 00661 ast_channel_unlock(chan); 00662 } 00663 00664 if (buf) { 00665 ast_copy_string(buf, ast_str_buffer(result), len); 00666 } 00667 00668 return 0; 00669 }
static int listfilter_read | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | parse, | |||
char * | buf, | |||
size_t | len | |||
) | [static] |
Definition at line 671 of file func_strings.c.
References listfilter().
00672 { 00673 return listfilter(chan, cmd, parse, buf, NULL, len); 00674 }
static int listfilter_read2 | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | parse, | |||
struct ast_str ** | buf, | |||
ssize_t | len | |||
) | [static] |
Definition at line 676 of file func_strings.c.
References listfilter().
00677 { 00678 return listfilter(chan, cmd, parse, NULL, buf, len); 00679 }
static int load_module | ( | void | ) | [static] |
Definition at line 1678 of file func_strings.c.
References app_clearhash, array_function, ast_custom_function_register, ast_register_application_xml, AST_TEST_REGISTER, csv_quote_function, eval_function, exec_clearhash(), fieldnum_function, fieldqty_function, filter_function, hash_function, hashkeys_function, keypadhash_function, len_function, listfilter_function, passthru_function, pop_function, push_function, quote_function, regex_function, replace_function, shift_function, strftime_function, strptime_function, tolower_function, toupper_function, and unshift_function.
01679 { 01680 int res = 0; 01681 01682 AST_TEST_REGISTER(test_FIELDNUM); 01683 AST_TEST_REGISTER(test_FILTER); 01684 res |= ast_custom_function_register(&fieldqty_function); 01685 res |= ast_custom_function_register(&fieldnum_function); 01686 res |= ast_custom_function_register(&filter_function); 01687 res |= ast_custom_function_register(&replace_function); 01688 res |= ast_custom_function_register(&listfilter_function); 01689 res |= ast_custom_function_register(®ex_function); 01690 res |= ast_custom_function_register(&array_function); 01691 res |= ast_custom_function_register("e_function); 01692 res |= ast_custom_function_register(&csv_quote_function); 01693 res |= ast_custom_function_register(&len_function); 01694 res |= ast_custom_function_register(&strftime_function); 01695 res |= ast_custom_function_register(&strptime_function); 01696 res |= ast_custom_function_register(&eval_function); 01697 res |= ast_custom_function_register(&keypadhash_function); 01698 res |= ast_custom_function_register(&hashkeys_function); 01699 res |= ast_custom_function_register(&hash_function); 01700 res |= ast_register_application_xml(app_clearhash, exec_clearhash); 01701 res |= ast_custom_function_register(&toupper_function); 01702 res |= ast_custom_function_register(&tolower_function); 01703 res |= ast_custom_function_register(&shift_function); 01704 res |= ast_custom_function_register(&pop_function); 01705 res |= ast_custom_function_register(&push_function); 01706 res |= ast_custom_function_register(&unshift_function); 01707 res |= ast_custom_function_register(&passthru_function); 01708 01709 return res; 01710 }
static int passthru | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
struct ast_str ** | buf, | |||
ssize_t | len | |||
) | [static] |
Definition at line 1530 of file func_strings.c.
References ast_str_set().
01531 { 01532 ast_str_set(buf, len, "%s", data); 01533 return 0; 01534 }
static int quote | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
char * | buf, | |||
size_t | len | |||
) | [static] |
Definition at line 1116 of file func_strings.c.
References ast_copy_string(), ast_log(), ast_strlen_zero(), LOG_ERROR, and LOG_WARNING.
Referenced by __ast_app_separate_args(), and parse_options().
01117 { 01118 char *bufptr = buf, *dataptr = data; 01119 01120 if (len < 3){ /* at least two for quotes and one for binary zero */ 01121 ast_log(LOG_ERROR, "Not enough buffer"); 01122 return -1; 01123 } 01124 01125 if (ast_strlen_zero(data)) { 01126 ast_log(LOG_WARNING, "No argument specified!\n"); 01127 ast_copy_string(buf, "\"\"", len); 01128 return 0; 01129 } 01130 01131 *bufptr++ = '"'; 01132 for (; bufptr < buf + len - 3; dataptr++) { 01133 if (*dataptr == '\\') { 01134 *bufptr++ = '\\'; 01135 *bufptr++ = '\\'; 01136 } else if (*dataptr == '"') { 01137 *bufptr++ = '\\'; 01138 *bufptr++ = '"'; 01139 } else if (*dataptr == '\0') { 01140 break; 01141 } else { 01142 *bufptr++ = *dataptr; 01143 } 01144 } 01145 *bufptr++ = '"'; 01146 *bufptr = '\0'; 01147 return 0; 01148 }
static int regex | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | parse, | |||
char * | buf, | |||
size_t | len | |||
) | [static] |
Definition at line 838 of file func_strings.c.
References args, AST_APP_ARG, ast_debug, AST_DECLARE_APP_ARGS, ast_log(), AST_NONSTANDARD_APP_ARGS, LOG_ERROR, LOG_WARNING, and str.
00840 { 00841 AST_DECLARE_APP_ARGS(args, 00842 AST_APP_ARG(null); 00843 AST_APP_ARG(reg); 00844 AST_APP_ARG(str); 00845 ); 00846 int errcode; 00847 regex_t regexbuf; 00848 00849 buf[0] = '\0'; 00850 00851 AST_NONSTANDARD_APP_ARGS(args, parse, '"'); 00852 00853 if (args.argc != 3) { 00854 ast_log(LOG_ERROR, "Unexpected arguments: should have been in the form '\"<regex>\" <string>'\n"); 00855 return -1; 00856 } 00857 if ((*args.str == ' ') || (*args.str == '\t')) 00858 args.str++; 00859 00860 ast_debug(1, "FUNCTION REGEX (%s)(%s)\n", args.reg, args.str); 00861 00862 if ((errcode = regcomp(®exbuf, args.reg, REG_EXTENDED | REG_NOSUB))) { 00863 regerror(errcode, ®exbuf, buf, len); 00864 ast_log(LOG_WARNING, "Malformed input %s(%s): %s\n", cmd, parse, buf); 00865 return -1; 00866 } 00867 00868 strcpy(buf, regexec(®exbuf, args.str, 0, NULL, 0) ? "0" : "1"); 00869 00870 regfree(®exbuf); 00871 00872 return 0; 00873 }
static int replace | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
struct ast_str ** | buf, | |||
ssize_t | len | |||
) | [static] |
Definition at line 768 of file func_strings.c.
References args, AST_APP_ARG, ast_debug, AST_DECLARE_APP_ARGS, ast_get_encoded_char(), ast_get_encoded_str(), ast_log(), AST_STANDARD_APP_ARGS, ast_str_buffer(), ast_str_set(), ast_str_strlen(), ast_str_substitute_variables(), ast_str_thread_get(), ast_strlen_zero(), LOG_ERROR, result_buf, and str.
Referenced by process_text_line().
00769 { 00770 AST_DECLARE_APP_ARGS(args, 00771 AST_APP_ARG(varname); 00772 AST_APP_ARG(find); 00773 AST_APP_ARG(replace); 00774 ); 00775 char *strptr, *varsubst; 00776 struct ast_str *str = ast_str_thread_get(&result_buf, 16); 00777 char find[256]; /* Only 256 characters possible */ 00778 char replace[2] = ""; 00779 size_t unused; 00780 00781 AST_STANDARD_APP_ARGS(args, data); 00782 00783 if (!str) { 00784 return -1; 00785 } 00786 00787 if (args.argc < 2) { 00788 ast_log(LOG_ERROR, "Usage: %s(<varname>,<search-chars>[,<replace-char>])\n", cmd); 00789 return -1; 00790 } 00791 00792 /* Decode escapes */ 00793 ast_get_encoded_str(args.find, find, sizeof(find)); 00794 ast_get_encoded_char(args.replace, replace, &unused); 00795 00796 if (ast_strlen_zero(find) || ast_strlen_zero(args.varname)) { 00797 ast_log(LOG_ERROR, "The characters to search for and the variable name must not be empty.\n"); 00798 return -1; 00799 } 00800 00801 varsubst = alloca(strlen(args.varname) + 4); 00802 sprintf(varsubst, "${%s}", args.varname); 00803 ast_str_substitute_variables(&str, 0, chan, varsubst); 00804 00805 if (!ast_str_strlen(str)) { 00806 /* Blank, nothing to replace */ 00807 return -1; 00808 } 00809 00810 ast_debug(3, "String to search: (%s)\n", ast_str_buffer(str)); 00811 ast_debug(3, "Characters to find: (%s)\n", find); 00812 ast_debug(3, "Character to replace with: (%s)\n", replace); 00813 00814 for (strptr = ast_str_buffer(str); *strptr; strptr++) { 00815 /* buf is already a mutable buffer, so we construct the result 00816 * directly there */ 00817 if (strchr(find, *strptr)) { 00818 if (ast_strlen_zero(replace)) { 00819 /* Remove character */ 00820 strcpy(strptr, strptr + 1); /* SAFE */ 00821 strptr--; 00822 } else { 00823 /* Replace character */ 00824 *strptr = *replace; 00825 } 00826 } 00827 } 00828 00829 ast_str_set(buf, len, "%s", ast_str_buffer(str)); 00830 return 0; 00831 }
static int shift_pop | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
struct ast_str ** | buf, | |||
ssize_t | len | |||
) | [static] |
Definition at line 1414 of file func_strings.c.
References args, AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_get_encoded_char(), ast_log(), AST_STANDARD_APP_ARGS, ast_str_buffer(), ast_str_set(), ast_str_strlen(), ast_str_substitute_variables(), ast_str_thread_get(), ast_strlen_zero(), beginning, LOG_WARNING, pbx_builtin_setvar_helper(), result_buf, and var.
01415 { 01416 #define beginning (cmd[0] == 'S') /* SHIFT */ 01417 char *after, delimiter[2] = ",", *varsubst; 01418 size_t unused; 01419 struct ast_str *before = ast_str_thread_get(&result_buf, 16); 01420 char *(*search_func)(const char *s, int c) = (beginning ? strchr : strrchr); 01421 AST_DECLARE_APP_ARGS(args, 01422 AST_APP_ARG(var); 01423 AST_APP_ARG(delimiter); 01424 ); 01425 01426 if (!before) { 01427 return -1; 01428 } 01429 01430 AST_STANDARD_APP_ARGS(args, data); 01431 01432 if (ast_strlen_zero(args.var)) { 01433 ast_log(LOG_WARNING, "%s requires a variable name\n", cmd); 01434 return -1; 01435 } 01436 01437 varsubst = alloca(strlen(args.var) + 4); 01438 sprintf(varsubst, "${%s}", args.var); 01439 ast_str_substitute_variables(&before, 0, chan, varsubst); 01440 01441 if (args.argc > 1 && !ast_strlen_zero(args.delimiter)) { 01442 ast_get_encoded_char(args.delimiter, delimiter, &unused); 01443 } 01444 01445 if (!ast_str_strlen(before)) { 01446 /* Nothing to pop */ 01447 return -1; 01448 } 01449 01450 if (!(after = search_func(ast_str_buffer(before), delimiter[0]))) { 01451 /* Only one entry in array */ 01452 ast_str_set(buf, len, "%s", ast_str_buffer(before)); 01453 pbx_builtin_setvar_helper(chan, args.var, ""); 01454 } else { 01455 *after++ = '\0'; 01456 ast_str_set(buf, len, "%s", beginning ? ast_str_buffer(before) : after); 01457 pbx_builtin_setvar_helper(chan, args.var, beginning ? after : ast_str_buffer(before)); 01458 } 01459 01460 return 0; 01461 #undef beginning 01462 }
static int string_tolower | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
char * | buf, | |||
size_t | buflen | |||
) | [static] |
Definition at line 1385 of file func_strings.c.
01386 { 01387 char *bufptr = buf, *dataptr = data; 01388 01389 while ((bufptr < buf + buflen - 1) && (*bufptr++ = tolower(*dataptr++))); 01390 01391 return 0; 01392 }
static int string_tolower2 | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
struct ast_str ** | buf, | |||
ssize_t | buflen | |||
) | [static] |
Definition at line 1394 of file func_strings.c.
References ast_str_buffer(), ast_str_make_space(), ast_str_size(), and ast_str_update().
01395 { 01396 char *bufptr, *dataptr = data; 01397 01398 if (buflen > -1) { 01399 ast_str_make_space(buf, buflen > 0 ? buflen : strlen(data) + 1); 01400 } 01401 bufptr = ast_str_buffer(*buf); 01402 while ((bufptr < ast_str_buffer(*buf) + ast_str_size(*buf) - 1) && (*bufptr++ = tolower(*dataptr++))); 01403 ast_str_update(*buf); 01404 01405 return 0; 01406 }
static int string_toupper | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
char * | buf, | |||
size_t | buflen | |||
) | [static] |
Definition at line 1356 of file func_strings.c.
01357 { 01358 char *bufptr = buf, *dataptr = data; 01359 01360 while ((bufptr < buf + buflen - 1) && (*bufptr++ = toupper(*dataptr++))); 01361 01362 return 0; 01363 }
static int string_toupper2 | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
struct ast_str ** | buf, | |||
ssize_t | buflen | |||
) | [static] |
Definition at line 1365 of file func_strings.c.
References ast_str_buffer(), ast_str_make_space(), ast_str_size(), and ast_str_update().
01366 { 01367 char *bufptr, *dataptr = data; 01368 01369 if (buflen > -1) { 01370 ast_str_make_space(buf, buflen > 0 ? buflen : strlen(data) + 1); 01371 } 01372 bufptr = ast_str_buffer(*buf); 01373 while ((bufptr < ast_str_buffer(*buf) + ast_str_size(*buf) - 1) && (*bufptr++ = toupper(*dataptr++))); 01374 ast_str_update(*buf); 01375 01376 return 0; 01377 }
static int unload_module | ( | void | ) | [static] |
Definition at line 1644 of file func_strings.c.
References app_clearhash, array_function, ast_custom_function_unregister(), AST_TEST_UNREGISTER, ast_unregister_application(), csv_quote_function, eval_function, fieldnum_function, fieldqty_function, filter_function, hash_function, hashkeys_function, keypadhash_function, len_function, listfilter_function, passthru_function, pop_function, push_function, quote_function, regex_function, replace_function, shift_function, strftime_function, strptime_function, tolower_function, toupper_function, and unshift_function.
01645 { 01646 int res = 0; 01647 01648 AST_TEST_UNREGISTER(test_FIELDNUM); 01649 AST_TEST_UNREGISTER(test_FILTER); 01650 res |= ast_custom_function_unregister(&fieldqty_function); 01651 res |= ast_custom_function_unregister(&fieldnum_function); 01652 res |= ast_custom_function_unregister(&filter_function); 01653 res |= ast_custom_function_unregister(&replace_function); 01654 res |= ast_custom_function_unregister(&listfilter_function); 01655 res |= ast_custom_function_unregister(®ex_function); 01656 res |= ast_custom_function_unregister(&array_function); 01657 res |= ast_custom_function_unregister("e_function); 01658 res |= ast_custom_function_unregister(&csv_quote_function); 01659 res |= ast_custom_function_unregister(&len_function); 01660 res |= ast_custom_function_unregister(&strftime_function); 01661 res |= ast_custom_function_unregister(&strptime_function); 01662 res |= ast_custom_function_unregister(&eval_function); 01663 res |= ast_custom_function_unregister(&keypadhash_function); 01664 res |= ast_custom_function_unregister(&hashkeys_function); 01665 res |= ast_custom_function_unregister(&hash_function); 01666 res |= ast_unregister_application(app_clearhash); 01667 res |= ast_custom_function_unregister(&toupper_function); 01668 res |= ast_custom_function_unregister(&tolower_function); 01669 res |= ast_custom_function_unregister(&shift_function); 01670 res |= ast_custom_function_unregister(&pop_function); 01671 res |= ast_custom_function_unregister(&push_function); 01672 res |= ast_custom_function_unregister(&unshift_function); 01673 res |= ast_custom_function_unregister(&passthru_function); 01674 01675 return res; 01676 }
static int unshift_push | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
const char * | new_value | |||
) | [static] |
Definition at line 1474 of file func_strings.c.
References args, AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_get_encoded_char(), ast_log(), AST_STANDARD_APP_ARGS, ast_str_buffer(), ast_str_set(), ast_str_strlen(), ast_str_substitute_variables(), ast_str_thread_get(), ast_strlen_zero(), beginning, LOG_WARNING, pbx_builtin_setvar_helper(), result_buf, tmp_buf, and var.
01475 { 01476 #define beginning (cmd[0] == 'U') /* UNSHIFT */ 01477 char delimiter[2] = ",", *varsubst; 01478 size_t unused; 01479 struct ast_str *buf, *previous_value; 01480 AST_DECLARE_APP_ARGS(args, 01481 AST_APP_ARG(var); 01482 AST_APP_ARG(delimiter); 01483 ); 01484 01485 if (!(buf = ast_str_thread_get(&result_buf, 16)) || 01486 !(previous_value = ast_str_thread_get(&tmp_buf, 16))) { 01487 return -1; 01488 } 01489 01490 AST_STANDARD_APP_ARGS(args, data); 01491 01492 if (ast_strlen_zero(args.var)) { 01493 ast_log(LOG_WARNING, "%s requires a variable name\n", cmd); 01494 return -1; 01495 } 01496 01497 if (args.argc > 1 && !ast_strlen_zero(args.delimiter)) { 01498 ast_get_encoded_char(args.delimiter, delimiter, &unused); 01499 } 01500 01501 varsubst = alloca(strlen(args.var) + 4); 01502 sprintf(varsubst, "${%s}", args.var); 01503 ast_str_substitute_variables(&previous_value, 0, chan, varsubst); 01504 01505 if (!ast_str_strlen(previous_value)) { 01506 ast_str_set(&buf, 0, "%s", new_value); 01507 } else { 01508 ast_str_set(&buf, 0, "%s%c%s", 01509 beginning ? new_value : ast_str_buffer(previous_value), 01510 delimiter[0], 01511 beginning ? ast_str_buffer(previous_value) : new_value); 01512 } 01513 01514 pbx_builtin_setvar_helper(chan, args.var, ast_str_buffer(buf)); 01515 01516 return 0; 01517 #undef beginning 01518 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "String handling dialplan functions" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "8586c2a7d357cb591cc3a6607a8f62d1" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } [static] |
Definition at line 1712 of file func_strings.c.
char* app_clearhash = "ClearHash" [static] |
struct ast_custom_function array_function [static] |
Initial value:
{ .name = "ARRAY", .write = array, }
Definition at line 1111 of file func_strings.c.
Referenced by load_module(), and unload_module().
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 1712 of file func_strings.c.
struct ast_custom_function csv_quote_function [static] |
Initial value:
{ .name = "CSV_QUOTE", .read = csv_quote, }
Definition at line 1185 of file func_strings.c.
Referenced by load_module(), and unload_module().
struct ast_custom_function eval_function [static] |
Initial value:
{ .name = "EVAL", .read = function_eval, .read2 = function_eval2, }
Definition at line 1310 of file func_strings.c.
Referenced by load_module(), and unload_module().
struct ast_custom_function fieldnum_function [static] |
Initial value:
{ .name = "FIELDNUM", .read = function_fieldnum, .read2 = function_fieldnum_str, }
Definition at line 552 of file func_strings.c.
Referenced by load_module(), and unload_module().
struct ast_custom_function fieldqty_function [static] |
Initial value:
{ .name = "FIELDQTY", .read = function_fieldqty, .read2 = function_fieldqty_str, }
Definition at line 473 of file func_strings.c.
Referenced by load_module(), and unload_module().
struct ast_custom_function filter_function [static] |
Initial value:
{ .name = "FILTER", .read = filter, }
Definition at line 763 of file func_strings.c.
Referenced by load_module(), and unload_module().
struct ast_custom_function hash_function [static] |
Initial value:
{ .name = "HASH", .write = hash_write, .read = hash_read, }
Definition at line 1099 of file func_strings.c.
Referenced by load_module(), and unload_module().
struct ast_custom_function hashkeys_function [static] |
Initial value:
{ .name = "HASHKEYS", .read = hashkeys_read, .read2 = hashkeys_read2, }
Definition at line 1105 of file func_strings.c.
Referenced by load_module(), and unload_module().
struct ast_custom_function keypadhash_function [static] |
Initial value:
{ .name = "KEYPADHASH", .read = keypadhash, }
Definition at line 1351 of file func_strings.c.
Referenced by load_module(), and unload_module().
struct ast_custom_function len_function [static] |
Initial value:
{ .name = "LEN", .read = len, .read_max = 12, }
Definition at line 1202 of file func_strings.c.
Referenced by load_module(), and unload_module().
struct ast_custom_function listfilter_function [static] |
Initial value:
{ .name = "LISTFILTER", .read = listfilter_read, .read2 = listfilter_read2, }
Definition at line 681 of file func_strings.c.
Referenced by load_module(), and unload_module().
struct ast_custom_function passthru_function [static] |
Initial value:
{ .name = "PASSTHRU", .read2 = passthru, }
Definition at line 1536 of file func_strings.c.
Referenced by load_module(), and unload_module().
struct ast_custom_function pop_function [static] |
Initial value:
{ .name = "POP", .read2 = shift_pop, }
Definition at line 1469 of file func_strings.c.
Referenced by load_module(), and unload_module().
struct ast_custom_function push_function [static] |
Initial value:
{ .name = "PUSH", .write = unshift_push, }
Definition at line 1520 of file func_strings.c.
Referenced by load_module(), and unload_module().
struct ast_custom_function quote_function [static] |
Initial value:
{ .name = "QUOTE", .read = quote, }
Definition at line 1150 of file func_strings.c.
Referenced by load_module(), and unload_module().
struct ast_custom_function regex_function [static] |
Initial value:
{ .name = "REGEX", .read = regex, }
Definition at line 875 of file func_strings.c.
Referenced by load_module(), and unload_module().
struct ast_custom_function replace_function [static] |
Initial value:
{ .name = "REPLACE", .read2 = replace, }
Definition at line 833 of file func_strings.c.
Referenced by load_module(), and unload_module().
struct ast_threadstorage result_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_result_buf , .custom_init = NULL , } [static] |
Definition at line 43 of file func_strings.c.
struct ast_custom_function shift_function [static] |
Initial value:
{ .name = "SHIFT", .read2 = shift_pop, }
Definition at line 1464 of file func_strings.c.
Referenced by load_module(), and unload_module().
struct ast_custom_function strftime_function [static] |
Initial value:
{ .name = "STRFTIME", .read = acf_strftime, }
Definition at line 1237 of file func_strings.c.
Referenced by load_module(), and unload_module().
struct ast_custom_function strptime_function [static] |
Initial value:
{ .name = "STRPTIME", .read = acf_strptime, }
Definition at line 1279 of file func_strings.c.
Referenced by load_module(), and unload_module().
struct ast_threadstorage tmp_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_tmp_buf , .custom_init = NULL , } [static] |
struct ast_custom_function tolower_function [static] |
Initial value:
{ .name = "TOLOWER", .read = string_tolower, .read2 = string_tolower2, }
Definition at line 1408 of file func_strings.c.
Referenced by load_module(), and unload_module().
struct ast_custom_function toupper_function [static] |
Initial value:
{ .name = "TOUPPER", .read = string_toupper, .read2 = string_toupper2, }
Definition at line 1379 of file func_strings.c.
Referenced by load_module(), and unload_module().
struct ast_custom_function unshift_function [static] |
Initial value:
{ .name = "UNSHIFT", .write = unshift_push, }
Definition at line 1525 of file func_strings.c.
Referenced by load_module(), and unload_module().