Line |
Branch |
Exec |
Source |
1 |
|
|
/** |
2 |
|
|
* This file is part of the CernVM File System. |
3 |
|
|
*/ |
4 |
|
|
|
5 |
|
|
#ifndef CVMFS_URL_H_ |
6 |
|
|
#define CVMFS_URL_H_ |
7 |
|
|
|
8 |
|
|
#include <string> |
9 |
|
|
|
10 |
|
|
class Url { |
11 |
|
|
public: |
12 |
|
|
/** |
13 |
|
|
* Parse a URL string and build a Url object |
14 |
|
|
* |
15 |
|
|
* A URL string is parsed and a Url object is constructed with the extracted |
16 |
|
|
* address and port components. |
17 |
|
|
* |
18 |
|
|
* Returns NULL if the URL string is not well formed |
19 |
|
|
* |
20 |
|
|
* Ex: The url: <fqdn>:<port>/<path> will parse as address <fqdn>/<path> |
21 |
|
|
* and port <port> |
22 |
|
|
*/ |
23 |
|
|
static const int kDefaultPort; |
24 |
|
|
static const char* kDefaultProtocol; |
25 |
|
|
|
26 |
|
|
/** |
27 |
|
|
* Parse an URL string |
28 |
|
|
* |
29 |
|
|
* Parse an URL string and extract the protocol, host, port, and path |
30 |
|
|
* components. The method can be called with protocol and port values that are |
31 |
|
|
* used when the input string doesn't contain these parts. The default |
32 |
|
|
* protocol is "http" and the default port is 80 |
33 |
|
|
*/ |
34 |
|
|
static Url* Parse(const std::string& url, |
35 |
|
|
const std::string& default_protocol = kDefaultProtocol, |
36 |
|
|
int default_port = kDefaultPort); |
37 |
|
|
static bool ValidateHost(const std::string& host); |
38 |
|
|
|
39 |
|
|
~Url(); |
40 |
|
|
|
41 |
|
8 |
std::string protocol() const { return protocol_; } |
42 |
|
8 |
std::string address() const { return address_; } |
43 |
|
8 |
std::string host() const { return host_; } |
44 |
|
8 |
std::string path() const { return path_; } |
45 |
|
8 |
int port() const { return port_; } |
46 |
|
|
|
47 |
|
|
private: |
48 |
|
|
Url(); |
49 |
|
|
Url(const std::string& protocol, const std::string& host, |
50 |
|
|
const std::string& path, int port); |
51 |
|
|
|
52 |
|
|
std::string protocol_; |
53 |
|
|
std::string host_; |
54 |
|
|
std::string path_; |
55 |
|
|
int port_; |
56 |
|
|
std::string address_; |
57 |
|
|
}; |
58 |
|
|
|
59 |
|
|
#endif // CVMFS_URL_H_ |
60 |
|
|
|