[asterisk-commits] twilson: trunk r309640 - in /trunk: ./ configs/ include/asterisk/ res/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Mar 4 17:22:43 CST 2011
Author: twilson
Date: Fri Mar 4 17:22:39 2011
New Revision: 309640
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=309640
Log:
Add setvar option to calendaring
Adding the setvar option with variable substitution on the value allows things
like setting the outbound caller id name to the summary of a calendar event,
etc. Values could be chained together as they are appended in order to do some
scripting if necessary.
Review: https://reviewboard.asterisk.org/r/1134/
Modified:
trunk/CHANGES
trunk/configs/calendar.conf.sample
trunk/include/asterisk/calendar.h
trunk/res/res_calendar.c
Modified: trunk/CHANGES
URL: http://svnview.digium.com/svn/asterisk/trunk/CHANGES?view=diff&rev=309640&r1=309639&r2=309640
==============================================================================
--- trunk/CHANGES (original)
+++ trunk/CHANGES Fri Mar 4 17:22:39 2011
@@ -64,6 +64,11 @@
is handled. To send display text from the dialplan use the SendText()
application when the option is enabled.
* Added mcid_send option to allow sending a MCID request on a span.
+
+Calendaring
+--------------------------
+ * Added setvar option to calendar.conf to allow setting channel variables on
+ notification channels.
------------------------------------------------------------------------------
--- Functionality changes from Asterisk 1.6.2 to Asterisk 1.8 ----------------
Modified: trunk/configs/calendar.conf.sample
URL: http://svnview.digium.com/svn/asterisk/trunk/configs/calendar.conf.sample?view=diff&rev=309640&r1=309639&r2=309640
==============================================================================
--- trunk/configs/calendar.conf.sample (original)
+++ trunk/configs/calendar.conf.sample Fri Mar 4 17:22:39 2011
@@ -32,6 +32,13 @@
;appdata = tt-weasels ; Data part of application to execute on answer
;
;waittime = 30 ; How long to wait for an answer, defaults to 30 seconds
+;
+; Channel variables can be set on the notification channel. The format is
+; setvar=name=value. Variable subsitution is done on the value to allow the use of dialplan
+; functions like CALENDAR_EVENT. The variables are set in order, so one can use the value
+; of earlier variables in the definition of later ones.
+;
+;setvar = CALLERID(name)=${CALENDAR_EVENT(summary)}
;[calendar2]
; Note: Support for Exchange Server 2003
Modified: trunk/include/asterisk/calendar.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/calendar.h?view=diff&rev=309640&r1=309639&r2=309640
==============================================================================
--- trunk/include/asterisk/calendar.h (original)
+++ trunk/include/asterisk/calendar.h Fri Mar 4 17:22:39 2011
@@ -123,6 +123,7 @@
AST_STRING_FIELD(notify_app); /*!< Optional dialplan app to execute for notification */
AST_STRING_FIELD(notify_appdata); /*!< Optional arguments for dialplan app */
);
+ struct ast_variable *vars; /*!< Channel variables to pass to notification channel */
int autoreminder; /*!< If set, override any calendar_tech specific notification times and use this time (in mins) */
int notify_waittime; /*!< Maxiumum time to allow for a notification attempt */
int refresh; /*!< When to refresh the calendar events */
Modified: trunk/res/res_calendar.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_calendar.c?view=diff&rev=309640&r1=309639&r2=309640
==============================================================================
--- trunk/res/res_calendar.c (original)
+++ trunk/res/res_calendar.c Fri Mar 4 17:22:39 2011
@@ -313,6 +313,10 @@
}
ast_calendar_clear_events(cal);
ast_string_field_free_memory(cal);
+ if (cal->vars) {
+ ast_variables_destroy(cal->vars);
+ cal->vars = NULL;
+ }
ao2_ref(cal->events, -1);
ao2_unlock(cal);
}
@@ -369,7 +373,7 @@
static struct ast_calendar *build_calendar(struct ast_config *cfg, const char *cat, const struct ast_calendar_tech *tech)
{
struct ast_calendar *cal;
- struct ast_variable *v;
+ struct ast_variable *v, *last = NULL;
int new_calendar = 0;
if (!(cal = find_calendar(cat))) {
@@ -423,6 +427,26 @@
cal->refresh = atoi(v->value);
} else if (!strcasecmp(v->name, "timeframe")) {
cal->timeframe = atoi(v->value);
+ } else if (!strcasecmp(v->name, "setvar")) {
+ char *name, *value;
+ struct ast_variable *var;
+
+ if ((name = (value = ast_strdup(v->value)))) {
+ strsep(&value, "=");
+ if (value) {
+ if ((var = ast_variable_new(ast_strip(name), ast_strip(value), ""))) {
+ if (last) {
+ last->next = var;
+ } else {
+ cal->vars = var;
+ }
+ last = var;
+ }
+ } else {
+ ast_log(LOG_WARNING, "Malformed argument. Should be '%s: variable=value'\n", v->name);
+ }
+ ast_free(name);
+ }
}
}
@@ -666,10 +690,11 @@
{
struct ast_calendar_event *event = data;
struct ast_dial *dial = NULL;
- struct ast_str *apptext = NULL;
+ struct ast_str *apptext = NULL, *tmpstr;
struct ast_datastore *datastore;
enum ast_dial_result res;
struct ast_channel *chan = NULL;
+ struct ast_variable *itervar;
char *tech, *dest;
char buf[8];
@@ -720,6 +745,15 @@
ao2_ref(event, +1);
res = ast_channel_datastore_add(chan, datastore);
+ if (!(tmpstr = ast_str_create(32))) {
+ goto notify_cleanup;
+ }
+
+ for (itervar = event->owner->vars; itervar; itervar = itervar->next) {
+ ast_str_substitute_variables(&tmpstr, 0, chan, itervar->value);
+ pbx_builtin_setvar_helper(chan, itervar->name, tmpstr->str);
+ }
+
if (!(apptext = ast_str_create(32))) {
goto notify_cleanup;
}
@@ -750,6 +784,9 @@
notify_cleanup:
if (apptext) {
ast_free(apptext);
+ }
+ if (tmpstr) {
+ ast_free(tmpstr);
}
if (dial) {
ast_dial_destroy(dial);
More information about the asterisk-commits
mailing list