libcurl and ruby-dl

Discussion in 'Ruby' started by Brian Takita, Jul 29, 2005.

  1. Brian Takita

    Brian Takita Guest

    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/rubyOneEightOh.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/libcurl/c/curl_easy_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/libcurl/c/curl_easy_cleanup.html
    Curl.curl_easy_cleanup(handle)
     
    Brian Takita, Jul 29, 2005
    #1
    1. Advertising

  2. 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/libcurl/c/curl_easy_cleanup.html
    Curl.curl_easy_cleanup(handle)

    --
    Takaaki Tateishi <>
     
    Takaaki Tateishi, Aug 1, 2005
    #2
    1. Advertising

  3. Brian Takita

    Brian Takita Guest

    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
     
    Brian Takita, Aug 2, 2005
    #3
  4. Brian Takita

    Brian Takita Guest

    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
     
    Brian Takita, Aug 2, 2005
    #4
  5. Brian Takita

    Brian Takita Guest

    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.
     
    Brian Takita, Aug 2, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sylvain/11XX

    libcurl and expat

    Sylvain/11XX, May 23, 2006, in forum: XML
    Replies:
    1
    Views:
    572
    Joe Kesselman
    May 23, 2006
  2. Replies:
    0
    Views:
    485
  3. Raj

    Post data using the libcurl

    Raj, Nov 9, 2006, in forum: Python
    Replies:
    0
    Views:
    338
  4. Raj

    Post data using the libcurl

    Raj, Nov 9, 2006, in forum: Python
    Replies:
    0
    Views:
    294
  5. Friedrich Dominicus

    ruby libcurl maintainer?

    Friedrich Dominicus, Oct 30, 2006, in forum: Ruby
    Replies:
    3
    Views:
    109
    Md.elme focruzzaman Shuvo
    Jun 7, 2007
Loading...

Share This Page