Skip to content

Commit a193c88

Browse files
committed
move TfwStr_string to str.h and rename TfwStr_string to TFW_STR_STRING
1 parent ac7c648 commit a193c88

File tree

5 files changed

+60
-67
lines changed

5 files changed

+60
-67
lines changed

tempesta_fw/cache.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,13 @@ static const int tfw_cache_spec_headers_304[] = {
4747
[TFW_HTTP_HDR_ETAG] = 1,
4848
};
4949
static const TfwStr tfw_cache_raw_headers_304[] = {
50-
#define TfwStr_string(v) { .data = (v), NULL, sizeof(v) - 1, 0 }
51-
TfwStr_string("cache-control:"),
52-
TfwStr_string("content-location:"),
53-
TfwStr_string("date:"),
54-
TfwStr_string("expires:"),
55-
TfwStr_string("last-modified:"),
56-
TfwStr_string("vary:"),
50+
TFW_STR_STRING("cache-control:"),
51+
TFW_STR_STRING("content-location:"),
52+
TFW_STR_STRING("date:"),
53+
TFW_STR_STRING("expires:"),
54+
TFW_STR_STRING("last-modified:"),
55+
TFW_STR_STRING("vary:"),
5756
/* Etag are Spec headers */
58-
#undef TfwStr_string
5957
};
6058
#define TFW_CACHE_304_SPEC_HDRS_NUM 1 /* ETag. */
6159
#define TFW_CACHE_304_HDRS_NUM \

tempesta_fw/http_msg.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -259,15 +259,13 @@ static inline bool
259259
__hdr_is_singular(const TfwStr *hdr)
260260
{
261261
static const TfwStr hdr_singular[] = {
262-
#define TfwStr_string(v) { .data = (v), NULL, sizeof(v) - 1, 0 }
263-
TfwStr_string("authorization:"),
264-
TfwStr_string("from:"),
265-
TfwStr_string("if-unmodified-since:"),
266-
TfwStr_string("location:"),
267-
TfwStr_string("max-forwards:"),
268-
TfwStr_string("proxy-authorization:"),
269-
TfwStr_string("referer:"),
270-
#undef TfwStr_string
262+
TFW_STR_STRING("authorization:"),
263+
TFW_STR_STRING("from:"),
264+
TFW_STR_STRING("if-unmodified-since:"),
265+
TFW_STR_STRING("location:"),
266+
TFW_STR_STRING("max-forwards:"),
267+
TFW_STR_STRING("proxy-authorization:"),
268+
TFW_STR_STRING("referer:"),
271269
};
272270

273271
return tfw_http_msg_find_hdr(hdr, hdr_singular);

tempesta_fw/http_parser.c

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -644,25 +644,23 @@ __hbh_parser_add_data(TfwHttpMsg *hm, char *data, unsigned long len, bool last)
644644
TfwStr *hdr, *append;
645645
TfwHttpHbhHdrs *hbh = &hm->conn->parser.hbh_parser;
646646
static const TfwStr block[] = {
647-
#define TfwStr_string(v) { .data = (v), NULL, sizeof(v) - 1, 0 }
648647
/* End-to-end spec and raw headers */
649-
TfwStr_string("age:"),
650-
TfwStr_string("authorization:"),
651-
TfwStr_string("cache-control:"),
652-
TfwStr_string("connection:"),
653-
TfwStr_string("content-length:"),
654-
TfwStr_string("content-type:"),
655-
TfwStr_string("cookie:"),
656-
TfwStr_string("date:"),
657-
TfwStr_string("etag:"),
658-
TfwStr_string("expires:"),
659-
TfwStr_string("host:"),
660-
TfwStr_string("pragma:"),
661-
TfwStr_string("server:"),
662-
TfwStr_string("transfer-encoding:"),
663-
TfwStr_string("user-agent:"),
664-
TfwStr_string("x-forwarded-for:"),
665-
#undef TfwStr_string
648+
TFW_STR_STRING("age:"),
649+
TFW_STR_STRING("authorization:"),
650+
TFW_STR_STRING("cache-control:"),
651+
TFW_STR_STRING("connection:"),
652+
TFW_STR_STRING("content-length:"),
653+
TFW_STR_STRING("content-type:"),
654+
TFW_STR_STRING("cookie:"),
655+
TFW_STR_STRING("date:"),
656+
TFW_STR_STRING("etag:"),
657+
TFW_STR_STRING("expires:"),
658+
TFW_STR_STRING("host:"),
659+
TFW_STR_STRING("pragma:"),
660+
TFW_STR_STRING("server:"),
661+
TFW_STR_STRING("transfer-encoding:"),
662+
TFW_STR_STRING("user-agent:"),
663+
TFW_STR_STRING("x-forwarded-for:"),
666664
};
667665

668666
if (hbh->off == TFW_HBH_TOKENS_MAX)

tempesta_fw/str.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,9 @@ typedef struct tfwstr_t {
216216
unsigned char eolen;
217217
} TfwStr;
218218

219-
#define DEFINE_TFW_STR(name, val) TfwStr name = \
220-
{.data = (val), NULL, sizeof(val) - 1, 0, 0, 0}
219+
#define TFW_STR_STRING(val) ((TfwStr){.data = (val), NULL, \
220+
sizeof(val) - 1, 0, 0, 0})
221+
#define DEFINE_TFW_STR(name, val) TfwStr name = TFW_STR_STRING(val)
221222
#define TFW_STR_FROM(s) ((TfwStr){.data = (char*)s, \
222223
NULL, strlen(s), 0, 0, 0})
223224

