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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
use std::ffi::CStr;
use std::str;
use curl_sys;
use libc::{c_int, c_char};
pub struct Version {
inner: *mut curl_sys::curl_version_info_data,
}
unsafe impl Send for Version {}
unsafe impl Sync for Version {}
pub struct Protocols<'a> {
cur: *const *const c_char,
_inner: &'a Version,
}
impl Version {
pub fn num() -> &'static str {
unsafe {
let s = CStr::from_ptr(curl_sys::curl_version() as *const _);
str::from_utf8(s.to_bytes()).unwrap()
}
}
pub fn get() -> Version {
unsafe {
let ptr = curl_sys::curl_version_info(curl_sys::CURLVERSION_FOURTH);
assert!(!ptr.is_null());
Version { inner: ptr }
}
}
pub fn version(&self) -> &str {
unsafe {
::opt_str((*self.inner).version).unwrap()
}
}
pub fn version_num(&self) -> u32 {
unsafe {
(*self.inner).version_num as u32
}
}
pub fn host(&self) -> &str {
unsafe {
::opt_str((*self.inner).host).unwrap()
}
}
pub fn feature_ipv6(&self) -> bool {
self.flag(curl_sys::CURL_VERSION_IPV6)
}
pub fn feature_ssl(&self) -> bool {
self.flag(curl_sys::CURL_VERSION_SSL)
}
pub fn feature_libz(&self) -> bool {
self.flag(curl_sys::CURL_VERSION_LIBZ)
}
pub fn feature_ntlm(&self) -> bool {
self.flag(curl_sys::CURL_VERSION_NTLM)
}
pub fn feature_gss_negotiate(&self) -> bool {
self.flag(curl_sys::CURL_VERSION_GSSNEGOTIATE)
}
pub fn feature_debug(&self) -> bool {
self.flag(curl_sys::CURL_VERSION_DEBUG)
}
pub fn feature_spnego(&self) -> bool {
self.flag(curl_sys::CURL_VERSION_SPNEGO)
}
pub fn feature_largefile(&self) -> bool {
self.flag(curl_sys::CURL_VERSION_LARGEFILE)
}
pub fn feature_idn(&self) -> bool {
self.flag(curl_sys::CURL_VERSION_IDN)
}
pub fn feature_sspi(&self) -> bool {
self.flag(curl_sys::CURL_VERSION_SSPI)
}
pub fn feature_async_dns(&self) -> bool {
self.flag(curl_sys::CURL_VERSION_ASYNCHDNS)
}
pub fn feature_conv(&self) -> bool {
self.flag(curl_sys::CURL_VERSION_CONV)
}
pub fn feature_tlsauth_srp(&self) -> bool {
self.flag(curl_sys::CURL_VERSION_TLSAUTH_SRP)
}
pub fn feature_ntlm_wb(&self) -> bool {
self.flag(curl_sys::CURL_VERSION_NTLM_WB)
}
fn flag(&self, flag: c_int) -> bool {
unsafe {
(*self.inner).features & flag != 0
}
}
pub fn ssl_version(&self) -> Option<&str> {
unsafe {
::opt_str((*self.inner).ssl_version)
}
}
pub fn libz_version(&self) -> Option<&str> {
unsafe {
::opt_str((*self.inner).libz_version)
}
}
pub fn protocols(&self) -> Protocols {
unsafe {
Protocols { _inner: self, cur: (*self.inner).protocols }
}
}
pub fn ares_version(&self) -> Option<&str> {
unsafe {
if (*self.inner).age >= 1 {
::opt_str((*self.inner).ares)
} else {
None
}
}
}
pub fn ares_version_num(&self) -> Option<u32> {
unsafe {
if (*self.inner).age >= 1 {
Some((*self.inner).ares_num as u32)
} else {
None
}
}
}
pub fn libidn_version(&self) -> Option<&str> {
unsafe {
if (*self.inner).age >= 2 {
::opt_str((*self.inner).libidn)
} else {
None
}
}
}
pub fn iconv_version_num(&self) -> Option<u32> {
unsafe {
if (*self.inner).age >= 3 {
Some((*self.inner).iconv_ver_num as u32)
} else {
None
}
}
}
pub fn libssh_version(&self) -> Option<&str> {
unsafe {
if (*self.inner).age >= 3 {
::opt_str((*self.inner).libssh_version)
} else {
None
}
}
}
}
impl<'a> Iterator for Protocols<'a> {
type Item = &'a str;
fn next(&mut self) -> Option<&'a str> {
unsafe {
if (*self.cur).is_null() {
return None
}
let ret = ::opt_str(*self.cur).unwrap();
self.cur = self.cur.offset(1);
Some(ret)
}
}
}