diff options
| author | Julian Hurst <ark@mansus.space> | 2024-03-10 02:35:08 +0100 |
|---|---|---|
| committer | Julian Hurst <ark@mansus.space> | 2024-03-10 02:35:08 +0100 |
| commit | 89173069e85416539b1256ed1ae1c77e89550ae6 (patch) | |
| tree | d2f42c63b91306ad1b4693737ab1e35514d746b9 /curl.ha | |
| parent | 69712258bafda1258454e6336faabf527f207e3b (diff) | |
| download | hacurl-89173069e85416539b1256ed1ae1c77e89550ae6.tar.gz | |
Allow retrieving in memory response struct, and cleanup
Diffstat (limited to 'curl.ha')
| -rw-r--r-- | curl.ha | 70 |
1 files changed, 0 insertions, 70 deletions
diff --git a/curl.ha b/curl.ha deleted file mode 100644 index 4c0c56d..0000000 --- a/curl.ha +++ /dev/null @@ -1,70 +0,0 @@ -use types::c; -use fmt; -use os; - -export type CURL = opaque; -export type CURLcode = int; -export type CURLINFO = int; - -def CURLOPT_URL = 10002; - -def CURLINFO_LONG = 0x200000; -def CURLINFO_RESPONSE_CODE = CURLINFO_LONG + 2; - -export @symbol("curl_easy_init") fn curl_easy_init() nullable *CURL; -export @symbol("curl_easy_cleanup") fn curl_easy_cleanup(handle: nullable *CURL) void; -export @symbol("curl_easy_setopt") fn curl_easy_setopt( - handle: nullable *CURL, - option: int, - parameter: const *c::char -) CURLcode; - -export @symbol("curl_easy_perform") fn curl_easy_perform(easy_handle: nullable *CURL) CURLcode; -export @symbol("curl_easy_getinfo") fn curl_easy_getinfo( - easy_handle: nullable *CURL, - info: CURLINFO, - code: nullable *c::long -) CURLcode; - -type curlerror = !(setopterr | performerr | getinfoerr); - -type setopterr = !int; -type performerr = !int; -type getinfoerr = !int; - -fn get(url: const str) (void | curlerror) = { - let c = curl_easy_init(); - defer curl_easy_cleanup(c); - let c_url = c::fromstr(url); - defer free(c_url); - let res = curl_easy_setopt(c, CURLOPT_URL, c_url); - if (res != 0) { - return res: setopterr; - }; - res = curl_easy_perform(c); - if (res != 0) { - return res: performerr; - }; - let rc: c::long = 0; - res = curl_easy_getinfo(c, CURLINFO_RESPONSE_CODE, &rc); - if (res != 0) { - return res: getinfoerr; - }; - fmt::println(rc)!; -}; - -export fn main() void = { - if (len(os::args) != 2) { - fmt::fatalf("USAGE: {} <url>", os::args[0]); - }; - match (get(os::args[1])) { - case void => - yield; - case let err: setopterr => - fmt::fatalf("setopt returned {} instead of 0", err: int); - case let err: performerr => - fmt::fatalf("perform returned {} instead of 0", err: int); - case let err: getinfoerr => - fmt::fatalf("getinfo returned {} instead of 0", err: int); - }; -}; |
