[svn-commits] trunk - r7319 /trunk/channels/chan_sip.c

svn-commits at lists.digium.com svn-commits at lists.digium.com
Sat Dec 3 17:35:17 CST 2005


Author: russell
Date: Sat Dec  3 17:35:15 2005
New Revision: 7319

URL: http://svn.digium.com/view/asterisk?rev=7319&view=rev
Log:
add the 'sip debug' options to the set of global flags and fix some compiler warnings

Modified:
    trunk/channels/chan_sip.c

Modified: trunk/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_sip.c?rev=7319&r1=7318&r2=7319&view=diff
==============================================================================
--- trunk/channels/chan_sip.c (original)
+++ trunk/channels/chan_sip.c Sat Dec  3 17:35:15 2005
@@ -409,9 +409,6 @@
 static struct sockaddr_in outboundproxyip;
 static int ourport;
 
-#define SIP_DEBUG_CONFIG 1 << 0
-#define SIP_DEBUG_CONSOLE 1 << 1
-static int sipdebug = 0;
 static struct sockaddr_in debugaddr;
 
 static int tos = 0;
@@ -571,10 +568,17 @@
 #define SIP_PAGE2_RTAUTOCLEAR		(1 << 2)
 #define SIP_PAGE2_IGNOREREGEXPIRE	(1 << 3)
 #define SIP_PAGE2_RT_FROMCONTACT 	(1 << 4)
+#define SIP_PAGE2_DEBUG			(3 << 5)
+#define SIP_PAGE2_DEBUG_CONFIG 		(1 << 5)
+#define SIP_PAGE2_DEBUG_CONSOLE 	(1 << 6)
 
 /* SIP packet 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_DEBUG		ast_test_flag(&global_flags_page2, SIP_PAGE2_DEBUG)
+#define SIP_DEBUG_CONFIG	ast_test_flag(&global_flags_page2, SIP_PAGE2_DEBUG_CONFIG)
+#define SIP_DEBUG_CONSOLE	ast_test_flag(&global_flags_page2, SIP_PAGE2_DEBUG_CONSOLE)
 
 static int global_rtautoclear = 120;
 
@@ -991,7 +995,7 @@
 	if (ast_strlen_zero(supported) )
 		return 0;
 
-	if (option_debug > 2 && sipdebug)
+	if (option_debug > 2 && SIP_DEBUG)
 		ast_log(LOG_DEBUG, "Begin: parsing SIP \"Supported: %s\"\n", supported);
 
 	next = temp;
@@ -1003,18 +1007,18 @@
 		}
 		while (*next == ' ')	/* Skip spaces */
 			next++;
-		if (option_debug > 2 && sipdebug)
+		if (option_debug > 2 && SIP_DEBUG)
 			ast_log(LOG_DEBUG, "Found SIP option: -%s-\n", next);
 		for (i=0; (i < (sizeof(sip_options) / sizeof(sip_options[0]))) && !res; i++) {
 			if (!strcasecmp(next, sip_options[i].text)) {
 				profile |= sip_options[i].id;
 				res = 1;
-				if (option_debug > 2 && sipdebug)
+				if (option_debug > 2 && SIP_DEBUG)
 					ast_log(LOG_DEBUG, "Matched SIP option: %s\n", next);
 			}
 		}
 		if (!res) 
-			if (option_debug > 2 && sipdebug)
+			if (option_debug > 2 && SIP_DEBUG)
 				ast_log(LOG_DEBUG, "Found no match for SIP option: %s (Please file bug report!)\n", next);
 		next = sep;
 	}
