Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > libcurl and ruby-dl

Reply
Thread Tools

libcurl and ruby-dl

 
 
Brian Takita
Guest
Posts: n/a
 
      07-29-2005
Hello,

I'm trying to figure out how to use libcurl via ruby-dl.
Here is some good documentation I found about ruby-dl.
http://www.jbrowse.com/text/rdl_en.html

I read _Why's intro to using libcurl at,
http://whytheluckystiff.net/articles...neEightOh.html, which is an
exciting but shallow introduction.
Right now, I am having trouble setting the url parameter by calling
curl_easy_setopt.

Here is libcurl's documentation that I am trying to grok:
http://curl.mirror.internet.tp/libcu...sy_setopt.html

What I have so far is at the end of this message. Unforunately, my C
knowledge is lacking that I am not confident how to finish this test
script.

Can somebody help me to get a simple request working with libcurl and
Ruby?

Thank you,
Brian Takita

require 'dl/import'
require 'dl/struct'

module Curl
extend DL::Importable
dlload "libcurl.dll"

typealias('CURL', 'void')
typealias('CURLOPT', 'long')

extern "CURL *curl_easy_init()"
extern "char *curl_version()"
extern "void *curl_version_info(int)"
extern "void curl_easy_setopt(CURL *, CURLOPT, char *)"
extern "curl_easy_cleanup(CURL *)"

VersionInfoData = struct [
"int age",
"char *version",
"uint version_num",
"char *host",
"int features",
"char *ssl_version",
"long ssl_version_num",
"char *libz_version",
"char **protocols"
]
end

handle = Curl.curl_easy_init

url_param = 0 # I don't know the value
Curl.curl_easy_setopt(handle, url_param, 'http://www.google.com')

# This also fails
# Documentation is at
http://curl.mirror.internet.tp/libcu...y_cleanup.html
Curl.curl_easy_cleanup(handle)

 
Reply With Quote
 
 
 
 
Takaaki Tateishi
Guest
Posts: n/a
 
      08-01-2005
Brian Takita wrote:
> Right now, I am having trouble setting the url parameter by calling
> curl_easy_setopt.


Please see the following program, in which I use 10002 for CURLOPT_URL.
If you'd like to know why I use 10002, please understand definitions of CINIT and
CURLOPT_URL in curl.h on your own.

Regards,

require 'dl/import'
require 'dl/struct'

module Curl
extend DL::Importable
dlload "libcurl.dll"

typealias('CURL', 'void')
typealias('CURLOPT', 'long')
typealias('CURLcode', 'int')

extern "CURL *curl_easy_init()"
extern "char *curl_version()"
extern "void *curl_version_info(int)"
extern "CURLcode curl_easy_setopt(CURL *, CURLOPT, char *)"
extern "void curl_easy_cleanup(CURL *)"
extern "CURLcode curl_easy_perform(CURL *)"

VersionInfoData = struct [
"int age",
"char *version",
"uint version_num",
"char *host",
"int features",
"char *ssl_version",
"long ssl_version_num",
"char *libz_version",
"char **protocols"
]
end

handle = Curl.curl_easy_init

CURLOPT_URL = 10002 # I don't know the value
URL = "http://www.google.com/"
p Curl.curl_easy_setopt(handle, CURLOPT_URL, URL)

p Curl.curl_easy_perform(handle)
# This also fails
# Documentation is at http://curl.mirror.internet.tp/libcu...y_cleanup.html
Curl.curl_easy_cleanup(handle)

--
Takaaki Tateishi <(E-Mail Removed)>



 
Reply With Quote
 
 
 
 
Brian Takita
Guest
Posts: n/a
 
      08-02-2005
Thank you for submitting a version that works.

Here are the CURLOPT values:

