[asterisk-commits] branch oej/siptransfer r20933 - in /team/oej/siptransfer: ./ channels/chan_sip.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Mon Apr 17 07:24:14 MST 2006


Author: oej
Date: Mon Apr 17 09:24:10 2006
New Revision: 20933

URL: http://svn.digium.com/view/asterisk?rev=20933&view=rev
Log:
Reset automerge

Modified:
    team/oej/siptransfer/   (props changed)
    team/oej/siptransfer/channels/chan_sip.c

Propchange: team/oej/siptransfer/
------------------------------------------------------------------------------
    automerge = http://edvina.net/training/

Propchange: team/oej/siptransfer/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Mon Apr 17 09:24:10 2006
@@ -1,1 +1,1 @@
-/trunk:1-20811
+/trunk:1-20931

Modified: team/oej/siptransfer/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/oej/siptransfer/channels/chan_sip.c?rev=20933&r1=20932&r2=20933&view=diff
==============================================================================
--- team/oej/siptransfer/channels/chan_sip.c (original)
+++ team/oej/siptransfer/channels/chan_sip.c Mon Apr 17 09:24:10 2006
@@ -819,12 +819,12 @@
 	int rtpholdtimeout;			/*!< RTP timeout when on hold */
 	int rtpkeepalive;			/*!< Send RTP packets for keepalive */
 	enum transfermodes allowtransfer;	/*! SIP Refer restriction scheme */
-	struct sip_refer *refer;		/*!< Refer data */
-	enum subscriptiontype subscribed;	/*!< Is this dialog a subscription?  */
-	int stateid;
-	int laststate;				/*!< Last known extension state */
-	int dialogver;
+	enum subscriptiontype subscribed;	/*!< SUBSCRIBE: Is this dialog a subscription?  */
+	int stateid;				/*!< SUBSCRIBE: ID for devicestate subscriptions */
+	int laststate;				/*!< SUBSCRIBE: Last known extension state */
+	int dialogver;				/*!< SUBSCRIBE: Version for subscription dialog-info */
 	
+	struct sip_refer *refer;		/*!< REFER: SIP transfer data structure */
 	struct ast_dsp *vad;			/*!< Voice Activation Detection dsp */
 	
 	struct sip_peer *relatedpeer;		/*!< If this dialog is related to a peer, which one 
@@ -834,7 +834,7 @@
 	struct ast_rtp *vrtp;			/*!< Video RTP session */
 	struct sip_pkt *packets;		/*!< Packets scheduled for re-transmission */
 	struct sip_history_head *history;	/*!< History of this SIP dialog */
-	struct ast_variable *chanvars;		/*!< Channel variables to set for call */
+	struct ast_variable *chanvars;		/*!< Channel variables to set for inbound call */
 	struct sip_pvt *next;			/*!< Next dialog in chain */
 	struct sip_invite_param *options;	/*!< Options for INVITE */
 } *iflist = NULL;
@@ -842,9 +842,9 @@
 #define FLAG_RESPONSE (1 << 0)
 #define FLAG_FATAL (1 << 1)
 
