You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2007/08/15 01:28:19 UTC
svn commit: r565967 - in /activemq/activemq-cpp/trunk/src/decaf/src/main:
Makefile.am decaf/net/URI.cpp decaf/net/URI.h decaf/net/URL.cpp
Author: tabish
Date: Tue Aug 14 16:28:18 2007
New Revision: 565967
URL: http://svn.apache.org/viewvc?view=rev&rev=565967
Log:
http://issues.apache.org/activemq/browse/AMQCPP-103
Adding start of URI class
Modified:
activemq/activemq-cpp/trunk/src/decaf/src/main/Makefile.am
activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/net/URI.cpp
activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/net/URI.h
activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/net/URL.cpp
Modified: activemq/activemq-cpp/trunk/src/decaf/src/main/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/Makefile.am?view=diff&rev=565967&r1=565966&r2=565967
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/Makefile.am Tue Aug 14 16:28:18 2007
@@ -23,6 +23,10 @@
decaf/net/SocketError.cpp \
decaf/net/TcpSocket.cpp \
decaf/net/SocketFactory.cpp \
+ decaf/net/URI.cpp \
+ decaf/net/URL.cpp \
+ decaf/net/URLEncoder.cpp \
+ decaf/net/URLDecoder.cpp \
decaf/lang/Exception.cpp \
decaf/lang/Thread.cpp \
decaf/lang/Byte.cpp \
@@ -84,6 +88,10 @@
decaf/net/SocketInputStream.h \
decaf/net/ServerSocket.h \
decaf/net/SocketFactory.h \
+ decaf/net/URI.h \
+ decaf/net/URL.h \
+ decaf/net/URLEncoder.h \
+ decaf/net/URLDecoder.h \
decaf/lang/Throwable.h \
decaf/lang/Exception.h \
decaf/lang/Byte.h \
Modified: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/net/URI.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/net/URI.cpp?view=diff&rev=565967&r1=565966&r2=565967
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/net/URI.cpp (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/net/URI.cpp Tue Aug 14 16:28:18 2007
@@ -17,12 +17,26 @@
#include "URI.h"
+#include <apr_strings.h>
+#include <decaf/lang/Integer.h>
+
using namespace decaf;
using namespace decaf::net;
using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+const std::string URI::unreserved = "_-!.~\'()*";
+const std::string URI::punct = ",;:$&+=";
+const std::string URI::reserved = punct + "?/[]@";
+const std::string URI::someLegal = unreserved + punct;
+const std::string URI::allLegal = unreserved + reserved;
////////////////////////////////////////////////////////////////////////////////
URI::URI( const std::string& uri ) throw ( URISyntaxException) {
+
+ this->uriString = NULL;
+ this->parseURI( uri );
}
////////////////////////////////////////////////////////////////////////////////
@@ -30,6 +44,26 @@
const std::string& ssp,
const std::string& fragment ) throw ( URISyntaxException ) {
+ std::string uri = "";
+
+ if( scheme != "" ) {
+ uri.append( scheme );
+ uri.append( ":" );
+ }
+
+ if( ssp != "" ) {
+ // QUOTE ILLEGAL CHARACTERS
+ uri.append( quoteComponent( ssp, allLegal ) );
+ }
+
+ if( fragment != "" ) {
+ uri.append( "#" );
+ // QUOTE ILLEGAL CHARACTERS
+ uri.append( quoteComponent( fragment, allLegal ) );
+ }
+
+ // Now hand of to the main parse function.
+ parseURI( uri );
}
////////////////////////////////////////////////////////////////////////////////
@@ -38,6 +72,77 @@
const std::string& path, const std::string& query,
const std::string& fragment ) throw ( URISyntaxException ) {
+ this->uriString = NULL;
+
+ if( scheme == "" && userInfo == "" && host == "" &&
+ path == "" && query == "" && fragment == "" ) {
+
+ this->uri.path = "";
+ return;
+ }
+
+ if( scheme != "" && path.length() > 0 && path.at(0) != '/') {
+
+ throw URISyntaxException(
+ __FILE__, __LINE__,
+ "URI::URI - Path string: %s starts with invalid char '/'",
+ path.c_str() );
+ }
+
+ std::string uri = "";
+ if( scheme != "" ) {
+ uri.append( scheme );
+ uri.append( ":" );
+ }
+
+ if( userInfo != "" || host != "" || port != -1 ) {
+ uri.append( "//" );
+ }
+
+ if( userInfo != "" ) {
+ // QUOTE ILLEGAL CHARACTERS in userinfo
+ uri.append(quoteComponent( userInfo, someLegal ) );
+ uri.append( "@" );
+ }
+
+ if( host != "" ) {
+ std::string newHost = host;
+
+ // check for ipv6 addresses that hasn't been enclosed
+ // in square brackets
+ if( host.find( ":" ) != std::string::npos &&
+ host.find( "]" ) == std::string::npos &&
+ host.find( "[" ) == std::string::npos ) {
+
+ newHost = std::string( "[" ) + host + "]";
+ }
+
+ uri.append( newHost );
+ }
+
+ if( port != -1 ) {
+ uri.append( ":" );
+ uri.append( Integer::toString( port ) );
+ }
+
+ if( path != "" ) {
+ // QUOTE ILLEGAL CHARS
+ uri.append( quoteComponent( path, "/@" + someLegal ) );
+ }
+
+ if( query != "" ) {
+ uri.append( "?" );
+ // QUOTE ILLEGAL CHARS
+ uri.append( quoteComponent( query, allLegal ) );
+ }
+
+ if( fragment != "" ) {
+ // QUOTE ILLEGAL CHARS
+ uri.append( "#" );
+ uri.append( quoteComponent( fragment, allLegal ) );
+ }
+
+ parseURI( uri );
}
////////////////////////////////////////////////////////////////////////////////
@@ -45,6 +150,7 @@
const std::string& path, const std::string& fragment )
throw ( URISyntaxException ) {
+ this->uriString = NULL;
}
////////////////////////////////////////////////////////////////////////////////
@@ -52,6 +158,24 @@
const std::string& path, const std::string& query,
const std::string& fragment ) throw ( URISyntaxException ) {
+ this->uriString = NULL;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void URI::parseURI( const std::string& uri ) throw ( URISyntaxException ) {
+
+ // Use APR to perform the main parse.
+ apr_status_t result = apr_uri_parse( pool.getAprPool(),
+ uri.c_str(), &this->uri );
+
+ if( result != APR_SUCCESS ) {
+ throw URISyntaxException(
+ __FILE__, __LINE__,
+ "URI::praseURI - URI String %s invalid.",
+ uri.c_str() );
+ }
+
+
}
////////////////////////////////////////////////////////////////////////////////
@@ -83,4 +207,20 @@
} catch( URISyntaxException& e ) {
throw IllegalArgumentException( e );
}
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string URI::quoteComponent( const std::string& component,
+ const std::string& legalset ) {
+// try {
+ /*
+ * Use a different encoder than URLEncoder since: 1. chars like "/",
+ * "#", "@" etc needs to be preserved instead of being encoded, 2.
+ * UTF-8 char set needs to be used for encoding instead of default
+ * platform one
+ */
+// return URIEncoderDecoder.quoteIllegal(component, legalset);
+// } catch( UnsupportedEncodingException e ) {
+// throw RuntimeException( e );
+// }
}
Modified: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/net/URI.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/net/URI.h?view=diff&rev=565967&r1=565966&r2=565967
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/net/URI.h (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/net/URI.h Tue Aug 14 16:28:18 2007
@@ -39,10 +39,16 @@
// Apr Data for parsing the uri.
apr_uri_t uri;
- AprPool pool;
+ internal::AprPool pool;
// The original string entered from URI( string ), empty if not set.
- std::string uri;
+ const char* uriString;
+
+ static const std::string unreserved;
+ static const std::string punct;
+ static const std::string reserved;
+ static const std::string someLegal;
+ static const std::string allLegal;
public:
@@ -134,58 +140,42 @@
/**
* @eturns the decoded authority component of this URI.
*/
- std::string getAuthority() const {
- return this->uri.hostinfo;
- }
+ std::string getAuthority() const;
/**
* @returns the decoded fragment component of this URI.
*/
- std::string getFragment() const {
- return this->uri.fragment;
- }
+ std::string getFragment() const;
/**
* @returns the host component of this URI.
*/
- std::string getHost() const {
- return this->uri.host;
- }
+ std::string getHost() const;
/**
* @returns the path component of this URI.
*/
- std::string getPath() const {
- return this->uri.path;
- }
+ std::string getPath() const;
/**
* @returns the port component of this URI.
*/
- int getPort() const {
- return this->uri.port;
- }
+ int getPort() const;
/**
* @returns the query component of this URI.
*/
- std::string getQuery() const {
- return this->uri.query;
- }
+ std::string getQuery() const;
/**
* @returns the scheme component of this URI
*/
- std::string getScheme() const {
- return this->uri.scheme;
- }
+ std::string getScheme() const;
/**
* @returns the user info component of this URI
*/
- std::string getUserInfo() const {
- return this->uri.username;
- }
+ std::string getUserInfo() const;
/**
* Returns the raw authority component of this URI.
@@ -248,7 +238,7 @@
* characters in the unreserved, punct, escaped, and other categories.
* @returns the raw user-information component of the URI
*/
- std::string getRawUserInfo()() const;
+ std::string getRawUserInfo() const;
/**
* Tells whether or not this URI is absolute. A URI is absolute if,
@@ -419,6 +409,22 @@
*/
static URI create( const std::string uri )
throw ( lang::exceptions::IllegalArgumentException );
+
+ private:
+
+ // Parses a URI string and fills in the member data, throws a
+ // URISyntaxException if things fail
+ void parseURI( const std::string& uri ) throw ( URISyntaxException );
+
+ /*
+ * Quote illegal chars for each component, but not the others
+ *
+ * @param component java.lang.String the component to be converted @param
+ * legalset java.lang.String the legal character set allowed in the
+ * component s @return java.lang.String the converted string
+ */
+ std::string quoteComponent( const std::string& component,
+ const std::string& legalset );
};
Modified: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/net/URL.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/net/URL.cpp?view=diff&rev=565967&r1=565966&r2=565967
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/net/URL.cpp (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/net/URL.cpp Tue Aug 14 16:28:18 2007
@@ -18,7 +18,7 @@
#include "URL.h"
using namespace decaf;
-using namespace decaf::net
+using namespace decaf::net;
////////////////////////////////////////////////////////////////////////////////
URL::URL() {