-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcurl_url.hpp
105 lines (94 loc) · 2.9 KB
/
curl_url.hpp
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#ifndef __curl_cpp_curl_url_HPP__
# define __curl_cpp_curl_url_HPP__
# include "curl.hpp"
namespace curl {
/**
* @pre for using this class: curl_t::has_CURLU()
* @example curl_url.cc
*
* Why make Url_ref_t RAII-less?
*
* Since url can be used by multiple Easy_ref_t, users might want to
* manage it using std::shared_ptr.
*
* It Url_ref_t is RAII-ed, then user would have to write
* std::shared_ptr<Url_ref_t>, introducing another layer of indirection
* while it doesn't have to.
*
* Url_ref_t's member function cannot be called in multiple threads simultaneously.
*
* "<scheme>://<user>:<password>@<host>:<port>/<path>;<params>?<query>#<fragment>"
*/
class Url_ref_t {
protected:
static void check_url(int code);
public:
/**
* If url == nullptr, then calling any member function has
* undefined behavior.
*/
char *url;
enum class set_code {
ok,
/**
* For url, it could be:
* - url is longer than 8000000 bytes (7MiB)
* - scheme too long (newest libcurl support up to 40 bytes)
* - url does not match standard syntax
* - lack necessary part, e.g. scheme, host
* - contain junk character <= 0x1f || == 0x7f
*/
malform_input,
bad_port_number,
unsupported_scheme,
};
/**
* @return all of set_code
*/
auto set_url(const char *url_arg) noexcept -> Ret_except<set_code, std::bad_alloc>;
/**
* @return only set_code::unsupported_scheme, malform_input, ok
*/
auto set_scheme(const char *scheme) noexcept -> Ret_except<set_code, std::bad_alloc>;
/**
* @return only set_code::malform_input, ok
*/
auto set_options(const char *options) noexcept -> Ret_except<set_code, std::bad_alloc>;
/**
* @return only set_code::malform_input, ok
*/
auto set_query(const char *query) noexcept -> Ret_except<set_code, std::bad_alloc>;
/**
* Deleter for curl::Url_ref_t::string.
*/
struct curl_string_deleter {
void operator () (char *p) const noexcept;
};
/**
* std::unique_ptr for any libcurl-returned string
* that requires deallocation.
*/
using string = std::unique_ptr<char, curl_string_deleter>;
/**
* get_code::no_* can be returned by respective get_*() function.
*/
enum class get_code {
no_scheme,
no_user,
no_passwd,
no_options,
no_host,
no_port,
no_query,
no_fragment,
};
/**
* @return no_scheme or no_host
*/
auto get_url() const noexcept -> Ret_except<string, get_code, std::bad_alloc>;
auto get_scheme() const noexcept -> Ret_except<string, get_code, std::bad_alloc>;
auto get_options() const noexcept -> Ret_except<string, get_code, std::bad_alloc>;
auto get_query() const noexcept -> Ret_except<string, get_code, std::bad_alloc>;
};
} /* namespace curl */
#endif