String manipulation dialplan functions. More...
#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"
Go to the source code of this file.
Defines | |
| #define | HASH_FORMAT HASH_PREFIX "%s~" |
| #define | HASH_PREFIX "~HASH~%s~" |
Functions | |
| 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) |
| AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"String handling dialplan functions") | |
| AST_THREADSTORAGE (result_buf) | |
| 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, void *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_fieldqty (struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_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 | 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, size_t len) |
| static int | load_module (void) |
| 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 | string_tolower (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen) |
| static int | string_toupper (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen) |
| static int | unload_module (void) |
Variables | |
| static char * | app_clearhash = "ClearHash" |
| static struct ast_custom_function | array_function |
| static struct ast_custom_function | csv_quote_function |
| static struct ast_custom_function | eval_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 | quote_function |
| static struct ast_custom_function | regex_function |
| static struct ast_custom_function | strftime_function |
| static struct ast_custom_function | strptime_function |
| static struct ast_custom_function | tolower_function |
| static struct ast_custom_function | toupper_function |
String manipulation dialplan functions.
Definition in file func_strings.c.
| #define HASH_FORMAT HASH_PREFIX "%s~" |
Definition at line 551 of file func_strings.c.
Referenced by array(), hash_read(), and hash_write().
| #define HASH_PREFIX "~HASH~%s~" |
Definition at line 550 of file func_strings.c.
Referenced by exec_clearhash(), and hashkeys_read().
| static int acf_strftime | ( | struct ast_channel * | chan, | |
| const char * | cmd, | |||
| char * | parse, | |||
| char * | buf, | |||
| size_t | buflen | |||
| ) | [static] |
Definition at line 838 of file func_strings.c.
References 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.
00840 { 00841 AST_DECLARE_APP_ARGS(args, 00842 AST_APP_ARG(epoch); 00843 AST_APP_ARG(timezone); 00844 AST_APP_ARG(format); 00845 ); 00846 struct timeval when; 00847 struct ast_tm tm; 00848 00849 buf[0] = '\0'; 00850 00851 AST_STANDARD_APP_ARGS(args, parse); 00852 00853 ast_get_timeval(args.epoch, &when, ast_tvnow(), NULL); 00854 ast_localtime(&when, &tm, args.timezone); 00855 00856 if (!args.format) 00857 args.format = "%c"; 00858 00859 if (ast_strftime(buf, buflen, args.format, &tm) <= 0) 00860 ast_log(LOG_WARNING, "C function strftime() output nothing?!!\n"); 00861 00862 buf[buflen - 1] = '\0'; 00863 00864 return 0; 00865 }
| static int acf_strptime | ( | struct ast_channel * | chan, | |
| const char * | cmd, | |||
| char * | data, | |||
| char * | buf, | |||
| size_t | buflen | |||
| ) | [static] |
Definition at line 872 of file func_strings.c.
References 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.
00874 { 00875 AST_DECLARE_APP_ARGS(args, 00876 AST_APP_ARG(timestring); 00877 AST_APP_ARG(timezone); 00878 AST_APP_ARG(format); 00879 ); 00880 struct ast_tm tm; 00881 00882 buf[0] = '\0'; 00883 00884 if (!data) { 00885 ast_log(LOG_ERROR, 00886 "Asterisk function STRPTIME() requires an argument.\n"); 00887 return -1; 00888 } 00889 00890 AST_STANDARD_APP_ARGS(args, data); 00891 00892 if (ast_strlen_zero(args.format)) { 00893 ast_log(LOG_ERROR, 00894 "No format supplied to STRPTIME(<timestring>,<timezone>,<format>)"); 00895 return -1; 00896 } 00897 00898 if (!ast_strptime(args.timestring, args.format, &tm)) { 00899 ast_log(LOG_WARNING, "STRPTIME() found no time specified within the string\n"); 00900 } else { 00901 struct timeval when; 00902 when = ast_mktime(&tm, args.timezone); 00903 snprintf(buf, buflen, "%d", (int) when.tv_sec); 00904 } 00905 00906 return 0; 00907 }
| static int array | ( | struct ast_channel * | chan, | |
| const char * | cmd, | |||
| char * | var, | |||
| const char * | value | |||
| ) | [static] |
Definition at line 577 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(), and pbx_builtin_setvar_helper().
Referenced by hash_write().
00579 { 00580 AST_DECLARE_APP_ARGS(arg1, 00581 AST_APP_ARG(var)[100]; 00582 ); 00583 AST_DECLARE_APP_ARGS(arg2, 00584 AST_APP_ARG(val)[100]; 00585 ); 00586 char *origvar = "", *value2, varname[256]; 00587 int i, ishash = 0; 00588 00589 value2 = ast_strdupa(value); 00590 if (!var || !value2) 00591 return -1; 00592 00593 if (!strcmp(cmd, "HASH")) { 00594 const char *var2 = pbx_builtin_getvar_helper(chan, "~ODBCFIELDS~"); 00595 origvar = var; 00596 if (var2) 00597 var = ast_strdupa(var2); 00598 else { 00599 if (chan) 00600 ast_autoservice_stop(chan); 00601 return -1; 00602 } 00603 ishash = 1; 00604 } 00605 00606 /* The functions this will generally be used with are SORT and ODBC_*, which 00607 * both return comma-delimited lists. However, if somebody uses literal lists, 00608 * their commas will be translated to vertical bars by the load, and I don't 00609 * want them to be surprised by the result. Hence, we prefer commas as the 00610 * delimiter, but we'll fall back to vertical bars if commas aren't found. 00611 */ 00612 ast_debug(1, "array (%s=%s)\n", var, value2); 00613 AST_STANDARD_APP_ARGS(arg1, var); 00614 00615 AST_STANDARD_APP_ARGS(arg2, value2); 00616 00617 for (i = 0; i < arg1.argc; i++) { 00618 ast_debug(1, "array set value (%s=%s)\n", arg1.var[i], 00619 arg2.val[i]); 00620 if (i < arg2.argc) { 00621 if (ishash) { 00622 snprintf(varname, sizeof(varname), HASH_FORMAT, origvar, arg1.var[i]); 00623 pbx_builtin_setvar_helper(chan, varname, arg2.val[i]); 00624 } else { 00625 pbx_builtin_setvar_helper(chan, arg1.var[i], arg2.val[i]); 00626 } 00627 } else { 00628 /* We could unset the variable, by passing a NULL, but due to 00629 * pushvar semantics, that could create some undesired behavior. */ 00630 if (ishash) { 00631 snprintf(varname, sizeof(varname), HASH_FORMAT, origvar, arg1.var[i]); 00632 pbx_builtin_setvar_helper(chan, varname, ""); 00633 } else { 00634 pbx_builtin_setvar_helper(chan, arg1.var[i], ""); 00635 } 00636 } 00637 } 00638 00639 return 0; 00640 }
| AST_MODULE_INFO_STANDARD | ( | ASTERISK_GPL_KEY | , | |
| "String handling dialplan functions" | ||||
| ) |
| AST_THREADSTORAGE | ( | result_buf | ) |
| static void clearvar_prefix | ( | struct ast_channel * | chan, | |
| const char * | prefix | |||
| ) | [static] |
Definition at line 556 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(), len(), var, and ast_channel::varshead.
Referenced by exec_clearhash().
00557 { 00558 struct ast_var_t *var; 00559 int len = strlen(prefix); 00560 AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->varshead, var, entries) { 00561 if (strncasecmp(prefix, ast_var_name(var), len) == 0) { 00562 AST_LIST_REMOVE_CURRENT(entries); 00563 ast_free(var); 00564 } 00565 } 00566 AST_LIST_TRAVERSE_SAFE_END 00567 }
| static int csv_quote | ( | struct ast_channel * | chan, | |
| const char * | cmd, | |||
| char * | data, | |||
| char * | buf, | |||
| size_t | len | |||
| ) | [static] |
Definition at line 785 of file func_strings.c.
References ast_copy_string(), ast_log(), ast_strlen_zero(), LOG_ERROR, and LOG_WARNING.
00786 { 00787 char *bufptr = buf, *dataptr = data; 00788 00789 if (len < 3){ /* at least two for quotes and one for binary zero */ 00790 ast_log(LOG_ERROR, "Not enough buffer"); 00791 return -1; 00792 } 00793 00794 if (ast_strlen_zero(data)) { 00795 ast_log(LOG_WARNING, "No argument specified!\n"); 00796 ast_copy_string(buf,"\"\"",len); 00797 return 0; 00798 } 00799 00800 *bufptr++ = '"'; 00801 for (; bufptr < buf + len - 3; dataptr++){ 00802 if (*dataptr == '"') { 00803 *bufptr++ = '"'; 00804 *bufptr++ = '"'; 00805 } else if (*dataptr == '\0') { 00806 break; 00807 } else { 00808 *bufptr++ = *dataptr; 00809 } 00810 } 00811 *bufptr++ = '"'; 00812 *bufptr='\0'; 00813 return 0; 00814 }
| static int exec_clearhash | ( | struct ast_channel * | chan, | |
| void * | data | |||
| ) | [static] |
Definition at line 569 of file func_strings.c.
References clearvar_prefix(), HASH_PREFIX, and prefix.
Referenced by load_module().
00570 { 00571 char prefix[80]; 00572 snprintf(prefix, sizeof(prefix), HASH_PREFIX, data ? (char *)data : "null"); 00573 clearvar_prefix(chan, prefix); 00574 return 0; 00575 }
| static int filter | ( | struct ast_channel * | chan, | |
| const char * | cmd, | |||
| char * | parse, | |||
| char * | buf, | |||
| size_t | len | |||
| ) | [static] |
Definition at line 427 of file func_strings.c.
References 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, and LOG_WARNING.
Referenced by realtime_ldap_base_ap(), set_egress_subscription(), update2_ldap(), and update_ldap().
00429 { 00430 AST_DECLARE_APP_ARGS(args, 00431 AST_APP_ARG(allowed); 00432 AST_APP_ARG(string); 00433 ); 00434 char *outbuf = buf; 00435 unsigned char ac; 00436 char allowed[256] = ""; 00437 size_t allowedlen = 0; 00438 int32_t bitfield[8] = { 0, }; /* 256 bits */ 00439 00440 AST_STANDARD_RAW_ARGS(args, parse); 00441 00442 if (!args.string) { 00443 ast_log(LOG_ERROR, "Usage: FILTER(<allowed-chars>,<string>)\n"); 00444 return -1; 00445 } 00446 00447 if (args.allowed[0] == '"' && !ast_opt_dont_warn) { 00448 ast_log(LOG_WARNING, "FILTER allowed characters includes the quote (\") character. This may not be what you want.\n"); 00449 } 00450 00451 /* Expand ranges */ 00452 for (; *(args.allowed);) { 00453 char c1 = 0, c2 = 0; 00454 size_t consumed = 0; 00455 00456 if (ast_get_encoded_char(args.allowed, &c1, &consumed)) 00457 return -1; 00458 args.allowed += consumed; 00459 00460 if (*(args.allowed) == '-') { 00461 if (ast_get_encoded_char(args.allowed + 1, &c2, &consumed)) 00462 c2 = -1; 00463 args.allowed += consumed + 1; 00464 00465 if ((c2 < c1 || c2 == -1) && !ast_opt_dont_warn) { 00466 ast_log(LOG_WARNING, "Range wrapping in FILTER(%s,%s). This may not be what you want.\n", parse, args.string); 00467 } 00468 00469 /*!\note 00470 * Looks a little strange, until you realize that we can overflow 00471 * the size of a char. 00472 */ 00473 for (ac = c1; ac != c2; ac++) { 00474 bitfield[ac / 32] |= 1 << (ac % 32); 00475 } 00476 bitfield[ac / 32] |= 1 << (ac % 32); 00477 00478 ast_debug(4, "c1=%d, c2=%d\n", c1, c2); 00479 } else { 00480 ac = (unsigned char) c1; 00481 ast_debug(4, "c1=%d, consumed=%d, args.allowed=%s\n", c1, (int) consumed, args.allowed - consumed); 00482 bitfield[ac / 32] |= 1 << (ac % 32); 00483 } 00484 } 00485 00486 for (ac = 1; ac != 0; ac++) { 00487 if (bitfield[ac / 32] & (1 << (ac % 32))) { 00488 allowed[allowedlen++] = ac; 00489 } 00490 } 00491 00492 ast_debug(1, "Allowed: %s\n", allowed); 00493 00494 for (; *(args.string) && (buf + len - 1 > outbuf); (args.string)++) { 00495 if (strchr(allowed, *(args.string))) 00496 *outbuf++ = *(args.string); 00497 } 00498 *outbuf = '\0'; 00499 00500 return 0; 00501 }
| static int function_eval | ( | struct ast_channel * | chan, | |
| const char * | cmd, | |||
| char * | data, | |||
| char * | buf, | |||
| size_t | buflen | |||
| ) | [static] |
Definition at line 914 of file func_strings.c.
References ast_log(), ast_strlen_zero(), LOG_WARNING, and pbx_substitute_variables_helper().
00916 { 00917 if (ast_strlen_zero(data)) { 00918 ast_log(LOG_WARNING, "EVAL requires an argument: EVAL(<string>)\n"); 00919 return -1; 00920 } 00921 00922 pbx_substitute_variables_helper(chan, data, buf, buflen - 1); 00923 00924 return 0; 00925 }
| static int function_fieldqty | ( | struct ast_channel * | chan, | |
| const char * | cmd, | |||
| char * | parse, | |||
| char * | buf, | |||
| size_t | len | |||
| ) | [static] |
Definition at line 292 of file func_strings.c.
References AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_get_encoded_char(), AST_STANDARD_APP_ARGS, ast_strlen_zero(), pbx_substitute_variables_helper(), and strsep().
00294 { 00295 char *varsubst, varval[8192], *varval2 = varval; 00296 int fieldcount = 0; 00297 AST_DECLARE_APP_ARGS(args, 00298 AST_APP_ARG(varname); 00299 AST_APP_ARG(delim); 00300 ); 00301 char delim[2] = ""; 00302 size_t delim_used; 00303 00304 AST_STANDARD_APP_ARGS(args, parse); 00305 if (args.delim) { 00306 ast_get_encoded_char(args.delim, delim, &delim_used); 00307 00308 varsubst = alloca(strlen(args.varname) + 4); 00309 00310 sprintf(varsubst, "${%s}", args.varname); 00311 pbx_substitute_variables_helper(chan, varsubst, varval, sizeof(varval) - 1); 00312 if (ast_strlen_zero(varval2)) 00313 fieldcount = 0; 00314 else { 00315 while (strsep(&varval2, delim)) 00316 fieldcount++; 00317 } 00318 } else { 00319 fieldcount = 1; 00320 } 00321 snprintf(buf, len, "%d", fieldcount); 00322 00323 return 0; 00324 }
| static int hash_read | ( | struct ast_channel * | chan, | |
| const char * | cmd, | |||
| char * | data, | |||
| char * | buf, | |||
| size_t | len | |||
| ) | [static] |
Definition at line 684 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().
00685 { 00686 char varname[256]; 00687 const char *varvalue; 00688 AST_DECLARE_APP_ARGS(arg, 00689 AST_APP_ARG(hashname); 00690 AST_APP_ARG(hashkey); 00691 ); 00692 00693 AST_STANDARD_APP_ARGS(arg, data); 00694 if (arg.argc == 2) { 00695 snprintf(varname, sizeof(varname), HASH_FORMAT, arg.hashname, arg.hashkey); 00696 varvalue = pbx_builtin_getvar_helper(chan, varname); 00697 if (varvalue) 00698 ast_copy_string(buf, varvalue, len); 00699 else 00700 *buf = '\0'; 00701 } else if (arg.argc == 1) { 00702 char colnames[4096]; 00703 int i; 00704 AST_DECLARE_APP_ARGS(arg2, 00705 AST_APP_ARG(col)[100]; 00706 ); 00707 00708 /* Get column names, in no particular order */ 00709 hashkeys_read(chan, "HASHKEYS", arg.hashname, colnames, sizeof(colnames)); 00710 pbx_builtin_setvar_helper(chan, "~ODBCFIELDS~", colnames); 00711 00712 AST_STANDARD_APP_ARGS(arg2, colnames); 00713 *buf = '\0'; 00714 00715 /* Now get the corresponding column values, in exactly the same order */ 00716 for (i = 0; i < arg2.argc; i++) { 00717 snprintf(varname, sizeof(varname), HASH_FORMAT, arg.hashname, arg2.col[i]); 00718 varvalue = pbx_builtin_getvar_helper(chan, varname); 00719 strncat(buf, varvalue, len - strlen(buf) - 1); 00720 strncat(buf, ",", len - strlen(buf) - 1); 00721 } 00722 00723 /* Strip trailing comma */ 00724 buf[strlen(buf) - 1] = '\0'; 00725 } 00726 00727 return 0; 00728 }
| static int hash_write | ( | struct ast_channel * | chan, | |
| const char * | cmd, | |||
| char * | var, | |||
| const char * | value | |||
| ) | [static] |
Definition at line 664 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().
00665 { 00666 char varname[256]; 00667 AST_DECLARE_APP_ARGS(arg, 00668 AST_APP_ARG(hashname); 00669 AST_APP_ARG(hashkey); 00670 ); 00671 00672 if (!strchr(var, ',')) { 00673 /* Single argument version */ 00674 return array(chan, "HASH", var, value); 00675 } 00676 00677 AST_STANDARD_APP_ARGS(arg, var); 00678 snprintf(varname, sizeof(varname), HASH_FORMAT, arg.hashname, arg.hashkey); 00679 pbx_builtin_setvar_helper(chan, varname, value); 00680 00681 return 0; 00682 }
| static int hashkeys_read | ( | struct ast_channel * | chan, | |
| const char * | cmd, | |||
| char * | data, | |||
| char * | buf, | |||
| size_t | len | |||
| ) | [static] |
Definition at line 642 of file func_strings.c.
References AST_LIST_TRAVERSE, ast_var_name(), HASH_PREFIX, prefix, and ast_channel::varshead.
Referenced by hash_read().
00643 { 00644 struct ast_var_t *newvar; 00645 int plen; 00646 char prefix[80]; 00647 snprintf(prefix, sizeof(prefix), HASH_PREFIX, data); 00648 plen = strlen(prefix); 00649 00650 memset(buf, 0, len); 00651 AST_LIST_TRAVERSE(&chan->varshead, newvar, entries) { 00652 if (strncasecmp(prefix, ast_var_name(newvar), plen) == 0) { 00653 /* Copy everything after the prefix */ 00654 strncat(buf, ast_var_name(newvar) + plen, len - strlen(buf) - 1); 00655 /* Trim the trailing ~ */ 00656 buf[strlen(buf) - 1] = ','; 00657 } 00658 } 00659 /* Trim the trailing comma */ 00660 buf[strlen(buf) - 1] = '\0'; 00661 return 0; 00662 }
| static int keypadhash | ( | struct ast_channel * | chan, | |
| const char * | cmd, | |||
| char * | data, | |||
| char * | buf, | |||
| size_t | buflen | |||
| ) | [static] |
Definition at line 932 of file func_strings.c.
00933 { 00934 char *bufptr, *dataptr; 00935 00936 for (bufptr = buf, dataptr = data; bufptr < buf + buflen - 1; dataptr++) { 00937 if (*dataptr == '\0') { 00938 *bufptr++ = '\0'; 00939 break; 00940 } else if (*dataptr == '1') { 00941 *bufptr++ = '1'; 00942 } else if (strchr("AaBbCc2", *dataptr)) { 00943 *bufptr++ = '2'; 00944 } else if (strchr("DdEeFf3", *dataptr)) { 00945 *bufptr++ = '3'; 00946 } else if (strchr("GgHhIi4", *dataptr)) { 00947 *bufptr++ = '4'; 00948 } else if (strchr("JjKkLl5", *dataptr)) { 00949 *bufptr++ = '5'; 00950 } else if (strchr("MmNnOo6", *dataptr)) { 00951 *bufptr++ = '6'; 00952 } else if (strchr("PpQqRrSs7", *dataptr)) { 00953 *bufptr++ = '7'; 00954 } else if (strchr("TtUuVv8", *dataptr)) { 00955 *bufptr++ = '8'; 00956 } else if (strchr("WwXxYyZz9", *dataptr)) { 00957 *bufptr++ = '9'; 00958 } else if (*dataptr == '0') { 00959 *bufptr++ = '0'; 00960 } 00961 } 00962 buf[buflen - 1] = '\0'; 00963 00964 return 0; 00965 }
| static int len | ( | struct ast_channel * | chan, | |
| const char * | cmd, | |||
| char * | data, | |||
| char * | buf, | |||
| size_t | buflen | |||
| ) | [static] |
Definition at line 821 of file func_strings.c.
Referenced by __ast_cli_register(), __ast_realloc(), __ast_sizeof_region(), __ast_str_helper(), __ast_strdup(), __ast_strndup(), __get_header(), _parse(), add_sdp(), ael_token_subst(), aji_io_recv(), aji_recv(), aji_send_header(), aji_send_raw(), aji_start_sasl(), alsa_write(), append_interface(), append_var_and_value_to_filter(), ast_app_group_set_channel(), 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_uri_link(), ast_mkdir(), ast_read_image(), ast_rtcp_read(), ast_rtcp_write_rr(), ast_rtcp_write_sr(), ast_rtp_lookup_mime_multiple(), ast_rtp_read(), ast_say_number_full_ka(), ast_smoother_read(), ast_str_buffer(), ast_translate(), ast_udptl_read(), ast_udptl_write(), ast_xmldoc_printable(), auth_exec(), authenticate(), build_device(), build_facility(), builtin_automixmonitor(), builtin_automonitor(), 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(), conf_play(), config_jitterbuffer(), copy(), create_video_frame(), dahdi_setoption(), devstate_write(), dialgroup_refreshdb(), dictate_exec(), dundi_encrypt(), dundi_parse_ies(), dundi_send(), evt_event_deliver_cb(), expr2_token_subst(), feature_request_and_dial(), ffmpeg_decode(), 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_devstate_change(), handle_commandmatchesarray(), handle_memory_show(), handle_memory_show_summary(), 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(), 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(), process_sdp(), read_credentials(), readfile_exec(), reschedule_precache(), run_agi(), schedule_delivery(), set(), set_egress_subscription(), skinny_ss(), sms_messagetx(), socket_process_meta(), socket_read(), ss_thread(), static_callback(), strndup(), strnlen(), term_filter_escapes(), transfer_exec(), try_firmware(), udptl_build_packet(), unistim_sp(), unquote(), vmwi_generate(), wav_write(), and xmldoc_get_syntax_fun().
00822 { 00823 int length = 0; 00824 00825 if (data) 00826 length = strlen(data); 00827 00828 snprintf(buf, buflen, "%d", length); 00829 00830 return 0; 00831 }
| static int listfilter | ( | struct ast_channel * | chan, | |
| const char * | cmd, | |||
| char * | parse, | |||
| char * | buf, | |||
| size_t | len | |||
| ) | [static] |
Definition at line 331 of file func_strings.c.
References 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_thread_get(), first, LOG_ERROR, ast_custom_function::next, and pbx_builtin_getvar_helper().
00332 { 00333 AST_DECLARE_APP_ARGS(args, 00334 AST_APP_ARG(listname); 00335 AST_APP_ARG(delimiter); 00336 AST_APP_ARG(fieldvalue); 00337 ); 00338 const char *orig_list, *ptr; 00339 const char *begin, *cur, *next; 00340 int dlen, flen, first = 1; 00341 struct ast_str *result = ast_str_thread_get(&result_buf, 16); 00342 char *delim; 00343 00344 AST_STANDARD_APP_ARGS(args, parse); 00345 00346 if (args.argc < 3) { 00347 ast_log(LOG_ERROR, "Usage: LISTFILTER(<listname>,<delimiter>,<fieldvalue>)\n"); 00348 return -1; 00349 } 00350 00351 /* If we don't lock the channel, the variable could disappear out from underneath us. */ 00352 if (chan) { 00353 ast_channel_lock(chan); 00354 } 00355 if (!(orig_list = pbx_builtin_getvar_helper(chan, args.listname))) { 00356 ast_log(LOG_ERROR, "List variable '%s' not found\n", args.listname); 00357 if (chan) { 00358 ast_channel_unlock(chan); 00359 } 00360 return -1; 00361 } 00362 00363 /* If the string isn't there, just copy out the string and be done with it. */ 00364 if (!(ptr = strstr(orig_list, args.fieldvalue))) { 00365 ast_copy_string(buf, orig_list, len); 00366 if (chan) { 00367 ast_channel_unlock(chan); 00368 } 00369 return 0; 00370 } 00371 00372 dlen = strlen(args.delimiter); 00373 delim = alloca(dlen + 1); 00374 ast_get_encoded_str(args.delimiter, delim, dlen + 1); 00375 00376 if ((dlen = strlen(delim)) == 0) { 00377 delim = ","; 00378 dlen = 1; 00379 } 00380 00381 flen = strlen(args.fieldvalue); 00382 00383 ast_str_reset(result); 00384 /* Enough space for any result */ 00385 ast_str_make_space(&result, strlen(orig_list) + 1); 00386 00387 begin = orig_list; 00388 next = strstr(begin, delim); 00389 00390 do { 00391 /* Find next boundary */ 00392 if (next) { 00393 cur = next; 00394 next = strstr(cur + dlen, delim); 00395 } else { 00396 cur = strchr(begin + dlen, '\0'); 00397 } 00398 00399 if (flen == cur - begin && !strncmp(begin, args.fieldvalue, flen)) { 00400 /* Skip field */ 00401 begin += flen + dlen; 00402 } else { 00403 /* Copy field to output */ 00404 if (!first) { 00405 ast_str_append(&result, 0, "%s", delim); 00406 } 00407 00408 ast_str_append_substr(&result, 0, begin, cur - begin); 00409 first = 0; 00410 begin = cur + dlen; 00411 } 00412 } while (*cur != '\0'); 00413 if (chan) { 00414 ast_channel_unlock(chan); 00415 } 00416 00417 ast_copy_string(buf, ast_str_buffer(result), len); 00418 00419 return 0; 00420 }
| static int load_module | ( | void | ) | [static] |
Definition at line 1025 of file func_strings.c.
References ast_custom_function_register, ast_register_application_xml, and exec_clearhash().
01026 { 01027 int res = 0; 01028 01029 res |= ast_custom_function_register(&fieldqty_function); 01030 res |= ast_custom_function_register(&filter_function); 01031 res |= ast_custom_function_register(&listfilter_function); 01032 res |= ast_custom_function_register(®ex_function); 01033 res |= ast_custom_function_register(&array_function); 01034 res |= ast_custom_function_register("e_function); 01035 res |= ast_custom_function_register(&csv_quote_function); 01036 res |= ast_custom_function_register(&len_function); 01037 res |= ast_custom_function_register(&strftime_function); 01038 res |= ast_custom_function_register(&strptime_function); 01039 res |= ast_custom_function_register(&eval_function); 01040 res |= ast_custom_function_register(&keypadhash_function); 01041 res |= ast_custom_function_register(&hashkeys_function); 01042 res |= ast_custom_function_register(&hash_function); 01043 res |= ast_register_application_xml(app_clearhash, exec_clearhash); 01044 res |= ast_custom_function_register(&toupper_function); 01045 res |= ast_custom_function_register(&tolower_function); 01046 01047 return res; 01048 }
| static int quote | ( | struct ast_channel * | chan, | |
| const char * | cmd, | |||
| char * | data, | |||
| char * | buf, | |||
| size_t | len | |||
| ) | [static] |
Definition at line 746 of file func_strings.c.
References ast_copy_string(), ast_log(), ast_strlen_zero(), LOG_ERROR, and LOG_WARNING.
00747 { 00748 char *bufptr = buf, *dataptr = data; 00749 00750 if (len < 3){ /* at least two for quotes and one for binary zero */ 00751 ast_log(LOG_ERROR, "Not enough buffer"); 00752 return -1; 00753 } 00754 00755 if (ast_strlen_zero(data)) { 00756 ast_log(LOG_WARNING, "No argument specified!\n"); 00757 ast_copy_string(buf, "\"\"", len); 00758 return 0; 00759 } 00760 00761 *bufptr++ = '"'; 00762 for (; bufptr < buf + len - 3; dataptr++) { 00763 if (*dataptr == '\\') { 00764 *bufptr++ = '\\'; 00765 *bufptr++ = '\\'; 00766 } else if (*dataptr == '"') { 00767 *bufptr++ = '\\'; 00768 *bufptr++ = '"'; 00769 } else if (*dataptr == '\0') { 00770 break; 00771 } else { 00772 *bufptr++ = *dataptr; 00773 } 00774 } 00775 *bufptr++ = '"'; 00776 *bufptr = '\0'; 00777 return 0; 00778 }
| static int regex | ( | struct ast_channel * | chan, | |
| const char * | cmd, | |||
| char * | parse, | |||
| char * | buf, | |||
| size_t | len | |||
| ) | [static] |
Definition at line 508 of file func_strings.c.
References AST_APP_ARG, ast_debug, AST_DECLARE_APP_ARGS, ast_log(), AST_NONSTANDARD_APP_ARGS, LOG_ERROR, LOG_WARNING, and str.
00510 { 00511 AST_DECLARE_APP_ARGS(args, 00512 AST_APP_ARG(null); 00513 AST_APP_ARG(reg); 00514 AST_APP_ARG(str); 00515 ); 00516 int errcode; 00517 regex_t regexbuf; 00518 00519 buf[0] = '\0'; 00520 00521 AST_NONSTANDARD_APP_ARGS(args, parse, '"'); 00522 00523 if (args.argc != 3) { 00524 ast_log(LOG_ERROR, "Unexpected arguments: should have been in the form '\"<regex>\" <string>'\n"); 00525 return -1; 00526 } 00527 if ((*args.str == ' ') || (*args.str == '\t')) 00528 args.str++; 00529 00530 ast_debug(1, "FUNCTION REGEX (%s)(%s)\n", args.reg, args.str); 00531 00532 if ((errcode = regcomp(®exbuf, args.reg, REG_EXTENDED | REG_NOSUB))) { 00533 regerror(errcode, ®exbuf, buf, len); 00534 ast_log(LOG_WARNING, "Malformed input %s(%s): %s\n", cmd, parse, buf); 00535 return -1; 00536 } 00537 00538 strcpy(buf, regexec(®exbuf, args.str, 0, NULL, 0) ? "0" : "1"); 00539 00540 regfree(®exbuf); 00541 00542 return 0; 00543 }
| static int string_tolower | ( | struct ast_channel * | chan, | |
| const char * | cmd, | |||
| char * | data, | |||
| char * | buf, | |||
| size_t | buflen | |||
| ) | [static] |
Definition at line 986 of file func_strings.c.
| static int string_toupper | ( | struct ast_channel * | chan, | |
| const char * | cmd, | |||
| char * | data, | |||
| char * | buf, | |||
| size_t | buflen | |||
| ) | [static] |
Definition at line 972 of file func_strings.c.
| static int unload_module | ( | void | ) | [static] |
Definition at line 1000 of file func_strings.c.
References ast_custom_function_unregister(), and ast_unregister_application().
01001 { 01002 int res = 0; 01003 01004 res |= ast_custom_function_unregister(&fieldqty_function); 01005 res |= ast_custom_function_unregister(&filter_function); 01006 res |= ast_custom_function_unregister(&listfilter_function); 01007 res |= ast_custom_function_unregister(®ex_function); 01008 res |= ast_custom_function_unregister(&array_function); 01009 res |= ast_custom_function_unregister("e_function); 01010 res |= ast_custom_function_unregister(&csv_quote_function); 01011 res |= ast_custom_function_unregister(&len_function); 01012 res |= ast_custom_function_unregister(&strftime_function); 01013 res |= ast_custom_function_unregister(&strptime_function); 01014 res |= ast_custom_function_unregister(&eval_function); 01015 res |= ast_custom_function_unregister(&keypadhash_function); 01016 res |= ast_custom_function_unregister(&hashkeys_function); 01017 res |= ast_custom_function_unregister(&hash_function); 01018 res |= ast_unregister_application(app_clearhash); 01019 res |= ast_custom_function_unregister(&toupper_function); 01020 res |= ast_custom_function_unregister(&tolower_function); 01021 01022 return res; 01023 }
char* app_clearhash = "ClearHash" [static] |
Definition at line 553 of file func_strings.c.
struct ast_custom_function array_function [static] |
{
.name = "ARRAY",
.write = array,
}
Definition at line 741 of file func_strings.c.
struct ast_custom_function csv_quote_function [static] |
{
.name = "CSV_QUOTE",
.read = csv_quote,
}
Definition at line 816 of file func_strings.c.
struct ast_custom_function eval_function [static] |
{
.name = "EVAL",
.read = function_eval,
}
Definition at line 927 of file func_strings.c.
struct ast_custom_function fieldqty_function [static] |
{
.name = "FIELDQTY",
.read = function_fieldqty,
}
Definition at line 326 of file func_strings.c.
struct ast_custom_function filter_function [static] |
{
.name = "FILTER",
.read = filter,
}
Definition at line 503 of file func_strings.c.
struct ast_custom_function hash_function [static] |
{
.name = "HASH",
.write = hash_write,
.read = hash_read,
}
Definition at line 730 of file func_strings.c.
struct ast_custom_function hashkeys_function [static] |
{
.name = "HASHKEYS",
.read = hashkeys_read,
}
Definition at line 736 of file func_strings.c.
struct ast_custom_function keypadhash_function [static] |
{
.name = "KEYPADHASH",
.read = keypadhash,
}
Definition at line 967 of file func_strings.c.
struct ast_custom_function len_function [static] |
{
.name = "LEN",
.read = len,
}
Definition at line 833 of file func_strings.c.
struct ast_custom_function listfilter_function [static] |
{
.name = "LISTFILTER",
.read = listfilter,
}
Definition at line 422 of file func_strings.c.
struct ast_custom_function quote_function [static] |
{
.name = "QUOTE",
.read = quote,
}
Definition at line 780 of file func_strings.c.
struct ast_custom_function regex_function [static] |
{
.name = "REGEX",
.read = regex,
}
Definition at line 545 of file func_strings.c.
struct ast_custom_function strftime_function [static] |
{
.name = "STRFTIME",
.read = acf_strftime,
}
Definition at line 867 of file func_strings.c.
struct ast_custom_function strptime_function [static] |
{
.name = "STRPTIME",
.read = acf_strptime,
}
Definition at line 909 of file func_strings.c.
struct ast_custom_function tolower_function [static] |
{
.name = "TOLOWER",
.read = string_tolower,
}
Definition at line 995 of file func_strings.c.
struct ast_custom_function toupper_function [static] |
{
.name = "TOUPPER",
.read = string_toupper,
}
Definition at line 981 of file func_strings.c.
1.6.1