mt-lang 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/docs/index.html +4 -3
- data/lib/milk_tea/base.rb +1 -1
- data/std/asset_pack.mt +267 -0
- data/std/async/libuv_runtime.mt +539 -0
- data/std/async/mailbox.mt +191 -0
- data/std/async/runtime.mt +87 -0
- data/std/async.mt +87 -0
- data/std/base64.mt +185 -0
- data/std/behavior_tree.mt +396 -0
- data/std/binary.mt +314 -0
- data/std/binary_heap.mt +157 -0
- data/std/bitset.mt +239 -0
- data/std/box2d.mt +535 -0
- data/std/bytes.mt +46 -0
- data/std/c/box2d.mt +1254 -0
- data/std/c/cgltf.mt +647 -0
- data/std/c/cjson.mt +106 -0
- data/std/c/crypto.mt +11 -0
- data/std/c/crypto_support.h +51 -0
- data/std/c/ctype.mt +19 -0
- data/std/c/ctype_bindgen.h +29 -0
- data/std/c/curl.mt +1223 -0
- data/std/c/enet.mt +473 -0
- data/std/c/errno.mt +41 -0
- data/std/c/errno_bindgen.h +53 -0
- data/std/c/flecs.mt +2945 -0
- data/std/c/fs.linux.mt +43 -0
- data/std/c/fs.windows.mt +43 -0
- data/std/c/fs_support.h +954 -0
- data/std/c/gl.mt +2065 -0
- data/std/c/gl_registry_helpers.h +10748 -0
- data/std/c/glfw.mt +499 -0
- data/std/c/libc.mt +167 -0
- data/std/c/libuv.mt +1491 -0
- data/std/c/math.mt +22 -0
- data/std/c/math_bindgen.h +31 -0
- data/std/c/miniaudio.mt +3420 -0
- data/std/c/pcre2.mt +735 -0
- data/std/c/process.mt +58 -0
- data/std/c/process_support.h +1147 -0
- data/std/c/raygui.mt +1602 -0
- data/std/c/raylib.mt +1245 -0
- data/std/c/raymath.mt +163 -0
- data/std/c/rlgl.mt +434 -0
- data/std/c/rpng.mt +60 -0
- data/std/c/rres.mt +187 -0
- data/std/c/sdl3.mt +4132 -0
- data/std/c/sqlite3.mt +951 -0
- data/std/c/stb_image.mt +52 -0
- data/std/c/stb_image_resize2.mt +128 -0
- data/std/c/stb_image_write.mt +19 -0
- data/std/c/stb_rect_pack.mt +38 -0
- data/std/c/stb_truetype.mt +175 -0
- data/std/c/stb_vorbis.mt +31 -0
- data/std/c/stdio.mt +90 -0
- data/std/c/steamworks.h +5769 -0
- data/std/c/steamworks.mt +4771 -0
- data/std/c/string.mt +16 -0
- data/std/c/string_bindgen.h +36 -0
- data/std/c/sync.mt +33 -0
- data/std/c/sync_support.h +219 -0
- data/std/c/terminal.mt +24 -0
- data/std/c/terminal_support.h +408 -0
- data/std/c/time.mt +26 -0
- data/std/c/tls.mt +24 -0
- data/std/c/tls_support.h +626 -0
- data/std/c/tracy.mt +53 -0
- data/std/c/zlib.mt +20 -0
- data/std/c/zlib_support.h +239 -0
- data/std/c/zstd.mt +231 -0
- data/std/cell.mt +60 -0
- data/std/cgltf.mt +115 -0
- data/std/cjson.mt +90 -0
- data/std/cli.mt +768 -0
- data/std/cookie.mt +198 -0
- data/std/counter.mt +160 -0
- data/std/crypto.mt +74 -0
- data/std/cstring.mt +13 -0
- data/std/ctype.mt +52 -0
- data/std/curl/runtime.mt +261 -0
- data/std/curl.mt +38 -0
- data/std/deque.mt +348 -0
- data/std/encoding.mt +93 -0
- data/std/enet.mt +133 -0
- data/std/env.mt +41 -0
- data/std/errno.mt +47 -0
- data/std/flecs.mt +978 -0
- data/std/fmt.mt +271 -0
- data/std/fs.linux.mt +696 -0
- data/std/fs.windows.mt +711 -0
- data/std/fsm.mt +267 -0
- data/std/gl.mt +2062 -0
- data/std/glfw.mt +471 -0
- data/std/goap.mt +342 -0
- data/std/graph.mt +521 -0
- data/std/gzip.mt +77 -0
- data/std/hash.mt +429 -0
- data/std/http/server.mt +810 -0
- data/std/http.mt +1227 -0
- data/std/intern.mt +53 -0
- data/std/jobs.mt +288 -0
- data/std/json.mt +627 -0
- data/std/libc.mt +34 -0
- data/std/libuv.mt +554 -0
- data/std/linear_algebra.mt +243 -0
- data/std/linked_map.mt +372 -0
- data/std/linked_map_view.mt +49 -0
- data/std/linked_set.mt +117 -0
- data/std/log.mt +69 -0
- data/std/map.mt +418 -0
- data/std/math.mt +24 -0
- data/std/mem/arena.mt +137 -0
- data/std/mem/endian.mt +51 -0
- data/std/mem/heap.mt +298 -0
- data/std/mem/pool.mt +164 -0
- data/std/mem/stack.mt +47 -0
- data/std/mem/tracking.mt +119 -0
- data/std/miniaudio.mt +1299 -0
- data/std/multiset.mt +191 -0
- data/std/net/channel.mt +727 -0
- data/std/net/clock.mt +237 -0
- data/std/net/discovery.mt +277 -0
- data/std/net/lobby.mt +813 -0
- data/std/net/manager.mt +539 -0
- data/std/net/mux.mt +839 -0
- data/std/net/nat.mt +122 -0
- data/std/net/packet.mt +219 -0
- data/std/net/punch.mt +162 -0
- data/std/net/rpc.mt +119 -0
- data/std/net/session.mt +1157 -0
- data/std/net/stun.mt +252 -0
- data/std/net/sync.mt +183 -0
- data/std/net/turn.mt +459 -0
- data/std/net.mt +2944 -0
- data/std/oauth2.mt +408 -0
- data/std/option.mt +51 -0
- data/std/ordered_map.mt +497 -0
- data/std/ordered_set.mt +348 -0
- data/std/path.mt +368 -0
- data/std/pcre2/runtime.mt +35 -0
- data/std/pcre2.mt +78 -0
- data/std/priority_queue.mt +55 -0
- data/std/process.mt +837 -0
- data/std/queue.mt +55 -0
- data/std/random.mt +146 -0
- data/std/raygui.mt +99 -0
- data/std/raylib/debug_console.mt +71 -0
- data/std/raylib/easing.mt +388 -0
- data/std/raylib/packed_assets.mt +255 -0
- data/std/raylib/runtime.mt +30 -0
- data/std/raylib/tracy_gpu.mt +37 -0
- data/std/raylib.mt +1510 -0
- data/std/raymath.mt +153 -0
- data/std/result.mt +89 -0
- data/std/rlgl.mt +268 -0
- data/std/rpng.mt +46 -0
- data/std/rres.mt +36 -0
- data/std/sdl3/runtime.mt +54 -0
- data/std/sdl3.mt +1731 -0
- data/std/serialize.mt +68 -0
- data/std/set.mt +124 -0
- data/std/spatial.mt +176 -0
- data/std/sqlite3.mt +151 -0
- data/std/stack.mt +55 -0
- data/std/stb_image.mt +47 -0
- data/std/stb_image_resize2.mt +41 -0
- data/std/stb_image_write.mt +17 -0
- data/std/stb_rect_pack.mt +15 -0
- data/std/stb_truetype.mt +77 -0
- data/std/stb_vorbis.mt +16 -0
- data/std/stdio.mt +88 -0
- data/std/steamworks.mt +1542 -0
- data/std/str.mt +293 -0
- data/std/string.mt +234 -0
- data/std/sync.mt +194 -0
- data/std/tar.mt +704 -0
- data/std/terminal.mt +1002 -0
- data/std/testing.mt +266 -0
- data/std/thread.mt +120 -0
- data/std/time.mt +105 -0
- data/std/tls.mt +616 -0
- data/std/toml.mt +1310 -0
- data/std/tracy.mt +42 -0
- data/std/uri.mt +118 -0
- data/std/url.mt +372 -0
- data/std/vec.mt +433 -0
- data/std/zstd.mt +94 -0
- metadata +187 -2
data/std/c/tls_support.h
ADDED
|
@@ -0,0 +1,626 @@
|
|
|
1
|
+
#ifndef MT_TLS_SUPPORT_H
|
|
2
|
+
#define MT_TLS_SUPPORT_H
|
|
3
|
+
|
|
4
|
+
#include <arpa/inet.h>
|
|
5
|
+
#include <errno.h>
|
|
6
|
+
#include <limits.h>
|
|
7
|
+
#include <netdb.h>
|
|
8
|
+
#include <netinet/in.h>
|
|
9
|
+
#include <openssl/err.h>
|
|
10
|
+
#include <openssl/ssl.h>
|
|
11
|
+
#include <openssl/x509_vfy.h>
|
|
12
|
+
#include <stdint.h>
|
|
13
|
+
#include <stdio.h>
|
|
14
|
+
#include <stdlib.h>
|
|
15
|
+
#include <string.h>
|
|
16
|
+
#include <sys/socket.h>
|
|
17
|
+
#include <sys/types.h>
|
|
18
|
+
#include <unistd.h>
|
|
19
|
+
|
|
20
|
+
typedef struct mt_tls_bytes {
|
|
21
|
+
uint8_t* data;
|
|
22
|
+
uintptr_t len;
|
|
23
|
+
} mt_tls_bytes;
|
|
24
|
+
|
|
25
|
+
typedef struct mt_tls_error {
|
|
26
|
+
int code;
|
|
27
|
+
char* message_data;
|
|
28
|
+
uintptr_t message_len;
|
|
29
|
+
} mt_tls_error;
|
|
30
|
+
|
|
31
|
+
typedef struct mt_tls_client {
|
|
32
|
+
SSL_CTX* ctx;
|
|
33
|
+
SSL* ssl;
|
|
34
|
+
int fd;
|
|
35
|
+
} mt_tls_client;
|
|
36
|
+
|
|
37
|
+
static inline void mt_tls_reset_bytes(mt_tls_bytes* value) {
|
|
38
|
+
if (value == NULL) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
value->data = NULL;
|
|
43
|
+
value->len = 0;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
static inline void mt_tls_reset_error(mt_tls_error* error) {
|
|
47
|
+
if (error == NULL) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
error->code = 0;
|
|
52
|
+
error->message_data = NULL;
|
|
53
|
+
error->message_len = 0;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
static inline void mt_tls_client_cleanup(SSL_CTX* ctx, SSL* ssl) {
|
|
57
|
+
if (ssl != NULL) {
|
|
58
|
+
SSL_free(ssl);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (ctx != NULL) {
|
|
62
|
+
SSL_CTX_free(ctx);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
static inline int mt_tls_set_message(mt_tls_error* error, int code, const char* prefix, const char* detail) {
|
|
67
|
+
if (error == NULL) {
|
|
68
|
+
return code == 0 ? -1 : code;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
size_t prefix_len = prefix == NULL ? 0 : strlen(prefix);
|
|
72
|
+
size_t detail_len = detail == NULL ? 0 : strlen(detail);
|
|
73
|
+
size_t separator_len = prefix_len != 0 && detail_len != 0 ? 2 : 0;
|
|
74
|
+
size_t total_len = prefix_len + separator_len + detail_len;
|
|
75
|
+
|
|
76
|
+
char* message = NULL;
|
|
77
|
+
if (total_len != 0) {
|
|
78
|
+
message = (char*) malloc(total_len);
|
|
79
|
+
if (message != NULL) {
|
|
80
|
+
size_t offset = 0;
|
|
81
|
+
if (prefix_len != 0) {
|
|
82
|
+
memcpy(message + offset, prefix, prefix_len);
|
|
83
|
+
offset += prefix_len;
|
|
84
|
+
}
|
|
85
|
+
if (separator_len != 0) {
|
|
86
|
+
memcpy(message + offset, ": ", separator_len);
|
|
87
|
+
offset += separator_len;
|
|
88
|
+
}
|
|
89
|
+
if (detail_len != 0) {
|
|
90
|
+
memcpy(message + offset, detail, detail_len);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
error->code = code;
|
|
96
|
+
error->message_data = message;
|
|
97
|
+
error->message_len = (uintptr_t) total_len;
|
|
98
|
+
return code == 0 ? -1 : code;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
static inline int mt_tls_set_errno_error(mt_tls_error* error, int code, const char* prefix) {
|
|
102
|
+
return mt_tls_set_message(error, code == 0 ? -1 : code, prefix, strerror(code == 0 ? errno : code));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
static inline int mt_tls_set_gai_error(mt_tls_error* error, int code, const char* prefix) {
|
|
106
|
+
return mt_tls_set_message(error, code == 0 ? -1 : code, prefix, gai_strerror(code));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
static inline int mt_tls_set_ssl_error(mt_tls_error* error, int code, const char* prefix) {
|
|
110
|
+
unsigned long ssl_code = ERR_peek_last_error();
|
|
111
|
+
if (ssl_code != 0) {
|
|
112
|
+
char detail[256];
|
|
113
|
+
ERR_error_string_n(ssl_code, detail, sizeof(detail));
|
|
114
|
+
return mt_tls_set_message(error, code == 0 ? -1 : code, prefix, detail);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return mt_tls_set_message(error, code == 0 ? -1 : code, prefix, "OpenSSL reported an unspecified failure");
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
static inline const char* mt_tls_env_or_null(const char* name) {
|
|
121
|
+
const char* value = getenv(name);
|
|
122
|
+
if (value == NULL || value[0] == '\0') {
|
|
123
|
+
return NULL;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return value;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
static inline int mt_tls_load_verify_paths(SSL_CTX* ctx, mt_tls_error* out_error) {
|
|
130
|
+
const char* cert_file = mt_tls_env_or_null("SSL_CERT_FILE");
|
|
131
|
+
const char* cert_dir = mt_tls_env_or_null("SSL_CERT_DIR");
|
|
132
|
+
|
|
133
|
+
if (cert_file != NULL || cert_dir != NULL) {
|
|
134
|
+
if (SSL_CTX_load_verify_locations(ctx, cert_file, cert_dir) == 1) {
|
|
135
|
+
return 0;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return mt_tls_set_ssl_error(out_error, -1, "tls connect failed");
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (SSL_CTX_set_default_verify_paths(ctx) == 1) {
|
|
142
|
+
return 0;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return mt_tls_set_ssl_error(out_error, -1, "tls connect failed");
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
static inline int mt_tls_host_is_ip_literal(const char* host) {
|
|
149
|
+
struct in_addr ipv4_address;
|
|
150
|
+
struct in6_addr ipv6_address;
|
|
151
|
+
|
|
152
|
+
return inet_pton(AF_INET, host, &ipv4_address) == 1 || inet_pton(AF_INET6, host, &ipv6_address) == 1;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
static inline int mt_tls_configure_peer_name(SSL* ssl, const char* host, mt_tls_error* out_error) {
|
|
156
|
+
if (mt_tls_host_is_ip_literal(host)) {
|
|
157
|
+
X509_VERIFY_PARAM* verify_param = SSL_get0_param(ssl);
|
|
158
|
+
if (verify_param == NULL) {
|
|
159
|
+
return mt_tls_set_message(out_error, -1, "tls connect failed", "missing certificate verification parameters");
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (X509_VERIFY_PARAM_set1_ip_asc(verify_param, host) != 1) {
|
|
163
|
+
return mt_tls_set_ssl_error(out_error, -1, "tls connect failed");
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return 0;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (SSL_set_tlsext_host_name(ssl, host) != 1) {
|
|
170
|
+
return mt_tls_set_ssl_error(out_error, -1, "tls connect failed");
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (SSL_set1_host(ssl, host) != 1) {
|
|
174
|
+
return mt_tls_set_ssl_error(out_error, -1, "tls connect failed");
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return 0;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
static inline int mt_tls_grow_buffer(uint8_t** data, size_t* capacity, size_t minimum_capacity, mt_tls_error* out_error) {
|
|
181
|
+
size_t next_capacity = *capacity == 0 ? 4096 : *capacity;
|
|
182
|
+
while (next_capacity < minimum_capacity) {
|
|
183
|
+
if (next_capacity > SIZE_MAX / 2) {
|
|
184
|
+
if (next_capacity >= minimum_capacity) {
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return mt_tls_set_message(out_error, -1, "tls read failed", "response exceeds addressable memory");
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
next_capacity *= 2;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
uint8_t* resized = (uint8_t*) realloc(*data, next_capacity);
|
|
195
|
+
if (resized == NULL) {
|
|
196
|
+
return mt_tls_set_message(out_error, -1, "tls read failed", "out of memory");
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
*data = resized;
|
|
200
|
+
*capacity = next_capacity;
|
|
201
|
+
return 0;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
static inline int mt_tls_ssl_io_status(SSL* ssl, int io_status, const char* prefix, mt_tls_error* out_error, int eof_status) {
|
|
205
|
+
if (io_status > 0) {
|
|
206
|
+
return 0;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
int ssl_error = SSL_get_error(ssl, io_status);
|
|
210
|
+
if (ssl_error == SSL_ERROR_WANT_READ) {
|
|
211
|
+
return 1;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (ssl_error == SSL_ERROR_WANT_WRITE) {
|
|
215
|
+
return 2;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (ssl_error == SSL_ERROR_ZERO_RETURN) {
|
|
219
|
+
return eof_status;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (ssl_error == SSL_ERROR_SYSCALL && errno == 0) {
|
|
223
|
+
return eof_status;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
mt_tls_set_ssl_error(out_error, ssl_error, prefix);
|
|
227
|
+
return -1;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
static inline int mt_tls_client_create(const char* host, int fd, mt_tls_client** out_client, mt_tls_error* out_error) {
|
|
231
|
+
if (out_client != NULL) {
|
|
232
|
+
*out_client = NULL;
|
|
233
|
+
}
|
|
234
|
+
mt_tls_reset_error(out_error);
|
|
235
|
+
|
|
236
|
+
if (host == NULL || host[0] == '\0') {
|
|
237
|
+
return mt_tls_set_message(out_error, -1, "tls connect failed", "host is required");
|
|
238
|
+
}
|
|
239
|
+
if (fd < 0) {
|
|
240
|
+
return mt_tls_set_message(out_error, -1, "tls connect failed", "socket fd must be non-negative");
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
SSL_CTX* ctx = NULL;
|
|
244
|
+
SSL* ssl = NULL;
|
|
245
|
+
mt_tls_client* client = NULL;
|
|
246
|
+
|
|
247
|
+
ERR_clear_error();
|
|
248
|
+
ctx = SSL_CTX_new(TLS_client_method());
|
|
249
|
+
if (ctx == NULL) {
|
|
250
|
+
return mt_tls_set_ssl_error(out_error, -1, "tls connect failed");
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, NULL);
|
|
254
|
+
SSL_CTX_set_min_proto_version(ctx, TLS1_2_VERSION);
|
|
255
|
+
#ifdef SSL_OP_IGNORE_UNEXPECTED_EOF
|
|
256
|
+
SSL_CTX_set_options(ctx, SSL_OP_IGNORE_UNEXPECTED_EOF);
|
|
257
|
+
#endif
|
|
258
|
+
|
|
259
|
+
if (mt_tls_load_verify_paths(ctx, out_error) != 0) {
|
|
260
|
+
mt_tls_client_cleanup(ctx, ssl);
|
|
261
|
+
return out_error == NULL ? -1 : out_error->code;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
ERR_clear_error();
|
|
265
|
+
ssl = SSL_new(ctx);
|
|
266
|
+
if (ssl == NULL) {
|
|
267
|
+
mt_tls_client_cleanup(ctx, ssl);
|
|
268
|
+
return mt_tls_set_ssl_error(out_error, -1, "tls connect failed");
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
SSL_set_mode(ssl, SSL_MODE_ENABLE_PARTIAL_WRITE | SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);
|
|
272
|
+
SSL_set_connect_state(ssl);
|
|
273
|
+
|
|
274
|
+
if (mt_tls_configure_peer_name(ssl, host, out_error) != 0) {
|
|
275
|
+
mt_tls_client_cleanup(ctx, ssl);
|
|
276
|
+
return out_error == NULL ? -1 : out_error->code;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (SSL_set_fd(ssl, fd) != 1) {
|
|
280
|
+
mt_tls_client_cleanup(ctx, ssl);
|
|
281
|
+
return mt_tls_set_ssl_error(out_error, -1, "tls connect failed");
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
client = (mt_tls_client*) malloc(sizeof(mt_tls_client));
|
|
285
|
+
if (client == NULL) {
|
|
286
|
+
mt_tls_client_cleanup(ctx, ssl);
|
|
287
|
+
return mt_tls_set_message(out_error, -1, "tls connect failed", "out of memory");
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
client->ctx = ctx;
|
|
291
|
+
client->ssl = ssl;
|
|
292
|
+
client->fd = fd;
|
|
293
|
+
|
|
294
|
+
if (out_client != NULL) {
|
|
295
|
+
*out_client = client;
|
|
296
|
+
}
|
|
297
|
+
return 0;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
static inline int mt_tls_client_handshake(mt_tls_client* client, mt_tls_error* out_error) {
|
|
301
|
+
mt_tls_reset_error(out_error);
|
|
302
|
+
|
|
303
|
+
if (client == NULL || client->ssl == NULL) {
|
|
304
|
+
mt_tls_set_message(out_error, -1, "tls connect failed", "tls client is released");
|
|
305
|
+
return -1;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
ERR_clear_error();
|
|
309
|
+
int connect_status = SSL_connect(client->ssl);
|
|
310
|
+
if (connect_status == 1) {
|
|
311
|
+
long verify_status = SSL_get_verify_result(client->ssl);
|
|
312
|
+
if (verify_status != X509_V_OK) {
|
|
313
|
+
mt_tls_set_message(out_error, (int) verify_status, "tls connect failed", X509_verify_cert_error_string(verify_status));
|
|
314
|
+
return -1;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
return 0;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
int status = mt_tls_ssl_io_status(client->ssl, connect_status, "tls connect failed", out_error, -1);
|
|
321
|
+
if (status != -1) {
|
|
322
|
+
return status;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
long verify_status = SSL_get_verify_result(client->ssl);
|
|
326
|
+
if (verify_status != X509_V_OK) {
|
|
327
|
+
mt_tls_reset_error(out_error);
|
|
328
|
+
mt_tls_set_message(out_error, (int) verify_status, "tls connect failed", X509_verify_cert_error_string(verify_status));
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
return -1;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
static inline int mt_tls_client_write(mt_tls_client* client, const uint8_t* data, uintptr_t len, uintptr_t* out_written, mt_tls_error* out_error) {
|
|
335
|
+
if (out_written != NULL) {
|
|
336
|
+
*out_written = 0;
|
|
337
|
+
}
|
|
338
|
+
mt_tls_reset_error(out_error);
|
|
339
|
+
|
|
340
|
+
if (client == NULL || client->ssl == NULL) {
|
|
341
|
+
mt_tls_set_message(out_error, -1, "tls write failed", "tls client is released");
|
|
342
|
+
return -1;
|
|
343
|
+
}
|
|
344
|
+
if (len != 0 && data == NULL) {
|
|
345
|
+
mt_tls_set_message(out_error, -1, "tls write failed", "missing write buffer");
|
|
346
|
+
return -1;
|
|
347
|
+
}
|
|
348
|
+
if (len == 0) {
|
|
349
|
+
return 0;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
size_t written = 0;
|
|
353
|
+
ERR_clear_error();
|
|
354
|
+
int write_status = SSL_write_ex(client->ssl, data, (size_t) len, &written);
|
|
355
|
+
if (write_status == 1) {
|
|
356
|
+
if (out_written != NULL) {
|
|
357
|
+
*out_written = (uintptr_t) written;
|
|
358
|
+
}
|
|
359
|
+
return 0;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
return mt_tls_ssl_io_status(client->ssl, write_status, "tls write failed", out_error, 3);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
static inline int mt_tls_client_read(mt_tls_client* client, uint8_t* buffer, uintptr_t capacity, uintptr_t* out_read, mt_tls_error* out_error) {
|
|
366
|
+
if (out_read != NULL) {
|
|
367
|
+
*out_read = 0;
|
|
368
|
+
}
|
|
369
|
+
mt_tls_reset_error(out_error);
|
|
370
|
+
|
|
371
|
+
if (client == NULL || client->ssl == NULL) {
|
|
372
|
+
mt_tls_set_message(out_error, -1, "tls read failed", "tls client is released");
|
|
373
|
+
return -1;
|
|
374
|
+
}
|
|
375
|
+
if (capacity == 0) {
|
|
376
|
+
mt_tls_set_message(out_error, -1, "tls read failed", "read capacity must be greater than zero");
|
|
377
|
+
return -1;
|
|
378
|
+
}
|
|
379
|
+
if (buffer == NULL) {
|
|
380
|
+
mt_tls_set_message(out_error, -1, "tls read failed", "missing read buffer");
|
|
381
|
+
return -1;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
size_t read_count = 0;
|
|
385
|
+
ERR_clear_error();
|
|
386
|
+
int read_status = SSL_read_ex(client->ssl, buffer, (size_t) capacity, &read_count);
|
|
387
|
+
if (read_status == 1) {
|
|
388
|
+
if (out_read != NULL) {
|
|
389
|
+
*out_read = (uintptr_t) read_count;
|
|
390
|
+
}
|
|
391
|
+
return 0;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
return mt_tls_ssl_io_status(client->ssl, read_status, "tls read failed", out_error, 3);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
static inline int mt_tls_client_shutdown(mt_tls_client* client, mt_tls_error* out_error) {
|
|
398
|
+
mt_tls_reset_error(out_error);
|
|
399
|
+
|
|
400
|
+
if (client == NULL || client->ssl == NULL) {
|
|
401
|
+
mt_tls_set_message(out_error, -1, "tls shutdown failed", "tls client is released");
|
|
402
|
+
return -1;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
ERR_clear_error();
|
|
406
|
+
int shutdown_status = SSL_shutdown(client->ssl);
|
|
407
|
+
if (shutdown_status == 1) {
|
|
408
|
+
return 0;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
if (shutdown_status == 0) {
|
|
412
|
+
return 1;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
return mt_tls_ssl_io_status(client->ssl, shutdown_status, "tls shutdown failed", out_error, 0);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
static inline void mt_tls_client_release(mt_tls_client* client) {
|
|
419
|
+
if (client == NULL) {
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
mt_tls_client_cleanup(client->ctx, client->ssl);
|
|
424
|
+
client->ctx = NULL;
|
|
425
|
+
client->ssl = NULL;
|
|
426
|
+
free(client);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
static inline void mt_tls_cleanup(SSL_CTX* ctx, SSL* ssl, int fd, struct addrinfo* addresses) {
|
|
430
|
+
if (addresses != NULL) {
|
|
431
|
+
freeaddrinfo(addresses);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
if (ssl != NULL) {
|
|
435
|
+
SSL_shutdown(ssl);
|
|
436
|
+
SSL_free(ssl);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
if (ctx != NULL) {
|
|
440
|
+
SSL_CTX_free(ctx);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
if (fd >= 0) {
|
|
444
|
+
close(fd);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
static inline int mt_tls_exchange(const char* host, int port, const uint8_t* request_data, uintptr_t request_len, mt_tls_bytes* out_response, mt_tls_error* out_error) {
|
|
449
|
+
mt_tls_reset_bytes(out_response);
|
|
450
|
+
mt_tls_reset_error(out_error);
|
|
451
|
+
|
|
452
|
+
if (host == NULL || host[0] == '\0') {
|
|
453
|
+
return mt_tls_set_message(out_error, -1, "tls connect failed", "host is required");
|
|
454
|
+
}
|
|
455
|
+
if (port <= 0 || port > 65535) {
|
|
456
|
+
return mt_tls_set_message(out_error, -1, "tls connect failed", "port must be between 1 and 65535");
|
|
457
|
+
}
|
|
458
|
+
if (request_len != 0 && request_data == NULL) {
|
|
459
|
+
return mt_tls_set_message(out_error, -1, "tls write failed", "missing request data");
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
SSL_CTX* ctx = NULL;
|
|
463
|
+
SSL* ssl = NULL;
|
|
464
|
+
struct addrinfo hints;
|
|
465
|
+
struct addrinfo* addresses = NULL;
|
|
466
|
+
int fd = -1;
|
|
467
|
+
uint8_t* response_data = NULL;
|
|
468
|
+
size_t response_len = 0;
|
|
469
|
+
size_t response_capacity = 0;
|
|
470
|
+
int last_errno = 0;
|
|
471
|
+
char service[16];
|
|
472
|
+
|
|
473
|
+
ERR_clear_error();
|
|
474
|
+
ctx = SSL_CTX_new(TLS_client_method());
|
|
475
|
+
if (ctx == NULL) {
|
|
476
|
+
return mt_tls_set_ssl_error(out_error, -1, "tls connect failed");
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, NULL);
|
|
480
|
+
SSL_CTX_set_min_proto_version(ctx, TLS1_2_VERSION);
|
|
481
|
+
#ifdef SSL_OP_IGNORE_UNEXPECTED_EOF
|
|
482
|
+
SSL_CTX_set_options(ctx, SSL_OP_IGNORE_UNEXPECTED_EOF);
|
|
483
|
+
#endif
|
|
484
|
+
|
|
485
|
+
if (mt_tls_load_verify_paths(ctx, out_error) != 0) {
|
|
486
|
+
mt_tls_cleanup(ctx, ssl, fd, addresses);
|
|
487
|
+
return out_error == NULL ? -1 : out_error->code;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
memset(&hints, 0, sizeof(hints));
|
|
491
|
+
hints.ai_family = AF_UNSPEC;
|
|
492
|
+
hints.ai_socktype = SOCK_STREAM;
|
|
493
|
+
hints.ai_protocol = IPPROTO_TCP;
|
|
494
|
+
|
|
495
|
+
snprintf(service, sizeof(service), "%d", port);
|
|
496
|
+
int status = getaddrinfo(host, service, &hints, &addresses);
|
|
497
|
+
if (status != 0) {
|
|
498
|
+
mt_tls_cleanup(ctx, ssl, fd, addresses);
|
|
499
|
+
return mt_tls_set_gai_error(out_error, status, "tls connect failed");
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
for (struct addrinfo* current = addresses; current != NULL; current = current->ai_next) {
|
|
503
|
+
fd = socket(current->ai_family, current->ai_socktype, current->ai_protocol);
|
|
504
|
+
if (fd < 0) {
|
|
505
|
+
last_errno = errno;
|
|
506
|
+
continue;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
if (connect(fd, current->ai_addr, current->ai_addrlen) == 0) {
|
|
510
|
+
break;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
last_errno = errno;
|
|
514
|
+
close(fd);
|
|
515
|
+
fd = -1;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
if (fd < 0) {
|
|
519
|
+
mt_tls_cleanup(ctx, ssl, fd, addresses);
|
|
520
|
+
return mt_tls_set_errno_error(out_error, last_errno, "tls connect failed");
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
ERR_clear_error();
|
|
524
|
+
ssl = SSL_new(ctx);
|
|
525
|
+
if (ssl == NULL) {
|
|
526
|
+
mt_tls_cleanup(ctx, ssl, fd, addresses);
|
|
527
|
+
return mt_tls_set_ssl_error(out_error, -1, "tls connect failed");
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
if (mt_tls_configure_peer_name(ssl, host, out_error) != 0) {
|
|
531
|
+
mt_tls_cleanup(ctx, ssl, fd, addresses);
|
|
532
|
+
return out_error == NULL ? -1 : out_error->code;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
if (SSL_set_fd(ssl, fd) != 1) {
|
|
536
|
+
mt_tls_cleanup(ctx, ssl, fd, addresses);
|
|
537
|
+
return mt_tls_set_ssl_error(out_error, -1, "tls connect failed");
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
ERR_clear_error();
|
|
541
|
+
int connect_status = SSL_connect(ssl);
|
|
542
|
+
if (connect_status != 1) {
|
|
543
|
+
long verify_status = SSL_get_verify_result(ssl);
|
|
544
|
+
if (verify_status != X509_V_OK) {
|
|
545
|
+
mt_tls_cleanup(ctx, ssl, fd, addresses);
|
|
546
|
+
return mt_tls_set_message(out_error, (int) verify_status, "tls connect failed", X509_verify_cert_error_string(verify_status));
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
int ssl_error = SSL_get_error(ssl, connect_status);
|
|
550
|
+
mt_tls_cleanup(ctx, ssl, fd, addresses);
|
|
551
|
+
return mt_tls_set_ssl_error(out_error, ssl_error, "tls connect failed");
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
long verify_status = SSL_get_verify_result(ssl);
|
|
555
|
+
if (verify_status != X509_V_OK) {
|
|
556
|
+
mt_tls_cleanup(ctx, ssl, fd, addresses);
|
|
557
|
+
return mt_tls_set_message(out_error, (int) verify_status, "tls connect failed", X509_verify_cert_error_string(verify_status));
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
size_t request_offset = 0;
|
|
561
|
+
while (request_offset < request_len) {
|
|
562
|
+
size_t written = 0;
|
|
563
|
+
ERR_clear_error();
|
|
564
|
+
int write_status = SSL_write_ex(ssl, request_data + request_offset, (size_t) (request_len - request_offset), &written);
|
|
565
|
+
if (write_status == 1) {
|
|
566
|
+
request_offset += written;
|
|
567
|
+
continue;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
int ssl_error = SSL_get_error(ssl, write_status);
|
|
571
|
+
if (ssl_error == SSL_ERROR_WANT_READ || ssl_error == SSL_ERROR_WANT_WRITE) {
|
|
572
|
+
continue;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
mt_tls_cleanup(ctx, ssl, fd, addresses);
|
|
576
|
+
return mt_tls_set_ssl_error(out_error, ssl_error, "tls write failed");
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
while (1) {
|
|
580
|
+
if (response_capacity - response_len < 2048) {
|
|
581
|
+
size_t minimum_capacity = response_len + 4096;
|
|
582
|
+
if (mt_tls_grow_buffer(&response_data, &response_capacity, minimum_capacity, out_error) != 0) {
|
|
583
|
+
free(response_data);
|
|
584
|
+
mt_tls_cleanup(ctx, ssl, fd, addresses);
|
|
585
|
+
return out_error == NULL ? -1 : out_error->code;
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
size_t available = response_capacity - response_len;
|
|
590
|
+
int read_limit = available > (size_t) INT_MAX ? INT_MAX : (int) available;
|
|
591
|
+
ERR_clear_error();
|
|
592
|
+
int read_status = SSL_read(ssl, response_data + response_len, read_limit);
|
|
593
|
+
if (read_status > 0) {
|
|
594
|
+
response_len += (size_t) read_status;
|
|
595
|
+
continue;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
int ssl_error = SSL_get_error(ssl, read_status);
|
|
599
|
+
if (ssl_error == SSL_ERROR_WANT_READ || ssl_error == SSL_ERROR_WANT_WRITE) {
|
|
600
|
+
continue;
|
|
601
|
+
}
|
|
602
|
+
if (ssl_error == SSL_ERROR_ZERO_RETURN) {
|
|
603
|
+
break;
|
|
604
|
+
}
|
|
605
|
+
if (ssl_error == SSL_ERROR_SYSCALL && errno == 0) {
|
|
606
|
+
break;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
free(response_data);
|
|
610
|
+
mt_tls_cleanup(ctx, ssl, fd, addresses);
|
|
611
|
+
return mt_tls_set_ssl_error(out_error, ssl_error, "tls read failed");
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
mt_tls_cleanup(ctx, ssl, fd, addresses);
|
|
615
|
+
|
|
616
|
+
if (response_len == 0) {
|
|
617
|
+
free(response_data);
|
|
618
|
+
response_data = NULL;
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
out_response->data = response_data;
|
|
622
|
+
out_response->len = (uintptr_t) response_len;
|
|
623
|
+
return 0;
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
#endif
|
data/std/c/tracy.mt
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
external
|
|
2
|
+
|
|
3
|
+
link "tracyclient"
|
|
4
|
+
link "stdc++"
|
|
5
|
+
include "TracyC.h"
|
|
6
|
+
|
|
7
|
+
opaque TracyCZoneCtx = c"TracyCZoneCtx"
|
|
8
|
+
|
|
9
|
+
opaque TracyCSourceLocation
|
|
10
|
+
|
|
11
|
+
struct TracyCGpuTime:
|
|
12
|
+
gpu_time: long
|
|
13
|
+
query_id: ushort
|
|
14
|
+
context: ubyte
|
|
15
|
+
|
|
16
|
+
struct TracyCGpuZoneName:
|
|
17
|
+
query_id: ushort
|
|
18
|
+
context: ubyte
|
|
19
|
+
name: cstr
|
|
20
|
+
|
|
21
|
+
external function tracy_emit_zone_begin(srcloc: const_ptr[TracyCSourceLocation]?, active: int) -> TracyCZoneCtx = c"___tracy_emit_zone_begin"
|
|
22
|
+
external function tracy_emit_zone_begin_callstack(srcloc: const_ptr[TracyCSourceLocation]?, depth: int, active: int) -> TracyCZoneCtx = c"___tracy_emit_zone_begin_callstack"
|
|
23
|
+
external function tracy_emit_zone_end(ctx: TracyCZoneCtx) -> void = c"___tracy_emit_zone_end"
|
|
24
|
+
external function tracy_emit_zone_text(ctx: TracyCZoneCtx, text: cstr, size: ptr_uint) -> void = c"___tracy_emit_zone_text"
|
|
25
|
+
external function tracy_emit_zone_name(ctx: TracyCZoneCtx, name: cstr, size: ptr_uint) -> void = c"___tracy_emit_zone_name"
|
|
26
|
+
external function tracy_emit_zone_color(ctx: TracyCZoneCtx, color: uint) -> void = c"___tracy_emit_zone_color"
|
|
27
|
+
external function tracy_emit_zone_value(ctx: TracyCZoneCtx, value: long) -> void = c"___tracy_emit_zone_value"
|
|
28
|
+
external function tracy_emit_gpu_zone_begin(srcloc: const_ptr[TracyCSourceLocation]?, active: int) -> TracyCZoneCtx = c"___tracy_emit_gpu_zone_begin"
|
|
29
|
+
external function tracy_emit_gpu_zone_begin_callstack(srcloc: const_ptr[TracyCSourceLocation]?, depth: int, active: int) -> TracyCZoneCtx = c"___tracy_emit_gpu_zone_begin_callstack"
|
|
30
|
+
external function tracy_emit_gpu_zone_end(ctx: TracyCZoneCtx) -> void = c"___tracy_emit_gpu_zone_end"
|
|
31
|
+
external function tracy_emit_gpu_zone_name(ctx: TracyCZoneCtx, name: cstr, size: ptr_uint) -> void = c"___tracy_emit_gpu_zone_name"
|
|
32
|
+
external function tracy_emit_gpu_zone_value(ctx: TracyCZoneCtx, value: long) -> void = c"___tracy_emit_gpu_zone_value"
|
|
33
|
+
external function tracy_emit_gpu_new_context(ctx: TracyCZoneCtx) -> void = c"___tracy_emit_gpu_new_context"
|
|
34
|
+
external function tracy_emit_gpu_context_name(ctx: TracyCZoneCtx, name: cstr, size: ptr_uint) -> void = c"___tracy_emit_gpu_context_name"
|
|
35
|
+
external function tracy_emit_gpu_calibration(ctx: TracyCZoneCtx) -> void = c"___tracy_emit_gpu_calibration"
|
|
36
|
+
external function tracy_emit_gpu_time(data: const_ptr[TracyCGpuTime]) -> void = c"___tracy_emit_gpu_time"
|
|
37
|
+
external function tracy_emit_gpu_time_sync(data: const_ptr[TracyCGpuTime]) -> void = c"___tracy_emit_gpu_time_sync"
|
|
38
|
+
external function tracy_emit_frame_mark(name: cstr) -> void = c"___tracy_emit_frame_mark"
|
|
39
|
+
external function tracy_emit_frame_mark_start(name: cstr) -> void = c"___tracy_emit_frame_mark_start"
|
|
40
|
+
external function tracy_emit_frame_mark_end(name: cstr) -> void = c"___tracy_emit_frame_mark_end"
|
|
41
|
+
external function tracy_emit_plot(name: cstr, value: double) -> void = c"___tracy_emit_plot"
|
|
42
|
+
external function tracy_emit_plot_config(name: cstr, format_type: int, step: int, fill: int, color: uint) -> void = c"___tracy_emit_plot_config"
|
|
43
|
+
external function tracy_emit_plot_float(name: cstr, value: float) -> void = c"___tracy_emit_plot_float"
|
|
44
|
+
external function tracy_emit_plot_int(name: cstr, value: long) -> void = c"___tracy_emit_plot_int"
|
|
45
|
+
external function tracy_emit_message(text: cstr, size: ptr_uint, callstack: int) -> void = c"___tracy_emit_message"
|
|
46
|
+
external function tracy_emit_message_color(text: cstr, size: ptr_uint, color: uint, callstack: int) -> void = c"___tracy_emit_message_color"
|
|
47
|
+
external function tracy_emit_message_l(text: cstr, callstack: int) -> void = c"___tracy_emit_message_l"
|
|
48
|
+
external function tracy_emit_message_lc(text: cstr, color: uint, callstack: int) -> void = c"___tracy_emit_message_lc"
|
|
49
|
+
external function tracy_connected() -> int = c"___tracy_connected"
|
|
50
|
+
external function tracy_fiber_enter(fiber: cstr) -> void = c"___tracy_fiber_enter"
|
|
51
|
+
external function tracy_fiber_leave() -> void = c"___tracy_fiber_leave"
|
|
52
|
+
external function tracy_startup_profiler() -> void = c"___tracy_startup_profiler"
|
|
53
|
+
external function tracy_shutdown_profiler() -> void = c"___tracy_shutdown_profiler"
|
data/std/c/zlib.mt
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
external
|
|
2
|
+
|
|
3
|
+
link "z"
|
|
4
|
+
include "zlib_support.h"
|
|
5
|
+
|
|
6
|
+
struct mt_zlib_bytes = c"mt_zlib_bytes":
|
|
7
|
+
data: ptr[ubyte]?
|
|
8
|
+
len: ptr_uint
|
|
9
|
+
|
|
10
|
+
struct mt_zlib_error = c"mt_zlib_error":
|
|
11
|
+
code: int
|
|
12
|
+
message_data: ptr[char]?
|
|
13
|
+
message_len: ptr_uint
|
|
14
|
+
|
|
15
|
+
const MT_ZLIB_DEFAULT_COMPRESSION: int = -1
|
|
16
|
+
const MT_ZLIB_BEST_SPEED: int = 1
|
|
17
|
+
const MT_ZLIB_BEST_COMPRESSION: int = 9
|
|
18
|
+
|
|
19
|
+
external function mt_gzip_compress(data: ptr[ubyte]?, len: ptr_uint, level: int, out out_bytes: mt_zlib_bytes, out out_error: mt_zlib_error) -> int
|
|
20
|
+
external function mt_gzip_decompress(data: ptr[ubyte]?, len: ptr_uint, out out_bytes: mt_zlib_bytes, out out_error: mt_zlib_error) -> int
|