From dacb75f5c04b19e142762c81d5b13d3005c57c71 Mon Sep 17 00:00:00 2001 From: Andreas Steffen Date: Thu, 12 Jun 2014 22:57:15 +0200 Subject: Split swanctl --raw mode into single-line and --pretty mode --- src/swanctl/commands/terminate.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'src/swanctl/commands/terminate.c') diff --git a/src/swanctl/commands/terminate.c b/src/swanctl/commands/terminate.c index b0e2c6671..689ba4d50 100644 --- a/src/swanctl/commands/terminate.c +++ b/src/swanctl/commands/terminate.c @@ -17,13 +17,12 @@ #include - 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 terminate(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, *ike = NULL; int ret = 0, timeout = 0, level = 1, child_id = 0, ike_id = 0; @@ -47,8 +46,11 @@ static int terminate(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; @@ -76,7 +78,7 @@ static int terminate(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; @@ -109,9 +111,10 @@ static int terminate(vici_conn_t *conn) fprintf(stderr, "terminate request failed: %s\n", strerror(errno)); return errno; } - if (raw) + if (format & COMMAND_FORMAT_RAW) { - vici_dump(res, "terminate reply", stdout); + vici_dump(res, "terminate reply", format & COMMAND_FORMAT_PRETTY, + stdout); } else { @@ -138,7 +141,7 @@ static void __attribute__ ((constructor))reg() command_register((command_t) { terminate, 't', "terminate", "terminate a connection", {"--child | --ike | --ike-id ", - "[--timeout ] [--raw]"}, + "[--timeout ] [--raw|--pretty]"}, { {"help", 'h', 0, "show usage information"}, {"child", 'c', 1, "terminate by CHILD_SA name"}, @@ -147,6 +150,7 @@ static void __attribute__ ((constructor))reg() {"ike-id", 'I', 1, "terminate by IKE_SA unique identifier"}, {"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"}, } }); -- cgit v1.2.3