-/*! \brief sip packet - read in sipsock_read(), transmitted in send_request() */
+/*! \brief sip packet - raw format for outbound packets that are sent or scheduled for transmission */
 struct sip_pkt {
-	struct sip_pkt *next;			/*!< Next packet */
+	struct sip_pkt *next;			/*!< Next packet in linked list */
 	int retrans;				/*!< Retransmission number */
 	int method;				/*!< SIP method for this packet */
 	int seqno;				/*!< Sequence number */
@@ -1099,6 +1099,10 @@
 /*------ Response handling functions (called from handle_response() ) */
 static int handle_response_peerpoke(struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int seqno);
 
+/*------Response handling functions */
+static void handle_response_invite(struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int seqno);
+static void handle_response_refer(struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int seqno);
+
 /*----- 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 struct ast_rtp *sip_get_rtp_peer(struct ast_channel *chan);
@@ -1140,14 +1144,21 @@
 	return "";
 }
 
-/*! \brief Interface structure with callbacks used to connect to RTP module */
-static struct ast_rtp_protocol sip_rtp = {
-	type: "SIP",
-	get_rtp_info: sip_get_rtp_peer,
-	get_vrtp_info: sip_get_vrtp_peer,
-	set_rtp_peer: sip_set_rtp_peer,
-	get_codec: sip_get_codec,
-};
+/*! \brief Initialize the initital request packet in the pvt structure.
+ 	This packet is used for creating replies and future requests in
+	a dialog */
+void initialize_initreq(struct sip_pvt *p, struct sip_request *req)
+{
+	if (p->initreq.headers) {
+		ast_log(LOG_WARNING, "Initializing already initialized SIP dialog??? %s\n", p->callid);
+		return;
+	}
+	/* Use this as the basis */
+	copy_request(&p->initreq, req);
+	parse_request(&p->initreq);
+	if (ast_test_flag(req, SIP_PKT_DEBUG))
+		ast_verbose("%d headers, %d lines\n", p->initreq.headers, p->initreq.lines);
+}
 
 /*! \brief returns true if 'name' (with optional trailing whitespace)
  * matches the sip method 'id'.
@@ -2186,8 +2197,6 @@
 }
 
 
-
-
 /*! \brief Initiate SIP call from PBX 
  *      used from the dial() application      */
 static int sip_call(struct ast_channel *ast, char *dest, int timeout)
@@ -2232,8 +2241,6 @@
 	
 	res = 0;
 	ast_set_flag(&p->flags[0], SIP_OUTGOING);
-	if (option_debug)
-		ast_log(LOG_DEBUG, "Outgoing Call for %s\n", p->username);
 
 	if (p->options->transfer) {
 		char buf[BUFSIZ/2];
@@ -2246,7 +2253,8 @@
 			snprintf(buf, sizeof(buf)-1, "-> %s", p->cid_name);
 		}
 		ast_string_field_set(p, cid_name, buf);
-	} else
+	} 
+	if (option_debug)
 		ast_log(LOG_DEBUG, "Outgoing Call for %s\n", p->username);
 
 	res = update_call_counter(p, INC_CALL_LIMIT);
@@ -2880,7 +2888,6 @@
 		ast_log(LOG_WARNING, "old channel wasn't %p but was %p\n", oldchan, p->owner);
 	else {
 		p->owner = newchan;
-		append_history(p, "Masq", "Old channel: %s\n", oldchan->name);
 		ret = 0;
 	}
 	if (option_debug > 2)
@@ -3465,6 +3472,12 @@
 	char totag[128];
 	char fromtag[128];
 	const char *callid = get_header(req, "Call-ID");
+	const char *from = get_header(req, "From");
+	const char *to = get_header(req, "To");
+	const char *cseq = get_header(req, "Cseq");
+
+	if (!callid || !to || !from || !cseq)		/* Call-ID, to, from and Cseq are required by RFC 3261. (Max-forwards and via too - ignored now) */
+		return NULL;	/* Invalid packet */
 
 	if (pedanticsipchecking) {
 		/* In principle Call-ID's uniquely identify a call, but with a forking SIP proxy
@@ -3647,7 +3660,9 @@
 	return t; 
 }
 
-/*! \brief Parse a SIP message */
+/*! \brief Parse a SIP message 
+	\note this function is used both on incoming and outgoing packets
+*/
 static void parse_request(struct sip_request *req)
 {
 	/* Divide fields by NULL's */
@@ -4939,10 +4954,8 @@
 static int transmit_reinvite_with_sdp(struct sip_pvt *p)
 {
 	struct sip_request req;
-	if (ast_test_flag(&p->flags[0], SIP_REINVITE_UPDATE))
-		reqprep(&req, p, SIP_UPDATE, 0, 1);
-	else 
-		reqprep(&req, p, SIP_INVITE, 0, 1);
+
+	reqprep(&req, p, ast_test_flag(&p->flags[0], SIP_REINVITE_UPDATE) ?  SIP_UPDATE : SIP_INVITE, 0, 1);
 	
 	add_header(&req, "Allow", ALLOWED_METHODS);
 	add_header(&req, "Supported", SUPPORTED_EXTENSIONS);
@@ -4952,10 +4965,7 @@
 		append_history(p, "ReInv", "Re-invite sent");
 	add_sdp(&req, p);
 	/* Use this as the basis */
-	copy_request(&p->initreq, &req);
-	parse_request(&p->initreq);
-	if (sip_debug_test_pvt(p))
-		ast_verbose("%d headers, %d lines\n", p->initreq.headers, p->initreq.lines);
+	initialize_initreq(p, &req);
 	p->lastinvite = p->ocseq;
 	ast_set_flag(&p->flags[0], SIP_OUTGOING);
 	return send_request(p, &req, 1, p->ocseq);
@@ -5300,13 +5310,8 @@
 		add_blank_header(&req);
 	}
 
-	if (!p->initreq.headers) {
-		/* Use this as the basis */
-		copy_request(&p->initreq, &req);
-		parse_request(&p->initreq);
-		if (sip_debug_test_pvt(p))
-			ast_verbose("%d headers, %d lines\n", p->initreq.headers, p->initreq.lines);
-	}
+	if (!p->initreq.headers)
+		initialize_initreq(p, &req);
 	p->lastinvite = p->ocseq;
 	return send_request(p, &req, init ? 2 : 1, p->ocseq);
 }
@@ -5509,29 +5514,16 @@
 	add_header_contentLength(&req, strlen(tmp));
 	add_line(&req, tmp);
 
-	if (!p->initreq.headers) { /* Use this as the basis */
-		copy_request(&p->initreq, &req);
-		parse_request(&p->initreq);
-		if (sip_debug_test_pvt(p))
-			ast_verbose("%d headers, %d lines\n", p->initreq.headers, p->initreq.lines);
-		determine_firstline_parts(&p->initreq);
-	}
-
+	if (!p->initreq.headers) 
+		initialize_initreq(p, &req);
 	return send_request(p, &req, 1, p->ocseq);
 }
 
 /*! \brief Transmit SIP request */
 static int transmit_sip_request(struct sip_pvt *p,struct sip_request *req)
 {
-	if (!p->initreq.headers) {
-		/* Use this as the basis */
-		copy_request(&p->initreq, req);
-		parse_request(&p->initreq);
-		if (sip_debug_test_pvt(p))
-			ast_verbose("%d headers, %d lines\n", p->initreq.headers, p->initreq.lines);
-		determine_firstline_parts(&p->initreq);
-	}
-
+	if (!p->initreq.headers) 
+		initialize_initreq(p, req);
 	return send_request(p, req, 0, p->ocseq);
 }
 
