00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _purl_h_
00021 #define _purl_h_
00022
00023 #include <pclasses/pexport.h>
00024 #include <pclasses/pexception.h>
00025 #include <pclasses/pnetdb.h>
00026 #include <iostream>
00027 #include <string>
00028
00029 namespace P {
00030
00032
00036 class PNET_EXPORT InvalidURL: public RuntimeError {
00037 public:
00038 inline InvalidURL(const char* _what, const SourceInfo& _si) throw()
00039 : RuntimeError(_what,_si) {}
00040 };
00041
00043
00051 class PNET_EXPORT URL {
00052 public:
00054
00057 URL();
00058
00060 URL(const std::string& url) throw(InvalidURL,NetDbError);
00061
00062 URL(const URL& url);
00063
00064 ~URL();
00065
00066 inline const std::string& protocol() const
00067 { return m_proto; }
00068
00069 void setProtocol(const std::string& proto, bool setPort = true);
00070
00071 inline const std::string& host() const
00072 { return m_host; }
00073
00074 void setHost(const std::string& host);
00075
00076 inline const std::string& user() const
00077 { return m_user; }
00078
00079 void setUser(const std::string& user);
00080
00081 inline const std::string& password() const
00082 { return m_passwd; }
00083
00084 void setPassword(const std::string& passwd);
00085
00086 inline unsigned short port() const
00087 { return m_port; }
00088
00089 void setPort(unsigned short port);
00090
00091 inline const std::string& path() const
00092 { return m_path; }
00093
00094 void setPath(const std::string& path);
00095
00096 URL& operator=(const URL& url);
00097 URL& operator=(const std::string& url) throw(InvalidURL,NetDbError);
00098
00099 bool operator==(const URL& url) const;
00100
00101 std::string str() const;
00102
00103 PNET_EXPORT friend std::ostream& operator<<(std::ostream& os, const URL& url);
00104 PNET_EXPORT friend std::istream& operator>>(std::istream& is, URL& url) throw(InvalidURL);
00105
00106 private:
00107 static unsigned short lookupPort(const std::string& service, const std::string& proto = "tcp");
00108
00109 std::string m_proto;
00110 std::string m_host;
00111 std::string m_user;
00112 std::string m_passwd;
00113 unsigned short m_port;
00114 std::string m_path;
00115 };
00116
00117 }
00118
00119 #endif