@@ -1029,7 +1033,7 @@
 /*! \brief  sip_debug_test_addr: See if we pass debug IP filter */
 static inline int sip_debug_test_addr(struct sockaddr_in *addr) 
 {
-	if (sipdebug == 0)
+	if (!SIP_DEBUG)
 		return 0;
 	if (debugaddr.sin_addr.s_addr) {
 		if (((ntohs(debugaddr.sin_port) != 0)
@@ -1043,7 +1047,7 @@
 /*! \brief  sip_debug_test_pvt: Test PVT for debugging output */
 static inline int sip_debug_test_pvt(struct sip_pvt *p) 
 {
-	if (sipdebug == 0)
+	if (!SIP_DEBUG)
 		return 0;
 	return sip_debug_test_addr(((ast_test_flag(p, SIP_NAT) & SIP_NAT_ROUTE) ? &p->recv : &p->sa));
 }
@@ -1166,12 +1170,12 @@
 
 		pkt->retrans++;
  		if (!pkt->timer_t1) {	/* Re-schedule using timer_a and timer_t1 */
-			if (sipdebug && option_debug > 3)
+			if (SIP_DEBUG && option_debug > 3)
  				ast_log(LOG_DEBUG, "SIP TIMER: Not rescheduling id #%d:%s (Method %d) (No timer T1)\n", pkt->retransid, sip_methods[pkt->method].text, pkt->method);
 		} else {
  			int siptimer_a;
 
- 			if (sipdebug && option_debug > 3)
+ 			if (SIP_DEBUG && option_debug > 3)
  				ast_log(LOG_DEBUG, "SIP TIMER: Rescheduling retransmission #%d (%d) %s - %d\n", pkt->retransid, pkt->retrans, sip_methods[pkt->method].text, pkt->method);
  			if (!pkt->timer_a)
  				pkt->timer_a = 2 ;
@@ -1204,10 +1208,8 @@
 	} 
 	/* Too many retries */
 	if (pkt->owner && pkt->method != SIP_OPTIONS) {
-		if (ast_test_flag(pkt, FLAG_FATAL) || sipdebug)	/* Tell us if it's critical or if we're debugging */
-			ast_log(LOG_WARNING, "Maximum retries exceeded on transmission %s for seqno %d (%s %s)\n", pkt->owner->callid, pkt->seqno, (ast_test_flag(pkt, FLAG_FATAL)) ? "Critical" : "Non-critical", (ast_test_flag(pkt, FLAG_RESPONSE)) ? "Response" : "Request");
-	} else {
-		if (pkt->method == SIP_OPTIONS && sipdebug)
+		if (ast_test_flag(pkt, FLAG_FATAL) || SIP_DEBUG)	/* Tell us if it's critical or if we're debugging */ ast_log(LOG_WARNING, "Maximum retries exceeded on transmission %s for seqno %d (%s %s)\n", pkt->owner->callid, pkt->seqno, (ast_test_flag(pkt, FLAG_FATAL)) ? "Critical" : "Non-critical", (ast_test_flag(pkt, FLAG_RESPONSE)) ? "Response" : "Request"); } else {
+		if ((pkt->method == SIP_OPTIONS) && SIP_DEBUG)
 			ast_log(LOG_WARNING, "Cancelling retransmit of OPTIONs (call id %s) \n", pkt->owner->callid);
 	}
 	append_history(pkt->owner, "MaxRetries", (ast_test_flag(pkt, FLAG_FATAL)) ? "(Critical)" : "(Non-critical)");
@@ -1280,7 +1282,7 @@
 
 	/* Schedule retransmission */
 	pkt->retransid = ast_sched_add_variable(sched, siptimer_a, retrans_pkt, pkt, 1);
-	if (option_debug > 3 && sipdebug)
+	if (option_debug > 3 && SIP_DEBUG)
 		ast_log(LOG_DEBUG, "*** SIP TIMER: Initalizing retransmit timer on packet: Id  #%d\n", pkt->retransid);
 	pkt->next = p->packets;
 	p->packets = pkt;
@@ -1374,7 +1376,7 @@
 			else
 				p->packets = cur->next;
 			if (cur->retransid > -1) {
-				if (sipdebug && option_debug > 3)
+				if (SIP_DEBUG && option_debug > 3)
 					ast_log(LOG_DEBUG, "** SIP TIMER: Cancelling retransmit of packet (reply received) Retransid #%d\n", cur->retransid);
 				ast_sched_del(sched, cur->retransid);
 			}
@@ -1429,7 +1431,7 @@
 			 (!strncasecmp(msg, cur->data, strlen(msg)) && (cur->data[strlen(msg)] < 33)))) {
 			/* this is our baby */
 			if (cur->retransid > -1) {
-				if (option_debug > 3 && sipdebug)
+				if (option_debug > 3 && SIP_DEBUG)
 					ast_log(LOG_DEBUG, "*** SIP TIMER: Cancelling retransmission #%d - %s (got response)\n", cur->retransid, msg);
 				ast_sched_del(sched, cur->retransid);
 			}
@@ -2228,7 +2230,7 @@
 			} else {
 				*inuse = 0;
 			}
-			if (option_debug > 1 || sipdebug) {
+			if (option_debug > 1 || SIP_DEBUG) {
 				ast_log(LOG_DEBUG, "Call %s %s '%s' removed from call limit %d\n", outgoing ? "to" : "from", u ? "user":"peer", name, *call_limit);
 			}
 			break;
@@ -2244,7 +2246,7 @@
 				}
 			}
 			(*inuse)++;
-			if (option_debug > 1 || sipdebug) {
+			if (option_debug > 1 || SIP_DEBUG) {
 				ast_log(LOG_DEBUG, "Call %s %s '%s' is %d out of %d\n", outgoing ? "to" : "from", u ? "user":"peer", name, *inuse, *call_limit);
 			}
 			break;
@@ -2676,12 +2678,12 @@
 		res = -1;
 		break;
 	case AST_CONTROL_HOLD:	/* The other part of the bridge are put on hold */
-		if (sipdebug)
+		if (SIP_DEBUG)
 			ast_log(LOG_DEBUG, "Bridged channel now on hold%s\n", p->callid);
 		res = -1;
 		break;
 	case AST_CONTROL_UNHOLD:	/* The other part of the bridge are back from hold */
-		if (sipdebug)
+		if (SIP_DEBUG)
 			ast_log(LOG_DEBUG, "Bridged channel is back from hold, let's talk! : %s\n", p->callid);
 		res = -1;
 		break;
@@ -3313,7 +3315,7 @@
 			/* We've got a new header */
 			*c = 0;
 
-			if (sipdebug && option_debug > 3)
+			if (SIP_DEBUG && option_debug > 3)
 				ast_log(LOG_DEBUG, "Header %d: %s (%d)\n", f, req->header[f], (int) strlen(req->header[f]));
 			if (ast_strlen_zero(req->header[f])) {
 				/* Line by itself means we're now in content */
@@ -3333,7 +3335,7 @@
 	}
 	/* Check for last header */
 	if (!ast_strlen_zero(req->header[f])) {
-		if (sipdebug && option_debug > 3)
+		if (SIP_DEBUG && option_debug > 3)
 			ast_log(LOG_DEBUG, "Header %d: %s (%d)\n", f, req->header[f], (int) strlen(req->header[f]));
 		f++;
 	}
@@ -3345,7 +3347,7 @@
 		if (*c == '\n') {
 			/* We've got a new line */
 			*c = 0;
-			if (sipdebug && option_debug > 3)
+			if (SIP_DEBUG && option_debug > 3)
 				ast_log(LOG_DEBUG, "Line: %s (%d)\n", req->line[f], (int) strlen(req->line[f]));
 			if (f >= SIP_MAX_LINES - 1) {
 				ast_log(LOG_WARNING, "Too many SDP lines. Ignoring.\n");
@@ -4578,7 +4580,7 @@
 		reqprep(&req, p, SIP_INVITE, 0, 1);
 	
 	add_header(&req, "Allow", ALLOWED_METHODS);
-	if (sipdebug)
+	if (SIP_DEBUG)
 		add_header(&req, "X-asterisk-info", "SIP re-invite (RTP bridge)");
 	ast_rtp_offered_from_local(p->rtp, 1);
 	add_sdp(&req, p);
@@ -4879,11 +4881,11 @@
 	add_header(&req, "Allow", ALLOWED_METHODS);
 	if (p->options && p->options->addsipheaders ) {
 		struct ast_channel *ast;
-		char *header = (char *) NULL;
+		const char *header = (char *) NULL;
 		char *content = (char *) NULL;
 		char *end = (char *) NULL;
 		struct varshead *headp = (struct varshead *) NULL;
-		struct ast_var_t *current;
+		const struct ast_var_t *current;
 
 		ast = p->owner;	/* The owner channel */
 		if (ast) {
@@ -4912,7 +4914,7 @@
 								*end = '\0';
 						
 							add_header(&req, headdup, content);
-							if (sipdebug)
+							if (SIP_DEBUG)
 								ast_log(LOG_DEBUG, "Adding SIP Header \"%s\" with content :%s: \n", headdup, content);
 						}
 					}
@@ -5233,7 +5235,7 @@
 	}
 	/* Since registry's are only added/removed by the the monitor thread, this
 	   may be overkill to reference/dereference at all here */
-	if (sipdebug)
+	if (SIP_DEBUG)
 		ast_log(LOG_NOTICE, "   -- Re-registration for  %s@%s\n", r->username, r->hostname);
 
 	r->expire = -1;
@@ -5447,7 +5449,7 @@
 		char digest[1024];
 
 		/* We have auth data to reuse, build a digest header! */
-		if (sipdebug)
+		if (SIP_DEBUG)
 			ast_log(LOG_DEBUG, "   >>> Re-using Auth data for %s@%s\n", r->username, r->hostname);
 		ast_copy_string(p->realm, r->realm, sizeof(p->realm));
 		ast_copy_string(p->nonce, r->nonce, sizeof(p->nonce));
@@ -6271,13 +6273,13 @@
 
 			snprintf(randdata, randlen, "%08x", thread_safe_rand());
 			if (ua_hash && !strncasecmp(ua_hash, resp_hash, strlen(resp_hash))) {
-				if (sipdebug)
+				if (SIP_DEBUG)
 					ast_log(LOG_NOTICE, "stale nonce received from '%s'\n", get_header(req, "To"));
 				/* We got working auth token, based on stale nonce . */
 				transmit_response_with_auth(p, response, req, randdata, reliable, respheader, 1);
 			} else {
 				/* Everything was wrong, so give the device one more try with a new challenge */
-				if (sipdebug)
+				if (SIP_DEBUG)
 					ast_log(LOG_NOTICE, "Bad authentication received from '%s'\n", get_header(req, "To"));
 				transmit_response_with_auth(p, response, req, randdata, reliable, respheader, 0);
 			}
@@ -8616,7 +8618,7 @@
 			/* send a FLASH event */
 			struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_FLASH, };
 			ast_queue_frame(p->owner, &f);
-			if (sipdebug)
+			if (SIP_DEBUG)
 				ast_verbose("* DTMF-relay event received: FLASH\n");
 		} else {
 			/* send a DTMF event */
@@ -8631,7 +8633,7 @@
 				f.subclass = 'A' + (event - 12);
 			}
 			ast_queue_frame(p->owner, &f);
-			if (sipdebug)
+			if (SIP_DEBUG)
 				ast_verbose("* DTMF-relay event received: %c\n", f.subclass);
 		}
 		transmit_response(p, "200 OK", req);