@@ -5553,14 +5545,9 @@
 	add_header_contentLength(&req, strlen(tmp));
 	add_line(&req, tmp);
 
-	if (!p->initreq.headers) {
-		/* Use this as the basis */
-		copy_request(&p->initreq, &req);
-		parse_request(&p->initreq);
-		if (sip_debug_test_pvt(p))
-			ast_verbose("%d headers, %d lines\n", p->initreq.headers, p->initreq.lines);
-		determine_firstline_parts(&p->initreq);
-	}
+	
+	if (!p->initreq.headers)
+		initialize_initreq(p, &req);
 
 	return send_request(p, &req, 1, p->ocseq);
 }
@@ -5836,12 +5823,10 @@
 	add_header(&req, "Event", "registration");
 	add_header_contentLength(&req, 0);
 	add_blank_header(&req);
-	copy_request(&p->initreq, &req);
-	parse_request(&p->initreq);
-	if (sip_debug_test_pvt(p)) {
+
+	initialize_initreq(p, &req);
+	if (sip_debug_test_pvt(p))
 		ast_verbose("REGISTER %d headers, %d lines\n", p->initreq.headers, p->initreq.lines);
-	}
-	determine_firstline_parts(&p->initreq);
 	r->regstate = auth ? REG_STATE_AUTHSENT : REG_STATE_REGSENT;
 	r->regattempts++;	/* Another attempt */
 	if (option_debug > 3)
@@ -5861,13 +5846,8 @@
 
 /*! \brief Allocate SIP refer structure */
 int sip_refer_allocate(struct sip_pvt *p) {
-   p->refer = malloc(sizeof(struct sip_refer));
-   if (!p->refer) {
-      ast_log(LOG_ERROR, "Can't allocate memory for SIP transfer. \n");
-      return 0;
-   }
-   memset(p->refer, 0, sizeof(struct sip_refer));
-   return 1;
+   p->refer = ast_calloc(1, sizeof(struct sip_refer)); 
+   return p->refer ? 1 : 0;
 }
 
 /*! \brief Transmit SIP REFER message */
@@ -5993,10 +5973,12 @@
 	}
 	/* If we are hanging up and know a cause for that, send it in clear text to make
 		debugging easier. */
