From: Tomas Krizek Date: Mon, 5 Apr 2021 15:12:40 +0000 (+0200) Subject: daemon/http: use struct for http stream X-Git-Tag: v5.4.0~19^2~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2829f3261f1dd28787657afc24d9aa4286a8aa06;p=thirdparty%2Fknot-resolver.git daemon/http: use struct for http stream --- diff --git a/daemon/http.c b/daemon/http.c index 14e60babd..ae2c7a33b 100644 --- a/daemon/http.c +++ b/daemon/http.c @@ -234,7 +234,11 @@ static int process_uri_path(struct http_ctx *ctx, const char* path, int32_t stre } ctx->buf_pos += ret; - queue_push(ctx->streams, stream_id); + + struct http_stream stream = { + .id = stream_id + }; + queue_push(ctx->streams, stream); return 0; } @@ -345,7 +349,7 @@ static int data_chunk_recv_callback(nghttp2_session *h2, uint8_t flags, int32_t struct http_ctx *ctx = (struct http_ctx *)user_data; ssize_t remaining; ssize_t required; - bool is_first = queue_len(ctx->streams) == 0 || queue_tail(ctx->streams) != ctx->incomplete_stream; + bool is_first = queue_len(ctx->streams) == 0 || queue_tail(ctx->streams).id != ctx->incomplete_stream; if (ctx->incomplete_stream != stream_id) { kr_log_verbose( @@ -370,7 +374,10 @@ static int data_chunk_recv_callback(nghttp2_session *h2, uint8_t flags, int32_t if (is_first) { ctx->buf_pos = sizeof(uint16_t); /* Reserve 2B for dnsmsg len. */ - queue_push(ctx->streams, stream_id); + struct http_stream stream = { + .id = stream_id + }; + queue_push(ctx->streams, stream); } memmove(ctx->buf + ctx->buf_pos, data, len); @@ -429,7 +436,7 @@ static void on_pkt_write(struct http_data *data, int status) } /* - * Cleanup for closed steams. + * Cleanup for closed streams. * * If any stream_user_data was set, call the on_write callback to allow * freeing of the underlying data structure. diff --git a/daemon/http.h b/daemon/http.h index f0662779b..ebcd5045c 100644 --- a/daemon/http.h +++ b/daemon/http.h @@ -24,7 +24,12 @@ typedef ssize_t(*http_send_callback)(const uint8_t *buffer, const size_t buffer_len, struct session *session); -typedef queue_t(int32_t) queue_int32_t; +struct http_stream { + int32_t id; + trie_t *headers; +}; + +typedef queue_t(struct http_stream) queue_http_stream; typedef enum { HTTP_METHOD_NONE = 0, @@ -36,7 +41,7 @@ struct http_ctx { struct nghttp2_session *h2; http_send_callback send_cb; struct session *session; - queue_int32_t streams; /* IDs of streams present in the buffer. */ + queue_http_stream streams; /* Streams present in the wire buffer. */ int32_t incomplete_stream; ssize_t submitted; http_method_t current_method; diff --git a/daemon/worker.c b/daemon/worker.c index 6710fa669..ce511d3b4 100644 --- a/daemon/worker.c +++ b/daemon/worker.c @@ -386,7 +386,7 @@ static struct request_ctx *request_create(struct worker_ctx *worker, #if ENABLE_DOH2 if (req->qsource.flags.http) { struct http_ctx *http_ctx = session_http_get_server_ctx(session); - req->qsource.stream_id = queue_head(http_ctx->streams); + req->qsource.stream_id = queue_head(http_ctx->streams).id; } #endif /* We need to store a copy of peer address. */