swanctl: Stop logging with Ctrl+C on Windows as well
[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, daemon = 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 'd':
37 daemon = TRUE;
38 continue;
39 case EOF:
40 break;
41 default:
42 return command_usage("invalid --terminate option");
43 }
44 break;
45 }
46
47 if (!daemon)
48 {
49 printf("strongSwan swanctl %s\n", VERSION);
50 return 0;
51 }
52
53 req = vici_begin("version");
54 res = vici_submit(req, conn);
55 if (!res)
56 {
57 fprintf(stderr, "version request failed: %s\n", strerror(errno));
58 return errno;
59 }
60 if (raw)
61 {
62 vici_dump(res, "version reply", stdout);
63 }
64 else
65 {
66 printf("strongSwan %s %s (%s, %s, %s)\n",
67 vici_find_str(res, "", "version"),
68 vici_find_str(res, "", "daemon"),
69 vici_find_str(res, "", "sysname"),
70 vici_find_str(res, "", "release"),
71 vici_find_str(res, "", "machine"));
72 }
73 vici_free_res(res);
74 return 0;
75 }
76
77 /**
78 * Register the command.
79 */
80 static void __attribute__ ((constructor))reg()
81 {
82 command_register((command_t) {
83 version, 'v', "version", "show version information",
84 {"[--raw]"},
85 {
86 {"help", 'h', 0, "show usage information"},
87 {"daemon", 'd', 0, "query daemon version"},
88 {"raw", 'r', 0, "dump raw response message"},
89 }
90 });
91 }