Asterisk - The Open Source Telephony Project  GIT-master-8beac82
Macros | Functions | Variables
func_strings.c File Reference

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"
#include "asterisk/test.h"

Go to the source code of this file.

Macros

#define beginning   (cmd[0] == 'S') /* SHIFT */
 
#define beginning   (cmd[0] == 'U') /* UNSHIFT */
 
#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)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
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 const char * get_key (const struct ast_str *prefix, const struct ast_var_t *var)
 
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 strbetween (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 strreplace (struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len)
 
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 = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
 
static char * app_clearhash = "ClearHash"
 
static struct ast_custom_function array_function
 
static const struct ast_module_infoast_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 strbetween_function
 
static struct ast_custom_function strftime_function
 
static struct ast_custom_function strptime_function
 
static struct ast_custom_function strreplace_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
 

Detailed Description

String manipulation dialplan functions.

Author
Tilghman Lesher
Anothony Minessale II
Naveen Albert

Definition in file func_strings.c.

Macro Definition Documentation

◆ beginning [1/2]

#define beginning   (cmd[0] == 'S') /* SHIFT */

Referenced by shift_pop(), and unshift_push().

◆ beginning [2/2]

#define beginning   (cmd[0] == 'U') /* UNSHIFT */

◆ HASH_FORMAT

#define HASH_FORMAT   HASH_PREFIX "%s~"

Definition at line 1058 of file func_strings.c.

Referenced by array(), hash_read(), and hash_write().

◆ HASH_PREFIX

#define HASH_PREFIX   "~HASH~%s~"

Definition at line 1057 of file func_strings.c.

Referenced by exec_clearhash(), hashkeys_read(), and hashkeys_read2().

Function Documentation

◆ __init_result_buf()

static void __init_result_buf ( void  )
static

Definition at line 47 of file func_strings.c.

462 {

◆ __init_tmp_buf()

static void __init_tmp_buf ( void  )
static

Definition at line 48 of file func_strings.c.

462 {

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 2176 of file func_strings.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 2176 of file func_strings.c.

◆ acf_strftime()

static int acf_strftime ( struct ast_channel chan,
const char *  cmd,
char *  parse,
char *  buf,
size_t  buflen 
)
static

Definition at line 1429 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, LOG_WARNING, and NULL.

1431 {
1433  AST_APP_ARG(epoch);
1434  AST_APP_ARG(timezone);
1436  );
1437  struct timeval when;
1438  struct ast_tm tm;
1439 
1440  buf[0] = '\0';
1441 
1443 
1444  ast_get_timeval(args.epoch, &when, ast_tvnow(), NULL);
1445  ast_localtime(&when, &tm, args.timezone);
1446 
1447  if (!args.format)
1448  args.format = "%c";
1449 
1450  if (ast_strftime(buf, buflen, args.format, &tm) <= 0)
1451  ast_log(LOG_WARNING, "C function strftime() output nothing?!!\n");
1452 
1453  buf[buflen - 1] = '\0';
1454 
1455  return 0;
1456 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
#define LOG_WARNING
Definition: logger.h:274
struct ast_tm * ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone)
Timezone-independent version of localtime_r(3).
Definition: localtime.c:1739
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:150
const char * args
#define NULL
Definition: resample.c:96
int ast_get_timeval(const char *src, struct timeval *tv, struct timeval _default, int *consumed)
get values from config variables.
Definition: main/utils.c:2171
#define ast_log
Definition: astobj2.c:42
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1844
int ast_strftime(char *buf, size_t len, const char *format, const struct ast_tm *tm)
Special version of strftime(3) that handles fractions of a second. Takes the same arguments as strfti...
Definition: localtime.c:2524
static snd_pcm_format_t format
Definition: chan_alsa.c:106
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
#define AST_APP_ARG(name)
Define an application argument.

◆ acf_strptime()

static int acf_strptime ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  buflen 
)
static

Definition at line 1463 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.

1465 {
1467  AST_APP_ARG(timestring);
1468  AST_APP_ARG(timezone);
1470  );
1471  struct ast_tm tm;
1472 
1473  buf[0] = '\0';
1474 
1475  if (!data) {
1477  "Asterisk function STRPTIME() requires an argument.\n");
1478  return -1;
1479  }
1480 
1481  AST_STANDARD_APP_ARGS(args, data);
1482 
1483  if (ast_strlen_zero(args.format)) {
1485  "No format supplied to STRPTIME(<timestring>,<timezone>,<format>)");
1486  return -1;
1487  }
1488 
1489  if (!ast_strptime(args.timestring, args.format, &tm)) {
1490  ast_log(LOG_WARNING, "STRPTIME() found no time specified within the string\n");
1491  } else {
1492  struct timeval when;
1493  when = ast_mktime(&tm, args.timezone);
1494  snprintf(buf, buflen, "%d", (int) when.tv_sec);
1495  }
1496 
1497  return 0;
1498 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
#define LOG_WARNING
Definition: logger.h:274
const char * args
#define ast_log
Definition: astobj2.c:42
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
char * ast_strptime(const char *s, const char *format, struct ast_tm *tm)
Special version of strptime(3) which places the answer in the common structure ast_tm. Also, unlike strptime(3), ast_strptime() initializes its memory prior to use.
Definition: localtime.c:2550
#define LOG_ERROR
Definition: logger.h:285
struct timeval ast_mktime(struct ast_tm *const tmp, const char *zone)
Timezone-independent version of mktime(3).
Definition: localtime.c:2357
static snd_pcm_format_t format
Definition: chan_alsa.c:106
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
#define AST_APP_ARG(name)
Define an application argument.

◆ array()

static int array ( struct ast_channel chan,
const char *  cmd,
char *  var,
const char *  value 
)
static
Examples:
/tmp/asterisk-shallow/main/app.c.

Definition at line 1084 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(), S_OR, and var.

Referenced by app_to_json(), append_json(), device_to_json_cb(), devices_to_json(), hash_write(), json_array_from_list(), stasis_app_device_states_to_json(), and stasis_app_mailboxes_to_json().

1086 {
1087  AST_DECLARE_APP_ARGS(arg1,
1088  AST_APP_ARG(var)[100];
1089  );
1090  AST_DECLARE_APP_ARGS(arg2,
1091  AST_APP_ARG(val)[100];
1092  );
1093  char *origvar = "", *value2, varname[256];
1094  int i, ishash = 0;
1095 
1096  if (!var) {
1097  return -1;
1098  }
1099  value2 = ast_strdupa(value);
1100 
1101  if (!strcmp(cmd, "HASH")) {
1102  const char *var2 = pbx_builtin_getvar_helper(chan, "~ODBCFIELDS~");
1103  origvar = var;
1104  if (var2)
1105  var = ast_strdupa(var2);
1106  else {
1107  if (chan)
1108  ast_autoservice_stop(chan);
1109  return -1;
1110  }
1111  ishash = 1;
1112  }
1113 
1114  /* The functions this will generally be used with are SORT and ODBC_*, which
1115  * both return comma-delimited lists. However, if somebody uses literal lists,
1116  * their commas will be translated to vertical bars by the load, and I don't
1117  * want them to be surprised by the result. Hence, we prefer commas as the
1118  * delimiter, but we'll fall back to vertical bars if commas aren't found.
1119  */
1120  ast_debug(1, "array (%s=%s)\n", var, S_OR(value2, ""));
1121  AST_STANDARD_APP_ARGS(arg1, var);
1122 
1123  AST_STANDARD_APP_ARGS(arg2, value2);
1124 
1125  for (i = 0; i < arg1.argc; i++) {
1126  ast_debug(1, "array set value (%s=%s)\n", arg1.var[i],
1127  S_OR(arg2.val[i], ""));
1128  if (i < arg2.argc) {
1129  if (ishash) {
1130  if (origvar[0] == '_') {
1131  if (origvar[1] == '_') {
1132  snprintf(varname, sizeof(varname), "__" HASH_FORMAT, origvar + 2, arg1.var[i]);
1133  } else {
1134  snprintf(varname, sizeof(varname), "_" HASH_FORMAT, origvar + 1, arg1.var[i]);
1135  }
1136  } else {
1137  snprintf(varname, sizeof(varname), HASH_FORMAT, origvar, arg1.var[i]);
1138  }
1139 
1140  pbx_builtin_setvar_helper(chan, varname, arg2.val[i]);
1141  } else {
1142  pbx_builtin_setvar_helper(chan, arg1.var[i], arg2.val[i]);
1143  }
1144  } else {
1145  /* We could unset the variable, by passing a NULL, but due to
1146  * pushvar semantics, that could create some undesired behavior. */
1147  if (ishash) {
1148  snprintf(varname, sizeof(varname), HASH_FORMAT, origvar, arg1.var[i]);
1149  pbx_builtin_setvar_helper(chan, varname, "");
1150  } else {
1151  pbx_builtin_setvar_helper(chan, arg1.var[i], "");
1152  }
1153  }
1154  }
1155 
1156  return 0;
1157 }
Definition: ast_expr2.c:325
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
#define var
Definition: ast_expr2f.c:614
#define HASH_FORMAT
int value
Definition: syslog.c:37
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
int ast_autoservice_stop(struct ast_channel *chan)
Stop servicing a channel for us...
Definition: autoservice.c:266
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name...
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:79
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
#define AST_APP_ARG(name)
Define an application argument.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 2176 of file func_strings.c.

◆ clearvar_prefix()

static void clearvar_prefix ( struct ast_channel chan,
const char *  prefix 
)
static

Definition at line 1063 of file func_strings.c.

References ast_channel_varshead(), ast_free, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_var_name(), ast_var_t::entries, len(), and var.

Referenced by exec_clearhash().

1064 {
1065  struct ast_var_t *var;
1066  int len = strlen(prefix);
1068  if (strncmp(prefix, ast_var_name(var), len) == 0) {
1070  ast_free(var);
1071  }
1072  }
1074 }
const char * ast_var_name(const struct ast_var_t *var)
Definition: chanvars.c:60
#define var
Definition: ast_expr2f.c:614
struct varshead * ast_channel_varshead(struct ast_channel *chan)
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:614
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:556
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define ast_free(a)
Definition: astmm.h:182
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:528
struct ast_var_t::@236 entries
static char prefix[MAX_PREFIX]
Definition: http.c:141

◆ csv_quote()

static int csv_quote ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
)
static

Definition at line 1376 of file func_strings.c.

References ast_copy_string(), ast_log, ast_strlen_zero(), buf, and LOG_ERROR.

