|
|
|
@ -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;
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
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 @@ struct ast_custom_function fieldqty_function = {
|
|
|
|
|
|
|
|
|
|
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, "|");
|
|
|
|
|
AST_STANDARD_APP_ARGS(args, parse);
|
|
|
|
|
|
|
|
|
|
if (!string) {
|
|
|
|
|
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 @@ struct ast_custom_function filter_function = {
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
AST_NONSTANDARD_APP_ARGS(args, parse, '"');
|
|
|
|
|
|
|
|
|
|
ast_log(LOG_DEBUG, "FUNCTION REGEX (%s)(%s)\n", args.reg, args.str);
|
|
|
|
|
|
|
|
|
|
if ((errcode = regcomp(®exbuf, arg, REG_EXTENDED | REG_NOSUB))) {
|
|
|
|
|
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 @@ struct ast_custom_function len_function = {
|
|
|
|
|
|
|
|
|
|
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, "|");
|
|
|
|
|
AST_STANDARD_APP_ARGS(args, parse);
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
epochi = tv.tv_sec;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ast_localtime(&epochi, &time, timezone);
|
|
|
|
|
|
|
|
|
|
if (!format) {
|
|
|
|
|
format = "%c";
|
|
|
|
|
}
|
|
|
|
|
ast_localtime(&epochi, &time, args.timezone);
|
|
|
|
|
|
|
|
|
|
if (!strftime(buf, len, format, &time)) {
|
|
|
|
|
if (!strftime(buf, len, args.format?args.format:"%c", &time)) {
|
|
|
|
|
ast_log(LOG_WARNING, "C function strftime() output nothing?!!\n");
|
|
|
|
|
}
|
|
|
|
|
buf[len - 1] = '\0';
|
|
|
|
|