Skip to content

Commit 8ffa37c

Browse files
authored
refactor: move some subsys independent types to proxy_wasm/ (#80)
1 parent ea91955 commit 8ffa37c

File tree

9 files changed

+79
-79
lines changed

9 files changed

+79
-79
lines changed

config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ngx_module_srcs=" \
55
$ngx_addon_dir/src/http/ngx_http_wasm_api.c \
66
$ngx_addon_dir/src/http/ngx_http_wasm_call.c \
77
$ngx_addon_dir/src/http/ngx_http_wasm_state.c \
8-
$ngx_addon_dir/src/http/ngx_http_wasm_map.c \
8+
$ngx_addon_dir/src/proxy_wasm/proxy_wasm_map.c \
99
$ngx_addon_dir/src/vm/wasmtime.c \
1010
$ngx_addon_dir/src/vm/vm.c \
1111
"

src/http/ngx_http_wasm_api.c

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
#include "ngx_http_wasm_api.h"
55
#include "ngx_http_wasm_module.h"
66
#include "ngx_http_wasm_state.h"
7-
#include "ngx_http_wasm_map.h"
87
#include "ngx_http_wasm_call.h"
98
#include "ngx_http_wasm_ctx.h"
9+
#include "proxy_wasm/proxy_wasm_map.h"
1010

1111

1212
typedef struct {
@@ -550,8 +550,8 @@ proxy_send_http_response(int32_t res_code,
550550
return PROXY_RESULT_INVALID_MEMORY_ACCESS;
551551
}
552552

553-
ngx_http_wasm_map_init_iter(&it, p);
554-
while (ngx_http_wasm_map_next(&it, &key, &key_len, &val, &val_len)) {
553+
proxy_wasm_map_init_iter(&it, p);
554+
while (proxy_wasm_map_next(&it, &key, &key_len, &val, &val_len)) {
555555
rc = ngx_http_wasm_set_resp_header(r, key, key_len, 0, val, val_len, 0);
556556
if (rc != NGX_OK) {
557557
return PROXY_RESULT_BAD_ARGUMENT;
@@ -690,12 +690,12 @@ ngx_http_wasm_req_get_headers(ngx_http_request_t *r, int32_t addr, int32_t size_
690690
}
691691

692692
/* get the data */
693-
ngx_http_wasm_map_init_map(buf, count + PROXY_WASM_HEADER_STATIC_TABLE_ENTRIES);
694-
ngx_http_wasm_map_init_iter(&it, buf);
693+
proxy_wasm_map_init_map(buf, count + PROXY_WASM_HEADER_STATIC_TABLE_ENTRIES);
694+
proxy_wasm_map_init_iter(&it, buf);
695695

696696
for (i = 0; i < count; i++) {
697-
ngx_http_wasm_map_reserve(&it, &key, headers[i].key.len,
698-
&val, headers[i].value.len);
697+
proxy_wasm_map_reserve(&it, &key, headers[i].key.len,
698+
&val, headers[i].value.len);
699699
/* the header key is already lowercase */
700700
ngx_memcpy(key, headers[i].key.data, headers[i].key.len);
701701
ngx_memcpy(val, headers[i].value.data, headers[i].value.len);
@@ -713,8 +713,8 @@ ngx_http_wasm_req_get_headers(ngx_http_request_t *r, int32_t addr, int32_t size_
713713
wh = &wasm_h2_header_static_table[i];
714714
s = wh->getter(r);
715715

716-
ngx_http_wasm_map_reserve(&it, &key, wh->name.len,
717-
&val, s->len);
716+
proxy_wasm_map_reserve(&it, &key, wh->name.len,
717+
&val, s->len);
718718
ngx_memcpy(key, wh->name.data, wh->name.len);
719719
ngx_memcpy(val, s->data, s->len);
720720
}
@@ -811,8 +811,8 @@ ngx_http_wasm_resp_get_headers(ngx_http_request_t *r, int32_t addr, int32_t size
811811
}
812812

813813
/* get the data */
814-
ngx_http_wasm_map_init_map(buf, count);
815-
ngx_http_wasm_map_init_iter(&it, buf);
814+
proxy_wasm_map_init_map(buf, count);
815+
proxy_wasm_map_init_iter(&it, buf);
816816

817817
for (i = 0; /* void */; i++) {
818818

@@ -834,8 +834,8 @@ ngx_http_wasm_resp_get_headers(ngx_http_request_t *r, int32_t addr, int32_t size
834834

835835
/* nginx does not even bother initializing output header entry's
836836
* "lowcase_key" field. so we cannot count on that at all. */
837-
ngx_http_wasm_map_reserve(&it, &lowcase_key, header[i].key.len,
838-
&val, header[i].value.len);
837+
proxy_wasm_map_reserve(&it, &lowcase_key, header[i].key.len,
838+
&val, header[i].value.len);
839839
ngx_strlow((u_char *) lowcase_key, header[i].key.data, header[i].key.len);
840840
ngx_memcpy(val, header[i].value.data, header[i].value.len);
841841

@@ -845,31 +845,31 @@ ngx_http_wasm_resp_get_headers(ngx_http_request_t *r, int32_t addr, int32_t size
845845
}
846846

847847
if (r->headers_out.content_type.len) {
848-
ngx_http_wasm_map_reserve(&it, &lowcase_key, sizeof("content-type") - 1,
849-
&val, r->headers_out.content_type.len);
848+
proxy_wasm_map_reserve(&it, &lowcase_key, sizeof("content-type") - 1,
849+
&val, r->headers_out.content_type.len);
850850
ngx_memcpy(lowcase_key, "content-type", sizeof("content-type") - 1);
851851
ngx_memcpy(val, r->headers_out.content_type.data, r->headers_out.content_type.len);
852852
}
853853

854854
if (content_length_hdr != NULL) {
855-
ngx_http_wasm_map_reserve(&it, &lowcase_key, sizeof("content-length") - 1,
856-
&val, content_length_hdr_len);
855+
proxy_wasm_map_reserve(&it, &lowcase_key, sizeof("content-length") - 1,
856+
&val, content_length_hdr_len);
857857
ngx_memcpy(lowcase_key, "content-length", sizeof("content-length") - 1);
858858
ngx_memcpy(val, content_length_hdr, content_length_hdr_len);
859859
}
860860

861861
if (r->headers_out.status == NGX_HTTP_SWITCHING_PROTOCOLS) {
862-
ngx_http_wasm_map_reserve_literal(&it, "connection", "upgrade");
862+
proxy_wasm_map_reserve_literal(&it, "connection", "upgrade");
863863

864864
} else if (r->keepalive) {
865-
ngx_http_wasm_map_reserve_literal(&it, "connection", "keep-alive");
865+
proxy_wasm_map_reserve_literal(&it, "connection", "keep-alive");
866866

867867
} else {
868-
ngx_http_wasm_map_reserve_literal(&it, "connection", "close");
868+
proxy_wasm_map_reserve_literal(&it, "connection", "close");
869869
}
870870

871871
if (r->chunked) {
872-
ngx_http_wasm_map_reserve_literal(&it, "transfer-encoding", "chunked");
872+
proxy_wasm_map_reserve_literal(&it, "transfer-encoding", "chunked");
873873
}
874874

875875
return PROXY_RESULT_OK;
@@ -908,13 +908,13 @@ ngx_http_wasm_http_call_resp_get_headers(ngx_http_request_t *r, int32_t addr, in
908908
}
909909

910910
/* get the data */
911-
ngx_http_wasm_map_init_map(buf, ctx->call_resp_n_header);
912-
ngx_http_wasm_map_init_iter(&it, buf);
911+
proxy_wasm_map_init_map(buf, ctx->call_resp_n_header);
912+
proxy_wasm_map_init_iter(&it, buf);
913913

914914
for (i = 0; i < ctx->call_resp_n_header; i++) {
915915
char *key, *val;
916916

917-
ngx_http_wasm_map_reserve(&it, &key, hdr[i].key.len, &val, hdr[i].value.len);
917+
proxy_wasm_map_reserve(&it, &key, hdr[i].key.len, &val, hdr[i].value.len);
918918
ngx_memcpy(key, hdr[i].key.data, hdr[i].key.len);
919919
ngx_memcpy(val, hdr[i].value.data, hdr[i].value.len);
920920
}

src/http/ngx_http_wasm_api.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <wasm.h>
66
#include <wasmtime.h>
77
#include <ngx_core.h>
8-
#include "ngx_http_wasm_types.h"
8+
#include "proxy_wasm/proxy_wasm_types.h"
99

1010

1111
#define MAX_WASM_API_ARG 12

src/http/ngx_http_wasm_call.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include <ngx_http.h>
22
#include "ngx_http_wasm_call.h"
33
#include "ngx_http_wasm_ctx.h"
4-
#include "ngx_http_wasm_map.h"
5-
#include "ngx_http_wasm_types.h"
4+
#include "proxy_wasm/proxy_wasm_types.h"
5+
#include "proxy_wasm/proxy_wasm_map.h"
66

77

88
typedef struct {
@@ -86,7 +86,7 @@ ngx_http_wasm_call_max_headers_count(ngx_http_request_t *r)
8686

8787
ctx = ngx_http_wasm_get_module_ctx(r);
8888
callout = ctx->callout;
89-
ngx_http_wasm_map_init_iter(&it, callout->map_data);
89+
proxy_wasm_map_init_iter(&it, callout->map_data);
9090

9191
return it.len;
9292
}
@@ -112,9 +112,9 @@ ngx_http_wasm_call_get(ngx_http_request_t *r, ngx_str_t *method, ngx_str_t *sche
112112
*host = *callout->up;
113113
*timeout = callout->timeout_ms;
114114

115-
ngx_http_wasm_map_init_iter(&it, callout->map_data);
115+
proxy_wasm_map_init_iter(&it, callout->map_data);
116116

117-
while (ngx_http_wasm_map_next(&it, &key, &key_len, &val, &val_len)) {
117+
while (proxy_wasm_map_next(&it, &key, &key_len, &val, &val_len)) {
118118
if (key_len == 0) {
119119
continue;
120120
}

src/http/ngx_http_wasm_ctx.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#include <ngx_core.h>
66
#include "ngx_http_wasm_state.h"
7-
#include "ngx_http_wasm_types.h"
7+
#include "proxy_wasm/proxy_wasm_types.h"
88

99

1010
#define PROXY_WASM_ABI_VER_010 0

src/http/ngx_http_wasm_map.h

Lines changed: 0 additions & 38 deletions
This file was deleted.
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "ngx_http_wasm_map.h"
1+
#include "proxy_wasm_map.h"
22

33

44
/**
@@ -10,14 +10,14 @@
1010

1111

1212
void
13-
ngx_http_wasm_map_init_map(const u_char *map_data, int32_t len)
13+
proxy_wasm_map_init_map(const u_char *map_data, int32_t len)
1414
{
1515
*(int32_t *) map_data = len;
1616
}
1717

1818

1919
void
20-
ngx_http_wasm_map_init_iter(proxy_wasm_map_iter *it, const u_char *map_data)
20+
proxy_wasm_map_init_iter(proxy_wasm_map_iter *it, const u_char *map_data)
2121
{
2222
it->idx = 0;
2323
it->len = *(int32_t *) map_data;
@@ -27,7 +27,7 @@ ngx_http_wasm_map_init_iter(proxy_wasm_map_iter *it, const u_char *map_data)
2727

2828

2929
bool
30-
ngx_http_wasm_map_next(proxy_wasm_map_iter *it, char **key, int32_t *key_len,
30+
proxy_wasm_map_next(proxy_wasm_map_iter *it, char **key, int32_t *key_len,
3131
char **val, int32_t *val_len)
3232
{
3333
if (it->idx == it->len) {
@@ -50,7 +50,7 @@ ngx_http_wasm_map_next(proxy_wasm_map_iter *it, char **key, int32_t *key_len,
5050

5151

5252
bool
53-
ngx_http_wasm_map_reserve(proxy_wasm_map_iter *it, char **key, int32_t key_len,
53+
proxy_wasm_map_reserve(proxy_wasm_map_iter *it, char **key, int32_t key_len,
5454
char **val, int32_t val_len)
5555
{
5656
if (it->idx == it->len) {
@@ -77,7 +77,7 @@ ngx_http_wasm_map_reserve(proxy_wasm_map_iter *it, char **key, int32_t key_len,
7777

7878

7979
bool
80-
ngx_http_wasm_map_reserve_literal_with_len(proxy_wasm_map_iter *it,
80+
proxy_wasm_map_reserve_literal_with_len(proxy_wasm_map_iter *it,
8181
const char *key, size_t key_len,
8282
const char *val, size_t val_len)
8383
{

src/proxy_wasm/proxy_wasm_map.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#ifndef PROXY_WASM_MAP_H
2+
#define PROXY_WASM_MAP_H
3+
#include <stdbool.h>
4+
#include <ngx_core.h>
5+
6+
7+
typedef enum {
8+
PROXY_MAP_TYPE_HTTP_REQUEST_HEADERS = 0,
9+
PROXY_MAP_TYPE_HTTP_REQUEST_TRAILERS = 1,
10+
PROXY_MAP_TYPE_HTTP_RESPONSE_HEADERS = 2,
11+
PROXY_MAP_TYPE_HTTP_RESPONSE_TRAILERS = 3,
12+
PROXY_MAP_TYPE_HTTP_CALL_RESPONSE_HEADERS = 6,
13+
PROXY_MAP_TYPE_HTTP_CALL_RESPONSE_TRAILERS = 7,
14+
} proxy_map_type_t;
15+
16+
17+
typedef struct {
18+
int32_t idx;
19+
int32_t len;
20+
int32_t *size_ptr;
21+
char *data_ptr;
22+
} proxy_wasm_map_iter;
23+
24+
25+
void proxy_wasm_map_init_map(const u_char *map_data, int32_t len);
26+
void proxy_wasm_map_init_iter(proxy_wasm_map_iter *it, const u_char *map_data);
27+
bool proxy_wasm_map_next(proxy_wasm_map_iter *it, char **key, int32_t *key_len,
28+
char **val, int32_t *val_len);
29+
bool proxy_wasm_map_reserve(proxy_wasm_map_iter *it, char **key, int32_t key_len,
30+
char **val, int32_t val_len);
31+
bool proxy_wasm_map_reserve_literal_with_len(proxy_wasm_map_iter *it,
32+
const char *key, size_t key_len,
33+
const char *val, size_t val_len);
34+
#define proxy_wasm_map_reserve_literal(it, k, v) \
35+
proxy_wasm_map_reserve_literal_with_len(it, k, sizeof((k)) - 1, v, sizeof((v)) - 1)
36+
37+
38+
#endif // PROXY_WASM_MAP_H
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef NGX_HTTP_WASM_TYPES_H
2-
#define NGX_HTTP_WASM_TYPES_H
1+
#ifndef PROXY_WASM_TYPES_H
2+
#define PROXY_WASM_TYPES_H
33

44

55
#include <ngx_core.h>
@@ -72,4 +72,4 @@ enum {
7272
};
7373

7474

75-
#endif // NGX_HTTP_WASM_TYPES_H
75+
#endif // PROXY_WASM_TYPES_H

0 commit comments

Comments
 (0)