curb 0.1.0 → 0.1.2

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/Rakefile CHANGED
@@ -289,7 +289,7 @@ task :tag => [:prerelease] do
289
289
  s = `svn info`
290
290
  if s =~ /URL:\s*([^\n]*)\n/
291
291
  svnroot = $1
292
- if svnroot =~ /^(.*)\/trunk/
292
+ if svnroot =~ /^(.*)\/trunk/i
293
293
  svnbase = $1
294
294
  sh %{svn cp #{svnroot} #{svnbase}/TAGS/#{reltag} -m "Release #{PKG_VERSION}"}
295
295
  else
data/ext/curb.c CHANGED
@@ -222,16 +222,19 @@ void Init_curb_core() {
222
222
  // TODO we need to call curl_global_cleanup at exit!
223
223
  curl_global_init(CURL_GLOBAL_ALL);
224
224
  curl_version_info_data *ver = curl_version_info(CURLVERSION_NOW);
225
- VALUE curlver, curllongver;
225
+ VALUE curlver, curllongver, curlvernum;
226
226
 
227
227
  mCurl = rb_define_module("Curl");
228
228
 
229
229
  curlver = rb_str_new2(ver->version);
230
230
  curllongver = rb_str_new2(curl_version());
231
+ curlvernum = LONG2NUM(LIBCURL_VERSION_NUM);
231
232
 
232
233
  rb_define_const(mCurl, "CURB_VERSION", rb_str_new2(CURB_VERSION));
233
234
  rb_define_const(mCurl, "VERSION", curlver);
234
235
  rb_define_const(mCurl, "CURL_VERSION", curlver);
236
+ rb_define_const(mCurl, "VERNUM", curlvernum);
237
+ rb_define_const(mCurl, "CURL_VERNUM", curlvernum);
235
238
  rb_define_const(mCurl, "LONG_VERSION", curllongver);
236
239
  rb_define_const(mCurl, "CURL_LONG_VERSION", curllongver);
237
240
 
data/ext/curb.h CHANGED
@@ -18,11 +18,11 @@
18
18
  #include "curb_macros.h"
19
19
 
20
20
  // These should be managed from the Rake 'release' task.
21
- #define CURB_VERSION "0.1.0"
22
- #define CURB_VER_NUM 100
21
+ #define CURB_VERSION "0.1.2"
22
+ #define CURB_VER_NUM 120
23
23
  #define CURB_VER_MAJ 0
24
24
  #define CURB_VER_MIN 1
25
- #define CURB_VER_MIC 0
25
+ #define CURB_VER_MIC 2
26
26
  #define CURB_VER_PATCH 0
27
27
 
28
28
 
@@ -8,6 +8,8 @@
8
8
  #include "curb_errors.h"
9
9
  #include "curb_postfield.h"
10
10
 
11
+ #include <string.h>
12
+
11
13
  extern VALUE mCurl;
12
14
 
13
15
  static VALUE idCall;
@@ -78,6 +80,7 @@ static int proc_debug_handler(CURL *curl,
78
80
  /* ================== MARK/FREE FUNC ==================*/
79
81
  void curl_easy_mark(ruby_curl_easy *rbce) {
80
82
  rb_gc_mark(rbce->url);
83
+ rb_gc_mark(rbce->proxy_url);
81
84
  rb_gc_mark(rbce->body_proc);
82
85
  rb_gc_mark(rbce->body_data);
83
86
  rb_gc_mark(rbce->header_proc);
@@ -86,7 +89,7 @@ void curl_easy_mark(ruby_curl_easy *rbce) {
86
89
  rb_gc_mark(rbce->debug_proc);
87
90
  rb_gc_mark(rbce->interface);
88
91
  rb_gc_mark(rbce->userpwd);
89
- rb_gc_mark(rbce->proxypwd);
92
+ rb_gc_mark(rbce->proxypwd);
90
93
  rb_gc_mark(rbce->headers);
91
94
  rb_gc_mark(rbce->cookiejar);
92
95
 
@@ -124,13 +127,13 @@ static VALUE ruby_curl_easy_new(int argc, VALUE *argv, VALUE klass) {
124
127
 
125
128
  /* assoc objects */
126
129
  rbce->url = url;
130
+ rbce->proxy_url = Qnil;
127
131
  rbce->body_data = Qnil;
128
132
  rbce->body_proc = Qnil;
129
133
  rbce->header_data = Qnil;
130
134
  rbce->header_proc = Qnil;
131
135
  rbce->progress_proc = Qnil;
132
136
  rbce->debug_proc = Qnil;
133
- rbce->proxy_addr = Qnil;
134
137
  rbce->interface = Qnil;
135
138
  rbce->userpwd = Qnil;
136
139
  rbce->proxypwd = Qnil;
@@ -219,6 +222,45 @@ static VALUE ruby_curl_easy_url_get(VALUE self) {
219
222
  CURB_OBJECT_GETTER(ruby_curl_easy, url);
220
223
  }
221
224
 
225
+ /*
226
+ * call-seq:
227
+ * easy.proxy_url = "some.url" => "some.url"
228
+ *
229
+ * Set the URL of the HTTP proxy to use for subsequent calls to +perform+.
230
+ * The URL should specify the the host name or dotted IP address. To specify
231
+ * port number in this string, append :[port] to the end of the host name.
232
+ * The proxy string may be prefixed with [protocol]:// since any such prefix
233
+ * will be ignored. The proxy's port number may optionally be specified with
234
+ * the separate option proxy_port .
235
+ *
236
+ * When you tell the library to use an HTTP proxy, libcurl will transparently
237
+ * convert operations to HTTP even if you specify an FTP URL etc. This may have
238
+ * an impact on what other features of the library you can use, such as
239
+ * FTP specifics that don't work unless you tunnel through the HTTP proxy. Such
240
+ * tunneling is activated with proxy_tunnel = true.
241
+ *
242
+ * libcurl respects the environment variables *http_proxy*, *ftp_proxy*,
243
+ * *all_proxy* etc, if any of those is set. The proxy_url option does however
244
+ * override any possibly set environment variables.
245
+ *
246
+ * Starting with libcurl 7.14.1, the proxy host string given in environment
247
+ * variables can be specified the exact same way as the proxy can be set with
248
+ * proxy_url, including protocol prefix (http://) and embedded user + password.
249
+ */
250
+ static VALUE ruby_curl_easy_proxy_url_set(VALUE self, VALUE proxy_url) {
251
+ CURB_OBJECT_SETTER(ruby_curl_easy, proxy_url);
252
+ }
253
+
254
+ /*
255
+ * call-seq:
256
+ * easy.proxy_url => "some.url"
257
+ *
258
+ * Obtain the HTTP Proxy URL that will be used by subsequent calls to +perform+.
259
+ */
260
+ static VALUE ruby_curl_easy_proxy_url_get(VALUE self) {
261
+ CURB_OBJECT_GETTER(ruby_curl_easy, proxy_url);
262
+ }
263
+
222
264
  /*
223
265
  * call-seq:
224
266
  * easy.headers = "Header: val" => ["Header: val", ...]
@@ -1003,6 +1045,12 @@ static VALUE handle_perform(ruby_curl_easy *rbce) {
1003
1045
  curl_easy_setopt(curl, CURLOPT_USERPWD, NULL);
1004
1046
  }
1005
1047
 
1048
+ if (rbce->proxy_url != Qnil) {
1049
+ curl_easy_setopt(curl, CURLOPT_PROXY, StringValuePtr(rbce->proxy_url));
1050
+ } else {
1051
+ curl_easy_setopt(curl, CURLOPT_PROXY, NULL);
1052
+ }
1053
+
1006
1054
  if (rbce->proxypwd != Qnil) {
1007
1055
  curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, StringValuePtr(rbce->proxypwd));
1008
1056
  } else {
@@ -1904,7 +1952,12 @@ static VALUE ruby_curl_easy_escape(VALUE self, VALUE str) {
1904
1952
 
1905
1953
  Data_Get_Struct(self, ruby_curl_easy, rbce);
1906
1954
 
1955
+ #if (LIBCURL_VERSION_NUM >= 0x070f04)
1907
1956
  result = (char*)curl_easy_escape(rbce->curl, StringValuePtr(str), RSTRING_LEN(str));
1957
+ #else
1958
+ result = (char*)curl_escape(StringValuePtr(str), RSTRING_LEN(str));
1959
+ #endif
1960
+
1908
1961
  rresult = rb_str_new2(result);
1909
1962
  curl_free(result);
1910
1963
 
@@ -1927,7 +1980,13 @@ static VALUE ruby_curl_easy_unescape(VALUE self, VALUE str) {
1927
1980
 
1928
1981
  Data_Get_Struct(self, ruby_curl_easy, rbce);
1929
1982
 
1983
+ #if (LIBCURL_VERSION_NUM >= 0x070f04)
1930
1984
  result = (char*)curl_easy_unescape(rbce->curl, StringValuePtr(str), RSTRING_LEN(str), &rlen);
1985
+ #else
1986
+ result = (char*)curl_unescape(StringValuePtr(str), RSTRING_LEN(str));
1987
+ rlen = strlen(result);
1988
+ #endif
1989
+
1931
1990
  rresult = rb_str_new(result, rlen);
1932
1991
  curl_free(result);
1933
1992
 
@@ -2032,6 +2091,8 @@ void init_curb_easy() {
2032
2091
  /* Attributes for config next perform */
2033
2092
  rb_define_method(cCurlEasy, "url=", ruby_curl_easy_url_set, 1);
2034
2093
  rb_define_method(cCurlEasy, "url", ruby_curl_easy_url_get, 0);
2094
+ rb_define_method(cCurlEasy, "proxy_url=", ruby_curl_easy_proxy_url_set, 1);
2095
+ rb_define_method(cCurlEasy, "proxy_url", ruby_curl_easy_proxy_url_get, 0);
2035
2096
  rb_define_method(cCurlEasy, "headers=", ruby_curl_easy_headers_set, 1);
2036
2097
  rb_define_method(cCurlEasy, "headers", ruby_curl_easy_headers_get, 0);
2037
2098
  rb_define_method(cCurlEasy, "interface=", ruby_curl_easy_interface_set, 1);
@@ -20,7 +20,7 @@ typedef struct {
20
20
 
21
21
  /* Objects we associate */
22
22
  VALUE url;
23
- VALUE proxy_addr;
23
+ VALUE proxy_url;
24
24
 
25
25
  VALUE body_proc;
26
26
  VALUE header_proc;
@@ -3,7 +3,9 @@
3
3
  # stop working altogether when they next change gmail but
4
4
  # it's still an example of posting with curb...
5
5
 
6
- require '../curb'
6
+ $:.unshift(File.join(File.dirname(__FILE__), '..', 'ext'))
7
+ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
8
+ require 'curb'
7
9
 
8
10
  $EMAIL = '<YOUR GMAIL LOGIN>'
9
11
  $PASSWD = '<YOUR GMAIL PASSWORD>'
@@ -67,7 +67,11 @@ class TestCurbCurlEasy < Test::Unit::TestCase
67
67
  c = Curl::Easy.new
68
68
 
69
69
  assert_equal "one two", c.unescape('one%20two')
70
- assert_equal "one\000two three", c.unescape("one%00two%20three")
70
+
71
+ # prior to 7.15.4 embedded nulls cannot be unescaped
72
+ if Curl::VERNUM >= 0x070f04
73
+ assert_equal "one\000two three", c.unescape("one%00two%20three")
74
+ end
71
75
  end
72
76
 
73
77
  def test_headers
@@ -178,6 +182,22 @@ class TestCurbCurlEasy < Test::Unit::TestCase
178
182
  assert_raise(ArgumentError) { c.local_port_range = -1 }
179
183
  end
180
184
 
185
+ def test_proxy_url_01
186
+ c = Curl::Easy.new($TEST_URL)
187
+
188
+ assert_equal $TEST_URL, c.url
189
+ assert_nil c.proxy_url
190
+
191
+ c.proxy_url = "http://some.proxy"
192
+
193
+ assert_equal $TEST_URL, c.url
194
+ assert_equal "http://some.proxy", c.proxy_url
195
+
196
+ c.proxy_url = nil
197
+ assert_equal $TEST_URL, c.url
198
+ assert_nil c.proxy_url
199
+ end
200
+
181
201
  def test_proxy_port_01
182
202
  c = Curl::Easy.new($TEST_URL)
183
203
 
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: curb
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.0
7
- date: 2006-12-23 00:00:00 +00:00
6
+ version: 0.1.2
7
+ date: 2007-01-14 00:00:00 +00:00
8
8
  summary: Ruby bindings for the libcurl(3) URL transfer library.
9
9
  require_paths:
10
10
  - lib