4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
25 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
26 * Use is subject to license terms.
30 * Parse replicated server lists of the form:
32 * host1:/path1,host2,host3,host4:/path2,host5:/path3
34 * into an array containing its constituent parts:
41 * where a server could also be represented in form of literal address
42 * and in case it is an IPv6 literal address it will be enclosed in
43 * square brackets [IPv6 Literal address]
44 * Problems indicated by null return; they will be memory allocation
45 * errors worthy of an error message unless count == -1, which means
53 #include <sys/types.h>
58 free_replica(struct replica
*list
, int count
)
62 for (i
= 0; i
< count
; i
++) {
70 parse_replica(char *special
, int *count
)
72 struct replica
*list
= NULL
;
73 char *root
, *special2
;
75 int scount
, v6addr
, i
;
81 root
= special2
= strdup(special
);
87 if ((root
!= special2
) && (*(root
-1) != ',')) {
91 y
= strchr(root
, ']');
96 if ((*(y
+ 1) != ',') && (*(y
+ 1) != ':')) {
101 * Found a v6 Literal Address, so set "v6addr"
102 * and grab the address and store it in the list
108 if ((list
= reallocarray(list
, *count
+ 1,
109 sizeof (struct replica
))) == NULL
)
111 bzero(&list
[(*count
)++], sizeof (struct replica
));
113 list
[*count
-1].host
= strdup(proot
);
114 if (!list
[*count
-1].host
)
121 * Find comma (if present), which bounds the path.
122 * The comma implies that the user is trying to
123 * specify failover syntax if another colon follows.
125 if (((y
= strchr(x
, ',')) != NULL
) &&
126 (strchr((y
+ 1), ':'))) {
134 * If "v6addr" is set, unset it, and since the "host
135 * part" is already taken care of, skip to the "path
141 if ((list
= reallocarray(list
, *count
+ 1,
142 sizeof (struct replica
))) == NULL
)
144 bzero(&list
[(*count
)++],
145 sizeof (struct replica
));
146 list
[*count
-1].host
= strdup(proot
);
147 if (!list
[*count
-1].host
)
152 for (i
= scount
; i
< *count
; i
++) {
153 list
[i
].path
= strdup(x
);
164 * If "v6addr" is set, unset it and continue
165 * else grab the address and store it in the list
174 if ((list
= reallocarray(list
, *count
+ 1,
175 sizeof (struct replica
))) == NULL
)
177 bzero(&list
[(*count
)++],
178 sizeof (struct replica
));
179 list
[*count
-1].host
= strdup(proot
);
180 if (!list
[*count
-1].host
)
199 free_replica(list
, *count
);