tempesta_fw/t/unit/test_http_msg.c

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,49 +25,47 @@
2525
TEST(http_msg, hdr_in_array)
2626
{
2727
size_t i;
28-
#define TfwStr_string(v) { .data = (v), NULL, sizeof(v) - 1, 0 }
2928
static const TfwStr hdrs[] = {
30-
TfwStr_string("age:"),
31-
TfwStr_string("authorization:"),
32-
TfwStr_string("cache-control:"),
33-
TfwStr_string("connection:"),
34-
TfwStr_string("content-length:"),
35-
TfwStr_string("content-type:"),
36-
TfwStr_string("cookie:"),
37-
TfwStr_string("date:"),
38-
TfwStr_string("etag:"),
39-
TfwStr_string("expires:"),
40-
TfwStr_string("from:"),
41-
TfwStr_string("host:"),
42-
TfwStr_string("if-unmodified-since:"),
43-
TfwStr_string("last-modified:"),
44-
TfwStr_string("location:"),
45-
TfwStr_string("pragma:"),
46-
TfwStr_string("proxy-authorization:"),
47-
TfwStr_string("referer:"),
48-
TfwStr_string("server:"),
49-
TfwStr_string("transfer-encoding:"),
50-
TfwStr_string("user-agent:"),
51-
TfwStr_string("vary:"),
52-
TfwStr_string("x-forwarded-for:"),
29+
TFW_STR_STRING("age:"),
30+
TFW_STR_STRING("authorization:"),
31+
TFW_STR_STRING("cache-control:"),
32+
TFW_STR_STRING("connection:"),
33+
TFW_STR_STRING("content-length:"),
34+
TFW_STR_STRING("content-type:"),
35+
TFW_STR_STRING("cookie:"),
36+
TFW_STR_STRING("date:"),
37+
TFW_STR_STRING("etag:"),
38+
TFW_STR_STRING("expires:"),
39+
TFW_STR_STRING("from:"),
40+
TFW_STR_STRING("host:"),
41+
TFW_STR_STRING("if-unmodified-since:"),
42+
TFW_STR_STRING("last-modified:"),
43+
TFW_STR_STRING("location:"),
44+
TFW_STR_STRING("pragma:"),
45+
TFW_STR_STRING("proxy-authorization:"),
46+
TFW_STR_STRING("referer:"),
47+
TFW_STR_STRING("server:"),
48+
TFW_STR_STRING("transfer-encoding:"),
49+
TFW_STR_STRING("user-agent:"),
50+
TFW_STR_STRING("vary:"),
51+
TFW_STR_STRING("x-forwarded-for:"),
5352
};
5453
static const TfwStr o_hdrs[] = {
55-
TfwStr_string("keep-alive:"),
56-
TfwStr_string("max-forwards:"),
57-
TfwStr_string("content-location:"),
54+
TFW_STR_STRING("keep-alive:"),
55+
TFW_STR_STRING("max-forwards:"),
56+
TFW_STR_STRING("content-location:"),
5857
};
5958
#define S_PART_01 "cache-control: no-cache"
6059
#define S_PART_02 "cache-control: no-store"
6160
TfwStr dup_hdr = {
6261
.chunks = (TfwStr []){
63-
TfwStr_string(S_PART_01),
64-
TfwStr_string(S_PART_01),
62+
TFW_STR_STRING(S_PART_01),
63+
TFW_STR_STRING(S_PART_01),
6564
},
6665
.len = SLEN(S_PART_01 S_PART_02),
6766
.nchunks = 2,
6867
.flags = TFW_STR_DUPLICATE,
6968
};
70-
#undef TfwStr_string
7169
#undef S_PART_01
7270
#undef S_PART_02
7371

0 commit comments

Comments
 (0)