]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: qpack: add comments and remove a useless trace
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Tue, 14 Jun 2022 15:34:53 +0000 (17:34 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 15 Jun 2022 09:20:42 +0000 (11:20 +0200)
Add comments on the decoding function to facilitate code analysis.

Also remove the qpack_debug_hexdump() which prints the whole left buffer
on each header parsing. With large HEADERS frame payload, QPACK traces
are complicated to debug with this statement.

include/haproxy/qpack-dec.h
src/qpack-dec.c

index b847c802747b189998ab89cb11736a3d202fef36..991e1a9f7a513674766e5fb4b40a75f3f08555c4 100644 (file)
@@ -29,11 +29,11 @@ struct http_hdr;
  *Nothing to see with the RFC.
  */
 enum {
-       QPACK_ERR_NONE = 0,
-       QPACK_ERR_RIC,
-       QPACK_ERR_DB,
-       QPACK_ERR_TRUNCATED,
-       QPACK_ERR_HUFFMAN,
+       QPACK_ERR_NONE = 0,  /* no error */
+       QPACK_ERR_RIC,       /* cannot decode Required Insert Count prefix field */
+       QPACK_ERR_DB,        /* cannot decode Delta Base prefix field */
+       QPACK_ERR_TRUNCATED, /* truncated stream */
+       QPACK_ERR_HUFFMAN,   /* huffman decoding error */
 };
 
 struct qpack_dec {
index 3ca2eda650ea057d25b5528d23d0c8696be500b0..82ffd81e0524bd598a958656fd386477325dd23a 100644 (file)
@@ -181,8 +181,13 @@ static int qpack_decode_fs_pfx(uint64_t *enc_ric, uint64_t *db, int *sign_bit,
        return 0;
 }
 
-/* Decode a field section from <len> bytes length <raw> buffer.
- * Produces the output into <tmp> buffer.
+/* Decode a field section from the <raw> buffer of <len> bytes. Each parsed
+ * header is inserted into <list> and uses <tmp> as a storage for some elements
+ * pointing into it. An end marker is inserted at the end of the list with
+ * empty strings as name/value.
+ *
+ * Returns 0 on success. In case of error, a negative code QPACK_ERR_* is
+ * returned.
  */
 int qpack_decode_fs(const unsigned char *raw, size_t len, struct buffer *tmp,
                     struct http_hdr *list)
@@ -195,6 +200,7 @@ int qpack_decode_fs(const unsigned char *raw, size_t len, struct buffer *tmp,
 
        qpack_debug_hexdump(stderr, "[QPACK-DEC-FS] ", (const char *)raw, 0, len);
 
+       /* parse field section prefix */
        ret = qpack_decode_fs_pfx(&enc_ric, &db, &s, &raw, &len);
        if (ret < 0) {
                qpack_debug_printf(stderr, "##ERR@%d(%d)\n", __LINE__, ret);
@@ -206,9 +212,10 @@ int qpack_decode_fs(const unsigned char *raw, size_t len, struct buffer *tmp,
                           (unsigned long long)enc_ric, (unsigned long long)db, !!s);
        /* Decode field lines */
        while (len) {
-               qpack_debug_hexdump(stderr, "raw ", (const char *)raw, 0, len);
+               /* parse field line representation */
                efl_type = *raw & QPACK_EFL_BITMASK;
                qpack_debug_printf(stderr, "efl_type=0x%02x\n", efl_type);
+
                if (efl_type == QPACK_LFL_WPBNM) {
                        /* Literal field line with post-base name reference */
                        uint64_t index __maybe_unused, length;