curb 0.7.15 → 0.7.18
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/README +4 -0
- data/Rakefile +7 -3
- data/ext/curb.c +600 -0
- data/ext/curb.h +3 -3
- data/ext/curb_easy.c +270 -386
- data/ext/curb_easy.h +1 -0
- data/ext/curb_errors.c +10 -0
- data/ext/curb_macros.h +4 -0
- data/ext/curb_multi.c +58 -12
- data/ext/extconf.rb +223 -3
- data/lib/curb.rb +2 -307
- data/lib/curl/easy.rb +385 -0
- data/lib/curl/multi.rb +244 -0
- data/tests/bug_crash_on_progress.rb +33 -0
- data/tests/tc_curl_download.rb +4 -4
- data/tests/tc_curl_easy.rb +74 -8
- data/tests/tc_curl_easy_setopt.rb +31 -0
- metadata +31 -41
data/ext/curb_easy.c
CHANGED
|
@@ -28,6 +28,10 @@ VALUE cCurlEasy;
|
|
|
28
28
|
|
|
29
29
|
/* ================== CURL HANDLER FUNCS ==============*/
|
|
30
30
|
|
|
31
|
+
static VALUE callback_exception(VALUE unused) {
|
|
32
|
+
return Qfalse;
|
|
33
|
+
}
|
|
34
|
+
|
|
31
35
|
/* These handle both body and header data */
|
|
32
36
|
static size_t default_data_handler(char *stream,
|
|
33
37
|
size_t size,
|
|
@@ -111,27 +115,56 @@ static size_t proc_data_handler(char *stream,
|
|
|
111
115
|
}
|
|
112
116
|
}
|
|
113
117
|
|
|
118
|
+
static VALUE call_progress_handler(VALUE ary) {
|
|
119
|
+
return rb_funcall(rb_ary_entry(ary, 0), idCall, 4,
|
|
120
|
+
rb_ary_entry(ary, 1), // rb_float_new(dltotal),
|
|
121
|
+
rb_ary_entry(ary, 2), // rb_float_new(dlnow),
|
|
122
|
+
rb_ary_entry(ary, 3), // rb_float_new(ultotal),
|
|
123
|
+
rb_ary_entry(ary, 4)); // rb_float_new(ulnow));
|
|
124
|
+
}
|
|
125
|
+
|
|
114
126
|
static int proc_progress_handler(VALUE proc,
|
|
115
127
|
double dltotal,
|
|
116
128
|
double dlnow,
|
|
117
129
|
double ultotal,
|
|
118
130
|
double ulnow) {
|
|
119
131
|
VALUE procret;
|
|
132
|
+
VALUE callargs = rb_ary_new2(5);
|
|
133
|
+
|
|
134
|
+
rb_ary_store(callargs, 0, proc);
|
|
135
|
+
rb_ary_store(callargs, 1, rb_float_new(dltotal));
|
|
136
|
+
rb_ary_store(callargs, 2, rb_float_new(dlnow));
|
|
137
|
+
rb_ary_store(callargs, 3, rb_float_new(ultotal));
|
|
138
|
+
rb_ary_store(callargs, 4, rb_float_new(ulnow));
|
|
120
139
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
140
|
+
//v = rb_rescue(range_check, (VALUE)args, range_failed, 0);
|
|
141
|
+
//procret = rb_funcall(proc, idCall, 4, rb_float_new(dltotal),
|
|
142
|
+
// rb_float_new(dlnow),
|
|
143
|
+
// rb_float_new(ultotal),
|
|
144
|
+
// rb_float_new(ulnow));
|
|
145
|
+
procret = rb_rescue(call_progress_handler, callargs, callback_exception, Qnil);
|
|
125
146
|
|
|
126
147
|
return(((procret == Qfalse) || (procret == Qnil)) ? -1 : 0);
|
|
127
148
|
}
|
|
128
149
|
|
|
150
|
+
static VALUE call_debug_handler(VALUE ary) {
|
|
151
|
+
return rb_funcall(rb_ary_entry(ary, 0), idCall, 2,
|
|
152
|
+
rb_ary_entry(ary, 1), // INT2FIX(type),
|
|
153
|
+
rb_ary_entry(ary, 2)); // rb_str_new(data, data_len)
|
|
154
|
+
}
|
|
129
155
|
static int proc_debug_handler(CURL *curl,
|
|
130
156
|
curl_infotype type,
|
|
131
157
|
char *data,
|
|
132
158
|
size_t data_len,
|
|
133
159
|
VALUE proc) {
|
|
134
|
-
|
|
160
|
+
VALUE procret;
|
|
161
|
+
VALUE callargs = rb_ary_new2(3);
|
|
162
|
+
rb_ary_store(callargs, 0, proc);
|
|
163
|
+
rb_ary_store(callargs, 1, INT2FIX(type));
|
|
164
|
+
rb_ary_store(callargs, 2, rb_str_new(data, data_len));
|
|
165
|
+
rb_rescue(call_debug_handler, callargs, callback_exception, Qnil);
|
|
166
|
+
// XXX: no way to indicate to libcurl that we should break out given an exception in the on_debug handler... this means exceptions will be swallowed
|
|
167
|
+
//rb_funcall(proc, idCall, 2, INT2FIX(type), rb_str_new(data, data_len));
|
|
135
168
|
return 0;
|
|
136
169
|
}
|
|
137
170
|
|
|
@@ -191,7 +224,7 @@ static void ruby_curl_easy_zero(ruby_curl_easy *rbce) {
|
|
|
191
224
|
rbce->proxy_tunnel = 0;
|
|
192
225
|
rbce->fetch_file_time = 0;
|
|
193
226
|
rbce->ssl_verify_peer = 1;
|
|
194
|
-
rbce->ssl_verify_host =
|
|
227
|
+
rbce->ssl_verify_host = 2;
|
|
195
228
|
rbce->header_in_body = 0;
|
|
196
229
|
rbce->use_netrc = 0;
|
|
197
230
|
rbce->follow_location = 0;
|
|
@@ -347,18 +380,6 @@ static VALUE ruby_curl_easy_reset(VALUE self) {
|
|
|
347
380
|
|
|
348
381
|
/* ================ OBJ ATTRIBUTES ==================*/
|
|
349
382
|
|
|
350
|
-
/*
|
|
351
|
-
* call-seq:
|
|
352
|
-
* easy.url = "http://some.url/" => "http://some.url/"
|
|
353
|
-
*
|
|
354
|
-
* Set the URL for subsequent calls to +perform+. It is acceptable
|
|
355
|
-
* (and even recommended) to reuse Curl::Easy instances by reassigning
|
|
356
|
-
* the URL between calls to +perform+.
|
|
357
|
-
*/
|
|
358
|
-
static VALUE ruby_curl_easy_url_set(VALUE self, VALUE url) {
|
|
359
|
-
CURB_OBJECT_HSETTER(ruby_curl_easy, url);
|
|
360
|
-
}
|
|
361
|
-
|
|
362
383
|
/*
|
|
363
384
|
* call-seq:
|
|
364
385
|
* easy.url => string
|
|
@@ -369,35 +390,6 @@ static VALUE ruby_curl_easy_url_get(VALUE self) {
|
|
|
369
390
|
CURB_OBJECT_HGETTER(ruby_curl_easy, url);
|
|
370
391
|
}
|
|
371
392
|
|
|
372
|
-
/*
|
|
373
|
-
* call-seq:
|
|
374
|
-
* easy.proxy_url = string => string
|
|
375
|
-
*
|
|
376
|
-
* Set the URL of the HTTP proxy to use for subsequent calls to +perform+.
|
|
377
|
-
* The URL should specify the the host name or dotted IP address. To specify
|
|
378
|
-
* port number in this string, append :[port] to the end of the host name.
|
|
379
|
-
* The proxy string may be prefixed with [protocol]:// since any such prefix
|
|
380
|
-
* will be ignored. The proxy's port number may optionally be specified with
|
|
381
|
-
* the separate option proxy_port .
|
|
382
|
-
*
|
|
383
|
-
* When you tell the library to use an HTTP proxy, libcurl will transparently
|
|
384
|
-
* convert operations to HTTP even if you specify an FTP URL etc. This may have
|
|
385
|
-
* an impact on what other features of the library you can use, such as
|
|
386
|
-
* FTP specifics that don't work unless you tunnel through the HTTP proxy. Such
|
|
387
|
-
* tunneling is activated with proxy_tunnel = true.
|
|
388
|
-
*
|
|
389
|
-
* libcurl respects the environment variables *http_proxy*, *ftp_proxy*,
|
|
390
|
-
* *all_proxy* etc, if any of those is set. The proxy_url option does however
|
|
391
|
-
* override any possibly set environment variables.
|
|
392
|
-
*
|
|
393
|
-
* Starting with libcurl 7.14.1, the proxy host string given in environment
|
|
394
|
-
* variables can be specified the exact same way as the proxy can be set with
|
|
395
|
-
* proxy_url, including protocol prefix (http://) and embedded user + password.
|
|
396
|
-
*/
|
|
397
|
-
static VALUE ruby_curl_easy_proxy_url_set(VALUE self, VALUE proxy_url) {
|
|
398
|
-
CURB_OBJECT_HSETTER(ruby_curl_easy, proxy_url);
|
|
399
|
-
}
|
|
400
|
-
|
|
401
393
|
/*
|
|
402
394
|
* call-seq:
|
|
403
395
|
* easy.proxy_url => string
|
|
@@ -449,17 +441,6 @@ static VALUE ruby_curl_easy_headers_get(VALUE self) {
|
|
|
449
441
|
return headers;
|
|
450
442
|
}
|
|
451
443
|
|
|
452
|
-
/*
|
|
453
|
-
* call-seq:
|
|
454
|
-
* easy.interface = string => string
|
|
455
|
-
*
|
|
456
|
-
* Set the interface name to use as the outgoing network interface.
|
|
457
|
-
* The name can be an interface name, an IP address or a host name.
|
|
458
|
-
*/
|
|
459
|
-
static VALUE ruby_curl_easy_interface_set(VALUE self, VALUE interface_hm) {
|
|
460
|
-
CURB_OBJECT_HSETTER(ruby_curl_easy, interface_hm);
|
|
461
|
-
}
|
|
462
|
-
|
|
463
444
|
/*
|
|
464
445
|
* call-seq:
|
|
465
446
|
* easy.interface => string
|
|
@@ -471,17 +452,6 @@ static VALUE ruby_curl_easy_interface_get(VALUE self) {
|
|
|
471
452
|
CURB_OBJECT_HGETTER(ruby_curl_easy, interface_hm);
|
|
472
453
|
}
|
|
473
454
|
|
|
474
|
-
/*
|
|
475
|
-
* call-seq:
|
|
476
|
-
* easy.userpwd = string => string
|
|
477
|
-
*
|
|
478
|
-
* Set the username/password string to use for subsequent calls to +perform+.
|
|
479
|
-
* The supplied string should have the form "username:password"
|
|
480
|
-
*/
|
|
481
|
-
static VALUE ruby_curl_easy_userpwd_set(VALUE self, VALUE userpwd) {
|
|
482
|
-
CURB_OBJECT_HSETTER(ruby_curl_easy, userpwd);
|
|
483
|
-
}
|
|
484
|
-
|
|
485
455
|
/*
|
|
486
456
|
* call-seq:
|
|
487
457
|
* easy.userpwd => string
|
|
@@ -493,18 +463,6 @@ static VALUE ruby_curl_easy_userpwd_get(VALUE self) {
|
|
|
493
463
|
CURB_OBJECT_HGETTER(ruby_curl_easy, userpwd);
|
|
494
464
|
}
|
|
495
465
|
|
|
496
|
-
/*
|
|
497
|
-
* call-seq:
|
|
498
|
-
* easy.proxypwd = string => string
|
|
499
|
-
*
|
|
500
|
-
* Set the username/password string to use for proxy connection during
|
|
501
|
-
* subsequent calls to +perform+. The supplied string should have the
|
|
502
|
-
* form "username:password"
|
|
503
|
-
*/
|
|
504
|
-
static VALUE ruby_curl_easy_proxypwd_set(VALUE self, VALUE proxypwd) {
|
|
505
|
-
CURB_OBJECT_HSETTER(ruby_curl_easy, proxypwd);
|
|
506
|
-
}
|
|
507
|
-
|
|
508
466
|
/*
|
|
509
467
|
* call-seq:
|
|
510
468
|
* easy.proxypwd => string
|
|
@@ -517,19 +475,6 @@ static VALUE ruby_curl_easy_proxypwd_get(VALUE self) {
|
|
|
517
475
|
CURB_OBJECT_HGETTER(ruby_curl_easy, proxypwd);
|
|
518
476
|
}
|
|
519
477
|
|
|
520
|
-
|
|
521
|
-
/*
|
|
522
|
-
* call-seq:
|
|
523
|
-
* easy.cookies = "name1=content1; name2=content2;" => string
|
|
524
|
-
*
|
|
525
|
-
* Set cookies to be sent by this Curl::Easy instance. The format of the string should
|
|
526
|
-
* be NAME=CONTENTS, where NAME is the cookie name and CONTENTS is what the cookie should contain.
|
|
527
|
-
* Set multiple cookies in one string like this: "name1=content1; name2=content2;" etc.
|
|
528
|
-
*/
|
|
529
|
-
static VALUE ruby_curl_easy_cookies_set(VALUE self, VALUE cookies) {
|
|
530
|
-
CURB_OBJECT_HSETTER(ruby_curl_easy, cookies);
|
|
531
|
-
}
|
|
532
|
-
|
|
533
478
|
/*
|
|
534
479
|
* call-seq:
|
|
535
480
|
* easy.cookies => "name1=content1; name2=content2;"
|
|
@@ -540,19 +485,6 @@ static VALUE ruby_curl_easy_cookies_get(VALUE self) {
|
|
|
540
485
|
CURB_OBJECT_HGETTER(ruby_curl_easy, cookies);
|
|
541
486
|
}
|
|
542
487
|
|
|
543
|
-
/*
|
|
544
|
-
* call-seq:
|
|
545
|
-
* easy.cookiefile = string => string
|
|
546
|
-
*
|
|
547
|
-
* Set a file that contains cookies to be sent in subsequent requests by this Curl::Easy instance.
|
|
548
|
-
*
|
|
549
|
-
* *Note* that you must set enable_cookies true to enable the cookie
|
|
550
|
-
* engine, or this option will be ignored.
|
|
551
|
-
*/
|
|
552
|
-
static VALUE ruby_curl_easy_cookiefile_set(VALUE self, VALUE cookiefile) {
|
|
553
|
-
CURB_OBJECT_HSETTER(ruby_curl_easy, cookiefile);
|
|
554
|
-
}
|
|
555
|
-
|
|
556
488
|
/*
|
|
557
489
|
* call-seq:
|
|
558
490
|
* easy.cookiefile => string
|
|
@@ -563,20 +495,6 @@ static VALUE ruby_curl_easy_cookiefile_get(VALUE self) {
|
|
|
563
495
|
CURB_OBJECT_HGETTER(ruby_curl_easy, cookiefile);
|
|
564
496
|
}
|
|
565
497
|
|
|
566
|
-
/*
|
|
567
|
-
* call-seq:
|
|
568
|
-
* easy.cookiejar = string => string
|
|
569
|
-
*
|
|
570
|
-
* Set a cookiejar file to use for this Curl::Easy instance.
|
|
571
|
-
* Cookies from the response will be written into this file.
|
|
572
|
-
*
|
|
573
|
-
* *Note* that you must set enable_cookies true to enable the cookie
|
|
574
|
-
* engine, or this option will be ignored.
|
|
575
|
-
*/
|
|
576
|
-
static VALUE ruby_curl_easy_cookiejar_set(VALUE self, VALUE cookiejar) {
|
|
577
|
-
CURB_OBJECT_HSETTER(ruby_curl_easy, cookiejar);
|
|
578
|
-
}
|
|
579
|
-
|
|
580
498
|
/*
|
|
581
499
|
* call-seq:
|
|
582
500
|
* easy.cookiejar => string
|
|
@@ -1453,7 +1371,7 @@ static VALUE ruby_curl_easy_ssl_verify_peer_q(VALUE self) {
|
|
|
1453
1371
|
|
|
1454
1372
|
/*
|
|
1455
1373
|
* call-seq:
|
|
1456
|
-
* easy.ssl_verify_host =
|
|
1374
|
+
* easy.ssl_verify_host = [0, 1, 2] => [0, 1, 2]
|
|
1457
1375
|
*
|
|
1458
1376
|
* Configure whether this Curl instance will verify that the server cert
|
|
1459
1377
|
* is for the server it is known as. When true (the default) the server
|
|
@@ -1465,18 +1383,18 @@ static VALUE ruby_curl_easy_ssl_verify_peer_q(VALUE self) {
|
|
|
1465
1383
|
* The server could be lying. To control lying, see ssl_verify_peer? .
|
|
1466
1384
|
*/
|
|
1467
1385
|
static VALUE ruby_curl_easy_ssl_verify_host_set(VALUE self, VALUE ssl_verify_host) {
|
|
1468
|
-
|
|
1386
|
+
CURB_IMMED_SETTER(ruby_curl_easy, ssl_verify_host, 0);
|
|
1469
1387
|
}
|
|
1470
1388
|
|
|
1471
1389
|
/*
|
|
1472
1390
|
* call-seq:
|
|
1473
|
-
* easy.ssl_verify_host
|
|
1391
|
+
* easy.ssl_verify_host => number
|
|
1474
1392
|
*
|
|
1475
1393
|
* Determine whether this Curl instance will verify that the server cert
|
|
1476
1394
|
* is for the server it is known as.
|
|
1477
1395
|
*/
|
|
1478
|
-
static VALUE
|
|
1479
|
-
|
|
1396
|
+
static VALUE ruby_curl_easy_ssl_verify_host_get(VALUE self) {
|
|
1397
|
+
CURB_IMMED_GETTER(ruby_curl_easy, ssl_verify_host, 0);
|
|
1480
1398
|
}
|
|
1481
1399
|
|
|
1482
1400
|
/*
|
|
@@ -1685,6 +1603,65 @@ static VALUE ruby_curl_easy_ignore_content_length_q(VALUE self) {
|
|
|
1685
1603
|
CURB_BOOLEAN_GETTER(ruby_curl_easy, ignore_content_length);
|
|
1686
1604
|
}
|
|
1687
1605
|
|
|
1606
|
+
/*
|
|
1607
|
+
* call-seq:
|
|
1608
|
+
* easy.resolve_mode => symbol
|
|
1609
|
+
*
|
|
1610
|
+
* Determines what type of IP address this Curl::Easy instance
|
|
1611
|
+
* resolves DNS names to.
|
|
1612
|
+
*/
|
|
1613
|
+
static VALUE ruby_curl_easy_resolve_mode(VALUE self) {
|
|
1614
|
+
ruby_curl_easy *rbce;
|
|
1615
|
+
Data_Get_Struct(self, ruby_curl_easy, rbce);
|
|
1616
|
+
|
|
1617
|
+
unsigned short rm = rbce->resolve_mode;
|
|
1618
|
+
|
|
1619
|
+
switch(rm) {
|
|
1620
|
+
case CURL_IPRESOLVE_V4:
|
|
1621
|
+
return rb_easy_sym("ipv4");
|
|
1622
|
+
case CURL_IPRESOLVE_V6:
|
|
1623
|
+
return rb_easy_sym("ipv6");
|
|
1624
|
+
default:
|
|
1625
|
+
return rb_easy_sym("auto");
|
|
1626
|
+
}
|
|
1627
|
+
}
|
|
1628
|
+
|
|
1629
|
+
/*
|
|
1630
|
+
* call-seq:
|
|
1631
|
+
* easy.resolve_mode = symbol => symbol
|
|
1632
|
+
*
|
|
1633
|
+
* Configures what type of IP address this Curl::Easy instance
|
|
1634
|
+
* resolves DNS names to. Valid options are:
|
|
1635
|
+
*
|
|
1636
|
+
* [:auto] resolves DNS names to all IP versions your system allows
|
|
1637
|
+
* [:ipv4] resolves DNS names to IPv4 only
|
|
1638
|
+
* [:ipv6] resolves DNS names to IPv6 only
|
|
1639
|
+
*/
|
|
1640
|
+
static VALUE ruby_curl_easy_resolve_mode_set(VALUE self, VALUE resolve_mode) {
|
|
1641
|
+
if (TYPE(resolve_mode) != T_SYMBOL) {
|
|
1642
|
+
rb_raise(rb_eTypeError, "Must pass a symbol");
|
|
1643
|
+
return Qnil;
|
|
1644
|
+
} else {
|
|
1645
|
+
ruby_curl_easy *rbce;
|
|
1646
|
+
Data_Get_Struct(self, ruby_curl_easy, rbce);
|
|
1647
|
+
|
|
1648
|
+
ID resolve_mode_id = rb_to_id(resolve_mode);
|
|
1649
|
+
|
|
1650
|
+
if (resolve_mode_id == rb_intern("auto")) {
|
|
1651
|
+
rbce->resolve_mode = CURL_IPRESOLVE_WHATEVER;
|
|
1652
|
+
return resolve_mode;
|
|
1653
|
+
} else if (resolve_mode_id == rb_intern("ipv4")) {
|
|
1654
|
+
rbce->resolve_mode = CURL_IPRESOLVE_V4;
|
|
1655
|
+
return resolve_mode;
|
|
1656
|
+
} else if (resolve_mode_id == rb_intern("ipv6")) {
|
|
1657
|
+
rbce->resolve_mode = CURL_IPRESOLVE_V6;
|
|
1658
|
+
return resolve_mode;
|
|
1659
|
+
} else {
|
|
1660
|
+
rb_raise(rb_eArgError, "Must set to one of :auto, :ipv4, :ipv6");
|
|
1661
|
+
return Qnil;
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1688
1665
|
|
|
1689
1666
|
|
|
1690
1667
|
/* ================= EVENT PROCS ================== */
|
|
@@ -1816,7 +1793,10 @@ static VALUE ruby_curl_easy_on_debug_set(int argc, VALUE *argv, VALUE self) {
|
|
|
1816
1793
|
/***********************************************
|
|
1817
1794
|
* This is an rb_iterate callback used to set up http headers.
|
|
1818
1795
|
*/
|
|
1819
|
-
static VALUE cb_each_http_header(VALUE header,
|
|
1796
|
+
static VALUE cb_each_http_header(VALUE header, VALUE wrap) {
|
|
1797
|
+
struct curl_slist **list;
|
|
1798
|
+
Data_Get_Struct(wrap, struct curl_slist *, list);
|
|
1799
|
+
|
|
1820
1800
|
VALUE header_str = Qnil;
|
|
1821
1801
|
|
|
1822
1802
|
//rb_p(header);
|
|
@@ -1845,7 +1825,10 @@ static VALUE cb_each_http_header(VALUE header, struct curl_slist **list) {
|
|
|
1845
1825
|
/***********************************************
|
|
1846
1826
|
* This is an rb_iterate callback used to set up ftp commands.
|
|
1847
1827
|
*/
|
|
1848
|
-
static VALUE cb_each_ftp_command(VALUE ftp_command,
|
|
1828
|
+
static VALUE cb_each_ftp_command(VALUE ftp_command, VALUE wrap) {
|
|
1829
|
+
struct curl_slist **list;
|
|
1830
|
+
Data_Get_Struct(wrap, struct curl_slist *, list);
|
|
1831
|
+
|
|
1849
1832
|
VALUE ftp_command_string = rb_obj_as_string(ftp_command);
|
|
1850
1833
|
*list = curl_slist_append(*list, StringValuePtr(ftp_command));
|
|
1851
1834
|
|
|
@@ -1976,12 +1959,12 @@ VALUE ruby_curl_easy_setup( ruby_curl_easy *rbce ) {
|
|
|
1976
1959
|
curl_easy_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, rbce->proxy_tunnel);
|
|
1977
1960
|
curl_easy_setopt(curl, CURLOPT_FILETIME, rbce->fetch_file_time);
|
|
1978
1961
|
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, rbce->ssl_verify_peer);
|
|
1979
|
-
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, rbce->
|
|
1962
|
+
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, rbce->ssl_verify_host);
|
|
1980
1963
|
|
|
1981
1964
|
if ((rbce->use_netrc != Qnil) && (rbce->use_netrc != Qfalse)) {
|
|
1982
|
-
curl_easy_setopt(curl,
|
|
1965
|
+
curl_easy_setopt(curl, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
|
|
1983
1966
|
} else {
|
|
1984
|
-
curl_easy_setopt(curl,
|
|
1967
|
+
curl_easy_setopt(curl, CURLOPT_NETRC, CURL_NETRC_IGNORED);
|
|
1985
1968
|
}
|
|
1986
1969
|
|
|
1987
1970
|
curl_easy_setopt(curl, CURLOPT_UNRESTRICTED_AUTH, rbce->unrestricted_auth);
|
|
@@ -1992,6 +1975,8 @@ VALUE ruby_curl_easy_setup( ruby_curl_easy *rbce ) {
|
|
|
1992
1975
|
|
|
1993
1976
|
curl_easy_setopt(curl, CURLOPT_IGNORE_CONTENT_LENGTH, rbce->ignore_content_length);
|
|
1994
1977
|
|
|
1978
|
+
curl_easy_setopt(curl, CURLOPT_IPRESOLVE, rbce->resolve_mode);
|
|
1979
|
+
|
|
1995
1980
|
|
|
1996
1981
|
#if LIBCURL_VERSION_NUM >= 0x070a08
|
|
1997
1982
|
curl_easy_setopt(curl, CURLOPT_FTP_RESPONSE_TIMEOUT, rbce->ftp_response_timeout);
|
|
@@ -2077,7 +2062,9 @@ VALUE ruby_curl_easy_setup( ruby_curl_easy *rbce ) {
|
|
|
2077
2062
|
|
|
2078
2063
|
/* Set up HTTPS cert handling if necessary */
|
|
2079
2064
|
if (!rb_easy_nil("cert")) {
|
|
2080
|
-
|
|
2065
|
+
if (!rb_easy_nil("certtype")) {
|
|
2066
|
+
curl_easy_setopt(curl, CURLOPT_SSLCERTTYPE, rb_easy_get_str("certtype"));
|
|
2067
|
+
}
|
|
2081
2068
|
curl_easy_setopt(curl, CURLOPT_SSLCERT, rb_easy_get_str("cert"));
|
|
2082
2069
|
if (!rb_easy_nil("certpassword")) {
|
|
2083
2070
|
curl_easy_setopt(curl, CURLOPT_SSLCERTPASSWD, rb_easy_get_str("certpassword"));
|
|
@@ -2086,13 +2073,15 @@ VALUE ruby_curl_easy_setup( ruby_curl_easy *rbce ) {
|
|
|
2086
2073
|
curl_easy_setopt(curl, CURLOPT_SSLKEY, rb_easy_get_str("cert_key"));
|
|
2087
2074
|
}
|
|
2088
2075
|
}
|
|
2076
|
+
|
|
2089
2077
|
if (!rb_easy_nil("cacert")) {
|
|
2078
|
+
curl_easy_setopt(curl, CURLOPT_CAINFO, rb_easy_get_str("cacert"));
|
|
2079
|
+
}
|
|
2090
2080
|
#ifdef HAVE_CURL_CONFIG_CA
|
|
2081
|
+
else {
|
|
2091
2082
|
curl_easy_setopt(curl, CURLOPT_CAINFO, CURL_CONFIG_CA);
|
|
2092
|
-
#else
|
|
2093
|
-
curl_easy_setopt(curl, CURLOPT_CAINFO, "/usr/local/share/curl/curl-ca-bundle.crt");
|
|
2094
|
-
#endif
|
|
2095
2083
|
}
|
|
2084
|
+
#endif
|
|
2096
2085
|
|
|
2097
2086
|
#ifdef CURL_VERSION_SSL
|
|
2098
2087
|
if (rbce->ssl_version > 0) {
|
|
@@ -2122,7 +2111,8 @@ VALUE ruby_curl_easy_setup( ruby_curl_easy *rbce ) {
|
|
|
2122
2111
|
|
|
2123
2112
|
if (!rb_easy_nil("headers")) {
|
|
2124
2113
|
if (rb_easy_type_check("headers", T_ARRAY) || rb_easy_type_check("headers", T_HASH)) {
|
|
2125
|
-
|
|
2114
|
+
VALUE wrap = Data_Wrap_Struct(rb_cObject, 0, 0, hdrs);
|
|
2115
|
+
rb_iterate(rb_each, rb_easy_get("headers"), cb_each_http_header, wrap);
|
|
2126
2116
|
} else {
|
|
2127
2117
|
VALUE headers_str = rb_obj_as_string(rb_easy_get("headers"));
|
|
2128
2118
|
*hdrs = curl_slist_append(*hdrs, StringValuePtr(headers_str));
|
|
@@ -2136,7 +2126,8 @@ VALUE ruby_curl_easy_setup( ruby_curl_easy *rbce ) {
|
|
|
2136
2126
|
/* Setup FTP commands if necessary */
|
|
2137
2127
|
if (!rb_easy_nil("ftp_commands")) {
|
|
2138
2128
|
if (rb_easy_type_check("ftp_commands", T_ARRAY)) {
|
|
2139
|
-
|
|
2129
|
+
VALUE wrap = Data_Wrap_Struct(rb_cObject, 0, 0, cmds);
|
|
2130
|
+
rb_iterate(rb_each, rb_easy_get("ftp_commands"), cb_each_ftp_command, wrap);
|
|
2140
2131
|
}
|
|
2141
2132
|
|
|
2142
2133
|
if (*cmds) {
|
|
@@ -2181,35 +2172,6 @@ VALUE ruby_curl_easy_cleanup( VALUE self, ruby_curl_easy *rbce ) {
|
|
|
2181
2172
|
return Qnil;
|
|
2182
2173
|
}
|
|
2183
2174
|
|
|
2184
|
-
/***********************************************
|
|
2185
|
-
*
|
|
2186
|
-
* This is the main worker for the perform methods (get, post, head, put).
|
|
2187
|
-
* It's not surfaced as a Ruby method - instead, the individual request
|
|
2188
|
-
* methods are responsible for setting up stuff specific to that type,
|
|
2189
|
-
* then calling this to handle common stuff and do the perform.
|
|
2190
|
-
*
|
|
2191
|
-
* Always returns Qtrue, rb_raise on error.
|
|
2192
|
-
*
|
|
2193
|
-
*/
|
|
2194
|
-
static VALUE handle_perform(VALUE self, ruby_curl_easy *rbce) {
|
|
2195
|
-
|
|
2196
|
-
VALUE ret;
|
|
2197
|
-
|
|
2198
|
-
/* reuse existing multi handle for this easy handle */
|
|
2199
|
-
if (NIL_P(rbce->multi)) {
|
|
2200
|
-
rbce->multi = ruby_curl_multi_new(cCurlMulti);
|
|
2201
|
-
}
|
|
2202
|
-
rb_funcall(rbce->multi, rb_intern("add"), 1, self );
|
|
2203
|
-
ret = rb_funcall(rbce->multi, rb_intern("perform"), 0);
|
|
2204
|
-
|
|
2205
|
-
/* check for errors in the easy response and raise exceptions if anything went wrong and their is no on_failure handler */
|
|
2206
|
-
if (rbce->last_result != 0 && rb_easy_nil("failure_proc")) {
|
|
2207
|
-
raise_curl_easy_error_exception(rbce->last_result);
|
|
2208
|
-
}
|
|
2209
|
-
|
|
2210
|
-
return ret;
|
|
2211
|
-
}
|
|
2212
|
-
|
|
2213
2175
|
/*
|
|
2214
2176
|
* call-seq:
|
|
2215
2177
|
* easy.http_get => true
|
|
@@ -2228,7 +2190,7 @@ static VALUE ruby_curl_easy_perform_get(VALUE self) {
|
|
|
2228
2190
|
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, NULL);
|
|
2229
2191
|
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
|
|
2230
2192
|
|
|
2231
|
-
return
|
|
2193
|
+
return rb_funcall(self, rb_intern("perform"), 0);
|
|
2232
2194
|
}
|
|
2233
2195
|
|
|
2234
2196
|
/*
|
|
@@ -2244,7 +2206,7 @@ static VALUE ruby_curl_easy_perform_verb_str(VALUE self, const char *verb) {
|
|
|
2244
2206
|
|
|
2245
2207
|
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, verb);
|
|
2246
2208
|
|
|
2247
|
-
retval =
|
|
2209
|
+
retval = rb_funcall(self, rb_intern("perform"), 0);
|
|
2248
2210
|
|
|
2249
2211
|
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, NULL);
|
|
2250
2212
|
|
|
@@ -2273,33 +2235,17 @@ static VALUE ruby_curl_easy_perform_delete(VALUE self) {
|
|
|
2273
2235
|
static VALUE ruby_curl_easy_perform_verb(VALUE self, VALUE verb) {
|
|
2274
2236
|
VALUE str_verb;
|
|
2275
2237
|
if (rb_type(verb) == T_STRING) {
|
|
2276
|
-
return ruby_curl_easy_perform_verb_str(self,
|
|
2238
|
+
return ruby_curl_easy_perform_verb_str(self, StringValueCStr(verb));
|
|
2277
2239
|
}
|
|
2278
2240
|
else if (rb_respond_to(verb,rb_intern("to_s"))) {
|
|
2279
2241
|
str_verb = rb_funcall(verb, rb_intern("to_s"), 0);
|
|
2280
|
-
return ruby_curl_easy_perform_verb_str(self,
|
|
2242
|
+
return ruby_curl_easy_perform_verb_str(self, StringValueCStr(str_verb));
|
|
2281
2243
|
}
|
|
2282
2244
|
else {
|
|
2283
2245
|
rb_raise(rb_eRuntimeError, "Invalid HTTP VERB, must response to 'to_s'");
|
|
2284
2246
|
}
|
|
2285
2247
|
}
|
|
2286
2248
|
|
|
2287
|
-
/*
|
|
2288
|
-
* call-seq:
|
|
2289
|
-
* easy.perform => true
|
|
2290
|
-
*
|
|
2291
|
-
* Transfer the currently configured URL using the options set for this
|
|
2292
|
-
* Curl::Easy instance. If this is an HTTP URL, it will be transferred via
|
|
2293
|
-
* the GET or HEAD request method.
|
|
2294
|
-
*/
|
|
2295
|
-
static VALUE ruby_curl_easy_perform(VALUE self) {
|
|
2296
|
-
ruby_curl_easy *rbce;
|
|
2297
|
-
|
|
2298
|
-
Data_Get_Struct(self, ruby_curl_easy, rbce);
|
|
2299
|
-
|
|
2300
|
-
return handle_perform(self,rbce);
|
|
2301
|
-
}
|
|
2302
|
-
|
|
2303
2249
|
/*
|
|
2304
2250
|
* call-seq:
|
|
2305
2251
|
* easy.http_post("url=encoded%20form%20data;and=so%20on") => true
|
|
@@ -2353,7 +2299,7 @@ static VALUE ruby_curl_easy_perform_post(int argc, VALUE *argv, VALUE self) {
|
|
|
2353
2299
|
|
|
2354
2300
|
curl_easy_setopt(curl, CURLOPT_POST, 0);
|
|
2355
2301
|
curl_easy_setopt(curl, CURLOPT_HTTPPOST, first);
|
|
2356
|
-
ret =
|
|
2302
|
+
ret = rb_funcall(self, rb_intern("perform"), 0);
|
|
2357
2303
|
curl_formfree(first);
|
|
2358
2304
|
|
|
2359
2305
|
return ret;
|
|
@@ -2375,7 +2321,7 @@ static VALUE ruby_curl_easy_perform_post(int argc, VALUE *argv, VALUE self) {
|
|
|
2375
2321
|
ruby_curl_easy_post_body_set(self, post_body);
|
|
2376
2322
|
}
|
|
2377
2323
|
|
|
2378
|
-
return
|
|
2324
|
+
return rb_funcall(self, rb_intern("perform"), 0);
|
|
2379
2325
|
}
|
|
2380
2326
|
}
|
|
2381
2327
|
}
|
|
@@ -2400,7 +2346,7 @@ static VALUE ruby_curl_easy_perform_head(VALUE self) {
|
|
|
2400
2346
|
|
|
2401
2347
|
curl_easy_setopt(curl, CURLOPT_NOBODY, 1);
|
|
2402
2348
|
|
|
2403
|
-
ret =
|
|
2349
|
+
ret = rb_funcall(self, rb_intern("perform"), 0);
|
|
2404
2350
|
|
|
2405
2351
|
curl_easy_setopt(curl, CURLOPT_NOBODY, 0);
|
|
2406
2352
|
return ret;
|
|
@@ -2427,62 +2373,6 @@ static VALUE ruby_curl_easy_set_head_option(VALUE self, VALUE onoff) {
|
|
|
2427
2373
|
|
|
2428
2374
|
return onoff;
|
|
2429
2375
|
}
|
|
2430
|
-
/*
|
|
2431
|
-
*call-seq:
|
|
2432
|
-
*
|
|
2433
|
-
* easy = Curl::Easy.new("url")
|
|
2434
|
-
* easy.version = Curl::HTTP_1_1
|
|
2435
|
-
* easy.version = Curl::HTTP_1_0
|
|
2436
|
-
* easy.version = Curl::HTTP_NONE
|
|
2437
|
-
*
|
|
2438
|
-
*/
|
|
2439
|
-
static VALUE ruby_curl_easy_set_version(VALUE self, VALUE version) {
|
|
2440
|
-
ruby_curl_easy *rbce;
|
|
2441
|
-
//fprintf(stderr,"CURL_HTTP_VERSION_1_1: %d, CURL_HTTP_VERSION_1_0: %d, CURL_HTTP_VERSION_NONE: %d\n", CURL_HTTP_VERSION_1_1, CURL_HTTP_VERSION_1_0, CURL_HTTP_VERSION_NONE);
|
|
2442
|
-
|
|
2443
|
-
Data_Get_Struct(self, ruby_curl_easy, rbce);
|
|
2444
|
-
|
|
2445
|
-
curl_easy_setopt(rbce->curl, CURLOPT_HTTP_VERSION, FIX2INT(version));
|
|
2446
|
-
|
|
2447
|
-
return version;
|
|
2448
|
-
}
|
|
2449
|
-
/*
|
|
2450
|
-
* call-seq:
|
|
2451
|
-
*
|
|
2452
|
-
* easy = Curl::Easy.new
|
|
2453
|
-
* easy.nosignal = true
|
|
2454
|
-
*/
|
|
2455
|
-
static VALUE ruby_curl_easy_set_nosignal(VALUE self, VALUE onoff) {
|
|
2456
|
-
ruby_curl_easy *rbce;
|
|
2457
|
-
|
|
2458
|
-
Data_Get_Struct(self, ruby_curl_easy, rbce);
|
|
2459
|
-
|
|
2460
|
-
curl_easy_setopt(rbce->curl, CURLOPT_NOSIGNAL, (Qtrue == onoff) ? 1 : 0);
|
|
2461
|
-
|
|
2462
|
-
return onoff;
|
|
2463
|
-
}
|
|
2464
|
-
/*
|
|
2465
|
-
*call-seq:
|
|
2466
|
-
* easy = Curl::Easy.new("url") do|c|
|
|
2467
|
-
* c.delete = true
|
|
2468
|
-
* end
|
|
2469
|
-
* easy.perform
|
|
2470
|
-
*/
|
|
2471
|
-
static VALUE ruby_curl_easy_set_delete_option(VALUE self, VALUE onoff) {
|
|
2472
|
-
ruby_curl_easy *rbce;
|
|
2473
|
-
|
|
2474
|
-
Data_Get_Struct(self, ruby_curl_easy, rbce);
|
|
2475
|
-
|
|
2476
|
-
if( onoff == Qtrue ) {
|
|
2477
|
-
curl_easy_setopt(rbce->curl, CURLOPT_CUSTOMREQUEST, "DELETE");
|
|
2478
|
-
}
|
|
2479
|
-
else {
|
|
2480
|
-
curl_easy_setopt(rbce->curl, CURLOPT_CUSTOMREQUEST, NULL);
|
|
2481
|
-
}
|
|
2482
|
-
|
|
2483
|
-
return onoff;
|
|
2484
|
-
}
|
|
2485
|
-
|
|
2486
2376
|
/*
|
|
2487
2377
|
* call-seq:
|
|
2488
2378
|
* easy.http_put(data) => true
|
|
@@ -2501,20 +2391,9 @@ static VALUE ruby_curl_easy_perform_put(VALUE self, VALUE data) {
|
|
|
2501
2391
|
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, NULL);
|
|
2502
2392
|
ruby_curl_easy_put_data_set(self, data);
|
|
2503
2393
|
|
|
2504
|
-
return
|
|
2394
|
+
return rb_funcall(self, rb_intern("perform"), 0);
|
|
2505
2395
|
}
|
|
2506
2396
|
|
|
2507
|
-
/*
|
|
2508
|
-
* call-seq:
|
|
2509
|
-
* Curl::Easy.http_put(url, data) {|c| ... }
|
|
2510
|
-
*
|
|
2511
|
-
* see easy.http_put
|
|
2512
|
-
*/
|
|
2513
|
-
static VALUE ruby_curl_easy_class_perform_put(VALUE klass, VALUE url, VALUE data) {
|
|
2514
|
-
VALUE c = ruby_curl_easy_new(1, &url, klass);
|
|
2515
|
-
ruby_curl_easy_perform_put(c, data);
|
|
2516
|
-
return c;
|
|
2517
|
-
}
|
|
2518
2397
|
|
|
2519
2398
|
/* =================== DATA FUNCS =============== */
|
|
2520
2399
|
|
|
@@ -2923,7 +2802,10 @@ static VALUE ruby_curl_easy_ssl_verify_result_get(VALUE self) {
|
|
|
2923
2802
|
|
|
2924
2803
|
/* TODO CURLINFO_SSL_ENGINES
|
|
2925
2804
|
|
|
2926
|
-
Pass the address of a 'struct curl_slist *' to receive a linked-list of OpenSSL crypto-engines supported.
|
|
2805
|
+
Pass the address of a 'struct curl_slist *' to receive a linked-list of OpenSSL crypto-engines supported.
|
|
2806
|
+
Note that engines are normally implemented in separate dynamic libraries.
|
|
2807
|
+
Hence not all the returned engines may be available at run-time.
|
|
2808
|
+
NOTE: you must call curl_slist_free_all(3) on the list pointer once you're done with it, as libcurl will not free the data for you. (Added in 7.12.3)
|
|
2927
2809
|
*/
|
|
2928
2810
|
|
|
2929
2811
|
/*
|
|
@@ -3099,6 +2981,119 @@ static VALUE ruby_curl_easy_ftp_entry_path_get(VALUE self) {
|
|
|
3099
2981
|
#endif
|
|
3100
2982
|
}
|
|
3101
2983
|
|
|
2984
|
+
/*
|
|
2985
|
+
* call-seq:
|
|
2986
|
+
* easy.multi => "#<Curl::Multi>"
|
|
2987
|
+
*/
|
|
2988
|
+
static VALUE ruby_curl_easy_multi_get(VALUE self) {
|
|
2989
|
+
ruby_curl_easy *rbce;
|
|
2990
|
+
Data_Get_Struct(self, ruby_curl_easy, rbce);
|
|
2991
|
+
return rbce->multi;
|
|
2992
|
+
}
|
|
2993
|
+
|
|
2994
|
+
/*
|
|
2995
|
+
* call-seq:
|
|
2996
|
+
* easy.multi=multi => "#<Curl::Multi>"
|
|
2997
|
+
*/
|
|
2998
|
+
static VALUE ruby_curl_easy_multi_set(VALUE self, VALUE multi) {
|
|
2999
|
+
ruby_curl_easy *rbce;
|
|
3000
|
+
Data_Get_Struct(self, ruby_curl_easy, rbce);
|
|
3001
|
+
rbce->multi = multi;
|
|
3002
|
+
return rbce->multi;
|
|
3003
|
+
}
|
|
3004
|
+
|
|
3005
|
+
/*
|
|
3006
|
+
* call-seq:
|
|
3007
|
+
* easy.last_result => 0
|
|
3008
|
+
*/
|
|
3009
|
+
static VALUE ruby_curl_easy_last_result(VALUE self) {
|
|
3010
|
+
ruby_curl_easy *rbce;
|
|
3011
|
+
Data_Get_Struct(self, ruby_curl_easy, rbce);
|
|
3012
|
+
return INT2FIX(rbce->last_result);
|
|
3013
|
+
}
|
|
3014
|
+
|
|
3015
|
+
/*
|
|
3016
|
+
* call-seq:
|
|
3017
|
+
* easy.setopt Fixnum, value => value
|
|
3018
|
+
*
|
|
3019
|
+
* Iniital access to libcurl curl_easy_setopt
|
|
3020
|
+
*/
|
|
3021
|
+
static VALUE ruby_curl_easy_set_opt(VALUE self, VALUE opt, VALUE val) {
|
|
3022
|
+
ruby_curl_easy *rbce;
|
|
3023
|
+
long option = FIX2LONG(opt);
|
|
3024
|
+
|
|
3025
|
+
Data_Get_Struct(self, ruby_curl_easy, rbce);
|
|
3026
|
+
|
|
3027
|
+
switch (option) {
|
|
3028
|
+
/* BEHAVIOR OPTIONS */
|
|
3029
|
+
case CURLOPT_VERBOSE: {
|
|
3030
|
+
VALUE verbose = val;
|
|
3031
|
+
CURB_BOOLEAN_SETTER(ruby_curl_easy, verbose);
|
|
3032
|
+
} break;
|
|
3033
|
+
case CURLOPT_HEADER:
|
|
3034
|
+
case CURLOPT_NOPROGRESS:
|
|
3035
|
+
case CURLOPT_NOSIGNAL:
|
|
3036
|
+
curl_easy_setopt(rbce->curl, CURLOPT_NOSIGNAL, val == Qtrue ? 1 : 0);
|
|
3037
|
+
break;
|
|
3038
|
+
/* TODO: CALLBACK OPTIONS */
|
|
3039
|
+
/* TODO: ERROR OPTIONS */
|
|
3040
|
+
/* NETWORK OPTIONS */
|
|
3041
|
+
case CURLOPT_URL: {
|
|
3042
|
+
VALUE url = val;
|
|
3043
|
+
CURB_OBJECT_HSETTER(ruby_curl_easy, url);
|
|
3044
|
+
} break;
|
|
3045
|
+
case CURLOPT_CUSTOMREQUEST:
|
|
3046
|
+
curl_easy_setopt(rbce->curl, CURLOPT_CUSTOMREQUEST, NIL_P(val) ? NULL : StringValueCStr(val));
|
|
3047
|
+
break;
|
|
3048
|
+
case CURLOPT_HTTP_VERSION:
|
|
3049
|
+
curl_easy_setopt(rbce->curl, CURLOPT_HTTP_VERSION, FIX2INT(val));
|
|
3050
|
+
break;
|
|
3051
|
+
case CURLOPT_PROXY: {
|
|
3052
|
+
VALUE proxy_url = val;
|
|
3053
|
+
CURB_OBJECT_HSETTER(ruby_curl_easy, proxy_url);
|
|
3054
|
+
} break;
|
|
3055
|
+
case CURLOPT_INTERFACE: {
|
|
3056
|
+
VALUE interface_hm = val;
|
|
3057
|
+
CURB_OBJECT_HSETTER(ruby_curl_easy, interface_hm);
|
|
3058
|
+
} break;
|
|
3059
|
+
case CURLOPT_USERPWD: {
|
|
3060
|
+
VALUE userpwd = val;
|
|
3061
|
+
CURB_OBJECT_HSETTER(ruby_curl_easy, userpwd);
|
|
3062
|
+
} break;
|
|
3063
|
+
case CURLOPT_PROXYUSERPWD: {
|
|
3064
|
+
VALUE proxypwd = val;
|
|
3065
|
+
CURB_OBJECT_HSETTER(ruby_curl_easy, proxypwd);
|
|
3066
|
+
} break;
|
|
3067
|
+
case CURLOPT_COOKIE: {
|
|
3068
|
+
VALUE cookies = val;
|
|
3069
|
+
CURB_OBJECT_HSETTER(ruby_curl_easy, cookies);
|
|
3070
|
+
} break;
|
|
3071
|
+
case CURLOPT_COOKIEFILE: {
|
|
3072
|
+
VALUE cookiefile = val;
|
|
3073
|
+
CURB_OBJECT_HSETTER(ruby_curl_easy, cookiefile);
|
|
3074
|
+
} break;
|
|
3075
|
+
case CURLOPT_COOKIEJAR: {
|
|
3076
|
+
VALUE cookiejar = val;
|
|
3077
|
+
CURB_OBJECT_HSETTER(ruby_curl_easy, cookiejar);
|
|
3078
|
+
} break;
|
|
3079
|
+
|
|
3080
|
+
default:
|
|
3081
|
+
break;
|
|
3082
|
+
}
|
|
3083
|
+
|
|
3084
|
+
return val;
|
|
3085
|
+
}
|
|
3086
|
+
|
|
3087
|
+
/*
|
|
3088
|
+
* call-seq:
|
|
3089
|
+
* easy.getinfo Fixnum => value
|
|
3090
|
+
*
|
|
3091
|
+
* Iniital access to libcurl curl_easy_getinfo, remember getinfo doesn't return the same values as setopt
|
|
3092
|
+
*/
|
|
3093
|
+
static VALUE ruby_curl_easy_get_opt(VALUE self, VALUE opt) {
|
|
3094
|
+
return Qnil;
|
|
3095
|
+
}
|
|
3096
|
+
|
|
3102
3097
|
/*
|
|
3103
3098
|
* call-seq:
|
|
3104
3099
|
* easy.inspect => "#<Curl::Easy http://google.com/>"
|
|
@@ -3113,7 +3108,7 @@ static VALUE ruby_curl_easy_inspect(VALUE self) {
|
|
|
3113
3108
|
size_t len = 13+((RSTRING_LEN(url) > 50) ? 50 : RSTRING_LEN(url));
|
|
3114
3109
|
/* "#<Net::HTTP http://www.google.com/:80 open=false>" */
|
|
3115
3110
|
memcpy(buf,"#<Curl::Easy ", 13);
|
|
3116
|
-
memcpy(buf+13,
|
|
3111
|
+
memcpy(buf+13,StringValueCStr(url), (len - 13));
|
|
3117
3112
|
buf[len++] = '>';
|
|
3118
3113
|
return rb_str_new(buf,len);
|
|
3119
3114
|
}
|
|
@@ -3189,114 +3184,14 @@ static VALUE ruby_curl_easy_unescape(VALUE self, VALUE str) {
|
|
|
3189
3184
|
|
|
3190
3185
|
/*
|
|
3191
3186
|
* call-seq:
|
|
3192
|
-
* Curl::Easy.
|
|
3193
|
-
*
|
|
3194
|
-
* Convenience method that creates a new Curl::Easy instance with
|
|
3195
|
-
* the specified URL and calls the general +perform+ method, before returning
|
|
3196
|
-
* the new instance. For HTTP URLs, this is equivalent to calling +http_get+.
|
|
3197
|
-
*
|
|
3198
|
-
* If a block is supplied, the new instance will be yielded just prior to
|
|
3199
|
-
* the +http_get+ call.
|
|
3200
|
-
*/
|
|
3201
|
-
static VALUE ruby_curl_easy_class_perform(int argc, VALUE *argv, VALUE klass) {
|
|
3202
|
-
VALUE c = ruby_curl_easy_new(argc, argv, klass);
|
|
3203
|
-
|
|
3204
|
-
if (rb_block_given_p()) {
|
|
3205
|
-
rb_yield(c);
|
|
3206
|
-
}
|
|
3207
|
-
|
|
3208
|
-
ruby_curl_easy_perform(c);
|
|
3209
|
-
return c;
|
|
3210
|
-
}
|
|
3211
|
-
|
|
3212
|
-
/*
|
|
3213
|
-
* call-seq:
|
|
3214
|
-
* Curl::Easy.http_get(url) { |easy| ... } => #<Curl::Easy...>
|
|
3215
|
-
*
|
|
3216
|
-
* Convenience method that creates a new Curl::Easy instance with
|
|
3217
|
-
* the specified URL and calls +http_get+, before returning the new instance.
|
|
3218
|
-
*
|
|
3219
|
-
* If a block is supplied, the new instance will be yielded just prior to
|
|
3220
|
-
* the +http_get+ call.
|
|
3221
|
-
*/
|
|
3222
|
-
static VALUE ruby_curl_easy_class_perform_get(int argc, VALUE *argv, VALUE klass) {
|
|
3223
|
-
VALUE c = ruby_curl_easy_new(argc, argv, klass);
|
|
3224
|
-
|
|
3225
|
-
ruby_curl_easy_perform_get(c);
|
|
3226
|
-
return c;
|
|
3227
|
-
}
|
|
3228
|
-
|
|
3229
|
-
/*
|
|
3230
|
-
* call-seq:
|
|
3231
|
-
* Curl::Easy.http_delete(url) { |easy| ... } => #<Curl::Easy...>
|
|
3232
|
-
*
|
|
3233
|
-
* Convenience method that creates a new Curl::Easy instance with
|
|
3234
|
-
* the specified URL and calls +http_delete+, before returning the new instance.
|
|
3235
|
-
*
|
|
3236
|
-
* If a block is supplied, the new instance will be yielded just prior to
|
|
3237
|
-
* the +http_delete+ call.
|
|
3238
|
-
*/
|
|
3239
|
-
static VALUE ruby_curl_easy_class_perform_delete(int argc, VALUE *argv, VALUE klass) {
|
|
3240
|
-
VALUE c = ruby_curl_easy_new(argc, argv, klass);
|
|
3241
|
-
|
|
3242
|
-
ruby_curl_easy_perform_delete(c);
|
|
3243
|
-
return c;
|
|
3244
|
-
}
|
|
3245
|
-
|
|
3246
|
-
/*
|
|
3247
|
-
* call-seq:
|
|
3248
|
-
* Curl::Easy.http_head(url) { |easy| ... } => #<Curl::Easy...>
|
|
3249
|
-
*
|
|
3250
|
-
* Convenience method that creates a new Curl::Easy instance with
|
|
3251
|
-
* the specified URL and calls +http_head+, before returning the new instance.
|
|
3187
|
+
* Curl::Easy.error(code) => String
|
|
3252
3188
|
*
|
|
3253
|
-
*
|
|
3254
|
-
* the +http_head+ call.
|
|
3189
|
+
* translate an internal libcurl error to ruby error class
|
|
3255
3190
|
*/
|
|
3256
|
-
static VALUE
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
ruby_curl_easy_perform_head(c);
|
|
3260
|
-
|
|
3261
|
-
return c;
|
|
3191
|
+
static VALUE ruby_curl_easy_error_message(VALUE klass, VALUE code) {
|
|
3192
|
+
return rb_curl_easy_error(FIX2INT(code));
|
|
3262
3193
|
}
|
|
3263
3194
|
|
|
3264
|
-
// TODO: add convenience method for http_post
|
|
3265
|
-
|
|
3266
|
-
/*
|
|
3267
|
-
* call-seq:
|
|
3268
|
-
* Curl::Easy.http_post(url, "some=urlencoded%20form%20data&and=so%20on") => true
|
|
3269
|
-
* Curl::Easy.http_post(url, "some=urlencoded%20form%20data", "and=so%20on", ...) => true
|
|
3270
|
-
* Curl::Easy.http_post(url, "some=urlencoded%20form%20data", Curl::PostField, "and=so%20on", ...) => true
|
|
3271
|
-
* Curl::Easy.http_post(url, Curl::PostField, Curl::PostField ..., Curl::PostField) => true
|
|
3272
|
-
*
|
|
3273
|
-
* POST the specified formdata to the currently configured URL using
|
|
3274
|
-
* the current options set for this Curl::Easy instance. This method
|
|
3275
|
-
* always returns true, or raises an exception (defined under
|
|
3276
|
-
* Curl::Err) on error.
|
|
3277
|
-
*
|
|
3278
|
-
* If you wish to use multipart form encoding, you'll need to supply a block
|
|
3279
|
-
* in order to set multipart_form_post true. See #http_post for more
|
|
3280
|
-
* information.
|
|
3281
|
-
*/
|
|
3282
|
-
static VALUE ruby_curl_easy_class_perform_post(int argc, VALUE *argv, VALUE klass) {
|
|
3283
|
-
VALUE url, fields;
|
|
3284
|
-
VALUE c;
|
|
3285
|
-
|
|
3286
|
-
rb_scan_args(argc, argv, "1*", &url, &fields);
|
|
3287
|
-
|
|
3288
|
-
c = ruby_curl_easy_new(1, &url, klass);
|
|
3289
|
-
|
|
3290
|
-
if (argc > 1) {
|
|
3291
|
-
ruby_curl_easy_perform_post(argc - 1, &argv[1], c);
|
|
3292
|
-
} else {
|
|
3293
|
-
ruby_curl_easy_perform_post(0, NULL, c);
|
|
3294
|
-
}
|
|
3295
|
-
|
|
3296
|
-
return c;
|
|
3297
|
-
}
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
3195
|
/* =================== INIT LIB =====================*/
|
|
3301
3196
|
void init_curb_easy() {
|
|
3302
3197
|
idCall = rb_intern("call");
|
|
@@ -3309,31 +3204,18 @@ void init_curb_easy() {
|
|
|
3309
3204
|
|
|
3310
3205
|
/* Class methods */
|
|
3311
3206
|
rb_define_singleton_method(cCurlEasy, "new", ruby_curl_easy_new, -1);
|
|
3312
|
-
rb_define_singleton_method(cCurlEasy, "
|
|
3313
|
-
rb_define_singleton_method(cCurlEasy, "http_delete", ruby_curl_easy_class_perform_delete, -1);
|
|
3314
|
-
rb_define_singleton_method(cCurlEasy, "http_get", ruby_curl_easy_class_perform_get, -1);
|
|
3315
|
-
rb_define_singleton_method(cCurlEasy, "http_post", ruby_curl_easy_class_perform_post, -1);
|
|
3316
|
-
rb_define_singleton_method(cCurlEasy, "http_head", ruby_curl_easy_class_perform_head, -1);
|
|
3317
|
-
rb_define_singleton_method(cCurlEasy, "http_put", ruby_curl_easy_class_perform_put, 2);
|
|
3207
|
+
rb_define_singleton_method(cCurlEasy, "error", ruby_curl_easy_error_message, 1);
|
|
3318
3208
|
|
|
3319
3209
|
/* Attributes for config next perform */
|
|
3320
|
-
rb_define_method(cCurlEasy, "url=", ruby_curl_easy_url_set, 1);
|
|
3321
3210
|
rb_define_method(cCurlEasy, "url", ruby_curl_easy_url_get, 0);
|
|
3322
|
-
rb_define_method(cCurlEasy, "proxy_url=", ruby_curl_easy_proxy_url_set, 1);
|
|
3323
3211
|
rb_define_method(cCurlEasy, "proxy_url", ruby_curl_easy_proxy_url_get, 0);
|
|
3324
3212
|
rb_define_method(cCurlEasy, "headers=", ruby_curl_easy_headers_set, 1);
|
|
3325
3213
|
rb_define_method(cCurlEasy, "headers", ruby_curl_easy_headers_get, 0);
|
|
3326
|
-
rb_define_method(cCurlEasy, "interface=", ruby_curl_easy_interface_set, 1);
|
|
3327
3214
|
rb_define_method(cCurlEasy, "interface", ruby_curl_easy_interface_get, 0);
|
|
3328
|
-
rb_define_method(cCurlEasy, "userpwd=", ruby_curl_easy_userpwd_set, 1);
|
|
3329
3215
|
rb_define_method(cCurlEasy, "userpwd", ruby_curl_easy_userpwd_get, 0);
|
|
3330
|
-
rb_define_method(cCurlEasy, "proxypwd=", ruby_curl_easy_proxypwd_set, 1);
|
|
3331
3216
|
rb_define_method(cCurlEasy, "proxypwd", ruby_curl_easy_proxypwd_get, 0);
|
|
3332
|
-
rb_define_method(cCurlEasy, "cookies=", ruby_curl_easy_cookies_set, 1);
|
|
3333
3217
|
rb_define_method(cCurlEasy, "cookies", ruby_curl_easy_cookies_get, 0);
|
|
3334
|
-
rb_define_method(cCurlEasy, "cookiefile=", ruby_curl_easy_cookiefile_set, 1);
|
|
3335
3218
|
rb_define_method(cCurlEasy, "cookiefile", ruby_curl_easy_cookiefile_get, 0);
|
|
3336
|
-
rb_define_method(cCurlEasy, "cookiejar=", ruby_curl_easy_cookiejar_set, 1);
|
|
3337
3219
|
rb_define_method(cCurlEasy, "cookiejar", ruby_curl_easy_cookiejar_get, 0);
|
|
3338
3220
|
rb_define_method(cCurlEasy, "cert=", ruby_curl_easy_cert_set, 1);
|
|
3339
3221
|
rb_define_method(cCurlEasy, "cert", ruby_curl_easy_cert_get, 0);
|
|
@@ -3398,8 +3280,8 @@ void init_curb_easy() {
|
|
|
3398
3280
|
rb_define_method(cCurlEasy, "fetch_file_time?", ruby_curl_easy_fetch_file_time_q, 0);
|
|
3399
3281
|
rb_define_method(cCurlEasy, "ssl_verify_peer=", ruby_curl_easy_ssl_verify_peer_set, 1);
|
|
3400
3282
|
rb_define_method(cCurlEasy, "ssl_verify_peer?", ruby_curl_easy_ssl_verify_peer_q, 0);
|
|
3401
|
-
rb_define_method(cCurlEasy, "
|
|
3402
|
-
rb_define_method(cCurlEasy, "ssl_verify_host
|
|
3283
|
+
rb_define_method(cCurlEasy, "ssl_verify_host_integer=", ruby_curl_easy_ssl_verify_host_set, 1);
|
|
3284
|
+
rb_define_method(cCurlEasy, "ssl_verify_host", ruby_curl_easy_ssl_verify_host_get, 0);
|
|
3403
3285
|
rb_define_method(cCurlEasy, "header_in_body=", ruby_curl_easy_header_in_body_set, 1);
|
|
3404
3286
|
rb_define_method(cCurlEasy, "header_in_body?", ruby_curl_easy_header_in_body_q, 0);
|
|
3405
3287
|
rb_define_method(cCurlEasy, "use_netrc=", ruby_curl_easy_use_netrc_set, 1);
|
|
@@ -3417,6 +3299,8 @@ void init_curb_easy() {
|
|
|
3417
3299
|
rb_define_method(cCurlEasy, "enable_cookies?", ruby_curl_easy_enable_cookies_q, 0);
|
|
3418
3300
|
rb_define_method(cCurlEasy, "ignore_content_length=", ruby_curl_easy_ignore_content_length_set, 1);
|
|
3419
3301
|
rb_define_method(cCurlEasy, "ignore_content_length?", ruby_curl_easy_ignore_content_length_q, 0);
|
|
3302
|
+
rb_define_method(cCurlEasy, "resolve_mode", ruby_curl_easy_resolve_mode, 0);
|
|
3303
|
+
rb_define_method(cCurlEasy, "resolve_mode=", ruby_curl_easy_resolve_mode_set, 1);
|
|
3420
3304
|
|
|
3421
3305
|
rb_define_method(cCurlEasy, "on_body", ruby_curl_easy_on_body_set, -1);
|
|
3422
3306
|
rb_define_method(cCurlEasy, "on_header", ruby_curl_easy_on_header_set, -1);
|
|
@@ -3426,7 +3310,6 @@ void init_curb_easy() {
|
|
|
3426
3310
|
rb_define_method(cCurlEasy, "on_failure", ruby_curl_easy_on_failure_set, -1);
|
|
3427
3311
|
rb_define_method(cCurlEasy, "on_complete", ruby_curl_easy_on_complete_set, -1);
|
|
3428
3312
|
|
|
3429
|
-
rb_define_method(cCurlEasy, "perform", ruby_curl_easy_perform, 0);
|
|
3430
3313
|
rb_define_method(cCurlEasy, "http", ruby_curl_easy_perform_verb, 1);
|
|
3431
3314
|
rb_define_method(cCurlEasy, "http_delete", ruby_curl_easy_perform_delete, 0);
|
|
3432
3315
|
rb_define_method(cCurlEasy, "http_get", ruby_curl_easy_perform_get, 0);
|
|
@@ -3434,12 +3317,6 @@ void init_curb_easy() {
|
|
|
3434
3317
|
rb_define_method(cCurlEasy, "http_head", ruby_curl_easy_perform_head, 0);
|
|
3435
3318
|
rb_define_method(cCurlEasy, "http_put", ruby_curl_easy_perform_put, 1);
|
|
3436
3319
|
rb_define_method(cCurlEasy, "head=", ruby_curl_easy_set_head_option, 1);
|
|
3437
|
-
rb_define_method(cCurlEasy, "delete=", ruby_curl_easy_set_delete_option, 1);
|
|
3438
|
-
rb_define_method(cCurlEasy, "version=", ruby_curl_easy_set_version, 1);
|
|
3439
|
-
rb_define_const(mCurl, "HTTP_1_1", LONG2NUM(CURL_HTTP_VERSION_1_1));
|
|
3440
|
-
rb_define_const(mCurl, "HTTP_1_0", LONG2NUM(CURL_HTTP_VERSION_1_0));
|
|
3441
|
-
rb_define_const(mCurl, "HTTP_NONE", LONG2NUM(CURL_HTTP_VERSION_NONE));
|
|
3442
|
-
rb_define_method(cCurlEasy, "nosignal=", ruby_curl_easy_set_nosignal, 1);
|
|
3443
3320
|
|
|
3444
3321
|
/* Post-perform info methods */
|
|
3445
3322
|
rb_define_method(cCurlEasy, "body_str", ruby_curl_easy_body_str_get, 0);
|
|
@@ -3484,4 +3361,11 @@ void init_curb_easy() {
|
|
|
3484
3361
|
rb_define_method(cCurlEasy, "clone", ruby_curl_easy_clone, 0);
|
|
3485
3362
|
rb_define_alias(cCurlEasy, "dup", "clone");
|
|
3486
3363
|
rb_define_method(cCurlEasy, "inspect", ruby_curl_easy_inspect, 0);
|
|
3364
|
+
|
|
3365
|
+
rb_define_method(cCurlEasy, "multi", ruby_curl_easy_multi_get, 0);
|
|
3366
|
+
rb_define_method(cCurlEasy, "multi=", ruby_curl_easy_multi_set, 1);
|
|
3367
|
+
rb_define_method(cCurlEasy, "last_result", ruby_curl_easy_last_result, 0);
|
|
3368
|
+
|
|
3369
|
+
rb_define_method(cCurlEasy, "setopt", ruby_curl_easy_set_opt, 2);
|
|
3370
|
+
rb_define_method(cCurlEasy, "getinfo", ruby_curl_easy_get_opt, 1);
|
|
3487
3371
|
}
|