Return-Path: Delivered-To: apmail-geronimo-activemq-commits-archive@www.apache.org Received: (qmail 35216 invoked from network); 20 Jan 2007 22:17:13 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 20 Jan 2007 22:17:13 -0000 Received: (qmail 43072 invoked by uid 500); 20 Jan 2007 22:17:19 -0000 Delivered-To: apmail-geronimo-activemq-commits-archive@geronimo.apache.org Received: (qmail 43056 invoked by uid 500); 20 Jan 2007 22:17:19 -0000 Mailing-List: contact activemq-commits-help@geronimo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: activemq-dev@geronimo.apache.org Delivered-To: mailing list activemq-commits@geronimo.apache.org Received: (qmail 43047 invoked by uid 99); 20 Jan 2007 22:17:19 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 20 Jan 2007 14:17:19 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 20 Jan 2007 14:17:12 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id 65B8D1A981A; Sat, 20 Jan 2007 14:16:06 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r498194 - in /incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/utils: OpenwireStringSupport.cpp OpenwireStringSupport.h Date: Sat, 20 Jan 2007 22:16:06 -0000 To: activemq-commits@geronimo.apache.org From: tabish@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070120221606.65B8D1A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: tabish Date: Sat Jan 20 14:16:05 2007 New Revision: 498194 URL: http://svn.apache.org/viewvc?view=rev&rev=498194 Log: http://issues.apache.org/activemq/browse/AMQCPP-30 Added: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/utils/OpenwireStringSupport.cpp (with props) incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/utils/OpenwireStringSupport.h (with props) Added: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/utils/OpenwireStringSupport.cpp URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/utils/OpenwireStringSupport.cpp?view=auto&rev=498194 ============================================================================== --- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/utils/OpenwireStringSupport.cpp (added) +++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/utils/OpenwireStringSupport.cpp Sat Jan 20 14:16:05 2007 @@ -0,0 +1,179 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "OpenwireStringSupport.h" + +#include + +using namespace activemq; +using namespace activemq::io; +using namespace activemq::util; +using namespace activemq::exceptions; +using namespace activemq::connector; +using namespace activemq::connector::openwire; +using namespace activemq::connector::openwire::utils; + +//////////////////////////////////////////////////////////////////////////////// +std::string OpenwireStringSupport::readString( io::DataInputStream& dataIn ) + throw ( io::IOException ) { + + try { + + short utflen = dataIn.readShort(); + + if( utflen > -1 ) + { + // Let the stream get us all that data. + std::vector value; + value.resize( utflen ); + dataIn.readFully( value ); + + int c, char2, char3; + int count = 0; + + while( count < utflen ) + { + c = value[count] & 0xff; + switch( c >> 4 ) + { + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + /* 0xxxxxxx */ + count++; +// str.Append((char) c); + break; + case 12: + case 13: +// /* 110x xxxx 10xx xxxx */ +// count += 2; +// if (count > utflen) +// { +// throw CreateDataFormatException(); +// } +// char2 = bytearr[count - 1]; +// if ((char2 & 0xC0) != 0x80) +// { +// throw CreateDataFormatException(); +// } +// str.Append((char) (((c & 0x1F) << 6) | (char2 & 0x3F))); +// break; + case 14: +// /* 1110 xxxx 10xx xxxx 10xx xxxx */ +// count += 3; +// if (count > utflen) +// { +// throw CreateDataFormatException(); +// } +// char2 = bytearr[count - 2]; +// char3 = bytearr[count - 1]; +// if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80)) +// { +// throw CreateDataFormatException(); +// } +// str.Append((char) (((c & 0x0F) << 12) | ((char2 & 0x3F) << 6) | ((char3 & 0x3F) << 0))); +// break; + default : + { + /* 10xx xxxx, 1111 xxxx */ + throw IOException( + __FILE__, + __LINE__, + "OpenwireStringSupport::readString - Encoding not supported" ); + } + } + } + + // Let the Compiler give us a string. + return reinterpret_cast( &value[0] ); + } + + return ""; + } + AMQ_CATCH_RETHROW( ActiveMQException ) + AMQ_CATCHALL_THROW( ActiveMQException ) +} + +//////////////////////////////////////////////////////////////////////////////// +void OpenwireStringSupport::writeString( io::DataOutputStream& dataOut, + const std::string* str ) + throw ( io::IOException ) { + + try { + + if( str != NULL ) + { + if( str->size() > 65536 ) { + throw IOException( + __FILE__, + __LINE__, + ( std::string( "OpenwireStringSupport::writeString - Cannot marshall " ) + + "string longer than: 65536 characters, supplied steing was: " + + Integer::toString( str->size() ) + " characters long." ).c_str() ); + } + + short strlen = (short)str->size(); + short utflen = 0; + int c, count = 0; + + std::string::const_iterator iter = str->begin(); + + for(; iter != str->end(); ++iter ) { + c = *iter; + if( (c >= 0x0001) && (c <= 0x007F) ) { + utflen++; + } else if( c > 0x07FF ) { + utflen += 3; + } else { + utflen += 2; + } + } + + dataOut.writeShort( utflen ); + std::vector byteArr; + byteArr.resize( utflen ); + + for( iter = str->begin(); iter != str->end(); ++iter ) { + + c = *iter; + if( (c >= 0x0001) && (c <= 0x007F) ) { + byteArr[count++] = (unsigned char)c; + } else if ( c > 0x07FF ) { + byteArr[count++] = (unsigned char)( 0xE0 | ( (c >> 12) & 0x0F) ); + byteArr[count++] = (unsigned char)( 0x80 | ( (c >> 6) & 0x3F) ); + byteArr[count++] = (unsigned char)( 0x80 | ( (c >> 0) & 0x3F) ); + } else { + byteArr[count++] = (unsigned char)( 0xC0 | ( (c >> 6) & 0x1F) ); + byteArr[count++] = (unsigned char)( 0x80 | ( (c >> 0) & 0x3F) ); + } + } + + dataOut.write( byteArr ); + } + else + { + dataOut.writeShort( (short)-1 ); + } + } + AMQ_CATCH_RETHROW( ActiveMQException ) + AMQ_CATCHALL_THROW( ActiveMQException ) +} Propchange: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/utils/OpenwireStringSupport.cpp ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/utils/OpenwireStringSupport.h URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/utils/OpenwireStringSupport.h?view=auto&rev=498194 ============================================================================== --- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/utils/OpenwireStringSupport.h (added) +++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/utils/OpenwireStringSupport.h Sat Jan 20 14:16:05 2007 @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _ACTIVEMQ_CONNECTOR_OPENWIRE_UTILS_OPENWIRESTRINGSUPPORT_H_ +#define _ACTIVEMQ_CONNECTOR_OPENWIRE_UTILS_OPENWIRESTRINGSUPPORT_H_ + +#include +#include +#include + +namespace activemq{ +namespace connector{ +namespace openwire{ +namespace utils{ + + class OpenwireStringSupport + { + protected: + + OpenwireStringSupport() {} + virtual ~OpenwireStringSupport() {} + + public: + + /** + * Static method used for reading a string that uses the Openwire format + * from a DataInputStream, this can throw an IOException for the same + * reason as a DataInputStream.readUTF might, as well as if the string + * that is received doesn't conform to the supported charactor encoding. + * @param dataIn - DataInputStream to read from + * @returns A string that has been read + * @throws IOException on Errror. + */ + static std::string readString( io::DataInputStream& dataIn ) + throw ( io::IOException ); + + /** + * Static method used for writing a string that uses the Openwire format + * from a DataOutputStream, this can throw an IOException for the same + * reason as a DataOutputStream.writeUTF might. + * @param dataOut - DataOutputStream to write to + * @param str - A pointer to a string that should be written, NULL needs + * to be an option here as its written as -1. + * @throws IOException on Errror. + */ + static void writeString( io::DataOutputStream& dataOut, + const std::string* str ) + throw ( io::IOException ); + + }; + +}}}} + +#endif /*_ACTIVEMQ_CONNECTOR_OPENWIRE_UTILS_OPENWIRESTRINGSUPPORT_H_*/ Propchange: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/utils/OpenwireStringSupport.h ------------------------------------------------------------------------------ svn:eol-style = native