From 297fbb45fee4f1519421e6416745fdf3c3ec7ea1 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Mon, 13 May 2019 14:41:27 +0200 Subject: [PATCH] MINOR: htx: Replace the function http_find_stline() by http_get_stline() Now, we only return the start-line. If not found, NULL is returned. No lookup is performed and the HTX message is no more updated. It is now the caller responsibility to update the position of the start-line to the right value. So when it is not found, i.e sl_pos is set to -1, it means the last start-line has been already processed and the next one has not been inserted yet. It is mandatory to rely on this kind of warranty to store 1xx informational responses and final reponse in the same HTX message. --- include/proto/http_htx.h | 2 +- src/backend.c | 4 ++-- src/cache.c | 2 +- src/flt_trace.c | 2 +- src/hlua.c | 2 +- src/http_fetch.c | 28 +++++++++++------------ src/http_htx.c | 48 ++++++++++++++-------------------------- src/proto_htx.c | 24 ++++++++++---------- src/stats.c | 2 +- src/stream_interface.c | 2 +- 10 files changed, 51 insertions(+), 65 deletions(-) diff --git a/include/proto/http_htx.h b/include/proto/http_htx.h index 6028292d2..a13405223 100644 --- a/include/proto/http_htx.h +++ b/include/proto/http_htx.h @@ -30,7 +30,7 @@ extern struct buffer htx_err_chunks[HTTP_ERR_SIZE]; -struct htx_sl *http_find_stline(struct htx *htx); +struct htx_sl *http_get_stline(struct htx *htx); int http_find_header(const struct htx *htx, const struct ist name, struct http_hdr_ctx *ctx, int full); int http_add_header(struct htx *htx, const struct ist n, const struct ist v); int http_replace_stline(struct htx *htx, const struct ist p1, const struct ist p2, const struct ist p3); diff --git a/src/backend.c b/src/backend.c index 4dff185ec..fc0066665 100644 --- a/src/backend.c +++ b/src/backend.c @@ -743,7 +743,7 @@ int assign_server(struct stream *s) else { struct ist uri; - uri = htx_sl_req_uri(http_find_stline(htxbuf(&s->req.buf))); + uri = htx_sl_req_uri(http_get_stline(htxbuf(&s->req.buf))); srv = get_server_uh(s->be, uri.ptr, uri.len, prev_srv); } break; @@ -760,7 +760,7 @@ int assign_server(struct stream *s) else { struct ist uri; - uri = htx_sl_req_uri(http_find_stline(htxbuf(&s->req.buf))); + uri = htx_sl_req_uri(http_get_stline(htxbuf(&s->req.buf))); srv = get_server_ph(s->be, uri.ptr, uri.len, prev_srv); } diff --git a/src/cache.c b/src/cache.c index 7402e5efd..188efea17 100644 --- a/src/cache.c +++ b/src/cache.c @@ -1351,7 +1351,7 @@ int sha1_hosturi(struct stream *s) return 0; chunk_memcat(trash, ctx.value.ptr, ctx.value.len); - sl = http_find_stline(htx); + sl = http_get_stline(htx); path = http_get_path(htx_sl_req_uri(sl)); if (!path.ptr) return 0; diff --git a/src/flt_trace.c b/src/flt_trace.c index 3cfd842ce..ed159e8a7 100644 --- a/src/flt_trace.c +++ b/src/flt_trace.c @@ -414,7 +414,7 @@ trace_http_headers(struct stream *s, struct filter *filter, if (IS_HTX_STRM(s)) { struct htx *htx = htxbuf(&msg->chn->buf); - struct htx_sl *sl = http_find_stline(htx); + struct htx_sl *sl = http_get_stline(htx); int32_t pos; STRM_TRACE(conf, s, "\t%.*s %.*s %.*s", diff --git a/src/hlua.c b/src/hlua.c index f8e481c27..72ce6bab6 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -3944,7 +3944,7 @@ static int hlua_applet_http_new(lua_State *L, struct appctx *ctx) if (IS_HTX_STRM(s)) { /* HTX version */ struct htx *htx = htxbuf(&s->req.buf); - struct htx_sl *sl = http_find_stline(htx); + struct htx_sl *sl = http_get_stline(htx); struct ist path; unsigned long long len = 0; int32_t pos; diff --git a/src/http_fetch.c b/src/http_fetch.c index e16d7bf4c..0a5a2f91f 100644 --- a/src/http_fetch.c +++ b/src/http_fetch.c @@ -209,7 +209,7 @@ struct htx *smp_prefetch_htx(struct sample *smp, struct channel *chn, int vol) return NULL; } } - sl = http_find_stline(htx); + sl = http_get_stline(htx); if (vol && !sl) { /* The start-line was already forwarded, it is too late to fetch anything */ return NULL; @@ -434,7 +434,7 @@ static int smp_fetch_meth(const struct arg *args, struct sample *smp, const char /* ensure the indexes are not affected */ return 0; } - sl = http_find_stline(htx); + sl = http_get_stline(htx); smp->flags |= SMP_F_CONST; smp->data.u.meth.str.area = HTX_SL_REQ_MPTR(sl); smp->data.u.meth.str.data = HTX_SL_REQ_MLEN(sl); @@ -478,7 +478,7 @@ static int smp_fetch_rqver(const struct arg *args, struct sample *smp, const cha if (!htx) return 0; - sl = http_find_stline(htx); + sl = http_get_stline(htx); len = HTX_SL_REQ_VLEN(sl); ptr = HTX_SL_REQ_VPTR(sl); } @@ -518,7 +518,7 @@ static int smp_fetch_stver(const struct arg *args, struct sample *smp, const cha if (!htx) return 0; - sl = http_find_stline(htx); + sl = http_get_stline(htx); len = HTX_SL_RES_VLEN(sl); ptr = HTX_SL_RES_VPTR(sl); } @@ -559,7 +559,7 @@ static int smp_fetch_stcode(const struct arg *args, struct sample *smp, const ch if (!htx) return 0; - sl = http_find_stline(htx); + sl = http_get_stline(htx); len = HTX_SL_RES_CLEN(sl); ptr = HTX_SL_RES_CPTR(sl); } @@ -1009,7 +1009,7 @@ static int smp_fetch_url(const struct arg *args, struct sample *smp, const char if (!htx) return 0; - sl = http_find_stline(htx); + sl = http_get_stline(htx); smp->data.type = SMP_T_STR; smp->data.u.str.area = HTX_SL_REQ_UPTR(sl); smp->data.u.str.data = HTX_SL_REQ_ULEN(sl); @@ -1041,7 +1041,7 @@ static int smp_fetch_url_ip(const struct arg *args, struct sample *smp, const ch if (!htx) return 0; - sl = http_find_stline(htx); + sl = http_get_stline(htx); url2sa(HTX_SL_REQ_UPTR(sl), HTX_SL_REQ_ULEN(sl), &addr, NULL); } else { @@ -1074,7 +1074,7 @@ static int smp_fetch_url_port(const struct arg *args, struct sample *smp, const if (!htx) return 0; - sl = http_find_stline(htx); + sl = http_get_stline(htx); url2sa(HTX_SL_REQ_UPTR(sl), HTX_SL_REQ_ULEN(sl), &addr, NULL); } else { @@ -1573,7 +1573,7 @@ static int smp_fetch_path(const struct arg *args, struct sample *smp, const char if (!htx) return 0; - sl = http_find_stline(htx); + sl = http_get_stline(htx); path = http_get_path(htx_sl_req_uri(sl)); if (!path.ptr) return 0; @@ -1643,7 +1643,7 @@ static int smp_fetch_base(const struct arg *args, struct sample *smp, const char chunk_memcat(temp, ctx.value.ptr, ctx.value.len); /* now retrieve the path */ - sl = http_find_stline(htx); + sl = http_get_stline(htx); path = http_get_path(htx_sl_req_uri(sl)); if (path.ptr) { size_t len; @@ -1728,7 +1728,7 @@ static int smp_fetch_base32(const struct arg *args, struct sample *smp, const ch } /* now retrieve the path */ - sl = http_find_stline(htx); + sl = http_get_stline(htx); path = http_get_path(htx_sl_req_uri(sl)); if (path.ptr) { size_t len; @@ -1844,7 +1844,7 @@ static int smp_fetch_query(const struct arg *args, struct sample *smp, const cha if (!htx) return 0; - sl = http_find_stline(htx); + sl = http_get_stline(htx); ptr = HTX_SL_REQ_UPTR(sl); end = HTX_SL_REQ_UPTR(sl) + HTX_SL_REQ_ULEN(sl); } @@ -2523,7 +2523,7 @@ static int smp_fetch_url_param(const struct arg *args, struct sample *smp, const if (!htx) return 0; - sl = http_find_stline(htx); + sl = http_get_stline(htx); smp->ctx.a[0] = http_find_param_list(HTX_SL_REQ_UPTR(sl), HTX_SL_REQ_ULEN(sl), delim); if (!smp->ctx.a[0]) return 0; @@ -2701,7 +2701,7 @@ static int smp_fetch_url32(const struct arg *args, struct sample *smp, const cha } /* now retrieve the path */ - sl = http_find_stline(htx); + sl = http_get_stline(htx); path = http_get_path(htx_sl_req_uri(sl)); while (path.len > 0 && *(path.ptr) != '?') { path.ptr++; diff --git a/src/http_htx.c b/src/http_htx.c index e6332f7da..e55420c40 100644 --- a/src/http_htx.c +++ b/src/http_htx.c @@ -20,35 +20,21 @@ struct buffer htx_err_chunks[HTTP_ERR_SIZE]; -/* Finds the start line in the HTX message stopping at the first - * end-of-message. It returns NULL when not found, otherwise, it returns the - * pointer on the htx_sl structure. The HTX message may be updated if the - * start-line is returned following a lookup. +/* Returns the next unporocessed start line in the HTX message. It returns NULL + * is the start-line is undefined (sl_pos == 1). Otherwise, it returns the + * pointer on the htx_sl structure. */ -struct htx_sl *http_find_stline(struct htx *htx) +struct htx_sl *http_get_stline(struct htx *htx) { - struct htx_sl *sl = NULL; - int32_t pos; + struct htx_blk *blk; - sl = htx_get_stline(htx); - if (sl) - return sl; + if (htx->sl_pos == -1) + return NULL; - for (pos = htx_get_head(htx); pos != -1; pos = htx_get_next(htx, pos)) { - struct htx_blk *blk = htx_get_blk(htx, pos); - enum htx_blk_type type = htx_get_blk_type(blk); - - if (type == HTX_BLK_REQ_SL || type == HTX_BLK_RES_SL) { - sl = htx_get_blk_ptr(htx, blk); - htx->sl_pos = pos; - break; - } - - if (type == HTX_BLK_EOH || type == HTX_BLK_EOM) - break; - } - - return sl; + blk = htx_get_blk(htx, htx->sl_pos); + if (!blk) + return NULL; + return htx_get_blk_ptr(htx, blk); } /* Finds the first or next occurrence of header in the HTX message @@ -213,7 +199,7 @@ int http_replace_stline(struct htx *htx, const struct ist p1, const struct ist p int http_replace_req_meth(struct htx *htx, const struct ist meth) { struct buffer *temp = get_trash_chunk(); - struct htx_sl *sl = http_find_stline(htx); + struct htx_sl *sl = http_get_stline(htx); struct ist uri, vsn; if (!sl) @@ -237,7 +223,7 @@ int http_replace_req_meth(struct htx *htx, const struct ist meth) int http_replace_req_uri(struct htx *htx, const struct ist uri) { struct buffer *temp = get_trash_chunk(); - struct htx_sl *sl = http_find_stline(htx); + struct htx_sl *sl = http_get_stline(htx); struct ist meth, vsn; if (!sl) @@ -260,7 +246,7 @@ int http_replace_req_uri(struct htx *htx, const struct ist uri) int http_replace_req_path(struct htx *htx, const struct ist path) { struct buffer *temp = get_trash_chunk(); - struct htx_sl *sl = http_find_stline(htx); + struct htx_sl *sl = http_get_stline(htx); struct ist meth, uri, vsn, p; size_t plen = 0; @@ -297,7 +283,7 @@ int http_replace_req_path(struct htx *htx, const struct ist path) int http_replace_req_query(struct htx *htx, const struct ist query) { struct buffer *temp = get_trash_chunk(); - struct htx_sl *sl = http_find_stline(htx); + struct htx_sl *sl = http_get_stline(htx); struct ist meth, uri, vsn, q; int offset = 1; @@ -342,7 +328,7 @@ int http_replace_req_query(struct htx *htx, const struct ist query) int http_replace_res_status(struct htx *htx, const struct ist status) { struct buffer *temp = get_trash_chunk(); - struct htx_sl *sl = http_find_stline(htx); + struct htx_sl *sl = http_get_stline(htx); struct ist vsn, reason; if (!sl) @@ -366,7 +352,7 @@ int http_replace_res_status(struct htx *htx, const struct ist status) int http_replace_res_reason(struct htx *htx, const struct ist reason) { struct buffer *temp = get_trash_chunk(); - struct htx_sl *sl = http_find_stline(htx); + struct htx_sl *sl = http_get_stline(htx); struct ist vsn, status; if (!sl) diff --git a/src/proto_htx.c b/src/proto_htx.c index 8838fd77c..35039fc53 100644 --- a/src/proto_htx.c +++ b/src/proto_htx.c @@ -291,7 +291,7 @@ int htx_wait_for_request(struct stream *s, struct channel *req, int an_bit) txn->flags &= ~TX_WAIT_NEXT_RQ; req->analyse_exp = TICK_ETERNITY; - sl = http_find_stline(htx); + sl = http_get_stline(htx); /* 0: we might have to print this header in debug mode */ if (unlikely((global.mode & MODE_DEBUG) && @@ -801,7 +801,7 @@ int htx_process_request(struct stream *s, struct channel *req, int an_bit) return 0; } - sl = http_find_stline(htx); + sl = http_get_stline(htx); uri = htx_sl_req_uri(sl); path = http_get_path(uri); if (url2sa(uri.ptr, uri.len - path.len, &conn->addr.to, NULL) == -1) @@ -1646,7 +1646,7 @@ int htx_wait_for_response(struct stream *s, struct channel *rep, int an_bit) */ msg->msg_state = HTTP_MSG_BODY; - sl = http_find_stline(htx); + sl = http_get_stline(htx); /* 0: we might have to print this header in debug mode */ if (unlikely((global.mode & MODE_DEBUG) && @@ -2414,7 +2414,7 @@ int htx_apply_redirect_rule(struct redirect_rule *rule, struct stream *s, struct if (http_find_header(htx, ist("Host"), &ctx, 0)) host = ctx.value; - sl = http_find_stline(htx); + sl = http_get_stline(htx); path = http_get_path(htx_sl_req_uri(sl)); /* build message using path */ if (path.ptr) { @@ -2462,7 +2462,7 @@ int htx_apply_redirect_rule(struct redirect_rule *rule, struct stream *s, struct case REDIRECT_TYPE_PREFIX: { struct ist path; - sl = http_find_stline(htx); + sl = http_get_stline(htx); path = http_get_path(htx_sl_req_uri(sl)); /* build message using path */ if (path.ptr) { @@ -3639,11 +3639,11 @@ static int htx_apply_filter_to_req_line(struct stream *s, struct channel *req, s done = 0; - reqline->data = htx_fmt_req_line(http_find_stline(htx), reqline->area, reqline->size); + reqline->data = htx_fmt_req_line(http_get_stline(htx), reqline->area, reqline->size); /* Now we have the request line between cur_ptr and cur_end */ if (regex_exec_match2(exp->preg, reqline->area, reqline->data, MAX_MATCH, pmatch, 0)) { - struct htx_sl *sl = http_find_stline(htx); + struct htx_sl *sl = http_get_stline(htx); struct ist meth, uri, vsn; int len; @@ -3850,11 +3850,11 @@ static int htx_apply_filter_to_sts_line(struct stream *s, struct channel *res, s return 0; done = 0; - resline->data = htx_fmt_res_line(http_find_stline(htx), resline->area, resline->size); + resline->data = htx_fmt_res_line(http_get_stline(htx), resline->area, resline->size); /* Now we have the status line between cur_ptr and cur_end */ if (regex_exec_match2(exp->preg, resline->area, resline->data, MAX_MATCH, pmatch, 0)) { - struct htx_sl *sl = http_find_stline(htx); + struct htx_sl *sl = http_get_stline(htx); struct ist vsn, code, reason; int len; @@ -4847,7 +4847,7 @@ static int htx_stats_check_uri(struct stream *s, struct http_txn *txn, struct pr return 0; htx = htxbuf(&s->req.buf); - sl = http_find_stline(htx); + sl = http_get_stline(htx); uri = htx_sl_req_uri(sl); /* check URI size */ @@ -4890,7 +4890,7 @@ static int htx_handle_stats(struct stream *s, struct channel *req) appctx->ctx.stats.flags |= STAT_CHUNKED; htx = htxbuf(&req->buf); - sl = http_find_stline(htx); + sl = http_get_stline(htx); lookup = HTX_SL_REQ_UPTR(sl) + uri_auth->uri_len; end = HTX_SL_REQ_UPTR(sl) + HTX_SL_REQ_ULEN(sl); @@ -5043,7 +5043,7 @@ void htx_perform_server_redirect(struct stream *s, struct stream_interface *si) /* 2: add the request Path */ htx = htxbuf(&req->buf); - sl = http_find_stline(htx); + sl = http_get_stline(htx); path = http_get_path(htx_sl_req_uri(sl)); if (!path.ptr) return; diff --git a/src/stats.c b/src/stats.c index de7f85667..7d9a8a3a7 100644 --- a/src/stats.c +++ b/src/stats.c @@ -277,7 +277,7 @@ static const char *stats_scope_ptr(struct appctx *appctx, struct stream_interfac if (IS_HTX_STRM(si_strm(si))) { struct channel *req = si_oc(si); struct htx *htx = htxbuf(&req->buf); - struct ist uri = htx_sl_req_uri(http_find_stline(htx)); + struct ist uri = htx_sl_req_uri(http_get_stline(htx)); p = uri.ptr; } diff --git a/src/stream_interface.c b/src/stream_interface.c index 071a76536..b12d50bc3 100644 --- a/src/stream_interface.c +++ b/src/stream_interface.c @@ -1305,7 +1305,7 @@ int si_cs_recv(struct conn_stream *cs) htx = htxbuf(&ic->buf); if (htx) { - sl = http_find_stline(htx); + sl = http_get_stline(htx); if (sl && l7_status_match(si_strm(si)->be, sl->info.res.status)) { /* If we got a status for which we would