Bug 6238 - Janitor - update to app_args macros

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@8076 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Tilghman Lesher
2006-01-14 19:30:37 +00:00
parent 3578c5b19d
commit 9702fac4f8

View File

@@ -43,24 +43,31 @@
static char *function_fieldqty(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) static char *function_fieldqty(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
{ {
char *varname, *varval, workspace[256]; char *varval, workspace[4096];
char *delim = ast_strdupa(data);
int fieldcount = 0; int fieldcount = 0;
char *parse;
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(varname);
AST_APP_ARG(delim);
);
if (delim) { parse = ast_strdupa(data);
varname = strsep(&delim, "|"); if (!parse) {
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);
} else {
ast_log(LOG_ERROR, "Out of memory\n"); ast_log(LOG_ERROR, "Out of memory\n");
strncpy(buf, "1", len); 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 {
fieldcount = 1;
}
snprintf(buf, len, "%d", fieldcount);
return buf; return buf;
} }
@@ -76,24 +83,29 @@ struct ast_custom_function fieldqty_function = {
static char *builtin_function_filter(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) static char *builtin_function_filter(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
{ {
char *allowed, *string, *outbuf=buf; char *parse;
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(allowed);
AST_APP_ARG(string);
);
char *outbuf=buf;
string = ast_strdupa(data); parse = ast_strdupa(data);
if (!string) { if (!parse) {
ast_log(LOG_ERROR, "Out of memory"); ast_log(LOG_ERROR, "Out of memory");
return ""; return "";
} }
allowed = strsep(&string, "|"); AST_STANDARD_APP_ARGS(args, parse);
if (!string) { if (!args.string ) {
ast_log(LOG_ERROR, "Usage: FILTER(<allowed-chars>,<string>)\n"); ast_log(LOG_ERROR, "Usage: FILTER(<allowed-chars>,<string>)\n");
return ""; return "";
} }
for ( ; *string && (buf + len - 1 > outbuf); string++) { for ( ; *(args.string) && (buf + len - 1 > outbuf); (args.string)++) {
if (strchr(allowed, *string)) { if (strchr(args.allowed, *(args.string))) {
*outbuf = *string; *outbuf = *(args.string);
outbuf++; outbuf++;
} }
} }
@@ -114,38 +126,35 @@ struct ast_custom_function filter_function = {
static char *builtin_function_regex(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) 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; int errcode;
regex_t regexbuf; regex_t regexbuf;
ast_copy_string(buf, "0", len); ast_copy_string(buf, "0", len);
tmp = ast_strdupa(data); parse = ast_strdupa(data);
if (!tmp) { if (!parse) {
ast_log(LOG_ERROR, "Out of memory in %s(%s)\n", cmd, data); ast_log(LOG_ERROR, "Out of memory in %s(%s)\n", cmd, data);
return buf; return buf;
} }
/* Regex in quotes */ AST_NONSTANDARD_APP_ARGS(args, parse, '"');
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(&regexbuf, arg, REG_EXTENDED | REG_NOSUB))) { ast_log(LOG_DEBUG, "FUNCTION REGEX (%s)(%s)\n", args.reg, args.str);
if ((errcode = regcomp(&regexbuf, args.reg, REG_EXTENDED | REG_NOSUB))) {
regerror(errcode, &regexbuf, errstr, sizeof(errstr)); regerror(errcode, &regexbuf, errstr, sizeof(errstr));
ast_log(LOG_WARNING, "Malformed input %s(%s): %s\n", cmd, data, errstr); ast_log(LOG_WARNING, "Malformed input %s(%s): %s\n", cmd, data, errstr);
} else { } else {
if (!regexec(&regexbuf, earg ? earg : "", 0, NULL, 0)) if (!regexec(&regexbuf, args.str, 0, NULL, 0))
ast_copy_string(buf, "1", len); ast_copy_string(buf, "1", len);
} }
regfree(&regexbuf); regfree(&regexbuf);
@@ -243,38 +252,38 @@ struct ast_custom_function len_function = {
static char *acf_strftime(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) 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; long epochi;
struct tm time; struct tm time;
buf[0] = '\0'; buf[0] = '\0';
if (!data) { if (ast_strlen_zero(data)) {
ast_log(LOG_ERROR, "Asterisk function STRFTIME() requires an argument.\n"); ast_log(LOG_ERROR, "Asterisk function STRFTIME() requires an argument.\n");
return buf; return buf;
} }
format = ast_strdupa(data); parse = ast_strdupa(data);
if (!format) { if (!parse) {
ast_log(LOG_ERROR, "Out of memory\n"); ast_log(LOG_ERROR, "Out of memory\n");
return buf; return buf;
} }
epoch = strsep(&format, "|"); AST_STANDARD_APP_ARGS(args, parse);
timezone = strsep(&format, "|");
if (ast_strlen_zero(epoch) || !sscanf(epoch, "%ld", &epochi)) { if (ast_strlen_zero(args.epoch) || !sscanf(args.epoch, "%ld", &epochi)) {
struct timeval tv = ast_tvnow(); struct timeval tv = ast_tvnow();
epochi = tv.tv_sec; epochi = tv.tv_sec;
} }
ast_localtime(&epochi, &time, timezone); ast_localtime(&epochi, &time, args.timezone);
if (!format) { if (!strftime(buf, len, args.format?args.format:"%c", &time)) {
format = "%c";
}
if (!strftime(buf, len, format, &time)) {
ast_log(LOG_WARNING, "C function strftime() output nothing?!!\n"); ast_log(LOG_WARNING, "C function strftime() output nothing?!!\n");
} }
buf[len - 1] = '\0'; buf[len - 1] = '\0';