taf2-curb 0.4.0.0 → 0.4.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/ext/curb_errors.h CHANGED
@@ -1,7 +1,7 @@
1
1
  /* curb_errors.h - Ruby exception types for curl errors
2
- * Copyright (c)2006 Ross Bamford.
2
+ * Copyright (c)2006 Ross Bamford.
3
3
  * Licensed under the Ruby License. See LICENSE for details.
4
- *
4
+ *
5
5
  * $Id: curb_errors.h 4 2006-11-17 18:35:31Z roscopeco $
6
6
  */
7
7
  #ifndef __CURB_ERRORS_H
data/ext/curb_multi.c CHANGED
@@ -1,7 +1,7 @@
1
1
  /* curb_easy.c - Curl easy mode
2
- * Copyright (c)2008 Todd A. Fisher.
2
+ * Copyright (c)2008 Todd A. Fisher.
3
3
  * Licensed under the Ruby License. See LICENSE for details.
4
- *
4
+ *
5
5
  * $Id$
6
6
  */
7
7
 
@@ -66,17 +66,18 @@ static void curl_multi_free(ruby_curl_multi *rbcm) {
66
66
  //rb_hash_clear(rbcm->requests)
67
67
  rbcm->requests = Qnil;
68
68
  }
69
+ free(rbcm);
69
70
  }
70
71
 
71
72
  /*
72
73
  * call-seq:
73
74
  * Curl::Multi.new => #<Curl::Easy...>
74
- *
75
+ *
75
76
  * Create a new Curl::Multi instance
76
77
  */