-	if (sipmethod == SIP_BYE) {
-		if (p->owner && p->owner->hangupcause)	{
-			add_header(&resp, "X-Asterisk-HangupCause", ast_cause2str(p->owner->hangupcause));
-		}
+	if (sipmethod == SIP_BYE && p->owner && p->owner->hangupcause)	{
+		char buf[10];
+
+		add_header(&resp, "X-Asterisk-HangupCause", ast_cause2str(p->owner->hangupcause));
+		snprintf(buf, sizeof(buf), "%d", p->owner->hangupcause);
+		add_header(&resp, "X-Asterisk-HangupCauseCode", buf);
 	}
 
 	add_header_contentLength(&resp, 0);
@@ -9964,7 +9946,7 @@
 }
 
 /*! \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);
 	
@@ -9983,39 +9965,39 @@
 
 	switch (resp) {
 	case 100:	/* Trying */
-		if (!ignore)
+		if (!ast_test_flag(req, SIP_PKT_IGNORE))
 			sip_cancel_destroy(p);
 		break;
 	case 180:	/* 180 Ringing */
-		if (!ignore)
+		if (!ast_test_flag(req, SIP_PKT_IGNORE))
 			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);
 			if (p->owner->_state != AST_STATE_UP)
 				ast_setstate(p->owner, AST_STATE_RINGING);
 		}
 		if (!strcasecmp(get_header(req, "Content-Type"), "application/sdp")) {
 			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 */
 				ast_queue_control(p->owner, AST_CONTROL_PROGRESS);
 			}
 		}
 		break;
 	case 183:	/* Session progress */
-		if (!ignore)
+		if (!ast_test_flag(req, SIP_PKT_IGNORE))
 			sip_cancel_destroy(p);
 		/* Ignore 183 Session progress without SDP */
 		if (!strcasecmp(get_header(req, "Content-Type"), "application/sdp")) {
 			process_sdp(p, req);
-			if (!ignore && p->owner) {
+			if (!ast_test_flag(req, SIP_PKT_IGNORE) && p->owner) {
 				/* Queue a progress frame */
 				ast_queue_control(p->owner, AST_CONTROL_PROGRESS);
 			}
 		}
 		break;
 	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);
 		p->authtries = 0;
 		if (!strcasecmp(get_header(req, "Content-Type"), "application/sdp")) 
@@ -10034,7 +10016,7 @@
 					should we care about resolving the contact
 					or should we just send it?
 				*/
-				if (!ignore)
+				if (!ast_test_flag(req, SIP_PKT_IGNORE))
 					ast_set_flag(&p->flags[0], SIP_PENDINGBYE);	
 			} 
 
@@ -10042,7 +10024,7 @@
 			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) {
 				ast_queue_control(p->owner, AST_CONTROL_ANSWER);
 			} else {	/* RE-invite */
@@ -10052,7 +10034,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 (!ignore)
+			if (!ast_test_flag(req, SIP_PKT_IGNORE))
 				ast_set_flag(&p->flags[0], SIP_PENDINGBYE);	
 		}
 		/* If I understand this right, the branch is different for a non-200 ACK only */
@@ -10068,7 +10050,7 @@
 
 		/* Then we AUTH */
 		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 *authorization = (resp == 401 ? "Authorization" : "Proxy-Authorization");
 			if ((p->authtries == MAX_AUTHTRIES) || do_proxy_auth(p, req, authenticate, authorization, SIP_INVITE, 1)) {
@@ -10084,14 +10066,14 @@
 		/* First we ACK */
 		transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, 0);
 		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_set_flag(&p->flags[0], SIP_NEEDDESTROY);	
 		ast_set_flag(&p->flags[0], SIP_ALREADYGONE);	
 		break;
 	case 404: /* Not found */
 		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_set_flag(&p->flags[0], SIP_ALREADYGONE);	
 		break;
@@ -10118,7 +10100,7 @@
    not follow up outbound REFERs caused by app transfer()
    at all...
    */
-static void handle_response_refer(struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int ignore, int seqno)
+static void handle_response_refer(struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int seqno)
 {
 	char *auth = "Proxy-Authenticate";
 	char *auth2 = "Proxy-Authorization";
@@ -10387,15 +10369,15 @@
 		switch(resp) {
 		case 100:	/* 100 Trying */
 			if (sipmethod == SIP_INVITE) 
-				handle_response_invite(p, resp, rest, req, ignore, seqno);
+				handle_response_invite(p, resp, rest, req, seqno);
 			break;
 		case 183:	/* 183 Session Progress */
 			if (sipmethod == SIP_INVITE) 
-				handle_response_invite(p, resp, rest, req, ignore, seqno);
+				handle_response_invite(p, resp, rest, req, seqno);
 			break;
 		case 180:	/* 180 Ringing */
 			if (sipmethod == SIP_INVITE) 
-				handle_response_invite(p, resp, rest, req, ignore, seqno);
+				handle_response_invite(p, resp, rest, req, seqno);
 			break;
 		case 200:	/* 200 OK */
 			p->authtries = 0;	/* Reset authentication counter */
@@ -10418,19 +10400,19 @@
 					}
 				}
 			} 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)
 				res = handle_response_register(p, resp, rest, req, ignore, seqno);
 			break;
 		case 202:   /* Transfer accepted */
 			if (sipmethod == SIP_REFER) 
