r2935 - in trunk/libmsip: . source

erik at minisip.org erik at minisip.org
Sun Nov 19 14:55:12 CET 2006


Author: erik
Date: 2006-11-19 14:55:11 +0100 (Sun, 19 Nov 2006)
New Revision: 2935

Modified:
   trunk/libmsip/configure.ac
   trunk/libmsip/source/SipLayerTransport.cxx
Log:

  * Make it possible to enable output of messages to mout even if
    libmsip was not configured with --enable-debug.

    It is good to run the regression testing without debug output since
    such output is likely to change quite often. We still want to be
    able to output what messages are sent and received.

  * Fixed format of timestamping code for output of
    packets (000:1 -> 000:001).



Modified: trunk/libmsip/configure.ac
===================================================================
--- trunk/libmsip/configure.ac	2006-11-18 19:09:23 UTC (rev 2934)
+++ trunk/libmsip/configure.ac	2006-11-19 13:55:11 UTC (rev 2935)
@@ -20,6 +20,17 @@
 AM_MINISIP_ENABLE_DEBUG
 AM_MINISIP_ENABLE_TEST_SUITE
 
+
+dnl debug flag
+AC_ARG_ENABLE(dropemul,
+		AS_HELP_STRING([--enable-dropemul],
+			[enables simulated packet dropping of UDP packets (for debugging only - default disabled)]),
+		[ if test "${enable_dropemul}" = "yes"
+		then
+		AC_DEFINE(DEBUG_UDPPACKETDROPEMUL, [], [Debug autocalling])
+		fi ])
+
+
 dnl Damn RedHat
 AC_DEFINE(OPENSSL_NO_KRB5, [], [No Kerberos in OpenSSL])
 

Modified: trunk/libmsip/source/SipLayerTransport.cxx
===================================================================
--- trunk/libmsip/source/SipLayerTransport.cxx	2006-11-18 19:09:23 UTC (rev 2934)
+++ trunk/libmsip/source/SipLayerTransport.cxx	2006-11-19 13:55:11 UTC (rev 2935)
@@ -78,10 +78,59 @@
 # endif
 #endif
 
+#ifdef DEBUG_UDPPACKETDROPEMUL
+Mutex dropStringLock;
+string dropStringOut;
+string dropStringIn;
+
+void setDropFilterOut(string s){
+	dropStringLock.lock();
+	dropStringOut=s;
+	dropStringLock.unlock();
+}
+
+void setDropFilterIn(string s){
+	dropStringLock.lock();
+	dropStringIn=s;
+	dropStringLock.unlock();
+}
+
+static bool dropOut(){
+	char c='1';
+	dropStringLock.lock();
+	if (dropStringOut.size()>0){
+		c = dropStringOut[0];
+		dropStringOut = dropStringOut.substr(1);
+	}
+	dropStringLock.unlock();
+	if (c=='0'){
+		return true;
+	}else{
+		return false;
+	}
+}
+
+static bool dropIn(){
+	char c='1';
+	dropStringLock.lock();
+	if (dropStringIn.size()>0){
+		c = dropStringIn[0];
+		dropStringIn = dropStringIn.substr(1);
+	}
+	dropStringLock.unlock();
+	if (c=='0'){
+		return true;
+	}else{
+		return false;
+	}
+}
+
+#endif
+
+
 // 
 // SipMessageParser
 // 
-
 class SipMessageParser{
 	public:
 		SipMessageParser();
@@ -242,8 +291,6 @@
 	return sipdebug_print_packets;
 }
 
