taf2-curb 0.4.3.0 → 0.4.4.0
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 +10 -1
- data/ext/curb.h +3 -3
- data/ext/curb_easy.c +59 -12
- data/ext/curb_errors.c +19 -5
- data/ext/curb_errors.h +2 -0
- data/ext/curb_multi.c +7 -6
- data/tests/bug_multi_segfault.rb +10 -0
- data/tests/helper.rb +1 -1
- data/tests/tc_curl_easy.rb +19 -1
- data/tests/tc_curl_multi.rb +4 -1
- metadata +3 -2
data/README
CHANGED
@@ -106,7 +106,16 @@ HTTP POST file upload:
|
|
106
106
|
c.multipart_form_post = true
|
107
107
|
c.http_post(Curl::PostField.file('myfile.rb'))
|
108
108
|
|
109
|
-
Multi Interface:
|
109
|
+
Multi Interface (Basic):
|
110
|
+
easy_options = {:follow_location => true}
|
111
|
+
multi_options = {:pipeline => true}
|
112
|
+
|
113
|
+
Curl::Multi.get('url1','url2','url3','url4','url5', easy_options, multi_options) do|easy|
|
114
|
+
# do something interesting with the easy response
|
115
|
+
puts easy.last_effective_url
|
116
|
+
end
|
117
|
+
|
118
|
+
Multi Interface (Advanced):
|
110
119
|
responses = {}
|
111
120
|
requests = ["http://www.google.co.uk/", "http://www.ruby-lang.org/"]
|
112
121
|
m = Curl::Multi.new
|
data/ext/curb.h
CHANGED
@@ -20,11 +20,11 @@
|
|
20
20
|
#include "curb_macros.h"
|
21
21
|
|
22
22
|
// These should be managed from the Rake 'release' task.
|
23
|
-
#define CURB_VERSION "0.4.
|
24
|
-
#define CURB_VER_NUM
|
23
|
+
#define CURB_VERSION "0.4.4.0"
|
24
|
+
#define CURB_VER_NUM 440
|
25
25
|
#define CURB_VER_MAJ 0
|
26
26
|
#define CURB_VER_MIN 4
|
27
|
-
#define CURB_VER_MIC
|
27
|
+
#define CURB_VER_MIC 4
|
28
28
|
#define CURB_VER_PATCH 0
|
29
29
|
|
30
30
|
|
data/ext/curb_easy.c
CHANGED
@@ -678,6 +678,58 @@ static VALUE ruby_curl_easy_useragent_get(VALUE self) {
|
|
678
678
|
CURB_OBJECT_GETTER(ruby_curl_easy, useragent);
|
679
679
|
}
|
680
680
|
|
681
|
+
/*
|
682
|
+
* call-seq:
|
683
|
+
* easy.post_body = "some=form%20data&to=send" => string or nil
|
684
|
+
*
|
685
|
+
* Sets the POST body of this Curl::Easy instance. This is expected to be
|
686
|
+
* URL encoded; no additional processing or encoding is done on the string.
|
687
|
+
* The content-type header will be set to application/x-www-form-urlencoded.
|
688
|
+
*
|
689
|
+
* This is handy if you want to perform a POST against a Curl::Multi instance.
|
690
|
+
*/
|
691
|
+
static VALUE ruby_curl_easy_post_body_set(VALUE self, VALUE post_body) {
|
692
|
+
ruby_curl_easy *rbce;
|
693
|
+
CURL *curl;
|
694
|
+
|
695
|
+
char *data;
|
696
|
+
long len;
|
697
|
+
|
698
|
+
Data_Get_Struct(self, ruby_curl_easy, rbce);
|
699
|
+
|
700
|
+
curl = rbce->curl;
|
701
|
+
|
702
|
+
if ( post_body == Qnil ) {
|
703
|
+
rbce->postdata_buffer = Qnil;
|
704
|
+
|
705
|
+
} else {
|
706
|
+
data = StringValuePtr(post_body);
|
707
|
+
len = RSTRING_LEN(post_body);
|
708
|
+
|
709
|
+
// Store the string, since it has to hang around for the duration of the
|
710
|
+
// request. See CURLOPT_POSTFIELDS in the libcurl docs.
|
711
|
+
rbce->postdata_buffer = post_body;
|
712
|
+
|
713
|
+
curl_easy_setopt(curl, CURLOPT_POST, 1);
|
714
|
+
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
|
715
|
+
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, len);
|
716
|
+
|
717
|
+
return post_body;
|
718
|
+
}
|
719
|
+
|
720
|
+
return Qnil;
|
721
|
+
}
|
722
|
+
|
723
|
+
/*
|
724
|
+
* call-seq:
|
725
|
+
* easy.post_body => "string" or nil
|
726
|
+
*
|
727
|
+
* Obtain the POST body used in this Curl::Easy instance.
|
728
|
+
*/
|
729
|
+
static VALUE ruby_curl_easy_post_body_get(VALUE self) {
|
730
|
+
CURB_OBJECT_GETTER(ruby_curl_easy, postdata_buffer);
|
731
|
+
}
|
732
|
+
|
681
733
|
/* ================== IMMED ATTRS ==================*/
|
682
734
|
|
683
735
|
/*
|
@@ -1789,7 +1841,7 @@ static VALUE handle_perform(VALUE self, ruby_curl_easy *rbce) {
|
|
1789
1841
|
if (result != 0) {
|
1790
1842
|
// printf("error: %s\n", errors);
|
1791
1843
|
if (rbce->failure_proc != Qnil) {
|
1792
|
-
rb_funcall( rbce->failure_proc, idCall, 2, rbce->self,
|
1844
|
+
rb_funcall( rbce->failure_proc, idCall, 2, rbce->self, rb_curl_easy_error(result) );
|
1793
1845
|
} else {
|
1794
1846
|
raise_curl_easy_error_exception(result);
|
1795
1847
|
}
|
@@ -1801,7 +1853,7 @@ static VALUE handle_perform(VALUE self, ruby_curl_easy *rbce) {
|
|
1801
1853
|
}
|
1802
1854
|
else if (rbce->failure_proc != Qnil &&
|
1803
1855
|
(response_code >= 300 && response_code <= 999)) {
|
1804
|
-
rb_funcall( rbce->failure_proc, idCall, 2, rbce->self,
|
1856
|
+
rb_funcall( rbce->failure_proc, idCall, 2, rbce->self, rb_curl_easy_error(result) );
|
1805
1857
|
}
|
1806
1858
|
|
1807
1859
|
return Qtrue;
|
@@ -1925,19 +1977,12 @@ static VALUE ruby_curl_easy_perform_post(int argc, VALUE *argv, VALUE self) {
|
|
1925
1977
|
|
1926
1978
|
return ret;
|
1927
1979
|
} else {
|
1928
|
-
|
1929
|
-
|
1930
|
-
|
1931
|
-
if ((rbce->postdata_buffer = rb_funcall(args_ary, idJoin, 1, rbstrAmp)) == Qnil) {
|
1980
|
+
VALUE post_body;
|
1981
|
+
if ((post_body = rb_funcall(args_ary, idJoin, 1, rbstrAmp)) == Qnil) {
|
1932
1982
|
rb_raise(eCurlErrError, "Failed to join arguments");
|
1933
1983
|
return Qnil;
|
1934
1984
|
} else {
|
1935
|
-
|
1936
|
-
len = RSTRING_LEN(rbce->postdata_buffer);
|
1937
|
-
|
1938
|
-
curl_easy_setopt(curl, CURLOPT_POST, 1);
|
1939
|
-
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
|
1940
|
-
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, len);
|
1985
|
+
ruby_curl_easy_post_body_set(self, post_body);
|
1941
1986
|
|
1942
1987
|
return handle_perform(self,rbce);
|
1943
1988
|
}
|
@@ -2847,6 +2892,8 @@ void init_curb_easy() {
|
|
2847
2892
|
rb_define_method(cCurlEasy, "encoding", ruby_curl_easy_encoding_get, 0);
|
2848
2893
|
rb_define_method(cCurlEasy, "useragent=", ruby_curl_easy_useragent_set, 1);
|
2849
2894
|
rb_define_method(cCurlEasy, "useragent", ruby_curl_easy_useragent_get, 0);
|
2895
|
+
rb_define_method(cCurlEasy, "post_body=", ruby_curl_easy_post_body_set, 1);
|
2896
|
+
rb_define_method(cCurlEasy, "post_body", ruby_curl_easy_post_body_get, 0);
|
2850
2897
|
|
2851
2898
|
rb_define_method(cCurlEasy, "local_port=", ruby_curl_easy_local_port_set, 1);
|
2852
2899
|
rb_define_method(cCurlEasy, "local_port", ruby_curl_easy_local_port_get, 0);
|
data/ext/curb_errors.c
CHANGED
@@ -121,8 +121,7 @@ VALUE mCurlErrUnknownOption;
|
|
121
121
|
VALUE eCurlErrInvalidPostField;
|
122
122
|
|
123
123
|
|
124
|
-
|
125
|
-
void raise_curl_easy_error_exception(CURLcode code) {
|
124
|
+
VALUE rb_curl_easy_error(CURLcode code) {
|
126
125
|
VALUE exclz;
|
127
126
|
const char *exmsg = NULL;
|
128
127
|
|
@@ -437,9 +436,17 @@ void raise_curl_easy_error_exception(CURLcode code) {
|
|
437
436
|
exmsg = curl_easy_strerror(code);
|
438
437
|
}
|
439
438
|
|
440
|
-
|
439
|
+
VALUE results = rb_ary_new2(2);
|
440
|
+
rb_ary_push(results, exclz);
|
441
|
+
rb_ary_push(results, rb_str_new2(exmsg));
|
442
|
+
return results;
|
441
443
|
}
|
442
|
-
|
444
|
+
/* rb_raise an approriate exception for the supplied CURLcode */
|
445
|
+
void raise_curl_easy_error_exception(CURLcode code) {
|
446
|
+
VALUE obj = rb_curl_easy_error(code);
|
447
|
+
rb_raise(rb_ary_entry(obj,0), RSTRING_PTR(rb_ary_entry(obj,1)));
|
448
|
+
}
|
449
|
+
VALUE rb_curl_multi_error(CURLMcode code) {
|
443
450
|
VALUE exclz;
|
444
451
|
const char *exmsg = NULL;
|
445
452
|
|
@@ -478,7 +485,14 @@ void raise_curl_multi_error_exception(CURLMcode code) {
|
|
478
485
|
exmsg = curl_multi_strerror(code);
|
479
486
|
}
|
480
487
|
|
481
|
-
|
488
|
+
VALUE results = rb_ary_new2(2);
|
489
|
+
rb_ary_push(results, exclz);
|
490
|
+
rb_ary_push(results, rb_str_new2(exmsg));
|
491
|
+
return results;
|
492
|
+
}
|
493
|
+
void raise_curl_multi_error_exception(CURLMcode code) {
|
494
|
+
VALUE obj = rb_curl_multi_error(code);
|
495
|
+
rb_raise(rb_ary_entry(obj,0), RSTRING_PTR(rb_ary_entry(obj,1)));
|
482
496
|
}
|
483
497
|
|
484
498
|
void init_curb_errors() {
|
data/ext/curb_errors.h
CHANGED
@@ -122,5 +122,7 @@ extern VALUE eCurlErrInvalidPostField;
|
|
122
122
|
void init_curb_errors();
|
123
123
|
void raise_curl_easy_error_exception(CURLcode code);
|
124
124
|
void raise_curl_multi_error_exception(CURLMcode code);
|
125
|
+
VALUE rb_curl_easy_error(CURLcode code);
|
126
|
+
VALUE rb_curl_multi_error(CURLMcode code);
|
125
127
|
|
126
128
|
#endif
|
data/ext/curb_multi.c
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
/*
|
1
|
+
/* curb_multi.c - Curl multi mode
|
2
2
|
* Copyright (c)2008 Todd A. Fisher.
|
3
3
|
* Licensed under the Ruby License. See LICENSE for details.
|
4
4
|
*
|
5
|
-
* $Id$
|
6
5
|
*/
|
7
6
|
|
8
7
|
#include "curb_config.h"
|
@@ -58,14 +57,16 @@ static void curl_multi_flush_easy(VALUE key, VALUE easy, ruby_curl_multi *rbcm)
|
|
58
57
|
}
|
59
58
|
|
60
59
|
static void curl_multi_free(ruby_curl_multi *rbcm) {
|
60
|
+
|
61
61
|
//printf("hash entries: %d\n", RHASH(rbcm->requests)->tbl->num_entries );
|
62
|
-
if (rbcm && RHASH_LEN(rbcm->requests) > 0) {
|
62
|
+
if (rbcm && !rbcm->requests == Qnil && rb_type(rbcm->requests) == T_HASH && RHASH_LEN(rbcm->requests) > 0) {
|
63
|
+
|
63
64
|
rb_hash_foreach( rbcm->requests, (int (*)())curl_multi_flush_easy, (VALUE)rbcm );
|
64
65
|
|
65
|
-
curl_multi_cleanup(rbcm->handle);
|
66
66
|
//rb_hash_clear(rbcm->requests)
|
67
67
|
rbcm->requests = Qnil;
|
68
68
|
}
|
69
|
+
curl_multi_cleanup(rbcm->handle);
|
69
70
|
free(rbcm);
|
70
71
|
}
|
71
72
|
|
@@ -257,7 +258,7 @@ static void rb_curl_multi_read_info(VALUE self, CURLM *multi_handle) {
|
|
257
258
|
|
258
259
|
if (result != 0) {
|
259
260
|
if (rbce->failure_proc != Qnil) {
|
260
|
-
rb_funcall( rbce->failure_proc, idCall, 2, rbce->self,
|
261
|
+
rb_funcall( rbce->failure_proc, idCall, 2, rbce->self, rb_curl_easy_error(result) );
|
261
262
|
}
|
262
263
|
}
|
263
264
|
else if (rbce->success_proc != Qnil &&
|
@@ -267,7 +268,7 @@ static void rb_curl_multi_read_info(VALUE self, CURLM *multi_handle) {
|
|
267
268
|
}
|
268
269
|
else if (rbce->failure_proc != Qnil &&
|
269
270
|
(response_code >= 300 && response_code <= 999)) {
|
270
|
-
rb_funcall( rbce->failure_proc, idCall, 2, rbce->self,
|
271
|
+
rb_funcall( rbce->failure_proc, idCall, 2, rbce->self, rb_curl_easy_error(result) );
|
271
272
|
}
|
272
273
|
rbce->self = Qnil;
|
273
274
|
}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# From safis http://github.com/taf2/curb/issues#issue/5
|
2
|
+
# irb: require 'curb'
|
3
|
+
# irb: multi = Curl::Multi.new
|
4
|
+
# irb: exit
|
5
|
+
# <main>:47140: [BUG] Bus Error
|
6
|
+
$:.unshift File.join(File.dirname(__FILE__),'..','ext')
|
7
|
+
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
8
|
+
require 'curb'
|
9
|
+
multi = Curl::Multi.new
|
10
|
+
exit
|
data/tests/helper.rb
CHANGED
data/tests/tc_curl_easy.rb
CHANGED
@@ -497,7 +497,25 @@ class TestCurbCurlEasy < Test::Unit::TestCase
|
|
497
497
|
def test_post_remote
|
498
498
|
curl = Curl::Easy.new(TestServlet.url)
|
499
499
|
curl.http_post
|
500
|
-
assert_equal
|
500
|
+
assert_equal "POST\n", curl.body_str
|
501
|
+
end
|
502
|
+
|
503
|
+
def test_post_with_body_remote
|
504
|
+
curl = Curl::Easy.new(TestServlet.url)
|
505
|
+
curl.post_body = 'foo=bar&encoded%20string=val'
|
506
|
+
|
507
|
+
curl.perform
|
508
|
+
|
509
|
+
assert_equal "POST\nfoo=bar&encoded%20string=val", curl.body_str
|
510
|
+
assert_equal 'foo=bar&encoded%20string=val', curl.post_body
|
511
|
+
end
|
512
|
+
|
513
|
+
def test_form_post_body_remote
|
514
|
+
curl = Curl::Easy.new(TestServlet.url)
|
515
|
+
curl.http_post('foo=bar', 'encoded%20string=val')
|
516
|
+
|
517
|
+
assert_equal "POST\nfoo=bar&encoded%20string=val", curl.body_str
|
518
|
+
assert_equal 'foo=bar&encoded%20string=val', curl.post_body
|
501
519
|
end
|
502
520
|
|
503
521
|
def test_delete_remote
|
data/tests/tc_curl_multi.rb
CHANGED
@@ -146,7 +146,10 @@ class TestCurbCurlMulti < Test::Unit::TestCase
|
|
146
146
|
end
|
147
147
|
|
148
148
|
c1.on_failure do|c,rc|
|
149
|
-
#
|
149
|
+
# rc => [Curl::Err::MalformedURLError, "URL using bad/illegal format or missing URL"]
|
150
|
+
assert_equal Curl::Easy, c.class
|
151
|
+
assert_equal Curl::Err::MalformedURLError, rc.first
|
152
|
+
assert_equal "URL using bad/illegal format or missing URL", rc.last
|
150
153
|
end
|
151
154
|
|
152
155
|
c2.on_success do|c|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: taf2-curb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ross Bamford
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-07-
|
13
|
+
date: 2009-07-12 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|
@@ -83,4 +83,5 @@ test_files:
|
|
83
83
|
- tests/alltests.rb
|
84
84
|
- tests/helper.rb
|
85
85
|
- tests/tc_curl_easy.rb
|
86
|
+
- tests/bug_multi_segfault.rb
|
86
87
|
- tests/require_last_or_segfault_script.rb
|