[asterisk-commits] trunk - r8076 /trunk/funcs/func_strings.c
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Sat Jan 14 13:30:38 CST 2006
Author: tilghman
Date: Sat Jan 14 13:30:37 2006
New Revision: 8076
URL: http://svn.digium.com/view/asterisk?rev=8076&view=rev
Log:
Bug 6238 - Janitor - update to app_args macros
Modified:
trunk/funcs/func_strings.c
Modified: trunk/funcs/func_strings.c
URL: http://svn.digium.com/view/asterisk/trunk/funcs/func_strings.c?rev=8076&r1=8075&r2=8076&view=diff
==============================================================================
--- trunk/funcs/func_strings.c (original)
+++ trunk/funcs/func_strings.c Sat Jan 14 13:30:37 2006
@@ -43,24 +43,31 @@
static char *function_fieldqty(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
{
- char *varname, *varval, workspace[256];
- char *delim = ast_strdupa(data);
+ char *varval, workspace[4096];
int fieldcount = 0;
-
- if (delim) {
- varname = strsep(&delim, "|");
- pbx_retrieve_variable(chan, varname, &varval, workspace, sizeof(workspace), NULL);
- if (delim) {
- while (strsep(&varval, delim))
- fieldcount++;
- } else if (!ast_strlen_zero(varval)) {
- fieldcount = 1;
- }
- snprintf(buf, len, "%d", fieldcount);
+ char *parse;
+ AST_DECLARE_APP_ARGS(args,
+ AST_APP_ARG(varname);
+ AST_APP_ARG(delim);
+ );
+
+ parse = ast_strdupa(data);
+ if (!parse) {
+ ast_log(LOG_ERROR, "Out of memory\n");
+ ast_copy_string(buf, "0", len);
+ return buf;
+ }
+
+ AST_STANDARD_APP_ARGS(args, parse);
+ if (args.delim) {
+ pbx_retrieve_variable(chan, args.varname, &varval, workspace, sizeof(workspace), NULL);
+ while (strsep(&varval, args.delim))
+ fieldcount++;
} else {
- ast_log(LOG_ERROR, "Out of memory\n");
- strncpy(buf, "1", len);
- }
+ fieldcount = 1;
+ }
+ snprintf(buf, len, "%d", fieldcount);
+
return buf;
}
@@ -76,24 +83,29 @@
static char *builtin_function_filter(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
{
- char *allowed, *string, *outbuf=buf;
-
- string = ast_strdupa(data);
- if (!string) {
+ char *parse;
+ AST_DECLARE_APP_ARGS(args,
+ AST_APP_ARG(allowed);
+ AST_APP_ARG(string);
+ );
+ char *outbuf=buf;
+
+ parse = ast_strdupa(data);
+ if (!parse) {
ast_log(LOG_ERROR, "Out of memory");
return "";
}
- allowed = strsep(&string, "|");
-
- if (!string) {
+ AST_STANDARD_APP_ARGS(args, parse);
+
+ if (!args.string ) {
ast_log(LOG_ERROR, "Usage: FILTER(<allowed-chars>,<string>)\n");
return "";
}
- for ( ; *string && (buf + len - 1 > outbuf); string++) {
- if (strchr(allowed, *string)) {
- *outbuf = *string;
+ for ( ; *(args.string) && (buf + len - 1 > outbuf); (args.string)++) {
+ if (strchr(args.allowed, *(args.string))) {
+ *outbuf = *(args.string);
outbuf++;
}
}
@@ -114,38 +126,35 @@
static char *builtin_function_regex(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
{
- char *arg, *earg = NULL, *tmp, errstr[256] = "";
+ char *parse;
+ AST_DECLARE_APP_ARGS(args,
+ AST_APP_ARG(null);
+ AST_APP_ARG(reg);
+ AST_APP_ARG(str);
+ );
+
+
+ char errstr[256] = "";
int errcode;
regex_t regexbuf;
ast_copy_string(buf, "0", len);
- tmp = ast_strdupa(data);
- if (!tmp) {
+ parse = ast_strdupa(data);
+ if (!parse) {
ast_log(LOG_ERROR, "Out of memory in %s(%s)\n", cmd, data);
return buf;
}
- /* Regex in quotes */
- arg = strchr(tmp, '"');
- if (arg) {
- arg++;
- earg = strrchr(arg, '"');
- if (earg) {
- *earg++ = '\0';
- /* Skip over any spaces before the data we are checking */
- while (*earg == ' ')
- earg++;
- }
- } else {
- arg = tmp;
- }
-
- if ((errcode = regcomp(®exbuf, arg, REG_EXTENDED | REG_NOSUB))) {
+ AST_NONSTANDARD_APP_ARGS(args, parse, '"');
+
+ ast_log(LOG_DEBUG, "FUNCTION REGEX (%s)(%s)\n", args.reg, args.str);
+
+ if ((errcode = regcomp(®exbuf, args.reg, REG_EXTENDED | REG_NOSUB))) {
regerror(errcode, ®exbuf, errstr, sizeof(errstr));
ast_log(LOG_WARNING, "Malformed input %s(%s): %s\n", cmd, data, errstr);
} else {
- if (!regexec(®exbuf, earg ? earg : "", 0, NULL, 0))
+ if (!regexec(®exbuf, args.str, 0, NULL, 0))
ast_copy_string(buf, "1", len);
}
regfree(®exbuf);
@@ -243,38 +252,38 @@
static char *acf_strftime(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
{
- char *format, *epoch, *timezone = NULL;
+ char *parse;
+ AST_DECLARE_APP_ARGS(args,
+ AST_APP_ARG(epoch);
+ AST_APP_ARG(timezone);
+ AST_APP_ARG(format);
+ );
long epochi;
struct tm time;
buf[0] = '\0';
- if (!data) {
+ if (ast_strlen_zero(data)) {
ast_log(LOG_ERROR, "Asterisk function STRFTIME() requires an argument.\n");
return buf;
}
- format = ast_strdupa(data);
- if (!format) {
+ parse = ast_strdupa(data);
+ if (!parse) {
ast_log(LOG_ERROR, "Out of memory\n");
return buf;
}
- epoch = strsep(&format, "|");
- timezone = strsep(&format, "|");
-
- if (ast_strlen_zero(epoch) || !sscanf(epoch, "%ld", &epochi)) {
+ AST_STANDARD_APP_ARGS(args, parse);
+
+ if (ast_strlen_zero(args.epoch) || !sscanf(args.epoch, "%ld", &epochi)) {
struct timeval tv = ast_tvnow();
epochi = tv.tv_sec;
}
- ast_localtime(&epochi, &time, timezone);
-
- if (!format) {
- format = "%c";
- }
-
- if (!strftime(buf, len, format, &time)) {
+ ast_localtime(&epochi, &time, args.timezone);
+
+ if (!strftime(buf, len, args.format?args.format:"%c", &time)) {
ast_log(LOG_WARNING, "C function strftime() output nothing?!!\n");
}
buf[len - 1] = '\0';
More information about the asterisk-commits
mailing list