gus-curb 0.8.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +51 -0
  3. data/README.markdown +230 -0
  4. data/Rakefile +320 -0
  5. data/doc.rb +42 -0
  6. data/ext/curb.c +997 -0
  7. data/ext/curb.h +48 -0
  8. data/ext/curb_easy.c +3466 -0
  9. data/ext/curb_easy.h +90 -0
  10. data/ext/curb_errors.c +660 -0
  11. data/ext/curb_errors.h +132 -0
  12. data/ext/curb_macros.h +159 -0
  13. data/ext/curb_multi.c +641 -0
  14. data/ext/curb_multi.h +26 -0
  15. data/ext/curb_postfield.c +523 -0
  16. data/ext/curb_postfield.h +40 -0
  17. data/ext/curb_upload.c +80 -0
  18. data/ext/curb_upload.h +30 -0
  19. data/ext/extconf.rb +392 -0
  20. data/lib/curb.rb +1 -0
  21. data/lib/curl.rb +64 -0
  22. data/lib/curl/easy.rb +480 -0
  23. data/lib/curl/multi.rb +248 -0
  24. data/tests/alltests.rb +3 -0
  25. data/tests/bug_crash_on_debug.rb +39 -0
  26. data/tests/bug_crash_on_progress.rb +73 -0
  27. data/tests/bug_curb_easy_blocks_ruby_threads.rb +52 -0
  28. data/tests/bug_curb_easy_post_with_string_no_content_length_header.rb +83 -0
  29. data/tests/bug_instance_post_differs_from_class_post.rb +53 -0
  30. data/tests/bug_issue102.rb +17 -0
  31. data/tests/bug_multi_segfault.rb +14 -0
  32. data/tests/bug_postfields_crash.rb +26 -0
  33. data/tests/bug_postfields_crash2.rb +57 -0
  34. data/tests/bug_require_last_or_segfault.rb +40 -0
  35. data/tests/bugtests.rb +9 -0
  36. data/tests/helper.rb +204 -0
  37. data/tests/mem_check.rb +65 -0
  38. data/tests/require_last_or_segfault_script.rb +36 -0
  39. data/tests/signals.rb +33 -0
  40. data/tests/tc_curl.rb +39 -0
  41. data/tests/tc_curl_download.rb +75 -0
  42. data/tests/tc_curl_easy.rb +1038 -0
  43. data/tests/tc_curl_easy_setopt.rb +31 -0
  44. data/tests/tc_curl_multi.rb +485 -0
  45. data/tests/tc_curl_postfield.rb +143 -0
  46. data/tests/timeout.rb +100 -0
  47. data/tests/timeout_server.rb +33 -0
  48. data/tests/unittests.rb +2 -0
  49. metadata +123 -0
