00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00027 #ifndef OW32_URIComponents_h
00028 #define OW32_URIComponents_h
00029
00030 #include <OW32/OW32Libs.h>
00031 #include <string>
00032
00033 namespace OW32
00034 {
00035
00039 class OW32_LIB_EXPORT CURIComponents
00040 {
00041 public:
00042
00043
00044 static const int d_scheme = 1;
00045 static const int d_authority = 2;
00046 static const int d_query = 4;
00047 static const int d_fragment = 8;
00048
00052 CURIComponents::CURIComponents() :
00053 m_defined(0)
00054 {
00055 }
00056
00063 CURIComponents::CURIComponents(
00064 const char* uriString,
00065 std::string::size_type uriStringLen) :
00066 m_defined(0)
00067 {
00068 parse(uriString, uriStringLen);
00069 }
00070
00076 CURIComponents::CURIComponents(
00077 const std::string &uriString) :
00078 m_defined(0)
00079 {
00080 parse(uriString.c_str(), uriString.length());
00081 }
00082
00089 void parse(
00090 const char* uriString,
00091 std::string::size_type uriStringLen);
00092
00099 void parse(
00100 const std::string &uriString)
00101 {
00102 parse(uriString.c_str(), uriString.length());
00103 }
00104
00110 std::string make() const;
00111
00117 void resolve(const CURIComponents &base);
00118
00125 void resolve(
00126 const char *base,
00127 const std::string::size_type baseLen)
00128 {
00129 CURIComponents baseURI(base, baseLen);
00130 return resolve(baseURI);
00131 }
00132
00138 void resolve(
00139 const std::string &base)
00140 {
00141 resolve(base.c_str(), base.length());
00142 }
00143
00153 static std::string resolve(
00154 const char *relative,
00155 std::string::size_type relativeLen,
00156 const char *base,
00157 std::string::size_type baseLen
00158 );
00159
00160
00168 static std::string resolve(
00169 const std::string &relative,
00170 const std::string &base
00171 )
00172 {
00173 return resolve(relative.c_str(), relative.length(), base.c_str(), base.length());
00174 }
00175
00179 void reset()
00180 {
00181 m_defined = 0;
00182 m_scheme.clear();
00183 m_authority.clear();
00184 m_path.clear();
00185 m_query.clear();
00186 m_fragment.clear();
00187 }
00188
00192 const std::string& getScheme() const
00193 {
00194 return m_scheme;
00195 }
00196
00200 bool isSchemeDefined() const
00201 {
00202 return !!(m_defined & d_scheme);
00203 }
00204
00208 void setScheme(const char *scheme)
00209 {
00210 if (!scheme) {
00211 m_defined &= ~d_scheme;
00212 m_scheme.clear();
00213 } else {
00214 m_scheme = scheme;
00215 m_defined |= d_scheme;
00216 }
00217 }
00218
00222 void setScheme(const std::string &scheme)
00223 {
00224 m_scheme = scheme;
00225 m_defined |= d_scheme;
00226 }
00227
00231 const std::string& getAuthority() const
00232 {
00233 return m_authority;
00234 }
00235
00239 bool isAuthorityDefined() const
00240 {
00241 return !!(m_defined & d_authority);
00242 }
00243
00247 void setAuthority(const char *authority)
00248 {
00249 if (!authority) {
00250 m_defined &= ~d_authority;
00251 m_authority.clear();
00252 } else {
00253 m_authority = authority;
00254 m_defined |= d_authority;
00255 }
00256 }
00257
00261 void setAuthority(const std::string &authority)
00262 {
00263 m_authority = authority;
00264 m_defined |= d_authority;
00265 }
00266
00270 const std::string& getPath() const
00271 {
00272 return m_path;
00273 }
00274
00278 void setPath(const char *path)
00279 {
00280 if (!path)
00281 m_path.clear();
00282 else
00283 m_path = path;
00284 }
00285
00289 void setPath(const std::string &path)
00290 {
00291 m_path = path;
00292 }
00293
00297 const std::string& getQuery() const
00298 {
00299 return m_query;
00300 }
00301
00305 bool isQueryDefined() const
00306 {
00307 return !!(m_defined & d_query);
00308 }
00309
00313 void setQuery(const char *query)
00314 {
00315 if (!query) {
00316 m_defined &= ~d_query;
00317 m_query.clear();
00318 } else {
00319 m_query = query;
00320 m_defined |= d_query;
00321 }
00322 }
00323
00327 void setQuery(const std::string &query)
00328 {
00329 m_query = query;
00330 m_defined |= d_query;
00331 }
00332
00336 const std::string& getFragment() const
00337 {
00338 return m_fragment;
00339 }
00340
00344 bool isFragmentDefined() const
00345 {
00346 return !!(m_defined & d_fragment);
00347 }
00348
00352 void setFragment(const char *fragment)
00353 {
00354 if (!fragment) {
00355 m_defined &= ~d_fragment;
00356 m_fragment.clear();
00357 } else {
00358 m_fragment = fragment;
00359 m_defined |= d_fragment;
00360 }
00361 }
00362
00366 void setFragment(const std::string &fragment)
00367 {
00368 m_fragment = fragment;
00369 m_defined |= d_fragment;
00370 }
00371
00375 unsigned int getDefined() const
00376 {
00377 return m_defined;
00378 }
00379
00383 void setDefined(unsigned int defined)
00384 {
00385 m_defined = defined;
00386 }
00387
00388 private:
00389 std::string m_scheme;
00390 std::string m_authority;
00391 std::string m_path;
00392 std::string m_query;
00393 std::string m_fragment;
00394
00395 unsigned int m_defined;
00396 };
00397
00401 class OW32_LIB_EXPORT CServerAuthority
00402 {
00403 public:
00407 CServerAuthority::CServerAuthority() :
00408 m_port(-1)
00409 {
00410 }
00411
00418 CServerAuthority::CServerAuthority(
00419 const char* authorityString,
00420 std::string::size_type authorityStringLen) :
00421 m_port(-1)
00422 {
00423 parse(authorityString, authorityStringLen);
00424 }
00425
00431 CServerAuthority::CServerAuthority(
00432 const std::string &authorityString) :
00433 m_port(-1)
00434 {
00435 parse(authorityString.c_str(), authorityString.length());
00436 }
00437
00444 void parse(
00445 const char *authorityString,
00446 std::string::size_type authorityStringLen);
00447
00453 std::string make() const;
00454
00458 void setHost(const std::string &host)
00459 {
00460 m_host = host;
00461 }
00462
00466 void setHost(const char *host)
00467 {
00468 if (!host)
00469 m_host.clear();
00470 else
00471 m_host = host;
00472 }
00473
00477 const std::string &getHost() const
00478 {
00479 return m_host;
00480 }
00481
00485 void setPort(const int port)
00486 {
00487 m_port = port;
00488 }
00489
00494 const int getPort() const
00495 {
00496 return m_port;
00497 }
00498
00502 void setUser(const char *user)
00503 {
00504 if (!user)
00505 m_user.clear();
00506 else
00507 m_user = user;
00508 }
00509
00513 void setUser(const std::string &user)
00514 {
00515 m_user = user;
00516 }
00517
00521 const std::string &getUser() const
00522 {
00523 return m_user;
00524 }
00525
00529 void setPassword(const std::string &password)
00530 {
00531 m_pass = password;
00532 }
00533
00537 void setPassword(const char *password)
00538 {
00539 if (!password)
00540 m_pass.clear();
00541 else
00542 m_pass = password;
00543 }
00544
00548 const std::string &getPassword() const
00549 {
00550 return m_pass;
00551 }
00552
00553 private:
00554 std::string m_host;
00555 int m_port;
00556 std::string m_user;
00557 std::string m_pass;
00558 };
00559
00560 }
00561
00562 #endif // OW32_URIComponents_h