ethon 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.md CHANGED
@@ -2,7 +2,22 @@
2
2
 
3
3
  ## Master
4
4
 
5
- [Full Changelog](http://github.com/typhoeus/ethon/compare/v0.3.0...master)
5
+ [Full Changelog](http://github.com/typhoeus/ethon/compare/v0.4.0...master)
6
+
7
+ ## 0.4.0
8
+
9
+ [Full Changelog](http://github.com/typhoeus/ethon/compare/v0.3.0...v0.4.0)
10
+
11
+ Enhancements:
12
+
13
+ * ruby 1.8.7 compatible
14
+ * Ethon.logger
15
+ * Deal with string param/body
16
+ * More documentation
17
+
18
+ Bugfixes:
19
+
20
+ * Add multi_cleanup to curl
6
21
 
7
22
  ## 0.3.0
8
23
 
data/lib/ethon/curl.rb CHANGED
@@ -1,472 +1,40 @@
1
+ require 'ethon/curls/codes'
2
+ require 'ethon/curls/options'
3
+ require 'ethon/curls/infos'
4
+ require 'ethon/curls/form_options'
5
+ require 'ethon/curls/auth_types'
6
+ require 'ethon/curls/proxy_types'
7
+ require 'ethon/curls/ssl_versions'
8
+ require 'ethon/curls/messages'
9
+ require 'ethon/curls/functions'
10
+
1
11
  module Ethon
2
12
 
3
13
  # FFI Wrapper module for Curl. Holds constants and required initializers.
4
14
  module Curl
5
- # :nodoc:
6
- def Curl.windows?
7
- !(RbConfig::CONFIG['host_os'] !~ /mingw|mswin|bccwin/)
8
- end
9
-
10
15
  extend ::FFI::Library
16
+ extend Ethon::Curls::Codes
17
+ extend Ethon::Curls::Options
18
+ extend Ethon::Curls::Infos
19
+ extend Ethon::Curls::FormOptions
20
+ extend Ethon::Curls::AuthTypes
21
+ extend Ethon::Curls::ProxyTypes
22
+ extend Ethon::Curls::SslVersions
23
+ extend Ethon::Curls::Messages
11
24
 
12
- # :nodoc:
13
- VERSION_NOW = 3
14
-
15
- # Flag. Initialize SSL.
16
- GLOBAL_SSL = 0x01
17
- # Flag. Initialize win32 socket libraries.
18
- GLOBAL_WIN32 = 0x02
19
- # Flag. Initialize everything possible.
20
- GLOBAL_ALL = (GLOBAL_SSL | GLOBAL_WIN32)
21
- # Flag. Initialize everything by default.
22
- GLOBAL_DEFAULT = GLOBAL_ALL
23
-
24
- # Libcurl error codes, refer
25
- # https://github.com/bagder/curl/blob/master/include/curl/curl.h for details
26
- EasyCode = enum :easy_code, [
27
- :ok,
28
- :unsupported_protocol,
29
- :failed_init,
30
- :url_malformat,
31
- :not_built_in,
32
- :couldnt_resolve_proxy,
33
- :couldnt_resolve_host,
34
- :couldnt_connect,
35
- :ftp_weird_server_reply,
36
- :remote_access_denied,
37
- :ftp_accept_failed,
38
- :ftp_weird_pass_reply,
39
- :ftp_accept_timeout,
40
- :ftp_weird_pasv_reply,
41
- :ftp_weird_227_format,
42
- :ftp_cant_get_host,
43
- :obsolete16,
44
- :ftp_couldnt_set_type,
45
- :partial_file,
46
- :ftp_couldnt_retr_file,
47
- :obsolete20,
48
- :quote_error,
49
- :http_returned_error,
50
- :write_error,
51
- :obsolete24,
52
- :upload_failed,
53
- :read_error,
54
- :out_of_memory,
55
- :operation_timedout,
56
- :obsolete29,
57
- :ftp_port_failed,
58
- :ftp_couldnt_use_rest,
59
- :obsolete32,
60
- :range_error,
61
- :http_post_error,
62
- :ssl_connect_error,
63
- :bad_download_resume,
64
- :file_couldnt_read_file,
65
- :ldap_cannot_bind,
66
- :ldap_search_failed,
67
- :obsolete40,
68
- :function_not_found,
69
- :aborted_by_callback,
70
- :bad_function_argument,
71
- :obsolete44,
72
- :interface_failed,
73
- :obsolete46,
74
- :too_many_redirects ,
75
- :unknown_option,
76
- :telnet_option_syntax ,
77
- :obsolete50,
78
- :peer_failed_verification,
79
- :got_nothing,
80
- :ssl_engine_notfound,
81
- :ssl_engine_setfailed,
82
- :send_error,
83
- :recv_error,
84
- :obsolete57,
85
- :ssl_certproblem,
86
- :ssl_cipher,
87
- :ssl_cacert,
88
- :bad_content_encoding,
89
- :ldap_invalid_url,
90
- :filesize_exceeded,
91
- :use_ssl_failed,
92
- :send_fail_rewind,
93
- :ssl_engine_initfailed,
94
- :login_denied,
95
- :tftp_notfound,
96
- :tftp_perm,
97
- :remote_disk_full,
98
- :tftp_illegal,
99
- :tftp_unknownid,
100
- :remote_file_exists,
101
- :tftp_nosuchuser,
102
- :conv_failed,
103
- :conv_reqd,
104
- :ssl_cacert_badfile,
105
- :remote_file_not_found,
106
- :ssh,
107
- :ssl_shutdown_failed,
108
- :again,
109
- :ssl_crl_badfile,
110
- :ssl_issuer_error,
111
- :ftp_pret_failed,
112
- :rtsp_cseq_error,
113
- :rtsp_session_error,
114
- :ftp_bad_file_list,
115
- :chunk_failed,
116
- :last]
117
-
118
- # Curl-Multi socket error codes, refer
119
- # https://github.com/bagder/curl/blob/master/include/curl/multi.h for details
120
- MultiCode = enum :multi_code, [
121
- :call_multi_perform, -1,
122
- :ok,
123
- :bad_handle,
124
- :bad_easy_handle,
125
- :out_of_memory,
126
- :internal_error,
127
- :bad_socket,
128
- :unknown_option,
129
- :last]
130
-
131
- # :nodoc:
132
- OptionType = enum [
133
- :long, 0,
134
- :object_point, 10000,
135
- :function_point, 20000,
136
- :off_t, 30000]
137
-
138
- # Curl options, refer
139
- # https://github.com/bagder/curl/blob/master/src/tool_cfgable.h for details
140
- Option = enum :option, [
141
- :file, OptionType[:object_point] + 1,
142
- :writedata, OptionType[:object_point] + 1,
143
- :url, OptionType[:object_point] + 2,
144
- :port, OptionType[:long] + 3,
145
- :proxy, OptionType[:object_point] + 4,
146
- :userpwd, OptionType[:object_point] + 5,
147
- :proxyuserpwd, OptionType[:object_point] + 6,
148
- :range, OptionType[:object_point] + 7,
149
- :infile, OptionType[:object_point] + 9,
150
- :readdata, OptionType[:object_point] + 9,
151
- :errorbuffer, OptionType[:object_point] + 10,
152
- :writefunction, OptionType[:function_point] + 11,
153
- :readfunction, OptionType[:function_point] + 12,
154
- :timeout, OptionType[:long] + 13,
155
- :infilesize, OptionType[:long] + 14,
156
- :postfields, OptionType[:object_point] + 15,
157
- :referer, OptionType[:object_point] + 16,
158
- :ftpport, OptionType[:object_point] + 17,
159
- :useragent, OptionType[:object_point] + 18,
160
- :low_speed_time, OptionType[:long] + 20,
161
- :resume_from, OptionType[:long] + 21,
162
- :cookie, OptionType[:object_point] + 22,
163
- :httpheader, OptionType[:object_point] + 23,
164
- :httppost, OptionType[:object_point] + 24,
165
- :sslcert, OptionType[:object_point] + 25,
166
- :sslcertpasswd, OptionType[:object_point] + 26,
167
- :sslkeypasswd, OptionType[:object_point] + 26,
168
- :crlf, OptionType[:long] + 27,
169
- :quote, OptionType[:object_point] + 28,
170
- :writeheader, OptionType[:object_point] + 29,
171
- :headerdata, OptionType[:object_point] + 29,
172
- :cookiefile, OptionType[:object_point] + 31,
173
- :sslversion, OptionType[:long] + 32,
174
- :timecondition, OptionType[:long] + 33,
175
- :timevalue, OptionType[:long] + 34,
176
- :customrequest, OptionType[:object_point] + 36,
177
- :stderr, OptionType[:object_point] + 37,
178
- :postquote, OptionType[:object_point] + 39,
179
- :writeinfo, OptionType[:object_point] + 40,
180
- :verbose, OptionType[:long] + 41,
181
- :header, OptionType[:long] + 42,
182
- :noprogress, OptionType[:long] + 43,
183
- :nobody, OptionType[:long] + 44,
184
- :failonerror, OptionType[:long] + 45,
185
- :upload, OptionType[:long] + 46,
186
- :post, OptionType[:long] + 47,
187
- :ftplistonly, OptionType[:long] + 48,
188
- :ftpappend, OptionType[:long] + 50,
189
- :netrc, OptionType[:long] + 51,
190
- :followlocation, OptionType[:long] + 52,
191
- :transfertext, OptionType[:long] + 53,
192
- :put, OptionType[:long] + 54,
193
- :progressfunction, OptionType[:function_point] + 56,
194
- :progressdata, OptionType[:object_point] + 57,
195
- :autoreferer, OptionType[:long] + 58,
196
- :proxyport, OptionType[:long] + 59,
197
- :postfieldsize, OptionType[:long] + 60,
198
- :httpproxytunnel, OptionType[:long] + 61,
199
- :interface, OptionType[:object_point] + 62,
200
- :ssl_verifypeer, OptionType[:long] + 64,
201
- :cainfo, OptionType[:object_point] + 65,
202
- :maxredirs, OptionType[:long] + 68,
203
- :filetime, OptionType[:long] + 69,
204
- :telnetoptions, OptionType[:object_point] + 70,
205
- :maxconnects, OptionType[:long] + 71,
206
- :closepolicy, OptionType[:long] + 72,
207
- :fresh_connect, OptionType[:long] + 74,
208
- :forbid_reuse, OptionType[:long] + 75,
209
- :random_file, OptionType[:object_point] + 76,
210
- :egdsocket, OptionType[:object_point] + 77,
211
- :connecttimeout, OptionType[:long] + 78,
212
- :headerfunction, OptionType[:function_point] + 79,
213
- :httpget, OptionType[:long] + 80,
214
- :ssl_verifyhost, OptionType[:long] + 81,
215
- :cookiejar, OptionType[:object_point] + 82,
216
- :ssl_cipher_list, OptionType[:object_point] + 83,
217
- :http_version, OptionType[:long] + 84,
218
- :ftp_use_epsv, OptionType[:long] + 85,
219
- :sslcerttype, OptionType[:object_point] + 86,
220
- :sslkey, OptionType[:object_point] + 87,
221
- :sslkeytype, OptionType[:object_point] + 88,
222
- :sslengine, OptionType[:object_point] + 89,
223
- :sslengine_default, OptionType[:long] + 90,
224
- :dns_use_global_cache, OptionType[:long] + 91,
225
- :dns_cache_timeout, OptionType[:long] + 92,
226
- :prequote, OptionType[:object_point] + 93,
227
- :debugfunction, OptionType[:function_point] + 94,
228
- :debugdata, OptionType[:object_point] + 95,
229
- :cookiesession, OptionType[:long] + 96,
230
- :capath, OptionType[:object_point] + 97,
231
- :buffersize, OptionType[:long] + 98,
232
- :nosignal, OptionType[:long] + 99,
233
- :share, OptionType[:object_point] + 100,
234
- :proxytype, OptionType[:long] + 101,
235
- :encoding, OptionType[:object_point] + 102,
236
- :private, OptionType[:object_point] + 103,
237
- :unrestricted_auth, OptionType[:long] + 105,
238
- :ftp_use_eprt, OptionType[:long] + 106,
239
- :httpauth, OptionType[:long] + 107,
240
- :ssl_ctx_function, OptionType[:function_point] + 108,
241
- :ssl_ctx_data, OptionType[:object_point] + 109,
242
- :ftp_create_missing_dirs, OptionType[:long] + 110,
243
- :proxyauth, OptionType[:long] + 111,
244
- :ipresolve, OptionType[:long] + 113,
245
- :maxfilesize, OptionType[:long] + 114,
246
- :infilesize_large, OptionType[:off_t] + 115,
247
- :resume_from_large, OptionType[:off_t] + 116,
248
- :maxfilesize_large, OptionType[:off_t] + 117,
249
- :netrc_file, OptionType[:object_point] + 118,
250
- :ftp_ssl, OptionType[:long] + 119,
251
- :postfieldsize_large, OptionType[:off_t] + 120,
252
- :tcp_nodelay, OptionType[:long] + 121,
253
- :ftpsslauth, OptionType[:long] + 129,
254
- :ioctlfunction, OptionType[:function_point] + 130,
255
- :ioctldata, OptionType[:object_point] + 131,
256
- :ftp_account, OptionType[:object_point] + 134,
257
- :cookielist, OptionType[:object_point] + 135,
258
- :ignore_content_length, OptionType[:long] + 136,
259
- :ftp_skip_pasv_ip, OptionType[:long] + 137,
260
- :ftp_filemethod, OptionType[:long] + 138,
261
- :localport, OptionType[:long] + 139,
262
- :localportrange, OptionType[:long] + 140,
263
- :connect_only, OptionType[:long] + 141,
264
- :conv_from_network_function, OptionType[:function_point] + 142,
265
- :conv_to_network_function, OptionType[:function_point] + 143,
266
- :max_send_speed_large, OptionType[:off_t] + 145,
267
- :max_recv_speed_large, OptionType[:off_t] + 146,
268
- :ftp_alternative_to_user, OptionType[:object_point] + 147,
269
- :sockoptfunction, OptionType[:function_point] + 148,
270
- :sockoptdata, OptionType[:object_point] + 149,
271
- :ssl_sessionid_cache, OptionType[:long] + 150,
272
- :ssh_auth_types, OptionType[:long] + 151,
273
- :ssh_public_keyfile, OptionType[:object_point] + 152,
274
- :ssh_private_keyfile, OptionType[:object_point] + 153,
275
- :ftp_ssl_ccc, OptionType[:long] + 154,
276
- :timeout_ms, OptionType[:long] + 155,
277
- :connecttimeout_ms, OptionType[:long] + 156,
278
- :http_transfer_decoding, OptionType[:long] + 157,
279
- :http_content_decoding, OptionType[:long] + 158,
280
- :copypostfields, OptionType[:object_point] + 165]
281
-
282
- # :nodoc:
283
- InfoType = enum [
284
- :string, 0x100000,
285
- :long, 0x200000,
286
- :double, 0x300000,
287
- :slist, 0x400000]
288
-
289
- # Info details, refer
290
- # https://github.com/bagder/curl/blob/master/src/tool_writeout.c#L66 for details
291
- Info = enum :info, [
292
- :effective_url, InfoType[:string] + 1,
293
- :response_code, InfoType[:long] + 2,
294
- :total_time, InfoType[:double] + 3,
295
- :namelookup_time, InfoType[:double] + 4,
296
- :connect_time, InfoType[:double] + 5,
297
- :pretransfer_time, InfoType[:double] + 6,
298
- :size_upload, InfoType[:double] + 7,
299
- :size_download, InfoType[:double] + 8,
300
- :speed_download, InfoType[:double] + 9,
301
- :speed_upload, InfoType[:double] + 10,
302
- :header_size, InfoType[:long] + 11,
303
- :request_size, InfoType[:long] + 12,
304
- :ssl_verifyresult, InfoType[:long] + 13,
305
- :filetime, InfoType[:long] + 14,
306
- :content_length_download, InfoType[:double] + 15,
307
- :content_length_upload, InfoType[:double] + 16,
308
- :starttransfer_time, InfoType[:double] + 17,
309
- :content_type, InfoType[:string] + 18,
310
- :redirect_time, InfoType[:double] + 19,
311
- :redirect_count, InfoType[:long] + 20,
312
- :private, InfoType[:string] + 21,
313
- :http_connectcode, InfoType[:long] + 22,
314
- :httpauth_avail, InfoType[:long] + 23,
315
- :proxyauth_avail, InfoType[:long] + 24,
316
- :os_errno, InfoType[:long] + 25,
317
- :num_connects, InfoType[:long] + 26,
318
- :ssl_engines, InfoType[:slist] + 27,
319
- :cookielist, InfoType[:slist] + 28,
320
- :lastsocket, InfoType[:long] + 29,
321
- :ftp_entry_path, InfoType[:string] + 30,
322
- :redirect_url, InfoType[:string] + 31,
323
- :primary_ip, InfoType[:string] + 32,
324
- :appconnect_time, InfoType[:double] + 33,
325
- :certinfo, InfoType[:slist] + 34,
326
- :condition_unmet, InfoType[:long] + 35,
327
- :rtsp_session_id, InfoType[:string] + 36,
328
- :rtsp_client_cseq, InfoType[:long] + 37,
329
- :rtsp_server_cseq, InfoType[:long] + 38,
330
- :rtsp_cseq_recv, InfoType[:long] + 39,
331
- :primary_port, InfoType[:long] + 40,
332
- :local_ip, InfoType[:string] + 41,
333
- :local_port, InfoType[:long] + 42,
334
- :last, 42]
335
-
336
- # Form options, used by FormAdd for temporary storage, refer
337
- # https://github.com/bagder/curl/blob/master/lib/formdata.h#L51 for details
338
- FormOption = enum :form_option, [
339
- :none,
340
- :copyname,
341
- :ptrname,
342
- :namelength,
343
- :copycontents,
344
- :ptrcontents,
345
- :contentslength,
346
- :filecontent,
347
- :array,
348
- :obsolete,
349
- :file,
350
- :buffer,
351
- :bufferptr,
352
- :bufferlength,
353
- :contenttype,
354
- :contentheader,
355
- :filename,
356
- :end,
357
- :obsolete2,
358
- :stream,
359
- :last]
360
-
361
- # :nodoc:
362
- Auth = enum [
363
- :basic, 0x01,
364
- :digest, 0x02,
365
- :gssnegotiate, 0x04,
366
- :ntlm, 0x08,
367
- :digest_ie, 0x10,
368
- :auto, 0x1f] # all options or'd together
369
-
370
- # :nodoc:
371
- Proxy = enum [
372
- :http, 0,
373
- :http_1_0, 1,
374
- :socks4, 4,
375
- :socks5, 5,
376
- :socks4a, 6,
377
- :socks5_hostname, 7]
378
-
379
- # :nodoc:
380
- SSLVersion = enum [
381
- :default, 0,
382
- :tlsv1, 1,
383
- :sslv2, 2,
384
- :sslv3, 3]
385
-
386
- # :nodoc:
387
- MsgCode = enum :msg_code, [:none, :done, :last]
388
-
389
- # :nodoc:
390
- class MsgData < ::FFI::Union
391
- layout :whatever, :pointer,
392
- :code, :easy_code
393
- end
394
-
395
- # :nodoc:
396
- class Msg < ::FFI::Struct
397
- layout :code, :msg_code,
398
- :easy_handle, :pointer,
399
- :data, MsgData
400
- end
401
-
402
- # :nodoc:
403
- class FDSet < ::FFI::Struct
404
- # XXX how does this work on non-windows? how can curl know the new size...
405
- FD_SETSIZE = 524288 # set a higher maximum number of fds. this has never applied to windows, so just use the default there
406
-
407
- if Curl.windows?
408
- layout :fd_count, :u_int,
409
- :fd_array, [:u_int, 64] # 2048 FDs
410
-
411
- def clear; self[:fd_count] = 0; end
412
- else
413
- layout :fds_bits, [:long, FD_SETSIZE / ::FFI::Type::LONG.size]
414
-
415
- # :nodoc:
416
- def clear; super; end
417
- end
418
- end
419
-
420
- # :nodoc:
421
- class Timeval < ::FFI::Struct
422
- layout :sec, :time_t,
423
- :usec, :suseconds_t
424
- end
425
-
426
- callback :callback, [:pointer, :size_t, :size_t, :pointer], :size_t
427
-
428
- ffi_lib_flags :now, :global
429
- ffi_lib ['libcurl', 'libcurl.so.4']
430
-
431
- attach_function :global_init, :curl_global_init, [:long], :int
432
-
433
- attach_function :easy_init, :curl_easy_init, [], :pointer
434
- attach_function :easy_cleanup, :curl_easy_cleanup, [:pointer], :void
435
- attach_function :easy_getinfo, :curl_easy_getinfo, [:pointer, :info, :pointer], :easy_code
436
- attach_function :easy_setopt, :curl_easy_setopt, [:pointer, :option, :pointer], :easy_code
437
- attach_function :easy_setopt_ffi_pointer, :curl_easy_setopt, [:pointer, :option, :pointer], :easy_code
438
- attach_function :easy_setopt_string, :curl_easy_setopt, [:pointer, :option, :string], :easy_code
439
- attach_function :easy_setopt_long, :curl_easy_setopt, [:pointer, :option, :long], :easy_code
440
- attach_function :easy_setopt_fixnum, :curl_easy_setopt, [:pointer, :option, :long], :easy_code
441
- attach_function :easy_setopt_callback, :curl_easy_setopt, [:pointer, :option, :callback], :easy_code
442
- attach_function :easy_setopt_proc, :curl_easy_setopt, [:pointer, :option, :callback], :easy_code
443
- attach_function :easy_perform, :curl_easy_perform, [:pointer], :easy_code
444
- attach_function :easy_strerror, :curl_easy_strerror, [:int], :string
445
- attach_function :easy_escape, :curl_easy_escape, [:pointer, :pointer, :int], :string
446
- attach_function :easy_reset, :curl_easy_reset, [:pointer], :void
447
-
448
- attach_function :formadd, :curl_formadd, [:pointer, :pointer, :varargs], :int
449
25
 
450
- attach_function :multi_init, :curl_multi_init, [], :pointer
451
- attach_function :multi_add_handle, :curl_multi_add_handle, [:pointer, :pointer], :multi_code
452
- attach_function :multi_remove_handle, :curl_multi_remove_handle, [:pointer, :pointer], :multi_code
453
- attach_function :multi_info_read, :curl_multi_info_read, [:pointer, :pointer], Msg.ptr
454
- attach_function :multi_perform, :curl_multi_perform, [:pointer, :pointer], :multi_code
455
- attach_function :multi_timeout, :curl_multi_timeout, [:pointer, :pointer], :multi_code
456
- attach_function :multi_fdset, :curl_multi_fdset, [:pointer, FDSet.ptr, FDSet.ptr, FDSet.ptr, :pointer], :multi_code
457
- attach_function :multi_strerror, :curl_multi_strerror, [:int], :string
458
-
459
- attach_function :version, :curl_version, [], :string
460
- attach_function :slist_append, :curl_slist_append, [:pointer, :string], :pointer
461
- attach_function :slist_free_all, :curl_slist_free_all, [:pointer], :void
26
+ require 'ethon/curls/constants'
27
+ require 'ethon/curls/settings'
28
+ require 'ethon/curls/classes'
29
+ extend Ethon::Curls::Functions
462
30
 
463
31
  if windows?
464
32
  ffi_lib 'ws2_32'
465
33
  else
466
34
  ffi_lib ::FFI::Library::LIBC
467
35
  end
36
+
468
37
  @blocking = true
469
- attach_function :select, [:int, FDSet.ptr, FDSet.ptr, FDSet.ptr, Timeval.ptr], :int
470
38
 
471
39
  @@initialized = false
472
40
  @@init_mutex = Mutex.new
@@ -495,91 +63,10 @@ module Ethon
495
63
  if not @@initialized
496
64
  raise Errors::GlobalInit.new if Curl.global_init(GLOBAL_ALL) != 0
497
65
  @@initialized = true
66
+ Ethon.logger.debug("ETHON: Libcurl initialized") if Ethon.logger
498
67
  end
499
68
  }
500
69
  end
501
-
502
- # Sets appropriate option for easy, depending on value type.
503
- def set_option(option, value, handle)
504
- return unless value
505
-
506
- method("easy_setopt_#{value.class.to_s.underscr}").call(handle, option, value)
507
- end
508
-
509
- # Return info as string.
510
- #
511
- # @example Return info.
512
- # Curl.get_info_string(:primary_ip, easy)
513
- #
514
- # @param [ Symbol ] option The option name.
515
- # @param [ ::FFI::Pointer ] handle The easy handle.
516
- #
517
- # @return [ String ] The info.
518
- def get_info_string(option, handle)
519
- if easy_getinfo(handle, option, string_ptr) == :ok
520
- string_ptr.read_pointer.read_string
521
- end
522
- end
523
-
524
- # Return info as integer.
525
- #
526
- # @example Return info.
527
- # Curl.get_info_long(:response_code, easy)
528
- #
529
- # @param [ Symbol ] option The option name.
530
- # @param [ ::FFI::Pointer ] handle The easy handle.
531
- #
532
- # @return [ Integer ] The info.
533
- def get_info_long(option, handle)
534
- if easy_getinfo(handle, option, long_ptr) == :ok
535
- long_ptr.read_long
536
- end
537
- end
538
-
539
- # Return info as float.
540
- #
541
- # @example Return info.
542
- # Curl.get_info_double(:response_code, easy)
543
- #
544
- # @param [ Symbol ] option The option name.
545
- # @param [ ::FFI::Pointer ] handle The easy handle.
546
- #
547
- # @return [ Float ] The info.
548
- def get_info_double(option, handle)
549
- if easy_getinfo(handle, option, double_ptr) == :ok
550
- double_ptr.read_double
551
- end
552
- end
553
-
554
- # Return a string pointer.
555
- #
556
- # @example Return a string pointer.
557
- # Curl.string_ptr
558
- #
559
- # @return [ ::FFI::Pointer ] The string pointer.
560
- def string_ptr
561
- @string_ptr ||= ::FFI::MemoryPointer.new(:pointer)
562
- end
563
-
564
- # Return a long pointer.
565
- #
566
- # @example Return a long pointer.
567
- # Curl.long_ptr
568
- #
569
- # @return [ ::FFI::Pointer ] The long pointer.
570
- def long_ptr
571
- @long_ptr ||= ::FFI::MemoryPointer.new(:long)
572
- end
573
-
574
- # Return a double pointer.
575
- #
576
- # @example Return a double pointer.
577
- # Curl.double_ptr
578
- #
579
- # @return [ ::FFI::Pointer ] The double pointer.
580
- def double_ptr
581
- @double_ptr ||= ::FFI::MemoryPointer.new(:double)
582
- end
583
70
  end
584
71
  end
585
72
  end
@@ -0,0 +1,25 @@
1
+ module Ethon
2
+ module Curls
3
+
4
+ # This module contain available auth types.
5
+ module AuthTypes
6
+
7
+ # Return available auth types.
8
+ #
9
+ # @example Return auth types.
10
+ # Ethon::Curl.auth_types
11
+ #
12
+ # @return [ Hash ] The auth types.
13
+ def auth_types
14
+ {
15
+ :basic => 0x01,
16
+ :digest => 0x02,
17
+ :gssnegotiate =>0x04,
18
+ :ntlm => 0x08,
19
+ :digest_ie => 0x10,
20
+ :auto => 0x1f
21
+ }
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,42 @@
1
+ module Ethon
2
+ module Curl
3
+ # :nodoc:
4
+ class MsgData < ::FFI::Union
5
+ layout :whatever, :pointer, :code, :easy_code
6
+ end
7
+
8
+ # :nodoc:
9
+ class Msg < ::FFI::Struct
10
+ layout :code, :msg_code, :easy_handle, :pointer, :data, MsgData
11
+ end
12
+
13
+ # :nodoc:
14
+ def Curl.windows?
15
+ !(RbConfig::CONFIG['host_os'] !~ /mingw|mswin|bccwin/)
16
+ end
17
+
18
+ # :nodoc:
19
+ class FDSet < ::FFI::Struct
20
+ # XXX how does this work on non-windows? how can curl know the new size...
21
+ FD_SETSIZE = 524288 # set a higher maximum number of fds. this has never applied to windows, so just use the default there
22
+
23
+ if Curl.windows?
24
+ layout :fd_count, :u_int,
25
+ :fd_array, [:u_int, 64] # 2048 FDs
26
+
27
+ def clear; self[:fd_count] = 0; end
28
+ else
29
+ layout :fds_bits, [:long, FD_SETSIZE / ::FFI::Type::LONG.size]
30
+
31
+ # :nodoc:
32
+ def clear; super; end
33
+ end
34
+ end
35
+
36
+ # :nodoc:
37
+ class Timeval < ::FFI::Struct
38
+ layout :sec, :time_t,
39
+ :usec, :suseconds_t
40
+ end
41
+ end
42
+ end