[asterisk-commits] rizzo: branch rizzo/astobj2 r76389 - /team/rizzo/astobj2/channels/chan_sip.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sun Jul 22 15:25:43 CDT 2007


Author: rizzo
Date: Sun Jul 22 15:25:42 2007
New Revision: 76389

URL: http://svn.digium.com/view/asterisk?view=rev&rev=76389
Log:
merge from trunk

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=76389&r1=76388&r2=76389
==============================================================================
--- team/rizzo/astobj2/channels/chan_sip.c (original)
+++ team/rizzo/astobj2/channels/chan_sip.c Sun Jul 22 15:25:42 2007
@@ -616,12 +616,6 @@
 #define DEC_CALL_RINGING 2
 #define INC_CALL_RINGING 3
 
-/* SIP packet flags, go into sip_request.flags */
-#define SIP_PKT_DEBUG		(1 << 0)	/*!< Debug this packet */
-#define SIP_PKT_WITH_TOTAG	(1 << 1)	/*!< This packet has a to-tag */
-#define SIP_PKT_IGNORE 		(1 << 2)	/*!< This is a re-transmit, ignore it */
-#define SIP_PKT_PARSED 		(1 << 3)	/*!< lines are NUL-separated */
-
 /*!
  * Incoming packet, or outgoing one (for the time being)
  * For incoming packets, we first store the data from the socket in data[],
@@ -629,7 +623,7 @@
  * Then call parse_request() and req.method = find_sip_method();
  * to initialize the other fields. The \r\n at the end of line is
  * replaced by \0, so that data[] is not a conforming one anymore.
- * flags has SIP_PKT_PARSED set to remember that we can run get_header()
+ * rlPart1 is set to remember that we can run get_header()
  * on this kind of packet.
  *
  * For outgoing packets, we initialize the fields with init_req() or init_resp()
@@ -644,10 +638,10 @@
  * empty line, which we store as the last of the headers.
  *
  * parse_request() splits the first line as follows:
- * Requests have in the first line	METHOD URI SIP/2.0
+ * Requests have in the first line	method uri SIP/2.0
  *	rlPart1 = method; rlPart2 = uri;
- * Responses have in the first line	SIP/2.0 code description
- *	rlPart1 = SIP/2.0; rlPart2 = code + description;
+ * Responses have in the first line	SIP/2.0 NNN description
+ *	rlPart1 = SIP/2.0; rlPart2 = NNN + description;
  */
 
 struct sip_request {
@@ -657,9 +651,11 @@
 	int headers;            /*!< # of SIP Headers */
 	int method;             /*!< Method of this request */
 	int lines;              /*!< Body Content */
-	unsigned int flags;	/*!< SIP_PKT Flags for this packet */ /* XXX should be ast_flags */
 	unsigned int sdp_start; /*!< the line number where the SDP begins */
 	unsigned int sdp_end;   /*!< the line number where the SDP ends */
+	char debug;		/*!< print extra debugging if non zero */
+	char has_to_tag;	/*!< non-zero if packet has To: tag */
+	char ignore;		/*!< if non-zero This is a re-transmit, ignore it */
 	char *header[SIP_MAX_HEADERS];
 	char *line[SIP_MAX_LINES];
 	char data[SIP_MAX_PACKET];
@@ -679,12 +675,6 @@
 	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);
-}
-
 /*! \brief structure used in transfers */
 struct sip_dual {
 	struct ast_channel *chan1;	/*!< First channel involved */
@@ -751,11 +741,12 @@
 };
 
 /*--- Various flags for the flags field in the pvt structure
-       Trying to sort these up:
-       D: Dialog only
-       DP: Dialog and peer/user
-       P: Peer/user only, not dialog
-       G: Global flag only
+	Trying to sort these up (one or more of the following):
+	D: Dialog
+	P: Peer/user
+	G: Global flag
+	When flags are used by multiple structures, it is important that   
+	they have a common layout so it is easy to copy them.
 */
 #define __SIP_ALREADYGONE		(1 << 0)	/*!< D: Whether or not we've already been destroyed by our peer */
 #define __SIP_NEEDDESTROY		(1 << 1)	/*!< D: if we need to be destroyed by the monitor thread */
