r3569 - in trunk/libmsip: . include include/libmsip source source/headers source/messages

erik at minisip.org erik at minisip.org
Tue Mar 18 16:12:34 CET 2008


Author: erik
Date: 2008-03-18 16:12:34 +0100 (Tue, 18 Mar 2008)
New Revision: 3569

Added:
   trunk/libmsip/include/libmsip/SipMessageContentUnknown.h
   trunk/libmsip/source/SipMessageContentUnknown.cxx
Modified:
   trunk/libmsip/Makefile.am
   trunk/libmsip/include/Makefile.am
   trunk/libmsip/include/libmsip/SipHeaderMaxForwards.h
   trunk/libmsip/source/headers/SipHeaderMaxForwards.cxx
   trunk/libmsip/source/messages/SipMessage.cxx
   trunk/libmsip/source/messages/SipRequest.cxx
Log:
libmsip:
 * parsing fix: Fixed support of whitespace between messages
     received on reliable transport. A bug made us only support 
     spaces, and an even number of new lines in front of
     requests.
 * Added a "unknown" content type. We used to drop the content 
   during parsing. Now it is stored as a string in a 
   SipMessageContentUnknown object if there is no registred
   factory for the type.
 * Updated MaxForwards header to support setting the value in it.



Modified: trunk/libmsip/Makefile.am
===================================================================
--- trunk/libmsip/Makefile.am	2008-03-18 12:54:13 UTC (rev 3568)
+++ trunk/libmsip/Makefile.am	2008-03-18 15:12:34 UTC (rev 3569)
@@ -52,6 +52,7 @@
 		     source/SipSMCommand.cxx \
 		     source/SipCommandString.cxx \
 		     source/SipTimers.cxx \
+		     source/SipMessageContentUnknown.cxx \
 		     source/SipMessageContentIM.cxx \
 		     source/SipMessageContentFactory.cxx \
 		     source/SipMessageContentMime.cxx \

Modified: trunk/libmsip/include/Makefile.am
===================================================================
--- trunk/libmsip/include/Makefile.am	2008-03-18 12:54:13 UTC (rev 3568)
+++ trunk/libmsip/include/Makefile.am	2008-03-18 15:12:34 UTC (rev 3569)
@@ -37,6 +37,7 @@
 		     libmsip/SipHeaderReferTo.h \
 		     libmsip/SipDialogConfig.h \
 		     libmsip/SipMessageContent.h \
+		     libmsip/SipMessageContentUnknown.h \
 		     libmsip/SipMessageContentIM.h \
 		     libmsip/SipMessageContentFactory.h \
 		     libmsip/SipMessageContentMime.h \

Modified: trunk/libmsip/include/libmsip/SipHeaderMaxForwards.h
===================================================================
--- trunk/libmsip/include/libmsip/SipHeaderMaxForwards.h	2008-03-18 12:54:13 UTC (rev 3568)
+++ trunk/libmsip/include/libmsip/SipHeaderMaxForwards.h	2008-03-18 15:12:34 UTC (rev 3569)
@@ -63,7 +63,7 @@
 		 */
 		int32_t getMaxForwards() const;
 		
-		//void setMaxForwards(int32_t max);
+		void setMaxForwards(int32_t max);
 
 	private:
 		int32_t max;

Copied: trunk/libmsip/include/libmsip/SipMessageContentUnknown.h (from rev 3568, trunk/libmsip/include/libmsip/SipMessageContentIM.h)
===================================================================
--- trunk/libmsip/include/libmsip/SipMessageContentUnknown.h	                        (rev 0)
+++ trunk/libmsip/include/libmsip/SipMessageContentUnknown.h	2008-03-18 15:12:34 UTC (rev 3569)
@@ -0,0 +1,49 @@
+/*
+  Copyright (C) 2005, 2004 Erik Eliasson, Johan Bilien
+  
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License as published by the Free Software Foundation; either
+  version 2.1 of the License, or (at your option) any later version.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+/*
+ * Authors: Erik Eliasson <eliasson at it.kth.se>
+ *          Johan Bilien <jobi at via.ecp.fr>
+*/
+
+
+#ifndef _SIPMESSAGECONTENTUNKNOWN_H
+#define _SIPMESSAGECONTENTUNKNOWN_H
+
+#include<libmsip/libmsip_config.h>
+
+#include<libmsip/SipMessageContent.h>
+#include<iostream>
+
+MRef<SipMessageContent*> LIBMSIP_API sipUnknownMessageContentFactory(const std::string &, const std::string &ContentType);
+
+class LIBMSIP_API SipMessageContentUnknown : public SipMessageContent{
+public:
+	SipMessageContentUnknown(std::string m, std::string contentType);
+	
+	virtual std::string getMemObjectType() const {return "SipMessageContentUnknown";}
+	
+	virtual std::string getString() const;
+
+	virtual std::string getContentType() const;
+private:
+	std::string msg;
+	std::string contentType;
+};
+
+#endif

Copied: trunk/libmsip/source/SipMessageContentUnknown.cxx (from rev 3568, trunk/libmsip/source/SipMessageContentIM.cxx)
===================================================================
--- trunk/libmsip/source/SipMessageContentUnknown.cxx	                        (rev 0)
+++ trunk/libmsip/source/SipMessageContentUnknown.cxx	2008-03-18 15:12:34 UTC (rev 3569)
@@ -0,0 +1,44 @@
+/*
+  Copyright (C) 2005, 2004 Erik Eliasson, Johan Bilien
+  
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License as published by the Free Software Foundation; either
+  version 2.1 of the License, or (at your option) any later version.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+/*
+ * Authors: Erik Eliasson <eliasson at it.kth.se>
+ *          Johan Bilien <jobi at via.ecp.fr>
+*/
+
+#include<config.h>
+
+#include<libmsip/SipMessageContentUnknown.h>
+
+using namespace std;
+
+MRef<SipMessageContent*> sipUnknownMessageContentFactory(const string &buf, const string &type){
+        return new SipMessageContentUnknown(buf,type);
+}
+
+SipMessageContentUnknown::SipMessageContentUnknown(string m, string type): msg(m),contentType(type){
+
+}
+
+string SipMessageContentUnknown::getString() const{
+	return msg;
+}
+
+string SipMessageContentUnknown::getContentType() const{
+	return contentType;
+}

