Panda3D
 All Classes Functions Variables Enumerations
urlSpec.h
1 // Filename: urlSpec.h
2 // Created by: drose (24Sep02)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef URLSPEC_H
16 #define URLSPEC_H
17 
18 #include "pandabase.h"
19 #include "pnotify.h"
20 
21 ////////////////////////////////////////////////////////////////////
22 // Class : URLSpec
23 // Description : A container for a URL, e.g. "http://server:port/path".
24 //
25 // The URLSpec object is similar to a Filename in that
26 // it contains logic to identify the various parts of a
27 // URL and return (or modify) them separately.
28 ////////////////////////////////////////////////////////////////////
29 class EXPCL_PANDAEXPRESS URLSpec {
30 PUBLISHED:
31  URLSpec();
32  INLINE URLSpec(const string &url, bool server_name_expected = false);
33  INLINE URLSpec(const URLSpec &copy);
34  INLINE void operator = (const string &url);
35  void operator = (const URLSpec &copy);
36 
37  INLINE bool operator == (const URLSpec &other) const;
38  INLINE bool operator != (const URLSpec &other) const;
39  INLINE bool operator < (const URLSpec &other) const;
40  INLINE int compare_to(const URLSpec &other) const;
41 
42  INLINE bool has_scheme() const;
43  INLINE bool has_authority() const;
44  INLINE bool has_username() const;
45  INLINE bool has_server() const;
46  INLINE bool has_port() const;
47  INLINE bool has_path() const;
48  INLINE bool has_query() const;
49 
50  string get_scheme() const;
51  INLINE string get_authority() const;
52  INLINE string get_username() const;
53  INLINE string get_server() const;
54  INLINE string get_port_str() const;
55  int get_port() const;
56  string get_server_and_port() const;
57  bool is_default_port() const;
58  static int get_default_port_for_scheme(const string &scheme);
59  string get_path() const;
60  INLINE string get_query() const;
61  string get_path_and_query() const;
62  INLINE bool is_ssl() const;
63 
64  INLINE const string &get_url() const;
65 
66  void set_scheme(const string &scheme);
67  void set_authority(const string &authority);
68  void set_username(const string &username);
69  void set_server(const string &server);
70  void set_port(const string &port);
71  void set_port(int port);
72  void set_server_and_port(const string &server_and_port);
73  void set_path(const string &path);
74  void set_query(const string &query);
75 
76  void set_url(const string &url, bool server_name_expected = false);
77 
78  INLINE operator const string & () const;
79  INLINE const char *c_str() const;
80  INLINE bool empty() const;
81  INLINE size_t length() const;
82  INLINE char operator [] (int n) const;
83 
84  bool input(istream &in);
85  void output(ostream &out) const;
86 
87  static string quote(const string &source, const string &safe = "/");
88  static string quote_plus(const string &source, const string &safe = "/");
89  static string unquote(const string &source);
90  static string unquote_plus(const string &source);
91 
92 private:
93  void parse_authority();
94 
95  enum Flags {
96  F_has_scheme = 0x0001,
97  F_has_authority = 0x0002,
98  F_has_username = 0x0004,
99  F_has_server = 0x0008,
100  F_has_port = 0x0010,
101  F_has_path = 0x0020,
102  F_has_query = 0x0040,
103  };
104 
105  string _url;
106  int _port;
107  int _flags;
108 
109  size_t _scheme_end;
110  size_t _username_start;
111  size_t _username_end;
112  size_t _server_start;
113  size_t _server_end;
114  size_t _port_start;
115  size_t _port_end;
116  size_t _path_start;
117  size_t _path_end;
118  size_t _query_start;
119 };
120 
121 INLINE istream &operator >> (istream &in, URLSpec &url);
122 INLINE ostream &operator << (ostream &out, const URLSpec &url);
123 
124 #include "urlSpec.I"
125 
126 #endif
127 
A container for a URL, e.g.
Definition: urlSpec.h:29
An STL function object class, this is intended to be used on any ordered collection of class objects ...
Definition: stl_compares.h:79