-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcl-curl.lisp
More file actions
49 lines (41 loc) · 1.5 KB
/
Copy pathcl-curl.lisp
File metadata and controls
49 lines (41 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
(ql:quickload :cffi)
(defpackage :cffi-user
(:use :common-lisp :cffi))
(in-package :cffi-user)
(define-foreign-library libcurl
(:unix (:or "libcurl.so.3" "libcurl.so" "libcurl.so.4"))
(t (:default libcurl)))
(use-foreign-library libcurl)
(defctype curl-code :int)
;;; CURL code is the universal error code.
(defcfun "curl_global_init" curl-code
(flags :long))
(defcfun "curl_easy_init" :pointer)
(defcfun "curl_easy_cleanup" :void)
(defmacro define-curl-options (name type-offsets &rest enum-args)
"As with `CFFI:DEFCENUM', except each of `ENUM-ARGS' is as follows:
(NAME TYPE NUMBER)
Where the arguments are as they are with the
`CINIT' macro defined in curl.h, except NAME is a keyword.
`TYPE-OFFSETS' is a plist of TYPEs to their integer offsets, as
defined by the CURLOPTTYPE_LONG et al contrains in curl.h"
(flet ((enumerated-value (type offset)
(+ (getf type-offsets type)
offset)))
`(progn
(defcenum ,name
,@ (loop for (name type number) in enum-args
collect (list name (enumerated-value type number))))
',name)))
(define-curl-options curl-option
(long 0 objectpoint 10000 functionpoint 20000 off-t 30000)
(:noprogress long 43)
(:nosignal long 99)
(:errorbuffer objectpoint 10)
(:url objectpoint 2))
(defctype easy-handle :pointer)
(defmacro curl-easy-setopt (easy-handle enumerated-name
value-type new-value)
`(foreign-funcall "curl_easy_setopt" easy-handle ,easy-handle
curl-option ,enumerated-name
,value-type ,new-value curl-code))