/src/openvswitch/lib/ovsdb-session.c
Line | Count | Source (jump to first uncovered line) |
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 | 0 | { |
28 | 0 | for (const char *delimiter = strchr(s, ','); delimiter; |
29 | 0 | delimiter = strchr(delimiter + 1, ',')) { |
30 | 0 | const char *p = delimiter + 1; |
31 | 0 | p += strspn(p, " \t"); |
32 | 0 | size_t n_letters = strspn(p, "abcdefghijklmnopqrstuvwxyz"); |
33 | 0 | if (n_letters && p[n_letters] == ':') { |
34 | 0 | return delimiter; |
35 | 0 | } |
36 | 0 | } |
37 | 0 | return NULL; |
38 | 0 | } |
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 | 0 | { |
48 | 0 | *cid = UUID_ZERO; |
49 | 0 | for (;;) { |
50 | | /* Skip white space. */ |
51 | 0 | s += strspn(s, " \t"); |
52 | 0 | if (*s == '\0') { |
53 | 0 | break; |
54 | 0 | } |
55 | | |
56 | | /* Find the start of the next remote */ |
57 | 0 | const char *delimiter = next_remote(s); |
58 | 0 | if (!delimiter) { |
59 | 0 | svec_add(remotes, s); |
60 | 0 | break; |
61 | 0 | } |
62 | 0 | svec_add_nocopy(remotes, xmemdup0(s, delimiter - s)); |
63 | 0 | s = delimiter + 1; |
64 | 0 | } |
65 | |
|
66 | 0 | size_t i; |
67 | 0 | for (i = 0; i < remotes->n; i++) { |
68 | 0 | const char *name = remotes->names[i]; |
69 | 0 | struct uuid uuid; |
70 | 0 | if (!strncmp(name, "cid:", 4) && uuid_from_string(&uuid, name + 4)) { |
71 | 0 | *cid = uuid; |
72 | 0 | svec_del(remotes, name); |
73 | 0 | break; |
74 | 0 | } |
75 | 0 | } |
76 | 0 | } |