activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r674477 - in /activemq/activemq-cpp/trunk/src/main/decaf/internal/net: URIHelper.cpp URIHelper.h
Date Mon, 07 Jul 2008 12:50:10 GMT
Author: tabish
Date: Mon Jul  7 05:50:10 2008
New Revision: 674477

URL: http://svn.apache.org/viewvc?rev=674477&view=rev
Log:
Implementing the URIHelper class to aid the URI class in parsing URIs.

Modified:
    activemq/activemq-cpp/trunk/src/main/decaf/internal/net/URIHelper.cpp
    activemq/activemq-cpp/trunk/src/main/decaf/internal/net/URIHelper.h

Modified: activemq/activemq-cpp/trunk/src/main/decaf/internal/net/URIHelper.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/internal/net/URIHelper.cpp?rev=674477&r1=674476&r2=674477&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/internal/net/URIHelper.cpp (original)
+++ activemq/activemq-cpp/trunk/src/main/decaf/internal/net/URIHelper.cpp Mon Jul  7 05:50:10
2008
@@ -33,13 +33,192 @@
 using namespace decaf::internal::net;
 
 ////////////////////////////////////////////////////////////////////////////////
-URIHelper::URIHelper( const std::string& allLegal ) {
-    this->allLegal = allLegal;
+URIHelper::URIHelper() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void URIHelper::parseURI( const std::string& uri, bool forceServer )
+    throw( URISyntaxException ) {
+
+//    std::string temp = uri;
+//
+//    std::size_t index, index1, index2, index3;
+//    // parse into Fragment, Scheme, and SchemeSpecificPart
+//    // then parse SchemeSpecificPart if necessary
+//
+//    // Fragment
+//    index = temp.find( '#' );
+//    if( index != std::string::npos ) {
+//        // remove the fragment from the end
+//
+//        // TODO - Replace vars from URI.java with something in this class
+////        fragment = temp.substr( index + 1, std::string::npos );
+////        validateFragment( uri, fragment, index + 1 );
+//        temp = temp.substr( 0, index );
+//    }
+//
+//    // Scheme and SchemeSpecificPart
+//    index = index1 = temp.find( ':' );
+//    index2 = temp.find( '/' );
+//    index3 = temp.find( '?' );
+//
+//    // if a '/' or '?' occurs before the first ':' the uri has no
+//    // specified scheme, and is therefore not absolute
+//    if( index != std::string::npos &&
+//        ( index2 >= index || index2 == std::string::npos ) &&
+//        ( index3 >= index || index3 == std::string::npos ) ) {
+//
+//        // the characters up to the first ':' comprise the scheme
+//        absolute = true;
+//        scheme = temp.substr( 0, index );
+//        if( scheme.length() == 0 ) {
+//            throw URISyntaxException(
+//                __FILE__, __LINE__,
+//                uri, "Scheme not specified.", index );
+//        }
+//        validateScheme( uri, scheme, 0 );
+//        schemespecificpart = temp.substr( index + 1, std::string::npos );
+//        if( schemespecificpart.length() == 0 ) {
+//            throw URISyntaxException(
+//                __FILE__, __LINE__,
+//                uri, "Scheme specific part is invalid..", index + 1 );
+//        }
+//    } else {
+//        absolute = false;
+//        schemespecificpart = temp;
+//    }
+//
+//    if( scheme == "" || schemespecificpart.length() > 0 &&
+//        schemespecificpart.at( 0 ) == '/' ) {
+//
+//        opaque = false;
+//        // the URI is hierarchical
+//
+//        // Query
+//        temp = schemespecificpart;
+//        index = temp.find( '?' );
+//        if( index != std::string::npos ) {
+//            query = temp.substr( index + 1, std::string::npos );
+//            temp = temp.substr( 0, index );
+//            validateQuery( uri, query, index2 + 1 + index );
+//        }
+//
+//        // Authority and Path
+//        if( temp.at(0) == '/' && temp.at(1) == '/' ) {
+//
+//            index = temp.find( '/', 2 );
+//            if( index != std::string::npos ) {
+//                authority = temp.substr( 2, index );
+//                path = temp.substr( index, std::string::npos );
+//            } else {
+//                authority = temp.substr( 2, std::string::npos );
+//                if( authority.length() == 0 && query == "" && fragment
== "" ) {
+//                    throw URISyntaxException(
+//                        __FILE__, __LINE__,
+//                        uri, "Scheme specific part is invalid..", uri.length() );
+//                }
+//
+//                path = "";
+//                // nothing left, so path is empty (not null, path should
+//                // never be null)
+//            }
+//
+//            if( authority.length() == 0 ) {
+//                authority = "";
+//            } else {
+//                validateAuthority( uri, authority, index1 + 3 );
+//            }
+//        } else { // no authority specified
+//            path = temp;
+//        }
+//
+//        int pathIndex = 0;
+//        if( index2 != std::string::npos ) {
+//            pathIndex += index2;
+//        }
+//
+//        if( index != std::string::npos ) {
+//            pathIndex += index;
+//        }
+//
+//        validatePath( uri, path, pathIndex );
+//
+//    } else { // if not hierarchical, URI is opaque
+//        opaque = true;
+//        validateSsp( uri, schemespecificpart, index2 + 2 + index );
+//    }
+//
+//    parseAuthority( forceServer, authority );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void URIHelper::validateScheme( const std::string& uri, const std::string& scheme,
int index )
+    throw( URISyntaxException ) {
+
+    // first char needs to be an alpha char
+    if( !Character::isLetter( scheme.at(0) ) ) {
+        throw URISyntaxException(
+            __FILE__, __LINE__,
+            uri, "Schema must start with a Letter.", index );
+    }
+
+    try {
+        URIEncoderDecoder::validateSimple( scheme, "+-." );
+    } catch( URISyntaxException& e ) {
+        throw URISyntaxException(
+            __FILE__, __LINE__,
+            uri, "Invalid Schema", index + e.getIndex() );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void URIHelper::validateSsp( const std::string& uri, const std::string& ssp,
+                             std::size_t index, const std::string& allLegal )
+    throw( URISyntaxException ) {
+
+    try {
+        URIEncoderDecoder::validate( ssp, allLegal );
+    } catch( URISyntaxException& e ) {
+        throw URISyntaxException(
+            __FILE__, __LINE__,
+            uri, "Invalid URI Ssp", index + e.getIndex() );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void URIHelper::validateAuthority( const std::string& uri, const std::string& authority,
+                                   std::size_t index, const std::string& allLegal )
+    throw( URISyntaxException ) {
+
+    try {
+        // "@[]" + someLegal
+        URIEncoderDecoder::validate( authority, allLegal );
+    } catch( URISyntaxException& e ) {
+        throw URISyntaxException(
+            __FILE__, __LINE__,
+            uri, "Invalid URI Authority", index + e.getIndex() );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void URIHelper::validatePath( const std::string& uri, const std::string& path,
+                              std::size_t index, const std::string& allLegal )
+    throw( URISyntaxException ) {
+
+    try {
+        // "/@" + someLegal
+        URIEncoderDecoder::validate( path, allLegal );
+    } catch( URISyntaxException& e ) {
+        throw URISyntaxException(
+            __FILE__, __LINE__,
+            uri, "Invalid URI Path", index + e.getIndex() );
+    }
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 void URIHelper::validateQuery( const std::string& uri, const std::string& query,
-                               std::size_t index ) throw( URISyntaxException ) {
+                               std::size_t index, const std::string& allLegal )
+    throw( URISyntaxException ) {
 
     try {
         URIEncoderDecoder::validate( query, allLegal );
@@ -52,7 +231,8 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 void URIHelper::validateFragment( const std::string& uri, const std::string& fragment,
-                                  std::size_t index ) throw( URISyntaxException ) {
+                                  std::size_t index, const std::string& allLegal )
+    throw( URISyntaxException ) {
 
     try {
         URIEncoderDecoder::validate( fragment, allLegal );

Modified: activemq/activemq-cpp/trunk/src/main/decaf/internal/net/URIHelper.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/internal/net/URIHelper.h?rev=674477&r1=674476&r2=674477&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/internal/net/URIHelper.h (original)
+++ activemq/activemq-cpp/trunk/src/main/decaf/internal/net/URIHelper.h Mon Jul  7 05:50:10
2008
@@ -29,32 +29,76 @@
      * Helper class used by the URI classes in encoding and decoding of URI's.
      */
     class URIHelper {
-    private:
+    public:
+
+        URIHelper();
+        virtual ~URIHelper() {}
 
         /**
-         * All characters that are legal in a URI
+         * Parse the passed in URI.
+         * @param uri - the URI to Parse
+         * @param forceServer - if true invalid URI data throws an Exception
+         * @throws URISyntaxException if forceServer is true and the URI is invalid.
          */
-        std::string allLegal;
+        void parseURI( const std::string& uri, bool forceServer )
+            throw( decaf::net::URISyntaxException );
 
-    public:
+        /**
+         * Validate the schema portin of the URI.
+         * @param uri - the URI to check.
+         * @param schema - the schema section of the URI.
+         * @param index - index in uri where schema starts.
+         * @throw URISyntaxException if the fragment has errors.
+         */
+        void validateScheme( const std::string& uri, const std::string& scheme, int
index )
+            throw( decaf::net::URISyntaxException );
+
+        /**
+         * Validate that the URI Ssp Segment contains no invalid encodings.
+         * @param uri - the full uri.
+         * @param ssp - the SSP to check.
+         * @param index - position in the uri where Ssp starts.
+         * @param allLegal - all characters legal for this operation
+         * @throw URISyntaxException if the fragment has errors.
+         */
+        void validateSsp( const std::string& uri, const std::string& ssp,
+                          std::size_t index, const std::string& allLegal )
+            throw( decaf::net::URISyntaxException );
 
         /**
-         * Create a URIHelper with the assigned set of Legal URI Characters.
-         * @param allLegal - All Characters that are legal in this URI instance.
+         * Validate that the URI Authority Segment contains no invalid encodings.
+         * @param uri - the full uri.
+         * @param authority - the Authority to check.
+         * @param index - position in the uri where Authority starts.
+         * @param allLegal - all characters legal for this operation
+         * @throw URISyntaxException if the fragment has errors.
          */
-        URIHelper( const std::string& allLegal );
+        void validateAuthority( const std::string& uri, const std::string& authority,
+                                std::size_t index, const std::string& allLegal )
+            throw( decaf::net::URISyntaxException );
 
-        virtual ~URIHelper() {}
+        /**
+         * Validate that the URI Path Segment contains no invalid encodings.
+         * @param uri - the full uri.
+         * @param path - the path to check.
+         * @param index - position in the uri where path starts.
+         * @param allLegal - all characters legal for this operation
+         * @throw URISyntaxException if the fragment has errors.
+         */
+        void validatePath( const std::string& uri, const std::string& path,
+                           std::size_t index, const std::string& allLegal )
+            throw( decaf::net::URISyntaxException );
 
         /**
          * Validate that the URI Query Segment contains no invalid encodings.
          * @param uri - the full uri.
          * @param query - the query to check.
          * @param index - position in the uri where fragment starts.
+         * @param allLegal - all characters legal for this operation
          * @throw URISyntaxException if the fragment has errors.
          */
         void validateQuery( const std::string& uri, const std::string& query,
-                            std::size_t index )
+                            std::size_t index, const std::string& allLegal )
             throw( decaf::net::URISyntaxException );
 
         /**
@@ -62,10 +106,11 @@
          * @param uri - the full uri.
          * @param fragment - the fragment to check.
          * @param index - position in the uri where fragment starts.
+         * @param allLegal - all characters legal for this operation
          * @throw URISyntaxException if the fragment has errors.
          */
         void validateFragment( const std::string& uri, const std::string& fragment,
-                               std::size_t index )
+                               std::size_t index, const std::string& allLegal )
             throw( decaf::net::URISyntaxException );
 
         /**



Mime
View raw message