@@ -0,0 +1,90 @@
1
+ /* curb_easy.h - Curl easy mode
2
+ * Copyright (c)2006 Ross Bamford.
3
+ * Licensed under the Ruby License. See LICENSE for details.
4
+ *
5
+ * $Id: curb_easy.h 25 2006-12-07 23:38:25Z roscopeco $
6
+ */
7
+ #ifndef __CURB_EASY_H
8
+ #define __CURB_EASY_H
9
+
10
+ #include "curb.h"
11
+
12
+ #include <curl/easy.h>
13
+
14
+ #ifdef CURL_VERSION_SSL
15
+ #if LIBCURL_VERSION_NUM >= 0x070b00
16
+ # if LIBCURL_VERSION_NUM <= 0x071004
17
+ # define CURB_FTPSSL CURLOPT_FTP_SSL
18
+ # define CURB_FTPSSL_ALL CURLFTPSSL_ALL
19
+ # define CURB_FTPSSL_TRY CURLFTPSSL_TRY
20
+ # define CURB_FTPSSL_CONTROL CURLFTPSSL_CONTROL
21
+ # define CURB_FTPSSL_NONE CURLFTPSSL_NONE
22
+ # else
23
+ # define CURB_FTPSSL CURLOPT_USE_SSL
24
+ # define CURB_FTPSSL_ALL CURLUSESSL_ALL
25
+ # define CURB_FTPSSL_TRY CURLUSESSL_TRY
26
+ # define CURB_FTPSSL_CONTROL CURLUSESSL_CONTROL
27
+ # define CURB_FTPSSL_NONE CURLUSESSL_NONE
28
+ # endif
29
+ #endif
30
+ #endif
31
+
32
+ /* a lot of this *could* be kept in the handler itself,
33
+ * but then we lose the ability to query it's status.
34
+ */
35
+ typedef struct {
36
+ /* The handler */
37
+ CURL *curl;
38
+
39
+ VALUE opts; /* rather then allocate everything we might need to store, allocate a Hash and only store objects we actually use... */
40
+ VALUE multi; /* keep a multi handle alive for each easy handle not being used by a multi handle. This improves easy performance when not within a multi context */
41
+
42
+ /* Other opts */
43
+ unsigned short local_port; // 0 is no port
44
+ unsigned short local_port_range; // " " " "
45
+ unsigned short proxy_port; // " " " "
46
+ int proxy_type;
47
+ long http_auth_types;
48
+ long proxy_auth_types;
49
+ long max_redirs;
50
+ unsigned long timeout;
51
+ unsigned long connect_timeout;
52
+ long dns_cache_timeout;
53
+ unsigned long ftp_response_timeout;
54
+ long low_speed_limit;
55
+ long low_speed_time;
56
+ long ssl_version;
57
+ long use_ssl;
58
+ long ftp_filemethod;
59
+ unsigned short resolve_mode;
60
+
61
+ /* bool flags */
62
+ char proxy_tunnel;
63
+ char fetch_file_time;
64
+ char ssl_verify_peer;
65
+ char ssl_verify_host;
66
+ char header_in_body;
67
+ char use_netrc;
68
+ char follow_location;
69
+ char unrestricted_auth;
70
+ char verbose;
71
+ char multipart_form_post;
72
+ char enable_cookies;
73
+ char ignore_content_length;
74
+ char callback_active;
75
+
76
+ struct curl_slist *curl_headers;
77
+ struct curl_slist *curl_ftp_commands;
78
+
79
+ int last_result; /* last result code from multi loop */
80
+
81
+ } ruby_curl_easy;
82
+
83
+ extern VALUE cCurlEasy;
84
+
85
+ VALUE ruby_curl_easy_setup(ruby_curl_easy *rbce);
86
+ VALUE ruby_curl_easy_cleanup(VALUE self, ruby_curl_easy *rbce);
87
+
88
+ void init_curb_easy();
89
+
90
+ #endif
@@ -0,0 +1,660 @@
1
+ /* curb_errors.c - Ruby exception types for curl errors
2
+ * Copyright (c)2006 Ross Bamford.
3
+ * Licensed under the Ruby License. See LICENSE for details.
4
+ *
5
+ * $Id: curb_errors.c 10 2006-11-20 00:17:30Z roscopeco $
6
+ */
7
+ #include "curb_errors.h"
8
+
9
+ extern VALUE mCurl;
10
+
11
+ #ifdef RDOC_NEVER_DEFINED
12
+ mCurl = rb_define_module("Curl");
13
+ #endif
14
+
15
+ /* base errors */
16
+ VALUE mCurlErr;
17
+ VALUE eCurlErrError;
18
+ VALUE eCurlErrFTPError;
19
+ VALUE eCurlErrHTTPError;
20
+ VALUE eCurlErrFileError;
21
+ VALUE eCurlErrLDAPError;
22
+ VALUE eCurlErrTelnetError;
23
+ VALUE eCurlErrTFTPError;
24
+
25
+ /* Specific libcurl errors */
26
+ VALUE eCurlErrOK; /* not really an error but a return code */
27
+ VALUE eCurlErrUnsupportedProtocol;
28
+ VALUE eCurlErrFailedInit;
29
+ VALUE eCurlErrMalformedURL;
30
+ VALUE eCurlErrMalformedURLUser;
31
+ VALUE eCurlErrNotBuiltIn;
32
+ VALUE eCurlErrProxyResolution;
33
+ VALUE eCurlErrHostResolution;
34
+ VALUE eCurlErrConnectFailed;
35
+ VALUE eCurlErrFTPWeirdReply;
36
+ VALUE eCurlErrFTPAccessDenied;
37
+ VALUE eCurlErrFTPBadPassword;
38
+ VALUE eCurlErrFTPWeirdPassReply;
39
+ VALUE eCurlErrFTPWeirdUserReply;
40
+ VALUE eCurlErrFTPWeirdPasvReply;
41
+ VALUE eCurlErrFTPWeird227Format;
42
+ VALUE eCurlErrFTPCantGetHost;
43
+ VALUE eCurlErrFTPCantReconnect;
44
+ VALUE eCurlErrFTPCouldntSetBinary;
45
+ VALUE eCurlErrPartialFile;
46
+ VALUE eCurlErrFTPCouldntRetrFile;
47
+ VALUE eCurlErrFTPWrite;
48
+ VALUE eCurlErrFTPQuote;
49
+ VALUE eCurlErrHTTPFailed;
50
+ VALUE eCurlErrWriteError;
51
+ VALUE eCurlErrMalformedUser;
52
+ VALUE eCurlErrFTPCouldntStorFile;
53
+ VALUE eCurlErrReadError;
54
+ VALUE eCurlErrOutOfMemory;
55
+ VALUE eCurlErrTimeout;
56
+ VALUE eCurlErrFTPCouldntSetASCII;
57
+ VALUE eCurlErrFTPPortFailed;
58
+ VALUE eCurlErrFTPCouldntUseRest;
59
+ VALUE eCurlErrFTPCouldntGetSize;
60
+ VALUE eCurlErrHTTPRange;
61
+ VALUE eCurlErrHTTPPost;
62
+ VALUE eCurlErrSSLConnectError;
63
+ VALUE eCurlErrBadResume;
64
+ VALUE eCurlErrFileCouldntRead;
65
+ VALUE eCurlErrLDAPCouldntBind;
66
+ VALUE eCurlErrLDAPSearchFailed;
67
+ VALUE eCurlErrLibraryNotFound;
68
+ VALUE eCurlErrFunctionNotFound;
69
+ VALUE eCurlErrAbortedByCallback;
70
+ VALUE eCurlErrBadFunctionArgument;
71
+ VALUE eCurlErrBadCallingOrder;
72
+ VALUE eCurlErrInterfaceFailed;
73
+ VALUE eCurlErrBadPasswordEntered;
74
+ VALUE eCurlErrTooManyRedirects;
75
+ VALUE eCurlErrTelnetUnknownOption;
76
+ VALUE eCurlErrTelnetBadOptionSyntax;
77
+ VALUE eCurlErrObsolete;
78
+ VALUE eCurlErrSSLPeerCertificate;
79
+ VALUE eCurlErrGotNothing;
80
+ VALUE eCurlErrSSLEngineNotFound;
81
+ VALUE eCurlErrSSLEngineSetFailed;
82
+ VALUE eCurlErrSendError;
83
+ VALUE eCurlErrRecvError;
84
+ VALUE eCurlErrShareInUse;
85
+ VALUE eCurlErrSSLCertificate;
86
+ VALUE eCurlErrSSLCipher;
87
+ VALUE eCurlErrSSLCACertificate;
88
+ VALUE eCurlErrBadContentEncoding;
89
+ VALUE eCurlErrLDAPInvalidURL;
90
+ VALUE eCurlErrFileSizeExceeded;
91
+ VALUE eCurlErrFTPSSLFailed;
92
+ VALUE eCurlErrSendFailedRewind;
93
+ VALUE eCurlErrSSLEngineInitFailed;
94
+ VALUE eCurlErrLoginDenied;
95
+ VALUE eCurlErrTFTPNotFound;
96
+ VALUE eCurlErrTFTPPermission;
97
+ VALUE eCurlErrTFTPDiskFull;
98
+ VALUE eCurlErrTFTPIllegalOperation;
99
+ VALUE eCurlErrTFTPUnknownID;
100
+ VALUE eCurlErrTFTPFileExists;
101
+ VALUE eCurlErrTFTPNoSuchUser;
102
+
103
+ VALUE eCurlErrConvFailed;
104
+ VALUE eCurlErrConvReqd;
105
+ VALUE eCurlErrSSLCacertBadfile;
106
+ VALUE eCurlErrRemoteFileNotFound;
107
+ VALUE eCurlErrSSH;
108
+ VALUE eCurlErrSSLShutdownFailed;
109
+ VALUE eCurlErrAgain;
110
+ VALUE eCurlErrSSLCRLBadfile;
111
+ VALUE eCurlErrSSLIssuerError;
112
+
113
+ /* multi errors */
114
+ VALUE mCurlErrFailedInit;
115
+ VALUE mCurlErrCallMultiPerform;
116
+ VALUE mCurlErrBadHandle;
117
+ VALUE mCurlErrBadEasyHandle;
118
+ VALUE mCurlErrOutOfMemory;
119
+ VALUE mCurlErrInternalError;
120
+ VALUE mCurlErrBadSocket;
121
+ #if HAVE_CURLM_ADDED_ALREADY
122
+ VALUE mCurlErrAddedAlready;
123
+ #endif
124
+ VALUE mCurlErrUnknownOption;
125
+
126
+ /* binding errors */
127
+ VALUE eCurlErrInvalidPostField;
128
+
129
+
130
+ VALUE rb_curl_easy_error(CURLcode code) {
131
+ VALUE exclz;
132
+ const char *exmsg = NULL;
133
+ VALUE results;
134
+
135
+ switch (code) {
136
+ case CURLE_OK: /* 0 */
137
+ exclz = eCurlErrOK;
138
+ break;
139
+ case CURLE_UNSUPPORTED_PROTOCOL: /* 1 */
140
+ exclz = eCurlErrUnsupportedProtocol;
141
+ break;
142
+ case CURLE_FAILED_INIT: /* 2 */
143
+ exclz = eCurlErrFailedInit;
144
+ break;
145
+ case CURLE_URL_MALFORMAT: /* 3 */
146
+ exclz = eCurlErrMalformedURL;
147
+ break;
148
+ #ifdef HAVE_CURLE_NOT_BUILT_IN
149
+ case CURLE_NOT_BUILT_IN: /* 4 - [was obsoleted in August 2007 for 7.17.0, reused in April 2011 for 7.21.5] */
150
+ exclz = eCurlErrNotBuiltIn;
151
+ break;
152
+ #else
153
+ case CURLE_URL_MALFORMAT_USER: /* 4 (NOT USED) */
154
+ exclz = eCurlErrMalformedURLUser;
155
+ break;
156
+ #endif
157
+ case CURLE_COULDNT_RESOLVE_PROXY: /* 5 */
158
+ exclz = eCurlErrProxyResolution;
159
+ break;
160
+ case CURLE_COULDNT_RESOLVE_HOST: /* 6 */
161
+ exclz = eCurlErrHostResolution;
162
+ break;
163
+ case CURLE_COULDNT_CONNECT: /* 7 */
164
+ exclz = eCurlErrConnectFailed;
165
+ break;
166
+ case CURLE_FTP_WEIRD_SERVER_REPLY: /* 8 */
167
+ exclz = eCurlErrFTPWeirdReply;
168
+ break;
169
+ case CURLE_FTP_ACCESS_DENIED: /* 9 denied due to lack of access. */
170
+ exclz = eCurlErrFTPAccessDenied;
171
+ break;
172
+ case CURLE_FTP_USER_PASSWORD_INCORRECT: /* 10 */
173
+ exclz = eCurlErrFTPBadPassword;
174
+ break;
175
+ case CURLE_FTP_WEIRD_PASS_REPLY: /* 11 */
176
+ exclz = eCurlErrFTPWeirdPassReply;
177
+ break;
178
+ case CURLE_FTP_WEIRD_USER_REPLY: /* 12 */
179
+ exclz = eCurlErrFTPWeirdUserReply;
180
+ break;
181
+ case CURLE_FTP_WEIRD_PASV_REPLY: /* 13 */
182
+ exclz = eCurlErrFTPWeirdPasvReply;
183
+ break;
184
+ case CURLE_FTP_WEIRD_227_FORMAT: /* 14 */
185
+ exclz = eCurlErrFTPWeird227Format;
186
+ break;
187
+ case CURLE_FTP_CANT_GET_HOST: /* 15 */
188
+ exclz = eCurlErrFTPCantGetHost;
189
+ break;
190
+ case CURLE_FTP_CANT_RECONNECT: /* 16 */
191
+ exclz = eCurlErrFTPCantReconnect;
192
+ break;
193
+ case CURLE_FTP_COULDNT_SET_BINARY: /* 17 */
194
+ exclz = eCurlErrFTPCouldntSetBinary;
195
+ break;
196
+ case CURLE_PARTIAL_FILE: /* 18 */
197
+ exclz = eCurlErrPartialFile;
198
+ break;
199
+ case CURLE_FTP_COULDNT_RETR_FILE: /* 19 */
200
+ exclz = eCurlErrFTPCouldntRetrFile;
201
+ break;
202
+ case CURLE_FTP_WRITE_ERROR: /* 20 */
203
+ exclz = eCurlErrFTPWrite;
204
+ break;
205
+ case CURLE_FTP_QUOTE_ERROR: /* 21 */
206
+ exclz = eCurlErrFTPQuote;
207
+ break;
208
+ case CURLE_HTTP_RETURNED_ERROR: /* 22 */
209
+ exclz = eCurlErrHTTPFailed;
210
+ break;
211
+ case CURLE_WRITE_ERROR: /* 23 */
212
+ exclz = eCurlErrWriteError;
213
+ break;
214
+ case CURLE_MALFORMAT_USER: /* 24 - NOT USED */
215
+ exclz = eCurlErrMalformedUser;
216
+ break;
217
+ case CURLE_FTP_COULDNT_STOR_FILE: /* 25 - failed FTP upload */
218
+ exclz = eCurlErrFTPCouldntStorFile;
219
+ break;
220
+ case CURLE_READ_ERROR: /* 26 - could open/read from file */
221
+ exclz = eCurlErrReadError;
222
+ break;
223
+ case CURLE_OUT_OF_MEMORY: /* 27 */
224
+ exclz = eCurlErrOutOfMemory;
225
+ break;
226
+ case CURLE_OPERATION_TIMEOUTED: /* 28 - the timeout time was reached */
227
+ exclz = eCurlErrTimeout;
228
+ break;
229
+ case CURLE_FTP_COULDNT_SET_ASCII: /* 29 - TYPE A failed */
230
+ exclz = eCurlErrFTPCouldntSetASCII;
231
+ break;
232
+ case CURLE_FTP_PORT_FAILED: /* 30 - FTP PORT operation failed */
233
+ exclz = eCurlErrFTPPortFailed;
234
+ break;
235
+ case CURLE_FTP_COULDNT_USE_REST: /* 31 - the REST command failed */
236
+ exclz = eCurlErrFTPCouldntUseRest;
237
+ break;
238
+ case CURLE_FTP_COULDNT_GET_SIZE: /* 32 - the SIZE command failed */
239
+ exclz = eCurlErrFTPCouldntGetSize;
240
+ break;
241
+ case CURLE_HTTP_RANGE_ERROR: /* 33 - RANGE "command" didn't work */
242
+ exclz = eCurlErrHTTPRange;
243
+ break;
244
+ case CURLE_HTTP_POST_ERROR: /* 34 */
245
+ exclz = eCurlErrHTTPPost;
246
+ break;
247
+ case CURLE_SSL_CONNECT_ERROR: /* 35 - wrong when connecting with SSL */
248
+ exclz = eCurlErrSSLConnectError;
249
+ break;
250
+ case CURLE_BAD_DOWNLOAD_RESUME: /* 36 - couldn't resume download */
251
+ exclz = eCurlErrBadResume;
252
+ break;
253
+ case CURLE_FILE_COULDNT_READ_FILE: /* 37 */
254
+ exclz = eCurlErrFileCouldntRead;
255
+ break;
256
+ case CURLE_LDAP_CANNOT_BIND: /* 38 */
257
+ exclz = eCurlErrLDAPCouldntBind;
258
+ break;
259
+ case CURLE_LDAP_SEARCH_FAILED: /* 39 */
260
+ exclz = eCurlErrLDAPSearchFailed;
261
+ break;
262
+ case CURLE_LIBRARY_NOT_FOUND: /* 40 */
263
+ exclz = eCurlErrLibraryNotFound;
264
+ break;
265
+ case CURLE_FUNCTION_NOT_FOUND: /* 41 */
266
+ exclz = eCurlErrFunctionNotFound;
267
+ break;
268
+ case CURLE_ABORTED_BY_CALLBACK: /* 42 */
269
+ exclz = eCurlErrAbortedByCallback;
270
+ break;
271
+ case CURLE_BAD_FUNCTION_ARGUMENT: /* 43 */
272
+ exclz = eCurlErrBadFunctionArgument;
273
+ break;
274
+ case CURLE_BAD_CALLING_ORDER: /* 44 - NOT USED */
275
+ exclz = eCurlErrBadCallingOrder;
276
+ break;
277
+ case CURLE_INTERFACE_FAILED: /* 45 - CURLOPT_INTERFACE failed */
278
+ exclz = eCurlErrInterfaceFailed;
279
+ break;
280
+ case CURLE_BAD_PASSWORD_ENTERED: /* 46 - NOT USED */
281
+ exclz = eCurlErrBadPasswordEntered;
282
+ break;
283
+ case CURLE_TOO_MANY_REDIRECTS: /* 47 - catch endless re-direct loops */
284
+ exclz = eCurlErrTooManyRedirects;
285
+ break;
286
+ case CURLE_UNKNOWN_TELNET_OPTION: /* 48 - User specified an unknown option */
287
+ exclz = eCurlErrTelnetUnknownOption;
288
+ break;
289
+ case CURLE_TELNET_OPTION_SYNTAX: /* 49 - Malformed telnet option */
290
+ exclz = eCurlErrTelnetBadOptionSyntax;
291
+ break;
292
+ #ifdef HAVE_CURLE_OBSOLETE
293
+ case CURLE_OBSOLETE: /* 50 - NOT USED */
294
+ exclz = eCurlErrObsolete;
295
+ break;
296
+ #endif
297
+ case CURLE_SSL_PEER_CERTIFICATE: /* 51 - peer's certificate wasn't ok */
298
+ exclz = eCurlErrSSLPeerCertificate;
299
+ break;
300
+ case CURLE_GOT_NOTHING: /* 52 - when this is a specific error */
301
+ exclz = eCurlErrGotNothing;
302
+ break;
303
+ case CURLE_SSL_ENGINE_NOTFOUND: /* 53 - SSL crypto engine not found */
304
+ exclz = eCurlErrSSLEngineNotFound;
305
+ break;
306
+ case CURLE_SSL_ENGINE_SETFAILED: /* 54 - can not set SSL crypto engine as default */
307
+ exclz = eCurlErrSSLEngineSetFailed;
308
+ break;
309
+ case CURLE_SEND_ERROR: /* 55 - failed sending network data */
310
+ exclz = eCurlErrSendError;
311
+ break;
312
+ case CURLE_RECV_ERROR: /* 56 - failure in receiving network data */
313
+ exclz = eCurlErrRecvError;
314
+ break;
315
+ case CURLE_SHARE_IN_USE: /* 57 - share is in use */
316
+ exclz = eCurlErrShareInUse;
317
+ break;
318
+ case CURLE_SSL_CERTPROBLEM: /* 58 - problem with the local certificate */
319
+ exclz = eCurlErrSSLCertificate;
320
+ break;
321
+ case CURLE_SSL_CIPHER: /* 59 - couldn't use specified cipher */
322
+ exclz = eCurlErrSSLCipher;
323
+ break;
324
+ case CURLE_SSL_CACERT: /* 60 - problem with the CA cert (path?) */
325
+ exclz = eCurlErrSSLCACertificate;
326
+ break;
327
+ case CURLE_BAD_CONTENT_ENCODING: /* 61 - Unrecognized transfer encoding */
328
+ exclz = eCurlErrBadContentEncoding;
329
+ break;
330
+ case CURLE_LDAP_INVALID_URL: /* 62 - Invalid LDAP URL */
331
+ exclz = eCurlErrLDAPInvalidURL;
332
+ break;
333
+ case CURLE_FILESIZE_EXCEEDED: /* 63 - Maximum file size exceeded */
334
+ exclz = eCurlErrFileSizeExceeded;
335
+ break;
336
+ case CURLE_FTP_SSL_FAILED: /* 64 - Requested FTP SSL level failed */
337
+ exclz = eCurlErrFTPSSLFailed;
338
+ break;
339
+ #ifdef HAVE_CURLE_SEND_FAIL_REWIND
340
+ case CURLE_SEND_FAIL_REWIND: /* 65 - Sending the data requires a rewind that failed */
341
+ exclz = eCurlErrSendFailedRewind;
342
+ break;
343
+ #endif
344
+ #ifdef HAVE_CURLE_SSL_ENGINE_INITFAILED
345
+ case CURLE_SSL_ENGINE_INITFAILED: /* 66 - failed to initialise ENGINE */
346
+ exclz = eCurlErrSSLEngineInitFailed;
347
+ break;
348
+ #endif
349
+ #ifdef HAVE_CURLE_LOGIN_DENIED
350
+ case CURLE_LOGIN_DENIED: /* 67 - user, password or similar was not accepted and we failed to login */
351
+ exclz = eCurlErrLoginDenied;
352
+ break;
353
+ #endif
354
+
355
+ // recent additions, may not be present in all supported versions
356
+ #ifdef HAVE_CURLE_TFTP_NOTFOUND
357
+ case CURLE_TFTP_NOTFOUND: /* 68 - file not found on server */
358
+ exclz = eCurlErrTFTPNotFound;
359
+ break;
360
+ #endif
361
+ #ifdef HAVE_CURLE_TFTP_PERM
362
+ case CURLE_TFTP_PERM: /* 69 - permission problem on server */
363
+ exclz = eCurlErrTFTPPermission;
364
+ break;
365
+ #endif
366
+ #ifdef HAVE_CURLE_TFTP_DISKFULL
367
+ case CURLE_TFTP_DISKFULL: /* 70 - out of disk space on server */
368
+ exclz = eCurlErrTFTPDiskFull;
369
+ break;
370
+ #endif
371
+ #ifdef HAVE_CURLE_TFTP_ILLEGAL
372
+ case CURLE_TFTP_ILLEGAL: /* 71 - Illegal TFTP operation */
373
+ exclz = eCurlErrTFTPIllegalOperation;
374
+ break;
375
+ #endif
376
+ #ifdef HAVE_CURLE_TFTP_UNKNOWNID
377
+ case CURLE_TFTP_UNKNOWNID: /* 72 - Unknown transfer ID */
378
+ exclz = eCurlErrTFTPUnknownID;
379
+ break;
380
+ #endif
381
+ #ifdef HAVE_CURLE_TFTP_EXISTS
382
+ case CURLE_TFTP_EXISTS: /* 73 - File already exists */
383
+ exclz = eCurlErrTFTPFileExists;
384
+ break;
385
+ #endif
386
+ #ifdef HAVE_CURLE_TFTP_NOSUCHUSER
387
+ case CURLE_TFTP_NOSUCHUSER: /* 74 - No such user */
388
+ exclz = eCurlErrTFTPNotFound;
389
+ break;
390
+ #endif
391
+ #ifdef HAVE_CURLE_CONV_FAILED
392
+ case CURLE_CONV_FAILED: /* 75 - conversion failed */
393
+ exclz = eCurlErrConvFailed;
394
+ break;
395
+ #endif
396
+ #ifdef HAVE_CURLE_CONV_REQD
397
+ case CURLE_CONV_REQD: /* 76 - caller must register conversion
398
+ callbacks using curl_easy_setopt options
399
+ CURLOPT_CONV_FROM_NETWORK_FUNCTION,
400
+ CURLOPT_CONV_TO_NETWORK_FUNCTION, and
401
+ CURLOPT_CONV_FROM_UTF8_FUNCTION */
402
+ exclz = eCurlErrConvReqd;
403
+ break;
404
+ #endif
405
+ #ifdef HAVE_CURLE_SSL_CACERT_BADFILE
406
+ case CURLE_SSL_CACERT_BADFILE: /* 77 - could not load CACERT file, missing
407
+ or wrong format */
408
+ exclz = eCurlErrSSLCacertBadfile;
409
+ break;
410
+ #endif
411
+ #ifdef HAVE_CURLE_REMOTE_FILE_NOT_FOUND
412
+ case CURLE_REMOTE_FILE_NOT_FOUND: /* 78 - remote file not found */
413
+ exclz = eCurlErrRemoteFileNotFound;
414
+ break;
415
+ #endif
416
+ #ifdef HAVE_CURLE_SSH
417
+ case CURLE_SSH: /* 79 - error from the SSH layer, somewhat
418
+ generic so the error message will be of
419
+ interest when this has happened */
420
+ exclz = eCurlErrSSH;
421
+ break;
422
+ #endif
423
+ #ifdef HAVE_CURLE_SSL_SHUTDOWN_FAILED
424
+ case CURLE_SSL_SHUTDOWN_FAILED: /* 80 - Failed to shut down the SSL
425
+ connection */
426
+ exclz = eCurlErrSSLShutdownFailed;
427
+ break;
428
+ #endif
429
+ #ifdef HAVE_CURLE_AGAIN
430
+ case CURLE_AGAIN: /* 81 - socket is not ready for send/recv,
431
+ wait till it's ready and try again (Added
432
+ in 7.18.2) */
433
+ exclz = eCurlErrAgain;
434
+ break;
435
+ #endif
436
+ #ifdef HAVE_CURLE_SSL_CRL_BADFILE
437
+ case CURLE_SSL_CRL_BADFILE: /* 82 - could not load CRL file, missing or
438
+ wrong format (Added in 7.19.0) */
439
+ exclz = eCurlErrSSLCRLBadfile;
440
+ break;
441
+ #endif
442
+ #ifdef HAVE_CURLE_SSL_ISSUER_ERROR
443
+ case CURLE_SSL_ISSUER_ERROR: /* 83 - Issuer check failed. (Added in
444
+ 7.19.0) */
445
+ exclz = eCurlErrSSLIssuerError;
446
+ break;
447
+ #endif
448
+ default:
449
+ exclz = eCurlErrError;
450
+ exmsg = "Unknown error result from libcurl";
451
+ }
452
+
453
+ if (!exmsg) {
454
+ exmsg = curl_easy_strerror(code);
455
+ }
456
+
457
+ results = rb_ary_new2(2);
458
+ rb_ary_push(results, exclz);
459
+ rb_ary_push(results, rb_str_new2(exmsg));
460
+ return results;
461
+ }
462
+ /* rb_raise an approriate exception for the supplied CURLcode */
463
+ void raise_curl_easy_error_exception(CURLcode code) {
464
+ VALUE obj = rb_curl_easy_error(code);
465
+ VALUE exmsg = rb_ary_entry(obj,1);
466
+ rb_raise(rb_ary_entry(obj,0), "CURLError: %s", StringValueCStr(exmsg));
467
+ }
468
+ VALUE rb_curl_multi_error(CURLMcode code) {
469
+ VALUE exclz;
470
+ const char *exmsg = NULL;
471
+ VALUE results;
472
+
473
+ switch(code) {
474
+ case CURLM_CALL_MULTI_PERFORM: /* -1 */
475
+ exclz = mCurlErrCallMultiPerform;
476
+ break;
477
+ case CURLM_BAD_HANDLE: /* 1 */
478
+ exclz = mCurlErrBadHandle;
479
+ break;
480
+ case CURLM_BAD_EASY_HANDLE: /* 2 */
481
+ exclz = mCurlErrBadEasyHandle;
482
+ break;
483
+ case CURLM_OUT_OF_MEMORY: /* 3 */
484
+ exclz = mCurlErrOutOfMemory;
485
+ break;
486
+ case CURLM_INTERNAL_ERROR: /* 4 */
487
+ exclz = mCurlErrInternalError;
488
+ break;
489
+ #if HAVE_CURLM_BAD_SOCKET
490
+ case CURLM_BAD_SOCKET: /* 5 */
491
+ exclz = mCurlErrBadSocket;
492
+ break;
493
+ #endif
494
+ #if HAVE_CURLM_UNKNOWN_OPTION
495
+ case CURLM_UNKNOWN_OPTION: /* 6 */
496
+ exclz = mCurlErrUnknownOption;
497
+ break;
498
+ #endif
499
+ #if HAVE_CURLM_ADDED_ALREADY
500
+ case CURLM_ADDED_ALREADY: /* 7 */
501
+ exclz = mCurlErrAddedAlready;
502
+ break;
503
+ #endif
504
+ default:
505
+ exclz = eCurlErrError;
506
+ exmsg = "Unknown error result from libcurl";
507
+ }
508
+
509
+ if (!exmsg) {
510
+ exmsg = curl_multi_strerror(code);
511
+ }
512
+
513
+ results = rb_ary_new2(2);
514
+ rb_ary_push(results, exclz);
515
+ rb_ary_push(results, rb_str_new2(exmsg));
516
+
517
+ return results;
518
+ }
519
+ void raise_curl_multi_error_exception(CURLMcode code) {
520
+ VALUE obj = rb_curl_multi_error(code);
521
+ VALUE exmsg = rb_ary_entry(obj,1);
522
+ rb_raise(rb_ary_entry(obj,0), "CURLError: %s", StringValueCStr(exmsg));
523
+ }
524
+
525
+ void init_curb_errors() {
526
+ mCurlErr = rb_define_module_under(mCurl, "Err");
527
+ eCurlErrError = rb_define_class_under(mCurlErr, "CurlError", rb_eRuntimeError);
528
+
529
+ eCurlErrFTPError = rb_define_class_under(mCurlErr, "FTPError", eCurlErrError);
530
+ eCurlErrHTTPError = rb_define_class_under(mCurlErr, "HTTPError", eCurlErrError);
531
+ eCurlErrFileError = rb_define_class_under(mCurlErr, "FileError", eCurlErrError);
532
+ eCurlErrLDAPError = rb_define_class_under(mCurlErr, "LDAPError", eCurlErrError);
533
+ eCurlErrTelnetError = rb_define_class_under(mCurlErr, "TelnetError", eCurlErrError);
534
+ eCurlErrTFTPError = rb_define_class_under(mCurlErr, "TFTPError", eCurlErrError);
535
+
536
+ eCurlErrOK = rb_define_class_under(mCurlErr, "CurlOK", eCurlErrError);
537
+ eCurlErrUnsupportedProtocol = rb_define_class_under(mCurlErr, "UnsupportedProtocolError", eCurlErrError);
538
+ eCurlErrFailedInit = rb_define_class_under(mCurlErr, "FailedInitError", eCurlErrError);
539
+ eCurlErrMalformedURL = rb_define_class_under(mCurlErr, "MalformedURLError", eCurlErrError);
540
+ eCurlErrNotBuiltIn = rb_define_class_under(mCurlErr, "NotBuiltInError", eCurlErrError);
541
+ eCurlErrMalformedURLUser = rb_define_class_under(mCurlErr, "MalformedURLUserError", eCurlErrError);
542
+ eCurlErrProxyResolution = rb_define_class_under(mCurlErr, "ProxyResolutionError", eCurlErrError);
543
+ eCurlErrHostResolution = rb_define_class_under(mCurlErr, "HostResolutionError", eCurlErrError);
544
+ eCurlErrConnectFailed = rb_define_class_under(mCurlErr, "ConnectionFailedError", eCurlErrError);
545
+
546
+ eCurlErrFTPWeirdReply = rb_define_class_under(mCurlErr, "WeirdReplyError", eCurlErrFTPError);
547
+ eCurlErrFTPAccessDenied = rb_define_class_under(mCurlErr, "AccessDeniedError", eCurlErrFTPError);
548
+ eCurlErrFTPBadPassword = rb_define_class_under(mCurlErr, "BadPasswordError", eCurlErrFTPError);
549
+ eCurlErrFTPWeirdPassReply = rb_define_class_under(mCurlErr, "WeirdPassReplyError", eCurlErrFTPError);
550
+ eCurlErrFTPWeirdUserReply = rb_define_class_under(mCurlErr, "WeirdUserReplyError", eCurlErrFTPError);
551
+ eCurlErrFTPWeirdPasvReply = rb_define_class_under(mCurlErr, "WeirdPasvReplyError", eCurlErrFTPError);
552
+ eCurlErrFTPWeird227Format = rb_define_class_under(mCurlErr, "Weird227FormatError", eCurlErrFTPError);
553
+ eCurlErrFTPCantGetHost = rb_define_class_under(mCurlErr, "CantGetHostError", eCurlErrFTPError);
554
+ eCurlErrFTPCantReconnect = rb_define_class_under(mCurlErr, "CantReconnectError", eCurlErrFTPError);
555
+ eCurlErrFTPCouldntSetBinary = rb_define_class_under(mCurlErr, "CouldntSetBinaryError", eCurlErrFTPError);
556
+
557
+ eCurlErrPartialFile = rb_define_class_under(mCurlErr, "PartialFileError", eCurlErrError);
558
+
559
+ eCurlErrFTPCouldntRetrFile = rb_define_class_under(mCurlErr, "CouldntRetrFileError", eCurlErrFTPError);
560
+ eCurlErrFTPWrite = rb_define_class_under(mCurlErr, "FTPWriteError", eCurlErrFTPError);
561
+ eCurlErrFTPQuote = rb_define_class_under(mCurlErr, "FTPQuoteError", eCurlErrFTPError);
562
+
563
+ eCurlErrHTTPFailed = rb_define_class_under(mCurlErr, "HTTPFailedError", eCurlErrHTTPError);
564
+
565
+ eCurlErrWriteError = rb_define_class_under(mCurlErr, "WriteError", eCurlErrError);
566
+ eCurlErrMalformedUser = rb_define_class_under(mCurlErr, "MalformedUserError", eCurlErrError);
567
+
568
+ eCurlErrFTPCouldntStorFile = rb_define_class_under(mCurlErr, "CouldntStorFileError", eCurlErrFTPError);
569
+
570
+ eCurlErrReadError = rb_define_class_under(mCurlErr, "ReadError", eCurlErrError);
571
+ eCurlErrOutOfMemory = rb_define_class_under(mCurlErr, "OutOfMemoryError", eCurlErrError);
572
+ eCurlErrTimeout = rb_define_class_under(mCurlErr, "TimeoutError", eCurlErrError);
573
+
574
+ eCurlErrFTPCouldntSetASCII = rb_define_class_under(mCurlErr, "CouldntSetASCIIError", eCurlErrFTPError);
575
+ eCurlErrFTPPortFailed = rb_define_class_under(mCurlErr, "PortFailedError", eCurlErrFTPError);
576
+ eCurlErrFTPCouldntUseRest = rb_define_class_under(mCurlErr, "CouldntUseRestError", eCurlErrFTPError);
577
+ eCurlErrFTPCouldntGetSize = rb_define_class_under(mCurlErr, "CouldntGetSizeError", eCurlErrFTPError);
578
+
579
+ eCurlErrHTTPRange = rb_define_class_under(mCurlErr, "HTTPRangeError", eCurlErrHTTPError);
580
+ eCurlErrHTTPPost = rb_define_class_under(mCurlErr, "HTTPPostError", eCurlErrHTTPError);
581
+
582
+ eCurlErrSSLConnectError = rb_define_class_under(mCurlErr, "SSLConnectError", eCurlErrError);
583
+ eCurlErrBadResume = rb_define_class_under(mCurlErr, "BadResumeError", eCurlErrError);
584
+
585
+ eCurlErrFileCouldntRead = rb_define_class_under(mCurlErr, "CouldntReadError", eCurlErrFileError);
586
+
587
+ eCurlErrLDAPCouldntBind = rb_define_class_under(mCurlErr, "CouldntBindError", eCurlErrLDAPError);
588
+ eCurlErrLDAPSearchFailed = rb_define_class_under(mCurlErr, "SearchFailedError", eCurlErrLDAPError);
589
+
590
+ eCurlErrLibraryNotFound = rb_define_class_under(mCurlErr, "LibraryNotFoundError", eCurlErrError);
591
+ eCurlErrFunctionNotFound = rb_define_class_under(mCurlErr, "FunctionNotFoundError", eCurlErrError);
592
+ eCurlErrAbortedByCallback = rb_define_class_under(mCurlErr, "AbortedByCallbackError", eCurlErrError);
593
+ eCurlErrBadFunctionArgument = rb_define_class_under(mCurlErr, "BadFunctionArgumentError", eCurlErrError);
594
+ eCurlErrBadCallingOrder = rb_define_class_under(mCurlErr, "BadCallingOrderError", eCurlErrError);
595
+ eCurlErrInterfaceFailed = rb_define_class_under(mCurlErr, "InterfaceFailedError", eCurlErrError);
596
+
597
+ eCurlErrBadPasswordEntered = rb_define_class_under(mCurlErr, "BadPasswordEnteredError", eCurlErrError);
598
+ eCurlErrTooManyRedirects = rb_define_class_under(mCurlErr, "TooManyRedirectsError", eCurlErrError);
599
+
600
+ eCurlErrTelnetUnknownOption = rb_define_class_under(mCurlErr, "UnknownOptionError", eCurlErrTelnetError);
601
+ eCurlErrTelnetBadOptionSyntax = rb_define_class_under(mCurlErr, "BadOptionSyntaxError", eCurlErrTelnetError);
602
+
603
+ eCurlErrObsolete = rb_define_class_under(mCurlErr, "ObsoleteError", eCurlErrError);
604
+ eCurlErrSSLPeerCertificate = rb_define_class_under(mCurlErr, "SSLPeerCertificateError", eCurlErrError);
605
+ eCurlErrGotNothing = rb_define_class_under(mCurlErr, "GotNothingError", eCurlErrError);
606
+
607
+ eCurlErrSSLEngineNotFound = rb_define_class_under(mCurlErr, "SSLEngineNotFoundError", eCurlErrError);
608
+ eCurlErrSSLEngineSetFailed = rb_define_class_under(mCurlErr, "SSLEngineSetFailedError", eCurlErrError);
609
+
610
+ eCurlErrSendError = rb_define_class_under(mCurlErr, "SendError", eCurlErrError);
611
+ eCurlErrRecvError = rb_define_class_under(mCurlErr, "RecvError", eCurlErrError);
612
+ eCurlErrShareInUse = rb_define_class_under(mCurlErr, "ShareInUseError", eCurlErrError);
613
+
614
+ eCurlErrConvFailed = rb_define_class_under(mCurlErr, "ConvFailed", eCurlErrError);
615
+ eCurlErrConvReqd = rb_define_class_under(mCurlErr, "ConvReqd", eCurlErrError);
616
+ eCurlErrRemoteFileNotFound = rb_define_class_under(mCurlErr, "RemoteFileNotFound", eCurlErrError);
617
+ eCurlErrAgain = rb_define_class_under(mCurlErr, "Again", eCurlErrError);
618
+
619
+ eCurlErrSSLCertificate = rb_define_class_under(mCurlErr, "SSLCertificateError", eCurlErrError);
620
+ eCurlErrSSLCipher = rb_define_class_under(mCurlErr, "SSLCypherError", eCurlErrError);
621
+ eCurlErrSSLCACertificate = rb_define_class_under(mCurlErr, "SSLCACertificateError", eCurlErrError);
622
+ eCurlErrBadContentEncoding = rb_define_class_under(mCurlErr, "BadContentEncodingError", eCurlErrError);
623
+ eCurlErrSSLCacertBadfile = rb_define_class_under(mCurlErr, "SSLCaertBadFile", eCurlErrError);
624
+ eCurlErrSSLCRLBadfile = rb_define_class_under(mCurlErr, "SSLCRLBadfile", eCurlErrError);
625
+ eCurlErrSSLIssuerError = rb_define_class_under(mCurlErr, "SSLIssuerError", eCurlErrError);
626
+ eCurlErrSSLShutdownFailed = rb_define_class_under(mCurlErr, "SSLShutdownFailed", eCurlErrError);
627
+ eCurlErrSSH = rb_define_class_under(mCurlErr, "SSH", eCurlErrError);
628
+
629
+ mCurlErrFailedInit = rb_define_class_under(mCurlErr, "MultiInitError", eCurlErrError);
630
+ mCurlErrCallMultiPerform = rb_define_class_under(mCurlErr, "MultiPerform", eCurlErrError);
631
+ mCurlErrBadHandle = rb_define_class_under(mCurlErr, "MultiBadHandle", eCurlErrError);
632
+ mCurlErrBadEasyHandle = rb_define_class_under(mCurlErr, "MultiBadEasyHandle", eCurlErrError);
633
+ mCurlErrOutOfMemory = rb_define_class_under(mCurlErr, "MultiOutOfMemory", eCurlErrError);
634
+ mCurlErrInternalError = rb_define_class_under(mCurlErr, "MultiInternalError", eCurlErrError);
635
+ mCurlErrBadSocket = rb_define_class_under(mCurlErr, "MultiBadSocket", eCurlErrError);
636
+ #if HAVE_CURLM_ADDED_ALREADY
637
+ mCurlErrAddedAlready = rb_define_class_under(mCurlErr, "MultiAddedAlready", eCurlErrError);
638
+ #endif
639
+ mCurlErrUnknownOption = rb_define_class_under(mCurlErr, "MultiUnknownOption", eCurlErrError);
640
+
641
+ eCurlErrLDAPInvalidURL = rb_define_class_under(mCurlErr, "InvalidLDAPURLError", eCurlErrLDAPError);
642
+
643
+ eCurlErrFileSizeExceeded = rb_define_class_under(mCurlErr, "FileSizeExceededError", eCurlErrError);
644
+
645
+ eCurlErrFTPSSLFailed = rb_define_class_under(mCurlErr, "FTPSSLFailed", eCurlErrFTPError);
646
+
647
+ eCurlErrSendFailedRewind = rb_define_class_under(mCurlErr, "SendFailedRewind", eCurlErrError);
648
+ eCurlErrSSLEngineInitFailed = rb_define_class_under(mCurlErr, "SSLEngineInitFailedError", eCurlErrError);
649
+ eCurlErrLoginDenied = rb_define_class_under(mCurlErr, "LoginDeniedError", eCurlErrError);
650
+
651
+ eCurlErrTFTPNotFound = rb_define_class_under(mCurlErr, "NotFoundError", eCurlErrTFTPError);
652
+ eCurlErrTFTPPermission = rb_define_class_under(mCurlErr, "PermissionError", eCurlErrTFTPError);
653
+ eCurlErrTFTPDiskFull = rb_define_class_under(mCurlErr, "DiskFullError", eCurlErrTFTPError);
654
+ eCurlErrTFTPIllegalOperation = rb_define_class_under(mCurlErr, "IllegalOperationError", eCurlErrTFTPError);
655
+ eCurlErrTFTPUnknownID = rb_define_class_under(mCurlErr, "UnknownIDError", eCurlErrTFTPError);
656
+ eCurlErrTFTPFileExists = rb_define_class_under(mCurlErr, "FileExistsError", eCurlErrTFTPError);
657
+ eCurlErrTFTPNoSuchUser = rb_define_class_under(mCurlErr, "NoSuchUserError", eCurlErrTFTPError);
658
+
659
+ eCurlErrInvalidPostField = rb_define_class_under(mCurlErr, "InvalidPostFieldError", eCurlErrError);
660
+ }