Skip to content

Commit 6a2e1af

Browse files
committed
feat(ffi): expand FFI with 6 functions, 13 CURLINFO, 7 CURLcode, 14 CURLOPT
Add curl_global_init/cleanup, curl_version_info (with CurlVersionInfo struct), curl_easy_pause, curl_easy_upkeep, curl_multi_assign. Add microsecond timing CURLINFO codes (_T variants), REDIRECT_TIME, RETRY_AFTER, SIZE/SPEED _T variants. Add CURLcode values for FILESIZE_EXCEEDED, TOO_MANY_REDIRECTS, HTTP3, PARTIAL_FILE, RANGE_ERROR, AGAIN, UNRECOVERABLE_POLL. Add CURLOPT for CONNECT_TO, HAPROXYPROTOCOL, HTTPPOST stub, ABSTRACT_UNIX_SOCKET, DOH_SSL_VERIFY*, blob options, BUFFERSIZE, MAXLIFETIME_CONN, FILETIME. Fix proptest cookie domain generation to avoid PSL-rejected domains. 56 total FFI functions.
1 parent a3e37f7 commit 6a2e1af

3 files changed

Lines changed: 769 additions & 1 deletion

File tree

crates/liburlx-ffi/include/urlx.h

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,68 @@
99
#include <stdlib.h>
1010
typedef void CURL;
1111

12+
/**
13+
* Bitmask constants for `curl_global_init`.
14+
* `CURL_GLOBAL_SSL` — initialize SSL.
15+
*/
16+
#define CURL_GLOBAL_SSL 1
17+
18+
/**
19+
* `CURL_GLOBAL_WIN32` — initialize Win32 sockets.
20+
*/
21+
#define CURL_GLOBAL_WIN32 2
22+
23+
/**
24+
* `CURL_GLOBAL_ALL` — initialize everything.
25+
*/
26+
#define CURL_GLOBAL_ALL 3
27+
28+
/**
29+
* `CURL_GLOBAL_DEFAULT` — same as ALL.
30+
*/
31+
#define CURL_GLOBAL_DEFAULT 3
32+
33+
/**
34+
* Feature bit: SSL support.
35+
*/
36+
#define CURL_VERSION_SSL (1 << 2)
37+
38+
/**
39+
* Feature bit: HTTP/2 support.
40+
*/
41+
#define CURL_VERSION_HTTP2 (1 << 16)
42+
43+
/**
44+
* Feature bit: async DNS support.
45+
*/
46+
#define CURL_VERSION_ASYNCHDNS (1 << 7)
47+
48+
/**
49+
* Feature bit: PSL support.
50+
*/
51+
#define CURL_VERSION_PSL (1 << 20)
52+
53+
/**
54+
* Pause direction constants.
55+
* `CURLPAUSE_RECV` — pause receiving.
56+
*/
57+
#define CURLPAUSE_RECV 1
58+
59+
/**
60+
* `CURLPAUSE_SEND` — pause sending.
61+
*/
62+
#define CURLPAUSE_SEND 4
63+
64+
/**
65+
* `CURLPAUSE_ALL` — pause both directions.
66+
*/
67+
#define CURLPAUSE_ALL 5
68+
69+
/**
70+
* `CURLPAUSE_CONT` — unpause both directions.
71+
*/
72+
#define CURLPAUSE_CONT 0
73+
1274
/**
1375
* `CURLINFO` — info codes for `curl_easy_getinfo`.
1476
*/
@@ -43,6 +105,19 @@ typedef enum CURLINFO {
43105
CURLINFO_PRIMARY_PORT = 2097216,
44106
CURLINFO_LOCAL_PORT = 2097218,
45107
CURLINFO_SCHEME = 1048644,
108+
CURLINFO_REDIRECT_TIME = 3145747,
109+
CURLINFO_TOTAL_TIME_T = 6291518,
110+
CURLINFO_NAMELOOKUP_TIME_T = 6291519,
111+
CURLINFO_CONNECT_TIME_T = 6291520,
112+
CURLINFO_PRETRANSFER_TIME_T = 6291521,
113+
CURLINFO_STARTTRANSFER_TIME_T = 6291522,
114+
CURLINFO_REDIRECT_TIME_T = 6291523,
115+
CURLINFO_APPCONNECT_TIME_T = 6291524,
116+
CURLINFO_RETRY_AFTER = 2097210,
117+
CURLINFO_SIZE_UPLOAD_T = 6291525,
118+
CURLINFO_SIZE_DOWNLOAD_T = 6291526,
119+
CURLINFO_SPEED_DOWNLOAD_T = 6291527,
120+
CURLINFO_SPEED_UPLOAD_T = 6291528,
46121
} CURLINFO;
47122

