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
49 #pragma ident "%Z%%M% %I% %E% SMI"
55 #include <sys/types.h>
60 free_replica(struct replica
*list
, int count
)
64 for (i
= 0; i
< count
; i
++) {
74 parse_replica(char *special
, int *count
)
76 struct replica
*list
= NULL
;
77 char *root
, *special2
;
79 int scount
, v6addr
, i
;
85 root
= special2
= strdup(special
);
91 if ((root
!= special2
) && (*(root
-1) != ',')) {
95 y
= strchr(root
, ']');
100 if ((*(y
+ 1) != ',') && (*(y
+ 1) != ':')) {
105 * Found a v6 Literal Address, so set "v6addr"
106 * and grab the address and store it in the list
112 if ((list
= realloc(list
, (*count
+ 1) *
113 sizeof (struct replica
))) == NULL
)
115 bzero(&list
[(*count
)++], sizeof (struct replica
));
117 list
[*count
-1].host
= strdup(proot
);
118 if (!list
[*count
-1].host
)
125 * Find comma (if present), which bounds the path.
126 * The comma implies that the user is trying to
127 * specify failover syntax if another colon follows.
129 if (((y
= strchr(x
, ',')) != NULL
) &&
130 (strchr((y
+ 1), ':'))) {
138 * If "v6addr" is set, unset it, and since the "host
139 * part" is already taken care of, skip to the "path
145 if ((list
= realloc(list
, (*count
+ 1) *
146 sizeof (struct replica
))) == NULL
)
148 bzero(&list
[(*count
)++],
149 sizeof (struct replica
));
150 list
[*count
-1].host
= strdup(proot
);
151 if (!list
[*count
-1].host
)
156 for (i
= scount
; i
< *count
; i
++) {
157 list
[i
].path
= strdup(x
);
168 * If "v6addr" is set, unset it and continue
169 * else grab the address and store it in the list
178 if ((list
= realloc(list
, (*count
+ 1) *
179 sizeof (struct replica
))) == NULL
)
181 bzero(&list
[(*count
)++],
182 sizeof (struct replica
));
183 list
[*count
-1].host
= strdup(proot
);
184 if (!list
[*count
-1].host
)
203 free_replica(list
, *count
);