]> git.proxmox.com Git - mirror_ovs.git/blame - lib/ovsdb-parser.h
ovsdb-idl: Improve prototypes.
[mirror_ovs.git] / lib / ovsdb-parser.h
CommitLineData
edebc777 1/* Copyright (c) 2009, 2010, 2011, 2015, 2016 Nicira, Inc.
f85f8ebb
BP
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#ifndef OVSDB_PARSER_H
17#define OVSDB_PARSER_H 1
18
19#include <stdbool.h>
20#include "compiler.h"
ee89ea7b 21#include "openvswitch/json.h"
53d04661 22#include "sset.h"
f85f8ebb
BP
23#include "util.h"
24
25struct ovsdb_parser {
26 char *name; /* Used only in error messages. */
53d04661 27 struct sset used; /* Already-parsed names from 'object'. */
f85f8ebb
BP
28 const struct json *json; /* JSON object being parsed. */
29 struct ovsdb_error *error; /* Error signaled, if any. */
30};
31
32/* Check that the JSON types make the bitwise tricks below work OK. */
33BUILD_ASSERT_DECL(JSON_NULL >= 0 && JSON_NULL < 10);
34BUILD_ASSERT_DECL(JSON_FALSE >= 0 && JSON_FALSE < 10);
35BUILD_ASSERT_DECL(JSON_TRUE >= 0 && JSON_TRUE < 10);
36BUILD_ASSERT_DECL(JSON_OBJECT >= 0 && JSON_OBJECT < 10);
37BUILD_ASSERT_DECL(JSON_ARRAY >= 0 && JSON_ARRAY < 10);
38BUILD_ASSERT_DECL(JSON_INTEGER >= 0 && JSON_INTEGER < 10);
39BUILD_ASSERT_DECL(JSON_REAL >= 0 && JSON_REAL < 10);
40BUILD_ASSERT_DECL(JSON_STRING >= 0 && JSON_STRING < 10);
41BUILD_ASSERT_DECL(JSON_N_TYPES == 8);
42
43enum ovsdb_parser_types {
44 OP_NULL = 1 << JSON_NULL, /* null */
45 OP_FALSE = 1 << JSON_FALSE, /* false */
46 OP_TRUE = 1 << JSON_TRUE, /* true */
47 OP_OBJECT = 1 << JSON_OBJECT, /* {"a": b, "c": d, ...} */
48 OP_ARRAY = 1 << JSON_ARRAY, /* [1, 2, 3, ...] */
49 OP_INTEGER = 1 << JSON_INTEGER, /* 123. */
50 OP_NONINTEGER = 1 << JSON_REAL, /* 123.456. */
51 OP_STRING = 1 << JSON_STRING, /* "..." */
bfc96d9b
BP
52 OP_ANY = (OP_NULL | OP_FALSE | OP_TRUE | OP_OBJECT | OP_ARRAY
53 | OP_INTEGER | OP_NONINTEGER | OP_STRING),
f85f8ebb
BP
54
55 OP_BOOLEAN = OP_FALSE | OP_TRUE,
56 OP_NUMBER = OP_INTEGER | OP_NONINTEGER,
57
58 OP_ID = 1 << JSON_N_TYPES, /* "[_a-zA-Z][_a-zA-Z0-9]*" */
59 OP_OPTIONAL = 1 << (JSON_N_TYPES + 1) /* no value at all */
60};
61
62void ovsdb_parser_init(struct ovsdb_parser *, const struct json *,
63 const char *name, ...)
cab50449 64 OVS_PRINTF_FORMAT(3, 4);
f85f8ebb 65const struct json *ovsdb_parser_member(struct ovsdb_parser *, const char *name,
124f9671 66 enum ovsdb_parser_types);
f85f8ebb
BP
67
68void ovsdb_parser_raise_error(struct ovsdb_parser *parser,
69 const char *format, ...)
cab50449 70 OVS_PRINTF_FORMAT(2, 3);
edebc777 71void ovsdb_parser_put_error(struct ovsdb_parser *, struct ovsdb_error *);
f85f8ebb
BP
72bool ovsdb_parser_has_error(const struct ovsdb_parser *);
73struct ovsdb_error *ovsdb_parser_get_error(const struct ovsdb_parser *);
74struct ovsdb_error *ovsdb_parser_finish(struct ovsdb_parser *)
cab50449 75 OVS_WARN_UNUSED_RESULT;
d18e52e3
BP
76struct ovsdb_error *ovsdb_parser_destroy(struct ovsdb_parser *)
77 OVS_WARN_UNUSED_RESULT;
f85f8ebb 78
b966380b
BP
79bool ovsdb_parser_is_id(const char *string);
80
f85f8ebb 81#endif /* ovsdb-parser.h */