]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon/http: use struct for http stream
authorTomas Krizek <tomas.krizek@nic.cz>
Mon, 5 Apr 2021 15:12:40 +0000 (17:12 +0200)
committerTomas Krizek <tomas.krizek@nic.cz>
Mon, 24 May 2021 12:20:09 +0000 (14:20 +0200)
daemon/http.c
daemon/http.h
daemon/worker.c

index 14e60babde02a23eefcaa5ac25db270ab2288bd1..ae2c7a33b9e399d7629e941fc78de1144b3cc832 100644 (file)
@@ -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.
index f0662779b8d171e3b60a7aec389790ec8b603111..ebcd5045c51d6ec1ee5cc1bca9890e91f71ade7a 100644 (file)
@@ -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;
index 6710fa66988cf47196d219cf5c98b60d16f06740..ce511d3b48e99deccbaa0275fccfeb42366a4ecc 100644 (file)
@@ -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. */