Skip to content

Commit ab9a43a

Browse files
authored
Merge pull request #1166 from tempesta-tech/avb-str2
Separate number of chunks from flags
2 parents 5b3a12a + 79913d6 commit ab9a43a

17 files changed

+233
-250
lines changed

tempesta_fw/cache.c

Lines changed: 12 additions & 14 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 \
@@ -189,15 +187,15 @@ static TfwStr g_crlf = { .data = S_CRLF, .len = SLEN(S_CRLF) };
189187
} else { \
190188
c = req->uri_path.chunks; \
191189
u_end = req->uri_path.chunks \
192-
+ TFW_STR_CHUNKN(&req->uri_path); \
190+
+ req->uri_path.nchunks; \
193191
} \
194192
if (TFW_STR_PLAIN(&req->h_tbl->tbl[TFW_HTTP_HDR_HOST])) { \
195193
h_start = req->h_tbl->tbl + TFW_HTTP_HDR_HOST; \
196194
h_end = req->h_tbl->tbl + TFW_HTTP_HDR_HOST + 1; \
197195
} else { \
198196
h_start = req->h_tbl->tbl[TFW_HTTP_HDR_HOST].chunks; \
199-
h_end = req->h_tbl->tbl[TFW_HTTP_HDR_HOST].chunks \
200-
+ TFW_STR_CHUNKN(&req->h_tbl->tbl[TFW_HTTP_HDR_HOST]);\
197+
h_end = req->h_tbl->tbl[TFW_HTTP_HDR_HOST].chunks \
198+
+ req->h_tbl->tbl[TFW_HTTP_HDR_HOST].nchunks; \
201199
} \
202200
for ( ; c != h_end; ++c, c = (c == u_end) ? h_start : c)
203201

