Improve bit_set usage

This commit is contained in:
gingerBill
2025-09-04 12:39:30 +01:00
parent f1ab395bfd
commit 9c0a41552d
6 changed files with 115 additions and 50 deletions

18
vendor/curl/curl.odin vendored
View File

@@ -129,6 +129,15 @@ httppost_flag :: enum c.long {
LARGE = 7,
}
HTTPPOST_FILENAME :: httppost_flags{.FILENAME}
HTTPPOST_READFILE :: httppost_flags{.READFILE}
HTTPPOST_PTRNAME :: httppost_flags{.PTRNAME}
HTTPPOST_PTRCONTENTS :: httppost_flags{.PTRCONTENTS}
HTTPPOST_BUFFER :: httppost_flags{.BUFFER}
HTTPPOST_PTRBUFFER :: httppost_flags{.PTRBUFFER}
HTTPPOST_CALLBACK :: httppost_flags{.CALLBACK}
HTTPPOST_LARGE :: httppost_flags{.LARGE}
httppost :: struct {
next: ^httppost, /* next entry in the list */
name: cstring `fmt:"v,name"`, /* pointer to allocated name */
@@ -239,6 +248,15 @@ finfoflag :: enum c.uint {
KNOWN_HLINKCOUNT = 7,
}
FINFOFLAG_KNOWN_FILENAME :: finfoflags{.KNOWN_FILENAME}
FINFOFLAG_KNOWN_FILETYPE :: finfoflags{.KNOWN_FILETYPE}
FINFOFLAG_KNOWN_TIME :: finfoflags{.KNOWN_TIME}
FINFOFLAG_KNOWN_PERM :: finfoflags{.KNOWN_PERM}
FINFOFLAG_KNOWN_UID :: finfoflags{.KNOWN_UID}
FINFOFLAG_KNOWN_GID :: finfoflags{.KNOWN_GID}
FINFOFLAG_KNOWN_SIZE :: finfoflags{.KNOWN_SIZE}
FINFOFLAG_KNOWN_HLINKCOUNT :: finfoflags{.KNOWN_HLINKCOUNT}
/* Information about a single file, used when doing FTP wildcard matching */
fileinfo :: struct {
filename: cstring,

View File

@@ -3,14 +3,19 @@ package vendor_curl
import c "core:c/libc"
/* Flag bits in the curl_blob struct: */
BLOB_COPY :: 1 /* tell libcurl to copy the data */
BLOB_NOCOPY :: 0 /* tell libcurl to NOT copy the data */
BLOB_COPY :: blob_flags{.COPY} /* tell libcurl to copy the data */
BLOB_NOCOPY :: blob_flags{} /* tell libcurl to NOT copy the data */
blob_flags :: distinct bit_set[blob_flag; c.uint]
blob_flag :: enum c.uint {
COPY = 0,
}
blob :: struct {
data: rawptr,
len: c.size_t,
flags: c.uint, /* bit 0 is defined, the rest are reserved and should be
left zeroes */
flags: blob_flags, /* bit 0 is defined, the rest are reserved and should be
left zeroes */
}
@(default_calling_convention="c", link_prefix="curl_")

View File

@@ -8,16 +8,25 @@ header :: struct {
value: cstring,
amount: c.size_t, /* number of headers using this name */
index: c.size_t, /* ... of this instance, 0 or higher */
origin: c.uint, /* see bits below */
origin: header_origin_bits, /* see bits below */
anchor: rawptr, /* handle privately used by libcurl */
}
header_origin_bits :: distinct bit_set[header_origin_bit; c.uint]
/* 'origin' bits */
H_HEADER :: 1<<0 /* plain server header */
H_TRAILER :: 1<<1 /* trailers */
H_CONNECT :: 1<<2 /* CONNECT headers */
H_1XX :: 1<<3 /* 1xx headers */
H_PSEUDO :: 1<<4 /* pseudo headers */
header_origin_bit :: enum c.uint {
H_HEADER = 0, /* plain server header */
H_TRAILER = 1, /* trailers */
H_CONNECT = 2, /* CONNECT headers */
H_1XX = 3, /* 1xx headers */
H_PSEUDO = 4, /* pseudo headers */
}
H_HEADER :: header_origin_bits{.H_HEADER} /* plain server header */
H_TRAILER :: header_origin_bits{.H_TRAILER} /* trailers */
H_CONNECT :: header_origin_bits{.H_CONNECT} /* CONNECT headers */
H_1XX :: header_origin_bits{.H_1XX} /* 1xx headers */
H_PSEUDO :: header_origin_bits{.H_PSEUDO} /* pseudo headers */
Hcode :: enum c.int {
E_OK,

View File

@@ -14,9 +14,13 @@ easytype :: enum c.int {
OT_FUNCTION, /* function pointer */
}
/* "alias" means it is provided for old programs to remain functional,
we prefer another name */
OT_FLAG_ALIAS :: 1<<0
easyoptionflags :: distinct bit_set[easyoptionflag; c.uint]
easyoptionflag :: enum c.uint {
/* "alias" means it is provided for old programs to remain functional,
we prefer another name */
ALIAS = 0,
}
/* The CURLOPTTYPE_* id ranges can still be used to figure out what type/size
to use for curl_easy_setopt() for the given id */
@@ -24,7 +28,7 @@ easyoption :: struct {
name: cstring,
id: option,
type: easytype,
flags: c.uint,
flags: easyoptionflags,
}

View File

@@ -54,30 +54,48 @@ UPart :: enum c.int {
ZONEID, /* added in 7.65.0 */
}
UFlags :: distinct bit_set[UFlag; c.uint]
UFlag :: enum c.uint {
DEFAULT_PORT = 0, /* return default port number */
NO_DEFAULT_PORT = 1, /* act as if no port number was set,
if the port number matches the
default for the scheme */
DEFAULT_SCHEME = 2, /* return default scheme if
missing */
NON_SUPPORT_SCHEME = 3, /* allow non-supported scheme */
PATH_AS_IS = 4, /* leave dot sequences */
DISALLOW_USER = 5, /* no user+password allowed */
URLDECODE = 6, /* URL decode on get */
URLENCODE = 7, /* URL encode on set */
APPENDQUERY = 8, /* append a form style part */
GUESS_SCHEME = 9, /* legacy curl-style guessing */
NO_AUTHORITY = 10, /* Allow empty authority when the
scheme is unknown. */
ALLOW_SPACE = 11, /* Allow spaces in the URL */
PUNYCODE = 12, /* get the hostname in punycode */
PUNY2IDN = 13, /* punycode => IDN conversion */
GET_EMPTY = 14, /* allow empty queries and fragments
when extracting the URL or the
components */
NO_GUESS_SCHEME = 15, /* for get, do not accept a guess */
}
U_DEFAULT_PORT :: (1<<0) /* return default port number */
U_NO_DEFAULT_PORT :: (1<<1) /* act as if no port number was set,
if the port number matches the
default for the scheme */
U_DEFAULT_SCHEME :: (1<<2) /* return default scheme if
missing */
U_NON_SUPPORT_SCHEME :: (1<<3) /* allow non-supported scheme */
U_PATH_AS_IS :: (1<<4) /* leave dot sequences */
U_DISALLOW_USER :: (1<<5) /* no user+password allowed */
U_URLDECODE :: (1<<6) /* URL decode on get */
U_URLENCODE :: (1<<7) /* URL encode on set */
U_APPENDQUERY :: (1<<8) /* append a form style part */
U_GUESS_SCHEME :: (1<<9) /* legacy curl-style guessing */
U_NO_AUTHORITY :: (1<<10) /* Allow empty authority when the
scheme is unknown. */
U_ALLOW_SPACE :: (1<<11) /* Allow spaces in the URL */
U_PUNYCODE :: (1<<12) /* get the hostname in punycode */
U_PUNY2IDN :: (1<<13) /* punycode => IDN conversion */
U_GET_EMPTY :: (1<<14) /* allow empty queries and fragments
when extracting the URL or the
components */
U_NO_GUESS_SCHEME :: (1<<15) /* for get, do not accept a guess */
U_DEFAULT_PORT :: UFlags{.DEFAULT_PORT}
U_NO_DEFAULT_PORT :: UFlags{.NO_DEFAULT_PORT}
U_DEFAULT_SCHEME :: UFlags{.DEFAULT_SCHEME}
U_NON_SUPPORT_SCHEME :: UFlags{.NON_SUPPORT_SCHEME}
U_PATH_AS_IS :: UFlags{.PATH_AS_IS}
U_DISALLOW_USER :: UFlags{.DISALLOW_USER}
U_URLDECODE :: UFlags{.URLDECODE}
U_URLENCODE :: UFlags{.URLENCODE}
U_APPENDQUERY :: UFlags{.APPENDQUERY}
U_GUESS_SCHEME :: UFlags{.GUESS_SCHEME}
U_NO_AUTHORITY :: UFlags{.NO_AUTHORITY}
U_ALLOW_SPACE :: UFlags{.ALLOW_SPACE}
U_PUNYCODE :: UFlags{.PUNYCODE}
U_PUNY2IDN :: UFlags{.PUNY2IDN}
U_GET_EMPTY :: UFlags{.GET_EMPTY}
U_NO_GUESS_SCHEME :: UFlags{.NO_GUESS_SCHEME}
@(default_calling_convention="c", link_prefix="curl_")
foreign lib {
@@ -105,14 +123,14 @@ foreign lib {
* handle. Returns error code. The returned pointer MUST be freed with
* curl_free() afterwards.
*/
url_get :: proc(handle: ^CURLU, what: UPart, part: ^[^]byte, flags: c.uint) -> ^Ucode ---
url_get :: proc(handle: ^CURLU, what: UPart, part: ^[^]byte, flags: UFlags) -> ^Ucode ---
/*
* curl_url_set() sets a specific part of the URL in a CURLU handle. Returns
* error code. The passed in string will be copied. Passing a NULL instead of
* a part string, clears that part.
*/
url_set :: proc(handle: ^CURLU, what: ^UPart, part: cstring, flags: c.uint) -> Ucode ---
url_set :: proc(handle: ^CURLU, what: ^UPart, part: cstring, flags: UFlags) -> Ucode ---
/*
* curl_url_strerror() turns a CURLUcode value into the equivalent human

View File

@@ -5,22 +5,33 @@ import c "core:c/libc"
ws_frame :: struct {
age: c.int, /* zero */
flags: c.int, /* See the CURLWS_* defines */
flags: ws_flags, /* See the CURLWS_* defines */
offset: off_t, /* the offset of this data into the frame */
bytesleft: off_t, /* number of pending bytes left of the payload */
len: c.size_t, /* size of the current data chunk */
}
/* flag bits */
WS_TEXT :: 1<<0
WS_BINARY :: 1<<1
WS_CONT :: 1<<2
WS_CLOSE :: 1<<3
WS_PING :: 1<<4
WS_OFFSET :: 1<<5
ws_flags :: distinct bit_set[ws_flag; c.uint]
ws_flag :: enum c.uint {
/* flag bits */
TEXT = 0,
BINARY = 1,
CONT = 2,
CLOSE = 3,
PING = 4,
OFFSET = 5,
/* flags for curl_ws_send() */
WS_PONG :: 1<<6
/* flags for curl_ws_send() */
PONG = 6,
}
WS_TEXT :: ws_flags{.TEXT}
WS_BINARY :: ws_flags{.BINARY}
WS_CONT :: ws_flags{.CONT}
WS_CLOSE :: ws_flags{.CLOSE}
WS_PING :: ws_flags{.PING}
WS_OFFSET :: ws_flags{.OFFSET}
WS_PONG :: ws_flags{.PONG}
/* bits for the CURLOPT_WS_OPTIONS bitmask: */
WS_RAW_MODE :: 1<<0
@@ -51,7 +62,7 @@ foreign lib {
ws_send :: proc(curl: CURL, buffer: rawptr,
buflen: c.size_t, sent: ^c.size_t,
fragsize: off_t,
flags: c.uint) -> code ---
flags: ws_flags) -> code ---
ws_meta :: proc(curl: ^CURL) -> ^ws_frame ---