17
17
#include <config.h>
19
19
#include "jsonrpc.h"
23
22
#include <getopt.h>
25
24
#include <stdlib.h>
27
25
#include "command-line.h"
28
26
#include "daemon.h"
30
29
#include "poll-loop.h"
31
30
#include "stream-ssl.h"
32
31
#include "stream.h"
33
32
#include "timeval.h"
34
#include "openvswitch/vlog.h"
38
static void usage(void) NO_RETURN;
36
OVS_NO_RETURN static void usage(void);
39
37
static void parse_options(int argc, char *argv[]);
40
static struct command *get_all_commands(void);
38
static struct ovs_cmdl_command *get_all_commands(void);
43
41
test_jsonrpc_main(int argc, char *argv[])
45
proctitle_init(argc, argv);
43
struct ovs_cmdl_context ctx = { .argc = 0, };
44
ovs_cmdl_proctitle_init(argc, argv);
46
45
set_program_name(argv[0]);
46
service_start(&argc, &argv);
47
47
parse_options(argc, argv);
48
run_command(argc - optind, argv + optind, get_all_commands());
48
ctx.argc = argc - optind;
49
ctx.argv = argv + optind;
50
ovs_cmdl_run_command(&ctx, get_all_commands());
63
65
STREAM_SSL_LONG_OPTIONS,
64
66
{NULL, 0, NULL, 0},
66
char *short_options = long_options_to_short_options(long_options);
68
char *short_options = ovs_cmdl_long_options_to_short_options(long_options);
69
71
int c = getopt_long(argc, argv, short_options, long_options, NULL);
178
error = jsonrpc_pstream_open(argv[1], &pstream, DSCP_DEFAULT);
180
error = jsonrpc_pstream_open(ctx->argv[1], &pstream, DSCP_DEFAULT);
180
ovs_fatal(error, "could not listen on \"%s\"", argv[1]);
182
ovs_fatal(error, "could not listen on \"%s\"", ctx->argv[1]);
264
params = parse_json(argv[3]);
265
method = ctx->argv[2];
266
params = parse_json(ctx->argv[3]);
265
267
msg = jsonrpc_create_request(method, params, NULL);
266
268
string = jsonrpc_msg_is_valid(msg);
268
270
ovs_fatal(0, "not a valid JSON-RPC request: %s", string);
271
error = stream_open_block(jsonrpc_stream_open(argv[1], &stream,
273
error = stream_open_block(jsonrpc_stream_open(ctx->argv[1], &stream,
272
274
DSCP_DEFAULT), &stream);
274
ovs_fatal(error, "could not open \"%s\"", argv[1]);
276
ovs_fatal(error, "could not open \"%s\"", ctx->argv[1]);
276
278
rpc = jsonrpc_open(stream);
304
params = parse_json(argv[3]);
305
method = ctx->argv[2];
306
params = parse_json(ctx->argv[3]);
305
307
msg = jsonrpc_create_notify(method, params);
306
308
string = jsonrpc_msg_is_valid(msg);
308
310
ovs_fatal(0, "not a JSON RPC-valid notification: %s", string);
311
error = stream_open_block(jsonrpc_stream_open(argv[1], &stream,
313
error = stream_open_block(jsonrpc_stream_open(ctx->argv[1], &stream,
312
314
DSCP_DEFAULT), &stream);
314
ovs_fatal(error, "could not open \"%s\"", argv[1]);
316
ovs_fatal(error, "could not open \"%s\"", ctx->argv[1]);
316
318
rpc = jsonrpc_open(stream);
326
do_help(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
328
do_help(struct ovs_cmdl_context *ctx OVS_UNUSED)
331
static struct command all_commands[] = {
332
{ "listen", 1, 1, do_listen },
333
{ "request", 3, 3, do_request },
334
{ "notify", 3, 3, do_notify },
335
{ "help", 0, INT_MAX, do_help },
336
{ NULL, 0, 0, NULL },
333
static struct ovs_cmdl_command all_commands[] = {
334
{ "listen", NULL, 1, 1, do_listen },
335
{ "request", NULL, 3, 3, do_request },
336
{ "notify", NULL, 3, 3, do_notify },
337
{ "help", NULL, 0, INT_MAX, do_help },
338
{ NULL, NULL, 0, 0, NULL },
339
static struct command *
341
static struct ovs_cmdl_command *
340
342
get_all_commands(void)
342
344
return all_commands;