curb 0.6.0.0 → 0.6.2.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of curb might be problematic. Click here for more details.

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.6.0.0"
24
- #define CURB_VER_NUM 600
23
+ #define CURB_VERSION "0.6.2.0"
24
+ #define CURB_VER_NUM 620
25
25
  #define CURB_VER_MAJ 0
26
26
  #define CURB_VER_MIN 6
27
- #define CURB_VER_MIC 0
27
+ #define CURB_VER_MIC 2
28
28
  #define CURB_VER_PATCH 0
29
29
 
30
30
 
@@ -143,6 +143,8 @@ void curl_easy_mark(ruby_curl_easy *rbce) {
143
143
  rb_gc_mark(rbce->debug_proc);
144
144
  rb_gc_mark(rbce->interface_hm);
145
145
  rb_gc_mark(rbce->userpwd);
146
+ rb_gc_mark(rbce->username);
147
+ rb_gc_mark(rbce->password);
146
148
  rb_gc_mark(rbce->proxypwd);
147
149
  rb_gc_mark(rbce->headers);
148
150
  rb_gc_mark(rbce->cookies);
@@ -162,10 +164,6 @@ void curl_easy_mark(ruby_curl_easy *rbce) {
162
164
  rb_gc_mark(rbce->bodybuf);
163
165
  rb_gc_mark(rbce->headerbuf);
164
166
 
165
- if( rbce->self != Qnil ) {
166
- rb_gc_mark(rbce->self);
167
- }
168
-
169
167
  if( rbce->upload != Qnil ) {
170
168
  rb_gc_mark(rbce->upload);
171
169
  }
@@ -216,6 +214,8 @@ static VALUE ruby_curl_easy_new(int argc, VALUE *argv, VALUE klass) {
216
214
  rbce->debug_proc = Qnil;
217
215
  rbce->interface_hm = Qnil;
218
216
  rbce->userpwd = Qnil;
217
+ rbce->username = Qnil;
218
+ rbce->password = Qnil;
219
219
  rbce->proxypwd = Qnil;
220
220
  rbce->headers = rb_hash_new();
221
221
  rbce->cookies = Qnil;
@@ -263,13 +263,12 @@ static VALUE ruby_curl_easy_new(int argc, VALUE *argv, VALUE klass) {
263
263
  rbce->headerbuf = Qnil;
264
264
  rbce->curl_headers = NULL;
265
265
 
266
- rbce->self = Qnil;
267
266
  rbce->upload = Qnil;
268
267
 
269
268
  new_curl = Data_Wrap_Struct(klass, curl_easy_mark, curl_easy_free, rbce);
270
269
 
271
- /* set the rbce pointer to the curl handle */
272
- ecode = curl_easy_setopt(rbce->curl, CURLOPT_PRIVATE, (void*)rbce);
270
+ /* set the new_curl pointer to the curl handle */
271
+ ecode = curl_easy_setopt(rbce->curl, CURLOPT_PRIVATE, (void*)new_curl);
273
272
  if (ecode != CURLE_OK) {
274
273
  raise_curl_easy_error_exception(ecode);
275
274
  }
@@ -877,16 +876,61 @@ static VALUE ruby_curl_easy_proxy_type_get(VALUE self) {
877
876
  CURB_IMMED_GETTER(ruby_curl_easy, proxy_type, -1);
878
877
  }
879
878
 
879
+ #if defined(HAVE_CURLAUTH_DIGEST_IE)
880
+ #define CURL_HTTPAUTH_STR_TO_NUM(node) \
881
+ (!strncmp("basic",node,5)) ? CURLAUTH_BASIC : \
882
+ (!strncmp("digest_ie",node,9)) ? CURLAUTH_DIGEST_IE : \
883
+ (!strncmp("digest",node,6)) ? CURLAUTH_DIGEST : \
884
+ (!strncmp("gssnegotiate",node,12)) ? CURLAUTH_GSSNEGOTIATE : \
885
+ (!strncmp("ntlm",node,4)) ? CURLAUTH_NTLM : \
886
+ (!strncmp("any",node,3)) ? CURLAUTH_ANY : \
887
+ (!strncmp("anysafe",node,7)) ? CURLAUTH_ANYSAFE : 0
888
+ #else
889
+ #define CURL_HTTPAUTH_STR_TO_NUM(node) \
890
+ (!strncmp("basic",node,5)) ? CURLAUTH_BASIC : \
891
+ (!strncmp("digest",node,6)) ? CURLAUTH_DIGEST : \
892
+ (!strncmp("gssnegotiate",node,12)) ? CURLAUTH_GSSNEGOTIATE : \
893
+ (!strncmp("ntlm",node,4)) ? CURLAUTH_NTLM : \
894
+ (!strncmp("any",node,3)) ? CURLAUTH_ANY : \
895
+ (!strncmp("anysafe",node,7)) ? CURLAUTH_ANYSAFE : 0
896
+ #endif
880
897
  /*
881
898
  * call-seq:
882
899
  * easy.http_auth_types = fixnum or nil => fixnum or nil
900
+ * easy.http_auth_types = [:basic,:digest,:digest_ie,:gssnegotiate, :ntlm, :any, :anysafe]
883
901
  *
884
902
  * Set the HTTP authentication types that may be used for the following
885
903
  * +perform+ calls. This is a bitmap made by ORing together the
886
904
  * Curl::CURLAUTH constants.
887
905
  */
888
- static VALUE ruby_curl_easy_http_auth_types_set(VALUE self, VALUE http_auth_types) {
889
- CURB_IMMED_SETTER(ruby_curl_easy, http_auth_types, 0);
906
+ static VALUE ruby_curl_easy_http_auth_types_set(int argc, VALUE *argv, VALUE self) {//VALUE self, VALUE http_auth_types) {
907
+ ruby_curl_easy *rbce;
908
+ VALUE args_ary;
909
+ rb_scan_args(argc, argv, "*", &args_ary);
910
+ Data_Get_Struct(self, ruby_curl_easy, rbce);
911
+ int i, len = RARRAY_LEN(args_ary);
912
+ char* node = NULL;
913
+ long mask = 0x000000;
914
+
915
+ if (len == 1 && (TYPE(rb_ary_entry(args_ary,0)) == T_FIXNUM || rb_ary_entry(args_ary,0) == Qnil)) {
916
+ if (rb_ary_entry(args_ary,0) == Qnil) {
917
+ rbce->http_auth_types = 0;
918
+ }
919
+ else {
920
+ rbce->http_auth_types = NUM2INT(rb_ary_entry(args_ary,0));
921
+ }
922
+ }
923
+ else {
924
+ // we could have multiple values, but they should be symbols
925
+ node = RSTRING_PTR(rb_funcall(rb_ary_entry(args_ary,0),rb_intern("to_s"),0));
926
+ mask = CURL_HTTPAUTH_STR_TO_NUM(node);
927
+ for( i = 1; i < len; ++i ) {
928
+ node = RSTRING_PTR(rb_funcall(rb_ary_entry(args_ary,i),rb_intern("to_s"),0));
929
+ mask |= CURL_HTTPAUTH_STR_TO_NUM(node);
930
+ }
931
+ rbce->http_auth_types = mask;
932
+ }
933
+ return INT2NUM(rbce->http_auth_types);
890
934
  }
891
935
 
892
936
  /*
@@ -1052,6 +1096,22 @@ static VALUE ruby_curl_easy_ftp_response_timeout_get(VALUE self, VALUE ftp_respo
1052
1096
  CURB_IMMED_GETTER(ruby_curl_easy, ftp_response_timeout, 0);
1053
1097
  }
1054
1098
 
1099
+ static VALUE ruby_curl_easy_username_set(VALUE self, VALUE username) {
1100
+ CURB_OBJECT_SETTER(ruby_curl_easy, username);
1101
+ }
1102
+
1103
+ static VALUE ruby_curl_easy_username_get(VALUE self, VALUE username) {
1104
+ CURB_OBJECT_GETTER(ruby_curl_easy, username);
1105
+ }
1106
+
1107
+ static VALUE ruby_curl_easy_password_set(VALUE self, VALUE password) {
1108
+ CURB_OBJECT_SETTER(ruby_curl_easy, password);
1109
+ }
1110
+
1111
+ static VALUE ruby_curl_easy_password_get(VALUE self, VALUE password) {
1112
+ CURB_OBJECT_GETTER(ruby_curl_easy, password);
1113
+ }
1114
+
1055
1115
  /* ================== BOOL ATTRS ===================*/
1056
1116
 
1057
1117
  /*
@@ -1340,7 +1400,7 @@ static VALUE ruby_curl_easy_on_body_set(int argc, VALUE *argv, VALUE self) {
1340
1400
 
1341
1401
  /*
1342
1402
  * call-seq:
1343
- * easy.on_success { ... } => &lt;old handler&gt;
1403
+ * easy.on_success { |easy| ... } => &lt;old handler&gt;
1344
1404
  *
1345
1405
  * Assign or remove the +on_success+ handler for this Curl::Easy instance.
1346
1406
  * To remove a previously-supplied handler, call this method with no
@@ -1355,7 +1415,7 @@ static VALUE ruby_curl_easy_on_success_set(int argc, VALUE *argv, VALUE self) {
1355
1415
 
1356
1416
  /*
1357
1417
  * call-seq:
1358
- * easy.on_failure { ... } => &lt;old handler&gt;
1418
+ * easy.on_failure {|easy,code| ... } => &lt;old handler&gt;
1359
1419
  *
1360
1420
  * Assign or remove the +on_failure+ handler for this Curl::Easy instance.
1361
1421
  * To remove a previously-supplied handler, call this method with no
@@ -1370,7 +1430,7 @@ static VALUE ruby_curl_easy_on_failure_set(int argc, VALUE *argv, VALUE self) {
1370
1430
 
1371
1431
  /*
1372
1432
  * call-seq:
1373
- * easy.on_complete { ... } => &lt;old handler&gt;
1433
+ * easy.on_complete {|easy| ... } => &lt;old handler&gt;
1374
1434
  *
1375
1435
  * Assign or remove the +on_complete+ handler for this Curl::Easy instance.
1376
1436
  * To remove a previously-supplied handler, call this method with no
@@ -1501,9 +1561,23 @@ VALUE ruby_curl_easy_setup( ruby_curl_easy *rbce, VALUE *body_buffer, VALUE *hea
1501
1561
  curl_easy_setopt(curl, CURLOPT_INTERFACE, NULL);
1502
1562
  }
1503
1563
 
1564
+ #if HAVE_CURLOPT_USERNAME == 1 && HAVE_CURLOPT_PASSWORD == 1
1565
+ if (rbce->username != Qnil) {
1566
+ curl_easy_setopt(curl, CURLOPT_USERNAME, StringValuePtr(rbce->username));
1567
+ } else {
1568
+ curl_easy_setopt(curl, CURLOPT_USERNAME, NULL);
1569
+ }
1570
+ if (rbce->password != Qnil) {
1571
+ curl_easy_setopt(curl, CURLOPT_PASSWORD, StringValuePtr(rbce->password));
1572
+ }
1573
+ else {
1574
+ curl_easy_setopt(curl, CURLOPT_PASSWORD, NULL);
1575
+ }
1576
+ #endif
1577
+
1504
1578
  if (rbce->userpwd != Qnil) {
1505
1579
  curl_easy_setopt(curl, CURLOPT_USERPWD, StringValuePtr(rbce->userpwd));
1506
- } else {
1580
+ } else if (rbce->username == Qnil && rbce->password == Qnil) { /* don't set this even to NULL if we have set username and password */
1507
1581
  curl_easy_setopt(curl, CURLOPT_USERPWD, NULL);
1508
1582
  }
1509
1583
 
@@ -2636,7 +2710,7 @@ static VALUE ruby_curl_easy_escape(VALUE self, VALUE svalue) {
2636
2710
 
2637
2711
  /*
2638
2712
  * call-seq:
2639
- * easy.unescape("some text") => "some%20text"
2713
+ * easy.unescape("some%20text") => "some text"
2640
2714
  *
2641
2715
  * Convert the given URL encoded input string to a "plain string" and return
2642
2716
  * the result. All input characters that are URL encoded (%XX where XX is a
@@ -2837,7 +2911,7 @@ void init_curb_easy() {
2837
2911
  rb_define_method(cCurlEasy, "proxy_port", ruby_curl_easy_proxy_port_get, 0);
2838
2912
  rb_define_method(cCurlEasy, "proxy_type=", ruby_curl_easy_proxy_type_set, 1);
2839
2913
  rb_define_method(cCurlEasy, "proxy_type", ruby_curl_easy_proxy_type_get, 0);
2840
- rb_define_method(cCurlEasy, "http_auth_types=", ruby_curl_easy_http_auth_types_set, 1);
2914
+ rb_define_method(cCurlEasy, "http_auth_types=", ruby_curl_easy_http_auth_types_set, -1);
2841
2915
  rb_define_method(cCurlEasy, "http_auth_types", ruby_curl_easy_http_auth_types_get, 0);
2842
2916
  rb_define_method(cCurlEasy, "proxy_auth_types=", ruby_curl_easy_proxy_auth_types_set, 1);
2843
2917
  rb_define_method(cCurlEasy, "proxy_auth_types", ruby_curl_easy_proxy_auth_types_get, 0);
@@ -2852,6 +2926,11 @@ void init_curb_easy() {
2852
2926
  rb_define_method(cCurlEasy, "ftp_response_timeout=", ruby_curl_easy_ftp_response_timeout_set, 1);
2853
2927
  rb_define_method(cCurlEasy, "ftp_response_timeout", ruby_curl_easy_ftp_response_timeout_get, 0);
2854
2928
 
2929
+ rb_define_method(cCurlEasy, "username=", ruby_curl_easy_username_set, 1);
2930
+ rb_define_method(cCurlEasy, "username", ruby_curl_easy_username_get, 0);
2931
+ rb_define_method(cCurlEasy, "password=", ruby_curl_easy_password_set, 1);
2932
+ rb_define_method(cCurlEasy, "password", ruby_curl_easy_password_get, 0);
2933
+
2855
2934
  rb_define_method(cCurlEasy, "proxy_tunnel=", ruby_curl_easy_proxy_tunnel_set, 1);
2856
2935
  rb_define_method(cCurlEasy, "proxy_tunnel?", ruby_curl_easy_proxy_tunnel_q, 0);
2857
2936
  rb_define_method(cCurlEasy, "fetch_file_time=", ruby_curl_easy_fetch_file_time_set, 1);
@@ -86,11 +86,18 @@ typedef struct {
86
86
  VALUE headerbuf;
87
87
  struct curl_slist *curl_headers;
88
88
 
89
- VALUE self; /* pointer to self, used by multi interface */
89
+ // VALUE self; /* pointer to self, used by multi interface */
90
90
  VALUE upload; /* pointer to an active upload otherwise Qnil */
91
91
 
92
92
  int last_result; /* last result code from multi loop */
93
93
 
94
+ #if HAVE_CURLOPT_USERNAME == 1
95
+ VALUE username;
96
+ #endif
97
+ #if HAVE_CURLOPT_PASSWORD == 1
98
+ VALUE password;
99
+ #endif
100
+
94
101
  } ruby_curl_easy;
95
102
 
96
103
  extern VALUE cCurlEasy;
@@ -199,9 +199,6 @@ VALUE ruby_curl_multi_add(VALUE self, VALUE easy) {
199
199
  raise_curl_multi_error_exception(mcode);
200
200
  }
201
201
 
202
- /* save a pointer to self */
203
- rbce->self = easy;
204
-
205
202
  /* setup the easy handle */
206
203
  ruby_curl_easy_setup( rbce, &(rbce->bodybuf), &(rbce->headerbuf), &(rbce->curl_headers) );
207
204
 
@@ -263,7 +260,7 @@ static void rb_curl_multi_remove(ruby_curl_multi *rbcm, VALUE easy) {
263
260
  // active should equal INT2FIX(RHASH(rbcm->requests)->tbl->num_entries)
264
261
  r = rb_hash_delete( rbcm->requests, easy );
265
262
  if( r != easy || r == Qnil ) {
266
- rb_warn("Critical:: Unable to remove easy from requests");
263
+ rb_warn("Possibly lost track of Curl::Easy VALUE, it may not be reclaimed by GC");
267
264
  }
268
265
  }
269
266
 
@@ -287,16 +284,19 @@ static VALUE ruby_curl_multi_cancel(VALUE self) {
287
284
 
288
285
  rb_hash_foreach( rbcm->requests, ruby_curl_multi_cancel_callback, (VALUE)rbcm );
289
286
 
290
- // for chaining
287
+ /* for chaining */
291
288
  return self;
292
289
  }
293
290
 
294
291
  static void rb_curl_mutli_handle_complete(VALUE self, CURL *easy_handle, int result) {
295
292
 
296
293
  long response_code = -1;
294
+ VALUE easy;
297
295
  ruby_curl_easy *rbce = NULL;
298
- VALUE ref;
299
- CURLcode ecode = curl_easy_getinfo(easy_handle, CURLINFO_PRIVATE, (char**)&rbce);
296
+
297
+ CURLcode ecode = curl_easy_getinfo(easy_handle, CURLINFO_PRIVATE, (char**)&easy);
298
+
299
+ Data_Get_Struct(easy, ruby_curl_easy, rbce);
300
300
 
301
301
  if (ecode != 0) {
302
302
  raise_curl_easy_error_exception(ecode);
@@ -304,31 +304,27 @@ static void rb_curl_mutli_handle_complete(VALUE self, CURL *easy_handle, int res
304
304
 
305
305
  rbce->last_result = result; /* save the last easy result code */
306
306
 
307
- ruby_curl_multi_remove( self, rbce->self );
307
+ ruby_curl_multi_remove( self, easy );
308
308
 
309
309
  if (rbce->complete_proc != Qnil) {
310
- rb_funcall( rbce->complete_proc, idCall, 1, rbce->self );
310
+ rb_funcall( rbce->complete_proc, idCall, 1, easy );
311
311
  }
312
312
 
313
313
  curl_easy_getinfo(rbce->curl, CURLINFO_RESPONSE_CODE, &response_code);
314
314
 
315
- ref = rbce->self;
316
- /* break reference */
317
- rbce->self = Qnil;
318
-
319
315
  if (result != 0) {
320
316
  if (rbce->failure_proc != Qnil) {
321
- rb_funcall( rbce->failure_proc, idCall, 2, ref, rb_curl_easy_error(result) );
317
+ rb_funcall( rbce->failure_proc, idCall, 2, easy, rb_curl_easy_error(result) );
322
318
  }
323
319
  }
324
320
  else if (rbce->success_proc != Qnil &&
325
321
  ((response_code >= 200 && response_code < 300) || response_code == 0)) {
326
322
  /* NOTE: we allow response_code == 0, in the case of non http requests e.g. reading from disk */
327
- rb_funcall( rbce->success_proc, idCall, 1, ref );
323
+ rb_funcall( rbce->success_proc, idCall, 1, easy );
328
324
  }
329
325
  else if (rbce->failure_proc != Qnil &&
330
326
  (response_code >= 300 && response_code <= 999)) {
331
- rb_funcall( rbce->failure_proc, idCall, 2, ref, rb_curl_easy_error(result) );
327
+ rb_funcall( rbce->failure_proc, idCall, 2, easy, rb_curl_easy_error(result) );
332
328
  }
333
329
  }
334
330
 
@@ -111,6 +111,13 @@ have_constant "curle_again"
111
111
  have_constant "curle_ssl_crl_badfile"
112
112
  have_constant "curle_ssl_issuer_error"
113
113
 
114
+ # username/password added in 7.19.1
115
+ have_constant "curlopt_username"
116
+ have_constant "curlopt_password"
117
+
118
+ # ie quirk added in 7.19.3
119
+ have_constant "curlauth_digest_ie"
120
+
114
121
  # centos 4.5 build of libcurl
115
122
  have_constant "curlm_bad_socket"
116
123
  have_constant "curlm_unknown_option"
@@ -59,6 +59,7 @@ class TestServlet < WEBrick::HTTPServlet::AbstractServlet
59
59
 
60
60
  def respond_with(method,req,res)
61
61
  res.body = method.to_s
62
+ $auth_header = req['Authorization']
62
63
  res['Content-Type'] = "text/plain"
63
64
  end
64
65
 
@@ -655,6 +655,29 @@ class TestCurbCurlEasy < Test::Unit::TestCase
655
655
  assert /ScrubDog$/,curl.useragent
656
656
  end
657
657
 
658
+ def test_username_password
659
+ curl = Curl::Easy.new(TestServlet.url)
660
+ curl.username = "foo"
661
+ curl.password = "bar"
662
+ assert_equal "foo", curl.username
663
+ assert_equal "bar", curl.password
664
+ curl.http_auth_types = :basic
665
+ #curl.userpwd = "foo:bar"
666
+ #curl.verbose = true
667
+ curl.perform
668
+ assert_equal 'Basic Zm9vOmJhcg==', $auth_header
669
+
670
+ # curl checks the auth type supported by the server, so we have to create a
671
+ # new easy handle if we're going to change the auth type...
672
+
673
+ curl = Curl::Easy.new(TestServlet.url)
674
+ curl.username = "foo"
675
+ curl.password = "bar"
676
+ curl.http_auth_types = :ntlm
677
+ curl.perform
678
+ assert_equal 'NTLM TlRMTVNTUAABAAAABoIIAAAAAAAAAAAAAAAAAAAAAAA=', $auth_header
679
+ end
680
+
658
681
  include TestServerMethods
659
682
 
660
683
  def setup
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: curb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0.0
4
+ version: 0.6.2.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-11-27 00:00:00 -05:00
13
+ date: 2009-12-26 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies: []
16
16