GCC Code Coverage Report


Directory: src/gate/
File: src/gate/net/platform/libcurl_api.h
Date: 2025-09-14 13:10:38
Exec Total Coverage
Lines: 71 167 42.5%
Functions: 7 9 77.8%
Branches: 33 146 22.6%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright(c) 2018-2025, Stefan Meislinger <sm@opengate.at> |
4 | All rights reserved. |
5 | |
6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met:|
8 | |
9 | 1. Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. |
11 | 2. Redistributions in binary form must reproduce the above copyright |
12 | notice, this list of conditions and the following disclaimer in the |
13 | documentation and/or other materials provided with the distribution. |
14 | |
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"|
16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
25 | THE POSSIBILITY OF SUCH DAMAGE. |
26 +----------------------------------------------------------------------------+
27 */
28
29 #ifndef GATE_NET_LIBCURL_API_H_INCLUDED
30 #define GATE_NET_LIBCURL_API_H_INCLUDED
31
32 typedef enum
33 {
34 CURLE_OK = 0,
35 CURLE_UNSUPPORTED_PROTOCOL, /* 1 */
36 CURLE_FAILED_INIT, /* 2 */
37 CURLE_URL_MALFORMAT, /* 3 */
38 CURLE_NOT_BUILT_IN, /* 4 - [was obsoleted in August 2007 for
39 7.17.0, reused in April 2011 for 7.21.5] */
40 CURLE_COULDNT_RESOLVE_PROXY, /* 5 */
41 CURLE_COULDNT_RESOLVE_HOST, /* 6 */
42 CURLE_COULDNT_CONNECT, /* 7 */
43 CURLE_FTP_WEIRD_SERVER_REPLY, /* 8 */
44 CURLE_REMOTE_ACCESS_DENIED, /* 9 a service was denied by the server
45 due to lack of access - when login fails
46 this is not returned. */
47 CURLE_FTP_ACCEPT_FAILED, /* 10 - [was obsoleted in April 2006 for
48 7.15.4, reused in Dec 2011 for 7.24.0]*/
49 CURLE_FTP_WEIRD_PASS_REPLY, /* 11 */
50 CURLE_FTP_ACCEPT_TIMEOUT, /* 12 - timeout occurred accepting server
51 [was obsoleted in August 2007 for 7.17.0,
52 reused in Dec 2011 for 7.24.0]*/
53 CURLE_FTP_WEIRD_PASV_REPLY, /* 13 */
54 CURLE_FTP_WEIRD_227_FORMAT, /* 14 */
55 CURLE_FTP_CANT_GET_HOST, /* 15 */
56 CURLE_OBSOLETE16, /* 16 - NOT USED */
57 CURLE_FTP_COULDNT_SET_TYPE, /* 17 */
58 CURLE_PARTIAL_FILE, /* 18 */
59 CURLE_FTP_COULDNT_RETR_FILE, /* 19 */
60 CURLE_OBSOLETE20, /* 20 - NOT USED */
61 CURLE_QUOTE_ERROR, /* 21 - quote command failure */
62 CURLE_HTTP_RETURNED_ERROR, /* 22 */
63 CURLE_WRITE_ERROR, /* 23 */
64 CURLE_OBSOLETE24, /* 24 - NOT USED */
65 CURLE_UPLOAD_FAILED, /* 25 - failed upload "command" */
66 CURLE_READ_ERROR, /* 26 - couldn't open/read from file */
67 CURLE_OUT_OF_MEMORY, /* 27 */
68 /* Note: CURLE_OUT_OF_MEMORY may sometimes indicate a conversion error
69 instead of a memory allocation error if CURL_DOES_CONVERSIONS
70 is defined
71 */
72 CURLE_OPERATION_TIMEDOUT, /* 28 - the timeout time was reached */
73 CURLE_OBSOLETE29, /* 29 - NOT USED */
74 CURLE_FTP_PORT_FAILED, /* 30 - FTP PORT operation failed */
75 CURLE_FTP_COULDNT_USE_REST, /* 31 - the REST command failed */
76 CURLE_OBSOLETE32, /* 32 - NOT USED */
77 CURLE_RANGE_ERROR, /* 33 - RANGE "command" didn't work */
78 CURLE_HTTP_POST_ERROR, /* 34 */
79 CURLE_SSL_CONNECT_ERROR, /* 35 - wrong when connecting with SSL */
80 CURLE_BAD_DOWNLOAD_RESUME, /* 36 - couldn't resume download */
81 CURLE_FILE_COULDNT_READ_FILE, /* 37 */
82 CURLE_LDAP_CANNOT_BIND, /* 38 */
83 CURLE_LDAP_SEARCH_FAILED, /* 39 */
84 CURLE_OBSOLETE40, /* 40 - NOT USED */
85 CURLE_FUNCTION_NOT_FOUND, /* 41 */
86 CURLE_ABORTED_BY_CALLBACK, /* 42 */
87 CURLE_BAD_FUNCTION_ARGUMENT, /* 43 */
88 CURLE_OBSOLETE44, /* 44 - NOT USED */
89 CURLE_INTERFACE_FAILED, /* 45 - CURLOPT_INTERFACE failed */
90 CURLE_OBSOLETE46, /* 46 - NOT USED */
91 CURLE_TOO_MANY_REDIRECTS, /* 47 - catch endless re-direct loops */
92 CURLE_UNKNOWN_OPTION, /* 48 - User specified an unknown option */
93 CURLE_TELNET_OPTION_SYNTAX, /* 49 - Malformed telnet option */
94 CURLE_OBSOLETE50, /* 50 - NOT USED */
95 CURLE_PEER_FAILED_VERIFICATION, /* 51 - peer's certificate or fingerprint
96 wasn't verified fine */
97 CURLE_GOT_NOTHING, /* 52 - when this is a specific error */
98 CURLE_SSL_ENGINE_NOTFOUND, /* 53 - SSL crypto engine not found */
99 CURLE_SSL_ENGINE_SETFAILED, /* 54 - can not set SSL crypto engine as
100 default */
101 CURLE_SEND_ERROR, /* 55 - failed sending network data */
102 CURLE_RECV_ERROR, /* 56 - failure in receiving network data */
103 CURLE_OBSOLETE57, /* 57 - NOT IN USE */
104 CURLE_SSL_CERTPROBLEM, /* 58 - problem with the local certificate */
105 CURLE_SSL_CIPHER, /* 59 - couldn't use specified cipher */
106 CURLE_SSL_CACERT, /* 60 - problem with the CA cert (path?) */
107 CURLE_BAD_CONTENT_ENCODING, /* 61 - Unrecognized/bad encoding */
108 CURLE_LDAP_INVALID_URL, /* 62 - Invalid LDAP URL */
109 CURLE_FILESIZE_EXCEEDED, /* 63 - Maximum file size exceeded */
110 CURLE_USE_SSL_FAILED, /* 64 - Requested FTP SSL level failed */
111 CURLE_SEND_FAIL_REWIND, /* 65 - Sending the data requires a rewind
112 that failed */
113 CURLE_SSL_ENGINE_INITFAILED, /* 66 - failed to initialise ENGINE */
114 CURLE_LOGIN_DENIED, /* 67 - user, password or similar was not
115 accepted and we failed to login */
116 CURLE_TFTP_NOTFOUND, /* 68 - file not found on server */
117 CURLE_TFTP_PERM, /* 69 - permission problem on server */
118 CURLE_REMOTE_DISK_FULL, /* 70 - out of disk space on server */
119 CURLE_TFTP_ILLEGAL, /* 71 - Illegal TFTP operation */
120 CURLE_TFTP_UNKNOWNID, /* 72 - Unknown transfer ID */
121 CURLE_REMOTE_FILE_EXISTS, /* 73 - File already exists */
122 CURLE_TFTP_NOSUCHUSER, /* 74 - No such user */
123 CURLE_CONV_FAILED, /* 75 - conversion failed */
124 CURLE_CONV_REQD, /* 76 - caller must register conversion
125 callbacks using curl_easy_setopt options
126 CURLOPT_CONV_FROM_NETWORK_FUNCTION,
127 CURLOPT_CONV_TO_NETWORK_FUNCTION, and
128 CURLOPT_CONV_FROM_UTF8_FUNCTION */
129 CURLE_SSL_CACERT_BADFILE, /* 77 - could not load CACERT file, missing
130 or wrong format */
131 CURLE_REMOTE_FILE_NOT_FOUND, /* 78 - remote file not found */
132 CURLE_SSH, /* 79 - error from the SSH layer, somewhat
133 generic so the error message will be of
134 interest when this has happened */
135
136 CURLE_SSL_SHUTDOWN_FAILED, /* 80 - Failed to shut down the SSL
137 connection */
138 CURLE_AGAIN, /* 81 - socket is not ready for send/recv,
139 wait till it's ready and try again (Added
140 in 7.18.2) */
141 CURLE_SSL_CRL_BADFILE, /* 82 - could not load CRL file, missing or
142 wrong format (Added in 7.19.0) */
143 CURLE_SSL_ISSUER_ERROR, /* 83 - Issuer check failed. (Added in
144 7.19.0) */
145 CURLE_FTP_PRET_FAILED, /* 84 - a PRET command failed */
146 CURLE_RTSP_CSEQ_ERROR, /* 85 - mismatch of RTSP CSeq numbers */
147 CURLE_RTSP_SESSION_ERROR, /* 86 - mismatch of RTSP Session Ids */
148 CURLE_FTP_BAD_FILE_LIST, /* 87 - unable to parse FTP file list */
149 CURLE_CHUNK_FAILED, /* 88 - chunk callback reported error */
150 CURL_LAST /* never use! */
151 } CURLcode;
152
153
154
155 /* CURLPROTO_ defines are for the CURLOPT_*PROTOCOLS options */
156 #define CURLPROTO_HTTP (1<<0)
157 #define CURLPROTO_HTTPS (1<<1)
158 #define CURLPROTO_FTP (1<<2)
159 #define CURLPROTO_FTPS (1<<3)
160 #define CURLPROTO_SCP (1<<4)
161 #define CURLPROTO_SFTP (1<<5)
162 #define CURLPROTO_TELNET (1<<6)
163 #define CURLPROTO_LDAP (1<<7)
164 #define CURLPROTO_LDAPS (1<<8)
165 #define CURLPROTO_DICT (1<<9)
166 #define CURLPROTO_FILE (1<<10)
167 #define CURLPROTO_TFTP (1<<11)
168 #define CURLPROTO_IMAP (1<<12)
169 #define CURLPROTO_IMAPS (1<<13)
170 #define CURLPROTO_POP3 (1<<14)
171 #define CURLPROTO_POP3S (1<<15)
172 #define CURLPROTO_SMTP (1<<16)
173 #define CURLPROTO_SMTPS (1<<17)
174 #define CURLPROTO_RTSP (1<<18)
175 #define CURLPROTO_RTMP (1<<19)
176 #define CURLPROTO_RTMPT (1<<20)
177 #define CURLPROTO_RTMPE (1<<21)
178 #define CURLPROTO_RTMPTE (1<<22)
179 #define CURLPROTO_RTMPS (1<<23)
180 #define CURLPROTO_RTMPTS (1<<24)
181 #define CURLPROTO_GOPHER (1<<25)
182 #define CURLPROTO_ALL (~0) /* enable everything */
183
184
185 #define CURLOPTTYPE_LONG 0
186 #define CURLOPTTYPE_OBJECTPOINT 10000
187 #define CURLOPTTYPE_FUNCTIONPOINT 20000
188 #define CURLOPTTYPE_OFF_T 30000
189
190
191 #define CINIT(name,type,number) CURLOPT_ ## name = type + number
192
193 typedef enum
194 {
195 CINIT(FILE, CURLOPTTYPE_OBJECTPOINT, 1),
196 CINIT(URL, CURLOPTTYPE_OBJECTPOINT, 2),
197 CINIT(PORT, CURLOPTTYPE_LONG, 3),
198 CINIT(PROXY, CURLOPTTYPE_OBJECTPOINT, 4),
199 CINIT(USERPWD, CURLOPTTYPE_OBJECTPOINT, 5),
200 CINIT(PROXYUSERPWD, CURLOPTTYPE_OBJECTPOINT, 6),
201 CINIT(RANGE, CURLOPTTYPE_OBJECTPOINT, 7),
202 CINIT(INFILE, CURLOPTTYPE_OBJECTPOINT, 9),
203 CINIT(ERRORBUFFER, CURLOPTTYPE_OBJECTPOINT, 10),
204 CINIT(WRITEFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 11),
205 CINIT(READFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 12),
206 CINIT(TIMEOUT, CURLOPTTYPE_LONG, 13),
207 CINIT(INFILESIZE, CURLOPTTYPE_LONG, 14),
208 CINIT(POSTFIELDS, CURLOPTTYPE_OBJECTPOINT, 15),
209 CINIT(REFERER, CURLOPTTYPE_OBJECTPOINT, 16),
210 CINIT(FTPPORT, CURLOPTTYPE_OBJECTPOINT, 17),
211 CINIT(USERAGENT, CURLOPTTYPE_OBJECTPOINT, 18),
212 CINIT(LOW_SPEED_LIMIT, CURLOPTTYPE_LONG, 19),
213 CINIT(LOW_SPEED_TIME, CURLOPTTYPE_LONG, 20),
214 CINIT(RESUME_FROM, CURLOPTTYPE_LONG, 21),
215 CINIT(COOKIE, CURLOPTTYPE_OBJECTPOINT, 22),
216 CINIT(HTTPHEADER, CURLOPTTYPE_OBJECTPOINT, 23),
217 CINIT(HTTPPOST, CURLOPTTYPE_OBJECTPOINT, 24),
218 CINIT(SSLCERT, CURLOPTTYPE_OBJECTPOINT, 25),
219 CINIT(KEYPASSWD, CURLOPTTYPE_OBJECTPOINT, 26),
220 CINIT(CRLF, CURLOPTTYPE_LONG, 27),
221 CINIT(QUOTE, CURLOPTTYPE_OBJECTPOINT, 28),
222 CINIT(WRITEHEADER, CURLOPTTYPE_OBJECTPOINT, 29),
223 CINIT(COOKIEFILE, CURLOPTTYPE_OBJECTPOINT, 31),
224 CINIT(SSLVERSION, CURLOPTTYPE_LONG, 32),
225 CINIT(TIMECONDITION, CURLOPTTYPE_LONG, 33),
226 CINIT(TIMEVALUE, CURLOPTTYPE_LONG, 34),
227 CINIT(CUSTOMREQUEST, CURLOPTTYPE_OBJECTPOINT, 36),
228 CINIT(STDERR, CURLOPTTYPE_OBJECTPOINT, 37),
229 CINIT(POSTQUOTE, CURLOPTTYPE_OBJECTPOINT, 39),
230 CINIT(WRITEINFO, CURLOPTTYPE_OBJECTPOINT, 40),
231 CINIT(VERBOSE, CURLOPTTYPE_LONG, 41),
232 CINIT(HEADER, CURLOPTTYPE_LONG, 42),
233 CINIT(NOPROGRESS, CURLOPTTYPE_LONG, 43),
234 CINIT(NOBODY, CURLOPTTYPE_LONG, 44),
235 CINIT(FAILONERROR, CURLOPTTYPE_LONG, 45),
236 CINIT(UPLOAD, CURLOPTTYPE_LONG, 46),
237 CINIT(POST, CURLOPTTYPE_LONG, 47),
238 CINIT(DIRLISTONLY, CURLOPTTYPE_LONG, 48),
239 CINIT(APPEND, CURLOPTTYPE_LONG, 50),
240 CINIT(NETRC, CURLOPTTYPE_LONG, 51),
241 CINIT(FOLLOWLOCATION, CURLOPTTYPE_LONG, 52),
242 CINIT(TRANSFERTEXT, CURLOPTTYPE_LONG, 53),
243 CINIT(PUT, CURLOPTTYPE_LONG, 54),
244 CINIT(PROGRESSFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 56),
245 CINIT(PROGRESSDATA, CURLOPTTYPE_OBJECTPOINT, 57),
246 CINIT(AUTOREFERER, CURLOPTTYPE_LONG, 58),
247 CINIT(PROXYPORT, CURLOPTTYPE_LONG, 59),
248 CINIT(POSTFIELDSIZE, CURLOPTTYPE_LONG, 60),
249 CINIT(HTTPPROXYTUNNEL, CURLOPTTYPE_LONG, 61),
250 CINIT(INTERFACE, CURLOPTTYPE_OBJECTPOINT, 62),
251 CINIT(KRBLEVEL, CURLOPTTYPE_OBJECTPOINT, 63),
252 CINIT(SSL_VERIFYPEER, CURLOPTTYPE_LONG, 64),
253 CINIT(CAINFO, CURLOPTTYPE_OBJECTPOINT, 65),
254 CINIT(MAXREDIRS, CURLOPTTYPE_LONG, 68),
255 CINIT(FILETIME, CURLOPTTYPE_LONG, 69),
256 CINIT(TELNETOPTIONS, CURLOPTTYPE_OBJECTPOINT, 70),
257 CINIT(MAXCONNECTS, CURLOPTTYPE_LONG, 71),
258 CINIT(CLOSEPOLICY, CURLOPTTYPE_LONG, 72),
259 CINIT(FRESH_CONNECT, CURLOPTTYPE_LONG, 74),
260 CINIT(FORBID_REUSE, CURLOPTTYPE_LONG, 75),
261 CINIT(RANDOM_FILE, CURLOPTTYPE_OBJECTPOINT, 76),
262 CINIT(EGDSOCKET, CURLOPTTYPE_OBJECTPOINT, 77),
263 CINIT(CONNECTTIMEOUT, CURLOPTTYPE_LONG, 78),
264 CINIT(HEADERFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 79),
265 CINIT(HTTPGET, CURLOPTTYPE_LONG, 80),
266 CINIT(SSL_VERIFYHOST, CURLOPTTYPE_LONG, 81),
267 CINIT(COOKIEJAR, CURLOPTTYPE_OBJECTPOINT, 82),
268 CINIT(SSL_CIPHER_LIST, CURLOPTTYPE_OBJECTPOINT, 83),
269 CINIT(HTTP_VERSION, CURLOPTTYPE_LONG, 84),
270 CINIT(FTP_USE_EPSV, CURLOPTTYPE_LONG, 85),
271 CINIT(SSLCERTTYPE, CURLOPTTYPE_OBJECTPOINT, 86),
272 CINIT(SSLKEY, CURLOPTTYPE_OBJECTPOINT, 87),
273 CINIT(SSLKEYTYPE, CURLOPTTYPE_OBJECTPOINT, 88),
274 CINIT(SSLENGINE, CURLOPTTYPE_OBJECTPOINT, 89),
275 CINIT(SSLENGINE_DEFAULT, CURLOPTTYPE_LONG, 90),
276 CINIT(DNS_USE_GLOBAL_CACHE, CURLOPTTYPE_LONG, 91),
277 CINIT(DNS_CACHE_TIMEOUT, CURLOPTTYPE_LONG, 92),
278 CINIT(PREQUOTE, CURLOPTTYPE_OBJECTPOINT, 93),
279 CINIT(DEBUGFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 94),
280 CINIT(DEBUGDATA, CURLOPTTYPE_OBJECTPOINT, 95),
281 CINIT(COOKIESESSION, CURLOPTTYPE_LONG, 96),
282 CINIT(CAPATH, CURLOPTTYPE_OBJECTPOINT, 97),
283 CINIT(BUFFERSIZE, CURLOPTTYPE_LONG, 98),
284 CINIT(NOSIGNAL, CURLOPTTYPE_LONG, 99),
285 CINIT(SHARE, CURLOPTTYPE_OBJECTPOINT, 100),
286 CINIT(PROXYTYPE, CURLOPTTYPE_LONG, 101),
287 CINIT(ACCEPT_ENCODING, CURLOPTTYPE_OBJECTPOINT, 102),
288 CINIT(PRIVATE, CURLOPTTYPE_OBJECTPOINT, 103),
289 CINIT(HTTP200ALIASES, CURLOPTTYPE_OBJECTPOINT, 104),
290 CINIT(UNRESTRICTED_AUTH, CURLOPTTYPE_LONG, 105),
291 CINIT(FTP_USE_EPRT, CURLOPTTYPE_LONG, 106),
292 CINIT(HTTPAUTH, CURLOPTTYPE_LONG, 107),
293 CINIT(SSL_CTX_FUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 108),
294 CINIT(SSL_CTX_DATA, CURLOPTTYPE_OBJECTPOINT, 109),
295 CINIT(FTP_CREATE_MISSING_DIRS, CURLOPTTYPE_LONG, 110),
296 CINIT(PROXYAUTH, CURLOPTTYPE_LONG, 111),
297 CINIT(FTP_RESPONSE_TIMEOUT, CURLOPTTYPE_LONG, 112),
298 #define CURLOPT_SERVER_RESPONSE_TIMEOUT CURLOPT_FTP_RESPONSE_TIMEOUT
299 CINIT(IPRESOLVE, CURLOPTTYPE_LONG, 113),
300 CINIT(MAXFILESIZE, CURLOPTTYPE_LONG, 114),
301 CINIT(INFILESIZE_LARGE, CURLOPTTYPE_OFF_T, 115),
302 CINIT(RESUME_FROM_LARGE, CURLOPTTYPE_OFF_T, 116),
303 CINIT(MAXFILESIZE_LARGE, CURLOPTTYPE_OFF_T, 117),
304 CINIT(NETRC_FILE, CURLOPTTYPE_OBJECTPOINT, 118),
305 CINIT(USE_SSL, CURLOPTTYPE_LONG, 119),
306 CINIT(POSTFIELDSIZE_LARGE, CURLOPTTYPE_OFF_T, 120),
307 CINIT(TCP_NODELAY, CURLOPTTYPE_LONG, 121),
308 CINIT(FTPSSLAUTH, CURLOPTTYPE_LONG, 129),
309 CINIT(IOCTLFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 130),
310 CINIT(IOCTLDATA, CURLOPTTYPE_OBJECTPOINT, 131),
311 CINIT(FTP_ACCOUNT, CURLOPTTYPE_OBJECTPOINT, 134),
312 CINIT(COOKIELIST, CURLOPTTYPE_OBJECTPOINT, 135),
313 CINIT(IGNORE_CONTENT_LENGTH, CURLOPTTYPE_LONG, 136),
314 CINIT(FTP_SKIP_PASV_IP, CURLOPTTYPE_LONG, 137),
315 CINIT(FTP_FILEMETHOD, CURLOPTTYPE_LONG, 138),
316 CINIT(LOCALPORT, CURLOPTTYPE_LONG, 139),
317 CINIT(LOCALPORTRANGE, CURLOPTTYPE_LONG, 140),
318 CINIT(CONNECT_ONLY, CURLOPTTYPE_LONG, 141),
319 CINIT(CONV_FROM_NETWORK_FUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 142),
320 CINIT(CONV_TO_NETWORK_FUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 143),
321 CINIT(CONV_FROM_UTF8_FUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 144),
322 CINIT(MAX_SEND_SPEED_LARGE, CURLOPTTYPE_OFF_T, 145),
323 CINIT(MAX_RECV_SPEED_LARGE, CURLOPTTYPE_OFF_T, 146),
324 CINIT(FTP_ALTERNATIVE_TO_USER, CURLOPTTYPE_OBJECTPOINT, 147),
325 CINIT(SOCKOPTFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 148),
326 CINIT(SOCKOPTDATA, CURLOPTTYPE_OBJECTPOINT, 149),
327 CINIT(SSL_SESSIONID_CACHE, CURLOPTTYPE_LONG, 150),
328 CINIT(SSH_AUTH_TYPES, CURLOPTTYPE_LONG, 151),
329 CINIT(SSH_PUBLIC_KEYFILE, CURLOPTTYPE_OBJECTPOINT, 152),
330 CINIT(SSH_PRIVATE_KEYFILE, CURLOPTTYPE_OBJECTPOINT, 153),
331 CINIT(FTP_SSL_CCC, CURLOPTTYPE_LONG, 154),
332 CINIT(TIMEOUT_MS, CURLOPTTYPE_LONG, 155),
333 CINIT(CONNECTTIMEOUT_MS, CURLOPTTYPE_LONG, 156),
334 CINIT(HTTP_TRANSFER_DECODING, CURLOPTTYPE_LONG, 157),
335 CINIT(HTTP_CONTENT_DECODING, CURLOPTTYPE_LONG, 158),
336 CINIT(NEW_FILE_PERMS, CURLOPTTYPE_LONG, 159),
337 CINIT(NEW_DIRECTORY_PERMS, CURLOPTTYPE_LONG, 160),
338 CINIT(POSTREDIR, CURLOPTTYPE_LONG, 161),
339 CINIT(SSH_HOST_PUBLIC_KEY_MD5, CURLOPTTYPE_OBJECTPOINT, 162),
340 CINIT(OPENSOCKETFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 163),
341 CINIT(OPENSOCKETDATA, CURLOPTTYPE_OBJECTPOINT, 164),
342 CINIT(COPYPOSTFIELDS, CURLOPTTYPE_OBJECTPOINT, 165),
343 CINIT(PROXY_TRANSFER_MODE, CURLOPTTYPE_LONG, 166),
344 CINIT(SEEKFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 167),
345 CINIT(SEEKDATA, CURLOPTTYPE_OBJECTPOINT, 168),
346 CINIT(CRLFILE, CURLOPTTYPE_OBJECTPOINT, 169),
347 CINIT(ISSUERCERT, CURLOPTTYPE_OBJECTPOINT, 170),
348 CINIT(ADDRESS_SCOPE, CURLOPTTYPE_LONG, 171),
349 CINIT(CERTINFO, CURLOPTTYPE_LONG, 172),
350 CINIT(USERNAME, CURLOPTTYPE_OBJECTPOINT, 173),
351 CINIT(PASSWORD, CURLOPTTYPE_OBJECTPOINT, 174),
352 CINIT(PROXYUSERNAME, CURLOPTTYPE_OBJECTPOINT, 175),
353 CINIT(PROXYPASSWORD, CURLOPTTYPE_OBJECTPOINT, 176),
354 CINIT(NOPROXY, CURLOPTTYPE_OBJECTPOINT, 177),
355 CINIT(TFTP_BLKSIZE, CURLOPTTYPE_LONG, 178),
356 CINIT(SOCKS5_GSSAPI_SERVICE, CURLOPTTYPE_OBJECTPOINT, 179),
357 CINIT(SOCKS5_GSSAPI_NEC, CURLOPTTYPE_LONG, 180),
358 CINIT(PROTOCOLS, CURLOPTTYPE_LONG, 181),
359 CINIT(REDIR_PROTOCOLS, CURLOPTTYPE_LONG, 182),
360 CINIT(SSH_KNOWNHOSTS, CURLOPTTYPE_OBJECTPOINT, 183),
361 CINIT(SSH_KEYFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 184),
362 CINIT(SSH_KEYDATA, CURLOPTTYPE_OBJECTPOINT, 185),
363 CINIT(MAIL_FROM, CURLOPTTYPE_OBJECTPOINT, 186),
364 CINIT(MAIL_RCPT, CURLOPTTYPE_OBJECTPOINT, 187),
365 CINIT(FTP_USE_PRET, CURLOPTTYPE_LONG, 188),
366 CINIT(RTSP_REQUEST, CURLOPTTYPE_LONG, 189),
367 CINIT(RTSP_SESSION_ID, CURLOPTTYPE_OBJECTPOINT, 190),
368 CINIT(RTSP_STREAM_URI, CURLOPTTYPE_OBJECTPOINT, 191),
369 CINIT(RTSP_TRANSPORT, CURLOPTTYPE_OBJECTPOINT, 192),
370 CINIT(RTSP_CLIENT_CSEQ, CURLOPTTYPE_LONG, 193),
371 CINIT(RTSP_SERVER_CSEQ, CURLOPTTYPE_LONG, 194),
372 CINIT(INTERLEAVEDATA, CURLOPTTYPE_OBJECTPOINT, 195),
373 CINIT(INTERLEAVEFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 196),
374 CINIT(WILDCARDMATCH, CURLOPTTYPE_LONG, 197),
375 CINIT(CHUNK_BGN_FUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 198),
376 CINIT(CHUNK_END_FUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 199),
377 CINIT(FNMATCH_FUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 200),
378 CINIT(CHUNK_DATA, CURLOPTTYPE_OBJECTPOINT, 201),
379 CINIT(FNMATCH_DATA, CURLOPTTYPE_OBJECTPOINT, 202),
380 CINIT(RESOLVE, CURLOPTTYPE_OBJECTPOINT, 203),
381 CINIT(TLSAUTH_USERNAME, CURLOPTTYPE_OBJECTPOINT, 204),
382 CINIT(TLSAUTH_PASSWORD, CURLOPTTYPE_OBJECTPOINT, 205),
383 CINIT(TLSAUTH_TYPE, CURLOPTTYPE_OBJECTPOINT, 206),
384 CINIT(TRANSFER_ENCODING, CURLOPTTYPE_LONG, 207),
385 CINIT(CLOSESOCKETFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 208),
386 CINIT(CLOSESOCKETDATA, CURLOPTTYPE_OBJECTPOINT, 209),
387 CINIT(GSSAPI_DELEGATION, CURLOPTTYPE_LONG, 210),
388 CINIT(DNS_SERVERS, CURLOPTTYPE_OBJECTPOINT, 211),
389 CINIT(ACCEPTTIMEOUT_MS, CURLOPTTYPE_LONG, 212),
390 CINIT(TCP_KEEPALIVE, CURLOPTTYPE_LONG, 213),
391 CINIT(TCP_KEEPIDLE, CURLOPTTYPE_LONG, 214),
392 CINIT(TCP_KEEPINTVL, CURLOPTTYPE_LONG, 215),
393 CINIT(SSL_OPTIONS, CURLOPTTYPE_LONG, 216),
394 CINIT(MAIL_AUTH, CURLOPTTYPE_OBJECTPOINT, 217),
395
396 CURLOPT_LASTENTRY
397 } CURLoption;
398
399 #define CURLOPT_WRITEDATA CURLOPT_FILE
400 #define CURLOPT_READDATA CURLOPT_INFILE
401
402 #define CURLINFO_STRING 0x100000
403 #define CURLINFO_LONG 0x200000
404 #define CURLINFO_DOUBLE 0x300000
405 #define CURLINFO_SLIST 0x400000
406 #define CURLINFO_MASK 0x0fffff
407 #define CURLINFO_TYPEMASK 0xf00000
408
409 typedef enum
410 {
411 CURLINFO_NONE,
412 CURLINFO_EFFECTIVE_URL = CURLINFO_STRING + 1,
413 CURLINFO_RESPONSE_CODE = CURLINFO_LONG + 2,
414 CURLINFO_TOTAL_TIME = CURLINFO_DOUBLE + 3,
415 CURLINFO_NAMELOOKUP_TIME = CURLINFO_DOUBLE + 4,
416 CURLINFO_CONNECT_TIME = CURLINFO_DOUBLE + 5,
417 CURLINFO_PRETRANSFER_TIME = CURLINFO_DOUBLE + 6,
418 CURLINFO_SIZE_UPLOAD = CURLINFO_DOUBLE + 7,
419 CURLINFO_SIZE_DOWNLOAD = CURLINFO_DOUBLE + 8,
420 CURLINFO_SPEED_DOWNLOAD = CURLINFO_DOUBLE + 9,
421 CURLINFO_SPEED_UPLOAD = CURLINFO_DOUBLE + 10,
422 CURLINFO_HEADER_SIZE = CURLINFO_LONG + 11,
423 CURLINFO_REQUEST_SIZE = CURLINFO_LONG + 12,
424 CURLINFO_SSL_VERIFYRESULT = CURLINFO_LONG + 13,
425 CURLINFO_FILETIME = CURLINFO_LONG + 14,
426 CURLINFO_CONTENT_LENGTH_DOWNLOAD = CURLINFO_DOUBLE + 15,
427 CURLINFO_CONTENT_LENGTH_UPLOAD = CURLINFO_DOUBLE + 16,
428 CURLINFO_STARTTRANSFER_TIME = CURLINFO_DOUBLE + 17,
429 CURLINFO_CONTENT_TYPE = CURLINFO_STRING + 18,
430 CURLINFO_REDIRECT_TIME = CURLINFO_DOUBLE + 19,
431 CURLINFO_REDIRECT_COUNT = CURLINFO_LONG + 20,
432 CURLINFO_PRIVATE = CURLINFO_STRING + 21,
433 CURLINFO_HTTP_CONNECTCODE = CURLINFO_LONG + 22,
434 CURLINFO_HTTPAUTH_AVAIL = CURLINFO_LONG + 23,
435 CURLINFO_PROXYAUTH_AVAIL = CURLINFO_LONG + 24,
436 CURLINFO_OS_ERRNO = CURLINFO_LONG + 25,
437 CURLINFO_NUM_CONNECTS = CURLINFO_LONG + 26,
438 CURLINFO_SSL_ENGINES = CURLINFO_SLIST + 27,
439 CURLINFO_COOKIELIST = CURLINFO_SLIST + 28,
440 CURLINFO_LASTSOCKET = CURLINFO_LONG + 29,
441 CURLINFO_FTP_ENTRY_PATH = CURLINFO_STRING + 30,
442 CURLINFO_REDIRECT_URL = CURLINFO_STRING + 31,
443 CURLINFO_PRIMARY_IP = CURLINFO_STRING + 32,
444 CURLINFO_APPCONNECT_TIME = CURLINFO_DOUBLE + 33,
445 CURLINFO_CERTINFO = CURLINFO_SLIST + 34,
446 CURLINFO_CONDITION_UNMET = CURLINFO_LONG + 35,
447 CURLINFO_RTSP_SESSION_ID = CURLINFO_STRING + 36,
448 CURLINFO_RTSP_CLIENT_CSEQ = CURLINFO_LONG + 37,
449 CURLINFO_RTSP_SERVER_CSEQ = CURLINFO_LONG + 38,
450 CURLINFO_RTSP_CSEQ_RECV = CURLINFO_LONG + 39,
451 CURLINFO_PRIMARY_PORT = CURLINFO_LONG + 40,
452 CURLINFO_LOCAL_IP = CURLINFO_STRING + 41,
453 CURLINFO_LOCAL_PORT = CURLINFO_LONG + 42,
454
455 CURLINFO_LASTONE = 42
456 } CURLINFO;
457
458 typedef void CURL;
459
460 struct curl_slist
461 {
462 char* data;
463 struct curl_slist* next;
464 };
465
466 struct curl_httppost {
467 struct curl_httppost* next;
468 char* name;
469 long namelength;
470 char* contents;
471 long contentslength;
472 char* buffer;
473 long bufferlength;
474 char* contenttype;
475 struct curl_slist* contentheader;
476 struct curl_httppost* more;
477 long flags;
478 #define HTTPPOST_FILENAME (1<<0)
479 #define HTTPPOST_READFILE (1<<1)
480 #define HTTPPOST_PTRNAME (1<<2)
481 #define HTTPPOST_PTRCONTENTS (1<<3)
482 #define HTTPPOST_BUFFER (1<<4)
483 #define HTTPPOST_PTRBUFFER (1<<5)
484 #define HTTPPOST_CALLBACK (1<<6)
485
486 char* showfilename;
487 void* userp;
488 };
489
490
491 typedef enum {
492 CURL_FORMADD_OK,
493
494 CURL_FORMADD_MEMORY,
495 CURL_FORMADD_OPTION_TWICE,
496 CURL_FORMADD_NULL,
497 CURL_FORMADD_UNKNOWN_OPTION,
498 CURL_FORMADD_INCOMPLETE,
499 CURL_FORMADD_ILLEGAL_ARRAY,
500 CURL_FORMADD_DISABLED,
501
502 CURL_FORMADD_LAST
503 } CURLFORMcode;
504
505
506 #include "gate/gatetypes.h"
507 #include "gate/libraries.h"
508 #include "gate/results.h"
509 #include "gate/debugging.h"
510 #include "gate/streams.h"
511 #include "gate/platforms.h"
512
513
514 typedef struct gate_curl_functions_class
515 {
516 CURLcode(*easy_setopt) (CURL* handle, CURLoption option, ...);
517 void (*easy_cleanup) (CURL* handle);
518 CURLcode(*global_init) (long flags);
519 void (*global_cleanup) (void);
520 CURL* (*easy_init) (void);
521 CURLcode(*easy_perform) (CURL* handle);
522 CURLcode(*easy_getinfo) (CURL* handle, CURLINFO info, ...);
523 struct curl_slist* (*slist_append) (struct curl_slist* list, const char* str);
524 void (*slist_free_all) (struct curl_slist* list);
525 CURLFORMcode(*formadd) (struct curl_httppost** firstitem, struct curl_httppost** lastitem, ...);
526 void (*formfree) (struct curl_httppost* form);
527 } gate_curl_functions_t;
528
529 static gate_curl_functions_t curl;
530
531
532 static gate_library_t libcurl_library = NULL;
533 static gate_bool_t volatile libcurl_library_loaded = false;
534
535
536 2 static void libcurl_atexit_cleanup()
537 {
538
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (libcurl_library != NULL)
539 {
540 2 gate_library_close(libcurl_library);
541 2 libcurl_library = NULL;
542 }
543 2 }
544
545 9 static gate_result_t load_libcurl_functions()
546 {
547 #if defined(GATE_SYS_WIN)
548 static gate_string_t const lib_curl_file = GATE_STRING_INIT_STATIC("libcurl.dll");
549 static gate_string_t const lib_curl_file2 = GATE_STRING_INIT_STATIC("libcurl-4.dll");
550 #elif defined(GATE_SYS_DARWIN)
551 static gate_string_t const lib_curl_file = GATE_STRING_INIT_STATIC("libcurl.dylib");
552 static gate_string_t const lib_curl_file2 = GATE_STRING_INIT_STATIC("libcurl.dylib");
553 #else
554 static gate_string_t const lib_curl_file = GATE_STRING_INIT_STATIC("libcurl.so");
555 static gate_string_t const lib_curl_file2 = GATE_STRING_INIT_STATIC("libcurl.so.4");
556 #endif
557
558 9 gate_result_t ret = GATE_RESULT_NOTSUPPORTED;
559
560
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 7 times.
9 if (!libcurl_library_loaded)
561 {
562 do
563 {
564
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (libcurl_library == NULL)
565 {
566 2 ret = gate_library_open(&lib_curl_file, &libcurl_library, GATE_LIBRARY_FLAG_DEFAULT);
567
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (GATE_FAILED(ret))
568 {
569 2 ret = gate_library_open(&lib_curl_file2, &libcurl_library, GATE_LIBRARY_FLAG_DEFAULT);
570
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (GATE_FAILED(ret))
571 {
572 libcurl_library = NULL;
573 break;
574 }
575 }
576 2 gate_platform_atexit(&libcurl_atexit_cleanup);
577 }
578
579
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_data_name(libcurl_library, "curl_easy_setopt", &curl.easy_setopt));
580
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_data_name(libcurl_library, "curl_easy_cleanup", &curl.easy_cleanup));
581
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_data_name(libcurl_library, "curl_global_init", &curl.global_init));
582
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_data_name(libcurl_library, "curl_global_cleanup", &curl.global_cleanup));
583
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_data_name(libcurl_library, "curl_easy_init", &curl.easy_init));
584
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_data_name(libcurl_library, "curl_easy_perform", &curl.easy_perform));
585
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_data_name(libcurl_library, "curl_easy_getinfo", &curl.easy_getinfo));
586
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_data_name(libcurl_library, "curl_slist_append", &curl.slist_append));
587
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_data_name(libcurl_library, "curl_slist_free_all", &curl.slist_free_all));
588
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_data_name(libcurl_library, "curl_formadd", &curl.formadd));
589
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 GATE_BREAK_IF_FAILED(ret = gate_library_get_data_name(libcurl_library, "curl_formfree", &curl.formfree));
590
591 2 libcurl_library_loaded = true;
592 } while (0);
593 }
594
595
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if (libcurl_library_loaded)
596 {
597 9 ret = GATE_RESULT_OK;
598 }
599 9 return ret;
600 }
601
602 35 static gate_result_t gate_curl_map_result(CURLcode code, char const** ptr_msg)
603 {
604 35 gate_result_t ret = GATE_RESULT_FAILED;
605 35 char const* msg = NULL;
606
607
1/80
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✗ Branch 48 not taken.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 53 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 56 not taken.
✗ Branch 57 not taken.
✗ Branch 58 not taken.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
✗ Branch 61 not taken.
✗ Branch 62 not taken.
✗ Branch 63 not taken.
✗ Branch 64 not taken.
✗ Branch 65 not taken.
✗ Branch 66 not taken.
✗ Branch 67 not taken.
✗ Branch 68 not taken.
✗ Branch 69 not taken.
✗ Branch 70 not taken.
✗ Branch 71 not taken.
✗ Branch 72 not taken.
✗ Branch 73 not taken.
✗ Branch 74 not taken.
✗ Branch 75 not taken.
✗ Branch 76 not taken.
✗ Branch 77 not taken.
✗ Branch 78 not taken.
✗ Branch 79 not taken.
35 switch (code)
608 {
609 35 case CURLE_OK: ret = GATE_RESULT_OK; break;
610 case CURLE_UNSUPPORTED_PROTOCOL: ret = GATE_RESULT_NOTSUPPORTED; msg = "Unsupported Protocol"; break;
611 case CURLE_FAILED_INIT: ret = GATE_RESULT_FAILED; msg = "Initialization failed"; break;
612 case CURLE_URL_MALFORMAT: ret = GATE_RESULT_FAILED; msg = "Invalid URL"; break;
613 case CURLE_NOT_BUILT_IN: ret = GATE_RESULT_NOTSUPPORTED; msg = "Feature not built in"; break;
614 case CURLE_COULDNT_RESOLVE_PROXY: ret = GATE_RESULT_NOTAVAILABLE; msg = "Failed to resolve proxy"; break;
615 case CURLE_COULDNT_RESOLVE_HOST: ret = GATE_RESULT_NOTAVAILABLE; msg = "Failed to resolve host"; break;
616 case CURLE_COULDNT_CONNECT: ret = GATE_RESULT_NOTAVAILABLE; msg = "Connect failed"; break;
617 case CURLE_FTP_WEIRD_SERVER_REPLY: ret = GATE_RESULT_FAILED; msg = "Invalid FTP server reply"; break;
618 case CURLE_REMOTE_ACCESS_DENIED: ret = GATE_RESULT_ACCESSDENIED; msg = "Remote access denied"; break;
619 case CURLE_FTP_ACCEPT_FAILED: ret = GATE_RESULT_FAILED; msg = "FTP accept failed"; break;
620 case CURLE_FTP_WEIRD_PASS_REPLY: ret = GATE_RESULT_FAILED; msg = "Invalid FTP PASS reply"; break;
621 case CURLE_FTP_ACCEPT_TIMEOUT: ret = GATE_RESULT_TIMEOUT; msg = "FTP accept timeout"; break;
622 case CURLE_FTP_WEIRD_PASV_REPLY: ret = GATE_RESULT_FAILED; msg = "Invalid FTP PASV reply"; break;
623 case CURLE_FTP_WEIRD_227_FORMAT: ret = GATE_RESULT_FAILED; msg = "Invalid FTP 227 format"; break;
624 case CURLE_FTP_CANT_GET_HOST: ret = GATE_RESULT_FAILED; msg = "Cant get FTP host"; break;
625 #ifdef CURLE_HTTP2
626 case CURLE_HTTP2: ret = GATE_RESULT_FAILED; msg = "HTTP2"; break;
627 #endif
628 case CURLE_FTP_COULDNT_SET_TYPE: ret = GATE_RESULT_FAILED; msg = "Failed to set FTP type"; break;
629 case CURLE_PARTIAL_FILE: ret = GATE_RESULT_FAILED; msg = "Partial file"; break;
630 case CURLE_FTP_COULDNT_RETR_FILE: ret = GATE_RESULT_FAILED; msg = "Failed to retrieve FTP file"; break;
631 case CURLE_QUOTE_ERROR: ret = GATE_RESULT_FAILED; msg = "QUOTE error"; break;
632 case CURLE_HTTP_RETURNED_ERROR: ret = GATE_RESULT_FAILED; msg = "HTTP error"; break;
633 case CURLE_WRITE_ERROR: ret = GATE_RESULT_FAILED; msg = "Write failed"; break;
634 case CURLE_UPLOAD_FAILED: ret = GATE_RESULT_FAILED; msg = "Upload failed"; break;
635 case CURLE_READ_ERROR: ret = GATE_RESULT_FAILED; msg = "Read failed"; break;
636 case CURLE_OUT_OF_MEMORY: ret = GATE_RESULT_OUTOFMEMORY; msg = "Out of memory"; break;
637 case CURLE_OPERATION_TIMEDOUT: ret = GATE_RESULT_TIMEOUT; msg = "Operation timeout"; break;
638 case CURLE_FTP_PORT_FAILED: ret = GATE_RESULT_FAILED; msg = "FTP PORT command failed"; break;
639 case CURLE_FTP_COULDNT_USE_REST: ret = GATE_RESULT_FAILED; msg = "FTP REST command failed"; break;
640 case CURLE_RANGE_ERROR: ret = GATE_RESULT_FAILED; msg = "Range request failed"; break;
641 case CURLE_HTTP_POST_ERROR: ret = GATE_RESULT_FAILED; msg = "HTTP POST failed"; break;
642 case CURLE_SSL_CONNECT_ERROR: ret = GATE_RESULT_FAILED; msg = "SSL connect error"; break;
643 case CURLE_BAD_DOWNLOAD_RESUME: ret = GATE_RESULT_FAILED; msg = "Failed to resume download"; break;
644 case CURLE_FILE_COULDNT_READ_FILE: ret = GATE_RESULT_FAILED; msg = "Failed to read file"; break;
645 case CURLE_LDAP_CANNOT_BIND: ret = GATE_RESULT_FAILED; msg = "Cannot bind LDAP"; break;
646 case CURLE_LDAP_SEARCH_FAILED: ret = GATE_RESULT_FAILED; msg = "LDAP search failed"; break;
647 case CURLE_FUNCTION_NOT_FOUND: ret = GATE_RESULT_NOTAVAILABLE; msg = "Function not found"; break;
648 case CURLE_ABORTED_BY_CALLBACK: ret = GATE_RESULT_CANCELED; msg = "Canceled by callback"; break;
649 case CURLE_BAD_FUNCTION_ARGUMENT: ret = GATE_RESULT_INVALIDARG; msg = "Bad function argument"; break;
650 case CURLE_INTERFACE_FAILED: ret = GATE_RESULT_FAILED; msg = "Interface failed"; break;
651 case CURLE_TOO_MANY_REDIRECTS: ret = GATE_RESULT_FAILED; msg = "Too many redirects"; break;
652 case CURLE_UNKNOWN_OPTION: ret = GATE_RESULT_FAILED; msg = "Unknown option"; break;
653 case CURLE_TELNET_OPTION_SYNTAX: ret = GATE_RESULT_FAILED; msg = "Telnet option illegally formated"; break;
654 case CURLE_PEER_FAILED_VERIFICATION: ret = GATE_RESULT_FAILED; msg = "Peer verification failed"; break;
655 case CURLE_GOT_NOTHING: ret = GATE_RESULT_INVALIDDATA; msg = "No data returned"; break;
656 case CURLE_SSL_ENGINE_NOTFOUND: ret = GATE_RESULT_NOTAVAILABLE; msg = "SSL engine not found"; break;
657 case CURLE_SSL_ENGINE_SETFAILED: ret = GATE_RESULT_NOTAVAILABLE; msg = "SSL engine error"; break;
658 case CURLE_SEND_ERROR: ret = GATE_RESULT_FAILED; msg = "Send error"; break;
659 case CURLE_RECV_ERROR: ret = GATE_RESULT_FAILED; msg = "Receive error"; break;
660 case CURLE_SSL_CERTPROBLEM: ret = GATE_RESULT_FAILED; msg = "SSL Certificate problem"; break;
661 case CURLE_SSL_CIPHER: ret = GATE_RESULT_FAILED; msg = "SSL cipher error"; break;
662 case CURLE_SSL_CACERT: ret = GATE_RESULT_FAILED; msg = "SSL certificate authentication failed"; break;
663 case CURLE_BAD_CONTENT_ENCODING: ret = GATE_RESULT_INVALIDDATA; msg = "Bad content encoding"; break;
664 case CURLE_LDAP_INVALID_URL: ret = GATE_RESULT_FAILED; msg = "LDAP invalid URL"; break;
665 case CURLE_FILESIZE_EXCEEDED: ret = GATE_RESULT_INCORRECTSIZE;msg = "Filesize exceeded"; break;
666 case CURLE_USE_SSL_FAILED: ret = GATE_RESULT_FAILED; msg = "Requested SSL level failed"; break;
667 case CURLE_SEND_FAIL_REWIND: ret = GATE_RESULT_FAILED; msg = "Send-Rewind failed"; break;
668 case CURLE_SSL_ENGINE_INITFAILED: ret = GATE_RESULT_FAILED; msg = "SSL initialization failed"; break;
669 case CURLE_LOGIN_DENIED: ret = GATE_RESULT_ACCESSDENIED; msg = "Login denied"; break;
670 case CURLE_TFTP_NOTFOUND: ret = GATE_RESULT_NOTAVAILABLE; msg = "TFTP not found"; break;
671 case CURLE_TFTP_PERM: ret = GATE_RESULT_ACCESSDENIED; msg = "TFTP permission failed"; break;
672 case CURLE_REMOTE_DISK_FULL: ret = GATE_RESULT_FAILED; msg = "Remote disk full"; break;
673 case CURLE_TFTP_ILLEGAL: ret = GATE_RESULT_FAILED; msg = "Illegal TFTP operation"; break;
674 case CURLE_TFTP_UNKNOWNID: ret = GATE_RESULT_FAILED; msg = "Unknown TFTP transfer ID"; break;
675 case CURLE_REMOTE_FILE_EXISTS: ret = GATE_RESULT_ALREADYEXISTS;msg = "Remote file exists"; break;
676 case CURLE_TFTP_NOSUCHUSER: ret = GATE_RESULT_FAILED; msg = "TFTP: No such user"; break;
677 case CURLE_CONV_FAILED: ret = GATE_RESULT_INVALIDDATA; msg = "Character conversion failed"; break;
678 case CURLE_CONV_REQD: ret = GATE_RESULT_FAILED; msg = "Conversion callback missing"; break;
679 case CURLE_SSL_CACERT_BADFILE: ret = GATE_RESULT_FAILED; msg = "SSL CA cert file problem"; break;
680 case CURLE_REMOTE_FILE_NOT_FOUND: ret = GATE_RESULT_FAILED; msg = "Remote file not found"; break;
681 case CURLE_SSH: ret = GATE_RESULT_FAILED; msg = "SSH error"; break;
682 case CURLE_SSL_SHUTDOWN_FAILED: ret = GATE_RESULT_FAILED; msg = "SSL shutdown failed"; break;
683 case CURLE_AGAIN: ret = GATE_RESULT_NOTREADY; msg = "Socket not ready for send/recv"; break;
684 case CURLE_SSL_CRL_BADFILE: ret = GATE_RESULT_FAILED; msg = "Failed to load SSL CRL file"; break;
685 case CURLE_SSL_ISSUER_ERROR: ret = GATE_RESULT_FAILED; msg = "SSL issuer check failed"; break;
686 case CURLE_FTP_PRET_FAILED: ret = GATE_RESULT_FAILED; msg = "FTP PRET command failed"; break;
687 case CURLE_RTSP_CSEQ_ERROR: ret = GATE_RESULT_FAILED; msg = "Mismatch of RTSP CSeq numbers"; break;
688 case CURLE_RTSP_SESSION_ERROR: ret = GATE_RESULT_FAILED; msg = "Mismatch of RTSP session identifiers"; break;
689 case CURLE_FTP_BAD_FILE_LIST: ret = GATE_RESULT_FAILED; msg = "Unable to parse FTP file list"; break;
690 case CURLE_CHUNK_FAILED: ret = GATE_RESULT_FAILED; msg = "Chunk callback error"; break;
691 #ifdef CURLE_NO_CONNECTION_AVAILABLE
692 case CURLE_NO_CONNECTION_AVAILABLE: ret = GATE_RESULT_FAILED; msg = "No connection available"; break;
693 #endif
694 #ifdef CURLE_SSL_PINNEDPUBKEYNOTMATCH
695 case CURLE_SSL_PINNEDPUBKEYNOTMATCH: ret = GATE_RESULT_FAILED; msg = "Failed to match pinned key"; break;
696 #endif
697 #ifdef CURLE_SSL_INVALIDCERTSTATUS
698 case CURLE_SSL_INVALIDCERTSTATUS: ret = GATE_RESULT_FAILED; msg = "Invalid SSL cert status"; break;
699 #endif
700 #ifdef CURLE_HTTP2_STREAM
701 case CURLE_HTTP2_STREAM: ret = GATE_RESULT_FAILED; msg = "HTTP2 stream error"; break;
702 #endif
703 default: ret = GATE_RESULT_UNKNOWNERROR; msg = "Unknown error"; break;
704 }
705
706
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 if (ptr_msg)
707 {
708 35 *ptr_msg = msg;
709 }
710 35 return ret;
711 }
712
713
714 static size_t gate_curl_read_stream_cb(void* ptr, size_t size, size_t nmemb, void* data)
715 {
716 gate_stream_t* stream = (gate_stream_t*)data;
717 size_t len = size * nmemb;
718 gate_size_t lenread = 0;
719 gate_result_t result;
720
721 if (!stream || (len == 0))
722 {
723 return 0;
724 }
725
726 result = gate_stream_read_block(stream, (char*)ptr, len, &lenread);
727 if (GATE_SUCCEEDED(result))
728 {
729 /* success case */
730 GATE_DEBUG_ASSERT((lenread % size) == 0);
731 return lenread / size;
732 }
733 else
734 {
735 /* error case */
736 return 0;
737 }
738 }
739
740 static size_t gate_curl_noread_cb(void* ptr, size_t size, size_t nmemb, void* data)
741 {
742 return 0;
743 }
744
745
746 84 static size_t gate_curl_write_stream_cb(void* ptr, size_t size, size_t nmemb, void* data)
747 {
748 84 gate_stream_t* const stream = (gate_stream_t*)data;
749 84 size_t const len = size * nmemb;
750 84 char* const str = (char*)ptr;
751 84 gate_size_t written = 0;
752 gate_result_t result;
753
754
3/6
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 84 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 84 times.
84 if (len == 0 || !stream || !ptr)
755 {
756 /* invalid arg error */
757 return 0;
758 }
759
760 84 result = gate_stream_write_block(stream, str, len, &written);
761
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 84 times.
84 if (GATE_FAILED(result))
762 {
763 /* write failed */
764 return 0;
765 }
766 else
767 {
768 /* write succeeded */
769 84 GATE_DEBUG_ASSERT(written == len);
770 84 GATE_DEBUG_ASSERT((written % size) == 0);
771 84 return written / size;
772 }
773
774 }
775
776 1 static size_t gate_curl_nowrite_cb(void* ptr, size_t size, size_t nmemb, void* data)
777 {
778 1 return nmemb;
779 }
780
781
782 #ifndef CURL_BREAK_IF_FAILED
783 #define CURL_BREAK_IF_FAILED(curl_result) if(CURLE_OK != (curl_result)) { break; }
784 #endif
785
786 3 static gate_result_t gate_curl_setup(CURL* ptr_curl, gate_string_t const* url, gate_stream_t* input_stream, gate_stream_t* output_stream)
787 {
788 3 gate_result_t ret = GATE_RESULT_FAILED;
789 3 CURLcode curlresult = CURLE_OK;
790
791 do
792 {
793 3 curl.easy_setopt(ptr_curl, CURLOPT_NOSIGNAL, 1L);
794
795
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 if (!gate_string_is_empty(url))
796 {
797
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
3 CURL_BREAK_IF_FAILED(curl.easy_setopt(ptr_curl, CURLOPT_URL, gate_string_ptr(url, 0)));
798 }
799
800
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
3 CURL_BREAK_IF_FAILED(curl.easy_setopt(ptr_curl, CURLOPT_READDATA, (void*)input_stream));
801
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
3 CURL_BREAK_IF_FAILED(curl.easy_setopt(ptr_curl, CURLOPT_READFUNCTION,
802 (input_stream != NULL) ? &gate_curl_read_stream_cb : &gate_curl_noread_cb));
803
804
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
3 CURL_BREAK_IF_FAILED(curl.easy_setopt(ptr_curl, CURLOPT_WRITEDATA, (void*)output_stream));
805
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
3 CURL_BREAK_IF_FAILED(curl.easy_setopt(ptr_curl, CURLOPT_WRITEFUNCTION,
806 (output_stream != NULL) ? &gate_curl_write_stream_cb : &gate_curl_nowrite_cb));
807
808 3 ret = GATE_RESULT_OK;
809 } while (0);
810
811 3 return ret;
812 }
813
814 3 static gate_result_t gate_curl_reset(CURL* ptr_curl)
815 {
816 3 gate_result_t ret = GATE_RESULT_FAILED;
817 3 CURLcode curlresult = CURLE_OK;
818
819 do
820 {
821 /* ensure we don't have pointers and functions that are not valid anymore */
822 3 curl.easy_setopt(ptr_curl, CURLOPT_READDATA, NULL);
823 3 curl.easy_setopt(ptr_curl, CURLOPT_READFUNCTION, &gate_curl_noread_cb);
824
825 3 curl.easy_setopt(ptr_curl, CURLOPT_WRITEDATA, NULL);
826 3 curl.easy_setopt(ptr_curl, CURLOPT_WRITEFUNCTION, &gate_curl_nowrite_cb);
827
828 3 ret = GATE_RESULT_OK;
829 } while (0);
830
831 3 return ret;
832 }
833
834 #endif
835