netdev-dpdk: fix mbuf leaks
[cascardo/ovs.git] / lib / ovsdb-parser.h
1 /* Copyright (c) 2009, 2010, 2011, 2015 Nicira, Inc.
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"
21 #include "json.h"
22 #include "sset.h"
23 #include "util.h"
24
25 struct ovsdb_parser {
26     char *name;                 /* Used only in error messages. */
27     struct sset used;           /* Already-parsed names from 'object'. */
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. */
33 BUILD_ASSERT_DECL(JSON_NULL >= 0 && JSON_NULL < 10);
34 BUILD_ASSERT_DECL(JSON_FALSE >= 0 && JSON_FALSE < 10);
35 BUILD_ASSERT_DECL(JSON_TRUE >= 0 && JSON_TRUE < 10);
36 BUILD_ASSERT_DECL(JSON_OBJECT >= 0 && JSON_OBJECT < 10);
37 BUILD_ASSERT_DECL(JSON_ARRAY >= 0 && JSON_ARRAY < 10);
38 BUILD_ASSERT_DECL(JSON_INTEGER >= 0 && JSON_INTEGER < 10);
39 BUILD_ASSERT_DECL(JSON_REAL >= 0 && JSON_REAL < 10);
40 BUILD_ASSERT_DECL(JSON_STRING >= 0 && JSON_STRING < 10);
41 BUILD_ASSERT_DECL(JSON_N_TYPES == 8);
42
43 enum 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,         /* "..." */
52     OP_ANY = (OP_NULL | OP_FALSE | OP_TRUE | OP_OBJECT | OP_ARRAY
53               | OP_INTEGER | OP_NONINTEGER | OP_STRING),
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
62 void ovsdb_parser_init(struct ovsdb_parser *, const struct json *,
63                        const char *name, ...)
64     OVS_PRINTF_FORMAT(3, 4);
65 const struct json *ovsdb_parser_member(struct ovsdb_parser *, const char *name,
66                                        enum ovsdb_parser_types);
67
68 void ovsdb_parser_raise_error(struct ovsdb_parser *parser,
69                               const char *format, ...)
70     OVS_PRINTF_FORMAT(2, 3);
71 bool ovsdb_parser_has_error(const struct ovsdb_parser *);
72 struct ovsdb_error *ovsdb_parser_get_error(const struct ovsdb_parser *);
73 struct ovsdb_error *ovsdb_parser_finish(struct ovsdb_parser *)
74     OVS_WARN_UNUSED_RESULT;
75 struct ovsdb_error *ovsdb_parser_destroy(struct ovsdb_parser *)
76     OVS_WARN_UNUSED_RESULT;
77
78 bool ovsdb_parser_is_id(const char *string);
79
80 #endif /* ovsdb-parser.h */