Index: channels/chan_mgcp.c =================================================================== --- channels/chan_mgcp.c (revisiĆ³n: 186169) +++ channels/chan_mgcp.c (copia de trabajo) @@ -79,6 +79,7 @@ #include "asterisk/devicestate.h" #include "asterisk/stringfields.h" #include "asterisk/abstract_jb.h" +#include "asterisk/chanvars.h" #ifndef IPTOS_MINCOST #define IPTOS_MINCOST 0x02 @@ -368,6 +369,7 @@ /* struct ast_rtp *rtp; */ /* struct sockaddr_in tmpdest; */ /* message go the the endpoint and not the channel so they stay here */ + struct ast_variable *chanvars; /*!< Variables to set for channel created by user */ struct mgcp_endpoint *next; struct mgcp_gateway *parent; }; @@ -1019,6 +1021,8 @@ struct mgcp_gateway *g; struct mgcp_endpoint *e; int hasendpoints = 0; + struct ast_variable * v = NULL; + if (argc != 3) return RESULT_SHOWUSAGE; @@ -1029,8 +1033,14 @@ ast_cli(fd, "Gateway '%s' at %s (%s)\n", g->name, g->addr.sin_addr.s_addr ? ast_inet_ntoa(g->addr.sin_addr) : ast_inet_ntoa(g->defaddr.sin_addr), g->dynamic ? "Dynamic" : "Static"); while(e) { /* Don't show wilcard endpoint */ - if (strcmp(e->name, g->wcardep) !=0) - ast_cli(fd, " -- '%s@%s in '%s' is %s\n", e->name, g->name, e->context, e->sub->owner ? "active" : "idle"); + if (strcmp(e->name, g->wcardep) !=0) { + ast_cli(fd, " -- '%s@%s' in '%s' is %s\n", e->name, g->name, e->context, e->sub->owner ? "active" : "idle"); + if (e->chanvars) { + ast_cli(fd, " Variables:\n"); + for (v = e->chanvars ; v ; v = v->next) + ast_cli(fd, " %s = %s\n", v->name, v->value); + } + } hasendpoints = 1; e = e->next; } @@ -1458,6 +1468,7 @@ static struct ast_channel *mgcp_new(struct mgcp_subchannel *sub, int state) { struct ast_channel *tmp; + struct ast_variable *v = NULL; struct mgcp_endpoint *i = sub->parent; int fmt; @@ -1507,6 +1518,12 @@ if (!i->adsi) tmp->adsicpe = AST_ADSI_UNAVAILABLE; tmp->priority = 1; + + /* Set channel variables for this call from configuration */ + for (v = i->chanvars ; v ; v = v->next) { + pbx_builtin_setvar_helper(tmp, v->name, v->value); + } + if (sub->rtp) ast_jb_configure(tmp, &global_jbconf); if (state != AST_STATE_DOWN) { @@ -3611,6 +3628,10 @@ struct mgcp_gateway *gw; struct mgcp_endpoint *e; struct mgcp_subchannel *sub; + char *varname = NULL, *varval = NULL; + struct ast_variable *tmpvar = NULL; + struct ast_variable *chanvars = NULL; + /*char txident[80];*/ int i=0, y=0; int gw_reload = 0; @@ -3712,6 +3733,16 @@ } else { amaflags = y; } + + } else if (!strcasecmp(v->name, "setvar")) { + varname = ast_strdupa(v->value); + if ((varval = strchr(varname,'='))) { + *varval++ = '\0'; + if ((tmpvar = ast_variable_new(varname, varval))) { + tmpvar->next = chanvars; + chanvars = tmpvar; + } + } } else if (!strcasecmp(v->name, "musiconhold")) { ast_copy_string(musicclass, v->value, sizeof(musicclass)); } else if (!strcasecmp(v->name, "callgroup")) { @@ -3806,6 +3837,15 @@ e->onhooktime = time(NULL); /* ASSUME we're onhook */ e->hookstate = MGCP_ONHOOK; + + /* The chanvars are only valid for line/trunks, not for wildcard endpoint, + so we don't save the vars (only free the corresponding memory) + */ + if (chanvars) { + ast_variables_destroy(chanvars); + chanvars = NULL; + } + if (!ep_reload) { /*snprintf(txident, sizeof(txident), "%08lx", ast_random());*/ for (i = 0; i < MAX_SUBS; i++) { @@ -3908,6 +3948,17 @@ e->slowsequence = slowsequence; e->transfer = transfer; e->threewaycalling = threewaycalling; + + /* If we already have a valid chanvars, it's not a new endpoint (it's a reload), + so first, free previous mem + */ + if (e->chanvars) { + ast_variables_destroy(e->chanvars); + e->chanvars = NULL; + } + e->chanvars = chanvars; + chanvars = NULL; + if (!ep_reload) { e->onhooktime = time(NULL); /* ASSUME we're onhook */ @@ -4055,6 +4106,12 @@ ast_mutex_destroy(&s->cx_queue_lock); free(s); } + + if (e->chanvars) { + ast_variables_destroy(e->chanvars); + e->chanvars = NULL; + } + ast_mutex_destroy(&e->lock); ast_mutex_destroy(&e->rqnt_queue_lock); ast_mutex_destroy(&e->cmd_queue_lock);