00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00036 #include "OW_config.h"
00037 #include "OW_URL.hpp"
00038 #include "OW_StringBuffer.hpp"
00039 #include "OW_ExceptionIds.hpp"
00040
00041 namespace OW_NAMESPACE
00042 {
00043
00044 OW_DEFINE_EXCEPTION_WITH_ID(MalformedURL);
00045
00047 String
00048 URL::toString() const
00049 {
00050 StringBuffer retval;
00051 if (!scheme.empty())
00052 {
00053 retval += scheme;
00054 retval += "://";
00055 }
00056 if (!principal.empty() || !credential.empty())
00057 {
00058 retval += principal;
00059 if (!credential.empty())
00060 {
00061 retval += ':';
00062 retval += credential;
00063 }
00064 retval += '@';
00065 }
00066 retval += host;
00067 if (!port.empty())
00068 {
00069 retval += ":";
00070 retval += port;
00071 }
00072 if (!namespaceName.empty())
00073 {
00074 retval += '/';
00075 retval += namespaceName;
00076
00077 if (!modelPath.empty())
00078 {
00079 retval += "/:";
00080 retval += modelPath;
00081 }
00082 }
00083 return retval.releaseString();
00084 }
00086 URL::URL()
00087 {
00088 }
00089
00091 URL::URL(const String& sUrl)
00092 {
00093 String sURL = sUrl;
00094 sURL.trim();
00095
00096
00097 size_t iBeginIndex = 0;
00098 size_t iEndIndex = sURL.indexOf( "://" );
00099 if ( iEndIndex != String::npos )
00100 {
00101 if ( iEndIndex > 0 )
00102 {
00103 scheme = sURL.substring( 0, iEndIndex ).toLowerCase();
00104 }
00105 iBeginIndex = iEndIndex + 3;
00106 }
00107
00108 iEndIndex = sURL.indexOf( '@', iBeginIndex );
00109 if ( iEndIndex != String::npos )
00110 {
00111 String sNamePass = sURL.substring( iBeginIndex, iEndIndex - iBeginIndex );
00112 iBeginIndex = sNamePass.indexOf( ':' );
00113 if ( iBeginIndex != String::npos )
00114 {
00115 if ( iBeginIndex > 0 )
00116 {
00117 principal = sNamePass.substring( 0, iBeginIndex );
00118 }
00119 if ( iBeginIndex < iEndIndex-1 )
00120 {
00121 credential = sNamePass.substring( iBeginIndex + 1 );
00122 }
00123 }
00124 else if ( !sNamePass.empty())
00125 {
00126 principal = sNamePass;
00127 }
00128 iBeginIndex = iEndIndex + 1;
00129 }
00130
00131 iEndIndex = sURL.indexOf( '/', iBeginIndex );
00132 if (iEndIndex == String::npos)
00133 {
00134 iEndIndex = sURL.length();
00135 }
00136
00137 String hostPort = sURL.substring(iBeginIndex, iEndIndex - iBeginIndex);
00138 if (hostPort.empty())
00139 {
00140 OW_THROW(MalformedURLException, String("Invalid URL: " + sUrl).c_str());
00141 }
00142 size_t colonIdx = hostPort.indexOf( ':' );
00143 if ( colonIdx != String::npos )
00144 {
00145 host = hostPort.substring( 0, colonIdx );
00146 port = hostPort.substring( colonIdx + 1 );
00147 }
00148 else
00149 {
00150 host = hostPort;
00151 }
00152 if (host.empty())
00153 {
00154 OW_THROW(MalformedURLException, String("Invalid URL: " + sUrl).c_str());
00155 }
00156
00157
00158 iBeginIndex = sURL.indexOf('/', iBeginIndex);
00159 if ( iBeginIndex != String::npos )
00160 {
00161 iEndIndex = sURL.indexOf("/:", iBeginIndex);
00162 if (iEndIndex == String::npos)
00163 {
00164 iEndIndex = sURL.length();
00165 }
00166 namespaceName = sURL.substring( iBeginIndex+1, iEndIndex - (iBeginIndex+1) );
00167
00168
00169 iBeginIndex = sURL.indexOf("/:", iBeginIndex);
00170 if (iBeginIndex != String::npos)
00171 {
00172 modelPath = sURL.substring(iBeginIndex + 2);
00173 }
00174 }
00175 }
00176
00177
00178 const char* const URL::CIMXML_WBEM = "cimxml.wbem";
00179 const char* const URL::CIMXML_WBEMS = "cimxml.wbems";
00180 const char* const URL::HTTP = "http";
00181 const char* const URL::HTTPS = "https";
00182 const char* const URL::OWBINARY_WBEM = "owbinary.wbem";
00183 const char* const URL::OWBINARY_WBEMS = "owbinary.wbems";
00184 const char* const URL::OWBINARY = "owbinary";
00185
00186
00187 const char* const URL::OWIPC = "owipc";
00188
00189
00190 }
00191