aboutsummaryrefslogtreecommitdiffstats
path: root/pbx.c
diff options
context:
space:
mode:
authormarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2003-04-28 04:18:47 +0000
committermarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2003-04-28 04:18:47 +0000
commit078302117665eda70919ed413933f68b39e11b33 (patch)
treef9245fe10ea165e07fdd6b31bc3b06708e9addb1 /pbx.c
parentf87da775da2dfaad11b893a7d8cc886fa863257e (diff)
Add gotoiftime (thanks Tilghman)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@925 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'pbx.c')
-rwxr-xr-xpbx.c64
1 files changed, 59 insertions, 5 deletions
diff --git a/pbx.c b/pbx.c
index 2c5c0a963..8298b8a9d 100755
--- a/pbx.c
+++ b/pbx.c
@@ -150,6 +150,7 @@ struct ast_hint {
static int pbx_builtin_prefix(struct ast_channel *, void *);
+static int pbx_builtin_suffix(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 *);
@@ -168,6 +169,7 @@ static int pbx_builtin_setvar(struct ast_channel *, void *);
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);
@@ -240,6 +242,13 @@ static struct pbx_builtin {
"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." },
+
{ "Hangup", pbx_builtin_hangup,
"Unconditional hangup",
" Hangup(): Unconditionally hangs up a given channel by returning -1 always.\n" },
@@ -313,6 +322,17 @@ static struct pbx_builtin {
"has no first step, the PBX will treat it as though the user dialed an\n"
"invalid extension.\n" },
+ { "Suffix", pbx_builtin_suffix,
+"Append trailing digits",
+" Suffix(digits): Appends the digit string specified by digits to the\n"
+"channel's associated extension. For example, the number 555 when suffixed\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 Suffix 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" },
+
{ "Wait", pbx_builtin_wait,
"Waits for some time",
" Wait(seconds): Waits for a specified number of seconds, then returns 0.\n" },
@@ -433,10 +453,6 @@ static inline int include_valid(struct ast_include *i)
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))) {
@@ -2399,7 +2415,7 @@ static char *complete_show_dialplan_context(char *line, char *word, int pos,
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 ... */
@@ -4010,6 +4026,44 @@ static int pbx_builtin_prefix(struct ast_channel *chan, void *data)
return 0;
}
+static int pbx_builtin_suffix(struct ast_channel *chan, void *data)
+{
+ char newexten[AST_MAX_EXTENSION] = "";
+ if (!data || !strlen(data)) {
+ ast_log(LOG_DEBUG, "Ignoring, since there is no suffix 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 suffix, 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)
{
int ms;