-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathffi.bqn
107 lines (87 loc) · 2.9 KB
/
ffi.bqn
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
⟨
easyInit,
easyCleanup,
easyReset,
easySetoptStr,
easySetoptPtr,
easySetoptLong,
easyPerform,
easyGetinfoStr,
easyGetinfoLong,
easyGetinfoDouble,
slistAppend,
slistFreeAll,
fopen,
fclose,
curlOptions,
curlInfo
⟩⇐
⟨Hex2Num⟩←•Import"utils.bqn"
⟨libcurlPath⟩←•Import"config.bqn"
CurlFFI←libcurlPath⊸•FFI
curlPtr ←"*:i8"
curlOption←"i32"
curlCode ←"i32"
easyInit ←CurlFFI⟨curlPtr,"curl_easy_init"⟩
easyCleanup ←CurlFFI⟨"","curl_easy_cleanup",">"∾curlPtr⟩
easyReset ←CurlFFI⟨"","curl_easy_reset",">"∾curlPtr⟩
easySetoptStr ←CurlFFI⟨curlCode,"curl_easy_setopt",curlPtr,curlOption,"*u8:c8"⟩
easySetoptPtr ←CurlFFI⟨curlCode,"curl_easy_setopt",curlPtr,curlOption,"*:i8"⟩
easySetoptLong ←CurlFFI⟨curlCode,"curl_easy_setopt",curlPtr,curlOption,"i32"⟩
easyPerform ←CurlFFI⟨curlCode,"curl_easy_perform",curlPtr⟩
easyGetinfoStr ←CurlFFI⟨curlCode,"curl_easy_getinfo",curlPtr,curlOption,"&u8:c8"⟩
easyGetinfoLong ←CurlFFI⟨curlCode,"curl_easy_getinfo",curlPtr,curlOption,"&i32"⟩
easyGetinfoDouble←CurlFFI⟨curlCode,"curl_easy_getinfo",curlPtr,curlOption,"&f64"⟩
slistAppend ←CurlFFI⟨"*:i8","curl_slist_append","*:i8","*u8:c8"⟩
slistFreeAll ←CurlFFI⟨"","curl_slist_free_all",">*:i8"⟩
fopen ←@•FFI⟨"*:i8","fopen","*u8:c8","*u8:c8"⟩
fclose ←@•FFI⟨"","fclose",">*:i8"⟩
curlOptions←{
strOffset←10000
slistOffset←10000
ptrOffset←10000
# boolean options
verbose⇐41
header⇐42
noprogress⇐43
post⇐47
followlocation⇐52
httpget⇐80
# long integer options
postfieldsize⇐60 # size of the POST input data
timeout⇐78 # timeout in seconds
timeoutms⇐155 # timeout in milliseconds
# string options, null-terminated
url⇐strOffset+2
userpwd⇐strOffset+5 # user:password
useragent⇐strOffset+18
# pointer options
writedata⇐ptrOffset+1 # FILE* in which to write response content
postfields⇐ptrOffset+15 # pointer to POST input data
headerdata⇐ptrOffset+29 # FILE* in which to write response headers
# linked list options
httpHeader⇐slistOffset+23 # HTTP headers as a list of strings
}
curlInfo←{
strOffset←Hex2Num"100000"
longOffset←Hex2Num"200000"
doubleOffset←Hex2Num"300000"
slistOffset←Hex2Num"400000"
ptrOffset←Hex2Num"400000"
# long integer info
responseCode⇐longOffset+2
headerSize⇐longOffset+11 # in bytes
requestSize⇐longOffset+12 # in bytes
redirectCount⇐longOffset+20
httpVersion⇐longOffset+46
# double info
totalTime⇐doubleOffset+3 # in seconds
nameLookupTime⇐doubleOffset+4 # in seconds
connectTime⇐doubleOffset+5 # in seconds
# string info
effectiveUrl⇐strOffset+1
contentType⇐strOffset+18
primaryIP⇐strOffset+32
httpScheme⇐strOffset+49
effectiveMethod⇐strOffset+58
}