| /////////////////////////////////////////////////////////////////////////////// |
| // |
| // Copyright (c) 2000-2017 Ericsson Telecom AB |
| // |
| // All rights reserved. This program and the accompanying materials |
| // are made available under the terms of the Eclipse Public License v1.0 |
| // which accompanies this distribution, and is available at |
| // http://www.eclipse.org/legal/epl-v10.html |
| /////////////////////////////////////////////////////////////////////////////// |
| // |
| // Contributors: |
| // Elemer Lelik-initial implementation |
| // |
| // |
| //This function permits extracting JSON messages from a TCP stream by calculating the message length |
| // |
| |
| #include "STOMP_common.hh" |
| #include <ctype.h> |
| #include <string.h> |
| #include <iostream> |
| |
| namespace STOMP__common { |
| //returns length of first STOMP string in the input stream, calculated from index 0, or -1 in case of unsuccessful match |
| INTEGER f__calc__STOMP__length(const OCTETSTRING& data){ |
| int data_length=data.lengthof(); |
| const unsigned char* ptr=(const unsigned char*)data; |
| |
| |
| for(int i=0; i<data_length; i++){ |
| |
| if (ptr[i] == '\0') |
| { |
| if( (ptr[i+1] != '\n') && (ptr[i+1] != '\r') ) return i+1; |
| else { |
| |
| |
| for(int j=i+1; j<data_length; j++){ |
| |
| if ( (ptr[j+1] != '\n') && (ptr[j+1] != '\r') ) return j+1; |
| |
| }//endfor |
| |
| |
| }//endelse |
| |
| }//endif |
| |
| }//endfor |
| |
| return -1; |
| }//endfunction |
| |
| }//end ns |
| |