1377 {
1378  char *bufptr = buf, *dataptr = data;
1379 
1380  if (len < 3) { /* at least two for quotes and one for binary zero */
1381  ast_log(LOG_ERROR, "Not enough buffer\n");
1382  return -1;
1383  }
1384 
1385  if (ast_strlen_zero(data)) {
1386  ast_copy_string(buf, "\"\"", len);
1387  return 0;
1388  }
1389 
1390  *bufptr++ = '"';
1391  for (; bufptr < buf + len - 3; dataptr++){
1392  if (*dataptr == '"') {
1393  *bufptr++ = '"';
1394  *bufptr++ = '"';
1395  } else if (*dataptr == '\0') {
1396  break;
1397  } else {
1398  *bufptr++ = *dataptr;
1399  }
1400  }
1401  *bufptr++ = '"';
1402  *bufptr='\0';
1403  return 0;
1404 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define ast_log
Definition: astobj2.c:42
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
#define LOG_ERROR
Definition: logger.h:285
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401

◆ exec_clearhash()

static int exec_clearhash ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 1076 of file func_strings.c.

References clearvar_prefix(), HASH_PREFIX, and prefix.

Referenced by load_module().

1077 {
1078  char prefix[80];
1079  snprintf(prefix, sizeof(prefix), HASH_PREFIX, data ? (char *)data : "null");
1080  clearvar_prefix(chan, prefix);
1081  return 0;
1082 }
static void clearvar_prefix(struct ast_channel *chan, const char *prefix)
#define HASH_PREFIX
static char prefix[MAX_PREFIX]
Definition: http.c:141

◆ filter()

static int filter ( struct ast_channel chan,
const char *  cmd,
char *  parse,
char *  buf,
size_t  len 
)
static
Note
Looks a little strange, until you realize that we can overflow the size of a char.

Definition at line 729 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, buf, LOG_ERROR, and LOG_WARNING.

Referenced by action_filter(), action_getconfig(), action_getconfigjson(), create_lookup_filter(), kqueue_timer_ack(), process_text_line(), realtime_ldap_base_ap(), stasis_subscription_set_filter(), and update2_ldap().

731 {
733  AST_APP_ARG(allowed);
734  AST_APP_ARG(string);
735  );
736  char *outbuf = buf;
737  unsigned char ac;
738  char allowed[256] = "";
739  size_t allowedlen = 0;
740  int32_t bitfield[8] = { 0, }; /* 256 bits */
741 
743 
744  if (!args.string) {
745  ast_log(LOG_ERROR, "Usage: FILTER(<allowed-chars>,<string>)\n");
746  return -1;
747  }
748 
749  if (args.allowed[0] == '"' && !ast_opt_dont_warn) {
750  ast_log(LOG_WARNING, "FILTER allowed characters includes the quote (\") character. This may not be what you want.\n");
751  }
752 
753  /* Expand ranges */
754  for (; *(args.allowed);) {
755  char c1 = 0, c2 = 0;
756  size_t consumed = 0;
757 
758  if (ast_get_encoded_char(args.allowed, &c1, &consumed))
759  return -1;
760  args.allowed += consumed;
761 
762  if (*(args.allowed) == '-') {
763  if (ast_get_encoded_char(args.allowed + 1, &c2, &consumed))
764  c2 = c1;
765  args.allowed += consumed + 1;
766 
767  if ((unsigned char) c2 < (unsigned char) c1 && !ast_opt_dont_warn) {
768  ast_log(LOG_WARNING, "Range wrapping in FILTER(%s,%s). This may not be what you want.\n", parse, args.string);
769  }
770 
771  /*!\note
772  * Looks a little strange, until you realize that we can overflow
773  * the size of a char.
774  */
775  for (ac = (unsigned char) c1; ac != (unsigned char) c2; ac++) {
776  bitfield[ac / 32] |= 1 << (ac % 32);
777  }
778  bitfield[ac / 32] |= 1 << (ac % 32);
779 
780  ast_debug(4, "c1=%d, c2=%d\n", c1, c2);
781  } else {
782  ac = (unsigned char) c1;
783  ast_debug(4, "c1=%d, consumed=%d, args.allowed=%s\n", c1, (int) consumed, args.allowed - consumed);
784  bitfield[ac / 32] |= 1 << (ac % 32);
785  }
786  }
787 
788  for (ac = 1; ac != 0; ac++) {
789  if (bitfield[ac / 32] & (1 << (ac % 32))) {
790  allowed[allowedlen++] = ac;
791  }
792  }
793 
794  ast_debug(1, "Allowed: %s\n", allowed);
795 
796  for (; *(args.string) && (buf + len - 1 > outbuf); (args.string)++) {
797  if (strchr(allowed, *(args.string)))
798  *outbuf++ = *(args.string);
799  }
800  *outbuf = '\0';
801 
802  return 0;
803 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define LOG_WARNING
Definition: logger.h:274
#define AST_STANDARD_RAW_ARGS(args, parse)
const char * args
#define ast_opt_dont_warn
Definition: options.h:125
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_log
Definition: astobj2.c:42
int ast_get_encoded_char(const char *stream, char *result, size_t *consumed)
Decode an encoded control or extended ASCII character.
Definition: main/app.c:2867
#define LOG_ERROR
Definition: logger.h:285
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1844
int int32_t
Definition: db.h:60
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
#define AST_APP_ARG(name)
Define an application argument.

◆ function_eval()

static int function_eval ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  buflen 
)
static

Definition at line 1505 of file func_strings.c.

References ast_log, ast_strlen_zero(), LOG_WARNING, and pbx_substitute_variables_helper().