48123
/**
@@ -120,7 +195,14 @@ typedef enum CURLcode {
120195
CURLE_RECV_ERROR = 56,
121196
CURLE_SSL_CERTPROBLEM = 58,
122197
CURLE_PEER_FAILED_VERIFICATION = 60,
198+
CURLE_FILESIZE_EXCEEDED = 63,
123199
CURLE_LOGIN_DENIED = 67,
200+
CURLE_TOO_MANY_REDIRECTS = 47,
201+
CURLE_HTTP3 = 95,
202+
CURLE_PARTIAL_FILE = 18,
203+
CURLE_RANGE_ERROR = 33,
204+
CURLE_AGAIN = 81,
205+
CURLE_UNRECOVERABLE_POLL = 99,
124206
} CURLcode;
125207

126208
/**
@@ -265,6 +347,51 @@ typedef struct curl_waitfd {
265347
short revents;
266348
} curl_waitfd;
267349

350+
/**
351+
* Version info struct returned by `curl_version_info`.
352+
*
353+
* Matches the `curl_version_info_data` struct from libcurl.
354+
* Only the essential fields are populated.
355+
*/
356+
typedef struct CurlVersionInfo {
357+
/**
358+
* Age of this struct (`CURLVERSION_FIRST` = 0).
359+
*/
360+
long age;
361+
/**
362+
* Version string (e.g., "0.1.0").
363+
*/
364+
const char *version;
365+
/**
366+
* Numeric version (major*0x10000 + minor*0x100 + patch).
367+
*/
368+
long version_num;
369+
/**
370+
* Host system description.
371+
*/
372+
const char *host;
373+
/**
374+
* Feature bitmask.
375+
*/
376+
long features;
377+
/**
378+
* SSL version string or NULL.
379+
*/
380+
const char *ssl_version;
381+
/**
382+
* Unused (libssl version number).
383+
*/
384+
long ssl_version_num;
385+
/**
386+
* libz version string or NULL.
387+
*/
388+
const char *libz_version;
389+
/**
390+
* Null-terminated array of supported protocols.
391+
*/
392+
const char *const *protocols;
393+
} CurlVersionInfo;
394+
268395
#ifdef __cplusplus
269396
extern "C" {
270397
#endif // __cplusplus
@@ -820,6 +947,66 @@ enum CURLMcode curl_multi_socket_action(void *multi,
820947
*/
821948
const char *urlx_version(void) ;
822949

950+
/**
951+
* `curl_global_init` — global initialization (no-op in urlx).
952+
*
953+
* In libcurl this initializes SSL, Win32 sockets, etc. In urlx, tokio
954+
* and rustls handle their own initialization, so this is a no-op.
955+
*
956+
* # Safety
957+
*
958+
* This function is always safe to call.
959+
*/
960+
enum CURLcode curl_global_init(long _flags) ;
961+
962+
/**
963+
* `curl_global_cleanup` — global cleanup (no-op in urlx).
964+
*
965+
* # Safety
966+
*
967+
* This function is always safe to call.
968+
*/
969+
void curl_global_cleanup(void) ;
970+
971+
/**
972+
* `curl_version_info` — return version info struct.
973+
*
974+
* Returns a pointer to a static struct with version information.
975+
* The pointer is valid for the lifetime of the program.
976+
*
977+
* # Safety
978+
*
979+
* The returned pointer is valid for the lifetime of the program.
980+
*/
981+
const struct CurlVersionInfo *curl_version_info(long _age) ;
982+
983+
/**
984+
* `curl_easy_pause` — pause/unpause a transfer (stub).
985+
*
986+
* # Safety
987+
*
988+
* `handle` must be a valid pointer from `curl_easy_init`.
989+
*/
990+
enum CURLcode curl_easy_pause(void *_handle, long _bitmask) ;
991+
992+
/**
993+
* `curl_easy_upkeep` — perform connection upkeep (no-op).
994+
*
995+
* # Safety
996+
*
997+
* `handle` must be a valid pointer from `curl_easy_init`.
998+
*/
999+
enum CURLcode curl_easy_upkeep(void *_handle) ;
1000+
1001+
/**
1002+
* `curl_multi_assign` — assign custom pointer to socket (no-op stub).
1003+
*
1004+
* # Safety
1005+
*
1006+
* `multi_handle` must be a valid pointer from `curl_multi_init`.
1007+
*/
1008+
enum CURLMcode curl_multi_assign(void *_multi_handle, long _sockfd, void *_sockp) ;
1009+
8231010
#ifdef __cplusplus
8241011
} // extern "C"
8251012
#endif // __cplusplus

0 commit comments

Comments
 (0)