Split swanctl --raw mode into single-line and --pretty mode

This commit is contained in:
Andreas Steffen
2014-06-14 15:40:22 +02:00
parent 12d618e280
commit dacb75f5c0
18 changed files with 310 additions and 185 deletions
+14 -10
View File
@@ -17,13 +17,12 @@
#include <errno.h>
CALLBACK(log_cb, void,
bool *raw, char *name, vici_res_t *msg)
command_format_options_t *format, char *name, vici_res_t *msg)
{
if (*raw)
if (*format & COMMAND_FORMAT_RAW)
{
vici_dump(msg, "log", stdout);
vici_dump(msg, "log", *format & COMMAND_FORMAT_PRETTY, stdout);
}
else
{
@@ -37,7 +36,7 @@ static int initiate(vici_conn_t *conn)
{
vici_req_t *req;
vici_res_t *res;
bool raw = FALSE;
command_format_options_t format = COMMAND_FORMAT_NONE;
char *arg, *child = NULL;
int ret = 0, timeout = 0, level = 1;
@@ -47,8 +46,11 @@ static int initiate(vici_conn_t *conn)
{
case 'h':
return command_usage(NULL);
case 'P':
format |= COMMAND_FORMAT_PRETTY;
/* fall through to raw */
case 'r':
raw = TRUE;
format |= COMMAND_FORMAT_RAW;
continue;
case 'c':
child = arg;
@@ -67,7 +69,7 @@ static int initiate(vici_conn_t *conn)
break;
}
if (vici_register(conn, "control-log", log_cb, &raw) != 0)
if (vici_register(conn, "control-log", log_cb, &format) != 0)
{
fprintf(stderr, "registering for log failed: %s\n", strerror(errno));
return errno;
@@ -88,9 +90,10 @@ static int initiate(vici_conn_t *conn)
fprintf(stderr, "initiate request failed: %s\n", strerror(errno));
return errno;
}
if (raw)
if (format & COMMAND_FORMAT_RAW)
{
vici_dump(res, "initiate reply", stdout);
vici_dump(res, "initiate reply", format & COMMAND_FORMAT_PRETTY,
stdout);
}
else
{
@@ -116,12 +119,13 @@ static void __attribute__ ((constructor))reg()
{
command_register((command_t) {
initiate, 'i', "initiate", "initiate a connection",
{"--child <name> [--timeout <s>] [--raw]"},
{"--child <name> [--timeout <s>] [--raw|--pretty]"},
{
{"help", 'h', 0, "show usage information"},
{"child", 'c', 1, "initate a CHILD_SA configuration"},
{"timeout", 't', 1, "timeout in seconds before detaching"},
{"raw", 'r', 0, "dump raw response message"},
{"pretty", 'P', 0, "dump raw response message in pretty print"},
{"loglevel", 'l', 1, "verbosity of redirected log"},
}
});