1507 {
1508  if (ast_strlen_zero(data)) {
1509  ast_log(LOG_WARNING, "EVAL requires an argument: EVAL(<string>)\n");
1510  return -1;
1511  }
1512 
1513  pbx_substitute_variables_helper(chan, data, buf, buflen - 1);
1514 
1515  return 0;
1516 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define LOG_WARNING
Definition: logger.h:274
#define ast_log
Definition: astobj2.c:42
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
void pbx_substitute_variables_helper(struct ast_channel *c, const char *cp1, char *cp2, int count)
Definition: ael_main.c:211

◆ function_eval2()

static int function_eval2 ( struct ast_channel chan,
const char *  cmd,
char *  data,
struct ast_str **  buf,
ssize_t  buflen 
)
static

Definition at line 1518 of file func_strings.c.

References ast_log, ast_str_substitute_variables(), ast_strlen_zero(), and LOG_WARNING.

1520 {
1521  if (ast_strlen_zero(data)) {
1522  ast_log(LOG_WARNING, "EVAL requires an argument: EVAL(<string>)\n");
1523  return -1;
1524  }
1525 
1526  ast_str_substitute_variables(buf, buflen, chan, data);
1527 
1528  return 0;
1529 }
#define LOG_WARNING
Definition: logger.h:274
void ast_str_substitute_variables(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, const char *templ)
#define ast_log
Definition: astobj2.c:42
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65

◆ function_fieldnum()

static int function_fieldnum ( struct ast_channel chan,
const char *  cmd,
char *  parse,
char *  buf,
size_t  len 
)
static

Definition at line 584 of file func_strings.c.

References function_fieldnum_helper(), and NULL.

586 {
587  return function_fieldnum_helper(chan, cmd, parse, buf, NULL, len);
588 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define NULL
Definition: resample.c:96
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1844
static int function_fieldnum_helper(struct ast_channel *chan, const char *cmd, char *parse, char *buf, struct ast_str **sbuf, ssize_t len)
Definition: func_strings.c:523

◆ function_fieldnum_helper()

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 523 of file func_strings.c.

References args, ast_alloca, 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, NULL, result_buf, str, and strsep().

Referenced by function_fieldnum(), and function_fieldnum_str().

525 {
526  char *varsubst, *field;
527  struct ast_str *str = ast_str_thread_get(&result_buf, 16);
528  int fieldindex = 0, res = 0;
530  AST_APP_ARG(varname);
531  AST_APP_ARG(delim);
532  AST_APP_ARG(field);
533  );
534  char delim[2] = "";
535  size_t delim_used;
536 
537  if (!str) {
538  return -1;
539  }
540 
542 
543  if (args.argc < 3) {
544  ast_log(LOG_ERROR, "Usage: FIELDNUM(<listname>,<delimiter>,<fieldvalue>)\n");
545  res = -1;
546  } else {
547  varsubst = ast_alloca(strlen(args.varname) + 4);
548  sprintf(varsubst, "${%s}", args.varname);
549 
550  ast_str_substitute_variables(&str, 0, chan, varsubst);
551 
552  if (ast_str_strlen(str) == 0 || ast_strlen_zero(args.delim)) {
553  fieldindex = 0;
554  } else if (ast_get_encoded_char(args.delim, delim, &delim_used) == -1) {
555  res = -1;
556  } else {
557  char *varval = ast_str_buffer(str);
558 
559  while ((field = strsep(&varval, delim)) != NULL) {
560  fieldindex++;
561 
562  if (!strcasecmp(field, args.field)) {
563  break;
564  }
565  }
566 
567  if (!field) {
568  fieldindex = 0;
569  }
570 
571  res = 0;
572  }
573  }
574 
575  if (sbuf) {
576  ast_str_set(sbuf, len, "%d", fieldindex);
577  } else {
578  snprintf(buf, len, "%d", fieldindex);
579  }
580 
581  return res;
582 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
void ast_str_substitute_variables(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, const char *templ)
const char * str
Definition: app_jack.c:147
const char * args
#define NULL
Definition: resample.c:96
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Definition: strings.h:1065
#define ast_log
Definition: astobj2.c:42
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
int ast_get_encoded_char(const char *stream, char *result, size_t *consumed)
Decode an encoded control or extended ASCII character.
Definition: main/app.c:2867
static struct ast_threadstorage result_buf
Definition: func_strings.c:47
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: astmm.h:290
#define LOG_ERROR
Definition: logger.h:285
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1844
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition: strings.h:688
char * strsep(char **str, const char *delims)
struct ast_str * ast_str_thread_get(struct ast_threadstorage *ts, size_t init_len)
Retrieve a thread locally stored dynamic string.
Definition: strings.h:861
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
#define AST_APP_ARG(name)
Define an application argument.

◆ function_fieldnum_str()

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 590 of file func_strings.c.

References function_fieldnum_helper(), and NULL.

592 {
593  return function_fieldnum_helper(chan, cmd, parse, NULL, buf, len);
594 }
#define NULL
Definition: resample.c:96
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1844
static int function_fieldnum_helper(struct ast_channel *chan, const char *cmd, char *parse, char *buf, struct ast_str **sbuf, ssize_t len)
Definition: func_strings.c:523

◆ function_fieldqty()

static int function_fieldqty ( struct ast_channel chan,
const char *  cmd,
char *  parse,
char *  buf,
size_t  len 
)
static

Definition at line 505 of file func_strings.c.

References function_fieldqty_helper(), and NULL.

507 {
508  return function_fieldqty_helper(chan, cmd, parse, buf, NULL, len);
509 }
static int function_fieldqty_helper(struct ast_channel *chan, const char *cmd, char *parse, char *buf, struct ast_str **sbuf, ssize_t len)
Definition: func_strings.c:460
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define NULL
Definition: resample.c:96
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1844

◆ function_fieldqty_helper()

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 460 of file func_strings.c.

References args, ast_alloca, 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().

462 {
463  char *varsubst;
464  struct ast_str *str = ast_str_thread_get(&result_buf, 16);
465  int fieldcount = 0;
467  AST_APP_ARG(varname);
468  AST_APP_ARG(delim);
469  );
470  char delim[2] = "";
471  size_t delim_used;
472 
473  if (!str) {
474  return -1;
475  }
476 
478  if (args.delim) {
479  ast_get_encoded_char(args.delim, delim, &delim_used);
480 
481  varsubst = ast_alloca(strlen(args.varname) + 4);
482 
483  sprintf(varsubst, "${%s}", args.varname);
484  ast_str_substitute_variables(&str, 0, chan, varsubst);
485  if (ast_str_strlen(str) == 0) {
486  fieldcount = 0;
487  } else {
488  char *varval = ast_str_buffer(str);
489  while (strsep(&varval, delim)) {
490  fieldcount++;
491  }
492  }
493  } else {
494  fieldcount = 1;
495  }
496  if (sbuf) {
497  ast_str_set(sbuf, len, "%d", fieldcount);
498  } else {
499  snprintf(buf, len, "%d", fieldcount);
500  }
501 
502  return 0;
503 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
void ast_str_substitute_variables(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, const char *templ)
const char * str
Definition: app_jack.c:147
const char * args
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Definition: strings.h:1065
int ast_get_encoded_char(const char *stream, char *result, size_t *consumed)
Decode an encoded control or extended ASCII character.
Definition: main/app.c:2867
static struct ast_threadstorage result_buf
Definition: func_strings.c:47
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: astmm.h:290
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1844
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition: strings.h:688
char * strsep(char **str, const char *delims)
struct ast_str * ast_str_thread_get(struct ast_threadstorage *ts, size_t init_len)
Retrieve a thread locally stored dynamic string.
Definition: strings.h:861
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
#define AST_APP_ARG(name)
Define an application argument.

◆ function_fieldqty_str()

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 511 of file func_strings.c.

References function_fieldqty_helper(), and NULL.

513 {
514  return function_fieldqty_helper(chan, cmd, parse, NULL, buf, len);
515 }
static int function_fieldqty_helper(struct ast_channel *chan, const char *cmd, char *parse, char *buf, struct ast_str **sbuf, ssize_t len)
Definition: func_strings.c:460
#define NULL
Definition: resample.c:96
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1844

◆ get_key()

static const char* get_key ( const struct ast_str prefix,
const struct ast_var_t var 
)
static

Definition at line 1159 of file func_strings.c.

References ast_str_buffer(), ast_str_strlen(), ast_strlen_zero(), ast_var_name(), and NULL.

Referenced by hashkeys_read(), and hashkeys_read2().

1160 {
1161  const char *prefix_name = ast_str_buffer(prefix);
1162  const char *var_name = ast_var_name(var);
1163  int prefix_len;
1164  int var_len;
1165 
1166  if (ast_strlen_zero(var_name)) {
1167  return NULL;
1168  }
1169 
1170  prefix_len = ast_str_strlen(prefix);
1171  var_len = strlen(var_name);
1172 
1173  /*
1174  * Make sure we only match on non-empty, hash function created keys. If valid
1175  * then return a pointer to the variable that's just after the prefix.
1176  */
1177  return var_len > (prefix_len + 1) && var_name[var_len - 1] == '~' &&
1178  strncmp(prefix_name, var_name, prefix_len) == 0 ? var_name + prefix_len : NULL;
1179 }
const char * ast_var_name(const struct ast_var_t *var)
Definition: chanvars.c:60
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
#define NULL
Definition: resample.c:96
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition: strings.h:688

◆ hash_read()

static int hash_read ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
)
static

Definition at line 1269 of file func_strings.c.

References AST_APP_ARG, ast_copy_string(), AST_DECLARE_APP_ARGS, ast_log, AST_STANDARD_APP_ARGS, HASH_FORMAT, hashkeys_read(), LOG_WARNING, pbx_builtin_getvar_helper(), and pbx_builtin_setvar_helper().

1270 {
1271  char varname[256];
1272  const char *varvalue;
1274  AST_APP_ARG(hashname);
1275  AST_APP_ARG(hashkey);
1276  );
1277 
1278  AST_STANDARD_APP_ARGS(arg, data);
1279  if (arg.argc == 2) {
1280  snprintf(varname, sizeof(varname), HASH_FORMAT, arg.hashname, arg.hashkey);
1281  varvalue = pbx_builtin_getvar_helper(chan, varname);
1282  if (varvalue)
1283  ast_copy_string(buf, varvalue, len);
1284  else
1285  *buf = '\0';
1286  } else if (arg.argc == 1) {
1287  char colnames[4096];
1288  int i;
1289  AST_DECLARE_APP_ARGS(arg2,
1290  AST_APP_ARG(col)[100];
1291  );
1292 
1293  if (!chan) {
1294  ast_log(LOG_WARNING, "No channel and only 1 parameter was provided to %s function.\n", cmd);
1295  return -1;
1296  }
1297 
1298  /* Get column names, in no particular order */
1299  hashkeys_read(chan, "HASHKEYS", arg.hashname, colnames, sizeof(colnames));
1300  pbx_builtin_setvar_helper(chan, "~ODBCFIELDS~", colnames);
1301 
1302  AST_STANDARD_APP_ARGS(arg2, colnames);
1303  *buf = '\0';
1304 
1305  /* Now get the corresponding column values, in exactly the same order */
1306  for (i = 0; i < arg2.argc; i++) {
1307  snprintf(varname, sizeof(varname), HASH_FORMAT, arg.hashname, arg2.col[i]);
1308  varvalue = pbx_builtin_getvar_helper(chan, varname);
1309  strncat(buf, varvalue, len - strlen(buf) - 1);
1310  strncat(buf, ",", len - strlen(buf) - 1);
1311  }
1312 
1313  /* Strip trailing comma */
1314  buf[strlen(buf) - 1] = '\0';
1315  }
1316 
1317  return 0;
1318 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
#define LOG_WARNING
Definition: logger.h:274
#define HASH_FORMAT
static int hashkeys_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
#define ast_log
Definition: astobj2.c:42
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name...
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
#define AST_APP_ARG(name)
Define an application argument.

◆ hash_write()

static int hash_write ( struct ast_channel chan,
const char *  cmd,
char *  var,
const char *  value 
)
static

Definition at line 1241 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().

1242 {
1243  char varname[256];
1245  AST_APP_ARG(hashname);
1246  AST_APP_ARG(hashkey);
1247  );
1248 
1249  if (!strchr(var, ',')) {
1250  /* Single argument version */
1251  return array(chan, "HASH", var, value);
1252  }
1253 
1254  AST_STANDARD_APP_ARGS(arg, var);
1255  if (arg.hashname[0] == '_') {
1256  if (arg.hashname[1] == '_') {
1257  snprintf(varname, sizeof(varname), "__" HASH_FORMAT, arg.hashname + 2, arg.hashkey);
1258  } else {
1259  snprintf(varname, sizeof(varname), "_" HASH_FORMAT, arg.hashname + 1, arg.hashkey);
1260  }
1261  } else {
1262  snprintf(varname, sizeof(varname), HASH_FORMAT, arg.hashname, arg.hashkey);
1263  }
1264  pbx_builtin_setvar_helper(chan, varname, value);
1265 
1266  return 0;
1267 }
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
#define var
Definition: ast_expr2f.c:614
#define HASH_FORMAT
int value
Definition: syslog.c:37
static int array(struct ast_channel *chan, const char *cmd, char *var, const char *value)
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name...
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
#define AST_APP_ARG(name)
Define an application argument.

◆ hashkeys_read()

static int hashkeys_read ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
)
static

Definition at line 1181 of file func_strings.c.

References ast_channel_varshead(), AST_LIST_TRAVERSE, ast_log, ast_str_alloca, ast_str_set(), get_key(), HASH_PREFIX, LOG_WARNING, and prefix.

Referenced by hash_read().

1182 {
1183  struct ast_var_t *newvar;
1184  struct ast_str *prefix = ast_str_alloca(80);
1185  size_t buf_len;
1186 
1187  if (!chan) {
1188  ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
1189  return -1;
1190  }
1191 
1192  ast_str_set(&prefix, -1, HASH_PREFIX, data);
1193  memset(buf, 0, len);
1194 
1195  AST_LIST_TRAVERSE(ast_channel_varshead(chan), newvar, entries) {
1196  const char *key = get_key(prefix, newvar);
1197 
1198  if (key) {
1199  strncat(buf, key, len - strlen(buf) - 1);
1200  /* Replace the trailing ~ */
1201  buf[strlen(buf) - 1] = ',';
1202  }
1203  }
1204  /* Trim the trailing comma */
1205  buf_len = strlen(buf);
1206  if (buf_len) {
1207  buf[buf_len - 1] = '\0';
1208  }
1209  return 0;
1210 }
static const char * get_key(const struct ast_str *prefix, const struct ast_var_t *var)
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define LOG_WARNING
Definition: logger.h:274
#define ast_str_alloca(init_len)
Definition: strings.h:800
struct varshead * ast_channel_varshead(struct ast_channel *chan)
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Definition: strings.h:1065
#define ast_log
Definition: astobj2.c:42
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
#define HASH_PREFIX
static char prefix[MAX_PREFIX]
Definition: http.c:141

◆ hashkeys_read2()

static int hashkeys_read2 ( struct ast_channel chan,
const char *  cmd,
char *  data,
struct ast_str **  buf,
ssize_t  len 
)
static

