/
xqd.h
303 lines (233 loc) · 11.9 KB
/
xqd.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
#ifndef xqd_H
#define xqd_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#define WASM_IMPORT(module, name) __attribute__((import_module(module), import_name(name)))
#define XQD_ABI_VERSION 0x01ULL
//max header size to match vcl
#define HEADER_MAX_LEN 69000
#define METHOD_MAX_LEN 1024
#define URI_MAX_LEN 8192
#define DICTIONARY_ENTRY_MAX_LEN 8000
// TODO ACF 2020-01-17: these aren't very C-friendly names
typedef struct {
uint32_t handle;
} BodyHandle;
typedef struct {
uint32_t handle;
} RequestHandle;
typedef struct {
uint32_t handle;
} ResponseHandle;
typedef struct {
uint32_t handle;
} PendingRequestHandle;
typedef struct {
uint32_t handle;
} LogEndpointHandle;
typedef struct {
uint32_t handle;
} DictionaryHandle;
#define INVALID_HANDLE (UINT32_MAX - 1)
typedef enum BodyWriteEnd {
BodyWriteEndBack = 0,
BodyWriteEndFront = 1,
} BodyWriteEnd;
#define CACHE_OVERRIDE_NONE (0u)
#define CACHE_OVERRIDE_PASS (1u<<0)
#define CACHE_OVERRIDE_TTL (1u<<1)
#define CACHE_OVERRIDE_STALE_WHILE_REVALIDATE (1u<<2)
#define CACHE_OVERRIDE_PCI (1u<<3)
// TODO ACF 2019-12-05: nicer type for the return value (XqdStatus)
// Module fastly_abi
WASM_IMPORT("fastly_abi", "init")
int xqd_init(uint64_t abi_version);
// Module fastly_uap
WASM_IMPORT("fastly_uap", "parse")
int xqd_uap_parse(const char *user_agent, size_t user_agent_len, char *family,
size_t family_max_len, size_t *family_nwritten, char *major, size_t major_max_len,
size_t *major_nwritten, char *minor, size_t minor_max_len, size_t *minor_nwritten,
char *patch, size_t patch_max_len, size_t *patch_nwritten);
// Module fastly_http_body
WASM_IMPORT("fastly_http_body", "append")
int xqd_body_append(BodyHandle dst_handle, BodyHandle src_handle);
WASM_IMPORT("fastly_http_body", "new")
int xqd_body_new(BodyHandle *handle_out);
WASM_IMPORT("fastly_http_body", "read")
int xqd_body_read(BodyHandle body_handle, char *buf, size_t buf_len, size_t *nread);
WASM_IMPORT("fastly_http_body", "write")
int xqd_body_write(BodyHandle body_handle, const char *buf, size_t buf_len, BodyWriteEnd end,
size_t *nwritten);
WASM_IMPORT("fastly_http_body", "close")
int xqd_body_close(BodyHandle body_handle);
// Module fastly_log
WASM_IMPORT("fastly_log", "endpoint_get")
int xqd_log_endpoint_get(const char *name, size_t name_len, LogEndpointHandle *endpoint_handle);
WASM_IMPORT("fastly_log", "write")
int xqd_log_write(LogEndpointHandle endpoint_handle, const char* msg, size_t msg_len,
size_t *nwritten);
// Module fastly_http_req
WASM_IMPORT("fastly_http_req", "body_downstream_get")
int xqd_req_body_downstream_get(RequestHandle *req_handle_out, BodyHandle *body_handle_out);
/**
* Set the cache override behavior for this request.
*
* The default behavior, equivalent to `CACHE_OVERRIDE_NONE`, respects the cache control headers
* from the origin's response.
*
* Calling this function with `CACHE_OVERRIDE_PASS` will ignore the subsequent arguments and Pass
* unconditionally.
*
* To override, TTL, stale-while-revalidate, or stale-with-error, set the appropriate bits in the
* tag using the corresponding constants, and pass the override values in the appropriate arguments.
*
* xqd_req_cache_override_v2_set also includes an optional Surrogate-Key which will be set or added
* to any received from the origin.
*/
WASM_IMPORT("fastly_http_req", "cache_override_set")
int xqd_req_cache_override_set(RequestHandle req_handle, int tag, uint32_t ttl,
uint32_t stale_while_revalidate);
WASM_IMPORT("fastly_http_req", "cache_override_v2_set")
int xqd_req_cache_override_v2_set(RequestHandle req_handle, int tag, uint32_t ttl,
uint32_t stale_while_revalidate,
const char *surrogate_key, size_t surrogate_key_len);
/**
* `octets` must be a 16-byte array.
* If, after a successful call, `nwritten` == 4, the value in `octets` is an IPv4 address.
* Otherwise, if `nwritten` will is `16`, the value in `octets` is an IPv6 address.
* Otherwise, `nwritten` will be `0`, and no address is available.
*/
WASM_IMPORT("fastly_http_req", "downstream_client_ip_addr")
int xqd_req_downstream_client_ip_addr_get(char* octets, size_t *nwritten);
// TODO:
// (@interface func (export "downstream_tls_cipher_openssl_name")
// (param $cipher_out (@witx pointer char8))
// (param $cipher_max_len (@witx usize))
// (param $nwritten_out (@witx pointer (@witx usize)))
// (result $err $fastly_status)
// )
// (@interface func (export "downstream_tls_protocol")
// (param $protocol_out (@witx pointer char8))
// (param $protocol_max_len (@witx usize))
// (param $nwritten_out (@witx pointer (@witx usize)))
// (result $err $fastly_status)
// )
// (@interface func (export "downstream_tls_client_hello")
// (param $chello_out (@witx pointer char8))
// (param $chello_max_len (@witx usize))
// (param $nwritten_out (@witx pointer (@witx usize)))
// (result $err $fastly_status)
// )
WASM_IMPORT("fastly_http_req", "new")
int xqd_req_new(RequestHandle *req_handle_out);
WASM_IMPORT("fastly_http_req", "header_names_get")
int xqd_req_header_names_get(RequestHandle req_handle, char *buf, size_t buf_len, uint32_t cursor,
int64_t *ending_cursor, size_t *nwritten);
WASM_IMPORT("fastly_http_req", "original_header_names_get")
int xqd_req_original_header_names_get(char *buf, size_t buf_len, uint32_t cursor,
int64_t *ending_cursor, size_t *nwritten);
WASM_IMPORT("fastly_http_req", "original_header_count")
int xqd_req_original_header_count(uint32_t *count);
WASM_IMPORT("fastly_http_req", "header_value_get")
int xqd_req_header_value_get(RequestHandle req_handle, const char *name, size_t name_len,
char *value, size_t value_max_len, size_t *nwritten);
WASM_IMPORT("fastly_http_req", "header_values_get")
int xqd_req_header_values_get(RequestHandle req_handle, const char *name, size_t name_len,
char *buf, size_t buf_len, uint32_t cursor, int64_t *ending_cursor,
size_t *nwritten);
WASM_IMPORT("fastly_http_req", "header_values_set")
int xqd_req_header_values_set(RequestHandle req_handle, const char *name, size_t name_len,
const char *values, size_t values_len);
WASM_IMPORT("fastly_http_req", "header_insert")
int xqd_req_header_insert(RequestHandle req_handle, const char *name, size_t name_len,
const char *value, size_t value_len);
WASM_IMPORT("fastly_http_req", "header_append")
int xqd_req_header_append(RequestHandle req_handle, const char *name, size_t name_len,
const char *value, size_t value_len);
WASM_IMPORT("fastly_http_req", "header_remove")
int xqd_req_header_remove(RequestHandle req_handle, const char *name, size_t name_len);
WASM_IMPORT("fastly_http_req", "method_get")
int xqd_req_method_get(RequestHandle req_handle, char *method, size_t method_max_len,
size_t *nwritten);
WASM_IMPORT("fastly_http_req", "method_set")
int xqd_req_method_set(RequestHandle req_handle, const char *method, size_t method_len);
WASM_IMPORT("fastly_http_req", "uri_get")
int xqd_req_uri_get(RequestHandle req_handle, char *uri, size_t uri_max_len, size_t *nwritten);
WASM_IMPORT("fastly_http_req", "uri_set")
int xqd_req_uri_set(RequestHandle req_handle, const char *uri, size_t uri_len);
WASM_IMPORT("fastly_http_req", "version_get")
int xqd_req_version_get(RequestHandle req_handle, uint32_t *version);
WASM_IMPORT("fastly_http_req", "version_set")
int xqd_req_version_set(RequestHandle req_handle, uint32_t version);
WASM_IMPORT("fastly_http_req", "send")
int xqd_req_send(RequestHandle req_handle, BodyHandle body_handle, const char *backend,
size_t backend_len, ResponseHandle *resp_handle_out,
BodyHandle *resp_body_handle_out);
WASM_IMPORT("fastly_http_req", "send_async")
int xqd_req_send_async(RequestHandle req_handle, BodyHandle body_handle, const char *backend,
size_t backend_len, PendingRequestHandle *pending_req_out);
WASM_IMPORT("fastly_http_req", "send_async_streaming")
int xqd_req_send_async_streaming(RequestHandle req_handle, BodyHandle body_handle,
const char *backend, size_t backend_len,
PendingRequestHandle *pending_req_out);
WASM_IMPORT("fastly_http_req", "pending_req_poll")
int xqd_req_pending_req_poll(PendingRequestHandle req_handle, uint32_t *is_done_out,
ResponseHandle *resp_handle_out, BodyHandle *resp_body_handle_out);
WASM_IMPORT("fastly_http_req", "pending_req_wait")
int xqd_req_pending_req_wait(PendingRequestHandle req_handle, ResponseHandle *resp_handle_out,
BodyHandle *resp_body_handle_out);
WASM_IMPORT("fastly_http_req", "pending_req_select")
int xqd_req_pending_req_select(PendingRequestHandle req_handles[], size_t req_handles_len,
uint32_t *done_idx_out, ResponseHandle *resp_handle_out,
BodyHandle *resp_body_handle_out);
// Module fastly_http_resp
WASM_IMPORT("fastly_http_resp", "new")
int xqd_resp_new(ResponseHandle *resp_handle_out);
WASM_IMPORT("fastly_http_resp", "header_names_get")
int xqd_resp_header_names_get(ResponseHandle resp_handle, char *buf, size_t buf_len,
uint32_t cursor, int64_t *ending_cursor, size_t *nwritten);
WASM_IMPORT("fastly_http_resp", "header_value_get")
int xqd_resp_header_value_get(ResponseHandle resp_handle, const char *name, size_t name_len,
char *value, size_t value_max_len, size_t *nwritten);
WASM_IMPORT("fastly_http_resp", "header_values_get")
int xqd_resp_header_values_get(ResponseHandle resp_handle, const char *name, size_t name_len,
char *buf, size_t buf_len, uint32_t cursor, int64_t *ending_cursor,
size_t *nwritten);
WASM_IMPORT("fastly_http_resp", "header_values_set")
int xqd_resp_header_values_set(ResponseHandle resp_handle, const char *name, size_t name_len,
const char *buf, size_t buf_len);
WASM_IMPORT("fastly_http_resp", "header_insert")
int xqd_resp_header_insert(ResponseHandle resp_handle, const char *name, size_t name_len,
const char *value, size_t value_len);
WASM_IMPORT("fastly_http_resp", "header_append")
int xqd_resp_header_append(ResponseHandle resp_handle, const char *name, size_t name_len,
const char *value, size_t value_len);
WASM_IMPORT("fastly_http_resp", "header_remove")
int xqd_resp_header_remove(ResponseHandle resp_handle, const char *name, size_t name_len);
WASM_IMPORT("fastly_http_resp", "version_get")
int xqd_resp_version_get(ResponseHandle resp_handle, uint32_t *version_out);
WASM_IMPORT("fastly_http_resp", "version_set")
int xqd_resp_version_set(ResponseHandle resp_handle, uint32_t version);
WASM_IMPORT("fastly_http_resp", "send_downstream")
int xqd_resp_send_downstream(ResponseHandle resp_handle, BodyHandle body_handle, uint32_t streaming);
WASM_IMPORT("fastly_http_resp", "status_get")
int xqd_resp_status_get(ResponseHandle resp_handle, uint16_t *status_out);
WASM_IMPORT("fastly_http_resp", "status_set")
int xqd_resp_status_set(ResponseHandle resp_handle, uint16_t status);
// Module fastly_dictionary
WASM_IMPORT("fastly_dictionary", "open")
int xqd_dictionary_open(const char *name, size_t name_len, DictionaryHandle *dict_handle_out);
WASM_IMPORT("fastly_dictionary", "get")
int xqd_dictionary_get(DictionaryHandle dict_handle, const char *key, size_t key_len,
char *value, size_t value_max_len, size_t *nwritten);
WASM_IMPORT("fastly_geo", "lookup")
int xqd_geo_lookup(const char* addr_octets, size_t addr_len, char *buf, size_t buf_len,
size_t *nwritten);
#ifdef __cplusplus
}
#endif
#endif