2013-10-26 18:04:42 +02:00
|
|
|
/*
|
2014-03-30 12:09:21 +02:00
|
|
|
* nghttp2 - HTTP/2 C Library
|
2013-10-26 18:04:42 +02:00
|
|
|
*
|
|
|
|
* Copyright (c) 2013 Tatsuhiro Tsujikawa
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
#include "comp_helper.h"
|
2014-01-11 07:31:36 +01:00
|
|
|
#include <string.h>
|
2013-10-26 18:04:42 +02:00
|
|
|
|
2013-11-07 17:35:15 +01:00
|
|
|
static void dump_val(json_t *jent, const char *key, uint8_t *val, size_t len)
|
2013-10-26 18:04:42 +02:00
|
|
|
{
|
2014-02-13 15:22:52 +01:00
|
|
|
json_object_set_new(jent, key, json_pack("s#", val, len));
|
2013-10-26 18:04:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
json_t* dump_header_table(nghttp2_hd_context *context)
|
|
|
|
{
|
|
|
|
json_t *obj, *entries;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
obj = json_object();
|
|
|
|
entries = json_array();
|
|
|
|
for(i = 0; i < context->hd_table.len; ++i) {
|
|
|
|
nghttp2_hd_entry *ent = nghttp2_hd_table_get(context, i);
|
|
|
|
json_t *outent = json_object();
|
2013-11-16 08:18:44 +01:00
|
|
|
json_object_set_new(outent, "index", json_integer(i + 1));
|
2013-10-26 18:04:42 +02:00
|
|
|
dump_val(outent, "name", ent->nv.name, ent->nv.namelen);
|
|
|
|
dump_val(outent, "value", ent->nv.value, ent->nv.valuelen);
|
|
|
|
json_object_set_new(outent, "size",
|
|
|
|
json_integer(ent->nv.namelen + ent->nv.valuelen +
|
|
|
|
NGHTTP2_HD_ENTRY_OVERHEAD));
|
|
|
|
json_array_append_new(entries, outent);
|
|
|
|
}
|
|
|
|
json_object_set_new(obj, "entries", entries);
|
|
|
|
json_object_set_new(obj, "size", json_integer(context->hd_table_bufsize));
|
2014-01-11 07:31:36 +01:00
|
|
|
json_object_set_new(obj, "max_size",
|
2013-10-26 18:04:42 +02:00
|
|
|
json_integer(context->hd_table_bufsize_max));
|
|
|
|
return obj;
|
|
|
|
}
|
2014-01-11 07:31:36 +01:00
|
|
|
|
2014-01-16 15:41:13 +01:00
|
|
|
json_t* dump_header(const uint8_t *name, size_t namelen,
|
|
|
|
const uint8_t *value, size_t valuelen)
|
|
|
|
{
|
|
|
|
json_t *nv_pair = json_object();
|
|
|
|
char *cname = malloc(namelen + 1);
|
|
|
|
memcpy(cname, name, namelen);
|
|
|
|
cname[namelen] = '\0';
|
|
|
|
json_object_set_new(nv_pair, cname, json_pack("s#", value, valuelen));
|
|
|
|
free(cname);
|
|
|
|
return nv_pair;
|
|
|
|
}
|
|
|
|
|
2014-01-11 07:31:36 +01:00
|
|
|
json_t* dump_headers(const nghttp2_nv *nva, size_t nvlen)
|
|
|
|
{
|
|
|
|
json_t *headers;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
headers = json_array();
|
|
|
|
for(i = 0; i < nvlen; ++i) {
|
2014-01-16 15:41:13 +01:00
|
|
|
json_array_append_new(headers,
|
|
|
|
dump_header(nva[i].name, nva[i].namelen,
|
|
|
|
nva[i].value, nva[i].valuelen));
|
2014-01-11 07:31:36 +01:00
|
|
|
}
|
|
|
|
return headers;
|
|
|
|
}
|
|
|
|
|
2014-02-13 15:22:52 +01:00
|
|
|
void output_json_header(void)
|
2014-01-11 07:31:36 +01:00
|
|
|
{
|
|
|
|
printf("{\n"
|
|
|
|
" \"cases\":\n"
|
2014-02-13 15:22:52 +01:00
|
|
|
" [\n");
|
2014-01-11 07:31:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void output_json_footer(void)
|
|
|
|
{
|
|
|
|
printf(" ]\n"
|
|
|
|
"}\n");
|
|
|
|
}
|