static int transmit_response(struct sip_pvt *p, char *msg, struct sip_request *req);
static int transmit_response_with_sdp(struct sip_pvt *p, char *msg, struct sip_request *req, int retrans);
static int transmit_response_with_auth(struct sip_pvt *p, char *msg, struct sip_request *req, char *rand, int reliable);
-static int transmit_request(struct sip_pvt *p, char *msg, int inc, int reliable);
-static int transmit_request_with_auth(struct sip_pvt *p, char *msg, int inc, int reliable);
+static int transmit_request(struct sip_pvt *p, char *msg, int inc, int reliable, int newbranch);
+static int transmit_request_with_auth(struct sip_pvt *p, char *msg, int inc, int reliable, int newbranch);
static int transmit_invite(struct sip_pvt *p, char *msg, int sendsdp, char *auth, char *authheader, char *vxml_url,char *distinctive_ring, int init);
static int transmit_reinvite_with_sdp(struct sip_pvt *p, struct ast_rtp *rtp, struct ast_rtp *vrtp);
static int transmit_info_with_digit(struct sip_pvt *p, char digit);
if (!p->alreadygone && strlen(p->initreq.data)) {
if (needcancel) {
if (p->outgoing) {
- transmit_request_with_auth(p, "CANCEL", p->ocseq, 1);
+ transmit_request_with_auth(p, "CANCEL", p->ocseq, 1, 0);
/* Actually don't destroy us yet, wait for the 487 on our original
INVITE, but do set an autodestruct just in case. */
needdestroy = 0;
} else {
if (!p->pendinginvite) {
/* Send a hangup */
- transmit_request_with_auth(p, "BYE", 0, 1);
+ transmit_request_with_auth(p, "BYE", 0, 1, 1);
} else {
/* Note we will need a BYE when this all settles out
but we can't send one while we have "INVITE" outstanding. */
return 0;
}
-static int reqprep(struct sip_request *req, struct sip_pvt *p, char *msg, int seqno)
+static int reqprep(struct sip_request *req, struct sip_pvt *p, char *msg, int seqno, int newbranch)
{
struct sip_request *orig = &p->initreq;
char stripped[80] ="";
p->ocseq++;
seqno = p->ocseq;
}
+
+ if (newbranch) {
+ p->branch ^= rand();
+ snprintf(p->via, sizeof(p->via), "SIP/2.0/UDP %s:%d;branch=z9hG4bK%08x", inet_ntoa(p->ourip), ourport, p->branch);
+ }
if (strlen(p->uri)) {
c = p->uri;
{
struct sip_request req;
if (p->canreinvite == REINVITE_UPDATE)
- reqprep(&req, p, "UPDATE", 0);
- else {
- p->branch++;
- snprintf(p->via, sizeof(p->via), "SIP/2.0/UDP %s:%d;branch=z9hG4bK%08x", inet_ntoa(p->ourip), ourport, p->branch);
- reqprep(&req, p, "INVITE", 0);
- }
+ reqprep(&req, p, "UPDATE", 0, 1);
+ else
+ reqprep(&req, p, "INVITE", 0, 1);
+
add_header(&req, "Allow", ALLOWED_METHODS);
add_sdp(&req, p, rtp, vrtp);
/* Use this as the basis */
if (init)
initreqprep(&req, p, cmd, vxml_url);
else
- reqprep(&req, p, cmd, 0);
+ reqprep(&req, p, cmd, 0, 1);
if (auth)
add_header(&req, authheader, auth);
}
mfrom = c;
- reqprep(&req, p, "NOTIFY", 0);
+ reqprep(&req, p, "NOTIFY", 0, 1);
if (p->subscribed == 1) {
strncpy(to, get_header(&p->initreq, "To"), sizeof(to)-1);
static int transmit_message_with_text(struct sip_pvt *p, char *text)
{
struct sip_request req;
- reqprep(&req, p, "MESSAGE", 0);
+ reqprep(&req, p, "MESSAGE", 0, 1);
add_text(&req, text);
return send_request(p, &req, 1, p->ocseq);
}
strncpy(p->refer_to, referto, sizeof(p->refer_to) - 1);
strncpy(p->referred_by, p->our_contact, sizeof(p->referred_by) - 1);
- reqprep(&req, p, "REFER", 0);
+ reqprep(&req, p, "REFER", 0, 1);
add_header(&req, "Refer-To", referto);
if (strlen(p->our_contact))
add_header(&req, "Referred-By", p->our_contact);
static int transmit_info_with_digit(struct sip_pvt *p, char digit)
{
struct sip_request req;
- reqprep(&req, p, "INFO", 0);
+ reqprep(&req, p, "INFO", 0, 1);
add_digit(&req, digit);
return send_request(p, &req, 1, p->ocseq);
}
-static int transmit_request(struct sip_pvt *p, char *msg, int seqno, int reliable)
+static int transmit_request(struct sip_pvt *p, char *msg, int seqno, int reliable, int newbranch)
{
struct sip_request resp;
- reqprep(&resp, p, msg, seqno);
+ reqprep(&resp, p, msg, seqno, newbranch);
add_header(&resp, "Content-Length", "0");
add_blank_header(&resp);
return send_request(p, &resp, reliable, seqno ? seqno : p->ocseq);
}
-static int transmit_request_with_auth(struct sip_pvt *p, char *msg, int seqno, int reliable)
+static int transmit_request_with_auth(struct sip_pvt *p, char *msg, int seqno, int reliable, int newbranch)
{
struct sip_request resp;
- reqprep(&resp, p, msg, seqno);
+ reqprep(&resp, p, msg, seqno, newbranch);
if (*p->realm)
{
char digest[256];
if (peer->pokeexpire > -1)
ast_sched_del(sched, peer->pokeexpire);
if (!strcasecmp(msg, "INVITE"))
- transmit_request(p, "ACK", seqno, 0);
+ transmit_request(p, "ACK", seqno, 0, 0);
p->needdestroy = 1;
/* Try again eventually */
if ((peer->lastms < 0) || (peer->lastms > peer->maxms))
}
}
p->authtries = 0;
- transmit_request(p, "ACK", seqno, 0);
+ /* If I understand this right, the branch is different for a non-200 ACK only */
+ transmit_request(p, "ACK", seqno, 0, 1);
/* Go ahead and send bye at this point */
if (p->pendingbye) {
- transmit_request_with_auth(p, "BYE", 0, 1);
+ transmit_request_with_auth(p, "BYE", 0, 1, 1);
p->needdestroy = 1;
}
} else if (!strcasecmp(msg, "REGISTER")) {
case 401: /* Not authorized on REGISTER */
if (!strcasecmp(msg, "INVITE")) {
/* First we ACK */
- transmit_request(p, "ACK", seqno, 0);
+ transmit_request(p, "ACK", seqno, 0, 0);
/* Then we AUTH */
if ((p->authtries > 1) || do_proxy_auth(p, req, "WWW-Authenticate", "Authorization", "INVITE", 1)) {
ast_log(LOG_NOTICE, "Failed to authenticate on INVITE to '%s'\n", get_header(&p->initreq, "From"));
case 407:
if (!strcasecmp(msg, "INVITE")) {
/* First we ACK */
- transmit_request(p, "ACK", seqno, 0);
+ transmit_request(p, "ACK", seqno, 0, 0);
/* Then we AUTH */
/* But only if the packet wasn't marked as ignore in handle_request */
if(!ignore){
}
/* ACK on invite */
if (!strcasecmp(msg, "INVITE"))
- transmit_request(p, "ACK", seqno, 0);
+ transmit_request(p, "ACK", seqno, 0, 0);
p->alreadygone = 1;
if (!p->owner)
p->needdestroy = 1;
ast_verbose("Message is %s\n", msg);
switch(resp) {
case 200:
+ /* Change branch since this is a 200 response */
if (!strcasecmp(msg, "INVITE") || !strcasecmp(msg, "REGISTER") )
- transmit_request(p, "ACK", seqno, 0);
+ transmit_request(p, "ACK", seqno, 0, 1);
break;
case 407:
if (!strcasecmp(msg, "BYE") || !strcasecmp(msg, "REFER")) {
p->gotrefer = 1;
}
/* Always increment on a BYE */
- transmit_request_with_auth(p, "BYE", 0, 1);
+ transmit_request_with_auth(p, "BYE", 0, 1, 1);
p->alreadygone = 1;
}
} else if (!strcasecmp(cmd, "CANCEL")) {