-				handle_response_refer(p, resp, rest, req, ignore, seqno);
+				handle_response_refer(p, resp, rest, req, seqno);
 			break;
 		case 401: /* Not www-authorized on SIP method */
 			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)
-				handle_response_refer(p, resp, rest, req, ignore, seqno);
+				handle_response_refer(p, resp, rest, req, seqno);
 			else if (p->registry && sipmethod == SIP_REGISTER)
 				res = handle_response_register(p, resp, rest, req, ignore, seqno);
 			else {
@@ -10440,7 +10422,7 @@
 			break;
 		case 403: /* Forbidden - we failed authentication */
 			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) 
 				res = handle_response_register(p, resp, rest, req, ignore, seqno);
 			else {
@@ -10452,15 +10434,15 @@
 			if (p->registry && sipmethod == SIP_REGISTER)
 				res = handle_response_register(p, resp, rest, req, ignore, seqno);
 			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)
 				ast_queue_control(p->owner, AST_CONTROL_CONGESTION);
 			break;
 		case 407: /* Proxy auth required */
 			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)
-				handle_response_refer(p, resp, rest, req, ignore, seqno);
+				handle_response_refer(p, resp, rest, req, seqno);
 			else if (p->registry && sipmethod == SIP_REGISTER)
 				res = handle_response_register(p, resp, rest, req, ignore, seqno);
 			else if (sipmethod == SIP_BYE) {
@@ -10507,7 +10489,7 @@
 			break;
 		case 491: /* Pending */
 			if (sipmethod == SIP_INVITE)
-				handle_response_invite(p, resp, rest, req, ignore, seqno);
+				handle_response_invite(p, resp, rest, req, seqno);
 			else {
 				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);	
@@ -10515,15 +10497,15 @@
 			break;
 		case 501: /* Not Implemented */
 			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)
-				handle_response_refer(p, resp, rest, req, ignore, seqno);
+				handle_response_refer(p, resp, rest, req, seqno);
 			else
 				ast_log(LOG_WARNING, "Host '%s' does not implement '%s'\n", ast_inet_ntoa(iabuf, sizeof(iabuf), p->sa.sin_addr), msg);
 			break;
 		case 603:	/* Declined transfer */
 			if (sipmethod == SIP_REFER) {
-				handle_response_refer(p, resp, rest, req, ignore, seqno);
+				handle_response_refer(p, resp, rest, req, seqno);
 				break;
 			}
 			/* Fallthrough */
@@ -10576,11 +10558,10 @@
 				case 400: /* Bad Request */
 				case 500: /* Server error */
 					if (sipmethod == SIP_REFER) {
-						handle_response_refer(p, resp, rest, req, ignore, seqno);
+						handle_response_refer(p, resp, rest, req, seqno);
 						break;
 					}
 					/* Fall through */
-				handle_response_refer(p, resp, rest, req, ignore, seqno);
 				case 503: /* Service Unavailable */
 					if (owner)
 						ast_queue_control(p->owner, AST_CONTROL_CONGESTION);
