[Asterisk-cvs] asterisk channel.c, 1.221, 1.222 manager.c, 1.103,
1.104 pbx.c, 1.261, 1.262 sample.call, 1.2, 1.3
russell at lists.digium.com
russell at lists.digium.com
Fri Jul 15 19:17:04 CDT 2005
Update of /usr/cvsroot/asterisk
In directory mongoose.digium.com:/tmp/cvs-serv13448
Modified Files:
channel.c manager.c pbx.c sample.call
Log Message:
Allow manager originate to specifiy more than one variable to be set.
Allow manager originate and spool files to set writable dialplan functions,
including those that use the pipe symbol to seperate arguments.
Allow CDR dialplan function to be able to set the account code and userfield.
This deprecates the use of the Account header in manager originate and spool
files, as well as the SetAccount and SetCDRUserField applications.
Index: channel.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channel.c,v
retrieving revision 1.221
retrieving revision 1.222
diff -u -d -r1.221 -r1.222
--- channel.c 15 Jul 2005 23:00:46 -0000 1.221
+++ channel.c 15 Jul 2005 23:24:51 -0000 1.222
@@ -2031,20 +2031,8 @@
chan = ast_request(type, format, data, &cause);
if (chan) {
if (oh) {
- char *tmp, *var;
- /* JDG chanvar */
- if (oh->variable)
- variable = ast_strdupa(oh->variable);
- else
- variable = NULL;
- tmp = variable;
- /* FIXME replace this call with strsep NOT*/
- while( (var = strtok_r(NULL, "|", &tmp)) ) {
- pbx_builtin_setvar( chan, var );
- } /* /JDG */
+ ast_set_variables(chan, oh->vars);
ast_set_callerid(chan, oh->cid_num, oh->cid_name, oh->cid_num);
- if (oh->account && *oh->account)
- ast_cdr_setaccount(chan, oh->account);
}
ast_set_callerid(chan, cid_num, cid_name, cid_num);
@@ -2107,7 +2095,8 @@
ast_copy_string(chan->context, oh->context, sizeof(chan->context));
if (oh->exten && *oh->exten)
ast_copy_string(chan->exten, oh->exten, sizeof(chan->exten));
- chan->priority = oh->priority;
+ if (oh->priority)
+ chan->priority = oh->priority;
}
if (chan->_state == AST_STATE_UP)
state = AST_CONTROL_ANSWER;
@@ -3450,3 +3439,11 @@
}
return(buf);
}
+
+void ast_set_variables(struct ast_channel *chan, struct ast_variable *vars)
+{
+ struct ast_variable *cur;
+
+ for (cur = vars; cur; cur = cur->next)
+ pbx_builtin_setvar_helper(chan, cur->name, cur->value);
+}
Index: manager.c
===================================================================
RCS file: /usr/cvsroot/asterisk/manager.c,v
retrieving revision 1.103
retrieving revision 1.104
diff -u -d -r1.103 -r1.104
--- manager.c 15 Jul 2005 23:00:46 -0000 1.103
+++ manager.c 15 Jul 2005 23:24:51 -0000 1.104
@@ -46,8 +46,7 @@
#include "asterisk/acl.h"
#include "asterisk/utils.h"
-struct fast_originate_helper
-{
+struct fast_originate_helper {
char tech[256];
char data[256];
int timeout;
@@ -55,12 +54,11 @@
char appdata[256];
char cid_name[256];
char cid_num[256];
- char variable[256];
- char account[256];
char context[256];
char exten[256];
char idtext[256];
int priority;
+ struct ast_variable *vars;
};
static int enabled = 0;
@@ -283,6 +281,30 @@
return "";
}
+struct ast_variable *astman_get_variables(struct message *m)
+{
+ int varlen, x;
+ struct ast_variable *head = NULL, *cur;
+ char *var, *val;
+
+ varlen = strlen("Variable: ");
+
+ for (x = 0; x < m->hdrcount; x++) {
+ if (!strncasecmp("Variable: ", m->headers[x], varlen)) {
+ var = val = ast_strdupa(m->headers[x] + varlen);
+ strsep(&val, "=");
+ cur = ast_variable_new(var, val);
+ if (head) {
+ cur->next = head;
+ head = cur;
+ } else
+ head = cur;
+ }
+ }
+
+ return head;
+}
+
void astman_send_error(struct mansession *s, struct message *m, char *error)
{
char *id = astman_get_header(m,"ActionID");
@@ -864,12 +886,12 @@
res = ast_pbx_outgoing_app(in->tech, AST_FORMAT_SLINEAR, in->data, in->timeout, in->app, in->appdata, &reason, 1,
!ast_strlen_zero(in->cid_num) ? in->cid_num : NULL,
!ast_strlen_zero(in->cid_name) ? in->cid_name : NULL,
- in->variable, in->account, &chan);
+ in->vars, &chan);
} else {
res = ast_pbx_outgoing_exten(in->tech, AST_FORMAT_SLINEAR, in->data, in->timeout, in->context, in->exten, in->priority, &reason, 1,
!ast_strlen_zero(in->cid_num) ? in->cid_num : NULL,
!ast_strlen_zero(in->cid_name) ? in->cid_name : NULL,
- in->variable, in->account, &chan);
+ in->vars, &chan);
}
if (!res)
manager_event(EVENT_FLAG_CALL,
@@ -923,12 +945,12 @@
char *priority = astman_get_header(m, "Priority");
char *timeout = astman_get_header(m, "Timeout");
char *callerid = astman_get_header(m, "CallerID");
- char *variable = astman_get_header(m, "Variable");
char *account = astman_get_header(m, "Account");
char *app = astman_get_header(m, "Application");
char *appdata = astman_get_header(m, "Data");
char *async = astman_get_header(m, "Async");
char *id = astman_get_header(m, "ActionID");
+ struct ast_variable *vars = astman_get_variables(m);
char *tech, *data;
char *l=NULL, *n=NULL;
int pi = 0;
@@ -936,7 +958,7 @@
int to = 30000;
int reason = 0;
char tmp[256];
- char tmp2[256]="";
+ char tmp2[256];
pthread_t th;
pthread_attr_t attr;
@@ -972,6 +994,12 @@
if (ast_strlen_zero(l))
l = NULL;
}
+ if (account) {
+ struct ast_variable *newvar;
+ newvar = ast_variable_new("CDR(accountcode|r)", account);
+ newvar->next = vars;
+ vars = newvar;
+ }
if (ast_true(async)) {
struct fast_originate_helper *fast = malloc(sizeof(struct fast_originate_helper));
if (!fast) {
@@ -988,8 +1016,7 @@
ast_copy_string(fast->cid_num, l, sizeof(fast->cid_num));
if (n)
ast_copy_string(fast->cid_name, n, sizeof(fast->cid_name));
- ast_copy_string(fast->variable, variable, sizeof(fast->variable));
- ast_copy_string(fast->account, account, sizeof(fast->account));
+ fast->vars = vars;
ast_copy_string(fast->context, context, sizeof(fast->context));
ast_copy_string(fast->exten, exten, sizeof(fast->exten));
fast->timeout = to;
@@ -1003,10 +1030,10 @@
}
}
} else if (!ast_strlen_zero(app)) {
- res = ast_pbx_outgoing_app(tech, AST_FORMAT_SLINEAR, data, to, app, appdata, &reason, 1, l, n, variable, account, NULL);
+ res = ast_pbx_outgoing_app(tech, AST_FORMAT_SLINEAR, data, to, app, appdata, &reason, 1, l, n, vars, NULL);
} else {
if (exten && context && pi)
- res = ast_pbx_outgoing_exten(tech, AST_FORMAT_SLINEAR, data, to, context, exten, pi, &reason, 1, l, n, variable, account, NULL);
+ res = ast_pbx_outgoing_exten(tech, AST_FORMAT_SLINEAR, data, to, context, exten, pi, &reason, 1, l, n, vars, NULL);
else {
astman_send_error(s, m, "Originate with 'Exten' requires 'Context' and 'Priority'");
return 0;
Index: pbx.c
===================================================================
RCS file: /usr/cvsroot/asterisk/pbx.c,v
retrieving revision 1.261
retrieving revision 1.262
diff -u -d -r1.261 -r1.262
--- pbx.c 15 Jul 2005 22:06:15 -0000 1.261
+++ pbx.c 15 Jul 2005 23:24:51 -0000 1.262
@@ -4742,15 +4742,14 @@
return 0; /* success */
}
-int ast_pbx_outgoing_exten(const char *type, int format, void *data, int timeout, const char *context, const char *exten, int priority, int *reason, int sync, const char *cid_num, const char *cid_name, const char *variable, const char *account, struct ast_channel **channel)
+int ast_pbx_outgoing_exten(const char *type, int format, void *data, int timeout, const char *context, const char *exten, int priority, int *reason, int sync, const char *cid_num, const char *cid_name, struct ast_variable *vars, struct ast_channel **channel)
{
struct ast_channel *chan;
struct async_stat *as;
int res = -1, cdr_res = -1;
- char *var, *tmp;
struct outgoing_helper oh;
pthread_attr_t attr;
-
+
if (sync) {
LOAD_OH(oh);
chan = __ast_request_and_dial(type, format, data, timeout, reason, cid_num, cid_name, &oh);
@@ -4760,25 +4759,21 @@
ast_mutex_lock(&chan->lock);
}
if (chan) {
-
- if (account)
- ast_cdr_setaccount(chan, account);
-
if(chan->cdr) { /* check if the channel already has a cdr record, if not give it one */
ast_log(LOG_WARNING, "%s already has a call record??\n", chan->name);
} else {
chan->cdr = ast_cdr_alloc(); /* allocate a cdr for the channel */
- if(!chan->cdr) {
+ if (!chan->cdr) {
/* allocation of the cdr failed */
ast_log(LOG_WARNING, "Unable to create Call Detail Record\n");
free(chan->pbx);
- return -1; /* return failure */
+ res = -1;
+ goto outgoing_exten_cleanup;
}
/* allocation of the cdr was successful */
ast_cdr_init(chan->cdr, chan); /* initilize our channel's cdr */
ast_cdr_start(chan->cdr);
}
-
if (chan->_state == AST_STATE_UP) {
res = 0;
if (option_verbose > 3)
@@ -4805,7 +4800,7 @@
if(chan->cdr) { /* update the cdr */
/* here we update the status of the call, which sould be busy.
* if that fails then we set the status to failed */
- if(ast_cdr_disposition(chan->cdr, chan->hangupcause))
+ if (ast_cdr_disposition(chan->cdr, chan->hangupcause))
ast_cdr_failed(chan->cdr);
}
@@ -4814,29 +4809,26 @@
}
if(res < 0) { /* the call failed for some reason */
- if(*reason == 0) { /* if the call failed (not busy or no answer)
+ if (*reason == 0) { /* if the call failed (not busy or no answer)
* update the cdr with the failed message */
cdr_res = ast_pbx_outgoing_cdr_failed();
- if(cdr_res != 0)
- return cdr_res;
+ if (cdr_res != 0) {
+ res = cdr_res;
+ goto outgoing_exten_cleanup;
+ }
}
/* create a fake channel and execute the "failed" extension (if it exists) within the requested context */
/* check if "failed" exists */
if (ast_exists_extension(chan, context, "failed", 1, NULL)) {
chan = ast_channel_alloc(0);
- if(chan) {
+ if (chan) {
ast_copy_string(chan->name, "OutgoingSpoolFailed", sizeof(chan->name));
if (context && !ast_strlen_zero(context))
ast_copy_string(chan->context, context, sizeof(chan->context));
ast_copy_string(chan->exten, "failed", sizeof(chan->exten));
chan->priority = 1;
- if (variable) {
- tmp = ast_strdupa(variable);
- for (var = strtok_r(tmp, "|", &tmp); var; var = strtok_r(NULL, "|", &tmp)) {
- pbx_builtin_setvar( chan, var );
- }
- }
+ ast_set_variables(chan, vars);
ast_pbx_run(chan);
} else
ast_log(LOG_WARNING, "Can't allocate the channel structure, skipping execution of extension 'failed'\n");
@@ -4844,8 +4836,10 @@
}
} else {
as = malloc(sizeof(struct async_stat));
- if (!as)
- return -1;
+ if (!as) {
+ res = -1;
+ goto outgoing_exten_cleanup;
+ }
memset(as, 0, sizeof(struct async_stat));
chan = ast_request_and_dial(type, format, data, timeout, reason, cid_num, cid_name);
if (channel) {
@@ -4855,30 +4849,28 @@
}
if (!chan) {
free(as);
- return -1;
+ res = -1;
+ goto outgoing_exten_cleanup;
}
- if (account)
- ast_cdr_setaccount(chan, account);
as->chan = chan;
ast_copy_string(as->context, context, sizeof(as->context));
ast_copy_string(as->exten, exten, sizeof(as->exten));
as->priority = priority;
as->timeout = timeout;
- if (variable) {
- tmp = ast_strdupa(variable);
- for (var = strtok_r(tmp, "|", &tmp); var; var = strtok_r(NULL, "|", &tmp))
- pbx_builtin_setvar( chan, var );
- }
+ ast_set_variables(chan, vars);
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
if (ast_pthread_create(&as->p, &attr, async_wait, as)) {
ast_log(LOG_WARNING, "Failed to start async wait\n");
free(as);
ast_hangup(chan);
- return -1;
+ res = -1;
+ goto outgoing_exten_cleanup;
}
res = 0;
}
+outgoing_exten_cleanup:
+ ast_variables_destroy(vars);
return res;
}
@@ -4905,26 +4897,28 @@
return NULL;
}
-int ast_pbx_outgoing_app(const char *type, int format, void *data, int timeout, const char *app, const char *appdata, int *reason, int sync, const char *cid_num, const char *cid_name, const char *variable, const char *account, struct ast_channel **locked_channel)
+int ast_pbx_outgoing_app(const char *type, int format, void *data, int timeout, const char *app, const char *appdata, int *reason, int sync, const char *cid_num, const char *cid_name, struct ast_variable *vars, struct ast_channel **locked_channel)
{
struct ast_channel *chan;
struct async_stat *as;
struct app_tmp *tmp;
- char *var, *vartmp;
int res = -1, cdr_res = -1;
+ struct outgoing_helper oh;
pthread_attr_t attr;
+ memset(&oh, 0, sizeof(oh));
+ oh.vars = vars;
+
if (locked_channel)
*locked_channel = NULL;
- if (!app || ast_strlen_zero(app))
- return -1;
+ if (!app || ast_strlen_zero(app)) {
+ res = -1;
+ goto outgoing_app_cleanup;
+ }
if (sync) {
- chan = ast_request_and_dial(type, format, data, timeout, reason, cid_num, cid_name);
+ chan = __ast_request_and_dial(type, format, data, timeout, reason, cid_num, cid_name, &oh);
if (chan) {
- if (account)
- ast_cdr_setaccount(chan, account);
-
- if(chan->cdr) { /* check if the channel already has a cdr record, if not give it one */
+ if (chan->cdr) { /* check if the channel already has a cdr record, if not give it one */
ast_log(LOG_WARNING, "%s already has a call record??\n", chan->name);
} else {
chan->cdr = ast_cdr_alloc(); /* allocate a cdr for the channel */
@@ -4932,19 +4926,14 @@
/* allocation of the cdr failed */
ast_log(LOG_WARNING, "Unable to create Call Detail Record\n");
free(chan->pbx);
- return -1; /* return failure */
+ res = -1;
+ goto outgoing_app_cleanup;
}
/* allocation of the cdr was successful */
ast_cdr_init(chan->cdr, chan); /* initilize our channel's cdr */
ast_cdr_start(chan->cdr);
}
-
- if (variable) {
- vartmp = ast_strdupa(variable);
- for (var = strtok_r(vartmp, "|", &vartmp); var; var = strtok_r(NULL, "|", &vartmp)) {
- pbx_builtin_setvar( chan, var );
- }
- }
+ ast_set_variables(chan, vars);
if (chan->_state == AST_STATE_UP) {
res = 0;
if (option_verbose > 3)
@@ -4984,47 +4973,46 @@
} else {
if (option_verbose > 3)
ast_verbose(VERBOSE_PREFIX_4 "Channel %s was never answered.\n", chan->name);
- if(chan->cdr) { /* update the cdr */
+ if (chan->cdr) { /* update the cdr */
/* here we update the status of the call, which sould be busy.
* if that fails then we set the status to failed */
- if(ast_cdr_disposition(chan->cdr, chan->hangupcause))
+ if (ast_cdr_disposition(chan->cdr, chan->hangupcause))
ast_cdr_failed(chan->cdr);
}
ast_hangup(chan);
}
}
- if(res < 0) { /* the call failed for some reason */
- if(*reason == 0) { /* if the call failed (not busy or no answer)
+ if (res < 0) { /* the call failed for some reason */
+ if (*reason == 0) { /* if the call failed (not busy or no answer)
* update the cdr with the failed message */
cdr_res = ast_pbx_outgoing_cdr_failed();
- if(cdr_res != 0)
- return cdr_res;
+ if (cdr_res != 0) {
+ res = cdr_res;
+ goto outgoing_app_cleanup;
+ }
}
}
} else {
as = malloc(sizeof(struct async_stat));
- if (!as)
- return -1;
+ if (!as) {
+ res = -1;
+ goto outgoing_app_cleanup;
+ }
memset(as, 0, sizeof(struct async_stat));
chan = ast_request_and_dial(type, format, data, timeout, reason, cid_num, cid_name);
if (!chan) {
free(as);
- return -1;
+ res = -1;
+ goto outgoing_app_cleanup;
}
- if (account)
- ast_cdr_setaccount(chan, account);
as->chan = chan;
ast_copy_string(as->app, app, sizeof(as->app));
if (appdata)
ast_copy_string(as->appdata, appdata, sizeof(as->appdata));
as->timeout = timeout;
- if (variable) {
- vartmp = ast_strdupa(variable);
- for (var = strtok_r(vartmp, "|", &vartmp); var; var = strtok_r(NULL, "|", &vartmp))
- pbx_builtin_setvar( chan, var );
- }
+ ast_set_variables(chan, vars);
/* Start a new thread, and get something handling this channel. */
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
@@ -5036,13 +5024,16 @@
if (locked_channel)
ast_mutex_unlock(&chan->lock);
ast_hangup(chan);
- return -1;
+ res = -1;
+ goto outgoing_app_cleanup;
} else {
if (locked_channel)
*locked_channel = chan;
}
res = 0;
}
+outgoing_app_cleanup:
+ ast_variables_destroy(vars);
return res;
}
Index: sample.call
===================================================================
RCS file: /usr/cvsroot/asterisk/sample.call,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- sample.call 26 Mar 2004 08:04:13 -0000 1.2
+++ sample.call 15 Jul 2005 23:24:51 -0000 1.3
@@ -37,13 +37,11 @@
#Callerid: Wakeup Call Service <(555) 555-5555>
#
-# You can set channel variables that will be passed to the channel
-#
-#SetVar: file1=/tmp/to
-#SetVar: file2=/tmp/msg
-#SetVar: timestamp=20021023104500
-
-#
-# You may specify an account to be passed to CDRs
+# You can set channel variables that will be passed to the channel.
+# This includes writable dialplan functions.
#
-#Account: markster
+#Set: file1=/tmp/to
+#Set: file2=/tmp/msg
+#Set: timestamp=20021023104500
+#Set: CDR(accountcode|r)=blort
+#Set: CDR(userfield|r)=42
More information about the svn-commits
mailing list