@@ -854,6 +845,7 @@
 	(SIP_PAGE2_ALLOWSUBSCRIBE | SIP_PAGE2_ALLOWOVERLAP | SIP_PAGE2_VIDEOSUPPORT | \
 	SIP_PAGE2_T38SUPPORT | SIP_PAGE2_RFC2833_COMPENSATE | SIP_PAGE2_BUGGY_MWI | \
 	SIP_PAGE2_TEXTSUPPORT )
+
 
 /* T.38 set of flags */
 #define T38FAX_FILL_BIT_REMOVAL		(1 << 0)	/*!< Default: 0 (unset)*/
@@ -1156,8 +1148,8 @@
 	int retrans;				/*!< Retransmission number */
 	int method;				/*!< SIP method for this packet */
 	int seqno;				/*!< Sequence number */
-	int is_resp;				/*!< non-zero if this is a response packet (e.g. 200 OK) */
-	int is_fatal;				/*!< non-zero if this is a fatal error */
+	char is_resp;				/*!< non-zero if this is a response packet (e.g. 200 OK) */
+	char is_fatal;				/*!< non-zero if this is a fatal error */
 	struct sip_pvt *pvt;			/*!< Owner AST call */
 	int retransid;				/*!< Retransmission ID */
 	int timer_a;				/*!< SIP timer A, retransmission timer */
@@ -1782,10 +1774,10 @@
 	.answer = sip_answer,		/* called with chan locked */
 	.read = sip_read,		/* called with chan locked */
 	.write = sip_write,		/* called with chan locked */
-	.write_video = sip_write,		/* called with chan locked */
-	.write_text = sip_write,	/* XXX */
+	.write_video = sip_write,	/* called with chan locked */
+	.write_text = sip_write,
 	.indicate = sip_indicate,	/* called with chan locked */
-	.transfer = sip_transfer,		/* called with chan locked */
+	.transfer = sip_transfer,	/* called with chan locked */
 	.fixup = sip_fixup,		/* called with chan locked */
 	.send_digit_begin = sip_senddigit_begin,	/* called with chan unlocked */
 	.send_digit_end = sip_senddigit_end,