CURLOPT_FILE = 10001
CURLOPT_URL = 10002
CURLOPT_PORT = 10003
CURLOPT_PROXY = 10004
CURLOPT_USERPWD = 10005
CURLOPT_PROXYUSERPWD = 10006
CURLOPT_RANGE = 10007
CURLOPT_INFILE = 10009
CURLOPT_ERRORBUFFER = 10010
CURLOPT_WRITEFUNCTION = 10011
CURLOPT_READFUNCTION = 10012
CURLOPT_TIMEOUT = 10013
CURLOPT_INFILESIZE = 10014
CURLOPT_POSTFIELDS = 10015
CURLOPT_REFERER = 10016
CURLOPT_FTPPORT = 10017
CURLOPT_USERAGENT = 10018
CURLOPT_LOW_SPEED_LIMIT = 10019
CURLOPT_LOW_SPEED_TIME = 10020
CURLOPT_RESUME_FROM = 10021
CURLOPT_COOKIE = 10022
CURLOPT_HTTPHEADER = 10023
CURLOPT_HTTPPOST = 10024
CURLOPT_SSLCERT = 10025
CURLOPT_SSLCERTPASSWD = 10026
CURLOPT_SSLKEYPASSWD = 10026
CURLOPT_CRLF = 10027
CURLOPT_QUOTE = 10028
CURLOPT_WRITEHEADER = 10029
CURLOPT_COOKIEFILE = 10031
CURLOPT_SSLVERSION = 10032
CURLOPT_TIMECONDITION = 10033
CURLOPT_TIMEVALUE = 10034
CURLOPT_CUSTOMREQUEST = 10036
CURLOPT_STDERR = 10037
CURLOPT_POSTQUOTE = 10039
CURLOPT_WRITEINFO = 10040
CURLOPT_VERBOSE = 10048
CURLOPT_FTPAPPEND = 10050
CURLOPT_NETRC = 10051
CURLOPT_FOLLOWLOCATION = 10052
CURLOPT_TRANSFERTEXT = 10054
CURLOPT_PROGRESSFUNCTION = 10056
CURLOPT_PROGRESSDATA = 10057
CURLOPT_AUTOREFERER = 10058
CURLOPT_PROXYPORT = 10059
CURLOPT_POSTFIELDSIZE = 10060
CURLOPT_HTTPPROXYTUNNEL = 10061
CURLOPT_INTERFACE = 10062
CURLOPT_KRB4LEVEL = 10063
CURLOPT_SSL_VERIFYPEER = 10064
CURLOPT_CAINFO = 10065
CURLOPT_MAXREDIRS = 10068
CURLOPT_FILETIME = 10069
CURLOPT_TELNETOPTIONS = 10070
CURLOPT_MAXCONNECTS = 10071
CURLOPT_CLOSEPOLICY = 10072
CURLOPT_FRESH_CONNECT = 10074
CURLOPT_FORBID_REUSE = 10075
CURLOPT_RANDOM_FILE = 10076
CURLOPT_EGDSOCKET = 10077
CURLOPT_CONNECTTIMEOUT = 10078
CURLOPT_HEADERFUNCTION = 10079
CURLOPT_HTTPGET = 10080
CURLOPT_SSL_VERIFYHOST = 10081
CURLOPT_COOKIEJAR = 10082
CURLOPT_SSL_CIPHER_LIST = 10083
CURLOPT_HTTP_VERSION = 10084
CURLOPT_FTP_USE_EPSV = 10085
CURLOPT_SSLCERTTYPE = 10086
CURLOPT_SSLKEY = 10087
CURLOPT_SSLKEYTYPE = 10088
CURLOPT_SSLENGINE = 10089
CURLOPT_SSLENGINE_DEFAULT = 10090
CURLOPT_DNS_USE_GLOBAL_CACHE = 10091
CURLOPT_DNS_CACHE_TIMEOUT = 10092
CURLOPT_PREQUOTE = 10093
CURLOPT_DEBUGFUNCTION = 10094
CURLOPT_DEBUGDATA = 10095
CURLOPT_COOKIESESSION = 10096
CURLOPT_CAPATH = 10097
CURLOPT_BUFFERSIZE = 10098
CURLOPT_NOSIGNAL = 10099
CURLOPT_SHARE = 100100
CURLOPT_PROXYTYPE = 100101
CURLOPT_ENCODING = 100102
CURLOPT_PRIVATE = 100103
CURLOPT_HTTP200ALIASES = 100104
CURLOPT_UNRESTRICTED_AUTH = 100105
CURLOPT_FTP_USE_EPRT = 100106
CURLOPT_HTTPAUTH = 100107
CURLOPT_SSL_CTX_FUNCTION = 100108
CURLOPT_SSL_CTX_DATA = 100109
CURLOPT_FTP_CREATE_MISSING_DIRS = 100110
CURLOPT_PROXYAUTH = 100111
CURLOPT_FTP_RESPONSE_TIMEOUT = 100112
CURLOPT_IPRESOLVE = 100113
CURLOPT_MAXFILESIZE = 100114
CURLOPT_INFILESIZE_LARGE = 100115
CURLOPT_RESUME_FROM_LARGE = 100116
CURLOPT_MAXFILESIZE_LARGE = 100117
CURLOPT_NETRC_FILE = 100118
CURLOPT_FTP_SSL = 100119
CURLOPT_POSTFIELDSIZE_LARGE = 100120
CURLOPT_TCP_NODELAY = 100121
CURLOPT_SOURCE_USERPWD = 100123
CURLOPT_SOURCE_PREQUOTE = 100127
CURLOPT_SOURCE_POSTQUOTE = 100128
CURLOPT_FTPSSLAUTH = 100129
CURLOPT_IOCTLFUNCTION = 100130
CURLOPT_IOCTLDATA = 100131
CURLOPT_SOURCE_URL = 100132
CURLOPT_SOURCE_QUOTE = 100133
CURLOPT_FTP_ACCOUNT = 100134

 
Reply With Quote
 
