You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2006/07/04 15:44:20 UTC

svn commit: r419004 - /incubator/activemq/trunk/activemq-cpp/src/main/activemq/connector/stomp/StompCommandReader.cpp

Author: chirino
Date: Tue Jul  4 06:44:20 2006
New Revision: 419004

URL: http://svn.apache.org/viewvc?rev=419004&view=rev
Log:
Allows the stomp client to accept a variable amount of while space between frames.


Modified:
    incubator/activemq/trunk/activemq-cpp/src/main/activemq/connector/stomp/StompCommandReader.cpp

Modified: incubator/activemq/trunk/activemq-cpp/src/main/activemq/connector/stomp/StompCommandReader.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/main/activemq/connector/stomp/StompCommandReader.cpp?rev=419004&r1=419003&r2=419004&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-cpp/src/main/activemq/connector/stomp/StompCommandReader.cpp (original)
+++ incubator/activemq/trunk/activemq-cpp/src/main/activemq/connector/stomp/StompCommandReader.cpp Tue Jul  4 06:44:20 2006
@@ -70,20 +70,46 @@
 void StompCommandReader::readStompCommand( StompFrame& frame ) 
    throw ( StompConnectorException )
 {  
-    // Read the command;
-    int numChars = readStompHeaderLine();
-
-    if( numChars <= 0 )
-    {
-        throw StompConnectorException(
-            __FILE__, __LINE__,
-            "StompCommandReader::readStompCommand: "
-            "Error on Read of Command Header" );
-    }
-
-    // Set the command in the frame - copy the memory.
-    frame.setCommand( reinterpret_cast<char*>(&buffer[0]) );
-
+	while( true ) 
+	{
+	    // Clean up the mess.
+	    buffer.clear();
+
+	    // Read the command;
+	    readStompHeaderLine();
+
+        // Ignore all white space before the command.
+        int offset=-1;
+        for( size_t ix = 0; ix < buffer.size()-1; ++ix )
+        {
+        	// Find the first non space character
+        	char b = buffer[ix];
+            switch ( b ) 
+            {
+            	case '\n':
+            	case '\t':
+            	case '\r':
+            		break;
+            	  
+	            default:
+		            offset = ix;
+		            break; 
+            } 
+            
+	        if( offset != -1 )
+	        {
+	        	break;
+	        }            
+        }
+	
+	    if( offset >= 0 )
+	    {
+		    // Set the command in the frame - copy the memory.
+		    frame.setCommand( reinterpret_cast<char*>(&buffer[offset]) );
+			break;
+	    }
+	
+	}
     // Clean up the mess.
     buffer.clear();
 }
@@ -224,8 +250,7 @@
         read( &buffer[0], content_length );
 
         // Content Length read, now pop the end terminator off (\0\n).
-        if(inputStream->read() != '\0' ||
-           inputStream->read() != '\n')
+        if(inputStream->read() != '\0' )
         {
             throw StompConnectorException(
                 __FILE__, __LINE__,
@@ -249,16 +274,6 @@
             if(byte != '\0')
             {            
                 continue;
-            }
-
-            // We read up to the first NULL, now lets pop off the required
-            // newline to complete the packet.
-            if(inputStream->read() != '\n')
-            {
-                throw StompConnectorException(
-                    __FILE__, __LINE__,
-                    "StompCommandReader::readStompBody: "
-                    "Read Body, and no trailing newline");
             }
 
             break;  // Read null and newline we are done.