00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef _OASYS_URL_H_
00019 #define _OASYS_URL_H_
00020
00021
00022 #include <list>
00023 #include <string>
00024
00025 #include "../compat/inttypes.h"
00026
00027 namespace oasys {
00028
00029 typedef enum urlerr_t {
00030 URLPARSE_OK,
00031 URLPARSE_UNPARSED,
00032 URLPARSE_NOURL,
00033 URLPARSE_BADSEP,
00034 URLPARSE_BADPROTO,
00035 URLPARSE_BADPORT,
00036 URLPARSE_NOHOST,
00037 };
00038
00042 class URL {
00043 public:
00047 URL()
00048 {
00049 clear();
00050 }
00051
00055 URL(const std::string& url)
00056 {
00057 url_.assign(url.data(), url.length());
00058 parse();
00059 }
00060
00064 URL(const char* url)
00065 {
00066 url_.assign(url);
00067 parse();
00068 }
00069
00073 URL(const URL& copy)
00074 : url_(copy.url_),
00075 proto_(copy.proto_),
00076 host_(copy.host_),
00077 port_(copy.port_),
00078 path_(copy.path_),
00079 err_(copy.err_)
00080 {
00081 }
00082
00086 void clear()
00087 {
00088 url_.erase();
00089 err_ = URLPARSE_UNPARSED;
00090 }
00091
00095 urlerr_t parse();
00096
00100 urlerr_t parse(const std::string& url)
00101 {
00102 url_.assign(url);
00103 return parse();
00104 }
00105
00109 void format(const std::string& proto,
00110 const std::string& host, u_int16_t port,
00111 const std::string& path);
00112
00116 urlerr_t status() const
00117 {
00118 return err_;
00119 }
00120
00124 bool valid() const
00125 {
00126 return (err_ == URLPARSE_OK);
00127 }
00128
00133
00134 const char* c_str() const { return url_.c_str(); }
00135 const char* data() const { return url_.data(); }
00136 size_t length() const { return url_.length(); }
00137
00138
00139
00140
00141
00142
00143 std::string url_;
00144 std::string proto_;
00145 std::string host_;
00146 u_int16_t port_;
00147 std::string path_;
00148
00149 urlerr_t err_;
00150
00151 protected:
00152 urlerr_t parse_internal();
00153 };
00154
00155 }
00156
00157 #endif
00158