Definition at line 1212 of file func_strings.c.

References ast_channel_varshead(), AST_LIST_TRAVERSE, ast_log, ast_str_alloca, ast_str_append(), ast_str_buffer(), ast_str_set(), ast_str_strlen(), ast_str_truncate(), get_key(), HASH_PREFIX, LOG_WARNING, prefix, and tmp().

1213 {
1214  struct ast_var_t *newvar;
1215  struct ast_str *prefix = ast_str_alloca(80);
1216 
1217  if (!chan) {
1218  ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
1219  return -1;
1220  }
1221 
1222  ast_str_set(&prefix, -1, HASH_PREFIX, data);
1223 
1224  AST_LIST_TRAVERSE(ast_channel_varshead(chan), newvar, entries) {
1225  const char *key = get_key(prefix, newvar);
1226 
1227  if (key) {
1228  char *tmp;
1229 
1230  ast_str_append(buf, len, "%s", key);
1231  /* Replace the trailing ~ */
1232  tmp = ast_str_buffer(*buf);
1233  tmp[ast_str_strlen(*buf) - 1] = ',';
1234  }
1235  }
1236 
1237  ast_str_truncate(*buf, -1);
1238  return 0;
1239 }
static const char * get_key(const struct ast_str *prefix, const struct ast_var_t *var)
#define LOG_WARNING
Definition: logger.h:274
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
static int tmp()
Definition: bt_open.c:389
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:1091
#define ast_str_alloca(init_len)
Definition: strings.h:800
struct varshead * ast_channel_varshead(struct ast_channel *chan)
char * ast_str_truncate(struct ast_str *buf, ssize_t len)
Truncates the enclosed string to the given length.
Definition: strings.h:738
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Definition: strings.h:1065
#define ast_log
Definition: astobj2.c:42
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition: strings.h:688
#define HASH_PREFIX
static char prefix[MAX_PREFIX]
Definition: http.c:141

◆ keypadhash()

static int keypadhash ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  buflen 
)
static

Definition at line 1537 of file func_strings.c.

1538 {
1539  char *bufptr, *dataptr;
1540 
1541  for (bufptr = buf, dataptr = data; bufptr < buf + buflen - 1; dataptr++) {
1542  if (*dataptr == '\0') {
1543  *bufptr++ = '\0';
1544  break;
1545  } else if (*dataptr == '1') {
1546  *bufptr++ = '1';
1547  } else if (strchr("AaBbCc2", *dataptr)) {
1548  *bufptr++ = '2';
1549  } else if (strchr("DdEeFf3", *dataptr)) {
1550  *bufptr++ = '3';
1551  } else if (strchr("GgHhIi4", *dataptr)) {
1552  *bufptr++ = '4';
1553  } else if (strchr("JjKkLl5", *dataptr)) {
1554  *bufptr++ = '5';
1555  } else if (strchr("MmNnOo6", *dataptr)) {
1556  *bufptr++ = '6';
1557  } else if (strchr("PpQqRrSs7", *dataptr)) {
1558  *bufptr++ = '7';
1559  } else if (strchr("TtUuVv8", *dataptr)) {
1560  *bufptr++ = '8';
1561  } else if (strchr("WwXxYyZz9", *dataptr)) {
1562  *bufptr++ = '9';
1563  } else if (*dataptr == '0') {
1564  *bufptr++ = '0';
1565  }
1566  }
1567  buf[buflen - 1] = '\0';
1568 
1569  return 0;
1570 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66

◆ len()

static int len ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  buflen 
)
static
Examples:
/tmp/asterisk-shallow/include/asterisk/strings.h, and /tmp/asterisk-shallow/main/app.c.

Definition at line 1411 of file func_strings.c.

Referenced by __analog_ss_thread(), __ast_cli_register(), __ast_cli_register_multiple(), __ast_dsp_call_progress(), __ast_dsp_silence_noise(), __ast_frdup(), __big_return(), __bt_defcmp(), __bt_defpfx(), OrderedDict::__eq__(), __get_header(), OrderedDict::__init__(), __rec_fmap(), __rec_fpipe(), __rec_vpipe(), __rtp_recvfrom(), __rtp_sendto(), MultiOrderedDict::__setitem__(), AbsQuantW(), acf_escape(), action_command(), FaxPcap::add(), add_sdp(), adsi_careful_send(), ael_token_subst(), alsa_write(), amdf_pitch(), anaFilter(), analog_ss_thread(), anti_injection(), ao2_container_check(), aoc_parse_ie(), append_interface(), append_var_and_value_to_filter(), apply_outgoing(), ast_agi_register_multiple(), ast_agi_unregister_multiple(), ast_app_group_set_channel(), ast_app_options2str64(), ast_audiosocket_receive_frame(), ast_beep_start(), ast_bucket_alloc(), ast_bucket_file_alloc(), ast_channel_get_cc_agent_type(), ast_channel_get_device_name(), ast_cli_complete(), ast_cli_unregister_multiple(), ast_dsp_process(), ast_dsp_silence_noise_with_energy(), ast_format_str_reduce(), ast_get_namedgroups(), ast_http_send(), ast_http_uri_link(), ast_iostream_gets(), ast_iostream_printf(), ast_join_delim(), ast_json_utf8_check_len(), ast_mkdir(), ast_msg_data_alloc(), ast_read_image(), ast_register_cleanup(), ast_rtcp_generate_report(), ast_rtcp_generate_sdes(), ast_rtp_interpret(), ast_say_number_full_ka(), ast_sockaddr_from_pj_sockaddr(), ast_srtp_protect(), ast_srtp_unprotect(), ast_statsd_log_string(), ast_str_buffer(), ast_str_substitute_variables_full(), ast_tdd_gen_ecdisa(), AST_TEST_DEFINE(), ast_translate(), ast_websocket_write_string(), ast_xml_escape(), ast_xmldoc_printable(), auth_exec(), authenticate(), bucket_copy(), bucket_file_wizard_retrieve(), bucket_wizard_retrieve(), build_device(), build_ha(), build_regex(), build_route(), calc_energy(), category_set_sublevels(), CB_ADD_LEN(), cdr_read(), channel_do_masquerade(), chararray_handler_fn(), cleaned_basedn(), clearvar_prefix(), cli_complete(), cli_console_sendtext(), sip_to_pjsql::cli_options(), sip_to_pjsip::cli_options(), closefrom(), complete_confno(), complete_dialplan_add_extension(), complete_dialplan_add_ignorepat(), complete_dialplan_add_include(), complete_dialplan_remove_context(), complete_dialplan_remove_extension(), complete_dialplan_remove_ignorepat(), complete_dialplan_remove_include(), complete_meetmecmd_list(), complete_meetmecmd_mute_kick(), complete_peer_helper(), complete_userno(), conf_get_pin(), conf_play(), cops_getmsg(), copy(), create_video_frame(), custom_level_still_exists(), dahdi_cc_callback(), dahdi_chan_conf_default(), dahdi_sendtext(), dahdi_setoption(), dbl_list_expect_reverse(), dbm_open(), dcbias_(), devstate_write(), dialgroup_refreshdb(), dictate_exec(), do_pktccops(), dtmf_store_framehook(), dump_addr(), dump_ipaddr(), dump_prefs(), dump_raw(), dump_string(), dump_versioned_codec(), dundi_encrypt(), dundi_parse_ies(), dundi_send(), energy_(), expand_gosub_args(), expr2_token_subst(), ext_cmp_exten_strlen(), fbuf_append(), fetch_response_reader(), ffmpeg_decode(), frame_set_var(), fsk_serial(), func_read_header(), func_read_headers(), g722_decode(), g722_encode(), PathSegment::get_child(), get_content_line(), get_name_from_resource(), get_sdp(), get_sdp_iterate(), gsm_write(), gsmtolin_framein(), h261_encap(), h263_encap(), h263_read(), h263_write(), h263p_encap(), h264_read(), h264_write(), handle_cli_devstate_change(), handle_cli_mobile_search(), handle_cli_moh_unregister_class(), handle_cli_presencestate_change(), handle_commandmatchesarray(), handle_incoming(), handle_keypad_button_message(), handle_output(), handle_response(), handle_show_sysinfo(), handle_soft_key_event_message(), Model::has_properties(), Model::has_subtypes(), header_identify_match_check(), help1(), hepv3_create_capture_info(), hpInput(), hpOutput(), http_request_headers_get(), httpd_process_request(), iax_parse_ies(), iax_str2flags(), inner_product_single(), interpolate_product_single(), ip_identify_apply(), ivfilt_(), jb_debug_output(), json_utf8_check_full(), listener(), lpc10_decode(), lpc10tolin_framein(), lpfilt_(), lws2sws(), make_ari_stubs::main(), main(), refcounter::main(), spandspflow2pcap::main(), manager_login(), memcpy_decrypt(), memcpy_encrypt(), message_template_parse_emailbody(), method_match(), mgcp_postrequest(), mgcp_ss(), mgcpsock_read(), milliwatt_generate(), monmp3thread(), mpeg4_encap(), my_dahdi_write(), newpvt(), PathSegment::num_children(), parse_bookmark(), parse_ie(), refcounter::parse_line(), get_documentation::parse_manager_event_instance(), pbx_substitute_variables_helper_full(), pjsip_acf_channel_read(), playtones_generator(), plc_fillin(), plc_rx(), pp_each_extension_helper(), presence_write(), reflocks::process_file(), refstats::process_file(), process_sdp(), read_credentials(), read_header(), read_headers(), receive_message(), refer_blind_callback(), remove_header(), res_sdp_srtp_get_attr(), reschedule_precache(), resource_name_baselen(), rtp_instance_parse_extmap_extensions(), run_agi(), save_history(), scan_thread(), schedule_delivery(), sco_accept(), send_string(), set(), set_bridge_peer_vars_multiparty(), shared_write(), sip_addheader(), sip_route_process_header(), sip_show_channel(), sip_show_history(), sip_tcptls_write(), sip_unregister_tests(), sms_messagetx(), socket_process_meta(), start_automixmonitor(), start_automonitor(), StateConstructW(), StateSearchW(), static_callback(), syntFilter(), tdd_feed(), term_filter_escapes(), threadstorage_init(), tonepair_generator(), transfer_exec(), transmit_response_bysession(), try_firmware(), unistim_sp(), unquote(), OrderedDict::update(), uri_parse_and_default(), vm_allocate_dh(), wav_write(), ws_safe_read(), ws_send_msg(), xmldoc_get_syntax_fun(), xmldoc_setpostbr(), xmpp_client_authenticate_sasl(), xmpp_client_receive(), xmpp_client_request_tls(), xmpp_client_send_raw_message(), and xmpp_io_recv().

