]>
git.proxmox.com Git - ovs.git/blob - lib/ovsdb-session.c
1 /* Copyright (c) 2017 Nicira, Inc.
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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "ovsdb-session.h"
26 next_remote(const char *s
)
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
] == ':') {
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. */
45 ovsdb_session_parse_remote(const char *s
,
46 struct svec
*remotes
, struct uuid
*cid
)
50 /* Skip white space. */
51 s
+= strspn(s
, " \t");
56 /* Find the start of the next remote */
57 const char *delimiter
= next_remote(s
);
62 svec_add_nocopy(remotes
, xmemdup0(s
, delimiter
- s
));
67 for (i
= 0; i
< remotes
->n
; i
++) {
68 const char *name
= remotes
->names
[i
];
70 if (!strncmp(name
, "cid:", 4) && uuid_from_string(&uuid
, name
+ 4)) {
72 svec_del(remotes
, name
);