summaryrefslogtreecommitdiff
path: root/libproxy/url.hpp
blob: 44b44afbac514b290a80a39d7799d1e9ade9430e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*******************************************************************************
 * libproxy - A library for proxy configuration
 * Copyright (C) 2006 Nathaniel McCallum <nathaniel@natemccallum.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
 ******************************************************************************/

#ifndef URL_HPP_
#define URL_HPP_

#include <map>
#include <stdexcept>
#include <string>
#include <vector>

#include "config.hpp"

#define URL_GENERIC_DELIMITERS          ":/?#[]@"
#define URL_SUBCOMPONENT_DELIMITERS     "!$&'()*+,;="
#define URL_ALLOWED_IN_USERINFO_ELEMENT URL_SUBCOMPONENT_DELIMITERS
#define URL_ALLOWED_IN_USERINFO         URL_ALLOWED_IN_USERINFO_ELEMENT ":"
#define URL_ALLOWED_IN_PATH_ELEMENT     URL_SUBCOMPONENT_DELIMITERS ":@"
#define URL_ALLOWED_IN_PATH             URL_ALLOWED_IN_PATH_ELEMENT "/"

namespace libproxy {

using namespace std;

class DLL_PUBLIC parse_error : public runtime_error {
public:
	parse_error(const string& arg): runtime_error(arg) {}
};

class DLL_PUBLIC url {
public:
	static bool is_valid(const string &url);
	static string encode(const string &data, const string &valid_reserved = "");

	~url();
	url(const url& url);
	url(const string& url);
	bool operator==(const url& url) const;
	url& operator=(const url& url);
	url& operator=(const string &url);

	string   get_host()     const;
	sockaddr const* const* get_ips(bool usedns);
	string   get_password() const;
	string   get_path()     const;
	string   get_query()    const;
	uint16_t get_port()     const;
	string   get_scheme()   const;
	string   get_username() const;
	string   to_string()    const;
	char*    get_pac(); // Allocated, must free.  NULL on error.

private:
	void empty_cache();

	string     m_orig;
	string     m_scheme;
	string     m_user;
	string     m_pass;
	string     m_host;
	uint16_t   m_port;
	string     m_path;
	string     m_query;
	sockaddr** m_ips;
};

}

#endif /*URL_HPP_*/