-#ifdef DEBUG_OUTPUT
-
 uint64_t startTime = 0;
 
 void printMessage(string header, string packet){
@@ -253,29 +300,27 @@
 	t=mtime();
 	int64_t sec = t / 1000 - startTime / 1000;
 	int64_t msec = t - startTime;
-	
+	msec = msec%1000;
+
 	header = (sec<100?string("0"):string("")) + 
-		 (sec<10?"0":"") + 
-		 itoa((int)(msec/1000))+
-		 ":"+
-		 (msec<10?"0":"")+
-		 (msec<100?"0":"")+
-		 itoa((int)(msec%1000))+ 
-		 " " + 
-		 header;
-	
-	if (sipdebug_print_packets){
-		size_t strlen=packet.size();
-		mout << header<<": ";
-		for (size_t i=0; i<strlen; i++){
-			mout << packet[i];
-			if (packet[i]=='\n')
-				mout << header<<": ";
-		}
-		mout << end;
+		(sec<10?"0":"") + 
+		itoa((int)sec)+
+		":"+
+		(msec<10?"0":"")+
+		(msec<100?"0":"")+
+		itoa((int)msec)+ 
+		" " + 
+		header;
+
+	size_t strlen=packet.size();
+	mout << header<<": ";
+	for (size_t i=0; i<strlen; i++){
+		mout << packet[i];
+		if (packet[i]=='\n')
+			mout << header<<": ";
 	}
+	mout << end;
 }
-#endif
 
 static void * streamThread( void * arg );
 
@@ -367,12 +412,6 @@
 }
 
 
-/*
-void SipLayerTransport::setSipSMCommandReceiver(MRef<SipSMCommandReceiver*> rec){
-	commandReceiver = rec;
-}
-*/
-
 string getSocketTransport( MRef<Socket*> socket )
 {
 	switch( socket->getType() ){
@@ -766,9 +805,9 @@
 		if( ssocket ){
 			/* At this point if socket != we send on a 
 			 * streamsocket */
-#ifdef DEBUG_OUTPUT
-			printMessage("OUT (STREAM)", packetString);
-#endif
+			if (sipdebug_print_packets){
+				printMessage("OUT (STREAM)", packetString);
+			}
 #ifdef ENABLE_TS
 			//ts.save( PACKET_OUT );
 			char tmp[12];
@@ -781,9 +820,9 @@
 		}
 		else if( dsocket ){
 			/* otherwise use the UDP socket */
-#ifdef DEBUG_OUTPUT
-			printMessage("OUT (UDP)", packetString);
-#endif
+			if (sipdebug_print_packets){
+				printMessage("OUT (UDP)", packetString);
+			}
 #ifdef ENABLE_TS
 			//ts.save( PACKET_OUT );
 			char tmp[12];
@@ -795,6 +834,9 @@
 // 			MRef<IPAddress *>destAddr = IPAddress::create(ip_addr);
 
 			
+#ifdef DEBUG_UDPPACKETDROPEMUL
+				if (!dropOut())
+#endif
 				if( dsocket->sendTo( **destAddr, port, 
 							(const void*)packetString.c_str(),
 							(int32_t)packetString.length() ) == -1 ){
@@ -919,10 +961,17 @@
 				return; // FIXME
 			}
 
+#ifdef DEBUG_UDPPACKETDROPEMUL
+			if (dropIn()){
+				return;
+			}
+#endif
+
 			if (nread < (int)strlen("SIP/2.0")){
 				return;
 			}
 
+
 			try{
 #ifdef ENABLE_TS
 				//ts.save( PACKET_IN );
@@ -933,9 +982,9 @@
 
 #endif
 				string data = string(buffer, nread);
-#ifdef DEBUG_OUTPUT
-				printMessage("IN (UDP)", data);
-#endif
+				if (sipdebug_print_packets){
+					printMessage("IN (UDP)", data);
+				}
 				pack = SipMessage::createMessage( data );
 				
 				pack->setSocket( *sock );
@@ -1060,9 +1109,9 @@
 					pack = parser.feed( buffer[i] );
 					
 					if( pack ){
-#ifdef DEBUG_OUTPUT
+						if (sipdebug_print_packets){
 						printMessage("IN (STREAM)", buffer);
-#endif
+						}
 						//cerr << "Packet string:\n"<< pack->getString()<< "(end)"<<endl;
 
 						MRef<IPAddress *> peer = socket->getPeerAddress();



More information about the Minisip-devel mailing list