[svn-commits] rizzo: branch rizzo/astobj2 r47547 - /team/rizzo/astobj2/channels/chan_sip.c

svn-commits at lists.digium.com svn-commits at lists.digium.com
Mon Nov 13 10:04:04 MST 2006


Author: rizzo
Date: Mon Nov 13 11:04:03 2006
New Revision: 47547

URL: http://svn.digium.com/view/asterisk?view=rev&rev=47547
Log:
wrap checks of SIP_PKT_IGNORE with a function req_ignore()
so we can hide the underlying implementation (and shorten code).

Modified:
    team/rizzo/astobj2/channels/chan_sip.c

Modified: team/rizzo/astobj2/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/astobj2/channels/chan_sip.c?view=diff&rev=47547&r1=47546&r2=47547
==============================================================================
--- team/rizzo/astobj2/channels/chan_sip.c (original)
+++ team/rizzo/astobj2/channels/chan_sip.c Mon Nov 13 11:04:03 2006
@@ -605,6 +605,12 @@
 	char *line[SIP_MAX_LINES];
 	char data[SIP_MAX_PACKET];
 };
+
+/*! \brief test the IGNORE flags in a sip_request */
+static inline int req_ignore(struct sip_request *req)
+{
+	return ast_test_flag(req, SIP_PKT_IGNORE);
+}
 
 /*
  * A sip packet is stored into the data[] buffer, with the header followed
@@ -8416,7 +8422,7 @@
 		} else {
 			ast_copy_flags(&p->flags[0], &peer->flags[0], SIP_NAT);
 			transmit_response(p, "100 Trying", req);
-			if (!(res = check_auth(p, req, peer->name, peer->secret, peer->md5secret, SIP_REGISTER, uri, XMIT_UNRELIABLE, ast_test_flag(req, SIP_PKT_IGNORE)))) {
+			if (!(res = check_auth(p, req, peer->name, peer->secret, peer->md5secret, SIP_REGISTER, uri, XMIT_UNRELIABLE, req_ignore(req)))) {
 				sip_cancel_destroy(p);
 
 				/* We have a succesful registration attemp with proper authentication,
@@ -9203,7 +9209,7 @@
 	replace_cid(p, rpid_num, calleridname);
 	do_setnat(p, ast_test_flag(&p->flags[0], SIP_NAT_ROUTE) );
 
-	if (!(res = check_auth(p, req, user->name, user->secret, user->md5secret, sipmethod, uri2, reliable, ast_test_flag(req, SIP_PKT_IGNORE)))) {
+	if (!(res = check_auth(p, req, user->name, user->secret, user->md5secret, sipmethod, uri2, reliable, req_ignore(req)))) {
 		sip_cancel_destroy(p);
 		ast_copy_flags(&p->flags[0], &user->flags[0], SIP_FLAGS_TO_COPY);
 		ast_copy_flags(&p->flags[1], &user->flags[1], SIP_PAGE2_FLAGS_TO_COPY);
@@ -9328,7 +9334,7 @@
 		ast_string_field_free(p, peersecret);
 		ast_string_field_free(p, peermd5secret);
 	}
-	if (!(res = check_auth(p, req, peer->name, p->peersecret, p->peermd5secret, sipmethod, uri2, reliable, ast_test_flag(req, SIP_PKT_IGNORE)))) {
+	if (!(res = check_auth(p, req, peer->name, p->peersecret, p->peermd5secret, sipmethod, uri2, reliable, req_ignore(req)))) {
 		ast_copy_flags(&p->flags[0], &peer->flags[0], SIP_FLAGS_TO_COPY);
 		ast_copy_flags(&p->flags[1], &peer->flags[1], SIP_PAGE2_FLAGS_TO_COPY);
 		/* If we have a call limit, set flag */