77
- static VALUE ruby_curl_multi_new(VALUE self) {
78
+ static VALUE ruby_curl_multi_new(VALUE klass) {
78
79
  VALUE new_curlm;
79
-
80
+
80
81
  ruby_curl_multi *rbcm = ALLOC(ruby_curl_multi);
81
82
 
82
83
  rbcm->handle = curl_multi_init();
@@ -85,8 +86,8 @@ static VALUE ruby_curl_multi_new(VALUE self) {
85
86
 
86
87
  rbcm->active = 0;
87
88
  rbcm->running = 0;
88
-
89
- new_curlm = Data_Wrap_Struct(cCurlMulti, curl_multi_mark, curl_multi_free, rbcm);
89
+
90
+ new_curlm = Data_Wrap_Struct(klass, curl_multi_mark, curl_multi_free, rbcm);
90
91
 
91
92
  return new_curlm;
92
93
  }
@@ -179,7 +180,7 @@ static VALUE ruby_curl_multi_add(VALUE self, VALUE easy) {
179
180
  * easy = Curl::Easy.new('url')
180
181
  *
181
182
  * multi.add(easy)
182
- *
183
+ *
183
184
  * # sometime later
184
185
  * multi.remove(easy)
185
186
  *
@@ -203,7 +204,7 @@ static void rb_curl_multi_remove(ruby_curl_multi *rbcm, VALUE easy) {
203
204
  CURLMcode result;
204
205
  ruby_curl_easy *rbce;
205
206
  Data_Get_Struct(easy, ruby_curl_easy, rbce);
206
-
207
+
207
208
  rbcm->active--;
208
209
 
209
210
  //printf( "calling rb_curl_multi_remove: 0x%X, active: %d\n", (long)easy, rbcm->active );
@@ -212,7 +213,7 @@ static void rb_curl_multi_remove(ruby_curl_multi *rbcm, VALUE easy) {
212
213
  if (result != 0) {
213
214
  raise_curl_multi_error_exception(result);
214
215
  }
215
-
216
+
216
217
  ruby_curl_easy_cleanup( easy, rbce, rbce->bodybuf, rbce->headerbuf, rbce->curl_headers );
217
218
  rbce->headerbuf = Qnil;
218
219
  rbce->bodybuf = Qnil;
@@ -253,7 +254,7 @@ static void rb_curl_multi_read_info(VALUE self, CURLM *multi_handle) {
253
254
 
254
255
  long response_code = -1;
255
256
  curl_easy_getinfo(rbce->curl, CURLINFO_RESPONSE_CODE, &response_code);
256
-
257
+
257
258
  if (result != 0) {
258
259
  if (rbce->failure_proc != Qnil) {
259
260
  rb_funcall( rbce->failure_proc, idCall, 2, rbce->self, INT2FIX(result) );
@@ -320,7 +321,7 @@ static VALUE ruby_curl_multi_perform(VALUE self) {
320
321
 
321
322
  rb_curl_multi_run( self, rbcm->handle, &(rbcm->running) );
322
323
 
323
- while(rbcm->running) {
324
+ while(rbcm->running) {
324
325
  FD_ZERO(&fdread);
325
326
  FD_ZERO(&fdwrite);
326
327
  FD_ZERO(&fdexcep);
@@ -331,7 +332,7 @@ static VALUE ruby_curl_multi_perform(VALUE self) {
331
332
  raise_curl_multi_error_exception(mcode);
332
333
  }
333
334
 
334
- #ifdef HAVE_CURL_MULTI_TIMEOUT
335
+ #ifdef HAVE_CURL_MULTI_TIMEOUT
335
336
  /* get the curl suggested time out */
336
337
  mcode = curl_multi_timeout(rbcm->handle, &timeout);
337
338
  if (mcode != CURLM_OK) {
@@ -353,7 +354,7 @@ static VALUE ruby_curl_multi_perform(VALUE self) {
353
354
  if (rb_block_given_p()) {
354
355
  rb_yield(self);
355
356
  }
356
-
357
+
357
358
  tv.tv_sec = timeout / 1000;
358
359
  tv.tv_usec = (timeout * 1000) % 1000000;
359
360
 
@@ -376,7 +377,7 @@ void init_curb_multi() {
376
377
  cCurlMulti = rb_define_class_under(mCurl, "Multi", rb_cObject);
377
378
 
378
379
  /* Class methods */
379
- rb_define_singleton_method(cCurlMulti, "new", ruby_curl_multi_new, -1);
380
+ rb_define_singleton_method(cCurlMulti, "new", ruby_curl_multi_new, 0);
380
381
 
381
382
  /* Instnace methods */
382
383
  rb_define_method(cCurlMulti, "max_connects=", ruby_curl_multi_max_connects, 1);
data/ext/curb_multi.h CHANGED
@@ -1,7 +1,7 @@
1
1
  /* curb_multi.h - Curl easy mode
2
- * Copyright (c)2008 Todd A. Fisher.
2
+ * Copyright (c)2008 Todd A. Fisher.
3
3
  * Licensed under the Ruby License. See LICENSE for details.
4
- *
4
+ *
5
5
  * $Id$
6
6
  */
7
7
  #ifndef __CURB_MULTI_H
data/ext/curb_upload.c ADDED
@@ -0,0 +1,56 @@
1
+ /* curb_upload.c - Curl upload handle
2
+ * Copyright (c)2009 Todd A Fisher.
3
+ * Licensed under the Ruby License. See LICENSE for details.
4
+ */
5
+ #include "curb_upload.h"
6
+ extern VALUE mCurl;
7
+ VALUE cCurlUpload;
8
+
9
+ static void curl_upload_mark(ruby_curl_upload *rbcu) {
10
+ if (rbcu->stream) rb_gc_mark(rbcu->stream);
11
+ }
12
+ static void curl_upload_free(ruby_curl_upload *rbcu) {
13
+ free(rbcu);
14
+ }
15
+
16
+ VALUE ruby_curl_upload_new(VALUE klass) {
17
+ VALUE upload;
18
+ ruby_curl_upload *rbcu = ALLOC(ruby_curl_upload);
19
+ rbcu->stream = Qnil;
20
+ rbcu->offset = 0;
21
+ upload = Data_Wrap_Struct(klass, curl_upload_mark, curl_upload_free, rbcu);
22
+ return upload;
23
+ }
24
+
25
+ VALUE ruby_curl_upload_stream_set(VALUE self, VALUE stream) {
26
+ ruby_curl_upload *rbcu;
27
+ Data_Get_Struct(self, ruby_curl_upload, rbcu);
28
+ rbcu->stream = stream;
29
+ return stream;
30
+ }
31
+ VALUE ruby_curl_upload_stream_get(VALUE self) {
32
+ ruby_curl_upload *rbcu;
33
+ Data_Get_Struct(self, ruby_curl_upload, rbcu);
34
+ return rbcu->stream;
35
+ }
36
+ VALUE ruby_curl_upload_offset_set(VALUE self, VALUE offset) {
37
+ ruby_curl_upload *rbcu;
38
+ Data_Get_Struct(self, ruby_curl_upload, rbcu);
39
+ rbcu->offset = FIX2INT(offset);
40
+ return offset;
41
+ }
42
+ VALUE ruby_curl_upload_offset_get(VALUE self) {
43
+ ruby_curl_upload *rbcu;
44
+ Data_Get_Struct(self, ruby_curl_upload, rbcu);
45
+ return INT2FIX(rbcu->offset);
46
+ }
47
+
48
+ /* =================== INIT LIB =====================*/
49
+ void init_curb_upload() {
50
+ cCurlUpload = rb_define_class_under(mCurl, "Upload", rb_cObject);
51
+ rb_define_singleton_method(cCurlUpload, "new", ruby_curl_upload_new, 0);
52
+ rb_define_method(cCurlUpload, "stream=", ruby_curl_upload_stream_set, 1);
53
+ rb_define_method(cCurlUpload, "stream", ruby_curl_upload_stream_get, 0);
54
+ rb_define_method(cCurlUpload, "offset=", ruby_curl_upload_offset_set, 1);
55
+ rb_define_method(cCurlUpload, "offset", ruby_curl_upload_offset_get, 0);
56
+ }
data/ext/curb_upload.h ADDED
@@ -0,0 +1,30 @@
1
+ /* curb_upload.h - Curl upload handle
2
+ * Copyright (c)2009 Todd A Fisher.
3
+ * Licensed under the Ruby License. See LICENSE for details.
4
+ */
5
+ #ifndef __CURB_UPLOAD_H
6
+ #define __CURB_UPLOAD_H
7
+
8
+ #include "curb.h"
9
+
10
+ #include <curl/easy.h>
11
+
12
+ /*
13
+ * Maintain the state of an upload e.g. for putting large streams with very little memory
14
+ * out to a server. via PUT requests
15
+ */
16
+ typedef struct {
17
+ VALUE stream;
18
+ size_t offset;
19
+ } ruby_curl_upload;
20
+
21
+ extern VALUE cCurlUpload;
22
+ void init_curb_upload();
23
+
24
+ VALUE ruby_curl_upload_new(VALUE klass);
25
+ VALUE ruby_curl_upload_stream_set(VALUE self, VALUE stream);
26
+ VALUE ruby_curl_upload_stream_get(VALUE self);
27
+ VALUE ruby_curl_upload_offset_set(VALUE self, VALUE offset);
28
+ VALUE ruby_curl_upload_offset_get(VALUE self);
29
+
30
+ #endif
data/lib/curb.rb CHANGED
@@ -45,4 +45,3 @@ module Curl
45
45
  end
46
46
  end
47
47
  end
48
-
@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), 'helper')
2
2
 
3
3
  class TestCurbCurlEasy < Test::Unit::TestCase
4
4
  def test_class_perform_01
5
- assert_instance_of Curl::Easy, c = Curl::Easy.perform($TEST_URL)
5
+ assert_instance_of Curl::Easy, c = Curl::Easy.perform($TEST_URL)
6
6
  assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body_str)
7
7
  assert_equal "", c.header_str
8
8
  end
@@ -22,6 +22,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
22
22
 
23
23
  def test_new_01
24
24
  c = Curl::Easy.new
25
+ assert_equal Curl::Easy, c.class
25
26
  assert_nil c.url
26
27
  assert_nil c.body_str
27
28
  assert_nil c.header_str
@@ -54,8 +55,19 @@ class TestCurbCurlEasy < Test::Unit::TestCase
54
55
  assert_equal $TEST_URL, c.url
55
56
  assert_equal blk, c.on_body # sets handler nil, returns old handler
56
57
  assert_equal nil, c.on_body
57
- end
58
-
58
+ end
59
+
60
+ class Foo < Curl::Easy
61
+ end
62
+ def test_new_05
63
+ # can use Curl::Easy as a base class
64
+ c = Foo.new
65
+ assert_equal Foo, c.class
66
+ c.url = $TEST_URL
67
+ c.perform
68
+ assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body_str)
69
+ end
70
+
59
71
  def test_escape
60
72
  c = Curl::Easy.new
61
73
 
@@ -525,6 +537,14 @@ class TestCurbCurlEasy < Test::Unit::TestCase
525
537
  assert_match /message$/, curl.body_str
526
538
  end
527
539
 
540
+ def test_put_remote_file
541
+ curl = Curl::Easy.new(TestServlet.url)
542
+ File.open(__FILE__,'r') do|f|
543
+ assert curl.http_put(f)
544
+ end
545
+ assert_equal "PUT\n#{File.read(__FILE__)}", curl.body_str
546
+ end
547
+
528
548
  include TestServerMethods
529
549
 
530
550
  def setup
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.0.0
4
+ version: 0.4.1.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-06-17 00:00:00 -07:00
13
+ date: 2009-06-19 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
 
@@ -36,8 +36,10 @@ files:
36
36
  - ext/curb_multi.c
37
37
  - ext/curb_errors.c
38
38
  - ext/curb_easy.c
39
+ - ext/curb_upload.c
39
40
  - ext/curb_easy.h
40
41
  - ext/curb_errors.h
42
+ - ext/curb_upload.h
41
43
  - ext/curb_macros.h
42
44
  - ext/curb.h
43
45
  - ext/curb_postfield.h