Modified: trunk/libmsip/source/headers/SipHeaderMaxForwards.cxx
===================================================================
--- trunk/libmsip/source/headers/SipHeaderMaxForwards.cxx	2008-03-18 12:54:13 UTC (rev 3568)
+++ trunk/libmsip/source/headers/SipHeaderMaxForwards.cxx	2008-03-18 15:12:34 UTC (rev 3569)
@@ -72,9 +72,9 @@
 	return max;
 }
 
-/*
+
 void SipHeaderValueMaxForwards::setMaxForwards(int32_t m){
 	max=m;
 }
-*/
 
+

Modified: trunk/libmsip/source/messages/SipMessage.cxx
===================================================================
--- trunk/libmsip/source/messages/SipMessage.cxx	2008-03-18 12:54:13 UTC (rev 3568)
+++ trunk/libmsip/source/messages/SipMessage.cxx	2008-03-18 15:12:34 UTC (rev 3569)
@@ -41,6 +41,7 @@
 
 #include<libmnetutil/Socket.h>
 #include<libmsip/SipMessageContentFactory.h>
+#include<libmsip/SipMessageContentUnknown.h>
 #include<libmsip/SipHeaderContentLength.h>
 #include<libmsip/SipHeaderVia.h>
 #include<libmsip/SipHeaderFrom.h>
@@ -99,10 +100,14 @@
 MRef<SipMessage*> SipMessage::createMessage(string &data){
 	
 	size_t n = data.size();
+	size_t start = 0;
 
-	if (n>3   &&    (data[0]=='S'||data[0]=='s') &&
-			(data[1]=='I'||data[1]=='i') &&
-			(data[2]=='P'||data[2]=='p' )){
+	while ( start<n && isWS(data[start]))
+		start++;
+
+	if (n>3   &&    (data[start+0]=='S'||data[start+0]=='s') &&
+			(data[start+1]=='I'||data[start+1]=='i') &&
+			(data[start+2]=='P'||data[start+2]=='p' )){
 		return MRef<SipMessage*>(new SipResponse(data));
 	}else{
 		return new SipRequest(data);
@@ -227,15 +232,21 @@
 {
 	uint32_t i;
 
-	for (i=0; buildFrom[i]!='\r' && buildFrom[i]!='\n'; i++){
-		if(i==buildFrom.size()){
+	uint32_t start=0;
+	uint32_t blen=buildFrom.size();
+
+	//skip whitespace (can be there if received over reliable transport)
+	while (start<blen && isWS(buildFrom[start]))
+		start++;
+
+	//Skip first line (they are parsed by sub-class)
+	for (i=start; buildFrom[i]!='\r' && buildFrom[i]!='\n'; i++){
+		if(i==blen){
 #ifdef DEBUG_OUTPUT
 			cerr << "SipMessage::SipMessage: Size is too short - throwing exception"<< endl;
 #endif
 			throw SipExceptionInvalidMessage("SIP Message too short");
 		}
-		//header = header + buildFrom[i];
-
 	}
 	
 	int contentStart = parseHeaders(buildFrom, i);
@@ -253,13 +264,12 @@
 			SipMessageContentFactoryFuncPtr contentFactory = contentFactories.getFactory( contentType );
 			if (contentFactory){
 				MRef<SipMessageContent*> smcref = contentFactory(contentbuf, contentType );
-				setContent(smcref);
-			}else{ //TODO: Better error handling
-				merr << "WARNING: No SipMessageContentFactory found for content type "<<contentType <<endl;
+				setContent( new SipMessageContentUnknown( contentbuf, contentType ));
 			}
 			
-		}else{ //TODO: Better error handling
+		}else{
 			merr << "WARNING: Sip message has content, but no content type! Content ignored."<< endl;
+			setContent( new SipMessageContentUnknown( contentbuf, "unknown" ));
 		}
 	}
 }

Modified: trunk/libmsip/source/messages/SipRequest.cxx
===================================================================
--- trunk/libmsip/source/messages/SipRequest.cxx	2008-03-18 12:54:13 UTC (rev 3568)
+++ trunk/libmsip/source/messages/SipRequest.cxx	2008-03-18 15:12:34 UTC (rev 3569)
@@ -270,7 +270,7 @@
 	string requestLine;
 
 	// Skip white space
-	start = build_from.find_first_not_of( ' ', start );
+	start = build_from.find_first_not_of( " \r\n\t", start );
 	if( (int)start == (int)string::npos ){
 		throw SipExceptionInvalidMessage("SipRequest malformed - first line did not contain any non whitespace character");
 	}
@@ -293,7 +293,7 @@
 		throw SipExceptionInvalidMessage("SipRequest malformed - could not find method");
 	}
 
-	method = build_from.substr( start, pos - start );
+	method = requestLine.substr( start, pos - start );
 	#ifdef DEBUG_OUTPUT
 	cerr << "SipRequest::init - method = " << method << endl;
 	#endif



More information about the Minisip-devel mailing list