42345f86b155a4b07badf415541396f728a5d4fc
[sliver-openvswitch.git] / lib / cfg.h
1 /* Copyright (c) 2008, 2009 Nicira Networks
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
17 #ifndef VSWITCHD_CFG_H
18 #define VSWITCHD_CFG_H 1
19
20 #include <stdbool.h>
21 #include <stdint.h>
22 #include <unistd.h>
23 #include "compiler.h"
24 #include "sha1.h"
25
26 struct svec;
27 struct ofpbuf;
28
29 int cfg_set_file(const char *file_name);
30 int cfg_read(void);
31 int cfg_lock(uint8_t *cookie, int timeout);
32 void cfg_unlock(void);
33 int cfg_write(void);
34 int cfg_write_data(uint8_t *data, size_t len);
35 bool cfg_is_dirty(void);
36
37 void cfg_get_all(struct svec *);
38
39 #define CFG_COOKIE_LEN SHA1_DIGEST_SIZE
40 int cfg_get_cookie(uint8_t *cookie);
41
42 void cfg_buf_put(struct ofpbuf *buffer);
43 void cfg_get_subsections(struct svec *, const char *, ...) PRINTF_FORMAT(2, 3);
44
45 enum cfg_flags {
46     /* Types allowed. */
47     CFG_STRING = 1 << 0,        /* Arbitrary content. */
48     CFG_KEY = 1 << 0,           /* Valid key name. */
49     CFG_INT = 1 << 2,           /* Integer value. */
50     CFG_BOOL = 1 << 3,          /* Boolean. */
51     CFG_IP = 1 << 4,            /* IPv4 address. */
52     CFG_MAC = 1 << 5,           /* MAC address. */
53     CFG_VLAN = 1 << 6,          /* Integer in range 0...4095. */
54     CFG_DPID = 1 << 7,          /* 12 hexadecimal digits. */
55
56     /* Number allowed. */
57     CFG_REQUIRED = 1 << 8,      /* At least one value allowed. */
58     CFG_MULTIPLE = 1 << 9       /* More than one value allowed. */
59 };
60 void cfg_register(const char *key_spec, enum cfg_flags);
61
62 void cfg_add_entry(const char *key, ...) PRINTF_FORMAT(1, 2);
63 void cfg_del_entry(const char *key, ...) PRINTF_FORMAT(1, 2);
64 void cfg_del_section(const char *key, ...) PRINTF_FORMAT(1, 2);
65 void cfg_del_match(const char *pattern, ...) PRINTF_FORMAT(1, 2);
66 void cfg_get_matches(struct svec *svec, const char *pattern, ...)
67     PRINTF_FORMAT(2, 3);
68 void cfg_get_section(struct svec *svec, const char *key, ...) 
69     PRINTF_FORMAT(2, 3);
70
71 bool cfg_has(const char *key, ...) PRINTF_FORMAT(1, 2);
72 bool cfg_is_valid(enum cfg_flags, const char *key, ...) PRINTF_FORMAT(2, 3);
73 bool cfg_has_section(const char *key, ...) PRINTF_FORMAT(1, 2);
74 int cfg_count(const char *key, ...) PRINTF_FORMAT(1, 2);
75
76 const char *cfg_get_string(int idx, const char *key, ...) PRINTF_FORMAT(2, 3);
77 const char *cfg_get_key(int idx, const char *key, ...) PRINTF_FORMAT(2, 3);
78 int cfg_get_int(int idx, const char *key, ...) PRINTF_FORMAT(2, 3);
79 bool cfg_get_bool(int idx, const char *key, ...) PRINTF_FORMAT(2, 3);
80 uint32_t cfg_get_ip(int idx, const char *key, ...) PRINTF_FORMAT(2, 3);
81 uint64_t cfg_get_mac(int idx, const char *key, ...) PRINTF_FORMAT(2, 3);
82 int cfg_get_vlan(int idx, const char *key, ...) PRINTF_FORMAT(2, 3);
83 uint64_t cfg_get_dpid(int idx, const char *key, ...) PRINTF_FORMAT(2, 3);
84
85 void cfg_get_all_strings(struct svec *, const char *key, ...)
86     PRINTF_FORMAT(2, 3);
87 void cfg_get_all_keys(struct svec *, const char *key, ...) PRINTF_FORMAT(2, 3);
88
89 #endif /* vswitchd/cfg.h */