1412 {
1413  int length = 0;
1414 
1415  if (data)
1416  length = strlen(data);
1417 
1418  snprintf(buf, buflen, "%d", length);
1419 
1420  return 0;
1421 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66

◆ listfilter()

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 602 of file func_strings.c.

References args, ast_alloca, 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, result_buf, and tmp_buf.

Referenced by listfilter_read(), and listfilter_read2().

603 {
605  AST_APP_ARG(listname);
606  AST_APP_ARG(delimiter);
607  AST_APP_ARG(fieldvalue);
608  );
609  struct ast_str *orig_list = ast_str_thread_get(&tmp_buf, 16);
610  const char *begin, *cur, *next;
611  int dlen, flen, first = 1;
612  struct ast_str *result, **result_ptr = &result;
613  char *delim, *varsubst;
614 
616 
617  if (buf) {
618  if (!(result = ast_str_thread_get(&result_buf, 16))) {
619  return -1;
620  }
621  } else {
622  /* Place the result directly into the output buffer */
623  result_ptr = bufstr;
624  }
625 
626  if (args.argc < 3) {
627  ast_log(LOG_ERROR, "Usage: LISTFILTER(<listname>,<delimiter>,<fieldvalue>)\n");
628  return -1;
629  }
630 
631  varsubst = ast_alloca(strlen(args.listname) + 4);
632  sprintf(varsubst, "${%s}", args.listname);
633 
634  /* If we don't lock the channel, the variable could disappear out from underneath us. */
635  if (chan) {
636  ast_channel_lock(chan);
637  }
638  ast_str_substitute_variables(&orig_list, 0, chan, varsubst);
639  if (!ast_str_strlen(orig_list)) {
640  if (chan) {
641  ast_channel_unlock(chan);
642  }
643  return -1;
644  }
645 
646  /* If the string isn't there, just copy out the string and be done with it. */
647  if (!strstr(ast_str_buffer(orig_list), args.fieldvalue)) {
648  if (buf) {
649  ast_copy_string(buf, ast_str_buffer(orig_list), len);
650  } else {
651  ast_str_set(result_ptr, len, "%s", ast_str_buffer(orig_list));
652  }
653  if (chan) {
654  ast_channel_unlock(chan);
655  }
656  return 0;
657  }
658 
659  dlen = strlen(args.delimiter);
660  delim = ast_alloca(dlen + 1);
661  ast_get_encoded_str(args.delimiter, delim, dlen + 1);
662 
663  if ((dlen = strlen(delim)) == 0) {
664  delim = ",";
665  dlen = 1;
666  }
667 
668  flen = strlen(args.fieldvalue);
669 
670  ast_str_reset(*result_ptr);
671  /* Enough space for any result */
672  if (len > -1) {
673  ast_str_make_space(result_ptr, len ? len : ast_str_strlen(orig_list) + 1);
674  }
675 
676  begin = ast_str_buffer(orig_list);
677  next = strstr(begin, delim);
678 
679  do {
680  /* Find next boundary */
681  if (next) {
682  cur = next;
683  next = strstr(cur + dlen, delim);
684  } else {
685  cur = strchr(begin + dlen, '\0');
686  }
687 
688  if (flen == cur - begin && !strncmp(begin, args.fieldvalue, flen)) {
689  /* Skip field */
690  begin += flen + dlen;
691  } else {
692  /* Copy field to output */
693  if (!first) {
694  ast_str_append(result_ptr, len, "%s", delim);
695  }
696 
697  ast_str_append_substr(result_ptr, len, begin, cur - begin);
698  first = 0;
699  begin = cur + dlen;
700  }
701  } while (*cur != '\0');
702  if (chan) {
703  ast_channel_unlock(chan);
704  }
705 
706  if (buf) {
708  }
709 
710  return 0;
711 }
#define ast_channel_lock(chan)
Definition: channel.h:2913
char * ast_get_encoded_str(const char *stream, char *result, size_t result_len)
Decode a stream of encoded control or extended ASCII characters.
Definition: main/app.c:2942
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
#define ast_str_make_space(buf, new_len)
Definition: strings.h:780
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
void ast_str_substitute_variables(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, const char *templ)
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:1091
const char * args
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Definition: strings.h:1065
#define ast_log
Definition: astobj2.c:42
static struct ast_threadstorage tmp_buf
Definition: func_strings.c:48
char * ast_str_append_substr(struct ast_str **buf, ssize_t maxlen, const char *src, size_t maxsrc)
Append a non-NULL terminated substring to the end of a dynamic string.
Definition: strings.h:1014
static struct ast_threadstorage result_buf
Definition: func_strings.c:47
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: astmm.h:290
#define LOG_ERROR
Definition: logger.h:285
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
struct sla_ringing_trunk * first
Definition: app_meetme.c:1094
#define ast_channel_unlock(chan)
Definition: channel.h:2914
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1844
void ast_str_reset(struct ast_str *buf)
Reset the content of a dynamic string. Useful before a series of ast_str_append.
Definition: strings.h:653
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition: strings.h:688
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
static PGresult * result
Definition: cel_pgsql.c:88
struct ast_str * ast_str_thread_get(struct ast_threadstorage *ts, size_t init_len)
Retrieve a thread locally stored dynamic string.
Definition: strings.h:861
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
#define AST_APP_ARG(name)
Define an application argument.

◆ listfilter_read()

static int listfilter_read ( struct ast_channel chan,
const char *  cmd,
char *  parse,
char *  buf,
size_t  len 
)
static

Definition at line 713 of file func_strings.c.

References listfilter(), and NULL.

714 {
715  return listfilter(chan, cmd, parse, buf, NULL, len);
716 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define NULL
Definition: resample.c:96
static int listfilter(struct ast_channel *chan, const char *cmd, char *parse, char *buf, struct ast_str **bufstr, ssize_t len)
Definition: func_strings.c:602
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1844

◆ listfilter_read2()

static int listfilter_read2 ( struct ast_channel chan,
const char *  cmd,
char *  parse,
struct ast_str **  buf,
ssize_t  len 
)
static

Definition at line 718 of file func_strings.c.

References listfilter(), and NULL.

719 {
720  return listfilter(chan, cmd, parse, NULL, buf, len);
721 }
#define NULL
Definition: resample.c:96
static int listfilter(struct ast_channel *chan, const char *cmd, char *parse, char *buf, struct ast_str **bufstr, ssize_t len)
Definition: func_strings.c:602
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1844

◆ load_module()

static int load_module ( void  )
static

Definition at line 2137 of file func_strings.c.

References app_clearhash, ast_custom_function_register, ast_register_application_xml, AST_TEST_REGISTER, and exec_clearhash().

2138 {
2139  int res = 0;
2140 
2141  AST_TEST_REGISTER(test_FIELDNUM);
2142  AST_TEST_REGISTER(test_REPLACE);
2143  AST_TEST_REGISTER(test_FILTER);
2144  AST_TEST_REGISTER(test_STRREPLACE);
2145  AST_TEST_REGISTER(test_STRBETWEEN);
2172 
2173  return res;
2174 }
static struct ast_custom_function hashkeys_function
static struct ast_custom_function len_function
static struct ast_custom_function shift_function
static struct ast_custom_function strftime_function
static struct ast_custom_function passthru_function
#define AST_TEST_REGISTER(cb)
Definition: test.h:127
static struct ast_custom_function eval_function
static struct ast_custom_function fieldnum_function
Definition: func_strings.c:596
static struct ast_custom_function push_function
static struct ast_custom_function unshift_function
static struct ast_custom_function replace_function
Definition: func_strings.c:874
static struct ast_custom_function quote_function
static struct ast_custom_function strbetween_function
static int exec_clearhash(struct ast_channel *chan, const char *data)
static struct ast_custom_function listfilter_function
Definition: func_strings.c:723
static char * app_clearhash
static struct ast_custom_function toupper_function
static struct ast_custom_function csv_quote_function
static struct ast_custom_function filter_function
Definition: func_strings.c:805
static struct ast_custom_function regex_function
static struct ast_custom_function array_function
static struct ast_custom_function fieldqty_function
Definition: func_strings.c:517
static struct ast_custom_function keypadhash_function
static struct ast_custom_function hash_function
static struct ast_custom_function pop_function
static struct ast_custom_function tolower_function
static struct ast_custom_function strptime_function
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1508
static struct ast_custom_function strreplace_function
Definition: func_strings.c:963
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:626

◆ passthru()

static int passthru ( struct ast_channel chan,
const char *  cmd,
char *  data,
struct ast_str **  buf,
ssize_t  len 
)
static

Definition at line 1759 of file func_strings.c.

References ast_str_set().

1760 {
1761  ast_str_set(buf, len, "%s", data);
1762  return 0;
1763 }
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Definition: strings.h:1065
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)

◆ quote()

static int quote ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
)
static
Examples:
/tmp/asterisk-shallow/main/app.c.

Definition at line 1337 of file func_strings.c.

References ast_copy_string(), ast_log, ast_strlen_zero(), buf, LOG_ERROR, and LOG_WARNING.

Referenced by __ast_app_separate_args(), ast_app_separate_args(), parse_options(), and vm_allocate_dh().

