]> git.proxmox.com Git - mirror_ovs.git/blob - lib/jsonrpc.h
lldp: fix a buffer overflow when handling management address TLV
[mirror_ovs.git] / lib / jsonrpc.h
1 /*
2 * Copyright (c) 2009, 2010, 2012, 2013, 2017 Nicira, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef JSONRPC_H
18 #define JSONRPC_H 1
19
20 /* This is an implementation of the JSON-RPC 1.0 specification defined at
21 * http://json-rpc.org/wiki/specification. */
22
23 #include <stdbool.h>
24 #include <stddef.h>
25 #include "openvswitch/types.h"
26
27 struct json;
28 struct jsonrpc_msg;
29 struct pstream;
30 struct reconnect_stats;
31 struct stream;
32 struct svec;
33 \f
34 /* API for a JSON-RPC stream. */
35
36 /* Default port numbers.
37 *
38 * OVSDB_OLD_PORT defines the original port number used by OVS.
39 * OVSDB_PORT defines the official port number assigned by IANA. */
40 #define OVSDB_OLD_PORT 6632
41 #define OVSDB_PORT 6640
42
43 int jsonrpc_stream_open(const char *name, struct stream **, uint8_t dscp);
44 int jsonrpc_pstream_open(const char *name, struct pstream **, uint8_t dscp);
45
46 struct jsonrpc *jsonrpc_open(struct stream *);
47 void jsonrpc_close(struct jsonrpc *);
48
49 void jsonrpc_run(struct jsonrpc *);
50 void jsonrpc_wait(struct jsonrpc *);
51
52 int jsonrpc_get_status(const struct jsonrpc *);
53 size_t jsonrpc_get_backlog(const struct jsonrpc *);
54 void jsonrpc_set_backlog_threshold(struct jsonrpc *, size_t max_n_msgs,
55 size_t max_backlog_bytes);
56
57 unsigned int jsonrpc_get_received_bytes(const struct jsonrpc *);
58 const char *jsonrpc_get_name(const struct jsonrpc *);
59
60 int jsonrpc_send(struct jsonrpc *, struct jsonrpc_msg *);
61 int jsonrpc_recv(struct jsonrpc *, struct jsonrpc_msg **);
62 void jsonrpc_recv_wait(struct jsonrpc *);
63
64 int jsonrpc_send_block(struct jsonrpc *, struct jsonrpc_msg *);
65 int jsonrpc_recv_block(struct jsonrpc *, struct jsonrpc_msg **);
66 int jsonrpc_transact_block(struct jsonrpc *, struct jsonrpc_msg *,
67 struct jsonrpc_msg **);
68
69 /* Messages. */
70 enum jsonrpc_msg_type {
71 JSONRPC_REQUEST, /* Request. */
72 JSONRPC_NOTIFY, /* Notification. */
73 JSONRPC_REPLY, /* Successful reply. */
74 JSONRPC_ERROR /* Error reply. */
75 };
76
77 struct jsonrpc_msg {
78 enum jsonrpc_msg_type type;
79 char *method; /* Request or notification only. */
80 struct json *params; /* Request or notification only. */
81 struct json *result; /* Successful reply only. */
82 struct json *error; /* Error reply only. */
83 struct json *id; /* Request or reply only. */
84 };
85
86 struct jsonrpc_msg *jsonrpc_create_request(const char *method,
87 struct json *params,
88 struct json **idp);
89 struct jsonrpc_msg *jsonrpc_create_notify(const char *method,
90 struct json *params);
91 struct jsonrpc_msg *jsonrpc_create_reply(struct json *result,
92 const struct json *id);
93 struct jsonrpc_msg *jsonrpc_create_error(struct json *error,
94 const struct json *id);
95
96 struct jsonrpc_msg *jsonrpc_msg_clone(const struct jsonrpc_msg *);
97
98 const char *jsonrpc_msg_type_to_string(enum jsonrpc_msg_type);
99 char *jsonrpc_msg_is_valid(const struct jsonrpc_msg *);
100 void jsonrpc_msg_destroy(struct jsonrpc_msg *);
101
102 char *jsonrpc_msg_from_json(struct json *, struct jsonrpc_msg **);
103 struct json *jsonrpc_msg_to_json(struct jsonrpc_msg *);
104
105 char *jsonrpc_msg_to_string(const struct jsonrpc_msg *);
106 \f
107 /* A JSON-RPC session with reconnection. */
108
109 struct jsonrpc_session *jsonrpc_session_open(const char *name, bool retry);
110 struct jsonrpc_session *jsonrpc_session_open_multiple(const struct svec *,
111 bool retry);
112 struct jsonrpc_session *jsonrpc_session_open_unreliably(struct jsonrpc *,
113 uint8_t);
114 void jsonrpc_session_close(struct jsonrpc_session *);
115
116 struct jsonrpc *jsonrpc_session_steal(struct jsonrpc_session *);
117
118 void jsonrpc_session_run(struct jsonrpc_session *);
119 void jsonrpc_session_wait(struct jsonrpc_session *);
120
121 size_t jsonrpc_session_get_backlog(const struct jsonrpc_session *);
122 const char *jsonrpc_session_get_name(const struct jsonrpc_session *);
123 size_t jsonrpc_session_get_n_remotes(const struct jsonrpc_session *);
124
125 int jsonrpc_session_send(struct jsonrpc_session *, struct jsonrpc_msg *);
126 struct jsonrpc_msg *jsonrpc_session_recv(struct jsonrpc_session *);
127 void jsonrpc_session_recv_wait(struct jsonrpc_session *);
128
129 bool jsonrpc_session_is_alive(const struct jsonrpc_session *);
130 bool jsonrpc_session_is_connected(const struct jsonrpc_session *);
131 unsigned int jsonrpc_session_get_seqno(const struct jsonrpc_session *);
132 int jsonrpc_session_get_status(const struct jsonrpc_session *);
133 int jsonrpc_session_get_last_error(const struct jsonrpc_session *);
134 void jsonrpc_session_get_reconnect_stats(const struct jsonrpc_session *,
135 struct reconnect_stats *);
136
137 void jsonrpc_session_enable_reconnect(struct jsonrpc_session *);
138 void jsonrpc_session_force_reconnect(struct jsonrpc_session *);
139
140 void jsonrpc_session_set_max_backoff(struct jsonrpc_session *,
141 int max_backoff);
142 void jsonrpc_session_set_probe_interval(struct jsonrpc_session *,
143 int probe_interval);
144 void jsonrpc_session_set_dscp(struct jsonrpc_session *,
145 uint8_t dscp);
146 void jsonrpc_session_set_backlog_threshold(struct jsonrpc_session *,
147 size_t max_n_msgs,
148 size_t max_backlog_bytes);
149 const char *jsonrpc_session_get_id(const struct jsonrpc_session *);
150
151 #endif /* jsonrpc.h */