lsquic_qpack_exp.c revision 758aff32
1/* Copyright (c) 2017 - 2020 LiteSpeed Technologies Inc.  See LICENSE. */
2#include <inttypes.h>
3#include <stdio.h>
4#include <stdlib.h>
5
6#include "lsquic_int_types.h"
7#include "lsquic_qpack_exp.h"
8
9
10struct qpack_exp_record *
11lsquic_qpack_exp_new (void)
12{
13    return calloc(1, sizeof(struct qpack_exp_record));
14}
15
16
17void
18lsquic_qpack_exp_destroy (struct qpack_exp_record *exp)
19{
20    free(exp->qer_user_agent);
21    free(exp);
22}
23
24
25static const char *const flag2tag[] = {
26    [QER_SERVER|QER_ENCODER]    = "server",
27    [QER_SERVER|0]              = "user-agent",
28    [0         |QER_ENCODER]    = "user-agent",
29    [0         |0]              = "server",
30};
31
32
33int
34lsquic_qpack_exp_to_xml (const struct qpack_exp_record *exp, char *buf,
35                                                                size_t buf_sz)
36{
37    const char *const tag = flag2tag[exp->qer_flags & (QER_SERVER|QER_ENCODER)];
38
39    return snprintf(buf, buf_sz,
40        "<qpack-exp>"
41            "<role>%s</role>"
42            "<duration units=\"ms\">%"PRIu64"</duration>"
43            "<hblock-count>%u</hblock-count>"
44            "<hblock-size>%u</hblock-size>"
45            "<peer-max-size>%u</peer-max-size>"
46            "<used-max-size>%u</used-max-size>"
47            "<peer-max-blocked>%u</peer-max-blocked>"
48            "<used-max-blocked>%u</used-max-blocked>"
49            "<comp-ratio>%.3f</comp-ratio>"
50            /* We just print unescaped string... */
51            "<%s>%s</%s>"
52        "</qpack-exp>"
53        ,   exp->qer_flags & QER_ENCODER ? "encoder" : "decoder"
54        ,   (exp->qer_last_req - exp->qer_first_req) / 1000 /* Milliseconds */
55        ,   exp->qer_hblock_count
56        ,   exp->qer_hblock_size
57        ,   exp->qer_peer_max_size
58        ,   exp->qer_used_max_size
59        ,   exp->qer_peer_max_blocked
60        ,   exp->qer_used_max_blocked
61        ,   exp->qer_comp_ratio
62        ,   tag
63        ,   exp->qer_user_agent ? exp->qer_user_agent : ""
64        ,   tag
65        );
66}
67