[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

CURL-alike library for ruby

Yaroslav Tarasenko

3/15/2006 4:36:00 PM

Hello.

Can you please advice me any CURL-alike library for ruby? I've found two
projects named rCurl or alike but neither extension has been compiled on
my FreeBSD box. Therefore looking for an alternative.

Any information is appreciated. Thanks in advance.

--
Best,
Yaroslav Tarasenko aka Taras Tswiah
UNIX systems administrator



7 Answers

Ross Bamford

3/15/2006 5:30:00 PM

0

On Thu, 2006-03-16 at 01:36 +0900, Yaroslav Tarasenko wrote:
> Hello.
>
> Can you please advice me any CURL-alike library for ruby? I've found two
> projects named rCurl or alike but neither extension has been compiled on
> my FreeBSD box. Therefore looking for an alternative.

A while ago I had need of this, and made some changes to rbCurl [1] to
get it to compile against modern Ruby and GCC versions. I've not
extensively tested it (ended up not using it in fact) but it seemed to
work fairly well I think. The attached patch should work against the
0.0.2 prealpha version of rbCurl at [2].

[1]: http://www.d1.dion.ne.jp/~matuyuki...
[2]: http://www.d1.dion.ne.jp/~matuyuki/rbCurl-0...
--
Ross Bamford - rosco@roscopeco.REMOVE.co.uk

Yaroslav Tarasenko

3/15/2006 6:10:00 PM

0

Patched successfully, but when i tried to compile the extension on Linux
box with gcc4, it stopped with such error message:

init.c: In function 'Init_curl':
init.c:408: error: 'CURL_TIMECOND_NONE' undeclared (first use in this
function)
init.c:409: error: 'CURL_TIMECOND_IFMODSINCE' undeclared (first use in
this function)
init.c:410: error: 'CURL_TIMECOND_IFUNMODSINCE' undeclared (first use in
this function)
init.c:411: error: 'CURL_TIMECOND_LASTMOD' undeclared (first use in this
function)
init.c:413: error: 'CURL_HTTP_VERSION_NONE' undeclared (first use in
this function)
init.c:414: error: 'CURL_HTTP_VERSION_1_0' undeclared (first use in this
function)
init.c:415: error: 'CURL_HTTP_VERSION_1_1' undeclared (first use in this
function)
init.c:417: error: 'CURL_SSLVERSION_DEFAULT' undeclared (first use in
this function)
init.c:418: error: 'CURL_SSLVERSION_TLSv1' undeclared (first use in this
function)
init.c:419: error: 'CURL_SSLVERSION_SSLv2' undeclared (first use in this
function)
init.c:420: error: 'CURL_SSLVERSION_SSLv3' undeclared (first use in this
function)
make: *** [init.o] Error 1


Ross Bamford wrote:

>On Thu, 2006-03-16 at 01:36 +0900, Yaroslav Tarasenko wrote:
>
>
>>Hello.
>>
>>Can you please advice me any CURL-alike library for ruby? I've found two
>>projects named rCurl or alike but neither extension has been compiled on
>>my FreeBSD box. Therefore looking for an alternative.
>>
>>
>
>A while ago I had need of this, and made some changes to rbCurl [1] to
>get it to compile against modern Ruby and GCC versions. I've not
>extensively tested it (ended up not using it in fact) but it seemed to
>work fairly well I think. The attached patch should work against the
>0.0.2 prealpha version of rbCurl at [2].
>
>[1]: http://www.d1.dion.ne.jp/~matuyuki...
>[2]: http://www.d1.dion.ne.jp/~matuyuki/rbCurl-0...
>
>
>------------------------------------------------------------------------
>
>diff -u rbCurl-0.0.2/auto_funcs.inc rbCurl-0.0.2.local/auto_funcs.inc
>--- rbCurl-0.0.2/auto_funcs.inc 2002-05-15 18:07:22.000000000 +0100
>+++ rbCurl-0.0.2.local/auto_funcs.inc 2006-03-15 17:14:03.000000000 +0000
>@@ -8,7 +8,8 @@
> rb_iv_set(self, "@url", v);
>
> if (v != Qnil) {
>- src = rb_str2cstr(v, &len); /* copy string */
>+ src = StringValuePtr(v); /* copy string */
>+ len = RSTRING(v)->len;
> dst = ALLOC_N(char, len+1); /* able to free */
> memcpy(dst, src, len);
> dst[len] = '\0';
>@@ -41,7 +42,8 @@
> rb_iv_set(self, "@proxy", v);
>
> if (v != Qnil) {
>- src = rb_str2cstr(v, &len); /* copy string */
>+ src = StringValuePtr(v); /* copy string */
>+ len = RSTRING(v)->len;
> dst = ALLOC_N(char, len+1); /* able to free */
> memcpy(dst, src, len);
> dst[len] = '\0';
>@@ -63,7 +65,8 @@
> rb_iv_set(self, "@userpwd", v);
>
> if (v != Qnil) {
>- src = rb_str2cstr(v, &len); /* copy string */
>+ src = StringValuePtr(v); /* copy string */
>+ len = RSTRING(v)->len;
> dst = ALLOC_N(char, len+1); /* able to free */
> memcpy(dst, src, len);
> dst[len] = '\0';
>@@ -85,7 +88,8 @@
> rb_iv_set(self, "@proxyuserpwd", v);
>
> if (v != Qnil) {
>- src = rb_str2cstr(v, &len); /* copy string */
>+ src = StringValuePtr(v); /* copy string */
>+ len = RSTRING(v)->len;
> dst = ALLOC_N(char, len+1); /* able to free */
> memcpy(dst, src, len);
> dst[len] = '\0';
>@@ -107,7 +111,8 @@
> rb_iv_set(self, "@range", v);
>
> if (v != Qnil) {
>- src = rb_str2cstr(v, &len); /* copy string */
>+ src = StringValuePtr(v); /* copy string */
>+ len = RSTRING(v)->len;
> dst = ALLOC_N(char, len+1); /* able to free */
> memcpy(dst, src, len);
> dst[len] = '\0';
>@@ -140,7 +145,8 @@
> rb_iv_set(self, "@postfields", v);
>
> if (v != Qnil) {
>- src = rb_str2cstr(v, &len); /* copy string */
>+ src = StringValuePtr(v); /* copy string */
>+ len = RSTRING(v)->len;
> dst = ALLOC_N(char, len); /* able to free */
> memcpy(dst, src, len);
> curl_easy_setopt(s->curl, CURLOPT_POSTFIELDSIZE, len);
>@@ -162,7 +168,8 @@
> rb_iv_set(self, "@referer", v);
>
> if (v != Qnil) {
>- src = rb_str2cstr(v, &len); /* copy string */
>+ src = StringValuePtr(v); /* copy string */
>+ len = RSTRING(v)->len;
> dst = ALLOC_N(char, len+1); /* able to free */
> memcpy(dst, src, len);
> dst[len] = '\0';
>@@ -184,7 +191,8 @@
> rb_iv_set(self, "@ftpport", v);
>
> if (v != Qnil) {
>- src = rb_str2cstr(v, &len); /* copy string */
>+ src = StringValuePtr(v); /* copy string */
>+ len = RSTRING(v)->len;
> dst = ALLOC_N(char, len+1); /* able to free */
> memcpy(dst, src, len);
> dst[len] = '\0';
>@@ -206,7 +214,8 @@
> rb_iv_set(self, "@useragent", v);
>
> if (v != Qnil) {
>- src = rb_str2cstr(v, &len); /* copy string */
>+ src = StringValuePtr(v); /* copy string */
>+ len = RSTRING(v)->len;
> dst = ALLOC_N(char, len+1); /* able to free */
> memcpy(dst, src, len);
> dst[len] = '\0';
>@@ -261,7 +270,8 @@
> rb_iv_set(self, "@cookie", v);
>
> if (v != Qnil) {
>- src = rb_str2cstr(v, &len); /* copy string */
>+ src = StringValuePtr(v); /* copy string */
>+ len = RSTRING(v)->len;
> dst = ALLOC_N(char, len+1); /* able to free */
> memcpy(dst, src, len);
> dst[len] = '\0';
>@@ -305,7 +315,8 @@
> rb_iv_set(self, "@sslcert", v);
>
> if (v != Qnil) {
>- src = rb_str2cstr(v, &len); /* copy string */
>+ src = StringValuePtr(v); /* copy string */
>+ len = RSTRING(v)->len;
> dst = ALLOC_N(char, len+1); /* able to free */
> memcpy(dst, src, len);
> dst[len] = '\0';
>@@ -327,7 +338,8 @@
> rb_iv_set(self, "@sslcertpasswd", v);
>
> if (v != Qnil) {
>- src = rb_str2cstr(v, &len); /* copy string */
>+ src = StringValuePtr(v); /* copy string */
>+ len = RSTRING(v)->len;
> dst = ALLOC_N(char, len+1); /* able to free */
> memcpy(dst, src, len);
> dst[len] = '\0';
>@@ -347,8 +359,8 @@
> rb_iv_set(self, "@crlf", v);
>
> switch (v) {
>- case Qtrue: { curl_easy_setopt(s->curl, CURLOPT_CRLF, TRUE); break; }
>- case Qfalse: { curl_easy_setopt(s->curl, CURLOPT_CRLF, FALSE); break; }
>+ case Qtrue: { curl_easy_setopt(s->curl, CURLOPT_CRLF, 1); break; }
>+ case Qfalse: { curl_easy_setopt(s->curl, CURLOPT_CRLF, 0); break; }
> default: { rb_raise(rb_eArgError, "must be true or false"); }
> }
> return Qnil;
>@@ -386,7 +398,8 @@
> rb_iv_set(self, "@cookiefile", v);
>
> if (v != Qnil) {
>- src = rb_str2cstr(v, &len); /* copy string */
>+ src = StringValuePtr(v); /* copy string */
>+ len = RSTRING(v)->len;
> dst = ALLOC_N(char, len+1); /* able to free */
> memcpy(dst, src, len);
> dst[len] = '\0';
>@@ -441,7 +454,8 @@
> rb_iv_set(self, "@customrequest", v);
>
> if (v != Qnil) {
>- src = rb_str2cstr(v, &len); /* copy string */
>+ src = StringValuePtr(v); /* copy string */
>+ len = RSTRING(v)->len;
> dst = ALLOC_N(char, len+1); /* able to free */
> memcpy(dst, src, len);
> dst[len] = '\0';
>@@ -483,8 +497,8 @@
> rb_iv_set(self, "@verbose", v);
>
> switch (v) {
>- case Qtrue: { curl_easy_setopt(s->curl, CURLOPT_VERBOSE, TRUE); break; }
>- case Qfalse: { curl_easy_setopt(s->curl, CURLOPT_VERBOSE, FALSE); break; }
>+ case Qtrue: { curl_easy_setopt(s->curl, CURLOPT_VERBOSE, 1); break; }
>+ case Qfalse: { curl_easy_setopt(s->curl, CURLOPT_VERBOSE, 0); break; }
> default: { rb_raise(rb_eArgError, "must be true or false"); }
> }
> return Qnil;
>@@ -498,8 +512,8 @@
> rb_iv_set(self, "@header", v);
>
> switch (v) {
>- case Qtrue: { curl_easy_setopt(s->curl, CURLOPT_HEADER, TRUE); break; }
>- case Qfalse: { curl_easy_setopt(s->curl, CURLOPT_HEADER, FALSE); break; }
>+ case Qtrue: { curl_easy_setopt(s->curl, CURLOPT_HEADER, 1); break; }
>+ case Qfalse: { curl_easy_setopt(s->curl, CURLOPT_HEADER, 0); break; }
> default: { rb_raise(rb_eArgError, "must be true or false"); }
> }
> return Qnil;
>@@ -513,8 +527,8 @@
> rb_iv_set(self, "@nobody", v);
>
> switch (v) {
>- case Qtrue: { curl_easy_setopt(s->curl, CURLOPT_NOBODY, TRUE); break; }
>- case Qfalse: { curl_easy_setopt(s->curl, CURLOPT_NOBODY, FALSE); break; }
>+ case Qtrue: { curl_easy_setopt(s->curl, CURLOPT_NOBODY, 1); break; }
>+ case Qfalse: { curl_easy_setopt(s->curl, CURLOPT_NOBODY, 0); break; }
> default: { rb_raise(rb_eArgError, "must be true or false"); }
> }
> return Qnil;
>@@ -528,8 +542,8 @@
> rb_iv_set(self, "@failonerror", v);
>
> switch (v) {
>- case Qtrue: { curl_easy_setopt(s->curl, CURLOPT_FAILONERROR, TRUE); break; }
>- case Qfalse: { curl_easy_setopt(s->curl, CURLOPT_FAILONERROR, FALSE); break; }
>+ case Qtrue: { curl_easy_setopt(s->curl, CURLOPT_FAILONERROR, 1); break; }
>+ case Qfalse: { curl_easy_setopt(s->curl, CURLOPT_FAILONERROR, 0); break; }
> default: { rb_raise(rb_eArgError, "must be true or false"); }
> }
> return Qnil;
>@@ -543,8 +557,8 @@
> rb_iv_set(self, "@upload", v);
>
> switch (v) {
>- case Qtrue: { curl_easy_setopt(s->curl, CURLOPT_UPLOAD, TRUE); break; }
>- case Qfalse: { curl_easy_setopt(s->curl, CURLOPT_UPLOAD, FALSE); break; }
>+ case Qtrue: { curl_easy_setopt(s->curl, CURLOPT_UPLOAD, 1); break; }
>+ case Qfalse: { curl_easy_setopt(s->curl, CURLOPT_UPLOAD, 0); break; }
> default: { rb_raise(rb_eArgError, "must be true or false"); }
> }
> return Qnil;
>@@ -558,8 +572,8 @@
> rb_iv_set(self, "@ftplistonly", v);
>
> switch (v) {
>- case Qtrue: { curl_easy_setopt(s->curl, CURLOPT_FTPLISTONLY, TRUE); break; }
>- case Qfalse: { curl_easy_setopt(s->curl, CURLOPT_FTPLISTONLY, FALSE); break; }
>+ case Qtrue: { curl_easy_setopt(s->curl, CURLOPT_FTPLISTONLY, 1); break; }
>+ case Qfalse: { curl_easy_setopt(s->curl, CURLOPT_FTPLISTONLY, 0); break; }
> default: { rb_raise(rb_eArgError, "must be true or false"); }
> }
> return Qnil;
>@@ -573,8 +587,8 @@
> rb_iv_set(self, "@ftpappend", v);
>
> switch (v) {
>- case Qtrue: { curl_easy_setopt(s->curl, CURLOPT_FTPAPPEND, TRUE); break; }
>- case Qfalse: { curl_easy_setopt(s->curl, CURLOPT_FTPAPPEND, FALSE); break; }
>+ case Qtrue: { curl_easy_setopt(s->curl, CURLOPT_FTPAPPEND, 1); break; }
>+ case Qfalse: { curl_easy_setopt(s->curl, CURLOPT_FTPAPPEND, 0); break; }
> default: { rb_raise(rb_eArgError, "must be true or false"); }
> }
> return Qnil;
>@@ -588,8 +602,8 @@
> rb_iv_set(self, "@netrc", v);
>
> switch (v) {
>- case Qtrue: { curl_easy_setopt(s->curl, CURLOPT_NETRC, TRUE); break; }
>- case Qfalse: { curl_easy_setopt(s->curl, CURLOPT_NETRC, FALSE); break; }
>+ case Qtrue: { curl_easy_setopt(s->curl, CURLOPT_NETRC, 1); break; }
>+ case Qfalse: { curl_easy_setopt(s->curl, CURLOPT_NETRC, 0); break; }
> default: { rb_raise(rb_eArgError, "must be true or false"); }
> }
> return Qnil;
>@@ -603,8 +617,8 @@
> rb_iv_set(self, "@followlocation", v);
>
> switch (v) {
>- case Qtrue: { curl_easy_setopt(s->curl, CURLOPT_FOLLOWLOCATION, TRUE); break; }
>- case Qfalse: { curl_easy_setopt(s->curl, CURLOPT_FOLLOWLOCATION, FALSE); break; }
>+ case Qtrue: { curl_easy_setopt(s->curl, CURLOPT_FOLLOWLOCATION, 1); break; }
>+ case Qfalse: { curl_easy_setopt(s->curl, CURLOPT_FOLLOWLOCATION, 0); break; }
> default: { rb_raise(rb_eArgError, "must be true or false"); }
> }
> return Qnil;
>@@ -618,8 +632,8 @@
> rb_iv_set(self, "@transfertext", v);
>
> switch (v) {
>- case Qtrue: { curl_easy_setopt(s->curl, CURLOPT_TRANSFERTEXT, TRUE); break; }
>- case Qfalse: { curl_easy_setopt(s->curl, CURLOPT_TRANSFERTEXT, FALSE); break; }
>+ case Qtrue: { curl_easy_setopt(s->curl, CURLOPT_TRANSFERTEXT, 1); break; }
>+ case Qfalse: { curl_easy_setopt(s->curl, CURLOPT_TRANSFERTEXT, 0); break; }
> default: { rb_raise(rb_eArgError, "must be true or false"); }
> }
> return Qnil;
>@@ -633,8 +647,8 @@
> rb_iv_set(self, "@put", v);
>
> switch (v) {
>- case Qtrue: { curl_easy_setopt(s->curl, CURLOPT_PUT, TRUE); break; }
>- case Qfalse: { curl_easy_setopt(s->curl, CURLOPT_PUT, FALSE); break; }
>+ case Qtrue: { curl_easy_setopt(s->curl, CURLOPT_PUT, 1); break; }
>+ case Qfalse: { curl_easy_setopt(s->curl, CURLOPT_PUT, 0); break; }
> default: { rb_raise(rb_eArgError, "must be true or false"); }
> }
> return Qnil;
>@@ -659,8 +673,8 @@
> rb_iv_set(self, "@httpproxytunnel", v);
>
> switch (v) {
>- case Qtrue: { curl_easy_setopt(s->curl, CURLOPT_HTTPPROXYTUNNEL, TRUE); break; }
>- case Qfalse: { curl_easy_setopt(s->curl, CURLOPT_HTTPPROXYTUNNEL, FALSE); break; }
>+ case Qtrue: { curl_easy_setopt(s->curl, CURLOPT_HTTPPROXYTUNNEL, 1); break; }
>+ case Qfalse: { curl_easy_setopt(s->curl, CURLOPT_HTTPPROXYTUNNEL, 0); break; }
> default: { rb_raise(rb_eArgError, "must be true or false"); }
> }
> return Qnil;
>@@ -676,7 +690,8 @@
> rb_iv_set(self, "@interface", v);
>
> if (v != Qnil) {
>- src = rb_str2cstr(v, &len); /* copy string */
>+ src = StringValuePtr(v); /* copy string */
>+ len = RSTRING(v)->len;
> dst = ALLOC_N(char, len+1); /* able to free */
> memcpy(dst, src, len);
> dst[len] = '\0';
>@@ -698,7 +713,8 @@
> rb_iv_set(self, "@krb4level", v);
>
> if (v != Qnil) {
>- src = rb_str2cstr(v, &len); /* copy string */
>+ src = StringValuePtr(v); /* copy string */
>+ len = RSTRING(v)->len;
> dst = ALLOC_N(char, len+1); /* able to free */
> memcpy(dst, src, len);
> dst[len] = '\0';
>@@ -718,8 +734,8 @@
> rb_iv_set(self, "@ssl_verifypeer", v);
>
> switch (v) {
>- case Qtrue: { curl_easy_setopt(s->curl, CURLOPT_SSL_VERIFYPEER, TRUE); break; }
>- case Qfalse: { curl_easy_setopt(s->curl, CURLOPT_SSL_VERIFYPEER, FALSE); break; }
>+ case Qtrue: { curl_easy_setopt(s->curl, CURLOPT_SSL_VERIFYPEER, 1); break; }
>+ case Qfalse: { curl_easy_setopt(s->curl, CURLOPT_SSL_VERIFYPEER, 0); break; }
> default: { rb_raise(rb_eArgError, "must be true or false"); }
> }
> return Qnil;
>@@ -735,7 +751,8 @@
> rb_iv_set(self, "@cainfo", v);
>
> if (v != Qnil) {
>- src = rb_str2cstr(v, &len); /* copy string */
>+ src = StringValuePtr(v); /* copy string */
>+ len = RSTRING(v)->len;
> dst = ALLOC_N(char, len+1); /* able to free */
> memcpy(dst, src, len);
> dst[len] = '\0';
>@@ -766,8 +783,8 @@
> rb_iv_set(self, "@filetime", v);
>
> switch (v) {
>- case Qtrue: { curl_easy_setopt(s->curl, CURLOPT_FILETIME, TRUE); break; }
>- case Qfalse: { curl_easy_setopt(s->curl, CURLOPT_FILETIME, FALSE); break; }
>+ case Qtrue: { curl_easy_setopt(s->curl, CURLOPT_FILETIME, 1); break; }
>+ case Qfalse: { curl_easy_setopt(s->curl, CURLOPT_FILETIME, 0); break; }
> default: { rb_raise(rb_eArgError, "must be true or false"); }
> }
> return Qnil;
>@@ -814,8 +831,8 @@
> rb_iv_set(self, "@forbid_reuse", v);
>
> switch (v) {
>- case Qtrue: { curl_easy_setopt(s->curl, CURLOPT_FORBID_REUSE, TRUE); break; }
>- case Qfalse: { curl_easy_setopt(s->curl, CURLOPT_FORBID_REUSE, FALSE); break; }
>+ case Qtrue: { curl_easy_setopt(s->curl, CURLOPT_FORBID_REUSE, 1); break; }
>+ case Qfalse: { curl_easy_setopt(s->curl, CURLOPT_FORBID_REUSE, 0); break; }
> default: { rb_raise(rb_eArgError, "must be true or false"); }
> }
> return Qnil;
>@@ -831,7 +848,8 @@
> rb_iv_set(self, "@random_file", v);
>
> if (v != Qnil) {
>- src = rb_str2cstr(v, &len); /* copy string */
>+ src = StringValuePtr(v); /* copy string */
>+ len = RSTRING(v)->len;
> dst = ALLOC_N(char, len+1); /* able to free */
> memcpy(dst, src, len);
> dst[len] = '\0';
>@@ -853,7 +871,8 @@
> rb_iv_set(self, "@egdsocket", v);
>
> if (v != Qnil) {
>- src = rb_str2cstr(v, &len); /* copy string */
>+ src = StringValuePtr(v); /* copy string */
>+ len = RSTRING(v)->len;
> dst = ALLOC_N(char, len+1); /* able to free */
> memcpy(dst, src, len);
> dst[len] = '\0';
>@@ -884,8 +903,8 @@
> rb_iv_set(self, "@httpget", v);
>
> switch (v) {
>- case Qtrue: { curl_easy_setopt(s->curl, CURLOPT_HTTPGET, TRUE); break; }
>- case Qfalse: { curl_easy_setopt(s->curl, CURLOPT_HTTPGET, FALSE); break; }
>+ case Qtrue: { curl_easy_setopt(s->curl, CURLOPT_HTTPGET, 1); break; }
>+ case Qfalse: { curl_easy_setopt(s->curl, CURLOPT_HTTPGET, 0); break; }
> default: { rb_raise(rb_eArgError, "must be true or false"); }
> }
> return Qnil;
>@@ -912,7 +931,8 @@
> rb_iv_set(self, "@cookiejar", v);
>
> if (v != Qnil) {
>- src = rb_str2cstr(v, &len); /* copy string */
>+ src = StringValuePtr(v); /* copy string */
>+ len = RSTRING(v)->len;
> dst = ALLOC_N(char, len+1); /* able to free */
> memcpy(dst, src, len);
> dst[len] = '\0';
>@@ -934,7 +954,8 @@
> rb_iv_set(self, "@ssl_cipher_list", v);
>
> if (v != Qnil) {
>- src = rb_str2cstr(v, &len); /* copy string */
>+ src = StringValuePtr(v); /* copy string */
>+ len = RSTRING(v)->len;
> dst = ALLOC_N(char, len+1); /* able to free */
> memcpy(dst, src, len);
> dst[len] = '\0';
>@@ -965,8 +986,8 @@
> rb_iv_set(self, "@ftp_use_epsv", v);
>
> switch (v) {
>- case Qtrue: { curl_easy_setopt(s->curl, CURLOPT_FTP_USE_EPSV, TRUE); break; }
>- case Qfalse: { curl_easy_setopt(s->curl, CURLOPT_FTP_USE_EPSV, FALSE); break; }
>+ case Qtrue: { curl_easy_setopt(s->curl, CURLOPT_FTP_USE_EPSV, 1); break; }
>+ case Qfalse: { curl_easy_setopt(s->curl, CURLOPT_FTP_USE_EPSV, 0); break; }
> default: { rb_raise(rb_eArgError, "must be true or false"); }
> }
> return Qnil;
>diff -u rbCurl-0.0.2/extconf.rb rbCurl-0.0.2.local/extconf.rb
>--- rbCurl-0.0.2/extconf.rb 2002-05-15 18:07:22.000000000 +0100
>+++ rbCurl-0.0.2.local/extconf.rb 2006-03-15 17:14:03.000000000 +0000
>@@ -2,7 +2,7 @@
>
> require 'mkmf'
>
>-$LDFLAGS = '-lcurl'
>+have_library('curl', 'curl_easy_init')
> #$CFLAGS = '-g'
>
>-create_makefile("curl")
>+create_makefile('curl')
>diff -u rbCurl-0.0.2/init.c rbCurl-0.0.2.local/init.c
>--- rbCurl-0.0.2/init.c 2002-05-15 18:07:22.000000000 +0100
>+++ rbCurl-0.0.2.local/init.c 2006-03-15 17:14:03.000000000 +0000
>@@ -3,6 +3,16 @@
> #include <curl/types.h>
> #include <curl/easy.h>
>
>+/* Emulate Ruby 1.8 string handling on < 1.8 */
>+#if !defined(StringValue)
>+# define StringValue(x) do { >+ if (TYPE(x) != T_STRING) x = rb_str_to_str(x); >+ } while (0)
>+#endif
>+#if !defined(StringValuePtr)
>+# define StringValuePtr(x) ((STR2CSTR(x)))
>+#endif
>+
> typedef struct _rbCurl rbCurl;
> typedef struct _pFILE pFILE;
>
>@@ -55,7 +65,7 @@
> Data_Get_Struct(self, rbCurl, s);
> rb_iv_set(self, "@httppost", v);
>
>- if (s->list_httppost) { curl_formfree(s->list_httppost); }
>+ if (s->list_httppost) { curl_formfree((struct curl_httppost*)s->list_httppost); }
> for (i = 0; i < RARRAY(v)->len; i++) {
> curl_formparse(rb_str2cstr(RARRAY(v)->ptr[i], 0), &s->list_httppost, &last);
> }
>@@ -84,11 +94,11 @@
> if (v != Qnil) {
> curl_easy_setopt(s->curl, CURLOPT_PROGRESSFUNCTION, progress_func);
> curl_easy_setopt(s->curl, CURLOPT_PROGRESSDATA, v);
>- curl_easy_setopt(s->curl, CURLOPT_NOPROGRESS, FALSE);
>+ curl_easy_setopt(s->curl, CURLOPT_NOPROGRESS, 0);
> } else {
> curl_easy_setopt(s->curl, CURLOPT_PROGRESSFUNCTION, NULL);
> curl_easy_setopt(s->curl, CURLOPT_PROGRESSDATA, NULL);
>- curl_easy_setopt(s->curl, CURLOPT_NOPROGRESS, TRUE);
>+ curl_easy_setopt(s->curl, CURLOPT_NOPROGRESS, 1);
> }
>
> return Qnil;
>@@ -100,10 +110,13 @@
> passwd_func(VALUE proc, char *prompt, char *buffer, int buflen)
> {
> VALUE passwd;
>+ VALUE pass_s;
> char *str;
> int len;
> passwd = rb_funcall(proc, rb_intern("call"), 1, rb_str_new2(prompt));
>- str = rb_str2cstr(passwd, &len);
>+ pass_s = StringValue(passwd);
>+ len = RSTRING(pass_s)->len;
>+ str = RSTRING(pass_s)->ptr;
> if (len >= buflen) { return -1; }
> memcpy(buffer, str, len);
> buffer[len] = '\0';
>@@ -142,7 +155,7 @@
> curl_slist_free_all(s->list_httpheader);
> curl_slist_free_all(s->list_quote);
> curl_slist_free_all(s->list_postquote);
>- if (s->list_httppost) { curl_formfree(s->list_httppost); }
>+ if (s->list_httppost) { curl_formfree((struct curl_httppost*)s->list_httppost); }
>
> curl_easy_cleanup(s->curl);
> free(s);
>@@ -173,6 +186,7 @@
> return len;
> }
>
>+static VALUE perform(VALUE self);
>
> static VALUE
> new(VALUE klass)
>@@ -199,6 +213,15 @@
> s->list_quote = NULL;
> s->list_postquote = NULL;
> s->list_httppost = NULL;
>+
>+ if (rb_block_given_p()) {
>+ rb_yield(obj);
>+
>+ /* if a block is given, assume user wants to perform
>+ * right away.
>+ */
>+ perform(obj);
>+ }
>
> /*curl_easy_setopt(s->curl, CURLOPT_MUTE, TRUE);*/
> return obj;
>@@ -262,19 +285,21 @@
> curl_easy_setopt(s->curl, CURLOPT_FILE, &(s->body_str));
> curl_easy_setopt(s->curl, CURLOPT_WRITEFUNCTION, write_func);
> curl_easy_setopt(s->curl, CURLOPT_WRITEHEADER, &(s->header_str));
>- curl_easy_setopt(s->curl, CURLOPT_HEADER, FALSE);
>+ curl_easy_setopt(s->curl, CURLOPT_HEADER, 0);
> }
>
> /* No file for input */
> if (!file_infile) {
> /* use Ruby String */
>- fin.pt = rb_str2cstr(s->input_str, &len);
>+ fin.pt = StringValuePtr(s->input_str);
>+ len = RSTRING(s->input_str)->len;
>+
> if (len) { /* input exist */
> fin.len = len;
> curl_easy_setopt(s->curl, CURLOPT_INFILE, &fin);
> curl_easy_setopt(s->curl, CURLOPT_READFUNCTION, read_func);
> curl_easy_setopt(s->curl, CURLOPT_INFILESIZE, len);
>- curl_easy_setopt(s->curl, CURLOPT_UPLOAD, TRUE);
>+ curl_easy_setopt(s->curl, CURLOPT_UPLOAD, 0);
> }
> }
>
>@@ -380,10 +405,10 @@
> #include "auto_defs.inc"
> /***************************************************************/
>
>- rb_define_const(cCurl, "TIMECOND_NONE", INT2FIX(TIMECOND_NONE));
>- rb_define_const(cCurl, "TIMECOND_IFMODSINCE", INT2FIX(TIMECOND_IFMODSINCE));
>- rb_define_const(cCurl, "TIMECOND_IFUNMODSINCE", INT2FIX(TIMECOND_IFUNMODSINCE));
>- rb_define_const(cCurl, "TIMECOND_LASTMOD", INT2FIX(TIMECOND_LASTMOD));
>+ rb_define_const(cCurl, "TIMECOND_NONE", INT2FIX(CURL_TIMECOND_NONE));
>+ rb_define_const(cCurl, "TIMECOND_IFMODSINCE", INT2FIX(CURL_TIMECOND_IFMODSINCE));
>+ rb_define_const(cCurl, "TIMECOND_IFUNMODSINCE", INT2FIX(CURL_TIMECOND_IFUNMODSINCE));
>+ rb_define_const(cCurl, "TIMECOND_LASTMOD", INT2FIX(CURL_TIMECOND_LASTMOD));
>
> rb_define_const(cCurl, "HTTP_VERSION_NONE", INT2FIX(CURL_HTTP_VERSION_NONE));
> rb_define_const(cCurl, "HTTP_VERSION_1_0", INT2FIX(CURL_HTTP_VERSION_1_0));
>diff -u rbCurl-0.0.2/template.rb rbCurl-0.0.2.local/template.rb
>--- rbCurl-0.0.2/template.rb 2002-05-15 18:07:22.000000000 +0100
>+++ rbCurl-0.0.2.local/template.rb 2006-03-15 17:14:03.000000000 +0000
>@@ -11,7 +11,8 @@
> rb_iv_set(self, "@<NAME>", v);
>
> if (v != Qnil) {
>- src = rb_str2cstr(v, &len); /* copy string */
>+ src = StringValuePtr(v); /* copy string */
>+ len = RSTRING(v)->len;
> dst = ALLOC_N(char, len+1); /* able to free */
> memcpy(dst, src, len);
> dst[len] = '\0';
>@@ -36,7 +37,8 @@
> rb_iv_set(self, "@<NAME>", v);
>
> if (v != Qnil) {
>- src = rb_str2cstr(v, &len); /* copy string */
>+ src = StringValuePtr(v); /* copy string */
>+ len = RSTRING(v)->len;
> dst = ALLOC_N(char, len); /* able to free */
> memcpy(dst, src, len);
> curl_easy_setopt(s->curl, CURLOPT_POSTFIELDSIZE, len);
>@@ -73,8 +75,8 @@
> rb_iv_set(self, "@<NAME>", v);
>
> switch (v) {
>- case Qtrue: { curl_easy_setopt(s->curl, <ID>, TRUE); break; }
>- case Qfalse: { curl_easy_setopt(s->curl, <ID>, FALSE); break; }
>+ case Qtrue: { curl_easy_setopt(s->curl, <ID>, 1); break; }
>+ case Qfalse: { curl_easy_setopt(s->curl, <ID>, 0); break; }
> default: { rb_raise(rb_eArgError, "must be true or false"); }
> }
> return Qnil;
>
>

--
Best,
Yaroslav Tarasenko aka Taras Tswiah
UNIX systems administrator



Ross Bamford

3/15/2006 6:38:00 PM

0

On Thu, 2006-03-16 at 03:10 +0900, Yaroslav Tarasenko wrote:
> Patched successfully, but when i tried to compile the extension on Linux
> box with gcc4, it stopped with such error message:
>
> init.c: In function 'Init_curl':
> init.c:408: error: 'CURL_TIMECOND_NONE' undeclared (first use in this
> function)
> init.c:409: error: 'CURL_TIMECOND_IFMODSINCE' undeclared (first use in
> this function)
> [ ... snipped ... ]
> make: *** [init.o] Error 1
>

Hmm... I just tried it here with a fresh copy, and it worked straight
away. IIRC they should be declared in curl/curl.h - maybe you have a
different version or something?

Mine is:

$ curl --version
curl 7.13.1 (i386-redhat-linux-gnu) libcurl/7.13.1 OpenSSL/0.9.7f zlib/1.2.2.2 libidn/0.5.15

--
Ross Bamford - rosco@roscopeco.REMOVE.co.uk



eastcoastcoder

3/15/2006 8:29:00 PM

0

+1 that Ruby is in major need of a cURL binding.

Too bad I don't know how to do it... would love to see it done,
though....

Ross Bamford

3/15/2006 11:25:00 PM

0

On Thu, 2006-03-16 at 05:33 +0900, eastcoastcoder@gmail.com wrote:
> +1 that Ruby is in major need of a cURL binding.
>
> Too bad I don't know how to do it... would love to see it done,
> though....

I've found updating old extension code to Ruby 1.8 to be a great way to
learn :)

I played a bit more with rbCurl and found it to be fairly stable and
functional, so I posted a copy with my patch applied at:

http://roscopeco.co.uk/code/rbCurl-0.0.2-03...

(I tried contacting the original author, but received no response -
understandably I guess since it looks like it's been a few years...)

Also, OP: You may find that you can get what you need fairly easily with
net/http or open_uri, both in the standard library...

--
Ross Bamford - rosco@roscopeco.REMOVE.co.uk



Yaroslav Tarasenko

3/16/2006 3:29:00 PM

0

I decided to use http-access2 - it was fairly easy to set up and use.
Also i didn't find any possibility to force open-uri not to check
self-signed SSL certificates, which appeared to be made in one string
when using http-access2:
---
clnt = HTTPAccess2::Client.new
clnt.ssl_config.verify_mode = nil
---

Ross Bamford wrote:

>On Thu, 2006-03-16 at 05:33 +0900, eastcoastcoder@gmail.com wrote:
>
>
>>+1 that Ruby is in major need of a cURL binding.
>>
>>Too bad I don't know how to do it... would love to see it done,
>>though....
>>
>>
>
>I've found updating old extension code to Ruby 1.8 to be a great way to
>learn :)
>
>I played a bit more with rbCurl and found it to be fairly stable and
>functional, so I posted a copy with my patch applied at:
>
> http://roscopeco.co.uk/code/rbCurl-0.0.2-03...
>
>(I tried contacting the original author, but received no response -
>understandably I guess since it looks like it's been a few years...)
>
>Also, OP: You may find that you can get what you need fairly easily with
>net/http or open_uri, both in the standard library...
>
>
>

Regarding rbCurl: my curl version is 7.14.0 and the said extension
doesn't compile.

--
Best,
Yaroslav Tarasenko aka Taras Tswiah
UNIX systems administrator



Dimitri Aivaliotis

3/16/2006 3:48:00 PM

0

On 3/16/06, Yaroslav Tarasenko <tswiah@innovativemarketing.com.ua> wrote:

> ---
> clnt = HTTPAccess2::Client.new
> clnt.ssl_config.verify_mode = nil
> ---

Try:

clnt.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE

It took me awhile before I found this when I had to do it, too.

- Dimitri