Expand description
§liburlx-ffi
C ABI compatibility layer for liburlx — a drop-in replacement for libcurl.
This crate provides libcurl-compatible C functions (curl_easy_init,
curl_easy_setopt, curl_easy_perform, etc.) backed by the pure-Rust
liburlx engine. Existing C/C++ programs can link against liburlx_ffi
instead of libcurl without code changes.
All unsafe code in the urlx project is confined to this crate.
§Usage
#include "urlx.h"
CURL *curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
CURLcode res = curl_easy_perform(curl);
curl_easy_cleanup(curl);§Coverage
- 156
CURLOPToptions - 49
CURLINFOqueries - 41
CURLcodeerror codes - 57 exported C functions (all wrapped in
catch_unwind)
§Safety Invariants
The following safety contracts apply throughout this crate:
-
Handle pointers (
*mut c_voidfor easy/multi/share/url/mime handles): All callers must provide valid, non-null pointers obtained from the corresponding_initfunction. Every exported function null-checks its handle argument before dereferencing. Handles areBox-allocated and cast to*mut c_void;Box::from_rawreclaims ownership in_cleanup. -
C strings (
*const c_char): Callers must provide valid, null-terminated strings. The helperread_cstr()combines null-check +CStr::from_ptr+ UTF-8 validation. DirectCStr::from_ptrcalls appear whereread_cstris insufficient (e.g., when the pointer type differs or when non-UTF-8 data is acceptable). -
Output pointers in
curl_easy_getinfo: Callers must provide a valid pointer to the expected output type (*mut c_long,*mut f64,*mut *const c_char,*mut i64). Each match arm castsoutto the documented type and writes through it. The function null-checksoutbefore the match. -
Callback function pointers:
std::mem::transmuteconverts*const c_voidto the appropriate callback signature. Callers must ensure the pointer is actually a function with the documented C signature. Callbacks are invoked duringcurl_easy_performwith the corresponding*datapointer passed as the user-data argument. -
curl_slisttraversal: Linked-list nodes are caller-allocated. The list is walked via(*node).nextuntil null. Eachnode.datais a caller-owned C string.curl_slist_free_allreclaims all nodes. -
Panic safety: All exported
#[no_mangle]functions wrap their body instd::panic::catch_unwindto prevent Rust panics from unwinding across the FFI boundary.
Structs§
- CURLMsg
CURLMsg— completion message fromcurl_multi_info_read.- Curl
Version Info - Version info struct returned by
curl_version_info. - curl_
blob curl_blob— in-memory binary data for TLS certificate/key options.- curl_
slist - Linked list node for string data (e.g., HTTP headers).
- curl_
waitfd curl_waitfd— extra file descriptor forcurl_multi_wait/curl_multi_poll.
Enums§
- CURLINFO
CURLINFO— info codes forcurl_easy_getinfo.- CURLMSG
CURLMSG— message types fromcurl_multi_info_read.- CURL
Mcode CURLMcode— result codes for multi handle operations.- CURL
Moption CURLMoption— option codes forcurl_multi_setopt.- CURLS
Hcode CURLSHcode— result codes for share handle operations.- CURLS
Hoption CURLSHoption— option codes forcurl_share_setopt.- CURLU
Part CURLUPart— part identifiers for URL manipulation.- CURL
Ucode CURLUcode— result codes for URL API operations.- CURLcode
CURLcode— result codes for easy handle operations.- CURLoption
CURLOPT— option codes forcurl_easy_setopt.
Constants§
- CURLPAUSE_
ALL CURLPAUSE_ALL— pause both directions.- CURLPAUSE_
CONT CURLPAUSE_CONT— unpause both directions.- CURLPAUSE_
RECV - Pause direction constants.
CURLPAUSE_RECV— pause receiving. - CURLPAUSE_
SEND CURLPAUSE_SEND— pause sending.- CURL_
GLOBAL_ ALL CURL_GLOBAL_ALL— initialize everything.- CURL_
GLOBAL_ DEFAULT CURL_GLOBAL_DEFAULT— same as ALL.- CURL_
GLOBAL_ SSL - Bitmask constants for
curl_global_init.CURL_GLOBAL_SSL— initialize SSL. - CURL_
GLOBAL_ WIN32 CURL_GLOBAL_WIN32— initialize Win32 sockets.- CURL_
VERSION_ ASYNCHDNS - Feature bit: async DNS support.
- CURL_
VERSION_ HTTP2 - Feature bit: HTTP/2 support.
- CURL_
VERSION_ PSL - Feature bit: PSL support.
- CURL_
VERSION_ SSL - Feature bit: SSL support.
Functions§
- curl_
easy_ ⚠cleanup curl_easy_cleanup— free an easy handle.- curl_
easy_ ⚠duphandle curl_easy_duphandle— clone an easy handle.- curl_
easy_ ⚠escape curl_easy_escape— URL-encode a string using an easy handle.- curl_
easy_ ⚠getinfo curl_easy_getinfo— get info about the last transfer.- curl_
easy_ init curl_easy_init— create a new easy handle.- curl_
easy_ pause curl_easy_pause— pause/unpause a transfer (stub).- curl_
easy_ ⚠perform curl_easy_perform— perform the transfer.- curl_
easy_ ⚠reset curl_easy_reset— reset an easy handle to initial state.- curl_
easy_ ⚠setopt curl_easy_setopt— set options on an easy handle.- curl_
easy_ strerror curl_easy_strerror— return a human-readable error message.- curl_
easy_ ⚠unescape curl_easy_unescape— URL-decode a string using an easy handle.- curl_
easy_ upkeep curl_easy_upkeep— perform connection upkeep (no-op).- curl_
escape ⚠ curl_escape— URL-encode a string.- curl_
formadd ⚠ curl_formadd— deprecated multipart form API.- curl_
formfree ⚠ curl_formfree— free a form created bycurl_formadd.- curl_
free ⚠ curl_free— free memory allocated by curl functions.- curl_
getdate ⚠ curl_getdate— parse a date string to a Unix timestamp.- curl_
global_ cleanup curl_global_cleanup— global cleanup (no-op in urlx).- curl_
global_ init curl_global_init— global initialization (no-op in urlx).- curl_
mime_ ⚠addpart curl_mime_addpart— add a new part to a MIME handle.- curl_
mime_ ⚠data curl_mime_data— set data for a MIME part.- curl_
mime_ ⚠filename curl_mime_filename— set the filename for a MIME part.- curl_
mime_ ⚠free curl_mime_free— free a MIME handle and all its parts.- curl_
mime_ ⚠init curl_mime_init— create a new MIME handle.- curl_
mime_ ⚠name curl_mime_name— set the name of a MIME part.- curl_
mime_ ⚠type curl_mime_type— set the MIME type for a MIME part.- curl_
multi_ ⚠add_ handle curl_multi_add_handle— add an easy handle to a multi handle.- curl_
multi_ assign curl_multi_assign— assign custom pointer to socket (no-op stub).- curl_
multi_ ⚠cleanup curl_multi_cleanup— free a multi handle.- curl_
multi_ ⚠fdset curl_multi_fdset— extract file descriptors from the multi handle.- curl_
multi_ ⚠info_ read curl_multi_info_read— read a completion message from the multi handle.- curl_
multi_ init curl_multi_init— create a new multi handle.- curl_
multi_ ⚠perform curl_multi_perform— perform all queued transfers.- curl_
multi_ ⚠poll curl_multi_poll— poll for activity on any of the multi handle’s transfers.- curl_
multi_ ⚠remove_ handle curl_multi_remove_handle— remove an easy handle from a multi handle.- curl_
multi_ ⚠setopt curl_multi_setopt— set options on a multi handle.- curl_
multi_ ⚠socket_ action curl_multi_socket_action— socket action interface for event-driven programs.- curl_
multi_ strerror curl_multi_strerror— return a human-readable multi error message.- curl_
multi_ ⚠timeout curl_multi_timeout— return the timeout value for the multi handle.- curl_
multi_ ⚠wait curl_multi_wait— wait for activity on any of the multi handle’s transfers.- curl_
multi_ ⚠wakeup curl_multi_wakeup— wake up a sleepingcurl_multi_poll.- curl_
share_ ⚠cleanup curl_share_cleanup— free a share handle.- curl_
share_ init curl_share_init— create a new share handle.- curl_
share_ ⚠setopt curl_share_setopt— set options on a share handle.- curl_
share_ strerror curl_share_strerror— return a human-readable share error message.- curl_
slist_ ⚠append curl_slist_append— append a string to a linked list.- curl_
slist_ ⚠free_ all curl_slist_free_all— free an entire linked list.- curl_
unescape ⚠ curl_unescape— URL-decode a string.- curl_
url curl_url— create a new URL handle.- curl_
url_ ⚠cleanup curl_url_cleanup— free a URL handle.- curl_
url_ ⚠dup curl_url_dup— duplicate a URL handle.- curl_
url_ ⚠get curl_url_get— get a URL component.- curl_
url_ ⚠set curl_url_set— set a URL component.- curl_
version curl_version— returns the version string (libcurl compatibility).- curl_
version_ info curl_version_info— return version info struct.- urlx_
version urlx_version— returns the version string.