1338 {
1339  char *bufptr = buf, *dataptr = data;
1340 
1341  if (len < 3){ /* at least two for quotes and one for binary zero */
1342  ast_log(LOG_ERROR, "Not enough buffer\n");
1343  return -1;
1344  }
1345 
1346  if (ast_strlen_zero(data)) {
1347  ast_log(LOG_WARNING, "No argument specified!\n");
1348  ast_copy_string(buf, "\"\"", len);
1349  return 0;
1350  }
1351 
1352  *bufptr++ = '"';
1353  for (; bufptr < buf + len - 3; dataptr++) {
1354  if (*dataptr == '\\') {
1355  *bufptr++ = '\\';
1356  *bufptr++ = '\\';
1357  } else if (*dataptr == '"') {
1358  *bufptr++ = '\\';
1359  *bufptr++ = '"';
1360  } else if (*dataptr == '\0') {
1361  break;
1362  } else {
1363  *bufptr++ = *dataptr;
1364  }
1365  }
1366  *bufptr++ = '"';
1367  *bufptr = '\0';
1368  return 0;
1369 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define LOG_WARNING
Definition: logger.h:274
#define ast_log
Definition: astobj2.c:42
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
#define LOG_ERROR
Definition: logger.h:285
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401

◆ regex()

static int regex ( struct ast_channel chan,
const char *  cmd,
char *  parse,
char *  buf,
size_t  len 
)
static

Definition at line 1015 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, NULL, and str.

Referenced by ast_sip_cli_traverse_objects(), ast_strings_match(), build_regex(), cli_list_subscriptions_inout(), cli_show_subscriptions_inout(), cli_show_tasks(), config_option_destroy(), and xmldoc_get_syntax_config_option().

1017 {
1019  AST_APP_ARG(null);
1020  AST_APP_ARG(reg);
1021  AST_APP_ARG(str);
1022  );
1023  int errcode;
1024  regex_t regexbuf;
1025 
1026  buf[0] = '\0';
1027 
1029 
1030  if (args.argc != 3) {
1031  ast_log(LOG_ERROR, "Unexpected arguments: should have been in the form '\"<regex>\" <string>'\n");
1032  return -1;
1033  }
1034  if ((*args.str == ' ') || (*args.str == '\t'))
1035  args.str++;
1036 
1037  ast_debug(1, "FUNCTION REGEX (%s)(%s)\n", args.reg, args.str);
1038 
1039  if ((errcode = regcomp(&regexbuf, args.reg, REG_EXTENDED | REG_NOSUB))) {
1040  regerror(errcode, &regexbuf, buf, len);
1041  ast_log(LOG_WARNING, "Malformed input %s(%s): %s\n", cmd, parse, buf);
1042  return -1;
1043  }
1044 
1045  strcpy(buf, regexec(&regexbuf, args.str, 0, NULL, 0) ? "0" : "1");
1046 
1047  regfree(&regexbuf);
1048 
1049  return 0;
1050 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define LOG_WARNING
Definition: logger.h:274
const char * str
Definition: app_jack.c:147
const char * args
#define NULL
Definition: resample.c:96
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_log
Definition: astobj2.c:42
#define LOG_ERROR
Definition: logger.h:285
#define AST_NONSTANDARD_APP_ARGS(args, parse, sep)
Performs the &#39;nonstandard&#39; argument separation process for an application.
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1844
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
#define AST_APP_ARG(name)
Define an application argument.

◆ replace()

static int replace ( struct ast_channel chan,
const char *  cmd,
char *  data,
struct ast_str **  buf,
ssize_t  len 
)
static

Definition at line 810 of file func_strings.c.

References args, ast_alloca, AST_APP_ARG, ast_debug, AST_DECLARE_APP_ARGS, ast_free, ast_get_encoded_char(), ast_get_encoded_str(), ast_log, AST_STANDARD_APP_ARGS, ast_str_buffer(), ast_str_create, ast_str_set(), ast_str_strlen(), ast_str_substitute_variables(), ast_strlen_zero(), LOG_ERROR, RAII_VAR, and str.

Referenced by FaxPcap::add(), app_get_replace_channel_app(), app_set_replace_channel_app(), app_set_replace_channel_snapshot(), calc_txstamp(), get_replace_channel_snapshot(), ResourceApi::load(), ApiDeclaration::load_file(), manager_dialplan_extension_add(), spandspflow2pcap::n2b(), get_documentation::parse_manager_event_instance(), process_text_line(), replace_channel_destroy(), and astconfigparser::try_section().

811 {
813  AST_APP_ARG(varname);
814  AST_APP_ARG(find);
816  );
817  char *strptr, *varsubst;
818  RAII_VAR(struct ast_str *, str, ast_str_create(16), ast_free);
819  char find[256]; /* Only 256 characters possible */
820  char replace[2] = "";
821  size_t unused;
822 
824 
825  if (!str) {
826  return -1;
827  }
828 
829  if (args.argc < 2) {
830  ast_log(LOG_ERROR, "Usage: %s(<varname>,<search-chars>[,<replace-char>])\n", cmd);
831  return -1;
832  }
833 
834  /* Decode escapes */
835  ast_get_encoded_str(args.find, find, sizeof(find));
836  ast_get_encoded_char(args.replace, replace, &unused);
837 
838  if (ast_strlen_zero(find) || ast_strlen_zero(args.varname)) {
839  ast_log(LOG_ERROR, "The characters to search for and the variable name must not be empty.\n");
840  return -1;
841  }
842 
843  varsubst = ast_alloca(strlen(args.varname) + 4);
844  sprintf(varsubst, "${%s}", args.varname);
845  ast_str_substitute_variables(&str, 0, chan, varsubst);
846 
847  if (!ast_str_strlen(str)) {
848  /* Blank, nothing to replace */
849  return -1;
850  }
851 
852  ast_debug(3, "String to search: (%s)\n", ast_str_buffer(str));
853  ast_debug(3, "Characters to find: (%s)\n", find);
854  ast_debug(3, "Character to replace with: (%s)\n", replace);
855 
856  for (strptr = ast_str_buffer(str); *strptr; strptr++) {
857  /* buf is already a mutable buffer, so we construct the result
858  * directly there */
859  if (strchr(find, *strptr)) {
860  if (ast_strlen_zero(replace)) {
861  memmove(strptr, strptr + 1, strlen(strptr + 1) + 1);
862  strptr--;
863  } else {
864  /* Replace character */
865  *strptr = *replace;
866  }
867  }
868  }
869 
870  ast_str_set(buf, len, "%s", ast_str_buffer(str));
871  return 0;
872 }
char * ast_get_encoded_str(const char *stream, char *result, size_t result_len)
Decode a stream of encoded control or extended ASCII characters.
Definition: main/app.c:2942
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
void ast_str_substitute_variables(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, const char *templ)
const char * str
Definition: app_jack.c:147
const char * args
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Definition: strings.h:1065
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_log
Definition: astobj2.c:42
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
int ast_get_encoded_char(const char *stream, char *result, size_t *consumed)
Decode an encoded control or extended ASCII character.
Definition: main/app.c:2867
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: astmm.h:290
#define LOG_ERROR
Definition: logger.h:285
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define ast_free(a)
Definition: astmm.h:182
static int replace(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len)
Definition: func_strings.c:810
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition: strings.h:688
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
#define ast_str_create(init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:620
#define AST_APP_ARG(name)
Define an application argument.

◆ shift_pop()

static int shift_pop ( struct ast_channel chan,
const char *  cmd,
char *  data,
struct ast_str **  buf,
ssize_t  len 
)
static

Definition at line 1635 of file func_strings.c.

References args, ast_alloca, 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, c, LOG_WARNING, pbx_builtin_setvar_helper(), result_buf, and var.

1636 {
1637 #define beginning (cmd[0] == 'S') /* SHIFT */
1638  char *after, delimiter[2] = ",", *varsubst;
1639  size_t unused;
1640  struct ast_str *before = ast_str_thread_get(&result_buf, 16);
1641  char *(*search_func)(const char *s, int c) = (beginning ? strchr : strrchr);
1643  AST_APP_ARG(var);
1644  AST_APP_ARG(delimiter);
1645  );
1646 
1647  if (!before) {
1648  return -1;
1649  }
1650 
1651  AST_STANDARD_APP_ARGS(args, data);
1652 
1653  if (ast_strlen_zero(args.var)) {
1654  ast_log(LOG_WARNING, "%s requires a variable name\n", cmd);
1655  return -1;
1656  }
1657 
1658  varsubst = ast_alloca(strlen(args.var) + 4);
1659  sprintf(varsubst, "${%s}", args.var);
1660  ast_str_substitute_variables(&before, 0, chan, varsubst);
1661 
1662  if (args.argc > 1 && !ast_strlen_zero(args.delimiter)) {
1663  ast_get_encoded_char(args.delimiter, delimiter, &unused);
1664  }
1665 
1666  if (!ast_str_strlen(before)) {
1667  /* Nothing to pop */
1668  return -1;
1669  }
1670 
1671  if (!(after = search_func(ast_str_buffer(before), delimiter[0]))) {
1672  /* Only one entry in array */
1673  ast_str_set(buf, len, "%s", ast_str_buffer(before));
1674  pbx_builtin_setvar_helper(chan, args.var, "");
1675  } else {
1676  *after++ = '\0';
1677  ast_str_set(buf, len, "%s", beginning ? ast_str_buffer(before) : after);
1678  pbx_builtin_setvar_helper(chan, args.var, beginning ? after : ast_str_buffer(before));
1679  }
1680 
1681  return 0;
1682 #undef beginning
1683 }
#define beginning
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
#define LOG_WARNING
Definition: logger.h:274
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
#define var
Definition: ast_expr2f.c:614
void ast_str_substitute_variables(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, const char *templ)
static struct test_val c
const char * args
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Definition: strings.h:1065
#define ast_log
Definition: astobj2.c:42
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
int ast_get_encoded_char(const char *stream, char *result, size_t *consumed)
Decode an encoded control or extended ASCII character.
Definition: main/app.c:2867
static struct ast_threadstorage result_buf
Definition: func_strings.c:47
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: astmm.h:290
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name...
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition: strings.h:688
struct ast_str * ast_str_thread_get(struct ast_threadstorage *ts, size_t init_len)
Retrieve a thread locally stored dynamic string.
Definition: strings.h:861
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
#define AST_APP_ARG(name)
Define an application argument.

◆ strbetween()

static int strbetween ( struct ast_channel chan,
const char *  cmd,
char *  data,
struct ast_str **  buf,
ssize_t  len 
)
static

Definition at line 968 of file func_strings.c.

References args, ast_alloca, AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_log, AST_STANDARD_APP_ARGS, ast_str_append(), ast_str_buffer(), ast_str_reset(), ast_str_substitute_variables(), ast_str_thread_get(), ast_strlen_zero(), c, LOG_ERROR, result_buf, and str.

