]> git.proxmox.com Git - mirror_ovs.git/blob - lib/ovsdb-session.c
netdev-offload-tc: Use single 'once' variable for probing tc features
[mirror_ovs.git] / lib / ovsdb-session.c
1 /* Copyright (c) 2017 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 #include <config.h>
17 #include "ovsdb-session.h"
18 #include <stdbool.h>
19 #include <stddef.h>
20 #include <string.h>
21 #include "svec.h"
22 #include "util.h"
23 #include "uuid.h"
24
25 static const char *
26 next_remote(const char *s)
27 {
28 for (const char *delimiter = strchr(s, ','); delimiter;
29 delimiter = strchr(delimiter + 1, ',')) {
30 const char *p = delimiter + 1;
31 p += strspn(p, " \t");
32 size_t n_letters = strspn(p, "abcdefghijklmnopqrstuvwxyz");
33 if (n_letters && p[n_letters] == ':') {
34 return delimiter;
35 }
36 }
37 return NULL;
38 }
39
40 /* Parses string 's' into comma-delimited substrings and adds each of them into
41 * 'remotes'. If one of the substrings is of the form "cid:<uuid>", fills
42 * '*cid' with the UUID (and omits it from 'remotes'), otherwise initializes
43 * '*cid' to UUID_ZERO. */
44 void
45 ovsdb_session_parse_remote(const char *s,
46 struct svec *remotes, struct uuid *cid)
47 {
48 *cid = UUID_ZERO;
49 for (;;) {
50 /* Skip white space. */
51 s += strspn(s, " \t");
52 if (*s == '\0') {
53 break;
54 }
55
56 /* Find the start of the next remote */
57 const char *delimiter = next_remote(s);
58 if (!delimiter) {
59 svec_add(remotes, s);
60 break;
61 }
62 svec_add_nocopy(remotes, xmemdup0(s, delimiter - s));
63 s = delimiter + 1;
64 }
65
66 size_t i;
67 for (i = 0; i < remotes->n; i++) {
68 const char *name = remotes->names[i];
69 struct uuid uuid;
70 if (!strncmp(name, "cid:", 4) && uuid_from_string(&uuid, name + 4)) {
71 *cid = uuid;
72 svec_del(remotes, name);
73 break;
74 }
75 }
76 }