2 * Copyright (C) 2014 Martin Willi
3 * Copyright (C) 2014 revosec AG
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>.
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
21 CALLBACK(log_cb
, void,
22 bool *raw
, char *name
, vici_res_t
*msg
)
26 vici_dump(msg
, "log", stdout
);
31 vici_find_str(msg
, " ", "group"),
32 vici_find_str(msg
, "", "msg"));
36 static int initiate(vici_conn_t
*conn
)
41 char *arg
, *child
= NULL
;
42 int ret
= 0, timeout
= 0, level
= 1;
46 switch (command_getopt(&arg
))
49 return command_usage(NULL
);
65 return command_usage("invalid --initiate option");
70 if (vici_register(conn
, "control-log", log_cb
, &raw
) != 0)
72 fprintf(stderr
, "registering for log failed: %s\n", strerror(errno
));
75 req
= vici_begin("initiate");
78 vici_add_key_valuef(req
, "child", "%s", child
);
82 vici_add_key_valuef(req
, "timeout", "%d", timeout
* 1000);
84 vici_add_key_valuef(req
, "loglevel", "%d", level
);
85 res
= vici_submit(req
, conn
);
88 fprintf(stderr
, "initiate request failed: %s\n", strerror(errno
));
93 vici_dump(res
, "initiate reply", stdout
);
97 if (streq(vici_find_str(res
, "no", "success"), "yes"))
99 printf("initiate completed successfully\n");
103 fprintf(stderr
, "initiate failed: %s\n",
104 vici_find_str(res
, "", "errmsg"));
113 * Register the command.
115 static void __attribute__ ((constructor
))reg()
117 command_register((command_t
) {
118 initiate
, 'i', "initiate", "initiate a connection",
119 {"--child <name> [--timeout <s>] [--raw]"},
121 {"help", 'h', 0, "show usage information"},
122 {"child", 'c', 1, "initate a CHILD_SA configuration"},
123 {"timeout", 't', 1, "timeout in seconds before detaching"},
124 {"raw", 'r', 0, "dump raw response message"},
125 {"loglevel", 'l', 1, "verbosity of redirected log"},