969 {
970  int c, origsize;
971  char *varsubstr, *origstr;
972  struct ast_str *str = ast_str_thread_get(&result_buf, 16); /* Holds the data obtained from varname */
973 
975  AST_APP_ARG(varname);
976  AST_APP_ARG(insert_string);
977  AST_APP_ARG(other); /* Any remining unused arguments */
978  );
979 
980  ast_str_reset(*buf);
981 
982  if (!str) {
983  ast_log(LOG_ERROR, "Couldn't obtain string\n");
984  return -1;
985  }
986 
988 
989  if (args.argc != 2 || ast_strlen_zero(args.varname)) {
990  ast_log(LOG_ERROR, "Usage: %s(<varname>,<insert-string>)\n", cmd);
991  return -1;
992  }
993 
994  varsubstr = ast_alloca(strlen(args.varname) + 4);
995  sprintf(varsubstr, "${%s}", args.varname);
996  ast_str_substitute_variables(&str, 0, chan, varsubstr);
997  origstr = ast_str_buffer(str);
998  origsize = strlen(origstr);
999  for (c = 0; c < origsize; c++) {
1000  ast_str_append(buf, len, "%c", origstr[c]);
1001  /* no insert after the last character */
1002  if (c < (origsize - 1)) {
1003  ast_str_append(buf, len, "%s", args.insert_string);
1004  }
1005  }
1006 
1007  return 0;
1008 }
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
void ast_str_substitute_variables(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, const char *templ)
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:1091
static struct test_val c
const char * str
Definition: app_jack.c:147
const char * args
#define ast_log
Definition: astobj2.c:42
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
static struct ast_threadstorage result_buf
Definition: func_strings.c:47
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: astmm.h:290
#define LOG_ERROR
Definition: logger.h:285
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
void ast_str_reset(struct ast_str *buf)
Reset the content of a dynamic string. Useful before a series of ast_str_append.
Definition: strings.h:653
struct ast_str * ast_str_thread_get(struct ast_threadstorage *ts, size_t init_len)
Retrieve a thread locally stored dynamic string.
Definition: strings.h:861
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
#define AST_APP_ARG(name)
Define an application argument.

◆ string_tolower()

static int string_tolower ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  buflen 
)
static

Definition at line 1606 of file func_strings.c.

References buf.

1607 {
1608  char *bufptr = buf, *dataptr = data;
1609 
1610  while ((bufptr < buf + buflen - 1) && (*bufptr++ = tolower(*dataptr++)));
1611 
1612  return 0;
1613 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66

◆ string_tolower2()

static int string_tolower2 ( struct ast_channel chan,
const char *  cmd,
char *  data,
struct ast_str **  buf,
ssize_t  buflen 
)
static

Definition at line 1615 of file func_strings.c.

References ast_str_buffer(), ast_str_make_space, ast_str_size(), and ast_str_update().

1616 {
1617  char *bufptr, *dataptr = data;
1618 
1619  if (buflen > -1) {
1620  ast_str_make_space(buf, buflen > 0 ? buflen : strlen(data) + 1);
1621  }
1622  bufptr = ast_str_buffer(*buf);
1623  while ((bufptr < ast_str_buffer(*buf) + ast_str_size(*buf) - 1) && (*bufptr++ = tolower(*dataptr++)));
1624  ast_str_update(*buf);
1625 
1626  return 0;
1627 }
size_t ast_str_size(const struct ast_str *buf)
Returns the current maximum length (without reallocation) of the current buffer.
Definition: strings.h:699
#define ast_str_make_space(buf, new_len)
Definition: strings.h:780
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
void ast_str_update(struct ast_str *buf)
Update the length of the buffer, after using ast_str merely as a buffer.
Definition: strings.h:663

◆ string_toupper()

static int string_toupper ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  buflen 
)
static

Definition at line 1577 of file func_strings.c.

References buf.

1578 {
1579  char *bufptr = buf, *dataptr = data;
1580 
1581  while ((bufptr < buf + buflen - 1) && (*bufptr++ = toupper(*dataptr++)));
1582 
1583  return 0;
1584 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66

◆ string_toupper2()

static int string_toupper2 ( struct ast_channel chan,
const char *  cmd,
char *  data,
struct ast_str **  buf,
ssize_t  buflen 
)
static

Definition at line 1586 of file func_strings.c.

References ast_str_buffer(), ast_str_make_space, ast_str_size(), and ast_str_update().

1587 {
1588  char *bufptr, *dataptr = data;
1589 
1590  if (buflen > -1) {
1591  ast_str_make_space(buf, buflen > 0 ? buflen : strlen(data) + 1);
1592  }
1593  bufptr = ast_str_buffer(*buf);
1594  while ((bufptr < ast_str_buffer(*buf) + ast_str_size(*buf) - 1) && (*bufptr++ = toupper(*dataptr++)));
1595  ast_str_update(*buf);
1596 
1597  return 0;
1598 }
size_t ast_str_size(const struct ast_str *buf)
Returns the current maximum length (without reallocation) of the current buffer.
Definition: strings.h:699
#define ast_str_make_space(buf, new_len)
Definition: strings.h:780
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
void ast_str_update(struct ast_str *buf)
Update the length of the buffer, after using ast_str merely as a buffer.
Definition: strings.h:663

◆ strreplace()

static int strreplace ( struct ast_channel chan,
const char *  cmd,
char *  data,
struct ast_str **  buf,
ssize_t  len 
)
static

Definition at line 879 of file func_strings.c.

References args, ast_alloca, AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_log, AST_STANDARD_APP_ARGS, ast_str_append(), ast_str_buffer(), ast_str_reset(), ast_str_substitute_variables(), ast_str_thread_get(), ast_strlen_zero(), end, LOG_ERROR, result_buf, and str.

880 {
881  char *varsubstr; /* substring for input var */
882  char *start; /* Starting pos of substring search. */
883  char *end; /* Ending pos of substring search. */
884  int find_size; /* length of given find-string */
885  unsigned max_matches; /* number of matches we find before terminating search */
886  unsigned count; /* loop counter */
887  struct ast_str *str = ast_str_thread_get(&result_buf, 16); /* Holds the data obtained from varname */
888 
890  AST_APP_ARG(varname);
891  AST_APP_ARG(find_string);
892  AST_APP_ARG(replace_string);
893  AST_APP_ARG(max_replacements);
894  AST_APP_ARG(other); /* Any remining unused arguments */
895  );
896 
897  /* Guarantee output string is empty to start with. */
898  ast_str_reset(*buf);
899 
900  if (!str) {
901  /* We failed to allocate str, forget it. We failed. */
902  return -1;
903  }
904 
905  /* Parse the arguments. */
907 
908  if (args.argc < 2) {
909  /* Didn't receive enough arguments to do anything */
911  "Usage: %s(<varname>,<find-string>[,<replace-string>,[<max-replacements>]])\n",
912  cmd);
913  return -1;
914  }
915 
916  /* No var name specified. Return failure, string is already empty. */
917  if (ast_strlen_zero(args.varname)) {
918  return -1;
919  }
920 
921  /* Zero length find strings are a no-no. Kill the function if we run into one. */
922  if (ast_strlen_zero(args.find_string)) {
923  ast_log(LOG_ERROR, "No <find-string> specified\n");
924  return -1;
925  }
926  find_size = strlen(args.find_string);
927 
928  /* set varsubstr to the matching variable */
929  varsubstr = ast_alloca(strlen(args.varname) + 4);
930  sprintf(varsubstr, "${%s}", args.varname);
931  ast_str_substitute_variables(&str, 0, chan, varsubstr);
932 
933  /* Determine how many replacements are allowed. */
934  if (!args.max_replacements
935  || (max_matches = atoi(args.max_replacements)) <= 0) {
936  /* Unlimited replacements are allowed. */
937  max_matches = -1;
938  }
939 
940  /* Generate the search and replaced string. */
941  start = ast_str_buffer(str);
942  for (count = 0; count < max_matches; ++count) {
943  end = strstr(start, args.find_string);
944  if (!end) {
945  /* Did not find a matching substring in the remainder. */
946  break;
947  }
948 
949  /* Replace the found substring. */
950  *end = '\0';
951  ast_str_append(buf, len, "%s", start);
952  if (args.replace_string) {
953  /* Append the replacement string */
954  ast_str_append(buf, len, "%s", args.replace_string);
955  }
956  start = end + find_size;
957  }
958  ast_str_append(buf, len, "%s", start);
959 
960  return 0;
961 }
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
void ast_str_substitute_variables(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, const char *templ)
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:1091
const char * str
Definition: app_jack.c:147
const char * args
char * end
Definition: eagi_proxy.c:73
#define ast_log
Definition: astobj2.c:42
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
static struct ast_threadstorage result_buf
Definition: func_strings.c:47
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: astmm.h:290
#define LOG_ERROR
Definition: logger.h:285
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
void ast_str_reset(struct ast_str *buf)
Reset the content of a dynamic string. Useful before a series of ast_str_append.
Definition: strings.h:653
struct ast_str * ast_str_thread_get(struct ast_threadstorage *ts, size_t init_len)
Retrieve a thread locally stored dynamic string.
Definition: strings.h:861
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
#define AST_APP_ARG(name)
Define an application argument.

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 2098 of file func_strings.c.

References app_clearhash, ast_custom_function_unregister(), AST_TEST_UNREGISTER, and ast_unregister_application().

2099 {
2100  int res = 0;
2101 
2102  AST_TEST_UNREGISTER(test_FIELDNUM);
2103  AST_TEST_UNREGISTER(test_REPLACE);
2104  AST_TEST_UNREGISTER(test_FILTER);
2105  AST_TEST_UNREGISTER(test_STRREPLACE);
2106  AST_TEST_UNREGISTER(test_STRBETWEEN);
2133 
2134  return res;
2135 }
static struct ast_custom_function hashkeys_function
static struct ast_custom_function len_function
static struct ast_custom_function shift_function
static struct ast_custom_function strftime_function
static struct ast_custom_function passthru_function
static struct ast_custom_function eval_function
static struct ast_custom_function fieldnum_function
Definition: func_strings.c:596
static struct ast_custom_function push_function
static struct ast_custom_function unshift_function
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
static struct ast_custom_function replace_function
Definition: func_strings.c:874
static struct ast_custom_function quote_function
static struct ast_custom_function strbetween_function
static struct ast_custom_function listfilter_function
Definition: func_strings.c:723
static char * app_clearhash
static struct ast_custom_function toupper_function
static struct ast_custom_function csv_quote_function
static struct ast_custom_function filter_function
Definition: func_strings.c:805
static struct ast_custom_function regex_function
#define AST_TEST_UNREGISTER(cb)
Definition: test.h:128
static struct ast_custom_function array_function
static struct ast_custom_function fieldqty_function
Definition: func_strings.c:517
static struct ast_custom_function keypadhash_function
static struct ast_custom_function hash_function
static struct ast_custom_function pop_function
static struct ast_custom_function tolower_function
static struct ast_custom_function strptime_function
static struct ast_custom_function strreplace_function
Definition: func_strings.c:963

