[Asterisk-cvs] asterisk/channels chan_sip.c,1.867,1.868
kpfleming
kpfleming
Mon Sep 26 22:15:46 CDT 2005
Update of /usr/cvsroot/asterisk/channels
In directory mongoose.digium.com:/tmp/cvs-serv24613/channels
Modified Files:
chan_sip.c
Log Message:
store tag in the private structure as formatted text, instead of formatting every time we send a packet
Index: chan_sip.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_sip.c,v
retrieving revision 1.867
retrieving revision 1.868
diff -u -d -r1.867 -r1.868
--- chan_sip.c 27 Sep 2005 01:54:17 -0000 1.867
+++ chan_sip.c 27 Sep 2005 02:12:36 -0000 1.868
@@ -581,7 +581,7 @@
int authtries; /* Times we've tried to authenticate */
int expiry; /* How long we take to expire */
int branch; /* One random number */
- int tag; /* Another random number */
+ char tag[11]; /* Another random number */
int sessionid; /* SDP Session ID */
int sessionversion; /* SDP Session Version */
struct sockaddr_in sa; /* Our peer */
@@ -2949,6 +2949,11 @@
snprintf(callid, len, "@%s", ast_inet_ntoa(iabuf, sizeof(iabuf), ourip));
}
+static void make_our_tag(char *tagbuf, size_t len)
+{
+ snprintf(tagbuf, len, "as%08x", rand());
+}
+
/*--- sip_alloc: Allocate SIP_PVT structure and set defaults ---*/
static struct sip_pvt *sip_alloc(char *callid, struct sockaddr_in *sin, int useglobal_nat, const int intended_method)
{
@@ -2981,7 +2986,7 @@
}
p->branch = rand();
- p->tag = rand();
+ make_our_tag(p->tag, sizeof(p->tag));
/* Start with 101 instead of 1 */
p->ocseq = 101;
@@ -3893,7 +3898,7 @@
if (!ast_strlen_zero(p->theirtag) && ast_test_flag(p, SIP_OUTGOING))
snprintf(newto, sizeof(newto), "%s;tag=%s", ot, p->theirtag);
else if (p->tag && !ast_test_flag(p, SIP_OUTGOING))
- snprintf(newto, sizeof(newto), "%s;tag=as%08x", ot, p->tag);
+ snprintf(newto, sizeof(newto), "%s;tag=%s", ot, p->tag);
else {
ast_copy_string(newto, ot, sizeof(newto));
newto[sizeof(newto) - 1] = '\0';
@@ -4003,7 +4008,7 @@
if (ast_test_flag(p, SIP_OUTGOING) && !ast_strlen_zero(p->theirtag))
snprintf(newto, sizeof(newto), "%s;tag=%s", ot, p->theirtag);
else if (!ast_test_flag(p, SIP_OUTGOING))
- snprintf(newto, sizeof(newto), "%s;tag=as%08x", ot, p->tag);
+ snprintf(newto, sizeof(newto), "%s;tag=%s", ot, p->tag);
else
snprintf(newto, sizeof(newto), "%s", ot);
ot = newto;
@@ -4571,7 +4576,7 @@
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), ";privacy=%s;screen=%s", privacy, screen);
p->rpid = strdup(buf);
- snprintf(buf, sizeof(buf), "\"%s\" <sip:%s@%s>;tag=as%08x", clin,
+ snprintf(buf, sizeof(buf), "\"%s\" <sip:%s@%s>;tag=%s", clin,
ast_strlen_zero(p->fromuser) ? clid : p->fromuser,
fromdomain, p->tag);
p->rpid_from = strdup(buf);
@@ -4652,9 +4657,9 @@
}
if ((ourport != 5060) && ast_strlen_zero(p->fromdomain)) /* Needs to be 5060 */
- snprintf(from, sizeof(from), "\"%s\" <sip:%s@%s:%d>;tag=as%08x", n, l, ast_strlen_zero(p->fromdomain) ? ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip) : p->fromdomain, ourport, p->tag);
+ snprintf(from, sizeof(from), "\"%s\" <sip:%s@%s:%d>;tag=%s", n, l, ast_strlen_zero(p->fromdomain) ? ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip) : p->fromdomain, ourport, p->tag);
else
- snprintf(from, sizeof(from), "\"%s\" <sip:%s@%s>;tag=as%08x", n, l, ast_strlen_zero(p->fromdomain) ? ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip) : p->fromdomain, p->tag);
+ snprintf(from, sizeof(from), "\"%s\" <sip:%s@%s>;tag=%s", n, l, ast_strlen_zero(p->fromdomain) ? ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip) : p->fromdomain, p->tag);
/* If we're calling a registered SIP peer, use the fullcontact to dial to the peer */
if (!ast_strlen_zero(p->fullcontact)) {
@@ -5189,7 +5194,7 @@
return 0;
} else {
p = r->call;
- p->tag = rand(); /* create a new local tag for every register attempt */
+ make_our_tag(p->tag, sizeof(p->tag)); /* create a new local tag for every register attempt */
p->theirtag[0]='\0'; /* forget their old tag, so we don't match tags when getting response */
}
} else {
@@ -5274,13 +5279,13 @@
}
if (strchr(r->username, '@')) {
- snprintf(from, sizeof(from), "<sip:%s>;tag=as%08x", r->username, p->tag);
+ snprintf(from, sizeof(from), "<sip:%s>;tag=%s", r->username, p->tag);
if (!ast_strlen_zero(p->theirtag))
snprintf(to, sizeof(to), "<sip:%s>;tag=%s", r->username, p->theirtag);
else
snprintf(to, sizeof(to), "<sip:%s>", r->username);
} else {
- snprintf(from, sizeof(from), "<sip:%s@%s>;tag=as%08x", r->username, p->tohost, p->tag);
+ snprintf(from, sizeof(from), "<sip:%s@%s>;tag=%s", r->username, p->tohost, p->tag);
if (!ast_strlen_zero(p->theirtag))
snprintf(to, sizeof(to), "<sip:%s@%s>;tag=%s", r->username, p->tohost, p->theirtag);
else
@@ -8321,7 +8326,7 @@
ast_cli(fd, " Received Address: %s:%d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), cur->recv.sin_addr), ntohs(cur->recv.sin_port));
ast_cli(fd, " NAT Support: %s\n", nat2str(ast_test_flag(cur, SIP_NAT)));
ast_cli(fd, " Audio IP: %s %s\n", ast_inet_ntoa(iabuf, sizeof(iabuf), cur->redirip.sin_addr.s_addr ? cur->redirip.sin_addr : cur->ourip), cur->redirip.sin_addr.s_addr ? "(Outside bridge)" : "(local)" );
- ast_cli(fd, " Our Tag: as%08x\n", cur->tag);
+ ast_cli(fd, " Our Tag: %s\n", cur->tag);
ast_cli(fd, " Their Tag: %s\n", cur->theirtag);
ast_cli(fd, " SIP User agent: %s\n", cur->useragent);
if (!ast_strlen_zero(cur->username))
@@ -10181,7 +10186,7 @@
if (ast_strlen_zero(p->exten))
ast_copy_string(p->exten, "s", sizeof(p->exten));
/* Initialize tag */
- p->tag = rand();
+ make_our_tag(p->tag, sizeof(p->tag));
/* First invitation */
c = sip_new(p, AST_STATE_DOWN, ast_strlen_zero(p->username) ? NULL : p->username );
*recount = 1;
@@ -10500,8 +10505,8 @@
char *accept = get_header(req, "Accept");
/* Initialize tag for new subscriptions */
- if (!p->tag)
- p->tag = rand();
+ if (ast_strlen_zero(p->tag))
+ make_our_tag(p->tag, sizeof(p->tag));
if (!strcmp(event, "presence") || !strcmp(event, "dialog")) { /* Presence, RFC 3842 */
More information about the svn-commits
mailing list