fotonauts-curb 0.7.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/doc.rb ADDED
@@ -0,0 +1,42 @@
1
+ require 'fileutils'
2
+ include FileUtils
3
+
4
+ begin
5
+ incflags = File.read('ext/Makefile')[/INCFLAGS\s*=\s*(.*)$/,1]
6
+ rescue Errno::ENOENT
7
+ $stderr.puts("No makefile found; run `rake ext/Makefile' first.")
8
+ end
9
+
10
+ pp_srcdir = 'ext'
11
+
12
+ rm_rf(tmpdir = '.doc-tmp')
13
+ mkdir(tmpdir)
14
+
15
+ begin
16
+ if ARGV.include?('--cpp')
17
+ begin
18
+ if `cpp --version` =~ /\(GCC\)/
19
+ # gnu cpp
20
+ $stderr.puts "Running GNU cpp over source"
21
+
22
+ Dir['ext/*.c'].each do |fn|
23
+ system("cpp -DRDOC_NEVER_DEFINED -C #{incflags} -o " +
24
+ "#{File.join(tmpdir, File.basename(fn))} #{fn}")
25
+ end
26
+
27
+ pp_srcdir = tmpdir
28
+ else
29
+ $stderr.puts "Not running cpp (non-GNU)"
30
+ end
31
+ rescue
32
+ # no cpp
33
+ $stderr.puts "No cpp found"
34
+ end
35
+ end
36
+
37
+ system("rdoc --title='Curb - libcurl bindings for ruby' --main=README #{pp_srcdir}/*.c README LICENSE lib/curb.rb")
38
+ ensure
39
+ rm_rf(tmpdir)
40
+ end
41
+
42
+
data/ext/curb.c ADDED
@@ -0,0 +1,373 @@
1
+ /* Curb - Libcurl(3) bindings for Ruby.
2
+ * Copyright (c)2006 Ross Bamford.
3
+ * Licensed under the Ruby License. See LICENSE for details.
4
+ *
5
+ * $Id: curb.c 35 2006-12-23 15:22:19Z roscopeco $
6
+ */
7
+
8
+ #include "curb.h"
9
+
10
+ VALUE mCurl;
11
+
12
+ /* ================== VER QUERY FUNCS ==============*/
13
+
14
+ /*
15
+ * call-seq:
16
+ * Curl.ipv6? => true or false
17
+ *
18
+ * Returns true if the installed libcurl supports IPv6.
19
+ */
20
+ static VALUE ruby_curl_ipv6_q(VALUE mod) {
21
+ curl_version_info_data *ver = curl_version_info(CURLVERSION_NOW);
22
+ return((ver->features & CURL_VERSION_IPV6) ? Qtrue : Qfalse);
23
+ }
24
+
25
+ /*
26
+ * call-seq:
27
+ * Curl.kerberos4? => true or false
28
+ *
29
+ * Returns true if the installed libcurl supports Kerberos4 authentication
30
+ * with FTP connections.
31
+ */
32
+ static VALUE ruby_curl_kerberos4_q(VALUE mod) {
33
+ curl_version_info_data *ver = curl_version_info(CURLVERSION_NOW);
34
+ return((ver->features & CURL_VERSION_KERBEROS4) ? Qtrue : Qfalse);
35
+ }
36
+
37
+ /*
38
+ * call-seq:
39
+ * Curl.ssl? => true or false
40
+ *
41
+ * Returns true if the installed libcurl supports SSL connections.
42
+ * For libcurl versions < 7.10, always returns false.
43
+ */
44
+ static VALUE ruby_curl_ssl_q(VALUE mod) {
45
+ #ifdef HAVE_CURL_VERSION_SSL
46
+ curl_version_info_data *ver = curl_version_info(CURLVERSION_NOW);
47
+ return((ver->features & CURL_VERSION_SSL) ? Qtrue : Qfalse);
48
+ #else
49
+ return Qfalse;
50
+ #endif
51
+ }
52
+
53
+ /*
54
+ * call-seq:
55
+ * Curl.libz? => true or false
56
+ *
57
+ * Returns true if the installed libcurl supports HTTP deflate
58
+ * using libz. For libcurl versions < 7.10, always returns false.
59
+ */
60
+ static VALUE ruby_curl_libz_q(VALUE mod) {
61
+ #ifdef HAVE_CURL_VERSION_LIBZ
62
+ curl_version_info_data *ver = curl_version_info(CURLVERSION_NOW);
63
+ return((ver->features & CURL_VERSION_LIBZ) ? Qtrue : Qfalse);
64
+ #else
65
+ return Qfalse;
66
+ #endif
67
+ }
68
+
69
+ /*
70
+ * call-seq:
71
+ * Curl.ntlm? => true or false
72
+ *
73
+ * Returns true if the installed libcurl supports HTTP NTLM.
74
+ * For libcurl versions < 7.10.6, always returns false.
75
+ */
76
+ static VALUE ruby_curl_ntlm_q(VALUE mod) {
77
+ #ifdef HAVE_CURL_VERSION_NTLM
78
+ curl_version_info_data *ver = curl_version_info(CURLVERSION_NOW);
79
+ return((ver->features & CURL_VERSION_NTLM) ? Qtrue : Qfalse);
80
+ #else
81
+ return Qfalse;
82
+ #endif
83
+ }
84
+
85
+ /*
86
+ * call-seq:
87
+ * Curl.gssnegotiate? => true or false
88
+ *
89
+ * Returns true if the installed libcurl supports HTTP GSS-Negotiate.
90
+ * For libcurl versions < 7.10.6, always returns false.
91
+ */
92
+ static VALUE ruby_curl_gssnegotiate_q(VALUE mod) {
93
+ #ifdef HAVE_CURL_VERSION_GSSNEGOTIATE
94
+ curl_version_info_data *ver = curl_version_info(CURLVERSION_NOW);
95
+ return((ver->features & CURL_VERSION_GSSNEGOTIATE) ? Qtrue : Qfalse);
96
+ #else
97
+ return Qfalse;
98
+ #endif
99
+ }
100
+
101
+ /*
102
+ * call-seq:
103
+ * Curl.debug? => true or false
104
+ *
105
+ * Returns true if the installed libcurl was built with extra debug
106
+ * capabilities built-in. For libcurl versions < 7.10.6, always returns
107
+ * false.
108
+ */
109
+ static VALUE ruby_curl_debug_q(VALUE mod) {
110
+ #ifdef HAVE_CURL_VERSION_DEBUG
111
+ curl_version_info_data *ver = curl_version_info(CURLVERSION_NOW);
112
+ return((ver->features & CURL_VERSION_DEBUG) ? Qtrue : Qfalse);
113
+ #else
114
+ return Qfalse;
115
+ #endif
116
+ }
117
+
118
+ /*
119
+ * call-seq:
120
+ * Curl.asyncdns? => true or false
121
+ *
122
+ * Returns true if the installed libcurl was built with support for
123
+ * asynchronous name lookups, which allows more exact timeouts (even
124
+ * on Windows) and less blocking when using the multi interface.
125
+ * For libcurl versions < 7.10.7, always returns false.
126
+ */
127
+ static VALUE ruby_curl_asyncdns_q(VALUE mod) {
128
+ #ifdef HAVE_CURL_VERSION_ASYNCHDNS
129
+ curl_version_info_data *ver = curl_version_info(CURLVERSION_NOW);
130
+ return((ver->features & CURL_VERSION_ASYNCHDNS) ? Qtrue : Qfalse);
131
+ #else
132
+ return Qfalse;
133
+ #endif
134
+ }
135
+
136
+ /*
137
+ * call-seq:
138
+ * Curl.spnego? => true or false
139
+ *
140
+ * Returns true if the installed libcurl was built with support for SPNEGO
141
+ * authentication (Simple and Protected GSS-API Negotiation Mechanism, defined
142
+ * in RFC 2478). For libcurl versions < 7.10.8, always returns false.
143
+ */
144
+ static VALUE ruby_curl_spnego_q(VALUE mod) {
145
+ #ifdef HAVE_CURL_VERSION_SPNEGO
146
+ curl_version_info_data *ver = curl_version_info(CURLVERSION_NOW);
147
+ return((ver->features & CURL_VERSION_SPNEGO) ? Qtrue : Qfalse);
148
+ #else
149
+ return Qfalse;
150
+ #endif
151
+ }
152
+
153
+ /*
154
+ * call-seq:
155
+ * Curl.largefile? => true or false
156
+ *
157
+ * Returns true if the installed libcurl was built with support for large
158
+ * files. For libcurl versions < 7.11.1, always returns false.
159
+ */
160
+ static VALUE ruby_curl_largefile_q(VALUE mod) {
161
+ #ifdef HAVE_CURL_VERSION_LARGEFILE
162
+ curl_version_info_data *ver = curl_version_info(CURLVERSION_NOW);
163
+ return((ver->features & CURL_VERSION_LARGEFILE) ? Qtrue : Qfalse);
164
+ #else
165
+ return Qfalse;
166
+ #endif
167
+ }
168
+
169
+ /*
170
+ * call-seq:
171
+ * Curl.idn? => true or false
172
+ *
173
+ * Returns true if the installed libcurl was built with support for IDNA,
174
+ * domain names with international letters. For libcurl versions < 7.12.0,
175
+ * always returns false.
176
+ */
177
+ static VALUE ruby_curl_idn_q(VALUE mod) {
178
+ #ifdef HAVE_CURL_VERSION_IDN
179
+ curl_version_info_data *ver = curl_version_info(CURLVERSION_NOW);
180
+ return((ver->features & CURL_VERSION_IDN) ? Qtrue : Qfalse);
181
+ #else
182
+ return Qfalse;
183
+ #endif
184
+ }
185
+
186
+ /*
187
+ * call-seq:
188
+ * Curl.sspi? => true or false
189
+ *
190
+ * Returns true if the installed libcurl was built with support for SSPI.
191
+ * This is only available on Windows and makes libcurl use Windows-provided
192
+ * functions for NTLM authentication. It also allows libcurl to use the current
193
+ * user and the current user's password without the app having to pass them on.
194
+ * For libcurl versions < 7.13.2, always returns false.
195
+ */
196
+ static VALUE ruby_curl_sspi_q(VALUE mod) {
197
+ #ifdef HAVE_CURL_VERSION_SSPI
198
+ curl_version_info_data *ver = curl_version_info(CURLVERSION_NOW);
199
+ return((ver->features & CURL_VERSION_SSPI) ? Qtrue : Qfalse);
200
+ #else
201
+ return Qfalse;
202
+ #endif
203
+ }
204
+
205
+ /*
206
+ * call-seq:
207
+ * Curl.conv? => true or false
208
+ *
209
+ * Returns true if the installed libcurl was built with support for character
210
+ * conversions. For libcurl versions < 7.15.4, always returns false.
211
+ */
212
+ static VALUE ruby_curl_conv_q(VALUE mod) {
213
+ #ifdef HAVE_CURL_VERSION_CONV
214
+ curl_version_info_data *ver = curl_version_info(CURLVERSION_NOW);
215
+ return((ver->features & CURL_VERSION_CONV) ? Qtrue : Qfalse);
216
+ #else
217
+ return Qfalse;
218
+ #endif
219
+ }
220
+
221
+ void Init_curb_core() {
222
+ // TODO we need to call curl_global_cleanup at exit!
223
+ curl_version_info_data *ver;
224
+ VALUE curlver, curllongver, curlvernum;
225
+
226
+ curl_global_init(CURL_GLOBAL_ALL);
227
+ ver = curl_version_info(CURLVERSION_NOW);
228
+
229
+ mCurl = rb_define_module("Curl");
230
+
231
+ curlver = rb_str_new2(ver->version);
232
+ curllongver = rb_str_new2(curl_version());
233
+ curlvernum = LONG2NUM(LIBCURL_VERSION_NUM);
234
+
235
+ rb_define_const(mCurl, "CURB_VERSION", rb_str_new2(CURB_VERSION));
236
+ rb_define_const(mCurl, "VERSION", curlver);
237
+ rb_define_const(mCurl, "CURL_VERSION", curlver);
238
+ rb_define_const(mCurl, "VERNUM", curlvernum);
239
+ rb_define_const(mCurl, "CURL_VERNUM", curlvernum);
240
+ rb_define_const(mCurl, "LONG_VERSION", curllongver);
241
+ rb_define_const(mCurl, "CURL_LONG_VERSION", curllongver);
242
+
243
+ /* Passed to on_debug handler to indicate that the data is informational text. */
244
+ rb_define_const(mCurl, "CURLINFO_TEXT", INT2FIX(CURLINFO_TEXT));
245
+
246
+ /* Passed to on_debug handler to indicate that the data is header (or header-like) data received from the peer. */
247
+ rb_define_const(mCurl, "CURLINFO_HEADER_IN", INT2FIX(CURLINFO_HEADER_IN));
248
+
249
+ /* Passed to on_debug handler to indicate that the data is header (or header-like) data sent to the peer. */
250
+ rb_define_const(mCurl, "CURLINFO_HEADER_OUT", INT2FIX(CURLINFO_HEADER_OUT));
251
+
252
+ /* Passed to on_debug handler to indicate that the data is protocol data received from the peer. */
253
+ rb_define_const(mCurl, "CURLINFO_DATA_IN", INT2FIX(CURLINFO_DATA_IN));
254
+
255
+ /* Passed to on_debug handler to indicate that the data is protocol data sent to the peer. */
256
+ rb_define_const(mCurl, "CURLINFO_DATA_OUT", INT2FIX(CURLINFO_DATA_OUT));
257
+
258
+ #ifdef HAVE_CURLFTPMETHOD_MULTICWD
259
+ rb_define_const(mCurl, "CURL_MULTICWD", INT2FIX(CURLFTPMETHOD_MULTICWD));
260
+ #endif
261
+
262
+ #ifdef HAVE_CURLFTPMETHOD_NOCWD
263
+ rb_define_const(mCurl, "CURL_NOCWD", INT2FIX(CURLFTPMETHOD_NOCWD));
264
+ #endif
265
+
266
+ #ifdef HAVE_CURLFTPMETHOD_SINGLECWD
267
+ rb_define_const(mCurl, "CURL_SINGLECWD", INT2FIX(CURLFTPMETHOD_SINGLECWD));
268
+ #endif
269
+
270
+ /* When passed to Curl::Easy#proxy_type , indicates that the proxy is an HTTP proxy. (libcurl >= 7.10) */
271
+ #ifdef HAVE_CURLPROXY_HTTP
272
+ rb_define_const(mCurl, "CURLPROXY_HTTP", INT2FIX(CURLPROXY_HTTP));
273
+ #else
274
+ rb_define_const(mCurl, "CURLPROXY_HTTP", INT2FIX(-1));
275
+ #endif
276
+
277
+ #ifdef CURL_VERSION_SSL
278
+ rb_define_const(mCurl, "CURL_SSLVERSION_DEFAULT", INT2FIX(CURL_SSLVERSION_DEFAULT));
279
+ rb_define_const(mCurl, "CURL_SSLVERSION_TLSv1", INT2FIX(CURL_SSLVERSION_TLSv1));
280
+ rb_define_const(mCurl, "CURL_SSLVERSION_SSLv2", INT2FIX(CURL_SSLVERSION_SSLv2));
281
+ rb_define_const(mCurl, "CURL_SSLVERSION_SSLv3", INT2FIX(CURL_SSLVERSION_SSLv3));
282
+
283
+ rb_define_const(mCurl, "CURL_USESSL_CONTROL", INT2FIX(CURB_FTPSSL_CONTROL));
284
+ rb_define_const(mCurl, "CURL_USESSL_NONE", INT2FIX(CURB_FTPSSL_NONE));
285
+ rb_define_const(mCurl, "CURL_USESSL_TRY", INT2FIX(CURB_FTPSSL_TRY));
286
+ rb_define_const(mCurl, "CURL_USESSL_ALL", INT2FIX(CURB_FTPSSL_ALL));
287
+ #else
288
+ rb_define_const(mCurl, "CURL_SSLVERSION_DEFAULT", INT2FIX(-1));
289
+ rb_define_const(mCurl, "CURL_SSLVERSION_TLSv1", INT2FIX(-1));
290
+ rb_define_const(mCurl, "CURL_SSLVERSION_SSLv2", INT2FIX(-1));
291
+ rb_define_const(mCurl, "CURL_SSLVERSION_SSLv3", INT2FIX(-1));
292
+
293
+ rb_define_const(mCurl, "CURL_USESSL_CONTROL", INT2FIX(-1));
294
+ rb_define_const(mCurl, "CURL_USESSL_NONE", INT2FIX(-1));
295
+ rb_define_const(mCurl, "CURL_USESSL_TRY", INT2FIX(-1));
296
+ rb_define_const(mCurl, "CURL_USESSL_ALL", INT2FIX(-1));
297
+ #endif
298
+
299
+ /* When passed to Curl::Easy#proxy_type , indicates that the proxy is a SOCKS4 proxy. (libcurl >= 7.15.2) */
300
+ #ifdef HAVE_CURLPROXY_SOCKS4
301
+ rb_define_const(mCurl, "CURLPROXY_SOCKS4", INT2FIX(CURLPROXY_SOCKS4));
302
+ #else
303
+ rb_define_const(mCurl, "CURLPROXY_SOCKS4", INT2FIX(-2));
304
+ #endif
305
+
306
+ /* When passed to Curl::Easy#proxy_type , indicates that the proxy is a SOCKS5 proxy. (libcurl >= 7.10) */
307
+ #ifdef HAVE_CURLPROXY_SOCKS5
308
+ rb_define_const(mCurl, "CURLPROXY_SOCKS5", INT2FIX(CURLPROXY_SOCKS5));
309
+ #else
310
+ rb_define_const(mCurl, "CURLPROXY_SOCKS5", INT2FIX(-2));
311
+ #endif
312
+
313
+ /* When passed to Curl::Easy#http_auth_types or Curl::Easy#proxy_auth_types, directs libcurl to use Basic authentication. */
314
+ #ifdef HAVE_CURLAUTH_BASIC
315
+ rb_define_const(mCurl, "CURLAUTH_BASIC", INT2FIX(CURLAUTH_BASIC));
316
+ #else
317
+ rb_define_const(mCurl, "CURLAUTH_BASIC", INT2FIX(0));
318
+ #endif
319
+
320
+ /* When passed to Curl::Easy#http_auth_types or Curl::Easy#proxy_auth_types, directs libcurl to use Digest authentication. */
321
+ #ifdef HAVE_CURLAUTH_DIGEST
322
+ rb_define_const(mCurl, "CURLAUTH_DIGEST", INT2FIX(CURLAUTH_DIGEST));
323
+ #else
324
+ rb_define_const(mCurl, "CURLAUTH_DIGEST", INT2FIX(0));
325
+ #endif
326
+
327
+ /* When passed to Curl::Easy#http_auth_types or Curl::Easy#proxy_auth_types, directs libcurl to use GSS Negotiate authentication. Requires a suitable GSS-API library. */
328
+ #ifdef HAVE_CURLAUTH_GSSNEGOTIATE
329
+ rb_define_const(mCurl, "CURLAUTH_GSSNEGOTIATE", INT2FIX(CURLAUTH_GSSNEGOTIATE));
330
+ #else
331
+ rb_define_const(mCurl, "CURLAUTH_GSSNEGOTIATE", INT2FIX(0));
332
+ #endif
333
+
334
+ /* When passed to Curl::Easy#http_auth_types or Curl::Easy#proxy_auth_types, directs libcurl to use HTTP NTLM authentication. Requires MS Windows or OpenSSL support. */
335
+ #ifdef HAVE_CURLAUTH_NTLM
336
+ rb_define_const(mCurl, "CURLAUTH_NTLM", INT2FIX(CURLAUTH_NTLM));
337
+ #else
338
+ rb_define_const(mCurl, "CURLAUTH_NTLM", INT2FIX(0));
339
+ #endif
340
+
341
+ /* When passed to Curl::Easy#http_auth_types or Curl::Easy#proxy_auth_types, allows libcurl to select any suitable authentication method except basic. */
342
+ #ifdef HAVE_CURLAUTH_ANYSAFE
343
+ rb_define_const(mCurl, "CURLAUTH_ANYSAFE", INT2FIX(CURLAUTH_ANYSAFE));
344
+ #else
345
+ rb_define_const(mCurl, "CURLAUTH_ANYSAFE", INT2FIX(0));
346
+ #endif
347
+
348
+ /* When passed to Curl::Easy#http_auth_types or Curl::Easy#proxy_auth_types, allows libcurl to select any suitable authentication method. */
349
+ #ifdef HAVE_CURLAUTH_ANY
350
+ rb_define_const(mCurl, "CURLAUTH_ANY", INT2FIX(CURLAUTH_ANY));
351
+ #else
352
+ rb_define_const(mCurl, "CURLAUTH_ANY", INT2FIX(0));
353
+ #endif
354
+
355
+ rb_define_singleton_method(mCurl, "ipv6?", ruby_curl_ipv6_q, 0);
356
+ rb_define_singleton_method(mCurl, "kerberos4?", ruby_curl_kerberos4_q, 0);
357
+ rb_define_singleton_method(mCurl, "ssl?", ruby_curl_ssl_q, 0);
358
+ rb_define_singleton_method(mCurl, "libz?", ruby_curl_libz_q, 0);
359
+ rb_define_singleton_method(mCurl, "ntlm?", ruby_curl_ntlm_q, 0);
360
+ rb_define_singleton_method(mCurl, "gssnegotiate?", ruby_curl_gssnegotiate_q, 0);
361
+ rb_define_singleton_method(mCurl, "debug?", ruby_curl_debug_q, 0);
362
+ rb_define_singleton_method(mCurl, "asyncdns?", ruby_curl_asyncdns_q, 0);
363
+ rb_define_singleton_method(mCurl, "spnego?", ruby_curl_spnego_q, 0);
364
+ rb_define_singleton_method(mCurl, "largefile?", ruby_curl_largefile_q, 0);
365
+ rb_define_singleton_method(mCurl, "idn?", ruby_curl_idn_q, 0);
366
+ rb_define_singleton_method(mCurl, "sspi?", ruby_curl_sspi_q, 0);
367
+ rb_define_singleton_method(mCurl, "conv?", ruby_curl_conv_q, 0);
368
+
369
+ init_curb_errors();
370
+ init_curb_easy();
371
+ init_curb_postfield();
372
+ init_curb_multi();
373
+ }
data/ext/curb.h ADDED
@@ -0,0 +1,52 @@
1
+ /* Curb - Libcurl(3) bindings for Ruby.
2
+ * Copyright (c)2006 Ross Bamford.
3
+ * Licensed under the Ruby License. See LICENSE for details.
4
+ *
5
+ * $Id: curb.h 39 2006-12-23 15:28:45Z roscopeco $
6
+ */
7
+
8
+ #ifndef __CURB_H
9
+ #define __CURB_H
10
+
11
+ #include <ruby.h>
12
+ #include <curl/curl.h>
13
+
14
+ #include "curb_config.h"
15
+ #include "curb_easy.h"
16
+ #include "curb_errors.h"
17
+ #include "curb_postfield.h"
18
+ #include "curb_multi.h"
19
+
20
+ #include "curb_macros.h"
21
+
22
+ // These should be managed from the Rake 'release' task.
23
+ #define CURB_VERSION "0.7.7"
24
+ #define CURB_VER_NUM 707
25
+ #define CURB_VER_MAJ 0
26
+ #define CURB_VER_MIN 7
27
+ #define CURB_VER_MIC 7
28
+ #define CURB_VER_PATCH 0
29
+
30
+
31
+ // Maybe not yet defined in Ruby
32
+ #ifndef RSTRING_LEN
33
+ #define RSTRING_LEN(x) RSTRING(x)->len
34
+ #endif
35
+
36
+ #ifndef RSTRING_PTR
37
+ #define RSTRING_PTR(x) RSTRING(x)->ptr
38
+ #endif
39
+
40
+ #ifndef RHASH_LEN
41
+ #ifdef HAVE_RUBY19_HASH
42
+ #define RHASH_LEN(hash) RHASH(hash)->ntbl->num_entries
43
+ #else
44
+ #define RHASH_LEN(hash) RHASH(hash)->tbl->num_entries
45
+ #endif
46
+ #endif
47
+
48
+ extern VALUE mCurl;
49
+
50
+ extern void Init_curb_core();
51
+
52
+ #endif