@@ -8692,7 +8694,9 @@
 		ast_cli(fd, "SIP Debugging Enabled for IP: %s\n", ast_inet_ntoa(iabuf, sizeof(iabuf), debugaddr.sin_addr));
 	else
 		ast_cli(fd, "SIP Debugging Enabled for IP: %s:%d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), debugaddr.sin_addr), port);
-	sipdebug |= SIP_DEBUG_CONSOLE;
+
+	ast_set_flag(&global_flags_page2, SIP_PAGE2_DEBUG_CONSOLE);
+
 	return RESULT_SUCCESS;
 }
 
@@ -8710,7 +8714,7 @@
 			memcpy(&debugaddr.sin_addr, &peer->addr.sin_addr, sizeof(debugaddr.sin_addr));
 			debugaddr.sin_port = peer->addr.sin_port;
 			ast_cli(fd, "SIP Debugging Enabled for IP: %s:%d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), debugaddr.sin_addr), ntohs(debugaddr.sin_port));
-			sipdebug |= SIP_DEBUG_CONSOLE;
+			ast_set_flag(&global_flags_page2, SIP_PAGE2_DEBUG_CONSOLE);
 		} else
 			ast_cli(fd, "Unable to get IP address of peer '%s'\n", argv[3]);
 		ASTOBJ_UNREF(peer,sip_destroy_peer);
