Add peercontext parameter for default outbound context (bug #1929)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@3315 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.0
Mark Spencer 21 years ago
parent 1af31f2c64
commit d9ed36059c

@ -1687,7 +1687,6 @@ static int leave_voicemail(struct ast_channel *chan, char *ext, int silent, int
char *context; char *context;
char ecodes[16] = "#"; char ecodes[16] = "#";
char tmp[256] = "", *tmpptr; char tmp[256] = "", *tmpptr;
char language[MAX_LANGUAGE];
struct ast_vm_user *vmu; struct ast_vm_user *vmu;
struct ast_vm_user svm; struct ast_vm_user svm;

@ -647,6 +647,7 @@ static struct ast_frame *alsa_read(struct ast_channel *chan)
left = FRAME_SIZE; left = FRAME_SIZE;
if (chan->_state != AST_STATE_UP) { if (chan->_state != AST_STATE_UP) {
/* Don't transmit unless it's up */ /* Don't transmit unless it's up */
ast_mutex_unlock(&alsalock);
return &f; return &f;
} }
f.frametype = AST_FRAME_VOICE; f.frametype = AST_FRAME_VOICE;

@ -216,6 +216,7 @@ struct iax2_peer {
char secret[80]; char secret[80];
char outkey[80]; /* What key we use to talk to this peer */ char outkey[80]; /* What key we use to talk to this peer */
char context[AST_MAX_EXTENSION]; /* Default context (for transfer really) */ char context[AST_MAX_EXTENSION]; /* Default context (for transfer really) */
char peercontext[AST_MAX_EXTENSION]; /* Context to pass to peer */
char mailbox[AST_MAX_EXTENSION]; /* Mailbox */ char mailbox[AST_MAX_EXTENSION]; /* Mailbox */
struct sockaddr_in addr; struct sockaddr_in addr;
int formats; int formats;
@ -1960,7 +1961,7 @@ static struct iax2_user *mysql_user(char *user)
} }
#endif /* MYSQL_FRIENDS */ #endif /* MYSQL_FRIENDS */
static int create_addr(struct sockaddr_in *sin, int *capability, int *sendani, int *maxtime, char *peer, char *context, int *trunk, int *notransfer, char *secret, int seclen, int *ofound) static int create_addr(struct sockaddr_in *sin, int *capability, int *sendani, int *maxtime, char *peer, char *context, int *trunk, int *notransfer, char *secret, int seclen, int *ofound, char *peercontext)
{ {
struct ast_hostent ahp; struct hostent *hp; struct ast_hostent ahp; struct hostent *hp;
struct iax2_peer *p; struct iax2_peer *p;
@ -1995,6 +1996,8 @@ static int create_addr(struct sockaddr_in *sin, int *capability, int *sendani, i
*maxtime = p->maxms; /* Max time they should take */ *maxtime = p->maxms; /* Max time they should take */
if (context) if (context)
strncpy(context, p->context, AST_MAX_EXTENSION - 1); strncpy(context, p->context, AST_MAX_EXTENSION - 1);
if (peercontext)
strncpy(peercontext, p->peercontext, AST_MAX_EXTENSION - 1);
if (trunk) if (trunk)
*trunk = p->trunk; *trunk = p->trunk;
if (capability) if (capability)
@ -2079,6 +2082,7 @@ static int iax2_call(struct ast_channel *c, char *dest, int timeout)
struct iax_ie_data ied; struct iax_ie_data ied;
char myrdest [5] = "s"; char myrdest [5] = "s";
char context[AST_MAX_EXTENSION] =""; char context[AST_MAX_EXTENSION] ="";
char peercontext[AST_MAX_EXTENSION] ="";
char *portno = NULL; char *portno = NULL;
char *opts = ""; char *opts = "";
unsigned short callno = PTR_TO_CALLNO(c->pvt->pvt); unsigned short callno = PTR_TO_CALLNO(c->pvt->pvt);
@ -2125,7 +2129,7 @@ static int iax2_call(struct ast_channel *c, char *dest, int timeout)
strsep(&stringp, ":"); strsep(&stringp, ":");
portno = strsep(&stringp, ":"); portno = strsep(&stringp, ":");
} }
if (create_addr(&sin, NULL, NULL, NULL, hname, context, NULL, NULL, storedsecret, sizeof(storedsecret) - 1, NULL)) { if (create_addr(&sin, NULL, NULL, NULL, hname, context, NULL, NULL, storedsecret, sizeof(storedsecret) - 1, NULL, peercontext)) {
ast_log(LOG_WARNING, "No address associated with '%s'\n", hname); ast_log(LOG_WARNING, "No address associated with '%s'\n", hname);
return -1; return -1;
} }
@ -2168,6 +2172,8 @@ static int iax2_call(struct ast_channel *c, char *dest, int timeout)
iax_ie_append_str(&ied, IAX_IE_DNID, c->dnid); iax_ie_append_str(&ied, IAX_IE_DNID, c->dnid);
if (rcontext) if (rcontext)
iax_ie_append_str(&ied, IAX_IE_CALLED_CONTEXT, rcontext); iax_ie_append_str(&ied, IAX_IE_CALLED_CONTEXT, rcontext);
else if (strlen(peercontext))
iax_ie_append_str(&ied, IAX_IE_CALLED_CONTEXT, peercontext);
if (username) if (username)
iax_ie_append_str(&ied, IAX_IE_USERNAME, username); iax_ie_append_str(&ied, IAX_IE_USERNAME, username);
if (!secret && !ast_strlen_zero(storedsecret)) if (!secret && !ast_strlen_zero(storedsecret))
@ -5785,7 +5791,7 @@ static struct ast_channel *iax2_request(char *type, int format, void *data)
} }
/* Populate our address from the given */ /* Populate our address from the given */
if (create_addr(&sin, &capability, &sendani, &maxtime, hostname, NULL, &trunk, &notransfer, NULL, 0, &found)) { if (create_addr(&sin, &capability, &sendani, &maxtime, hostname, NULL, &trunk, &notransfer, NULL, 0, &found, NULL)) {
return NULL; return NULL;
} }
if (portno) { if (portno) {
@ -6012,6 +6018,9 @@ static struct iax2_peer *build_peer(char *name, struct ast_variable *v)
} else if (!strcasecmp(v->name, "context")) { } else if (!strcasecmp(v->name, "context")) {
if (ast_strlen_zero(peer->context)) if (ast_strlen_zero(peer->context))
strncpy(peer->context, v->value, sizeof(peer->context) - 1); strncpy(peer->context, v->value, sizeof(peer->context) - 1);
} else if (!strcasecmp(v->name, "peercontext")) {
if (ast_strlen_zero(peer->peercontext))
strncpy(peer->peercontext, v->value, sizeof(peer->peercontext) - 1);
} else if (!strcasecmp(v->name, "port")) { } else if (!strcasecmp(v->name, "port")) {
if (peer->dynamic) if (peer->dynamic)
peer->defaddr.sin_port = htons(atoi(v->value)); peer->defaddr.sin_port = htons(atoi(v->value));
@ -6553,7 +6562,7 @@ static int cache_get_callno_locked(char *data)
host = st; host = st;
} }
/* Populate our address from the given */ /* Populate our address from the given */
if (create_addr(&sin, NULL, NULL, NULL, host, NULL, NULL, NULL, NULL, 0, NULL)) { if (create_addr(&sin, NULL, NULL, NULL, host, NULL, NULL, NULL, NULL, 0, NULL, NULL)) {
return -1; return -1;
} }
ast_log(LOG_DEBUG, "host: %s, user: %s, password: %s, context: %s\n", host, username, password, context); ast_log(LOG_DEBUG, "host: %s, user: %s, password: %s, context: %s\n", host, username, password, context);

@ -208,6 +208,7 @@ host=216.207.245.47
;secret=mysecret ;secret=mysecret
;mailbox=1234 ; Notify about mailbox 1234 ;mailbox=1234 ; Notify about mailbox 1234
;inkeys=key1:key2 ;inkeys=key1:key2
;peercontext=local ; Default context to request for calls to peer
;defaultip=216.207.245.34 ;defaultip=216.207.245.34
;callerid="Some Host" <(256) 428-6011> ;callerid="Some Host" <(256) 428-6011>
; ;

@ -323,4 +323,8 @@ If the host uses dynamic registration, Asterisk may still be given a
default IP address to use when dynamic registration has not been performed default IP address to use when dynamic registration has not been performed
or has timed out. or has timed out.
> peercontext = <context>
Specifies the context name to be passed to the peer for it to use when routing
the call through its dial plan. This entry will be used only if a context
is not included in the IAX2 channel name passed to the Dial command.

Loading…
Cancel
Save