@@ -4692,7 +4684,7 @@
 {
 	int pass;
 
-	if (!(req->flags & SIP_PKT_PARSED)) {
+	if (req->rlPart1 == NULL) {
 		ast_log(LOG_WARNING, "packet not parsed, cannot extract field %s\n", name);
 		return "";
 	}
@@ -5154,7 +5146,7 @@
 		   in sip.conf
 		   */
 		if (gettag(req, "To", totag, sizeof(totag)))
-			ast_set_flag(req, SIP_PKT_WITH_TOTAG);	/* Used in handle_request/response */
+			req->has_to_tag = 1;	/* Used in handle_request/response */
 		gettag(req, "From", fromtag, sizeof(fromtag));
 
 		arg.tag = (req->method == SIP_RESPONSE) ? totag : fromtag;
@@ -5378,7 +5370,7 @@
 	char *c = req->data, **dst = req->header;
 	int i = 0, lim = SIP_MAX_HEADERS - 1;
 
-	if (req->flags & SIP_PKT_PARSED) {
+	if (req->rlPart1) {
 		ast_log(LOG_WARNING, "sorry, packet already parsed");
 		return;
 	}
@@ -5429,7 +5421,6 @@
 		ast_log(LOG_WARNING, "Too many lines, skipping <%s>\n", c);
 	/* Split up the first line parts */
 	determine_firstline_parts(req);
-	req->flags |= SIP_PKT_PARSED;
 }
 
 /*!
@@ -9301,7 +9292,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, req_ignore(req)))) {
+			if (!(res = check_auth(p, req, peer->name, peer->secret, peer->md5secret, SIP_REGISTER, uri, XMIT_UNRELIABLE, req->ignore))) {
 				sip_cancel_destroy(p);
 
 				/* We have a succesful registration attempt with proper authentication,
@@ -10091,7 +10082,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, req_ignore(req)))) {
+	if (!(res = check_auth(p, req, user->name, user->secret, user->md5secret, sipmethod, uri2, reliable, req->ignore))) {
 		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);
@@ -10222,7 +10213,7 @@
 		ast_string_field_free(p, secret);
 		ast_string_field_free(p, md5secret);
 	}
-	if (!(res = check_auth(p, req, peer->name, p->secret, p->md5secret, sipmethod, uri2, reliable, req_ignore(req)))) {
+	if (!(res = check_auth(p, req, peer->name, p->secret, p->md5secret, sipmethod, uri2, reliable, req->ignore))) {
 		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 */
@@ -11537,6 +11528,8 @@
 		msg = "Disabled, no localnet list";
 	else if (externip.sin_addr.s_addr == 0)
 		msg = "Disabled, externip is 0.0.0.0";
+	else if (stunaddr.sin_addr.s_addr != 0)
+		msg = "Enabled using STUN";
 	else if (!ast_strlen_zero(externhost))
 		msg = "Enabled using externhost";
 	else
@@ -12091,12 +12084,12 @@
 		} else {
 			ast_copy_string(buf, c, sizeof(buf));
 		}
+
 		if (!ast_strlen_zero((c = get_body(req, "Duration"))))
 			duration = atoi(c);
 		if (!duration)
 			duration = 100; /* 100 ms */
   	 
-	
 		if (!p->owner) {	/* not a PBX call */
 			transmit_response(p, "481 Call leg/transaction does not exist", req);
 			sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
@@ -12180,29 +12173,17 @@
 			ast_unlock_call_features();
 			return;
 		} 
-		/* OEJ: Why is the DTMF code included in the record section? */
+		/* Send the feature code to the PBX as DTMF, just like the handset had sent it */
 		f.len = 100;
 		for (j=0; j<strlen(feat->exten); j++) {
 			f.subclass = feat->exten[j];
 			ast_queue_frame(p->owner, &f);
 			if (sipdebug)
-				ast_verbose("* DTMF-relay event received: %c\n", f.subclass);
+				ast_verbose("* DTMF-relay event faked: %c\n", f.subclass);
 		}
 		ast_unlock_call_features();
-#ifdef DISABLED_CODE
-		/* And feat isn't used here - Is this code tested at all??? 
-			We just send a reply ... 
-		*/
-		if (strcasecmp(c, "on")== 0) {
-			ast_debug(1, "Got a Request to Record the channel!\n");
-			transmit_response(p, "200 OK", req);
-			return;
-		} else if (strcasecmp(c, "off")== 0) {
-			ast_debug(1, "Got a Request to Stop Recording the channel\n");
-			transmit_response(p, "200 OK", req);
-			return;
-		}
-#endif
+
+		ast_debug(1, "Got a Request to Record the channel, state %s\n", c);
 		transmit_response(p, "200 OK", req);
 		return;
 	}
