bqn-curl/ffi.bqn

108 lines
3 KiB
BQN

easyInit,
easyCleanup,
easyReset,
easySetoptStr,
easySetoptPtr,
easySetoptLong,
easyPerform,
easyGetinfoStr,
easyGetinfoLong,
easyGetinfoDouble,
slistAppend,
slistFreeAll,
fopen,
fclose,
curlOptions,
curlInfo
Hex2Num•Import"utils.bqn"
libcurlPath•Import"config.bqn"
CurlFFIlibcurlPath•FFI
curlPtr "*:i8"
curlOption"i32"
curlCode "i32"
easyInit CurlFFIcurlPtr,"curl_easy_init"
easyCleanup CurlFFI"","curl_easy_cleanup",">"curlPtr
easyReset CurlFFI"","curl_easy_reset",">"curlPtr
easySetoptStr CurlFFIcurlCode,"curl_easy_setopt",curlPtr,curlOption,"*u8:c8"
easySetoptPtr CurlFFIcurlCode,"curl_easy_setopt",curlPtr,curlOption,"*:i8"
easySetoptLong CurlFFIcurlCode,"curl_easy_setopt",curlPtr,curlOption,"i32"
easyPerform CurlFFIcurlCode,"curl_easy_perform",curlPtr
easyGetinfoStr CurlFFIcurlCode,"curl_easy_getinfo",curlPtr,curlOption,"&u8:c8"
easyGetinfoLong CurlFFIcurlCode,"curl_easy_getinfo",curlPtr,curlOption,"&i32"
easyGetinfoDoubleCurlFFIcurlCode,"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{
strOffset10000
slistOffset10000
ptrOffset10000
# boolean options
verbose41
header42
noprogress43
post47
followlocation52
httpget80
# long integer options
postfieldsize60 # size of the POST input data
timeout78 # timeout in seconds
timeoutms155 # timeout in milliseconds
# string options, null-terminated
urlstrOffset+2
userpwdstrOffset+5 # user:password
useragentstrOffset+18
# pointer options
writedataptrOffset+1 # FILE* in which to write response content
postfieldsptrOffset+15 # pointer to POST input data
headerdataptrOffset+29 # FILE* in which to write response headers
copypostfieldsptrOffset+165 # copy POST input data
# linked list options
httpHeaderslistOffset+23 # HTTP headers as a list of strings
}
curlInfo{
strOffsetHex2Num"100000"
longOffsetHex2Num"200000"
doubleOffsetHex2Num"300000"
slistOffsetHex2Num"400000"
ptrOffsetHex2Num"400000"
# long integer info
responseCodelongOffset+2
headerSizelongOffset+11 # in bytes
requestSizelongOffset+12 # in bytes
redirectCountlongOffset+20
httpVersionlongOffset+46
# double info
totalTimedoubleOffset+3 # in seconds
nameLookupTimedoubleOffset+4 # in seconds
connectTimedoubleOffset+5 # in seconds
# string info
effectiveUrlstrOffset+1
contentTypestrOffset+18
primaryIPstrOffset+32
httpSchemestrOffset+49
effectiveMethodstrOffset+58
}