Panda3D
|
00001 // Filename: urlSpec.h 00002 // Created by: drose (24Sep02) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef URLSPEC_H 00016 #define URLSPEC_H 00017 00018 #include "pandabase.h" 00019 #include "pnotify.h" 00020 00021 //////////////////////////////////////////////////////////////////// 00022 // Class : URLSpec 00023 // Description : A container for a URL, e.g. "http://server:port/path". 00024 // 00025 // The URLSpec object is similar to a Filename in that 00026 // it contains logic to identify the various parts of a 00027 // URL and return (or modify) them separately. 00028 //////////////////////////////////////////////////////////////////// 00029 class EXPCL_PANDAEXPRESS URLSpec { 00030 PUBLISHED: 00031 URLSpec(); 00032 INLINE URLSpec(const string &url, bool server_name_expected = false); 00033 INLINE URLSpec(const URLSpec ©); 00034 INLINE void operator = (const string &url); 00035 void operator = (const URLSpec ©); 00036 00037 INLINE bool operator == (const URLSpec &other) const; 00038 INLINE bool operator != (const URLSpec &other) const; 00039 INLINE bool operator < (const URLSpec &other) const; 00040 INLINE int compare_to(const URLSpec &other) const; 00041 00042 INLINE bool has_scheme() const; 00043 INLINE bool has_authority() const; 00044 INLINE bool has_username() const; 00045 INLINE bool has_server() const; 00046 INLINE bool has_port() const; 00047 INLINE bool has_path() const; 00048 INLINE bool has_query() const; 00049 00050 string get_scheme() const; 00051 INLINE string get_authority() const; 00052 INLINE string get_username() const; 00053 INLINE string get_server() const; 00054 INLINE string get_port_str() const; 00055 int get_port() const; 00056 string get_server_and_port() const; 00057 bool is_default_port() const; 00058 static int get_default_port_for_scheme(const string &scheme); 00059 string get_path() const; 00060 INLINE string get_query() const; 00061 string get_path_and_query() const; 00062 INLINE bool is_ssl() const; 00063 00064 INLINE const string &get_url() const; 00065 00066 void set_scheme(const string &scheme); 00067 void set_authority(const string &authority); 00068 void set_username(const string &username); 00069 void set_server(const string &server); 00070 void set_port(const string &port); 00071 void set_port(int port); 00072 void set_server_and_port(const string &server_and_port); 00073 void set_path(const string &path); 00074 void set_query(const string &query); 00075 00076 void set_url(const string &url, bool server_name_expected = false); 00077 00078 INLINE operator const string & () const; 00079 INLINE const char *c_str() const; 00080 INLINE bool empty() const; 00081 INLINE size_t length() const; 00082 INLINE char operator [] (int n) const; 00083 00084 bool input(istream &in); 00085 void output(ostream &out) const; 00086 00087 static string quote(const string &source, const string &safe = "/"); 00088 static string quote_plus(const string &source, const string &safe = "/"); 00089 static string unquote(const string &source); 00090 static string unquote_plus(const string &source); 00091 00092 private: 00093 void parse_authority(); 00094 00095 enum Flags { 00096 F_has_scheme = 0x0001, 00097 F_has_authority = 0x0002, 00098 F_has_username = 0x0004, 00099 F_has_server = 0x0008, 00100 F_has_port = 0x0010, 00101 F_has_path = 0x0020, 00102 F_has_query = 0x0040, 00103 }; 00104 00105 string _url; 00106 int _port; 00107 int _flags; 00108 00109 size_t _scheme_end; 00110 size_t _username_start; 00111 size_t _username_end; 00112 size_t _server_start; 00113 size_t _server_end; 00114 size_t _port_start; 00115 size_t _port_end; 00116 size_t _path_start; 00117 size_t _path_end; 00118 size_t _query_start; 00119 }; 00120 00121 INLINE istream &operator >> (istream &in, URLSpec &url); 00122 INLINE ostream &operator << (ostream &out, const URLSpec &url); 00123 00124 #include "urlSpec.I" 00125 00126 #endif 00127