Skip to content

Commit

Permalink
Partially working URI class, updates for bugs found in testing.
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/activemq/activemq-cpp/trunk@728327 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Timothy A. Bish committed Dec 20, 2008
1 parent d7719ac commit 7da2494
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
6 changes: 3 additions & 3 deletions src/main/decaf/internal/net/URIEncoderDecoder.cpp
Expand Up @@ -111,10 +111,10 @@ std::string URIEncoderDecoder::quoteIllegal( const std::string& s,
char ch = *iter; char ch = *iter;


if( Character::isLetterOrDigit( ch ) || if( Character::isLetterOrDigit( ch ) ||
legal.find( ch ) > std::string::npos || legal.find( ch ) != std::string::npos ||
( (unsigned char)ch > 127 && ( (unsigned char)ch > 127 &&
!Character::isWhitespace(ch) && ( !Character::isWhitespace(ch) &&
!Character::isISOControl(ch) ) ) { !Character::isISOControl(ch) ) ) ) {


buf += ch; buf += ch;
} else { } else {
Expand Down
22 changes: 10 additions & 12 deletions src/main/decaf/internal/net/URIHelper.cpp
Expand Up @@ -90,7 +90,7 @@ URIType URIHelper::parseURI( const std::string& uri, bool forceServer )
result.setAbsolute( true ); result.setAbsolute( true );
result.setScheme( temp.substr( 0, index ) ); result.setScheme( temp.substr( 0, index ) );


if( result.getScheme().length() == 0 ) { if( result.getScheme() == "" ) {
throw URISyntaxException( throw URISyntaxException(
__FILE__, __LINE__, __FILE__, __LINE__,
uri, "Scheme not specified.", index ); uri, "Scheme not specified.", index );
Expand All @@ -99,18 +99,19 @@ URIType URIHelper::parseURI( const std::string& uri, bool forceServer )
validateScheme( uri, result.getScheme(), 0 ); validateScheme( uri, result.getScheme(), 0 );
result.setSchemeSpecificPart( temp.substr( index + 1, std::string::npos ) ); result.setSchemeSpecificPart( temp.substr( index + 1, std::string::npos ) );


if( result.getSchemeSpecificPart().length() == 0 ) { if( result.getSchemeSpecificPart() == "" ) {
throw URISyntaxException( throw URISyntaxException(
__FILE__, __LINE__, __FILE__, __LINE__,
uri, "Scheme specific part is invalid..", index + 1 ); uri, "Scheme specific part is invalid..", index + 1 );
} }

} else { } else {
result.setAbsolute( false ); result.setAbsolute( false );
result.setSchemeSpecificPart( temp ); result.setSchemeSpecificPart( temp );
} }


if( result.getScheme() == "" || if( result.getScheme() == "" ||
( result.getSchemeSpecificPart().length() > 0 && ( !result.getSchemeSpecificPart().empty() &&
result.getSchemeSpecificPart().at( 0 ) == '/' ) ) { result.getSchemeSpecificPart().at( 0 ) == '/' ) ) {


result.setOpaque( false ); result.setOpaque( false );
Expand All @@ -135,20 +136,16 @@ URIType URIHelper::parseURI( const std::string& uri, bool forceServer )
} else { } else {
result.setAuthority( temp.substr( 2, std::string::npos ) ); result.setAuthority( temp.substr( 2, std::string::npos ) );


if( result.getAuthority().length() == 0 && if( result.getAuthority() == "" &&
result.getQuery() == "" && result.getFragment() == "" ) { result.getQuery() == "" && result.getFragment() == "" ) {


throw URISyntaxException( throw URISyntaxException(
__FILE__, __LINE__, __FILE__, __LINE__,
uri, "Scheme specific part is invalid..", uri.length() ); uri, "Scheme specific part is invalid..", uri.length() );
} }

result.setPath( "" );
// nothing left, so path is empty (not null, path should
// never be null)
} }


if( result.getAuthority().length() != 0 ) { if( result.getAuthority() != "" ) {
validateAuthority( uri, result.getAuthority(), index1 + 3 ); validateAuthority( uri, result.getAuthority(), index1 + 3 );
} }


Expand All @@ -175,7 +172,7 @@ URIType URIHelper::parseURI( const std::string& uri, bool forceServer )
URIType authority = parseAuthority( forceServer, result.getAuthority() ); URIType authority = parseAuthority( forceServer, result.getAuthority() );


// Authority was valid, so we capture the results // Authority was valid, so we capture the results
if( result.isValid() ) { if( authority.isValid() ) {
result.setUserInfo( authority.getUserInfo() ); result.setUserInfo( authority.getUserInfo() );
result.setHost( authority.getHost() ); result.setHost( authority.getHost() );
result.setPort( authority.getPort() ); result.setPort( authority.getPort() );
Expand Down Expand Up @@ -303,10 +300,10 @@ URIType URIHelper::parseAuthority( bool forceServer, const std::string& authorit
hostindex = index + 1; hostindex = index + 1;
} }


index = temp.find_last_of( ':' ); index = temp.rfind( ':' );
std::size_t endindex = temp.find( ']' ); std::size_t endindex = temp.find( ']' );


if( index != std::string::npos && endindex < index ) { if( index != std::string::npos && ( endindex < index || endindex == std::string::npos ) ){
// determine port and host // determine port and host
tempHost = temp.substr( 0, index ); tempHost = temp.substr( 0, index );


Expand All @@ -325,6 +322,7 @@ URIType URIHelper::parseAuthority( bool forceServer, const std::string& authorit


return result; return result;
} }

} catch( NumberFormatException& e ) { } catch( NumberFormatException& e ) {


if( forceServer ) { if( forceServer ) {
Expand Down
5 changes: 2 additions & 3 deletions src/main/decaf/net/URI.cpp
Expand Up @@ -86,11 +86,10 @@ URI::URI( const std::string& scheme, const std::string& userInfo,
if( scheme == "" && userInfo == "" && host == "" && if( scheme == "" && userInfo == "" && host == "" &&
path == "" && query == "" && fragment == "" ) { path == "" && query == "" && fragment == "" ) {


this->uri.setPath( "" );
return; return;
} }


if( scheme != "" && path.length() > 0 && path.at(0) != '/') { if( scheme != "" && !path.empty() && path.at(0) != '/') {


throw URISyntaxException( throw URISyntaxException(
__FILE__, __LINE__, path, __FILE__, __LINE__, path,
Expand Down Expand Up @@ -705,7 +704,7 @@ URI URI::parseServerAuthority() const throw( URISyntaxException ) {


URI newURI = *this; URI newURI = *this;


if( newURI.uri.isServerAuthority() ) { if( !newURI.uri.isServerAuthority() ) {
newURI.uri = URIHelper().parseAuthority( true, this->uri.getAuthority() ); newURI.uri = URIHelper().parseAuthority( true, this->uri.getAuthority() );
} }


Expand Down

0 comments on commit 7da2494

Please sign in to comment.