@@ -10633,7 +10614,7 @@
 			} else if (sipmethod == SIP_INVITE) {
 				/* 200 OK on an INVITE for inbound call
 					means re-invite */
-				handle_response_invite(p, resp, rest, req, ignore, seqno);
+				handle_response_invite(p, resp, rest, req, seqno);
 			} else if (sipmethod == SIP_NOTIFY) {
 				/* They got the notify, this is the end */
 				if (p->owner) {
@@ -10651,14 +10632,14 @@
 			break;
 		case 202:   /* Transfer accepted */
 			if (sipmethod == SIP_REFER) 
-				handle_response_refer(p, resp, rest, req, ignore, seqno);
+				handle_response_refer(p, resp, rest, req, seqno);
 			break;
 		case 401:	/* www-auth */
 		case 407:
 			if (sipmethod == SIP_REFER)
-				handle_response_refer(p, resp, rest, req, ignore, seqno);
+				handle_response_refer(p, resp, rest, req, seqno);
 			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) {
 				char *auth, *auth2;
 
@@ -10673,20 +10654,20 @@
 		case 481:	/* Call leg does not exist */
 			if (sipmethod == SIP_INVITE) {
 				/* Re-invite failed */
-				handle_response_invite(p, resp, rest, req, ignore, seqno);
+				handle_response_invite(p, resp, rest, req, seqno);
 			} else {
 				ast_log(LOG_WARNING, "Remote host can't match request %s to call '%s'. Giving up.\n", sip_methods[sipmethod].text, p->callid);
 			}
 			break;
 		case 501: /* Not Implemented */
 			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) 
-				handle_response_refer(p, resp, rest, req, ignore, seqno);
+				handle_response_refer(p, resp, rest, req, seqno);
 			break;
 		case 603:	/* Declined transfer */
 			if (sipmethod == SIP_REFER) {
-				handle_response_refer(p, resp, rest, req, ignore, seqno);
+				handle_response_refer(p, resp, rest, req, seqno);
 				break;
 			}
 			/* Fallthrough */
@@ -12709,18 +12690,18 @@
 			ast_log(LOG_WARNING, "Recv error: %s\n", strerror(errno));
 		return 1;
 	}
-	if (res == sizeof(req.data)) {
+	if (option_debug && res == sizeof(req.data))
 		ast_log(LOG_DEBUG, "Received packet exceeds buffer. Data is possibly lost\n");
-	}
+
 	req.data[res] = '\0';
 	req.len = res;
-	if(sip_debug_test_addr(&sin))
+	if(sip_debug_test_addr(&sin))	/* Set the debug flag early on packet level */
 		ast_set_flag(&req, SIP_PKT_DEBUG);
 	if (pedanticsipchecking)
 		req.len = lws2sws(req.data, req.len);	/* Fix multiline headers */
-	if (ast_test_flag(&req, SIP_PKT_DEBUG)) {
+	if (ast_test_flag(&req, SIP_PKT_DEBUG))
 		ast_verbose("\n<-- SIP read from %s:%d: \n%s\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr), ntohs(sin.sin_port), req.data);
-	}
+
 	parse_request(&req);
 	req.method = find_sip_method(req.rlPart1);
 	if (ast_test_flag(&req, SIP_PKT_DEBUG)) {
@@ -12744,7 +12725,8 @@
 		/* Go ahead and lock the owner if it has one -- we may need it */
 		/* becaues this is deadlock-prone, we need to try and unlock if failed */
 		if (p->owner && ast_mutex_trylock(&p->owner->lock)) {
-			ast_log(LOG_DEBUG, "Failed to grab lock, trying again...\n");
+			if (option_debug)
+				ast_log(LOG_DEBUG, "Failed to grab lock, trying again...\n");
 			ast_mutex_unlock(&p->lock);
 			ast_mutex_unlock(&netlock);
 			/* Sleep infintismly short amount of time */
@@ -12752,17 +12734,21 @@
 			goto retrylock;
 		}
 		p->recv = sin;
-		if (recordhistory) /* This is a response, note what it was for */
+		if (recordhistory) /* This is a request or response, note what it was for */
 			append_history(p, "Rx", "%s / %s / %s", req.data, get_header(&req, "CSeq"), req.rlPart2);
 		nounlock = 0;
 		if (handle_request(p, &req, &sin, &recount, &nounlock) == -1) {
 			/* Request failed */
-			ast_log(LOG_DEBUG, "SIP message could not be handled, bad request: %-70.70s\n", p->callid[0] ? p->callid : "<no callid>");
+			if (option_debug)
+				ast_log(LOG_DEBUG, "SIP message could not be handled, bad request: %-70.70s\n", p->callid[0] ? p->callid : "<no callid>");
 		}
 		
 		if (p->owner && !nounlock)
 			ast_mutex_unlock(&p->owner->lock);
 		ast_mutex_unlock(&p->lock);
+	} else {
+		if (option_debug)
+			ast_log(LOG_DEBUG, "Invalid SIP message - rejected , bad request: %-70.70s\n", p->callid[0] ? p->callid : "<no callid>");
 	}
 	ast_mutex_unlock(&netlock);
 	if (recount)



More information about the asterisk-commits mailing list