Clean up handle_response_invite

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@20844 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.4
Olle Johansson 20 years ago
parent 92ac73fe3b
commit a5e5fb18e2

@ -1078,6 +1078,7 @@ static int handle_request_message(struct sip_pvt *p, struct sip_request *req);
static int handle_request_subscribe(struct sip_pvt *p, struct sip_request *req, struct sockaddr_in *sin, int seqno, char *e); static int handle_request_subscribe(struct sip_pvt *p, struct sip_request *req, struct sockaddr_in *sin, int seqno, char *e);
static void handle_request_info(struct sip_pvt *p, struct sip_request *req); static void handle_request_info(struct sip_pvt *p, struct sip_request *req);
static int handle_request_options(struct sip_pvt *p, struct sip_request *req); static int handle_request_options(struct sip_pvt *p, struct sip_request *req);
static void handle_response_invite(struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int seqno);
/*----- RTP interface functions */ /*----- RTP interface functions */
static int sip_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, struct ast_rtp *vrtp, int codecs, int nat_active); static int sip_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, struct ast_rtp *vrtp, int codecs, int nat_active);
@ -9728,7 +9729,7 @@ static void check_pendings(struct sip_pvt *p)
} }
/*! \brief Handle SIP response in dialogue */ /*! \brief Handle SIP response in dialogue */
static void handle_response_invite(struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int ignore, int seqno) static void handle_response_invite(struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int seqno)
{ {
int outgoing = ast_test_flag(&p->flags[0], SIP_OUTGOING); int outgoing = ast_test_flag(&p->flags[0], SIP_OUTGOING);
@ -9747,39 +9748,39 @@ static void handle_response_invite(struct sip_pvt *p, int resp, char *rest, stru
switch (resp) { switch (resp) {
case 100: /* Trying */ case 100: /* Trying */
if (!ignore) if (!ast_test_flag(req, SIP_PKT_IGNORE))
sip_cancel_destroy(p); sip_cancel_destroy(p);
break; break;
case 180: /* 180 Ringing */ case 180: /* 180 Ringing */
if (!ignore) if (!ast_test_flag(req, SIP_PKT_IGNORE))
sip_cancel_destroy(p); sip_cancel_destroy(p);
if (!ignore && p->owner) { if (!ast_test_flag(req, SIP_PKT_IGNORE) && p->owner) {
ast_queue_control(p->owner, AST_CONTROL_RINGING); ast_queue_control(p->owner, AST_CONTROL_RINGING);
if (p->owner->_state != AST_STATE_UP) if (p->owner->_state != AST_STATE_UP)
ast_setstate(p->owner, AST_STATE_RINGING); ast_setstate(p->owner, AST_STATE_RINGING);
} }
if (!strcasecmp(get_header(req, "Content-Type"), "application/sdp")) { if (!strcasecmp(get_header(req, "Content-Type"), "application/sdp")) {
process_sdp(p, req); process_sdp(p, req);
if (!ignore && p->owner) { if (!ast_test_flag(req, SIP_PKT_IGNORE) && p->owner) {
/* Queue a progress frame only if we have SDP in 180 */ /* Queue a progress frame only if we have SDP in 180 */
ast_queue_control(p->owner, AST_CONTROL_PROGRESS); ast_queue_control(p->owner, AST_CONTROL_PROGRESS);
} }
} }
break; break;
case 183: /* Session progress */ case 183: /* Session progress */
if (!ignore) if (!ast_test_flag(req, SIP_PKT_IGNORE))
sip_cancel_destroy(p); sip_cancel_destroy(p);
/* Ignore 183 Session progress without SDP */ /* Ignore 183 Session progress without SDP */
if (!strcasecmp(get_header(req, "Content-Type"), "application/sdp")) { if (!strcasecmp(get_header(req, "Content-Type"), "application/sdp")) {
process_sdp(p, req); process_sdp(p, req);
if (!ignore && p->owner) { if (!ast_test_flag(req, SIP_PKT_IGNORE) && p->owner) {
/* Queue a progress frame */ /* Queue a progress frame */
ast_queue_control(p->owner, AST_CONTROL_PROGRESS); ast_queue_control(p->owner, AST_CONTROL_PROGRESS);
} }
} }
break; break;
case 200: /* 200 OK on invite - someone's answering our call */ case 200: /* 200 OK on invite - someone's answering our call */
if (!ignore) if (!ast_test_flag(req, SIP_PKT_IGNORE))
sip_cancel_destroy(p); sip_cancel_destroy(p);
p->authtries = 0; p->authtries = 0;
if (!strcasecmp(get_header(req, "Content-Type"), "application/sdp")) if (!strcasecmp(get_header(req, "Content-Type"), "application/sdp"))
@ -9798,7 +9799,7 @@ static void handle_response_invite(struct sip_pvt *p, int resp, char *rest, stru
should we care about resolving the contact should we care about resolving the contact
or should we just send it? or should we just send it?
*/ */
if (!ignore) if (!ast_test_flag(req, SIP_PKT_IGNORE))
ast_set_flag(&p->flags[0], SIP_PENDINGBYE); ast_set_flag(&p->flags[0], SIP_PENDINGBYE);
} }
@ -9806,7 +9807,7 @@ static void handle_response_invite(struct sip_pvt *p, int resp, char *rest, stru
build_route(p, req, 1); build_route(p, req, 1);
} }
if (!ignore && p->owner) { if (!ast_test_flag(req, SIP_PKT_IGNORE) && p->owner) {
if (p->owner->_state != AST_STATE_UP) { if (p->owner->_state != AST_STATE_UP) {
ast_queue_control(p->owner, AST_CONTROL_ANSWER); ast_queue_control(p->owner, AST_CONTROL_ANSWER);
} else { /* RE-invite */ } else { /* RE-invite */
@ -9816,7 +9817,7 @@ static void handle_response_invite(struct sip_pvt *p, int resp, char *rest, stru
/* It's possible we're getting an 200 OK after we've tried to disconnect /* It's possible we're getting an 200 OK after we've tried to disconnect
by sending CANCEL */ by sending CANCEL */
/* First send ACK, then send bye */ /* First send ACK, then send bye */
if (!ignore) if (!ast_test_flag(req, SIP_PKT_IGNORE))
ast_set_flag(&p->flags[0], SIP_PENDINGBYE); ast_set_flag(&p->flags[0], SIP_PENDINGBYE);
} }
/* If I understand this right, the branch is different for a non-200 ACK only */ /* If I understand this right, the branch is different for a non-200 ACK only */
@ -9832,7 +9833,7 @@ static void handle_response_invite(struct sip_pvt *p, int resp, char *rest, stru
/* Then we AUTH */ /* Then we AUTH */
ast_string_field_free(p, theirtag); /* forget their old tag, so we don't match tags when getting response */ ast_string_field_free(p, theirtag); /* forget their old tag, so we don't match tags when getting response */
if (!ignore) { if (!ast_test_flag(req, SIP_PKT_IGNORE)) {
char *authenticate = (resp == 401 ? "WWW-Authenticate" : "Proxy-Authenticate"); char *authenticate = (resp == 401 ? "WWW-Authenticate" : "Proxy-Authenticate");
char *authorization = (resp == 401 ? "Authorization" : "Proxy-Authorization"); char *authorization = (resp == 401 ? "Authorization" : "Proxy-Authorization");
if ((p->authtries == MAX_AUTHTRIES) || do_proxy_auth(p, req, authenticate, authorization, SIP_INVITE, 1)) { if ((p->authtries == MAX_AUTHTRIES) || do_proxy_auth(p, req, authenticate, authorization, SIP_INVITE, 1)) {
@ -9848,14 +9849,14 @@ static void handle_response_invite(struct sip_pvt *p, int resp, char *rest, stru
/* First we ACK */ /* First we ACK */
transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, 0); transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, 0);
ast_log(LOG_WARNING, "Received response: \"Forbidden\" from '%s'\n", get_header(&p->initreq, "From")); ast_log(LOG_WARNING, "Received response: \"Forbidden\" from '%s'\n", get_header(&p->initreq, "From"));
if (!ignore && p->owner) if (!ast_test_flag(req, SIP_PKT_IGNORE) && p->owner)
ast_queue_control(p->owner, AST_CONTROL_CONGESTION); ast_queue_control(p->owner, AST_CONTROL_CONGESTION);
ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
ast_set_flag(&p->flags[0], SIP_ALREADYGONE); ast_set_flag(&p->flags[0], SIP_ALREADYGONE);
break; break;
case 404: /* Not found */ case 404: /* Not found */
transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, 0); transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, 0);
if (p->owner && !ignore) if (p->owner && !ast_test_flag(req, SIP_PKT_IGNORE))
ast_queue_control(p->owner, AST_CONTROL_CONGESTION); ast_queue_control(p->owner, AST_CONTROL_CONGESTION);
ast_set_flag(&p->flags[0], SIP_ALREADYGONE); ast_set_flag(&p->flags[0], SIP_ALREADYGONE);
break; break;
@ -10151,15 +10152,15 @@ static void handle_response(struct sip_pvt *p, int resp, char *rest, struct sip_
switch(resp) { switch(resp) {
case 100: /* 100 Trying */ case 100: /* 100 Trying */
if (sipmethod == SIP_INVITE) if (sipmethod == SIP_INVITE)
handle_response_invite(p, resp, rest, req, ignore, seqno); handle_response_invite(p, resp, rest, req, seqno);
break; break;
case 183: /* 183 Session Progress */ case 183: /* 183 Session Progress */
if (sipmethod == SIP_INVITE) if (sipmethod == SIP_INVITE)
handle_response_invite(p, resp, rest, req, ignore, seqno); handle_response_invite(p, resp, rest, req, seqno);
break; break;
case 180: /* 180 Ringing */ case 180: /* 180 Ringing */
if (sipmethod == SIP_INVITE) if (sipmethod == SIP_INVITE)
handle_response_invite(p, resp, rest, req, ignore, seqno); handle_response_invite(p, resp, rest, req, seqno);
break; break;
case 200: /* 200 OK */ case 200: /* 200 OK */
p->authtries = 0; /* Reset authentication counter */ p->authtries = 0; /* Reset authentication counter */
@ -10177,7 +10178,7 @@ static void handle_response(struct sip_pvt *p, int resp, char *rest, struct sip_
} }
} }
} else if (sipmethod == SIP_INVITE) } else if (sipmethod == SIP_INVITE)
handle_response_invite(p, resp, rest, req, ignore, seqno); handle_response_invite(p, resp, rest, req, seqno);
else if (sipmethod == SIP_REGISTER) else if (sipmethod == SIP_REGISTER)
res = handle_response_register(p, resp, rest, req, ignore, seqno); res = handle_response_register(p, resp, rest, req, ignore, seqno);
break; break;
@ -10187,7 +10188,7 @@ static void handle_response(struct sip_pvt *p, int resp, char *rest, struct sip_
break; break;
case 401: /* Not www-authorized on SIP method */ case 401: /* Not www-authorized on SIP method */
if (sipmethod == SIP_INVITE) if (sipmethod == SIP_INVITE)
handle_response_invite(p, resp, rest, req, ignore, seqno); handle_response_invite(p, resp, rest, req, seqno);
else if (sipmethod == SIP_REFER) else if (sipmethod == SIP_REFER)
handle_response_refer(p, resp, rest, req, ignore, seqno); handle_response_refer(p, resp, rest, req, ignore, seqno);
else if (p->registry && sipmethod == SIP_REGISTER) else if (p->registry && sipmethod == SIP_REGISTER)
@ -10199,7 +10200,7 @@ static void handle_response(struct sip_pvt *p, int resp, char *rest, struct sip_
break; break;
case 403: /* Forbidden - we failed authentication */ case 403: /* Forbidden - we failed authentication */
if (sipmethod == SIP_INVITE) if (sipmethod == SIP_INVITE)
handle_response_invite(p, resp, rest, req, ignore, seqno); handle_response_invite(p, resp, rest, req, seqno);
else if (p->registry && sipmethod == SIP_REGISTER) else if (p->registry && sipmethod == SIP_REGISTER)
res = handle_response_register(p, resp, rest, req, ignore, seqno); res = handle_response_register(p, resp, rest, req, ignore, seqno);
else { else {
@ -10211,13 +10212,13 @@ static void handle_response(struct sip_pvt *p, int resp, char *rest, struct sip_
if (p->registry && sipmethod == SIP_REGISTER) if (p->registry && sipmethod == SIP_REGISTER)
res = handle_response_register(p, resp, rest, req, ignore, seqno); res = handle_response_register(p, resp, rest, req, ignore, seqno);
else if (sipmethod == SIP_INVITE) else if (sipmethod == SIP_INVITE)
handle_response_invite(p, resp, rest, req, ignore, seqno); handle_response_invite(p, resp, rest, req, seqno);
else if (owner) else if (owner)
ast_queue_control(p->owner, AST_CONTROL_CONGESTION); ast_queue_control(p->owner, AST_CONTROL_CONGESTION);
break; break;
case 407: /* Proxy auth required */ case 407: /* Proxy auth required */
if (sipmethod == SIP_INVITE) if (sipmethod == SIP_INVITE)
handle_response_invite(p, resp, rest, req, ignore, seqno); handle_response_invite(p, resp, rest, req, seqno);
else if (sipmethod == SIP_REFER) else if (sipmethod == SIP_REFER)
handle_response_refer(p, resp, rest, req, ignore, seqno); handle_response_refer(p, resp, rest, req, ignore, seqno);
else if (p->registry && sipmethod == SIP_REGISTER) else if (p->registry && sipmethod == SIP_REGISTER)
@ -10237,7 +10238,7 @@ static void handle_response(struct sip_pvt *p, int resp, char *rest, struct sip_
break; break;
case 491: /* Pending */ case 491: /* Pending */
if (sipmethod == SIP_INVITE) if (sipmethod == SIP_INVITE)
handle_response_invite(p, resp, rest, req, ignore, seqno); handle_response_invite(p, resp, rest, req, seqno);
else { else {
ast_log(LOG_DEBUG, "Got 491 on %s, unspported. Call ID %s\n", sip_methods[sipmethod].text, p->callid); ast_log(LOG_DEBUG, "Got 491 on %s, unspported. Call ID %s\n", sip_methods[sipmethod].text, p->callid);
ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
@ -10245,7 +10246,7 @@ static void handle_response(struct sip_pvt *p, int resp, char *rest, struct sip_
break; break;
case 501: /* Not Implemented */ case 501: /* Not Implemented */
if (sipmethod == SIP_INVITE) if (sipmethod == SIP_INVITE)
handle_response_invite(p, resp, rest, req, ignore, seqno); handle_response_invite(p, resp, rest, req, seqno);
else if (sipmethod == SIP_REFER) else if (sipmethod == SIP_REFER)
handle_response_refer(p, resp, rest, req, ignore, seqno); handle_response_refer(p, resp, rest, req, ignore, seqno);
else else
@ -10358,7 +10359,7 @@ static void handle_response(struct sip_pvt *p, int resp, char *rest, struct sip_
switch(resp) { switch(resp) {
case 200: case 200:
if (sipmethod == SIP_INVITE) { if (sipmethod == SIP_INVITE) {
handle_response_invite(p, resp, rest, req, ignore, seqno); handle_response_invite(p, resp, rest, req, seqno);
} else if (sipmethod == SIP_CANCEL) { } else if (sipmethod == SIP_CANCEL) {
ast_log(LOG_DEBUG, "Got 200 OK on CANCEL\n"); ast_log(LOG_DEBUG, "Got 200 OK on CANCEL\n");
/* Wait for 487, then destroy */ /* Wait for 487, then destroy */
@ -10375,7 +10376,7 @@ static void handle_response(struct sip_pvt *p, int resp, char *rest, struct sip_
if (sipmethod == SIP_REFER) if (sipmethod == SIP_REFER)
handle_response_refer(p, resp, rest, req, ignore, seqno); handle_response_refer(p, resp, rest, req, ignore, seqno);
else if (sipmethod == SIP_INVITE) else if (sipmethod == SIP_INVITE)
handle_response_invite(p, resp, rest, req, ignore, seqno); handle_response_invite(p, resp, rest, req, seqno);
else if (sipmethod == SIP_BYE) { else if (sipmethod == SIP_BYE) {
char *auth, *auth2; char *auth, *auth2;
@ -10390,12 +10391,12 @@ static void handle_response(struct sip_pvt *p, int resp, char *rest, struct sip_
case 481: /* Call leg does not exist */ case 481: /* Call leg does not exist */
if (sipmethod == SIP_INVITE) { if (sipmethod == SIP_INVITE) {
/* Re-invite failed */ /* Re-invite failed */
handle_response_invite(p, resp, rest, req, ignore, seqno); handle_response_invite(p, resp, rest, req, seqno);
} }
break; break;
case 501: /* Not Implemented */ case 501: /* Not Implemented */
if (sipmethod == SIP_INVITE) if (sipmethod == SIP_INVITE)
handle_response_invite(p, resp, rest, req, ignore, seqno); handle_response_invite(p, resp, rest, req, seqno);
else if (sipmethod == SIP_REFER) else if (sipmethod == SIP_REFER)
handle_response_refer(p, resp, rest, req, ignore, seqno); handle_response_refer(p, resp, rest, req, ignore, seqno);
break; break;

Loading…
Cancel
Save