Brian Takita
Guest
Posts: n/a
 
      08-02-2005
Thank you for submitting a version that works.

Here are the CURLOPT values:

CURLOPT_PORT = 3
CURLOPT_TIMEOUT = 13
CURLOPT_INFILESIZE = 14
CURLOPT_LOW_SPEED_LIMIT = 19
CURLOPT_LOW_SPEED_TIME = 20
CURLOPT_RESUME_FROM = 21
CURLOPT_CRLF = 27
CURLOPT_SSLVERSION = 32
CURLOPT_TIMECONDITION = 33
CURLOPT_TIMEVALUE = 34
CURLOPT_NETRC = 51
CURLOPT_AUTOREFERER = 58
CURLOPT_PROXYPORT = 59
CURLOPT_POSTFIELDSIZE = 60
CURLOPT_HTTPPROXYTUNNEL = 61
CURLOPT_SSL_VERIFYPEER = 64
CURLOPT_MAXREDIRS = 68
CURLOPT_FILETIME = 69
CURLOPT_MAXCONNECTS = 71
CURLOPT_CLOSEPOLICY = 72
CURLOPT_FRESH_CONNECT = 74
CURLOPT_FORBID_REUSE = 75
CURLOPT_CONNECTTIMEOUT = 78
CURLOPT_HTTPGET = 80
CURLOPT_SSL_VERIFYHOST = 81
CURLOPT_HTTP_VERSION = 84
CURLOPT_FTP_USE_EPSV = 85
CURLOPT_SSLENGINE_DEFAULT = 90
CURLOPT_DNS_CACHE_TIMEOUT = 92
CURLOPT_COOKIESESSION = 96
CURLOPT_BUFFERSIZE = 98
CURLOPT_NOSIGNAL = 99
CURLOPT_PROXYTYPE = 101
CURLOPT_UNRESTRICTED_AUTH = 105
CURLOPT_FTP_USE_EPRT = 106
CURLOPT_HTTPAUTH = 107
CURLOPT_FTP_CREATE_MISSING_DIRS = 110
CURLOPT_PROXYAUTH = 111
CURLOPT_FTP_RESPONSE_TIMEOUT = 112
CURLOPT_IPRESOLVE = 113
CURLOPT_MAXFILESIZE = 114
CURLOPT_FTP_SSL = 119
CURLOPT_TCP_NODELAY = 121
CURLOPT_FTPSSLAUTH = 129
CURLOPT_FILE = 10001
CURLOPT_URL = 10002
CURLOPT_PROXY = 10004
CURLOPT_USERPWD = 10005
CURLOPT_PROXYUSERPWD = 10006
CURLOPT_RANGE = 10007
CURLOPT_INFILE = 10009
CURLOPT_ERRORBUFFER = 10010
CURLOPT_POSTFIELDS = 10015
CURLOPT_REFERER = 10016
CURLOPT_FTPPORT = 10017
CURLOPT_USERAGENT = 10018
CURLOPT_COOKIE = 10022
CURLOPT_HTTPHEADER = 10023
CURLOPT_HTTPPOST = 10024
CURLOPT_SSLCERT = 10025
CURLOPT_SSLCERTPASSWD = 10026
CURLOPT_SSLKEYPASSWD = 10026
CURLOPT_QUOTE = 10028
CURLOPT_WRITEHEADER = 10029
CURLOPT_COOKIEFILE = 10031
CURLOPT_CUSTOMREQUEST = 10036
CURLOPT_STDERR = 10037
CURLOPT_POSTQUOTE = 10039
CURLOPT_WRITEINFO = 10040
CURLOPT_PROGRESSDATA = 10057
CURLOPT_INTERFACE = 10062
CURLOPT_KRB4LEVEL = 10063
CURLOPT_CAINFO = 10065
CURLOPT_TELNETOPTIONS = 10070
CURLOPT_RANDOM_FILE = 10076
CURLOPT_EGDSOCKET = 10077
CURLOPT_COOKIEJAR = 10082
CURLOPT_SSL_CIPHER_LIST = 10083
CURLOPT_SSLCERTTYPE = 10086
CURLOPT_SSLKEY = 10087
CURLOPT_SSLKEYTYPE = 10088
CURLOPT_SSLENGINE = 10089
CURLOPT_PREQUOTE = 10093
CURLOPT_DEBUGDATA = 10095
CURLOPT_CAPATH = 10097
CURLOPT_SHARE = 10100
CURLOPT_ENCODING = 10102
CURLOPT_PRIVATE = 10103
CURLOPT_HTTP200ALIASES = 10104
CURLOPT_SSL_CTX_DATA = 10109
CURLOPT_NETRC_FILE = 10118
CURLOPT_SOURCE_USERPWD = 10123
CURLOPT_SOURCE_PREQUOTE = 10127
CURLOPT_SOURCE_POSTQUOTE = 10128
CURLOPT_IOCTLDATA = 10131
CURLOPT_SOURCE_URL = 10132
CURLOPT_SOURCE_QUOTE = 10133
CURLOPT_FTP_ACCOUNT = 10134
CURLOPT_WRITEFUNCTION = 20011
CURLOPT_READFUNCTION = 20012
CURLOPT_PROGRESSFUNCTION = 20056
CURLOPT_HEADERFUNCTION = 20079
CURLOPT_DEBUGFUNCTION = 20094
CURLOPT_SSL_CTX_FUNCTION = 20108
CURLOPT_IOCTLFUNCTION = 20130
CURLOPT_INFILESIZE_LARGE = 30115
CURLOPT_RESUME_FROM_LARGE = 30116
CURLOPT_MAXFILESIZE_LARGE = 30117
CURLOPT_POSTFIELDSIZE_LARGE = 30120

 
Reply With Quote
 
Brian Takita
Guest
Posts: n/a
 
      08-02-2005
The values I submitted from this message's parent are correct.
The values from my first reply (this message's parents first sibling)
are incorrect.

I must also say that the Ruby-DL library is very nice. Thank you for
this project, Mr. Tateishi.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Post data to http server using libcurl Raj Python 0 11-09-2006 12:08 PM
Post data using the libcurl Raj Python 0 11-09-2006 12:06 PM
Post data using the libcurl Raj Python 0 11-09-2006 12:06 PM
libcurl and expat Sylvain/11XX XML 1 05-23-2006 08:54 PM
Help getting started with Pycurl / libcurl ? gjzusenet@gmail.com Python 0 02-27-2006 11:58 AM



Advertisments