@@ -608,7 +606,7 @@ tfw_cache_build_resp_hdr(TDB *db, TfwHttpResp *resp, TfwStr *hdr,
608606

609607
if (hdr) {
610608
hdr->chunks = dups;
611-
__TFW_STR_CHUNKN_SET(hdr, dn);
609+
hdr->nchunks = dn;
612610
hdr->flags |= TFW_STR_DUPLICATE;
613611
}
614612

@@ -835,7 +833,7 @@ tfw_cache_str_write_hdr(const TfwStr *str, char *p)
835833

836834
if (TFW_STR_DUP(str)) {
837835
s->flags = TFW_STR_DUPLICATE;
838-
s->len = TFW_STR_CHUNKN(str);
836+
s->len = str->nchunks;
839837
} else {
840838
s->flags = 0;
841839
s->len = str->len ? str->len + SLEN(S_CRLF) : 0;
@@ -1071,7 +1069,7 @@ __set_etag(TfwCacheEntry *ce, TfwHttpResp *resp, long h_off, TdbVRec *h_trec,
10711069

10721070
/* Compound string was allocated in resp->pool, move to cache entry. */
10731071
if (!TFW_STR_PLAIN(&ce->etag)) {
1074-
len = sizeof(TfwStr *) * TFW_STR_CHUNKN(&ce->etag);
1072+
len = sizeof(TfwStr *) * ce->etag.nchunks;
10751073
curr_p = tdb_entry_get_room(node_db(), curr_trec, curr_p, len,
10761074
len);
10771075
if (!curr_p)

tempesta_fw/hash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ tfw_hash_str(const TfwStr *str)
3939
}
4040
else {
4141
const TfwStr *c = str->chunks;
42-
const TfwStr *end = c + TFW_STR_CHUNKN(str);
42+
const TfwStr *end = c + str->nchunks;
4343
unsigned char *p, *e;
4444
unsigned int tail = 0;
4545

tempesta_fw/http.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ static TfwStr http_predef_resps[RESP_NUM] = {
130130
},
131131
.len = SLEN(S_200_PART_01 S_V_DATE S_200_PART_02 S_DEF_PART_03
132132
S_CRLF),
133-
.flags = 6 << TFW_STR_CN_SHIFT
133+
.nchunks = 6
134134
},
135135
/* Response has invalid syntax, client shouldn't repeat it. */
136136
[RESP_400] = {
@@ -144,7 +144,7 @@ static TfwStr http_predef_resps[RESP_NUM] = {
144144
},
145145
.len = SLEN(S_400_PART_01 S_V_DATE S_400_PART_02 S_DEF_PART_03
146146
S_CRLF),
147-
.flags = 6 << TFW_STR_CN_SHIFT
147+
.nchunks = 6
148148
},
149149
/* Response is syntactically valid, but refuse to authorize it. */
150150
[RESP_403] = {
@@ -158,7 +158,7 @@ static TfwStr http_predef_resps[RESP_NUM] = {
158158
},
159159
.len = SLEN(S_403_PART_01 S_V_DATE S_403_PART_02 S_DEF_PART_03
160160
S_CRLF),
161-
.flags = 6 << TFW_STR_CN_SHIFT
161+
.nchunks = 6
162162
},
163163
/* Can't find the requested resource. */
164164
[RESP_404] = {
@@ -172,7 +172,7 @@ static TfwStr http_predef_resps[RESP_NUM] = {
172172
},
173173
.len = SLEN(S_404_PART_01 S_V_DATE S_404_PART_02 S_DEF_PART_03
174174
S_CRLF),
175-
.flags = 6 << TFW_STR_CN_SHIFT
175+
.nchunks = 6
176176
},
177177
[RESP_412] = {
178178
.chunks = (TfwStr []){
@@ -185,7 +185,7 @@ static TfwStr http_predef_resps[RESP_NUM] = {
185185
},
186186
.len = SLEN(S_412_PART_01 S_V_DATE S_412_PART_02 S_DEF_PART_03
187187
S_CRLF),
188-
.flags = 6 << TFW_STR_CN_SHIFT
188+
.nchunks = 6
189189
},
190190
/* Internal error in TempestaFW. */
191191
[RESP_500] = {
@@ -199,7 +199,7 @@ static TfwStr http_predef_resps[RESP_NUM] = {
199199
},
200200
.len = SLEN(S_500_PART_01 S_V_DATE S_500_PART_02 S_DEF_PART_03
201201
S_CRLF),
202-
.flags = 6 << TFW_STR_CN_SHIFT
202+
.nchunks = 6
203203
},
204204
/* Error (syntax or network) while receiving request from backend. */
205205
[RESP_502] = {
@@ -213,7 +213,7 @@ static TfwStr http_predef_resps[RESP_NUM] = {
213213
},
214214
.len = SLEN(S_502_PART_01 S_V_DATE S_502_PART_02 S_DEF_PART_03
215215
S_CRLF),
216-
.flags = 6 << TFW_STR_CN_SHIFT
216+
.nchunks = 6
217217
},
218218
/*
219219
* Sticky cookie or JS challenge failed, refuse to serve the client.
@@ -231,7 +231,7 @@ static TfwStr http_predef_resps[RESP_NUM] = {
231231
},
232232
.len = SLEN(S_503_PART_01 S_V_DATE S_503_PART_02 S_DEF_PART_03
233233
S_CRLF),
234-
.flags = 6 << TFW_STR_CN_SHIFT
234+
.nchunks = 6
235235
},
236236
/* Can't get a response in time. */
237237
[RESP_504] = {
@@ -245,7 +245,7 @@ static TfwStr http_predef_resps[RESP_NUM] = {
245245
},
246246
.len = SLEN(S_504_PART_01 S_V_DATE S_504_PART_02 S_DEF_PART_03
247247
S_CRLF),
248-
.flags = 6 << TFW_STR_CN_SHIFT
248+
.nchunks = 6
249249
}
250250
};
251251

@@ -372,7 +372,7 @@ tfw_http_prep_redirect(TfwHttpMsg *resp, unsigned short status, TfwStr *rmark,
372372
{ .data = S_REDIR_GEN, .len = SLEN(S_REDIR_GEN) }
373373
},
374374
.len = SLEN(S_0 S_REDIR_GEN) + 3,
375-
.flags = 3 << TFW_STR_CN_SHIFT
375+
.nchunks = 3
376376
};
377377
TfwStr h_common_1 = {
378378
.chunks = (TfwStr []){
@@ -381,7 +381,7 @@ tfw_http_prep_redirect(TfwHttpMsg *resp, unsigned short status, TfwStr *rmark,
381381
{ .data = S_REDIR_P_02, .len = SLEN(S_REDIR_P_02) }
382382
},
383383
.len = SLEN(S_REDIR_P_01 S_V_DATE S_REDIR_P_02),
384-
.flags = 3 << TFW_STR_CN_SHIFT
384+
.nchunks = 3
385385
};
386386
static TfwStr h_common_2 = {
387387
.data = S_REDIR_P_03, .len = SLEN(S_REDIR_P_03) };
@@ -606,7 +606,7 @@ __tfw_http_send_resp(TfwHttpReq *req, resp_code_t code)
606606
TfwStr msg = {
607607
.chunks = (TfwStr []){ {}, {}, {}, {}, {}, {} },
608608
.len = 0,
609-
.flags = 6 << TFW_STR_CN_SHIFT
609+
.nchunks = 6
610610
};
611611

612612
if (tfw_strcpy_desc(&msg, &http_predef_resps[code]))
@@ -637,7 +637,7 @@ __tfw_http_send_resp(TfwHttpReq *req, resp_code_t code)
637637
date->data = *this_cpu_ptr(&g_buf);
638638
tfw_http_prep_date(date->data);
639639
if (!body->data)
640-
__TFW_STR_CHUNKN_SET(&msg, 5);
640+
msg.nchunks = 5;
641641

642642
if (tfw_msg_write(&it, &msg))
643643
goto err_setup;
@@ -2062,7 +2062,7 @@ tfw_http_add_hdr_via(TfwHttpMsg *hm)
20622062
},
20632063
.len = SLEN(S_VIA) + 4 + g_vhost->hdr_via_len,
20642064
.eolen = 2,
2065-
.flags = 3 << TFW_STR_CN_SHIFT
2065+
.nchunks = 3
20662066
#undef S_VIA
20672067
};
20682068

@@ -2141,12 +2141,12 @@ tfw_http_recreate_content_type_multipart_hdr(TfwHttpReq *req)
21412141
{
21422142
TfwStr replacement = {
21432143
.chunks = (TfwStr []) {
2144-
TFW_STR_FROM("Content-Type"),
2145-
TFW_STR_FROM(": "),
2146-
TFW_STR_FROM("multipart/form-data; boundary="),
2144+
TFW_STR_STRING("Content-Type"),
2145+
TFW_STR_STRING(": "),
2146+
TFW_STR_STRING("multipart/form-data; boundary="),
21472147
req->multipart_boundary_raw,
21482148
},
2149-
.flags = 4 << TFW_STR_CN_SHIFT,
2149+
.nchunks = 4,
21502150
};
21512151
TfwStr *c = replacement.chunks;
21522152

@@ -4003,7 +4003,7 @@ tfw_http_msg_body_dup(const char *filename, size_t *len)
40034003
{ .data = S_CRLFCRLF, .len = SLEN(S_CRLFCRLF) },
40044004
},
40054005
.len = SLEN(S_F_CONTENT_LENGTH S_CRLFCRLF),
4006-
.flags = 3 << TFW_STR_CN_SHIFT
4006+
.nchunks = 3
40074007
};
40084008
size_t b_off;
40094009

