swanctl: Be more verbose while loading connections and credentials
[strongswan.git] / src / swanctl / commands / version.c
1 /*
2 * Copyright (C) 2014 Martin Willi
3 * Copyright (C) 2014 revosec AG
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 #include "command.h"
17
18 #include <errno.h>
19
20 static int version(vici_conn_t *conn)
21 {
22 vici_req_t *req;
23 vici_res_t *res;
24 char *arg;
25 bool raw = FALSE;
26
27 while (TRUE)
28 {
29 switch (command_getopt(&arg))
30 {
31 case 'h':
32 return command_usage(NULL);
33 case 'r':
34 raw = TRUE;
35 continue;
36 case EOF:
37 break;
38 default:
39 return command_usage("invalid --terminate option");
40 }
41 break;
42 }
43
44 req = vici_begin("version");
45 res = vici_submit(req, conn);
46 if (!res)
47 {
48 fprintf(stderr, "version request failed: %s\n", strerror(errno));
49 return errno;
50 }
51 if (raw)
52 {
53 vici_dump(res, "version reply", stdout);
54 }
55 else
56 {
57 printf("strongSwan %s %s (%s, %s, %s)\n",
58 vici_find_str(res, "", "version"),
59 vici_find_str(res, "", "daemon"),
60 vici_find_str(res, "", "sysname"),
61 vici_find_str(res, "", "release"),
62 vici_find_str(res, "", "machine"));
63 }
64 vici_free_res(res);
65 return 0;
66 }
67
68 /**
69 * Register the command.
70 */
71 static void __attribute__ ((constructor))reg()
72 {
73 command_register((command_t) {
74 version, 'v', "version", "show daemon version information",
75 {"[--raw]"},
76 {
77 {"help", 'h', 0, "show usage information"},
78 {"raw", 'r', 0, "dump raw response message"},
79 }
80 });
81 }