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