@@ -12997,15 +12978,15 @@
 	switch (resp) {
 	case 100:	/* Trying */
 	case 101:	/* Dialog establishment */
-		if (!req_ignore(req))
+		if (!req->ignore)
 			sip_cancel_destroy(p);
 		check_pendings(p);
 		break;
 
 	case 180:	/* 180 Ringing */
-		if (!req_ignore(req))
+		if (!req->ignore)
 			sip_cancel_destroy(p);
-		if (!req_ignore(req) && p->owner) {
+		if (!req->ignore && p->owner) {
 			ast_queue_control(p->owner, AST_CONTROL_RINGING);
 			if (p->owner->_state != AST_STATE_UP) {
 				ast_setstate(p->owner, AST_STATE_RINGING);
@@ -13014,7 +12995,7 @@
 		if (find_sdp(req)) {
 			p->invitestate = INV_EARLY_MEDIA;
 			res = process_sdp(p, req);
-			if (!req_ignore(req) && p->owner) {
+			if (!req->ignore && p->owner) {
 				/* Queue a progress frame only if we have SDP in 180 */
 				ast_queue_control(p->owner, AST_CONTROL_PROGRESS);
 			}
@@ -13023,13 +13004,13 @@
 		break;
 
 	case 183:	/* Session progress */
-		if (!req_ignore(req))
+		if (!req->ignore)
 			sip_cancel_destroy(p);
 		/* Ignore 183 Session progress without SDP */
 		if (find_sdp(req)) {
 			p->invitestate = INV_EARLY_MEDIA;
 			res = process_sdp(p, req);
-			if (!req_ignore(req) && p->owner) {
+			if (!req->ignore && p->owner) {
 				/* Queue a progress frame */
 				ast_queue_control(p->owner, AST_CONTROL_PROGRESS);
 			}
@@ -13038,11 +13019,11 @@
 		break;
 
 	case 200:	/* 200 OK on invite - someone's answering our call */
-		if (!req_ignore(req))
+		if (!req->ignore)
 			sip_cancel_destroy(p);
 		p->authtries = 0;
 		if (find_sdp(req)) {
-			if ((res = process_sdp(p, req)) && !req_ignore(req))
+			if ((res = process_sdp(p, req)) && !req->ignore)
 				if (!reinvite)
 					/* This 200 OK's SDP is not acceptable, so we need to ack, then hangup */
 					/* For re-invites, we try to recover */
@@ -13063,7 +13044,7 @@
 					should we care about resolving the contact
 					or should we just send it?
 				*/
-				if (!req_ignore(req))
+				if (!req->ignore)
 					ast_set_flag(&p->flags[0], SIP_PENDINGBYE);	
 			} 
 
@@ -13114,7 +13095,7 @@
 			ast_debug(1, "T38 changed state to %d on channel %s\n", p->t38.state, p->owner ? p->owner->name : "<none>");
 		}
 
-		if (!req_ignore(req) && p->owner) {
+		if (!req->ignore && p->owner) {
 			if (!reinvite) {
 				ast_queue_control(p->owner, AST_CONTROL_ANSWER);
 				if (global_callevents)
@@ -13128,7 +13109,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 (!req_ignore(req))
+			if (!req->ignore)
 				ast_set_flag(&p->flags[0], SIP_PENDINGBYE);	
 		}
 		/* If I understand this right, the branch is different for a non-200 ACK only */
@@ -13146,7 +13127,7 @@
 
 		/* Then we AUTH */
 		ast_string_field_free(p, theirtag);	/* forget their old tag, so we don't match tags when getting response */
-		if (!req_ignore(req)) {
+		if (!req->ignore) {
 			/* XXX trunk has if (p->authtries < MAX_AUTHTRIES) ...
 			 * but i am not sure if it is correct.
 			 */
@@ -13165,7 +13146,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 (!req_ignore(req) && p->owner)
+		if (!req->ignore && p->owner)
 			ast_queue_control(p->owner, AST_CONTROL_CONGESTION);
 		p->needdestroy = 1;
 		sip_alreadygone(p);
@@ -13173,7 +13154,7 @@
 
 	case 404: /* Not found */
 		transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, FALSE);
-		if (p->owner && !req_ignore(req))
+		if (p->owner && !req->ignore)
 			ast_queue_control(p->owner, AST_CONTROL_CONGESTION);
 		sip_alreadygone(p);
 		break;
@@ -13191,9 +13172,9 @@
 			 This transaction is already scheduled to be killed by sip_hangup().
 		 */
 		 transmit_request(p, SIP_ACK, seqno, 0, 0);
-		 if (p->owner && !ast_test_flag(req, SIP_PKT_IGNORE))
+		 if (p->owner && !req->ignore)
 			 ast_queue_hangup(p->owner);
-		 else if (!ast_test_flag(req, SIP_PKT_IGNORE))
+		 else if (!req->ignore)
 			 update_call_counter(p, DEC_CALL_LIMIT);
 		 break;
         case 488: /* Not acceptable here */
@@ -13213,12 +13194,12 @@
 			    sides here?
 			 */
 			 /* While figuring that out, hangup the call */
-			 if (p->owner && !ast_test_flag(req, SIP_PKT_IGNORE))
+			 if (p->owner && !req->ignore)
 				 ast_queue_control(p->owner, AST_CONTROL_CONGESTION);
 			 p->needdestroy = 1;
 		 } else {
 			 /* We can't set up this call, so give up */
-			 if (p->owner && !ast_test_flag(req, SIP_PKT_IGNORE))
+			 if (p->owner && !req->ignore)
 				 ast_queue_control(p->owner, AST_CONTROL_CONGESTION);
 			 p->needdestroy = 1;
 		 }
@@ -13229,7 +13210,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 && !req_ignore(req))
+		if (p->owner && !req->ignore)
 			ast_queue_control(p->owner, AST_CONTROL_CONGESTION);
 		p->needdestroy = 1;
 		break;
@@ -13819,7 +13800,7 @@
 					p->needdestroy = 1;
 			} else if ((resp >= 100) && (resp < 200)) {
 				if (sipmethod == SIP_INVITE) {
-					if (!req_ignore(req))
+					if (!req->ignore)
 						sip_cancel_destroy(p);
 					if (find_sdp(req))
 						process_sdp(p, req);
@@ -13834,7 +13815,7 @@
 	} else {	
 		/* Responses to OUTGOING SIP requests on INCOMING calls 
 		   get handled here. As well as out-of-call message responses */
-		if (ast_test_flag(req, SIP_PKT_DEBUG))
+		if (req->debug)
 			ast_verbose("SIP Response message for INCOMING dialog %s arrived\n", msg);
 
 		if (sipmethod == SIP_INVITE && resp == 200) {
@@ -13918,7 +13899,7 @@
 		default:	/* Errors without handlers */
 			if ((resp >= 100) && (resp < 200)) {
 				if (sipmethod == SIP_INVITE) { 	/* re-invite */
-					if (!req_ignore(req))
+					if (!req->ignore)
 						sip_cancel_destroy(p);
 				}
 			}
@@ -14402,7 +14383,7 @@
 	else
 		ast_debug(4, "SIP transfer: Invite Replace incoming channel should replace and hang up channel %s (one call leg)\n", replacecall->name); 
 
-	if (req_ignore(req)) {
+	if (req->ignore) {
 		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 
@@ -14580,7 +14561,7 @@
 		return 0;
 	}
 	
-	if (!req_ignore(req) && p->pendinginvite) {
+	if (!req->ignore && p->pendinginvite) {
 		/* We already have a pending invite. Sorry. You are on hold. */
 		transmit_response(p, "491 Request Pending", req);
 		ast_debug(1, "Got INVITE on call where we already have pending INVITE, deferring that - %s\n", p->callid);
@@ -14703,7 +14684,7 @@
 	/* Check if this is an INVITE that sets up a new dialog or
 	   a re-invite in an existing dialog */
 
-	if (req_ignore(req)) {
+	if (req->ignore) {
 		ast_verbose("Ignoring this INVITE request\n");
 	} else {
 		int newcall = (p->initreq.headers ? TRUE : FALSE);
@@ -14742,7 +14723,7 @@
 		}
 	}
 	
-	if (!p->lastinvite && !req_ignore(req) && !p->owner) {
+	if (!p->lastinvite && !req->ignore && !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);
@@ -14842,7 +14823,7 @@
 		}
 	} else {
 		if (sipdebug) {
-			if (!req_ignore(req))
+			if (!req->ignore)
 				ast_debug(2, "Got a SIP re-invite for call %s\n", p->callid);
 			else
 				ast_debug(2, "Got a SIP re-transmit of INVITE for call %s\n", p->callid);
@@ -14850,14 +14831,14 @@
 		c = p->owner;
 	}
 
-	if (!req_ignore(req) && p)
+	if (!req->ignore && 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)
 			ast_debug(4, "Sending this call to the invite/replcaes handler %s\n", p->callid);
-		return handle_invite_replaces(p, req, debug, req_ignore(req), seqno, sin);
+		return handle_invite_replaces(p, req, debug, req->ignore, seqno, sin);
 	}
 
 
@@ -14877,7 +14858,7 @@
 				case AST_PBX_FAILED:
 					ast_log(LOG_WARNING, "Failed to start PBX :(\n");
 					p->invitestate = INV_COMPLETED;
-					if (req_ignore(req))
+					if (req->ignore)
 						transmit_response(p, "503 Unavailable", req);
 					else
 						transmit_response_reliable(p, "503 Unavailable", req);
@@ -14885,7 +14866,7 @@
 				case AST_PBX_CALL_LIMIT:
 					ast_log(LOG_WARNING, "Failed to start PBX (call limit reached) \n");
 					p->invitestate = INV_COMPLETED;
-					if (req_ignore(req))
+					if (req->ignore)
 						transmit_response(p, "480 Temporarily Unavailable", req);
 					else
 						transmit_response_reliable(p, "480 Temporarily Unavailable", req);
@@ -14908,7 +14889,7 @@
 				ast_channel_unlock(c);
 				if (ast_pickup_call(c)) {
 					ast_log(LOG_NOTICE, "Nothing to pick up for %s\n", p->callid);
-					if (req_ignore(req))
+					if (req->ignore)
 						transmit_response(p, "503 Unavailable", req);	/* OEJ - Right answer? */
 					else
 						transmit_response_reliable(p, "503 Unavailable", req);
@@ -14957,7 +14938,7 @@
 								bridgepvt->t38.state = T38_DISABLED;
 								sip_pvt_unlock(bridgepvt);
 								ast_debug(2,"T38 state changed to %d on channel %s\n", bridgepvt->t38.state, bridgepeer->name);
-								if (req_ignore(req))
+								if (req->ignore)
 									transmit_response(p, "488 Not acceptable here", req);
 								else
 									transmit_response_reliable(p, "488 Not acceptable here", req);
@@ -14971,7 +14952,7 @@
 						}
 					} else {
 						/* Other side is not a SIP channel */
-						if (req_ignore(req))
+						if (req->ignore)
 							transmit_response(p, "488 Not acceptable here", req);
 						else
 							transmit_response_reliable(p, "488 Not acceptable here", req);
@@ -15001,7 +14982,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 (req_ignore(req))
+							if (req->ignore)
 								transmit_response(p, "488 Not Acceptable Here (unsupported)", req);
 							else
 								transmit_response_reliable(p, "488 Not Acceptable Here (unsupported)", req);
@@ -15012,7 +14993,7 @@
 				} 
 				/* Respond to normal re-invite */
 				if (sendok)
-					transmit_response_with_sdp(p, "200 OK", req, ast_test_flag(req, SIP_PKT_IGNORE) ?  XMIT_UNRELIABLE : XMIT_CRITICAL);
+					transmit_response_with_sdp(p, "200 OK", req, req->ignore ?  XMIT_UNRELIABLE : XMIT_CRITICAL);
 			}
 			p->invitestate = INV_TERMINATED;
 			break;
@@ -15031,7 +15012,7 @@
 				ast_log(LOG_NOTICE, "Unable to create/find SIP channel for this INVITE\n");
 				msg = "503 Unavailable";
 			}
-			if (req_ignore(req))
+			if (req->ignore)
 				transmit_response(p, msg, req);
 			else
 				transmit_response_reliable(p, msg, req);
@@ -15209,7 +15190,7 @@
 
 	int res = 0;
 
-	if (ast_test_flag(req, SIP_PKT_DEBUG))
+	if (req->debug)
 		ast_verbose("Call %s got a SIP call transfer from %s: (REFER)!\n", p->callid, ast_test_flag(&p->flags[0], SIP_OUTGOING) ? "callee" : "caller");
 
 	if (!p->owner) {
@@ -15217,7 +15198,7 @@
 		/* We can't handle that, so decline it */
 		ast_debug(3, "Call %s: Declined REFER, outside of dialog...\n", p->callid);
 		transmit_response(p, "603 Declined (No dialog)", req);
-		if (!req_ignore(req)) {
+		if (!req->ignore) {
 			append_history(p, "Xfer", "Refer failed. Outside of dialog.");
 			sip_alreadygone(p);
 			p->needdestroy = 1;
@@ -15235,7 +15216,7 @@
 		return 0;
 	}
 
-	if(!req_ignore(req) && ast_test_flag(&p->flags[0], SIP_GOTREFER)) {
+	if(!req->ignore && 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.");
@@ -15258,13 +15239,13 @@
 		case -2:	/* Syntax error */
 			transmit_response(p, "400 Bad Request (Refer-to missing)", req);
 			append_history(p, "Xfer", "Refer failed. Refer-to missing.");
-			if (ast_test_flag(req, SIP_PKT_DEBUG))
+			if (req->debug)
 				ast_debug(1, "SIP transfer to black hole can't be handled (no refer-to: )\n");
 			break;
 		case -3:
 			transmit_response(p, "603 Declined (Non sip: uri)", req);
 			append_history(p, "Xfer", "Refer failed. Non SIP uri");
-			if (ast_test_flag(req, SIP_PKT_DEBUG))
+			if (req->debug)
 				ast_debug(1, "SIP transfer to non-SIP uri denied\n");
 			break;
 		default:
@@ -15273,7 +15254,7 @@
 			append_history(p, "Xfer", "Refer failed. Bad extension.");
 			transmit_notify_with_sipfrag(p, seqno, "404 Not found", TRUE);
 			ast_clear_flag(&p->flags[0], SIP_GOTREFER);	
-			if (ast_test_flag(req, SIP_PKT_DEBUG))
+			if (req->debug)
 				ast_debug(1, "SIP transfer to bad extension: %s\n", p->refer->refer_to);
 			break;
 		} 
@@ -15296,7 +15277,7 @@
 	
 	/* Is this a repeat of a current request? Ignore it */
 	/* Don't know what else to do right now. */
-	if (req_ignore(req)) 
+	if (req->ignore)
 		return res;
 
 	/* If this is a blind transfer, we have the following
@@ -15570,7 +15551,7 @@
 	struct ast_channel *bridged_to;
 
 	/* If we have an INCOMING invite that we haven't answered, terminate that transaction */
-	if (p->pendinginvite && !ast_test_flag(&p->flags[0], SIP_OUTGOING) && !req_ignore(req) && !p->owner)
+	if (p->pendinginvite && !ast_test_flag(&p->flags[0], SIP_OUTGOING) && !req->ignore && !p->owner)
 		transmit_response_reliable(p, "487 Request Terminated", &p->initreq);
 
 	p->invitestate = INV_TERMINATED;
@@ -15646,8 +15627,8 @@
 /*! \brief Handle incoming MESSAGE request */
 static int handle_request_message(struct sip_pvt *p, struct sip_request *req)
 {
-	if (!req_ignore(req)) {
-		if (ast_test_flag(req, SIP_PKT_DEBUG))
+	if (!req->ignore) {
+		if (req->debug)
 			ast_verbose("Receiving message!\n");
 		receive_message(p, req);
 	} else
@@ -15676,7 +15657,7 @@
 			/* Do not destroy session, since we will break the call if we do */
 			ast_debug(1, "Got a subscription within the context of another call, can't handle that - %s (Method %s)\n", p->callid, sip_methods[p->initreq.method].text);
 			return 0;
-		} else if (ast_test_flag(req, SIP_PKT_DEBUG)) {
+		} else if (req->debug) {
 			if (resubscribe)
 				ast_debug(1, "Got a re-subscribe on existing subscription %s\n", p->callid);
 			else
@@ -15693,22 +15674,22 @@
 		return 0;
 	}
 
-	if (!req_ignore(req) && !resubscribe) {	/* Set up dialog, new subscription */
+	if (!req->ignore && !resubscribe) {	/* Set up dialog, new subscription */
 		/* Use this as the basis */
-		if (ast_test_flag(req, SIP_PKT_DEBUG))
+		if (req->debug)
 			ast_verbose("Creating new subscription\n");
 
 		copy_request(&p->initreq, req);
 		if (sipdebug)
 			ast_debug(4, "Initializing initreq for method %s - callid %s\n", sip_methods[req->method].text, p->callid);
 		check_via(p, req);
-	} else if (ast_test_flag(req, SIP_PKT_DEBUG) && req_ignore(req))
+	} else if (req->debug && req->ignore)
 		ast_verbose("Ignoring this SUBSCRIBE request\n");
 
 	/* Find parameters to Event: header value and remove them for now */
 	if (ast_strlen_zero(eventheader)) {
+		transmit_response(p, "489 Bad Event", req);
 		ast_debug(2, "Received SIP subscribe for unknown event package: <none>\n");
-		transmit_response(p, "489 Bad Event", req);
 		p->needdestroy = 1;
 		return 0;
 	}
@@ -15809,6 +15790,7 @@
 			char mybuf[200];
 			snprintf(mybuf,sizeof(mybuf),"489 Bad Event (format %s)", accept);
 			transmit_response(p, mybuf, req);
+
 			ast_log(LOG_WARNING,"SUBSCRIBE failure: unrecognized format: '%s' pvt: subscribed: %d, stateid: %d, laststate: %d, dialogver: %d, subscribecont: '%s', subscribeuri: '%s'\n",
 				accept, (int)p->subscribed, p->stateid, p->laststate, p->dialogver, p->subscribecontext, p->subscribeuri);
 			p->needdestroy = 1;
@@ -15817,8 +15799,8 @@
 	} else if (!strcmp(event, "message-summary")) { 
 		if (!ast_strlen_zero(accept) && strcmp(accept, "application/simple-message-summary")) {
 			/* Format requested that we do not support */
+			transmit_response(p, "406 Not Acceptable", req);
 			ast_debug(2, "Received SIP mailbox subscription for unknown format: %s\n", accept);
-			transmit_response(p, "406 Not Acceptable", req);
 			p->needdestroy = 1;
 			unref_peer(authpeer);
 			return 0;
@@ -15864,7 +15846,7 @@
 	if (p->subscribed != MWI_NOTIFICATION && !resubscribe)
 		p->stateid = ast_extension_state_add(p->context, p->exten, cb_extensionstate, p);
 
-	if (!req_ignore(req) && p)
+	if (!req->ignore && p)
 		p->lastinvite = seqno;
 	if (p && !p->needdestroy) {
 		p->expiry = atoi(get_header(req, "Expires"));
@@ -16065,7 +16047,7 @@
 		} else if (p->ocseq != seqno) {
 			/* ignore means "don't do anything with it" but still have to 
 			   respond appropriately  */
-			ast_set_flag(req, SIP_PKT_IGNORE);
+			req->ignore = 1;
 			append_history(p, "Ignore", "Ignoring this retransmit\n");
 		}
 	
@@ -16106,7 +16088,7 @@
 		 * required action), but still have to respond appropriately, as the other
 		 * side might have lost our message.
 		 */
-		ast_set_flag(req, SIP_PKT_IGNORE);
+		req->ignore = 1;
 		ast_debug(3, "Ignoring SIP message because of retransmit (%s Seqno %d, ours %d)\n", sip_methods[p->method].text, p->icseq, seqno);
 	} else {
 		/* Good sequence number - record it. It can be anything larger than the
@@ -16129,9 +16111,9 @@
 			correct according to RFC 3261  */
 		/* Check if this a new request in a new dialog with a totag already attached to it,
 			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 (!p->initreq.headers && req->has_to_tag) {
 			/* If this is a first request and it got a to-tag, it is not for us */
-			if (!req_ignore(req) && req->method == SIP_INVITE) {
+			if (!req->ignore && 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) {
@@ -16177,9 +16159,9 @@
 		res = handle_request_register(p, req, sin, e);
 		break;
 	case SIP_INFO:
-		if (ast_test_flag(req, SIP_PKT_DEBUG))
+		if (req->debug)
 			ast_verbose("Receiving INFO!\n");
-		if (!req_ignore(req)) 
+		if (!req->ignore)
 			handle_request_info(p, req);
 		else  /* if ignoring, transmit response */
 			transmit_response(p, "200 OK", req);
@@ -16302,11 +16284,11 @@
 	if (res == buflen)
 		ast_debug(1, "Received packet exceeds buffer. Data is possibly lost\n");
 	req.len = res;
-	if(sip_debug_test_addr(&sin))	/* Set the debug flag early on packet level */
-		ast_set_flag(&req, SIP_PKT_DEBUG);
+	if (sip_debug_test_addr(&sin))	/* Set the debug flag early on packet level */
+		req.debug = 1;
 	if (pedanticsipchecking)
 		req.len = lws2sws(req.data, req.len);	/* Fix multiline headers */
-	if (ast_test_flag(&req, SIP_PKT_DEBUG))
+	if (req.debug)
 		ast_verbose("\n<--- SIP read from %s:%d --->\n%s\n<------------->\n", ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port), req.data);
 
 	ast_mark(prof_parse, 1);
@@ -16314,7 +16296,7 @@
 	req.method = find_sip_method(req.rlPart1);
 	ast_mark(prof_parse, 0);
 
-	if (ast_test_flag(&req, SIP_PKT_DEBUG))
+	if (req.debug)
 		ast_verbose("--- (%d headers %d lines)%s ---\n", req.headers, req.lines, (req.headers + req.lines == 0) ? " Nat keepalive" : "");
 
 	if (req.headers < 2)	/* Must have at least two headers */




More information about the asterisk-commits mailing list