curb 0.7.9 → 0.7.10

Sign up to get free protection for your applications and to get access to all the features.
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.7.9"
24
- #define CURB_VER_NUM 790
23
+ #define CURB_VERSION "0.7.10"
24
+ #define CURB_VER_NUM 710
25
25
  #define CURB_VER_MAJ 0
26
26
  #define CURB_VER_MIN 7
27
- #define CURB_VER_MIC 9
27
+ #define CURB_VER_MIC 1
28
28
  #define CURB_VER_PATCH 0
29
29
 
30
30
 
@@ -753,8 +753,18 @@ static VALUE ruby_curl_easy_post_body_set(VALUE self, VALUE post_body) {
753
753
  rb_easy_del("postdata_buffer");
754
754
 
755
755
  } else {
756
- data = StringValuePtr(post_body);
757
- len = RSTRING_LEN(post_body);
756
+ if (rb_type(post_body) == T_STRING) {
757
+ data = StringValuePtr(post_body);
758
+ len = RSTRING_LEN(post_body);
759
+ }
760
+ else if (rb_respond_to(post_body, rb_intern("to_s"))) {
761
+ VALUE str_body = rb_funcall(post_body, rb_intern("to_s"), 0);
762
+ data = StringValuePtr(str_body);
763
+ len = RSTRING_LEN(post_body);
764
+ }
765
+ else {
766
+ rb_raise(rb_eRuntimeError, "post data must respond_to .to_s");
767
+ }
758
768
 
759
769
  // Store the string, since it has to hang around for the duration of the
760
770
  // request. See CURLOPT_POSTFIELDS in the libcurl docs.
@@ -2141,6 +2151,7 @@ VALUE ruby_curl_easy_setup( ruby_curl_easy *rbce ) {
2141
2151
  VALUE ruby_curl_easy_cleanup( VALUE self, ruby_curl_easy *rbce ) {
2142
2152
 
2143
2153
  CURL *curl = rbce->curl;
2154
+ struct curl_slist *ftp_commands;
2144
2155
 
2145
2156
  /* Free everything up */
2146
2157
  if (rbce->curl_headers) {
@@ -2148,7 +2159,7 @@ VALUE ruby_curl_easy_cleanup( VALUE self, ruby_curl_easy *rbce ) {
2148
2159
  rbce->curl_headers = NULL;
2149
2160
  }
2150
2161
 
2151
- struct curl_slist *ftp_commands = rbce->curl_ftp_commands;
2162
+ ftp_commands = rbce->curl_ftp_commands;
2152
2163
  if (ftp_commands) {
2153
2164
  curl_slist_free_all(ftp_commands);
2154
2165
  rbce->curl_ftp_commands = NULL;
@@ -19,6 +19,11 @@
19
19
 
20
20
  #include <errno.h>
21
21
 
22
+ #ifdef _WIN32
23
+ // for O_RDWR and O_BINARY
24
+ #include <fcntl.h>
25
+ #endif
26
+
22
27
  extern VALUE mCurl;
23
28
  static VALUE idCall;
24
29
 
@@ -396,6 +401,35 @@ static void rb_curl_multi_run(VALUE self, CURLM *multi_handle, int *still_runnin
396
401
 
397
402
  }
398
403
 
404
+ #ifdef _WIN32
405
+ void create_crt_fd(fd_set *os_set, fd_set *crt_set)
406
+ {
407
+ int i;
408
+ crt_set->fd_count = os_set->fd_count;
409
+ for (i = 0; i < os_set->fd_count; i++) {
410
+ WSAPROTOCOL_INFO wsa_pi;
411
+ // dupicate the SOCKET
412
+ int r = WSADuplicateSocket(os_set->fd_array[i], GetCurrentProcessId(), &wsa_pi);
413
+ SOCKET s = WSASocket(wsa_pi.iAddressFamily, wsa_pi.iSocketType, wsa_pi.iProtocol, &wsa_pi, 0, 0);
414
+ // create the CRT fd so ruby can get back to the SOCKET
415
+ int fd = _open_osfhandle(s, O_RDWR|O_BINARY);
416
+ os_set->fd_array[i] = s;
417
+ crt_set->fd_array[i] = fd;
418
+ }
419
+ }
420
+
421
+ void cleanup_crt_fd(fd_set *os_set, fd_set *crt_set)
422
+ {
423
+ int i;
424
+ for (i = 0; i < os_set->fd_count; i++) {
425
+ // cleanup the CRT fd
426
+ _close(crt_set->fd_array[i]);
427
+ // cleanup the duplicated SOCKET
428
+ closesocket(os_set->fd_array[i]);
429
+ }
430
+ }
431
+ #endif
432
+
399
433
  /*
400
434
  * call-seq:
401
435
  * multi = Curl::Multi.new
@@ -416,6 +450,9 @@ VALUE ruby_curl_multi_perform(int argc, VALUE *argv, VALUE self) {
416
450
  ruby_curl_multi *rbcm;
417
451
  int maxfd, rc;
418
452
  fd_set fdread, fdwrite, fdexcep;
453
+ #ifdef _WIN32
454
+ fd_set crt_fdread, crt_fdwrite, crt_fdexcep;
455
+ #endif
419
456
 
420
457
  long timeout_milliseconds;
421
458
  struct timeval tv = {0, 0};
@@ -474,7 +511,20 @@ VALUE ruby_curl_multi_perform(int argc, VALUE *argv, VALUE self) {
474
511
  raise_curl_multi_error_exception(mcode);
475
512
  }
476
513
 
514
+ #ifdef _WIN32
515
+ create_crt_fd(&fdread, &crt_fdread);
516
+ create_crt_fd(&fdwrite, &crt_fdwrite);
517
+ create_crt_fd(&fdexcep, &crt_fdexcep);
518
+ #endif
519
+
477
520
  rc = rb_thread_select(maxfd+1, &fdread, &fdwrite, &fdexcep, &tv);
521
+
522
+ #ifdef _WIN32
523
+ cleanup_crt_fd(&fdread, &crt_fdread);
524
+ cleanup_crt_fd(&fdwrite, &crt_fdwrite);
525
+ cleanup_crt_fd(&fdexcep, &crt_fdexcep);
526
+ #endif
527
+
478
528
  switch(rc) {
479
529
  case -1:
480
530
  rb_raise(rb_eRuntimeError, "select(): %s", strerror(errno));
@@ -213,7 +213,7 @@ static VALUE ruby_curl_postfield_new_content(int argc, VALUE *argv, VALUE klass)
213
213
  // wierdness - we actually require two args, unless a block is provided, but
214
214
  // we have to work that out below.
215
215
  rb_scan_args(argc, argv, "12&", &rbcpf->name, &rbcpf->content, &rbcpf->content_type, &rbcpf->content_proc);
216
-
216
+
217
217
  // special handling if theres a block, second arg is actually content_type
218
218
  if (rbcpf->content_proc != Qnil) {
219
219
  if (rbcpf->content != Qnil) {
@@ -425,6 +425,7 @@ static VALUE ruby_curl_postfield_to_str(VALUE self) {
425
425
  ruby_curl_postfield *rbcpf;
426
426
  VALUE result = Qnil;
427
427
  VALUE name = Qnil;
428
+ char *tmpchrs;
428
429
 
429
430
  Data_Get_Struct(self, ruby_curl_postfield, rbcpf);
430
431
 
@@ -443,7 +444,7 @@ static VALUE ruby_curl_postfield_to_str(VALUE self) {
443
444
  rb_raise(eCurlErrInvalidPostField, "Cannot convert unnamed field to string %s:%d, make sure your field name responds_to :to_s", __FILE__, __LINE__);
444
445
  }
445
446
 
446
- char *tmpchrs = curl_escape(StringValuePtr(name), (int)RSTRING_LEN(name));
447
+ tmpchrs = curl_escape(StringValuePtr(name), (int)RSTRING_LEN(name));
447
448
 
448
449
  if (!tmpchrs) {
449
450
  rb_raise(eCurlErrInvalidPostField, "Failed to url-encode name `%s'", tmpchrs);
@@ -565,8 +565,8 @@ class TestCurbCurlEasy < Test::Unit::TestCase
565
565
 
566
566
  def test_post_remote
567
567
  curl = Curl::Easy.new(TestServlet.url)
568
- curl.http_post
569
- assert_equal "POST\n", curl.body_str
568
+ curl.http_post([Curl::PostField.content('document_id', 5)])
569
+ assert_equal "POST\ndocument%5Fid=5", curl.body_str
570
570
  end
571
571
 
572
572
  def test_post_remote_is_easy_handle
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: curb
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
- - 9
10
- version: 0.7.9
9
+ - 10
10
+ version: 0.7.10
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ross Bamford
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-12-22 00:00:00 -05:00
19
+ date: 2011-01-20 00:00:00 -05:00
20
20
  default_executable:
21
21
  dependencies: []
22
22