@@ -11952,15 +11958,15 @@
 
 	switch (resp) {
 	case 100:	/* Trying */
-		if (!ast_test_flag(req, SIP_PKT_IGNORE))
+		if (!req_ignore(req))
 			sip_cancel_destroy(p);
 		check_pendings(p);
 		break;
 
 	case 180:	/* 180 Ringing */
-		if (!ast_test_flag(req, SIP_PKT_IGNORE))
+		if (!req_ignore(req))
 			sip_cancel_destroy(p);
-		if (!ast_test_flag(req, SIP_PKT_IGNORE) && p->owner) {
+		if (!req_ignore(req) && p->owner) {
 			ast_queue_control(p->owner, AST_CONTROL_RINGING);
 			if (p->owner->_state != AST_STATE_UP) {
 				ast_setstate(p->owner, AST_STATE_RINGING);
@@ -11968,7 +11974,7 @@
 		}
 		if (find_sdp(req)) {
 			res = process_sdp(p, req);
-			if (!ast_test_flag(req, SIP_PKT_IGNORE) && p->owner) {
+			if (!req_ignore(req) && p->owner) {
 				/* Queue a progress frame only if we have SDP in 180 */
 				ast_queue_control(p->owner, AST_CONTROL_PROGRESS);
 			}
@@ -11978,12 +11984,12 @@
 		break;
 
 	case 183:	/* Session progress */
-		if (!ast_test_flag(req, SIP_PKT_IGNORE))
+		if (!req_ignore(req))
 			sip_cancel_destroy(p);
 		/* Ignore 183 Session progress without SDP */
 		if (find_sdp(req)) {
 			res = process_sdp(p, req);
-			if (!ast_test_flag(req, SIP_PKT_IGNORE) && p->owner) {
+			if (!req_ignore(req) && p->owner) {
 				/* Queue a progress frame */
 				ast_queue_control(p->owner, AST_CONTROL_PROGRESS);
 			}
@@ -11993,11 +11999,11 @@
 		break;
 
 	case 200:	/* 200 OK on invite - someone's answering our call */
-		if (!ast_test_flag(req, SIP_PKT_IGNORE))
+		if (!req_ignore(req))
 			sip_cancel_destroy(p);
 		p->authtries = 0;
 		if (find_sdp(req)) {
-			if ((res = process_sdp(p, req)) && !ast_test_flag(req, SIP_PKT_IGNORE))
+			if ((res = process_sdp(p, req)) && !req_ignore(req))
 				if (!reinvite)
 					/* This 200 OK's SDP is not acceptable, so we need to ack, then hangup */
 					/* For re-invites, we try to recover */
@@ -12018,7 +12024,7 @@
 					should we care about resolving the contact
 					or should we just send it?
 				*/
-				if (!ast_test_flag(req, SIP_PKT_IGNORE))
+				if (!req_ignore(req))
 					ast_set_flag(&p->flags[0], SIP_PENDINGBYE);	
 			} 
 
@@ -12072,7 +12078,7 @@
 				ast_log(LOG_DEBUG, "T38 changed state to %d on channel %s\n", p->t38.state, p->owner ? p->owner->name : "<none>");
 		}
 
-		if (!ast_test_flag(req, SIP_PKT_IGNORE) && p->owner) {
+		if (!req_ignore(req) && p->owner) {
 			if (!reinvite) {
 				ast_queue_control(p->owner, AST_CONTROL_ANSWER);
 			} else {	/* RE-invite */
@@ -12082,7 +12088,7 @@
 			 /* It's possible we're getting an 200 OK after we've tried to disconnect
 				  by sending CANCEL */
 			/* First send ACK, then send bye */
-			if (!ast_test_flag(req, SIP_PKT_IGNORE))
+			if (!req_ignore(req))
 				ast_set_flag(&p->flags[0], SIP_PENDINGBYE);	
 		}
 		/* If I understand this right, the branch is different for a non-200 ACK only */
@@ -12100,7 +12106,7 @@
 
 		/* Then we AUTH */
 		ast_string_field_free(p, theirtag);	/* forget their old tag, so we don't match tags when getting response */
-		if (!ast_test_flag(req, SIP_PKT_IGNORE)) {
+		if (!req_ignore(req)) {
 			if (p->authtries == MAX_AUTHTRIES || do_proxy_auth(p, req, resp, SIP_INVITE, 1)) {
 				ast_log(LOG_NOTICE, "Failed to authenticate on INVITE to '%s'\n", get_header(&p->initreq, "From"));
 				ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);	
@@ -12115,7 +12121,7 @@
 		/* First we ACK */
 		transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, FALSE);
 		ast_log(LOG_WARNING, "Received response: \"Forbidden\" from '%s'\n", get_header(&p->initreq, "From"));
-		if (!ast_test_flag(req, SIP_PKT_IGNORE) && p->owner)
+		if (!req_ignore(req) && p->owner)
 			ast_queue_control(p->owner, AST_CONTROL_CONGESTION);
 		ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);	
 		ast_set_flag(&p->flags[0], SIP_ALREADYGONE);	
@@ -12123,7 +12129,7 @@
 
 	case 404: /* Not found */
 		transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, FALSE);
-		if (p->owner && !ast_test_flag(req, SIP_PKT_IGNORE))
+		if (p->owner && !req_ignore(req))
 			ast_queue_control(p->owner, AST_CONTROL_CONGESTION);
 		ast_set_flag(&p->flags[0], SIP_ALREADYGONE);	
 		break;
@@ -12139,7 +12145,7 @@
 		/* We should support the retry-after at some point */
 		/* At this point, we treat this as a congestion */
 		transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, FALSE);
-		if (p->owner && !ast_test_flag(req, SIP_PKT_IGNORE))
+		if (p->owner && !req_ignore(req))
 			ast_queue_control(p->owner, AST_CONTROL_CONGESTION);
 		ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
 		break;
@@ -12661,7 +12667,7 @@
 					ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);	
 			} else if ((resp >= 100) && (resp < 200)) {
 				if (sipmethod == SIP_INVITE) {
-					if (!ast_test_flag(req, SIP_PKT_IGNORE))
+					if (!req_ignore(req))
 						sip_cancel_destroy(p);
 					if (find_sdp(req))
 						process_sdp(p, req);
@@ -12758,7 +12764,7 @@
 		default:	/* Errors without handlers */
 			if ((resp >= 100) && (resp < 200)) {
 				if (sipmethod == SIP_INVITE) { 	/* re-invite */
-					if (!ast_test_flag(req, SIP_PKT_IGNORE))
+					if (!req_ignore(req))
 						sip_cancel_destroy(p);
 				}
 			}
@@ -13247,7 +13253,7 @@
 			ast_log(LOG_DEBUG, "SIP transfer: Invite Replace incoming channel should replace and hang up channel %s (one call leg)\n", replacecall->name); 
 	}
 
-	if (ast_test_flag(req, SIP_PKT_IGNORE)) {
+	if (req_ignore(req)) {
 		ast_log(LOG_NOTICE, "Ignoring this INVITE with replaces in a stupid way.\n");
 		/* We should answer something here. If we are here, the
 			call we are replacing exists, so an accepted 
@@ -13425,7 +13431,7 @@
 		return 0;
 	}
 	
-	if (!ast_test_flag(req, SIP_PKT_IGNORE) && p->pendinginvite) {
+	if (!req_ignore(req) && p->pendinginvite) {
 		/* We already have a pending invite. Sorry. You are on hold. */
 		transmit_response(p, "491 Request Pending", req);
 		if (option_debug)
@@ -13547,7 +13553,7 @@
 	/* Check if this is an INVITE that sets up a new dialog or
 	   a re-invite in an existing dialog */
 
-	if (!ast_test_flag(req, SIP_PKT_IGNORE)) {
+	if (!req_ignore(req)) {
 		sip_cancel_destroy(p);
 		/* This also counts as a pending invite */
 		p->pendinginvite = seqno;
@@ -13581,7 +13587,7 @@
 		ast_verbose("Ignoring this INVITE request\n");
 
 	
-	if (!p->lastinvite && !ast_test_flag(req, SIP_PKT_IGNORE) && !p->owner) {
+	if (!p->lastinvite && !req_ignore(req) && !p->owner) {
 		/* This is a new invite */
 		/* Handle authentication if this is our first invite */
 		res = check_user(p, req, SIP_INVITE, e, XMIT_RELIABLE, sin);
@@ -13679,7 +13685,7 @@
 		}
 	} else {
 		if (option_debug > 1 && sipdebug) {
-			if (!ast_test_flag(req, SIP_PKT_IGNORE))
+			if (!req_ignore(req))
 				ast_log(LOG_DEBUG, "Got a SIP re-invite for call %s\n", p->callid);
 			else
 				ast_log(LOG_DEBUG, "Got a SIP re-transmit of INVITE for call %s\n", p->callid);
@@ -13687,14 +13693,14 @@
 		c = p->owner;
 	}
 
-	if (!ast_test_flag(req, SIP_PKT_IGNORE) && p)
+	if (!req_ignore(req) && p)
 		p->lastinvite = seqno;
 
 	if (replace_id) { 	/* Attended transfer or call pickup - we're the target */
 		/* Go and take over the target call */
 		if (sipdebug && option_debug > 3)
 			ast_log(LOG_DEBUG, "Sending this call to the invite/replcaes handler %s\n", p->callid);
-		return handle_invite_replaces(p, req, debug, ast_test_flag(req, SIP_PKT_IGNORE), seqno, sin);
+		return handle_invite_replaces(p, req, debug, req_ignore(req), seqno, sin);
 	}
 
 
@@ -13713,14 +13719,14 @@
 				switch(res) {
 				case AST_PBX_FAILED:
 					ast_log(LOG_WARNING, "Failed to start PBX :(\n");
-					if (ast_test_flag(req, SIP_PKT_IGNORE))
+					if (req_ignore(req))
 						transmit_response(p, "503 Unavailable", req);
 					else
 						transmit_response_reliable(p, "503 Unavailable", req);
 					break;
 				case AST_PBX_CALL_LIMIT:
 					ast_log(LOG_WARNING, "Failed to start PBX (call limit reached) \n");
-					if (ast_test_flag(req, SIP_PKT_IGNORE))
+					if (req_ignore(req))
 						transmit_response(p, "480 Temporarily Unavailable", req);
 					else
 						transmit_response_reliable(p, "480 Temporarily Unavailable", req);
@@ -13743,7 +13749,7 @@
 				ast_channel_unlock(c);
 				if (ast_pickup_call(c)) {
 					ast_log(LOG_NOTICE, "Nothing to pick up for %s\n", p->callid);
-					if (ast_test_flag(req, SIP_PKT_IGNORE))
+					if (req_ignore(req))
 						transmit_response(p, "503 Unavailable", req);	/* OEJ - Right answer? */
 					else
 						transmit_response_reliable(p, "503 Unavailable", req);
@@ -13791,7 +13797,7 @@
 								sip_pvt_unlock(bridgepvt);
 								if (option_debug > 1)
 									ast_log(LOG_DEBUG,"T38 state changed to %d on channel %s\n", bridgepvt->t38.state, bridgepeer->name);
-								if (ast_test_flag(req, SIP_PKT_IGNORE))
+								if (req_ignore(req))
 									transmit_response(p, "488 Not acceptable here", req);
 								else
 									transmit_response_reliable(p, "488 Not acceptable here", req);
@@ -13806,7 +13812,7 @@
 						}
 					} else {
 						/* Other side is not a SIP channel */
-						if (ast_test_flag(req, SIP_PKT_IGNORE))
+						if (req_ignore(req))
 							transmit_response(p, "488 Not acceptable here", req);
 						else
 							transmit_response_reliable(p, "488 Not acceptable here", req);
@@ -13836,7 +13842,7 @@
 						if (bridgepvt->t38.state == T38_ENABLED) {
 							ast_log(LOG_WARNING, "RTP re-invite after T38 session not handled yet !\n");
 							/* Insted of this we should somehow re-invite the other side of the bridge to RTP */
-							if (ast_test_flag(req, SIP_PKT_IGNORE))
+							if (req_ignore(req))
 								transmit_response(p, "488 Not Acceptable Here (unsupported)", req);
 							else
 								transmit_response_reliable(p, "488 Not Acceptable Here (unsupported)", req);
@@ -13866,7 +13872,7 @@
 				ast_log(LOG_NOTICE, "Unable to create/find SIP channel for this INVITE\n");
 				msg = "503 Unavailable";
 			}
-			if (ast_test_flag(req, SIP_PKT_IGNORE))
+			if (req_ignore(req))
 				transmit_response(p, msg, req);
 			else
 				transmit_response_reliable(p, msg, req);
@@ -14065,7 +14071,7 @@
 		if (option_debug > 2)
 			ast_log(LOG_DEBUG, "Call %s: Declined REFER, outside of dialog...\n", p->callid);
 		transmit_response(p, "603 Declined (No dialog)", req);
-		if (!ast_test_flag(req, SIP_PKT_IGNORE)) {
+		if (!req_ignore(req)) {
 			append_history(p, "Xfer", "Refer failed. Outside of dialog.");
 			ast_set_flag(&p->flags[0], SIP_ALREADYGONE);	
 			ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);	
@@ -14083,7 +14089,7 @@
 		return 0;
 	}
 
-	if(!ast_test_flag(req, SIP_PKT_IGNORE) && ast_test_flag(&p->flags[0], SIP_GOTREFER)) {
+	if(!req_ignore(req) && ast_test_flag(&p->flags[0], SIP_GOTREFER)) {
 		/* Already have a pending REFER */	
 		transmit_response(p, "491 Request pending", req);
 		append_history(p, "Xfer", "Refer failed. Request pending.");
@@ -14144,7 +14150,7 @@
 	
 	/* Is this a repeat of a current request? Ignore it */
 	/* Don't know what else to do right now. */
-	if (ast_test_flag(req, SIP_PKT_IGNORE)) 
+	if (req_ignore(req)) 
 		return res;
 
 	/* If this is a blind transfer, we have the following
@@ -14358,7 +14364,7 @@
 	int res;
 	struct ast_channel *bridged_to;
 	
-	if (p->pendinginvite && !ast_test_flag(&p->flags[0], SIP_OUTGOING) && !ast_test_flag(req, SIP_PKT_IGNORE))
+	if (p->pendinginvite && !ast_test_flag(&p->flags[0], SIP_OUTGOING) && !req_ignore(req))
 		transmit_response_reliable(p, "487 Request Terminated", &p->initreq);
 
 	copy_request(&p->initreq, req);
@@ -14425,7 +14431,7 @@
 /*! \brief Handle incoming MESSAGE request */
 static int handle_request_message(struct sip_pvt *p, struct sip_request *req)
 {
-	if (!ast_test_flag(req, SIP_PKT_IGNORE)) {
+	if (!req_ignore(req)) {
 		if (ast_test_flag(req, SIP_PKT_DEBUG))
 			ast_verbose("Receiving message!\n");
 		receive_message(p, req);
@@ -14475,14 +14481,14 @@
 		return 0;
 	}
 
-	if (!ast_test_flag(req, SIP_PKT_IGNORE) && !resubscribe) {	/* Set up dialog, new subscription */
+	if (!req_ignore(req) && !resubscribe) {	/* Set up dialog, new subscription */
 		/* Use this as the basis */
 		if (ast_test_flag(req, SIP_PKT_DEBUG))
 			ast_verbose("Creating new subscription\n");
 
 		copy_request(&p->initreq, req);
 		check_via(p, req);
-	} else if (ast_test_flag(req, SIP_PKT_DEBUG) && ast_test_flag(req, SIP_PKT_IGNORE))
+	} else if (ast_test_flag(req, SIP_PKT_DEBUG) && req_ignore(req))
 		ast_verbose("Ignoring this SUBSCRIBE request\n");
 
 	/* Find parameters to Event: header value and remove them for now */
@@ -14635,7 +14641,7 @@
 	if (p->subscribed != MWI_NOTIFICATION && !resubscribe)
 		p->stateid = ast_extension_state_add(p->context, p->exten, cb_extensionstate, p);
 
-	if (!ast_test_flag(req, SIP_PKT_IGNORE) && p)
+	if (!req_ignore(req) && p)
 		p->lastinvite = seqno;
 	if (p && !ast_test_flag(&p->flags[0], SIP_NEEDDESTROY)) {
 		p->expiry = atoi(get_header(req, "Expires"));
@@ -14909,7 +14915,7 @@
 			RFC 3261 - section 12.2 - and we don't want to mess with recovery  */
 		if (!p->initreq.headers && ast_test_flag(req, SIP_PKT_WITH_TOTAG)) {
 			/* If this is a first request and it got a to-tag, it is not for us */
-			if (!ast_test_flag(req, SIP_PKT_IGNORE) && req->method == SIP_INVITE) {
+			if (!req_ignore(req) && req->method == SIP_INVITE) {
 				transmit_response_reliable(p, "481 Call/Transaction Does Not Exist", req);
 				/* Will cease to exist after ACK */
 			} else if (req->method != SIP_ACK) {
@@ -14949,7 +14955,7 @@
 	case SIP_INFO:
 		if (ast_test_flag(req, SIP_PKT_DEBUG))
 			ast_verbose("Receiving INFO!\n");
-		if (!ast_test_flag(req, SIP_PKT_IGNORE)) 
+		if (!req_ignore(req)) 
 			handle_request_info(p, req);
 		else  /* if ignoring, transmit response */
 			transmit_response(p, "200 OK", req);



More information about the svn-commits mailing list