@@ -4028,7 +4028,7 @@ tfw_http_config_resp_body(int status_code, const char *filename)
40284028
{ .data = S_CRLF, .len = SLEN(S_CRLF) },
40294029
},
40304030
.len = SLEN(S_CRLF S_F_CONTENT_LENGTH S_CRLF),
4031-
.flags = 3 << TFW_STR_CN_SHIFT
4031+
.nchunks = 3
40324032
};
40334033

40344034
if (!(cl = __tfw_http_msg_body_dup(filename, &c_len_hdr, &sz, &b_off)))

tempesta_fw/http_match.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ tfw_http_verify_hdr_field(tfw_http_match_fld_t field, const char **hdr_name,
689689
},
690690
.len = h_len + SLEN(S_DLM),
691691
.eolen = 0,
692-
.flags = 2 << TFW_STR_CN_SHIFT
692+
.nchunks = 2
693693
};
694694

695695
*hid_out = tfw_http_msg_req_spec_hid(&tmp_hdr);

tempesta_fw/http_msg.c

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ tfw_http_msg_make_hdr(TfwPool *pool, const char *name, const char *val)
4949
},
5050
.len = n_len + SLEN(S_DLM) + v_len,
5151
.eolen = 2,
52-
.flags = (val ? 3 : 2) << TFW_STR_CN_SHIFT
52+
.nchunks = (val ? 3 : 2)
5353
};
5454

5555
return tfw_strdup(pool, &tmp_hdr);
@@ -216,7 +216,7 @@ __http_msg_hdr_val(TfwStr *hdr, unsigned id, TfwStr *val, bool client)
216216
* we get an empty string with val->len = 0 and val->data from the
217217
* last name's chunk, but it is unimportant.
218218
*/
219-
for (c = hdr->chunks, end = hdr->chunks + TFW_STR_CHUNKN(hdr);
219+
for (c = hdr->chunks, end = hdr->chunks + hdr->nchunks;
220220
c < end; ++c)
221221
{
222222
BUG_ON(!c->len);
@@ -240,8 +240,8 @@ __http_msg_hdr_val(TfwStr *hdr, unsigned id, TfwStr *val, bool client)
240240
val->chunks = c;
241241
return;
242242
}
243-
BUG_ON(TFW_STR_CHUNKN(val) < 1);
244-
TFW_STR_CHUNKN_SUB(val, 1);
243+
BUG_ON(val->nchunks < 1);
244+
val->nchunks--;
245245
}
246246

247247
/* Empty header value part. */
@@ -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);
@@ -686,7 +684,7 @@ tfw_http_msg_hdr_xfrm_str(TfwHttpMsg *hm, const TfwStr *hdr, unsigned int hid,
686684
{ .data = s_val->data, .len = s_val->len }
687685
},
688686
.len = s_val->len + 2,
689-
.flags = 2 << TFW_STR_CN_SHIFT
687+
.nchunks = 2
690688
};
691689
return __hdr_expand(hm, orig_hdr, &hdr_app, true);
692690
}
@@ -709,7 +707,7 @@ tfw_http_msg_hdr_xfrm(TfwHttpMsg *hm, char *name, size_t n_len,
709707
},
710708
.len = n_len + SLEN(S_DLM) + v_len,
711709
.eolen = 2,
712-
.flags = (val ? 3 : 2) << TFW_STR_CN_SHIFT
710+
.nchunks = (val ? 3 : 2)
713711
};
714712

715713
BUG_ON(!val && v_len);

0 commit comments

Comments
 (0)