diff --git a/channel.c b/channel.c index 6b9038873b02ac6d82b0cf67f1c5a557efcd8e2e..00c863b75a78c3d9633aae1fdf7e3fc9a82d41cd 100755 --- a/channel.c +++ b/channel.c @@ -1489,7 +1489,7 @@ int ast_set_read_format(struct ast_channel *chan, int fmts) return 0; } -struct ast_channel *ast_request_and_dial(char *type, int format, void *data, int timeout, int *outstate, char *callerid) +struct ast_channel *__ast_request_and_dial(char *type, int format, void *data, int timeout, int *outstate, char *callerid, struct outgoing_helper *oh) { int state = 0; struct ast_channel *chan; @@ -1497,8 +1497,23 @@ struct ast_channel *ast_request_and_dial(char *type, int format, void *data, int int res = 0; chan = ast_request(type, format, data); if (chan) { - if (callerid) - ast_set_callerid(chan, callerid, 1); + if (oh) { + char *tmp, *var; + /* JDG chanvar */ + tmp = oh->variable; + /* FIXME replace this call with strsep NOT*/ + while( (var = strtok_r(NULL, "|", &tmp)) ) { + pbx_builtin_setvar( chan, var ); + } /* /JDG */ + if (*oh->context) + strncpy(chan->context, oh->context, sizeof(chan->context) - 1); + if (*oh->exten) + strncpy(chan->exten, oh->exten, sizeof(chan->exten) - 1); + if (*oh->callerid) + ast_set_callerid(chan, oh->callerid, 1); + chan->priority = oh->priority; + } + if (!ast_call(chan, data, 0)) { while(timeout && (chan->_state != AST_STATE_UP)) { res = ast_waitfor(chan, timeout); @@ -1566,6 +1581,11 @@ struct ast_channel *ast_request_and_dial(char *type, int format, void *data, int return chan; } +struct ast_channel *ast_request_and_dial(char *type, int format, void *data, int timeout, int *outstate, char *callerid) +{ + return __ast_request_and_dial(type, format, data, timeout, outstate, callerid, NULL); +} + struct ast_channel *ast_request(char *type, int format, void *data) { struct chanlist *chan; diff --git a/include/asterisk/channel.h b/include/asterisk/channel.h index f33bb62d321725191e62e7b6c552162cd61e3701..16a148302f9dd99948eee380c93a4bd3c078ce04 100755 --- a/include/asterisk/channel.h +++ b/include/asterisk/channel.h @@ -230,6 +230,22 @@ struct ast_channel { struct chanmon; +#define LOAD_OH(oh) { \ + oh.context = context; \ + oh.exten = exten; \ + oh.priority = priority; \ + oh.callerid = callerid; \ + oh.variable = variable; \ +} + +struct outgoing_helper { + char *context; + char *exten; + int priority; + char *callerid; + char *variable; +}; + #define AST_CDR_TRANSFER (1 << 0) #define AST_CDR_FORWARD (1 << 1) #define AST_CDR_CALLWAIT (1 << 2) @@ -327,6 +343,8 @@ int ast_device_state(char *device); */ struct ast_channel *ast_request_and_dial(char *type, int format, void *data, int timeout, int *reason, char *callerid); +struct ast_channel *__ast_request_and_dial(char *type, int format, void *data, int timeout, int *reason, char *callerid, struct outgoing_helper *oh); + //! Registers a channel /*! * \param type type of channel you are registering diff --git a/include/asterisk/pbx.h b/include/asterisk/pbx.h index 32dfcc1274ecb40a6f410978962347a4eab0678f..3238ab403a85a3f2a3108003b68e95f455dd0d0a 100755 --- a/include/asterisk/pbx.h +++ b/include/asterisk/pbx.h @@ -521,6 +521,7 @@ struct ast_sw *ast_walk_context_switches(struct ast_context *con, struct ast_sw extern char *pbx_builtin_getvar_helper(struct ast_channel *chan, char *name); extern void pbx_builtin_setvar_helper(struct ast_channel *chan, char *name, char *value); extern void pbx_builtin_clear_globals(void); +extern int pbx_builtin_setvar(struct ast_channel *chan, void *data); extern void pbx_substitute_variables_helper(struct ast_channel *c,const char *cp1,char *cp2,int count); int ast_extension_patmatch(const char *pattern, const char *data); diff --git a/pbx.c b/pbx.c index 05820815409595e8559813acd4d19b503a950bf7..aa833c7917c48e192c2ce73c619295c4a770aaff 100755 --- a/pbx.c +++ b/pbx.c @@ -162,13 +162,13 @@ static int pbx_builtin_setaccount(struct ast_channel *, void *); static int pbx_builtin_ringing(struct ast_channel *, void *); static int pbx_builtin_congestion(struct ast_channel *, void *); static int pbx_builtin_busy(struct ast_channel *, void *); -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 *); +int pbx_builtin_setvar(struct ast_channel *, void *); void pbx_builtin_setvar_helper(struct ast_channel *chan, char *name, char *value); char *pbx_builtin_getvar_helper(struct ast_channel *chan, char *name); @@ -3786,31 +3786,16 @@ int ast_pbx_outgoing_exten(char *type, int format, void *data, int timeout, char struct async_stat *as; int res = -1; char *var, *tmp; + struct outgoing_helper oh; if (sync) { - chan = ast_request_and_dial(type, format, data, timeout, reason, callerid); + LOAD_OH(oh); + chan = __ast_request_and_dial(type, format, data, timeout, reason, callerid, &oh); if (chan) { - /* JDG chanvar */ - tmp = variable; - /* FIXME replace this call with strsep NOT*/ - while( (var = strtok_r(NULL, "|", &tmp)) ) { - pbx_builtin_setvar( chan, var ); - } /* /JDG */ if (chan->_state == AST_STATE_UP) { - res = 0; + res = 0; if (option_verbose > 3) ast_verbose(VERBOSE_PREFIX_4 "Channel %s was answered.\n", chan->name); - if (context && *context) - strncpy(chan->context, context, sizeof(chan->context) - 1); - if (exten && *exten) - strncpy(chan->exten, exten, sizeof(chan->exten) - 1); - if (callerid && *callerid) { - /* XXX call ast_set_callerid? */ - if (chan->callerid) - free(chan->callerid); - chan->callerid = strdup(callerid); - } - if (priority > 0) - chan->priority = priority; + if (sync > 1) { if (ast_pbx_run(chan)) { ast_log(LOG_WARNING, "Unable to run PBX on %s\n", chan->name); @@ -4345,7 +4330,7 @@ void pbx_builtin_setvar_helper(struct ast_channel *chan, char *name, char *value } } -static int pbx_builtin_setvar(struct ast_channel *chan, void *data) +int pbx_builtin_setvar(struct ast_channel *chan, void *data) { char *name; char *value;