◆ unshift_push()

static int unshift_push ( struct ast_channel chan,
const char *  cmd,
char *  data,
const char *  new_value 
)
static

Definition at line 1695 of file func_strings.c.

References args, ast_alloca, 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, buf, LOG_WARNING, MIN, pbx_builtin_setvar_helper(), result_buf, tmp_buf, and var.

1696 {
1697 #define beginning (cmd[0] == 'U') /* UNSHIFT */
1698  char delimiter[2] = ",", *varsubst;
1699  size_t unused;
1700  struct ast_str *buf, *previous_value;
1702  AST_APP_ARG(var);
1703  AST_APP_ARG(delimiter);
1704  );
1705  const char *stripped_var;
1706 
1707  if (!(buf = ast_str_thread_get(&result_buf, 16)) ||
1708  !(previous_value = ast_str_thread_get(&tmp_buf, 16))) {
1709  return -1;
1710  }
1711 
1712  AST_STANDARD_APP_ARGS(args, data);
1713 
1714  if (ast_strlen_zero(args.var)) {
1715  ast_log(LOG_WARNING, "%s requires a variable name\n", cmd);
1716  return -1;
1717  }
1718 
1719  if (args.argc > 1 && !ast_strlen_zero(args.delimiter)) {
1720  ast_get_encoded_char(args.delimiter, delimiter, &unused);
1721  }
1722 
1723  /* UNSHIFT and PUSH act as ways of setting a variable, so we need to be
1724  * sure to skip leading underscores if they appear. However, we only want
1725  * to skip up to two since that is the maximum number that can be used to
1726  * indicate variable inheritance. Any further underscores are part of the
1727  * variable name.
1728  */
1729  stripped_var = args.var + MIN(strspn(args.var, "_"), 2);
1730  varsubst = ast_alloca(strlen(stripped_var) + 4);
1731  sprintf(varsubst, "${%s}", stripped_var);
1732  ast_str_substitute_variables(&previous_value, 0, chan, varsubst);
1733 
1734  if (!ast_str_strlen(previous_value)) {
1735  ast_str_set(&buf, 0, "%s", new_value);
1736  } else {
1737  ast_str_set(&buf, 0, "%s%c%s",
1738  beginning ? new_value : ast_str_buffer(previous_value),
1739  delimiter[0],
1740  beginning ? ast_str_buffer(previous_value) : new_value);
1741  }
1742 
1744 
1745  return 0;
1746 #undef beginning
1747 }
#define beginning
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
#define LOG_WARNING
Definition: logger.h:274
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
#define var
Definition: ast_expr2f.c:614
void ast_str_substitute_variables(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, const char *templ)
const char * args
#define MIN(a, b)
Definition: utils.h:226
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Definition: strings.h:1065
#define ast_log
Definition: astobj2.c:42
static struct ast_threadstorage tmp_buf
Definition: func_strings.c:48
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
int ast_get_encoded_char(const char *stream, char *result, size_t *consumed)
Decode an encoded control or extended ASCII character.
Definition: main/app.c:2867
static struct ast_threadstorage result_buf
Definition: func_strings.c:47
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: astmm.h:290
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name...
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition: strings.h:688
struct ast_str * ast_str_thread_get(struct ast_threadstorage *ts, size_t init_len)
Retrieve a thread locally stored dynamic string.
Definition: strings.h:861
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
#define AST_APP_ARG(name)
Define an application argument.

Variable Documentation

◆ __mod_info

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 = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 2176 of file func_strings.c.

◆ app_clearhash

char* app_clearhash = "ClearHash"
static

Definition at line 1060 of file func_strings.c.

Referenced by load_module(), and unload_module().

◆ array_function

struct ast_custom_function array_function
static
Initial value:
= {
.name = "ARRAY",
.write = array,
}
static int array(struct ast_channel *chan, const char *cmd, char *var, const char *value)

Definition at line 1332 of file func_strings.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 2176 of file func_strings.c.

◆ csv_quote_function

struct ast_custom_function csv_quote_function
static
Initial value:
= {
.name = "CSV_QUOTE",
.read = csv_quote,
}
static int csv_quote(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)

Definition at line 1406 of file func_strings.c.

◆ eval_function

struct ast_custom_function eval_function
static
Initial value:
= {
.name = "EVAL",
.read = function_eval,
.read2 = function_eval2,
}
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)

Definition at line 1531 of file func_strings.c.

◆ fieldnum_function

struct ast_custom_function fieldnum_function
static
Initial value:
= {
.name = "FIELDNUM",
}
static int function_fieldnum(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
Definition: func_strings.c:584
static int function_fieldnum_str(struct ast_channel *chan, const char *cmd, char *parse, struct ast_str **buf, ssize_t len)
Definition: func_strings.c:590

Definition at line 596 of file func_strings.c.

◆ fieldqty_function

struct ast_custom_function fieldqty_function
static
Initial value:
= {
.name = "FIELDQTY",
}
static int function_fieldqty(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
Definition: func_strings.c:505
static int function_fieldqty_str(struct ast_channel *chan, const char *cmd, char *parse, struct ast_str **buf, ssize_t len)
Definition: func_strings.c:511

Definition at line 517 of file func_strings.c.

◆ filter_function

struct ast_custom_function filter_function
static
Initial value:
= {
.name = "FILTER",
.read = filter,
}
static int filter(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
Definition: func_strings.c:729

Definition at line 805 of file func_strings.c.

◆ hash_function

struct ast_custom_function hash_function
static
Initial value:
= {
.name = "HASH",
.write = hash_write,
.read = hash_read,
}
static int hash_write(struct ast_channel *chan, const char *cmd, char *var, const char *value)
static int hash_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)

Definition at line 1320 of file func_strings.c.

◆ hashkeys_function

struct ast_custom_function hashkeys_function
static
Initial value:
= {
.name = "HASHKEYS",
.read = hashkeys_read,
.read2 = hashkeys_read2,
}
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)

Definition at line 1326 of file func_strings.c.

◆ keypadhash_function

struct ast_custom_function keypadhash_function
static
Initial value:
= {
.name = "KEYPADHASH",
.read = keypadhash,
}
static int keypadhash(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)

Definition at line 1572 of file func_strings.c.

◆ len_function

struct ast_custom_function len_function
static
Initial value:
= {
.name = "LEN",
.read = len,
.read_max = 12,
}
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)

Definition at line 1423 of file func_strings.c.

◆ listfilter_function

struct ast_custom_function listfilter_function
static
Initial value:
= {
.name = "LISTFILTER",
.read = listfilter_read,
.read2 = listfilter_read2,
}
static int listfilter_read(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
Definition: func_strings.c:713
static int listfilter_read2(struct ast_channel *chan, const char *cmd, char *parse, struct ast_str **buf, ssize_t len)
Definition: func_strings.c:718

Definition at line 723 of file func_strings.c.

◆ passthru_function

struct ast_custom_function passthru_function
static
Initial value:
= {
.name = "PASSTHRU",
.read2 = passthru,
}
static int passthru(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len)

Definition at line 1765 of file func_strings.c.

◆ pop_function

struct ast_custom_function pop_function
static
Initial value:
= {
.name = "POP",
.read2 = shift_pop,
}
static int shift_pop(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len)

Definition at line 1690 of file func_strings.c.

◆ push_function

struct ast_custom_function push_function
static
Initial value:
= {
.name = "PUSH",
.write = unshift_push,
}
static int unshift_push(struct ast_channel *chan, const char *cmd, char *data, const char *new_value)

Definition at line 1749 of file func_strings.c.

◆ quote_function

struct ast_custom_function quote_function
static
Initial value:
= {
.name = "QUOTE",
.read = quote,
}
static int quote(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)

Definition at line 1371 of file func_strings.c.

◆ regex_function

struct ast_custom_function regex_function
static
Initial value:
= {
.name = "REGEX",
.read = regex,
}
static int regex(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)

Definition at line 1052 of file func_strings.c.

◆ replace_function

struct ast_custom_function replace_function
static
Initial value:
= {
.name = "REPLACE",
.read2 = replace,
}
static int replace(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len)
Definition: func_strings.c:810

Definition at line 874 of file func_strings.c.

◆ result_buf

struct ast_threadstorage result_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_result_buf , .custom_init = NULL , }
static

◆ shift_function

struct ast_custom_function shift_function
static
Initial value:
= {
.name = "SHIFT",
.read2 = shift_pop,
}
static int shift_pop(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len)

Definition at line 1685 of file func_strings.c.

◆ strbetween_function

struct ast_custom_function strbetween_function
static
Initial value:
= {
.name = "STRBETWEEN",
.read2 = strbetween,
}
static int strbetween(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len)
Definition: func_strings.c:968

Definition at line 1010 of file func_strings.c.

◆ strftime_function

struct ast_custom_function strftime_function
static
Initial value:
= {
.name = "STRFTIME",
.read = acf_strftime,
}
static int acf_strftime(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t buflen)

Definition at line 1458 of file func_strings.c.

◆ strptime_function

struct ast_custom_function strptime_function
static
Initial value:
= {
.name = "STRPTIME",
.read = acf_strptime,
}
static int acf_strptime(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)

Definition at line 1500 of file func_strings.c.

◆ strreplace_function

struct ast_custom_function strreplace_function
static
Initial value:
= {
.name = "STRREPLACE",
.read2 = strreplace,
}
static int strreplace(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len)
Definition: func_strings.c:879

Definition at line 963 of file func_strings.c.

◆ tmp_buf

struct ast_threadstorage tmp_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_tmp_buf , .custom_init = NULL , }
static

Definition at line 48 of file func_strings.c.

Referenced by listfilter(), and unshift_push().

◆ tolower_function

struct ast_custom_function tolower_function
static
Initial value:
= {
.name = "TOLOWER",
.read = string_tolower,
.read2 = string_tolower2,
}
static int string_tolower2(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t buflen)
static int string_tolower(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)

Definition at line 1629 of file func_strings.c.

◆ toupper_function

struct ast_custom_function toupper_function
static
Initial value:
= {
.name = "TOUPPER",
.read = string_toupper,
.read2 = string_toupper2,
}
static int string_toupper2(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)

Definition at line 1600 of file func_strings.c.

◆ unshift_function

struct ast_custom_function unshift_function
static
Initial value:
= {
.name = "UNSHIFT",
.write = unshift_push,
}
static int unshift_push(struct ast_channel *chan, const char *cmd, char *data, const char *new_value)

Definition at line 1754 of file func_strings.c.