Prettify verbose output

This commit is contained in:
Tatsuhiro Tsujikawa 2012-02-02 00:37:48 +09:00
parent 562278194c
commit db498a7601
1 changed files with 35 additions and 19 deletions

View File

@ -218,11 +218,19 @@ const char *ctrl_names[] = {
}; };
} // namespace } // namespace
namespace {
void print_frame_attr_indent()
{
printf(" ");
}
} // namespace
void print_nv(char **nv) void print_nv(char **nv)
{ {
int i; int i;
for(i = 0; nv[i]; i += 2) { for(i = 0; nv[i]; i += 2) {
printf(" %s: %s\n", nv[i], nv[i+1]); print_frame_attr_indent();
printf("%s: %s\n", nv[i], nv[i+1]);
} }
} }
@ -233,49 +241,57 @@ void print_timer()
printf("[%3ld.%03ld]", tv.tv_sec, tv.tv_usec/1000); printf("[%3ld.%03ld]", tv.tv_sec, tv.tv_usec/1000);
} }
namespace {
void print_ctrl_hd(const spdylay_ctrl_hd& hd)
{
printf("<version=%u, flags=%u, length=%d>\n",
hd.version, hd.flags, hd.length);
}
} // namespace
void print_frame(spdylay_frame_type type, spdylay_frame *frame) void print_frame(spdylay_frame_type type, spdylay_frame *frame)
{ {
printf("%s frame ", ctrl_names[type-1]); printf("%s frame ", ctrl_names[type-1]);
print_ctrl_hd(frame->syn_stream.hd);
switch(type) { switch(type) {
case SPDYLAY_SYN_STREAM: case SPDYLAY_SYN_STREAM:
printf("(stream_id=%d, assoc_stream_id=%d, flags=%u, length=%d, pri=%u)\n", print_frame_attr_indent();
printf("(stream_id=%d, assoc_stream_id=%d, pri=%u)\n",
frame->syn_stream.stream_id, frame->syn_stream.assoc_stream_id, frame->syn_stream.stream_id, frame->syn_stream.assoc_stream_id,
frame->syn_stream.hd.flags, frame->syn_stream.pri);
frame->syn_stream.hd.length, frame->syn_stream.pri);
print_nv(frame->syn_stream.nv); print_nv(frame->syn_stream.nv);
break; break;
case SPDYLAY_SYN_REPLY: case SPDYLAY_SYN_REPLY:
printf("(stream_id=%d, flags=%u, length=%d)\n", print_frame_attr_indent();
frame->syn_reply.stream_id, frame->syn_reply.hd.flags, printf("(stream_id=%d)\n", frame->syn_reply.stream_id);
frame->syn_reply.hd.length);
print_nv(frame->syn_reply.nv); print_nv(frame->syn_reply.nv);
break; break;
case SPDYLAY_RST_STREAM: case SPDYLAY_RST_STREAM:
printf("(stream_id=%d, status_code=%u, flags=%u, length=%d)\n", print_frame_attr_indent();
frame->rst_stream.stream_id, frame->rst_stream.status_code, printf("(stream_id=%d, status_code=%u)\n",
frame->rst_stream.hd.flags, frame->rst_stream.stream_id, frame->rst_stream.status_code);
frame->rst_stream.hd.length);
break; break;
case SPDYLAY_SETTINGS: case SPDYLAY_SETTINGS:
printf("(flags=%u, length=%d, niv=%lu)\n", print_frame_attr_indent();
frame->settings.hd.flags, frame->settings.hd.length, printf("(niv=%lu)\n", static_cast<unsigned long>(frame->settings.niv));
static_cast<unsigned long>(frame->settings.niv));
for(size_t i = 0; i < frame->settings.niv; ++i) { for(size_t i = 0; i < frame->settings.niv; ++i) {
printf(" [%d(%u):%u]\n", print_frame_attr_indent();
printf("[%d(%u):%u]\n",
frame->settings.iv[i].settings_id, frame->settings.iv[i].settings_id,
frame->settings.iv[i].flags, frame->settings.iv[i].value); frame->settings.iv[i].flags, frame->settings.iv[i].value);
} }
break; break;
case SPDYLAY_PING: case SPDYLAY_PING:
print_frame_attr_indent();
printf("(unique_id=%d)\n", frame->ping.unique_id); printf("(unique_id=%d)\n", frame->ping.unique_id);
break; break;
case SPDYLAY_GOAWAY: case SPDYLAY_GOAWAY:
print_frame_attr_indent();
printf("(last_good_stream_id=%d)\n", frame->goaway.last_good_stream_id); printf("(last_good_stream_id=%d)\n", frame->goaway.last_good_stream_id);
break; break;
case SPDYLAY_HEADERS: case SPDYLAY_HEADERS:
printf("(stream_id=%d, flags=%u, length=%d)\n", print_frame_attr_indent();
frame->headers.stream_id, frame->headers.hd.flags, printf("(stream_id=%d)\n", frame->headers.stream_id);
frame->headers.hd.length);
print_nv(frame->headers.nv); print_nv(frame->headers.nv);
break; break;
default: default:
@ -339,7 +355,7 @@ int select_next_proto_cb(SSL* ssl,
} }
for(unsigned int i = 0; i < inlen; i += in[i]+1) { for(unsigned int i = 0; i < inlen; i += in[i]+1) {
if(ssl_debug) { if(ssl_debug) {
std::cout << " * "; std::cout << " * ";
std::cout.write(reinterpret_cast<const char*>(&in[i+1]), in[i]); std::cout.write(reinterpret_cast<const char*>(&in[i+1]), in[i]);
std::cout << std::endl; std::cout << std::endl;
} }