@@ -8722,7 +8726,7 @@
 /*! \brief  sip_do_debug: Turn on SIP debugging (CLI command) */
 static int sip_do_debug(int fd, int argc, char *argv[])
 {
-	int oldsipdebug = sipdebug & SIP_DEBUG_CONSOLE;
+	int oldsipdebug = SIP_DEBUG_CONSOLE;
 	if (argc != 2) {
 		if (argc != 4) 
 			return RESULT_SHOWUSAGE;
@@ -8732,7 +8736,7 @@
 			return sip_do_debug_peer(fd, argc, argv);
 		else return RESULT_SHOWUSAGE;
 	}
-	sipdebug |= SIP_DEBUG_CONSOLE;
+	ast_set_flag(&global_flags_page2, SIP_PAGE2_DEBUG_CONSOLE);
 	memset(&debugaddr, 0, sizeof(debugaddr));
 	if (oldsipdebug)
 		ast_cli(fd, "SIP Debugging re-enabled\n");
@@ -8826,7 +8830,7 @@
 {
 	if (argc != 3)
 		return RESULT_SHOWUSAGE;
-	sipdebug &= ~SIP_DEBUG_CONSOLE;
+	ast_clear_flag(&global_flags_page2, SIP_PAGE2_DEBUG_CONSOLE);
 	ast_cli(fd, "SIP Debugging Disabled\n");
 	return RESULT_SUCCESS;
 }
@@ -8995,7 +8999,7 @@
  		username = auth->username;
  		secret = auth->secret;
  		md5secret = auth->md5secret;
-		if (sipdebug)
+		if (SIP_DEBUG)
  			ast_log(LOG_DEBUG,"Using realm %s authentication for call %s\n", p->realm, p->callid);
  	} else {
  		/* No authentication, use peer or register= config */
@@ -9657,7 +9661,7 @@
 			expires_ms -= MAX((expires_ms * EXPIRY_GUARD_PCT),EXPIRY_GUARD_MIN);
 		else
 			expires_ms -= EXPIRY_GUARD_SECS * 1000;
-		if (sipdebug)
+		if (SIP_DEBUG)
 			ast_log(LOG_NOTICE, "Outbound Registration: Expiry for %s is %d sec (Scheduling reregistration in %d s)\n", r->hostname, expires, expires_ms/1000); 
 
 		r->refresh= (int) expires_ms / 1000;
@@ -10372,7 +10376,7 @@
 		}
 		
 	} else {
-		if (option_debug > 1 && sipdebug)
+		if (option_debug > 1 && SIP_DEBUG)
 			ast_log(LOG_DEBUG, "Got a SIP re-invite for call %s\n", p->callid);
 		c = p->owner;
 	}
@@ -10780,7 +10784,7 @@
 			if (p->expiry > max_expiry)
 				p->expiry = max_expiry;
 		}
-		if (sipdebug || option_debug > 1)
+		if (SIP_DEBUG || option_debug > 1)
 			ast_log(LOG_DEBUG, "Adding subscription for extension %s context %s for peer %s\n", p->exten, p->context, p->username);
 		if (p->autokillid > -1)
 			sip_cancel_destroy(p);	/* Remove subscription expiry for renewals */
@@ -11355,7 +11359,7 @@
 		return 0;
 	}
 	if (peer->call > 0) {
-		if (sipdebug)
+		if (SIP_DEBUG)
 			ast_log(LOG_NOTICE, "Still have a QUALIFY dialog active, deleting\n");
 		sip_destroy(peer->call);
 	}
@@ -11682,7 +11686,7 @@
 	AST_LIST_INSERT_TAIL(&domain_list, d, list);
 	AST_LIST_UNLOCK(&domain_list);
 
- 	if (sipdebug)	
+ 	if (SIP_DEBUG)	
 		ast_log(LOG_DEBUG, "Added local SIP domain '%s'\n", domain);
 
 	return 1;
@@ -12252,7 +12256,7 @@
 	memset(&localaddr, 0, sizeof(localaddr));
 	memset(&externip, 0, sizeof(externip));
 	memset(&prefs, 0 , sizeof(prefs));
-	sipdebug &= ~SIP_DEBUG_CONFIG;
+	ast_clear_flag(&global_flags_page2, SIP_PAGE2_DEBUG_CONFIG);
 
 	/* Initialize some reasonable defaults at SIP reload */
 	ast_copy_string(default_context, DEFAULT_CONTEXT, sizeof(default_context));
@@ -12400,7 +12404,7 @@
 				default_expiry = DEFAULT_DEFAULT_EXPIRY;
 		} else if (!strcasecmp(v->name, "sipdebug")) {
 			if (ast_true(v->value))
-				sipdebug |= SIP_DEBUG_CONFIG;
+				ast_set_flag(&global_flags_page2, SIP_PAGE2_DEBUG_CONFIG);
 		} else if (!strcasecmp(v->name, "dumphistory")) {
 			dumphistory = ast_true(v->value);
 		} else if (!strcasecmp(v->name, "recordhistory")) {
@@ -12770,7 +12774,7 @@
 	int arglen;
 	int no = 0;
 	int ok = 0;
-	char *content = (char *) NULL;
+	const char *content = (char *) NULL;
 	char varbuf[128];
 	
 	arglen = strlen(data);
@@ -12791,7 +12795,7 @@
 	}
 	if (ok) {
 		pbx_builtin_setvar_helper (chan, varbuf, data);
-		if (sipdebug)
+		if (SIP_DEBUG)
 			ast_log(LOG_DEBUG,"SIP Header added \"%s\" as %s\n", (char *) data, varbuf);
 	} else {
 		ast_log(LOG_WARNING, "Too many SIP headers added, max 50\n");



More information about the svn-commits mailing list