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

svn-commits at lists.digium.com svn-commits at lists.digium.com
Thu Nov 23 05:21:45 MST 2006


Author: rizzo
Date: Thu Nov 23 06:21:44 2006
New Revision: 47961

URL: http://svn.digium.com/view/asterisk?view=rev&rev=47961
Log:
move the check for SIP_NO_HISTORY into append_history, which is a macro.
This lets the compiler do its optimizations (e.g. don't evaluate
arguments if not necessary), without requiring the programmer
to pollute the source with checks all over the place (and
without risking to forget some).

The function record_history() is still present for more complex
cases where commputing the append_history() arguments requires more work
than what could be done in a function call.

Certainly worth merging into 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=47961&r1=47960&r2=47961
==============================================================================
--- team/rizzo/astobj2/channels/chan_sip.c (original)
+++ team/rizzo/astobj2/channels/chan_sip.c Thu Nov 23 06:21:44 2006
@@ -1009,11 +1009,6 @@
 							you know more) */
 };
 
-static inline int record_history(const struct sip_pvt *p)
-{
-	return !ast_test_flag(&p->flags[0], SIP_NO_HISTORY);
-}
-
 #ifdef	USE_AO2	/* astobj2 implementation */
 #include "asterisk/astobj2.h"
 ao2_container *dialogs;
@@ -1518,7 +1513,6 @@
 static void sip_dump_history(struct sip_pvt *dialog);	/* Dump history to LOG_DEBUG at end of dialog, before destroying data */
 static inline int sip_debug_test_addr(const struct sockaddr_in *addr);
 static inline int sip_debug_test_pvt(struct sip_pvt *p);
-static void append_history_full(struct sip_pvt *p, const char *fmt, ...);
 static void sip_dump_history(struct sip_pvt *dialog);
 
 /*--- Device object handling */
@@ -1997,9 +1991,16 @@
 	return AST_SUCCESS;
 }
 
+static inline int record_history(const struct sip_pvt *p)
+{
+	return !ast_test_flag(&p->flags[0], SIP_NO_HISTORY);
+}
+
 /*! \brief Append to SIP dialog history 
 	\return Always returns 0 */
-#define append_history(p, event, fmt , args... )	append_history_full(p, "%-15s " fmt, event, ## args)
+#define append_history(p, event, fmt , args... )	do {	\
+	if (p && record_history(p))	append_history_full(p, "%-15s " fmt, event, ## args); \
+	} while (0)
 
 static void append_history_full(struct sip_pvt *p, const char *fmt, ...)
 	__attribute__ ((format (printf, 2, 3)));
@@ -2029,8 +2030,6 @@
 {
 	va_list ap;
 
-	if (!p)
-		return;
 	va_start(ap, fmt);
 	append_history_va(p, fmt, ap);
 	va_end(ap);
@@ -2249,8 +2248,7 @@
 	}
 	if (sip_debug_test_pvt(p))
 		ast_verbose("Scheduling destruction of SIP dialog '%s' in %d ms (Method: %s)\n", p->callid, ms, sip_methods[p->method].text);
-	if (record_history(p))
-		append_history(p, "SchedDestroy", "%d ms", ms);
+	append_history(p, "SchedDestroy", "%d ms", ms);
 
 	if (p->autokillid > -1)	/* cancel previous schedule, but keep the reference */
 		ast_sched_del(sched, p->autokillid);
@@ -4191,8 +4189,7 @@
 	for (v = i->chanvars ; v ; v = v->next)
 		pbx_builtin_setvar_helper(tmp,v->name,v->value);
 
-	if (record_history(i))
-		append_history(i, "NewChan", "Channel %s - from %s", tmp->name, i->callid);
+	append_history(i, "NewChan", "Channel %s - from %s", tmp->name, i->callid);
 
 	return tmp;
 }
@@ -6795,8 +6792,7 @@
 	add_header(&req, "Supported", SUPPORTED_EXTENSIONS);
 	if (sipdebug)
 		add_header(&req, "X-asterisk-Info", "SIP re-invite (External RTP bridge)");
-	if (record_history(p))
-		append_history(p, "ReInv", "Re-invite sent");
+	append_history(p, "ReInv", "Re-invite sent");
 	if (t38version)
 		add_t38_sdp(&req, p);
 	else
@@ -7526,8 +7522,7 @@
 			r->timeout = ast_sched_add(sched, global_reg_timeout*1000, sip_reg_timeout, r);
 			return 0;	/* non fatal error */
 		}
-		if (record_history(p))
-			append_history(p, "RegistryInit", "Account: %s@%s", r->username, r->hostname);
+		append_history(p, "RegistryInit", "Account: %s@%s", r->username, r->hostname);
 		/* Copy back Call-ID in case create_addr changed it */
 		ast_string_field_set(r, callid, p->callid);
 		if (r->portno)
@@ -12422,8 +12417,7 @@
 					ast_verbose("No authentication challenge, giving up for %s\n", r->hostname);
 			} else {
 				/* ok, log events, send the packet and be done */
-				if (record_history(p))
-					append_history(p, "RegistryAuth", "Try: %d", p->authtries);
+				append_history(p, "RegistryAuth", "Try: %d", p->authtries);
 				if (sip_debug_test_pvt(p))
 					ast_verbose("Responding to challenge, registration to domain/host name %s\n", r->hostname);
 				transmit_register(r, digest, respheader); 
@@ -13788,8 +13782,7 @@
 				if (option_debug)
 					ast_log(LOG_DEBUG, "Hm....  No sdp for the moment\n");
 			}
-			if (record_history(p)) /* This is a response, note what it was for */
-				append_history(p, "ReInv", "Re-invite received");
+			append_history(p, "ReInv", "Re-invite received"); /* This is a response, note what it was for */
 		}
 	}
 	
@@ -14597,15 +14590,13 @@
 		char *audioqos, *videoqos;
 		if (p->rtp) {
 			audioqos = ast_rtp_get_quality(p->rtp);
-			if (record_history(p))
-				append_history(p, "RTCPaudio", "Quality:%s", audioqos);
+			append_history(p, "RTCPaudio", "Quality:%s", audioqos);
 			if (p->owner)
 				pbx_builtin_setvar_helper(p->owner, "RTPAUDIOQOS", audioqos);
 		}
 		if (p->vrtp) {
 			videoqos = ast_rtp_get_quality(p->vrtp);
-			if (record_history(p))
-				append_history(p, "RTCPvideo", "Quality:%s", videoqos);
+			append_history(p, "RTCPvideo", "Quality:%s", videoqos);
 			if (p->owner)
 				pbx_builtin_setvar_helper(p->owner, "RTPVIDEOQOS", videoqos);
 		}
@@ -15290,8 +15281,8 @@
 	}
 	p->recv = sin;
 
-	if (record_history(p)) /* 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);
+	/* 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)) {
@@ -17251,8 +17242,7 @@
 	}
 	if (changed && !ast_test_flag(&p->flags[0], SIP_GOTREFER)) {
 		if (chan->_state != AST_STATE_UP) {	/* We are in early state */
-			if (record_history(p))
-				append_history(p, "ExtInv", "Initial invite sent with remote bridge proposal.");
+			append_history(p, "ExtInv", "Initial invite sent with remote bridge proposal.");
 			if (option_debug)
 				ast_log(LOG_DEBUG, "Early remote bridge setting SIP '%s' - Sending media to %s\n", p->callid, ast_inet_ntoa(rtp ? p->redirip.sin_addr : p->ourip));
 		} else if (!p->pendinginvite) {		/* We are up, and have no outstanding invite */



More information about the svn-commits mailing list