In case anybody is interested, this patch creates an application
which allows the dial plan to branch based upon what time it is.
The syntax is the same as for the time specifier in contexts.
I've also included 'Affix', which works just like Prefix, but it
adds numbers to the end of an extension.
static int pbx_builtin_prefix(struct ast_channel *, void *);
+static int pbx_builtin_affix(struct ast_channel *, void *);
static int pbx_builtin_stripmsd(struct ast_channel *, void *);
static int pbx_builtin_answer(struct ast_channel *, void *);
static int pbx_builtin_goto(struct ast_channel *, void *);
@@ -167,6 +168,7 @@
static int pbx_builtin_setglobalvar(struct ast_channel *, void *);
static int pbx_builtin_noop(struct ast_channel *, void *);
static int pbx_builtin_gotoif(struct ast_channel *, void *);
+static int pbx_builtin_gotoiftime(struct ast_channel *, void *);
static int pbx_builtin_saynumber(struct ast_channel *, void *);
static int pbx_builtin_saydigits(struct ast_channel *, void *);
void pbx_builtin_setvar_helper(struct ast_channel *chan, char *name, char *value);
@@ -257,6 +259,17 @@
"which has no first step, the PBX will treat it as though the user dialed an\n"
"invalid extension.\n" },
+ { "Affix", pbx_builtin_affix,
+"Append trailing digits",
+" Affix(digits): Appends the digit string specified by digits to the\n"
+"channel's associated extension. For example, the number 555 when affixed\n"
+"with '1212' will become 5551212. This app always returns 0, and the PBX will\n"
+"continue processing at the next priority for the *new* extension.\n"
+" So, for example, if priority 3 of 555 is Affix 1212, the next step\n"
+"executed will be priority 4 of 5551212. If you switch into an extension\n"
+"which has no first step, the PBX will treat it as though the user dialed an\n"
+"invalid extension.\n" },
+
{ "SetLanguage", pbx_builtin_setlanguage,
"Sets user language",
" SetLanguage(language): Set the channel language to 'language'. This\n"
@@ -300,6 +313,13 @@
"omitted (in that case, we just don't take the particular branch) but not\n"
"both. Look for the condition syntax in examples or documentation." },
+ { "GotoIfTime", pbx_builtin_gotoiftime,
+"Conditional goto on current time",
+" GotoIfTime(<times>|<weekdays>|<mdays>|<months>?[[context|]extension|]pri):\n"
+"If the current time matches the specified time, then branch to the specified\n"
+"extension. Each of the elements may be specified either as '*' (for always)\n"
+"or as a range. See the include syntax." },
+
{ "SayNumber", pbx_builtin_saynumber,
"Say Number",
" SayNumber(digits): Says the passed number\n" },
@@ -424,10 +444,6 @@
return 1;
time(&t);
localtime_r(&t,&tm);
- if (!&tm) {
- ast_log(LOG_WARNING, "Failed to get local time\n");
- return 0;
- }
/* If it's not the right month, return */
if (!(i->monthmask & (1 << tm.tm_mon))) {
@@ -2376,7 +2392,7 @@
struct ast_context *c;
int which = 0;
- /* we are do completion of [exten@]context on second postion only */
+ /* we are do completion of [exten@]context on second position only */
if (pos != 2) return NULL;
/* try to lock contexts list ... */
@@ -3975,6 +3991,44 @@
if (option_verbose > 2)
ast_verbose(VERBOSE_PREFIX_3 "Prepended prefix, new extension is %s\n", chan->exten);
return 0;
+}
+
+static int pbx_builtin_affix(struct ast_channel *chan, void *data)
+{
+ char newexten[AST_MAX_EXTENSION] = "";
+ if (!data || !strlen(data)) {
+ ast_log(LOG_DEBUG, "Ignoring, since there is no affix to add\n");
+ return 0;
+ }
+ snprintf(newexten, sizeof(newexten), "%s%s", chan->exten, (char *)data);
+ strncpy(chan->exten, newexten, sizeof(chan->exten)-1);
+ if (option_verbose > 2)
+ ast_verbose(VERBOSE_PREFIX_3 "Appended affix, new extension is %s\n", chan->exten);
+ return 0;
+}
+
+static int pbx_builtin_gotoiftime(struct ast_channel *chan, void *data)
+{
+ int res=0;
+ char *s, *ts;
+ struct ast_include include;
+
+ if (!data) {
+ ast_log(LOG_WARNING, "GotoIfTime requires an argument:\n <time range>|<days of week>|<days of month>|<months>?[[context|]extension|]priority\n");
+ return -1;
+ }
+
+ s = strdup((char *) data);
+ ts = s;
+
+ /* Separate the Goto path */
+ strsep(&ts,"?");
+
+ build_timing(&include, s);
+ if (include_valid(&include))
+ res = pbx_builtin_goto(chan, (void *)ts);
+ free(s);
+ return res;
}
static int pbx_builtin_wait(struct ast_channel *chan, void *data)
Excellent! I've been puttering with some code to do just this via
some really ugly AGI hacks, but this is much cleaner. The "include"
with date/time didn't really fit the bill for some applications.
Perhaps the "Affix" application may be more clear if it was re-named
to "Suffix"?
JT
Quote:
In case anybody is interested, this patch creates an application
which allows the dial plan to branch based upon what time it is.
The syntax is the same as for the time specifier in contexts.
I've also included 'Affix', which works just like Prefix, but it
adds numbers to the end of an extension.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum