xref: /illumos-gate/usr/src/lib/udapl/libdat/common/udat_sr_parser.c (revision 1da57d551424de5a9d469760be7c4b4d4f10a755)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.
24*7c478bd9Sstevel@tonic-gate  */
25*7c478bd9Sstevel@tonic-gate 
26*7c478bd9Sstevel@tonic-gate /*
27*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
28*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
29*7c478bd9Sstevel@tonic-gate  */
30*7c478bd9Sstevel@tonic-gate 
31*7c478bd9Sstevel@tonic-gate /*
32*7c478bd9Sstevel@tonic-gate  *
33*7c478bd9Sstevel@tonic-gate  * MODULE: dat_sr_parser.c
34*7c478bd9Sstevel@tonic-gate  *
35*7c478bd9Sstevel@tonic-gate  * PURPOSE: static registry parser
36*7c478bd9Sstevel@tonic-gate  *
37*7c478bd9Sstevel@tonic-gate  * $Id: udat_sr_parser.c,v 1.1 2003/07/31 14:04:19 jlentini Exp $
38*7c478bd9Sstevel@tonic-gate  */
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate 
41*7c478bd9Sstevel@tonic-gate #include "udat_sr_parser.h"
42*7c478bd9Sstevel@tonic-gate #include "dat_sr.h"
43*7c478bd9Sstevel@tonic-gate 
44*7c478bd9Sstevel@tonic-gate 
45*7c478bd9Sstevel@tonic-gate /*
46*7c478bd9Sstevel@tonic-gate  *
47*7c478bd9Sstevel@tonic-gate  * Constants
48*7c478bd9Sstevel@tonic-gate  *
49*7c478bd9Sstevel@tonic-gate  */
50*7c478bd9Sstevel@tonic-gate 
51*7c478bd9Sstevel@tonic-gate #define	DAT_SR_CONF_ENV 		"DAT_OVERRIDE"
52*7c478bd9Sstevel@tonic-gate #define	DAT_SR_CONF_DEFAULT 		"/etc/dat/dat.conf"
53*7c478bd9Sstevel@tonic-gate 
54*7c478bd9Sstevel@tonic-gate #define	DAT_SR_TOKEN_THREADSAFE 	"threadsafe"
55*7c478bd9Sstevel@tonic-gate #define	DAT_SR_TOKEN_NONTHREADSAFE 	"nonthreadsafe"
56*7c478bd9Sstevel@tonic-gate #define	DAT_SR_TOKEN_DEFAULT 		"default"
57*7c478bd9Sstevel@tonic-gate #define	DAT_SR_TOKEN_NONDEFAULT 	"nondefault"
58*7c478bd9Sstevel@tonic-gate 
59*7c478bd9Sstevel@tonic-gate #define	DAT_SR_CHAR_NEWLINE 		'\n'
60*7c478bd9Sstevel@tonic-gate #define	DAT_SR_CHAR_COMMENT 		'#'
61*7c478bd9Sstevel@tonic-gate #define	DAT_SR_CHAR_QUOTE 		'"'
62*7c478bd9Sstevel@tonic-gate #define	DAT_SR_CHAR_BACKSLASH 		'\\'
63*7c478bd9Sstevel@tonic-gate 
64*7c478bd9Sstevel@tonic-gate 
65*7c478bd9Sstevel@tonic-gate /*
66*7c478bd9Sstevel@tonic-gate  *
67*7c478bd9Sstevel@tonic-gate  * Enumerations
68*7c478bd9Sstevel@tonic-gate  *
69*7c478bd9Sstevel@tonic-gate  */
70*7c478bd9Sstevel@tonic-gate 
71*7c478bd9Sstevel@tonic-gate typedef enum
72*7c478bd9Sstevel@tonic-gate {
73*7c478bd9Sstevel@tonic-gate 	DAT_SR_TOKEN_STRING,	/* text field (both quoted or unquoted)	*/
74*7c478bd9Sstevel@tonic-gate 	DAT_SR_TOKEN_EOR,	/* end of record (newline)		*/
75*7c478bd9Sstevel@tonic-gate 	DAT_SR_TOKEN_EOF 	/* end of file				*/
76*7c478bd9Sstevel@tonic-gate } DAT_SR_TOKEN_TYPE;
77*7c478bd9Sstevel@tonic-gate 
78*7c478bd9Sstevel@tonic-gate typedef enum
79*7c478bd9Sstevel@tonic-gate {
80*7c478bd9Sstevel@tonic-gate 	DAT_SR_API_UDAT,
81*7c478bd9Sstevel@tonic-gate 	DAT_SR_API_KDAT
82*7c478bd9Sstevel@tonic-gate } DAT_SR_API_TYPE;
83*7c478bd9Sstevel@tonic-gate 
84*7c478bd9Sstevel@tonic-gate 
85*7c478bd9Sstevel@tonic-gate /*
86*7c478bd9Sstevel@tonic-gate  *
87*7c478bd9Sstevel@tonic-gate  * Structures
88*7c478bd9Sstevel@tonic-gate  *
89*7c478bd9Sstevel@tonic-gate  */
90*7c478bd9Sstevel@tonic-gate 
91*7c478bd9Sstevel@tonic-gate typedef struct
92*7c478bd9Sstevel@tonic-gate {
93*7c478bd9Sstevel@tonic-gate     DAT_SR_TOKEN_TYPE 	type;
94*7c478bd9Sstevel@tonic-gate     char		*value; /* valid if type is DAT_SR_TOKEN_STRING */
95*7c478bd9Sstevel@tonic-gate     DAT_OS_SIZE 	value_len;
96*7c478bd9Sstevel@tonic-gate } DAT_SR_TOKEN;
97*7c478bd9Sstevel@tonic-gate 
98*7c478bd9Sstevel@tonic-gate typedef struct DAT_SR_STACK_NODE
99*7c478bd9Sstevel@tonic-gate {
100*7c478bd9Sstevel@tonic-gate     DAT_SR_TOKEN 		token;
101*7c478bd9Sstevel@tonic-gate     struct DAT_SR_STACK_NODE    *next;
102*7c478bd9Sstevel@tonic-gate } DAT_SR_STACK_NODE;
103*7c478bd9Sstevel@tonic-gate 
104*7c478bd9Sstevel@tonic-gate typedef struct
105*7c478bd9Sstevel@tonic-gate {
106*7c478bd9Sstevel@tonic-gate     DAT_UINT32 			major;
107*7c478bd9Sstevel@tonic-gate     DAT_UINT32 			minor;
108*7c478bd9Sstevel@tonic-gate } DAT_SR_VERSION;
109*7c478bd9Sstevel@tonic-gate 
110*7c478bd9Sstevel@tonic-gate typedef struct
111*7c478bd9Sstevel@tonic-gate {
112*7c478bd9Sstevel@tonic-gate     char			*id;
113*7c478bd9Sstevel@tonic-gate     DAT_SR_VERSION 		version;
114*7c478bd9Sstevel@tonic-gate } DAT_SR_PROVIDER_VERSION;
115*7c478bd9Sstevel@tonic-gate 
116*7c478bd9Sstevel@tonic-gate typedef struct
117*7c478bd9Sstevel@tonic-gate {
118*7c478bd9Sstevel@tonic-gate     DAT_SR_API_TYPE 		type;
119*7c478bd9Sstevel@tonic-gate     DAT_SR_VERSION 		version;
120*7c478bd9Sstevel@tonic-gate } DAT_SR_API_VERSION;
121*7c478bd9Sstevel@tonic-gate 
122*7c478bd9Sstevel@tonic-gate typedef struct
123*7c478bd9Sstevel@tonic-gate {
124*7c478bd9Sstevel@tonic-gate     char			*ia_name;
125*7c478bd9Sstevel@tonic-gate     DAT_SR_API_VERSION 		api_version;
126*7c478bd9Sstevel@tonic-gate     DAT_BOOLEAN 		is_thread_safe;
127*7c478bd9Sstevel@tonic-gate     DAT_BOOLEAN 		is_default;
128*7c478bd9Sstevel@tonic-gate     char 			*lib_path;
129*7c478bd9Sstevel@tonic-gate     DAT_SR_PROVIDER_VERSION 	provider_version;
130*7c478bd9Sstevel@tonic-gate     char 			*ia_params;
131*7c478bd9Sstevel@tonic-gate     char  			*platform_params;
132*7c478bd9Sstevel@tonic-gate } DAT_SR_CONF_ENTRY;
133*7c478bd9Sstevel@tonic-gate 
134*7c478bd9Sstevel@tonic-gate 
135*7c478bd9Sstevel@tonic-gate /*
136*7c478bd9Sstevel@tonic-gate  *
137*7c478bd9Sstevel@tonic-gate  * Internal Function Declarations
138*7c478bd9Sstevel@tonic-gate  *
139*7c478bd9Sstevel@tonic-gate  */
140*7c478bd9Sstevel@tonic-gate 
141*7c478bd9Sstevel@tonic-gate static DAT_RETURN
142*7c478bd9Sstevel@tonic-gate dat_sr_load_entry(
143*7c478bd9Sstevel@tonic-gate     DAT_SR_CONF_ENTRY *entry);
144*7c478bd9Sstevel@tonic-gate 
145*7c478bd9Sstevel@tonic-gate static DAT_BOOLEAN
146*7c478bd9Sstevel@tonic-gate dat_sr_is_valid_entry(
147*7c478bd9Sstevel@tonic-gate     DAT_SR_CONF_ENTRY *entry);
148*7c478bd9Sstevel@tonic-gate 
149*7c478bd9Sstevel@tonic-gate static char *
150*7c478bd9Sstevel@tonic-gate dat_sr_type_to_str(
151*7c478bd9Sstevel@tonic-gate     DAT_SR_TOKEN_TYPE type);
152*7c478bd9Sstevel@tonic-gate 
153*7c478bd9Sstevel@tonic-gate static DAT_RETURN
154*7c478bd9Sstevel@tonic-gate dat_sr_parse_eof(
155*7c478bd9Sstevel@tonic-gate     DAT_OS_FILE *file);
156*7c478bd9Sstevel@tonic-gate 
157*7c478bd9Sstevel@tonic-gate static DAT_RETURN
158*7c478bd9Sstevel@tonic-gate dat_sr_parse_entry(
159*7c478bd9Sstevel@tonic-gate     DAT_OS_FILE *file);
160*7c478bd9Sstevel@tonic-gate 
161*7c478bd9Sstevel@tonic-gate static DAT_RETURN
162*7c478bd9Sstevel@tonic-gate dat_sr_parse_ia_name(
163*7c478bd9Sstevel@tonic-gate     DAT_OS_FILE *file,
164*7c478bd9Sstevel@tonic-gate     DAT_SR_CONF_ENTRY *entry);
165*7c478bd9Sstevel@tonic-gate 
166*7c478bd9Sstevel@tonic-gate static DAT_RETURN
167*7c478bd9Sstevel@tonic-gate dat_sr_parse_api(
168*7c478bd9Sstevel@tonic-gate     DAT_OS_FILE *file,
169*7c478bd9Sstevel@tonic-gate     DAT_SR_CONF_ENTRY *entry);
170*7c478bd9Sstevel@tonic-gate 
171*7c478bd9Sstevel@tonic-gate static DAT_RETURN
172*7c478bd9Sstevel@tonic-gate dat_sr_parse_thread_safety(
173*7c478bd9Sstevel@tonic-gate     DAT_OS_FILE *file,
174*7c478bd9Sstevel@tonic-gate     DAT_SR_CONF_ENTRY *entry);
175*7c478bd9Sstevel@tonic-gate 
176*7c478bd9Sstevel@tonic-gate static DAT_RETURN
177*7c478bd9Sstevel@tonic-gate dat_sr_parse_default(
178*7c478bd9Sstevel@tonic-gate     DAT_OS_FILE *file,
179*7c478bd9Sstevel@tonic-gate     DAT_SR_CONF_ENTRY *entry);
180*7c478bd9Sstevel@tonic-gate 
181*7c478bd9Sstevel@tonic-gate static DAT_RETURN
182*7c478bd9Sstevel@tonic-gate dat_sr_parse_lib_path(
183*7c478bd9Sstevel@tonic-gate     DAT_OS_FILE *file,
184*7c478bd9Sstevel@tonic-gate     DAT_SR_CONF_ENTRY *entry);
185*7c478bd9Sstevel@tonic-gate 
186*7c478bd9Sstevel@tonic-gate static DAT_RETURN
187*7c478bd9Sstevel@tonic-gate dat_sr_parse_provider_version(
188*7c478bd9Sstevel@tonic-gate     DAT_OS_FILE *file,
189*7c478bd9Sstevel@tonic-gate     DAT_SR_CONF_ENTRY *entry);
190*7c478bd9Sstevel@tonic-gate 
191*7c478bd9Sstevel@tonic-gate static DAT_RETURN
192*7c478bd9Sstevel@tonic-gate dat_sr_parse_ia_params(
193*7c478bd9Sstevel@tonic-gate     DAT_OS_FILE *file,
194*7c478bd9Sstevel@tonic-gate     DAT_SR_CONF_ENTRY *entry);
195*7c478bd9Sstevel@tonic-gate 
196*7c478bd9Sstevel@tonic-gate static DAT_RETURN
197*7c478bd9Sstevel@tonic-gate dat_sr_parse_platform_params(
198*7c478bd9Sstevel@tonic-gate     DAT_OS_FILE *file,
199*7c478bd9Sstevel@tonic-gate     DAT_SR_CONF_ENTRY *entry);
200*7c478bd9Sstevel@tonic-gate 
201*7c478bd9Sstevel@tonic-gate static DAT_RETURN
202*7c478bd9Sstevel@tonic-gate dat_sr_parse_eoe(
203*7c478bd9Sstevel@tonic-gate     DAT_OS_FILE *file,
204*7c478bd9Sstevel@tonic-gate     DAT_SR_CONF_ENTRY *entry);
205*7c478bd9Sstevel@tonic-gate 
206*7c478bd9Sstevel@tonic-gate static DAT_RETURN
207*7c478bd9Sstevel@tonic-gate dat_sr_convert_api(
208*7c478bd9Sstevel@tonic-gate     char *str,
209*7c478bd9Sstevel@tonic-gate     DAT_SR_API_VERSION *api_version);
210*7c478bd9Sstevel@tonic-gate 
211*7c478bd9Sstevel@tonic-gate static DAT_RETURN
212*7c478bd9Sstevel@tonic-gate dat_sr_convert_thread_safety(
213*7c478bd9Sstevel@tonic-gate     char *str,
214*7c478bd9Sstevel@tonic-gate     DAT_BOOLEAN *is_thread_safe);
215*7c478bd9Sstevel@tonic-gate 
216*7c478bd9Sstevel@tonic-gate static DAT_RETURN
217*7c478bd9Sstevel@tonic-gate dat_sr_convert_default(
218*7c478bd9Sstevel@tonic-gate     char *str,
219*7c478bd9Sstevel@tonic-gate     DAT_BOOLEAN *is_default);
220*7c478bd9Sstevel@tonic-gate 
221*7c478bd9Sstevel@tonic-gate static DAT_RETURN
222*7c478bd9Sstevel@tonic-gate dat_sr_convert_provider_version(
223*7c478bd9Sstevel@tonic-gate     char *str,
224*7c478bd9Sstevel@tonic-gate     DAT_SR_PROVIDER_VERSION *provider_version);
225*7c478bd9Sstevel@tonic-gate 
226*7c478bd9Sstevel@tonic-gate static DAT_RETURN
227*7c478bd9Sstevel@tonic-gate dat_sr_get_token(
228*7c478bd9Sstevel@tonic-gate     DAT_OS_FILE *file,
229*7c478bd9Sstevel@tonic-gate     DAT_SR_TOKEN *token);
230*7c478bd9Sstevel@tonic-gate 
231*7c478bd9Sstevel@tonic-gate static DAT_RETURN
232*7c478bd9Sstevel@tonic-gate dat_sr_put_token(
233*7c478bd9Sstevel@tonic-gate     DAT_OS_FILE *file,
234*7c478bd9Sstevel@tonic-gate     DAT_SR_TOKEN *token);
235*7c478bd9Sstevel@tonic-gate 
236*7c478bd9Sstevel@tonic-gate static DAT_RETURN
237*7c478bd9Sstevel@tonic-gate dat_sr_read_token(
238*7c478bd9Sstevel@tonic-gate     DAT_OS_FILE *file,
239*7c478bd9Sstevel@tonic-gate     DAT_SR_TOKEN *token);
240*7c478bd9Sstevel@tonic-gate 
241*7c478bd9Sstevel@tonic-gate static DAT_RETURN
242*7c478bd9Sstevel@tonic-gate dat_sr_read_str(
243*7c478bd9Sstevel@tonic-gate     DAT_OS_FILE *file,
244*7c478bd9Sstevel@tonic-gate     DAT_SR_TOKEN *token,
245*7c478bd9Sstevel@tonic-gate     DAT_OS_SIZE token_len);
246*7c478bd9Sstevel@tonic-gate 
247*7c478bd9Sstevel@tonic-gate static DAT_RETURN
248*7c478bd9Sstevel@tonic-gate dat_sr_read_quoted_str(
249*7c478bd9Sstevel@tonic-gate     DAT_OS_FILE *file,
250*7c478bd9Sstevel@tonic-gate     DAT_SR_TOKEN *token,
251*7c478bd9Sstevel@tonic-gate     DAT_OS_SIZE token_len,
252*7c478bd9Sstevel@tonic-gate     DAT_COUNT num_escape_seq);
253*7c478bd9Sstevel@tonic-gate 
254*7c478bd9Sstevel@tonic-gate static void
255*7c478bd9Sstevel@tonic-gate dat_sr_read_comment(
256*7c478bd9Sstevel@tonic-gate     DAT_OS_FILE *file);
257*7c478bd9Sstevel@tonic-gate 
258*7c478bd9Sstevel@tonic-gate 
259*7c478bd9Sstevel@tonic-gate /*
260*7c478bd9Sstevel@tonic-gate  *
261*7c478bd9Sstevel@tonic-gate  * Global Variables
262*7c478bd9Sstevel@tonic-gate  *
263*7c478bd9Sstevel@tonic-gate  */
264*7c478bd9Sstevel@tonic-gate 
265*7c478bd9Sstevel@tonic-gate static DAT_SR_STACK_NODE 	*g_token_stack = NULL;
266*7c478bd9Sstevel@tonic-gate 
267*7c478bd9Sstevel@tonic-gate 
268*7c478bd9Sstevel@tonic-gate /*
269*7c478bd9Sstevel@tonic-gate  *
270*7c478bd9Sstevel@tonic-gate  * External Function Definitions
271*7c478bd9Sstevel@tonic-gate  *
272*7c478bd9Sstevel@tonic-gate  */
273*7c478bd9Sstevel@tonic-gate 
274*7c478bd9Sstevel@tonic-gate /*
275*7c478bd9Sstevel@tonic-gate  * Function: dat_sr_load
276*7c478bd9Sstevel@tonic-gate  */
277*7c478bd9Sstevel@tonic-gate 
278*7c478bd9Sstevel@tonic-gate DAT_RETURN
dat_sr_load(void)279*7c478bd9Sstevel@tonic-gate dat_sr_load(void)
280*7c478bd9Sstevel@tonic-gate {
281*7c478bd9Sstevel@tonic-gate 	char 			*sr_path;
282*7c478bd9Sstevel@tonic-gate 	DAT_OS_FILE 		*sr_file;
283*7c478bd9Sstevel@tonic-gate 
284*7c478bd9Sstevel@tonic-gate 	sr_path = dat_os_getenv(DAT_SR_CONF_ENV);
285*7c478bd9Sstevel@tonic-gate 	if (sr_path == NULL) {
286*7c478bd9Sstevel@tonic-gate 		sr_path = DAT_SR_CONF_DEFAULT;
287*7c478bd9Sstevel@tonic-gate 	}
288*7c478bd9Sstevel@tonic-gate 
289*7c478bd9Sstevel@tonic-gate 	dat_os_dbg_print(DAT_OS_DBG_TYPE_SR,
290*7c478bd9Sstevel@tonic-gate 	    "DAT Registry: static registry file <%s> \n", sr_path);
291*7c478bd9Sstevel@tonic-gate 
292*7c478bd9Sstevel@tonic-gate 	sr_file = dat_os_fopen(sr_path);
293*7c478bd9Sstevel@tonic-gate 	if (sr_file == NULL) {
294*7c478bd9Sstevel@tonic-gate 		return (DAT_INTERNAL_ERROR);
295*7c478bd9Sstevel@tonic-gate 	}
296*7c478bd9Sstevel@tonic-gate 
297*7c478bd9Sstevel@tonic-gate 	for (;;) {
298*7c478bd9Sstevel@tonic-gate 		if (DAT_SUCCESS == dat_sr_parse_eof(sr_file)) {
299*7c478bd9Sstevel@tonic-gate 			break;
300*7c478bd9Sstevel@tonic-gate 		} else if (DAT_SUCCESS == dat_sr_parse_entry(sr_file)) {
301*7c478bd9Sstevel@tonic-gate 			continue;
302*7c478bd9Sstevel@tonic-gate 		} else {
303*7c478bd9Sstevel@tonic-gate 			dat_os_assert(!"unable to parse static registry file");
304*7c478bd9Sstevel@tonic-gate 			break;
305*7c478bd9Sstevel@tonic-gate 		}
306*7c478bd9Sstevel@tonic-gate 	}
307*7c478bd9Sstevel@tonic-gate 
308*7c478bd9Sstevel@tonic-gate 	if (0 != dat_os_fclose(sr_file)) {
309*7c478bd9Sstevel@tonic-gate 		return (DAT_INTERNAL_ERROR);
310*7c478bd9Sstevel@tonic-gate 	}
311*7c478bd9Sstevel@tonic-gate 
312*7c478bd9Sstevel@tonic-gate 	return (DAT_SUCCESS);
313*7c478bd9Sstevel@tonic-gate }
314*7c478bd9Sstevel@tonic-gate 
315*7c478bd9Sstevel@tonic-gate 
316*7c478bd9Sstevel@tonic-gate /*
317*7c478bd9Sstevel@tonic-gate  *
318*7c478bd9Sstevel@tonic-gate  * Internal Function Definitions
319*7c478bd9Sstevel@tonic-gate  *
320*7c478bd9Sstevel@tonic-gate  */
321*7c478bd9Sstevel@tonic-gate 
322*7c478bd9Sstevel@tonic-gate /*
323*7c478bd9Sstevel@tonic-gate  * Function: dat_sr_is_valid_entry
324*7c478bd9Sstevel@tonic-gate  */
325*7c478bd9Sstevel@tonic-gate 
326*7c478bd9Sstevel@tonic-gate DAT_BOOLEAN
dat_sr_is_valid_entry(DAT_SR_CONF_ENTRY * entry)327*7c478bd9Sstevel@tonic-gate dat_sr_is_valid_entry(
328*7c478bd9Sstevel@tonic-gate     DAT_SR_CONF_ENTRY *entry)
329*7c478bd9Sstevel@tonic-gate {
330*7c478bd9Sstevel@tonic-gate 	if ((DAT_SR_API_UDAT == entry->api_version.type) &&
331*7c478bd9Sstevel@tonic-gate 	    (entry->is_default)) {
332*7c478bd9Sstevel@tonic-gate 		return (DAT_TRUE);
333*7c478bd9Sstevel@tonic-gate 	} else {
334*7c478bd9Sstevel@tonic-gate 		return (DAT_FALSE);
335*7c478bd9Sstevel@tonic-gate 	}
336*7c478bd9Sstevel@tonic-gate }
337*7c478bd9Sstevel@tonic-gate 
338*7c478bd9Sstevel@tonic-gate 
339*7c478bd9Sstevel@tonic-gate /*
340*7c478bd9Sstevel@tonic-gate  * Function: dat_sr_load_entry
341*7c478bd9Sstevel@tonic-gate  */
342*7c478bd9Sstevel@tonic-gate 
343*7c478bd9Sstevel@tonic-gate DAT_RETURN
dat_sr_load_entry(DAT_SR_CONF_ENTRY * conf_entry)344*7c478bd9Sstevel@tonic-gate dat_sr_load_entry(
345*7c478bd9Sstevel@tonic-gate     DAT_SR_CONF_ENTRY *conf_entry)
346*7c478bd9Sstevel@tonic-gate {
347*7c478bd9Sstevel@tonic-gate 	DAT_SR_ENTRY entry;
348*7c478bd9Sstevel@tonic-gate 
349*7c478bd9Sstevel@tonic-gate 	if (DAT_NAME_MAX_LENGTH < (strlen(conf_entry->ia_name) + 1)) {
350*7c478bd9Sstevel@tonic-gate 		dat_os_dbg_print(DAT_OS_DBG_TYPE_SR,
351*7c478bd9Sstevel@tonic-gate 		    "DAT Registry: ia name %s is longer than "
352*7c478bd9Sstevel@tonic-gate 		    "DAT_NAME_MAX_LENGTH (%i)\n",
353*7c478bd9Sstevel@tonic-gate 		    conf_entry->ia_name, DAT_NAME_MAX_LENGTH);
354*7c478bd9Sstevel@tonic-gate 
355*7c478bd9Sstevel@tonic-gate 		return (DAT_INSUFFICIENT_RESOURCES);
356*7c478bd9Sstevel@tonic-gate 	}
357*7c478bd9Sstevel@tonic-gate 
358*7c478bd9Sstevel@tonic-gate 	(void) dat_os_strncpy(entry.info.ia_name, conf_entry->ia_name,
359*7c478bd9Sstevel@tonic-gate 	    DAT_NAME_MAX_LENGTH);
360*7c478bd9Sstevel@tonic-gate 	entry.info.dapl_version_major = conf_entry->api_version.version.major;
361*7c478bd9Sstevel@tonic-gate 	entry.info.dapl_version_minor = conf_entry->api_version.version.minor;
362*7c478bd9Sstevel@tonic-gate 	entry.info.is_thread_safe = conf_entry->is_thread_safe;
363*7c478bd9Sstevel@tonic-gate 	entry.lib_path = conf_entry->lib_path;
364*7c478bd9Sstevel@tonic-gate 	entry.ia_params = conf_entry->ia_params;
365*7c478bd9Sstevel@tonic-gate 	entry.lib_handle = NULL;
366*7c478bd9Sstevel@tonic-gate 	entry.ref_count = 0;
367*7c478bd9Sstevel@tonic-gate 
368*7c478bd9Sstevel@tonic-gate 	dat_os_dbg_print(DAT_OS_DBG_TYPE_SR,
369*7c478bd9Sstevel@tonic-gate 	    "DAT Registry: loading provider for %s\n",
370*7c478bd9Sstevel@tonic-gate 	    conf_entry->ia_name);
371*7c478bd9Sstevel@tonic-gate 
372*7c478bd9Sstevel@tonic-gate 	return (dat_sr_insert(&entry.info, &entry));
373*7c478bd9Sstevel@tonic-gate }
374*7c478bd9Sstevel@tonic-gate 
375*7c478bd9Sstevel@tonic-gate 
376*7c478bd9Sstevel@tonic-gate /*
377*7c478bd9Sstevel@tonic-gate  * Function: dat_sr_type_to_str
378*7c478bd9Sstevel@tonic-gate  */
379*7c478bd9Sstevel@tonic-gate 
380*7c478bd9Sstevel@tonic-gate char *
dat_sr_type_to_str(DAT_SR_TOKEN_TYPE type)381*7c478bd9Sstevel@tonic-gate dat_sr_type_to_str(
382*7c478bd9Sstevel@tonic-gate     DAT_SR_TOKEN_TYPE type)
383*7c478bd9Sstevel@tonic-gate {
384*7c478bd9Sstevel@tonic-gate 	static char *str_array[] = { "string", "eor", "eof" };
385*7c478bd9Sstevel@tonic-gate 
386*7c478bd9Sstevel@tonic-gate 	if ((type < 0) || (2 < type)) {
387*7c478bd9Sstevel@tonic-gate 		return ("error: invalid token type");
388*7c478bd9Sstevel@tonic-gate 	}
389*7c478bd9Sstevel@tonic-gate 
390*7c478bd9Sstevel@tonic-gate 	return (str_array[type]);
391*7c478bd9Sstevel@tonic-gate }
392*7c478bd9Sstevel@tonic-gate 
393*7c478bd9Sstevel@tonic-gate 
394*7c478bd9Sstevel@tonic-gate /*
395*7c478bd9Sstevel@tonic-gate  * Function: dat_sr_parse_eof
396*7c478bd9Sstevel@tonic-gate  */
397*7c478bd9Sstevel@tonic-gate 
398*7c478bd9Sstevel@tonic-gate DAT_RETURN
dat_sr_parse_eof(DAT_OS_FILE * file)399*7c478bd9Sstevel@tonic-gate dat_sr_parse_eof(
400*7c478bd9Sstevel@tonic-gate 	DAT_OS_FILE 		*file)
401*7c478bd9Sstevel@tonic-gate {
402*7c478bd9Sstevel@tonic-gate 	DAT_SR_TOKEN 	token;
403*7c478bd9Sstevel@tonic-gate 
404*7c478bd9Sstevel@tonic-gate 	if (DAT_SUCCESS != dat_sr_get_token(file, &token)) {
405*7c478bd9Sstevel@tonic-gate 		return (DAT_INTERNAL_ERROR);
406*7c478bd9Sstevel@tonic-gate 	}
407*7c478bd9Sstevel@tonic-gate 
408*7c478bd9Sstevel@tonic-gate 	if (DAT_SR_TOKEN_EOF == token.type) {
409*7c478bd9Sstevel@tonic-gate 		return (DAT_SUCCESS);
410*7c478bd9Sstevel@tonic-gate 	} else {
411*7c478bd9Sstevel@tonic-gate 		(void) dat_sr_put_token(file, &token);
412*7c478bd9Sstevel@tonic-gate 		return (DAT_INTERNAL_ERROR);
413*7c478bd9Sstevel@tonic-gate 	}
414*7c478bd9Sstevel@tonic-gate }
415*7c478bd9Sstevel@tonic-gate 
416*7c478bd9Sstevel@tonic-gate 
417*7c478bd9Sstevel@tonic-gate /*
418*7c478bd9Sstevel@tonic-gate  * Function: dat_sr_parse_ia_name
419*7c478bd9Sstevel@tonic-gate  */
420*7c478bd9Sstevel@tonic-gate 
421*7c478bd9Sstevel@tonic-gate DAT_RETURN
dat_sr_parse_entry(DAT_OS_FILE * file)422*7c478bd9Sstevel@tonic-gate dat_sr_parse_entry(
423*7c478bd9Sstevel@tonic-gate     DAT_OS_FILE 		*file)
424*7c478bd9Sstevel@tonic-gate {
425*7c478bd9Sstevel@tonic-gate 	DAT_SR_CONF_ENTRY		entry;
426*7c478bd9Sstevel@tonic-gate 	DAT_RETURN 			status;
427*7c478bd9Sstevel@tonic-gate 
428*7c478bd9Sstevel@tonic-gate 	(void) dat_os_memset(&entry, 0, sizeof (DAT_SR_CONF_ENTRY));
429*7c478bd9Sstevel@tonic-gate 
430*7c478bd9Sstevel@tonic-gate 	if ((DAT_SUCCESS == dat_sr_parse_ia_name(file, &entry)) &&
431*7c478bd9Sstevel@tonic-gate 	    (DAT_SUCCESS == dat_sr_parse_api(file, &entry)) &&
432*7c478bd9Sstevel@tonic-gate 	    (DAT_SUCCESS == dat_sr_parse_thread_safety(file, &entry)) &&
433*7c478bd9Sstevel@tonic-gate 	    (DAT_SUCCESS == dat_sr_parse_default(file, &entry)) &&
434*7c478bd9Sstevel@tonic-gate 	    (DAT_SUCCESS == dat_sr_parse_lib_path(file, &entry)) &&
435*7c478bd9Sstevel@tonic-gate 	    (DAT_SUCCESS == dat_sr_parse_provider_version(file, &entry)) &&
436*7c478bd9Sstevel@tonic-gate 	    (DAT_SUCCESS == dat_sr_parse_ia_params(file, &entry)) &&
437*7c478bd9Sstevel@tonic-gate 	    (DAT_SUCCESS == dat_sr_parse_platform_params(file, &entry)) &&
438*7c478bd9Sstevel@tonic-gate 	    (DAT_SUCCESS == dat_sr_parse_eoe(file, &entry))) {
439*7c478bd9Sstevel@tonic-gate 		dat_os_dbg_print(DAT_OS_DBG_TYPE_SR,
440*7c478bd9Sstevel@tonic-gate 		    "\n"
441*7c478bd9Sstevel@tonic-gate 		    "DAT Registry: entry \n"
442*7c478bd9Sstevel@tonic-gate 		    " ia_name %s\n"
443*7c478bd9Sstevel@tonic-gate 		    " api_version\n"
444*7c478bd9Sstevel@tonic-gate 		    "     type 0x%X\n"
445*7c478bd9Sstevel@tonic-gate 		    "     major.minor %d.%d\n"
446*7c478bd9Sstevel@tonic-gate 		    " is_thread_safe %d\n"
447*7c478bd9Sstevel@tonic-gate 		    " is_default %d\n"
448*7c478bd9Sstevel@tonic-gate 		    " lib_path %s\n"
449*7c478bd9Sstevel@tonic-gate 		    " provider_version\n"
450*7c478bd9Sstevel@tonic-gate 		    "     id %s\n"
451*7c478bd9Sstevel@tonic-gate 		    "     major.minor %d.%d\n"
452*7c478bd9Sstevel@tonic-gate 		    " ia_params %s\n"
453*7c478bd9Sstevel@tonic-gate 		    "\n",
454*7c478bd9Sstevel@tonic-gate 		    entry.ia_name,
455*7c478bd9Sstevel@tonic-gate 		    entry.api_version.type,
456*7c478bd9Sstevel@tonic-gate 		    entry.api_version.version.major,
457*7c478bd9Sstevel@tonic-gate 		    entry.api_version.version.minor,
458*7c478bd9Sstevel@tonic-gate 		    entry.is_thread_safe,
459*7c478bd9Sstevel@tonic-gate 		    entry.is_default,
460*7c478bd9Sstevel@tonic-gate 		    entry.lib_path,
461*7c478bd9Sstevel@tonic-gate 		    entry.provider_version.id,
462*7c478bd9Sstevel@tonic-gate 		    entry.provider_version.version.major,
463*7c478bd9Sstevel@tonic-gate 		    entry.provider_version.version.minor,
464*7c478bd9Sstevel@tonic-gate 		    entry.ia_params);
465*7c478bd9Sstevel@tonic-gate 
466*7c478bd9Sstevel@tonic-gate 		if (DAT_TRUE == dat_sr_is_valid_entry(&entry)) {
467*7c478bd9Sstevel@tonic-gate 			/*
468*7c478bd9Sstevel@tonic-gate 			 * The static registry configuration file may have
469*7c478bd9Sstevel@tonic-gate 			 * multiple entries with the same IA name. The first
470*7c478bd9Sstevel@tonic-gate 			 * entry will be installed in the static registry
471*7c478bd9Sstevel@tonic-gate 			 * causing subsequent attempts to register the same IA
472*7c478bd9Sstevel@tonic-gate 			 * name to fail. Therefore the return code from
473*7c478bd9Sstevel@tonic-gate 			 * dat_sr_load_entry() is ignored.
474*7c478bd9Sstevel@tonic-gate 			 */
475*7c478bd9Sstevel@tonic-gate 			(void) dat_sr_load_entry(&entry);
476*7c478bd9Sstevel@tonic-gate 		}
477*7c478bd9Sstevel@tonic-gate 
478*7c478bd9Sstevel@tonic-gate 		status = DAT_SUCCESS;
479*7c478bd9Sstevel@tonic-gate 	} else { /* resync */
480*7c478bd9Sstevel@tonic-gate 		DAT_SR_TOKEN 		token;
481*7c478bd9Sstevel@tonic-gate 
482*7c478bd9Sstevel@tonic-gate 		/*
483*7c478bd9Sstevel@tonic-gate 		 * The static registry format is specified in the DAT
484*7c478bd9Sstevel@tonic-gate 		 * specification. While the registry file's contents may change
485*7c478bd9Sstevel@tonic-gate 		 * between revisions of the specification, there is no way to
486*7c478bd9Sstevel@tonic-gate 		 * determine the specification version to which the
487*7c478bd9Sstevel@tonic-gate 		 * configuration file conforms. If an entry is found that does
488*7c478bd9Sstevel@tonic-gate 		 * not match the expected format, the entry is discarded
489*7c478bd9Sstevel@tonic-gate 		 * and the parsing of the file continues. There is no way to
490*7c478bd9Sstevel@tonic-gate 		 * determine if the entry was an error or an entry confirming
491*7c478bd9Sstevel@tonic-gate 		 * to an alternate version of specification.
492*7c478bd9Sstevel@tonic-gate 		 */
493*7c478bd9Sstevel@tonic-gate 
494*7c478bd9Sstevel@tonic-gate 		for (;;) {
495*7c478bd9Sstevel@tonic-gate 			if (DAT_SUCCESS != dat_sr_get_token(file, &token)) {
496*7c478bd9Sstevel@tonic-gate 				status = DAT_INTERNAL_ERROR;
497*7c478bd9Sstevel@tonic-gate 				break;
498*7c478bd9Sstevel@tonic-gate 			}
499*7c478bd9Sstevel@tonic-gate 
500*7c478bd9Sstevel@tonic-gate 			if (DAT_SR_TOKEN_STRING != token.type) {
501*7c478bd9Sstevel@tonic-gate 				status = DAT_SUCCESS;
502*7c478bd9Sstevel@tonic-gate 				break;
503*7c478bd9Sstevel@tonic-gate 			} else {
504*7c478bd9Sstevel@tonic-gate 				dat_os_free(token.value,
505*7c478bd9Sstevel@tonic-gate 				    (sizeof (char) *
506*7c478bd9Sstevel@tonic-gate 					dat_os_strlen(token.value)) + 1);
507*7c478bd9Sstevel@tonic-gate 				continue;
508*7c478bd9Sstevel@tonic-gate 			}
509*7c478bd9Sstevel@tonic-gate 		}
510*7c478bd9Sstevel@tonic-gate 	}
511*7c478bd9Sstevel@tonic-gate 
512*7c478bd9Sstevel@tonic-gate 	/* free resources */
513*7c478bd9Sstevel@tonic-gate 	if (NULL != entry.ia_name) {
514*7c478bd9Sstevel@tonic-gate 		dat_os_free(entry.ia_name,
515*7c478bd9Sstevel@tonic-gate 		    sizeof (char) * (dat_os_strlen(entry.ia_name) + 1));
516*7c478bd9Sstevel@tonic-gate 	}
517*7c478bd9Sstevel@tonic-gate 	if (NULL != entry.lib_path) {
518*7c478bd9Sstevel@tonic-gate 		dat_os_free(entry.lib_path,
519*7c478bd9Sstevel@tonic-gate 		    sizeof (char) * (dat_os_strlen(entry.lib_path) + 1));
520*7c478bd9Sstevel@tonic-gate 	}
521*7c478bd9Sstevel@tonic-gate 
522*7c478bd9Sstevel@tonic-gate 	if (NULL != entry.provider_version.id) {
523*7c478bd9Sstevel@tonic-gate 		dat_os_free(entry.provider_version.id,
524*7c478bd9Sstevel@tonic-gate 		    sizeof (char) *
525*7c478bd9Sstevel@tonic-gate 		    (dat_os_strlen(entry.provider_version.id) + 1));
526*7c478bd9Sstevel@tonic-gate 	}
527*7c478bd9Sstevel@tonic-gate 
528*7c478bd9Sstevel@tonic-gate 	if (NULL != entry.ia_params) {
529*7c478bd9Sstevel@tonic-gate 		dat_os_free(entry.ia_params,
530*7c478bd9Sstevel@tonic-gate 		    sizeof (char) * (dat_os_strlen(entry.ia_params) + 1));
531*7c478bd9Sstevel@tonic-gate 	}
532*7c478bd9Sstevel@tonic-gate 
533*7c478bd9Sstevel@tonic-gate 	return (status);
534*7c478bd9Sstevel@tonic-gate }
535*7c478bd9Sstevel@tonic-gate 
536*7c478bd9Sstevel@tonic-gate 
537*7c478bd9Sstevel@tonic-gate /*
538*7c478bd9Sstevel@tonic-gate  * Function: dat_sr_parse_ia_name
539*7c478bd9Sstevel@tonic-gate  */
540*7c478bd9Sstevel@tonic-gate 
541*7c478bd9Sstevel@tonic-gate DAT_RETURN
dat_sr_parse_ia_name(DAT_OS_FILE * file,DAT_SR_CONF_ENTRY * entry)542*7c478bd9Sstevel@tonic-gate dat_sr_parse_ia_name(
543*7c478bd9Sstevel@tonic-gate     DAT_OS_FILE 	*file,
544*7c478bd9Sstevel@tonic-gate     DAT_SR_CONF_ENTRY 	*entry)
545*7c478bd9Sstevel@tonic-gate {
546*7c478bd9Sstevel@tonic-gate 	DAT_SR_TOKEN 	token;
547*7c478bd9Sstevel@tonic-gate 	DAT_RETURN 	status;
548*7c478bd9Sstevel@tonic-gate 
549*7c478bd9Sstevel@tonic-gate 	if (DAT_SUCCESS != dat_sr_get_token(file, &token)) {
550*7c478bd9Sstevel@tonic-gate 		return (DAT_INTERNAL_ERROR);
551*7c478bd9Sstevel@tonic-gate 	}
552*7c478bd9Sstevel@tonic-gate 
553*7c478bd9Sstevel@tonic-gate 	if (DAT_SR_TOKEN_STRING != token.type) {
554*7c478bd9Sstevel@tonic-gate 		status = DAT_INTERNAL_ERROR;
555*7c478bd9Sstevel@tonic-gate 	} else {
556*7c478bd9Sstevel@tonic-gate 		entry->ia_name = token.value;
557*7c478bd9Sstevel@tonic-gate 
558*7c478bd9Sstevel@tonic-gate 		status = DAT_SUCCESS;
559*7c478bd9Sstevel@tonic-gate 	}
560*7c478bd9Sstevel@tonic-gate 
561*7c478bd9Sstevel@tonic-gate 	if (DAT_SUCCESS != status) {
562*7c478bd9Sstevel@tonic-gate 		DAT_RETURN 	status_success;
563*7c478bd9Sstevel@tonic-gate 
564*7c478bd9Sstevel@tonic-gate 		status_success = dat_sr_put_token(file, &token);
565*7c478bd9Sstevel@tonic-gate 		dat_os_assert(DAT_SUCCESS == status_success);
566*7c478bd9Sstevel@tonic-gate 	}
567*7c478bd9Sstevel@tonic-gate 
568*7c478bd9Sstevel@tonic-gate 	return (status);
569*7c478bd9Sstevel@tonic-gate }
570*7c478bd9Sstevel@tonic-gate 
571*7c478bd9Sstevel@tonic-gate 
572*7c478bd9Sstevel@tonic-gate /*
573*7c478bd9Sstevel@tonic-gate  * Function: dat_sr_parse_ia_name
574*7c478bd9Sstevel@tonic-gate  */
575*7c478bd9Sstevel@tonic-gate 
576*7c478bd9Sstevel@tonic-gate DAT_RETURN
dat_sr_parse_api(DAT_OS_FILE * file,DAT_SR_CONF_ENTRY * entry)577*7c478bd9Sstevel@tonic-gate dat_sr_parse_api(
578*7c478bd9Sstevel@tonic-gate     DAT_OS_FILE 	*file,
579*7c478bd9Sstevel@tonic-gate     DAT_SR_CONF_ENTRY 	*entry)
580*7c478bd9Sstevel@tonic-gate {
581*7c478bd9Sstevel@tonic-gate 	DAT_SR_TOKEN 	token;
582*7c478bd9Sstevel@tonic-gate 	DAT_RETURN 	status;
583*7c478bd9Sstevel@tonic-gate 
584*7c478bd9Sstevel@tonic-gate 	if (DAT_SUCCESS != dat_sr_get_token(file, &token)) {
585*7c478bd9Sstevel@tonic-gate 		return (DAT_INTERNAL_ERROR);
586*7c478bd9Sstevel@tonic-gate 	}
587*7c478bd9Sstevel@tonic-gate 
588*7c478bd9Sstevel@tonic-gate 	if (DAT_SR_TOKEN_STRING != token.type) {
589*7c478bd9Sstevel@tonic-gate 		status = DAT_INTERNAL_ERROR;
590*7c478bd9Sstevel@tonic-gate 	} else if (DAT_SUCCESS != dat_sr_convert_api(
591*7c478bd9Sstevel@tonic-gate 		token.value, &entry->api_version)) {
592*7c478bd9Sstevel@tonic-gate 		status = DAT_INTERNAL_ERROR;
593*7c478bd9Sstevel@tonic-gate 	} else {
594*7c478bd9Sstevel@tonic-gate 		dat_os_free(token.value,
595*7c478bd9Sstevel@tonic-gate 		    (sizeof (char) * dat_os_strlen(token.value)) + 1);
596*7c478bd9Sstevel@tonic-gate 
597*7c478bd9Sstevel@tonic-gate 		status = DAT_SUCCESS;
598*7c478bd9Sstevel@tonic-gate 	}
599*7c478bd9Sstevel@tonic-gate 
600*7c478bd9Sstevel@tonic-gate 	if (DAT_SUCCESS != status) {
601*7c478bd9Sstevel@tonic-gate 		DAT_RETURN 	status_success;
602*7c478bd9Sstevel@tonic-gate 
603*7c478bd9Sstevel@tonic-gate 		status_success = dat_sr_put_token(file, &token);
604*7c478bd9Sstevel@tonic-gate 		dat_os_assert(DAT_SUCCESS == status_success);
605*7c478bd9Sstevel@tonic-gate 	}
606*7c478bd9Sstevel@tonic-gate 
607*7c478bd9Sstevel@tonic-gate 	return (status);
608*7c478bd9Sstevel@tonic-gate }
609*7c478bd9Sstevel@tonic-gate 
610*7c478bd9Sstevel@tonic-gate 
611*7c478bd9Sstevel@tonic-gate /*
612*7c478bd9Sstevel@tonic-gate  * Function: dat_sr_parse_thread_safety
613*7c478bd9Sstevel@tonic-gate  */
614*7c478bd9Sstevel@tonic-gate 
615*7c478bd9Sstevel@tonic-gate static DAT_RETURN
dat_sr_parse_thread_safety(DAT_OS_FILE * file,DAT_SR_CONF_ENTRY * entry)616*7c478bd9Sstevel@tonic-gate dat_sr_parse_thread_safety(
617*7c478bd9Sstevel@tonic-gate     DAT_OS_FILE 	*file,
618*7c478bd9Sstevel@tonic-gate     DAT_SR_CONF_ENTRY 	*entry)
619*7c478bd9Sstevel@tonic-gate {
620*7c478bd9Sstevel@tonic-gate 	DAT_SR_TOKEN 	token;
621*7c478bd9Sstevel@tonic-gate 	DAT_RETURN 	status;
622*7c478bd9Sstevel@tonic-gate 
623*7c478bd9Sstevel@tonic-gate 	if (DAT_SUCCESS != dat_sr_get_token(file, &token)) {
624*7c478bd9Sstevel@tonic-gate 		return (DAT_INTERNAL_ERROR);
625*7c478bd9Sstevel@tonic-gate 	}
626*7c478bd9Sstevel@tonic-gate 
627*7c478bd9Sstevel@tonic-gate 	if (DAT_SR_TOKEN_STRING != token.type) {
628*7c478bd9Sstevel@tonic-gate 		status = DAT_INTERNAL_ERROR;
629*7c478bd9Sstevel@tonic-gate 	} else if (DAT_SUCCESS != dat_sr_convert_thread_safety(
630*7c478bd9Sstevel@tonic-gate 		token.value, &entry->is_thread_safe)) {
631*7c478bd9Sstevel@tonic-gate 		status = DAT_INTERNAL_ERROR;
632*7c478bd9Sstevel@tonic-gate 	} else {
633*7c478bd9Sstevel@tonic-gate 		dat_os_free(token.value,
634*7c478bd9Sstevel@tonic-gate 		    (sizeof (char) * dat_os_strlen(token.value)) + 1);
635*7c478bd9Sstevel@tonic-gate 
636*7c478bd9Sstevel@tonic-gate 		status = DAT_SUCCESS;
637*7c478bd9Sstevel@tonic-gate 	}
638*7c478bd9Sstevel@tonic-gate 
639*7c478bd9Sstevel@tonic-gate 	if (DAT_SUCCESS != status) {
640*7c478bd9Sstevel@tonic-gate 		DAT_RETURN 	status_success;
641*7c478bd9Sstevel@tonic-gate 
642*7c478bd9Sstevel@tonic-gate 		status_success = dat_sr_put_token(file, &token);
643*7c478bd9Sstevel@tonic-gate 		dat_os_assert(DAT_SUCCESS == status_success);
644*7c478bd9Sstevel@tonic-gate 	}
645*7c478bd9Sstevel@tonic-gate 
646*7c478bd9Sstevel@tonic-gate 	return (status);
647*7c478bd9Sstevel@tonic-gate }
648*7c478bd9Sstevel@tonic-gate 
649*7c478bd9Sstevel@tonic-gate 
650*7c478bd9Sstevel@tonic-gate /*
651*7c478bd9Sstevel@tonic-gate  * Function: dat_sr_parse_default
652*7c478bd9Sstevel@tonic-gate  */
653*7c478bd9Sstevel@tonic-gate 
654*7c478bd9Sstevel@tonic-gate DAT_RETURN
dat_sr_parse_default(DAT_OS_FILE * file,DAT_SR_CONF_ENTRY * entry)655*7c478bd9Sstevel@tonic-gate dat_sr_parse_default(
656*7c478bd9Sstevel@tonic-gate     DAT_OS_FILE 	*file,
657*7c478bd9Sstevel@tonic-gate     DAT_SR_CONF_ENTRY 	*entry)
658*7c478bd9Sstevel@tonic-gate {
659*7c478bd9Sstevel@tonic-gate 	DAT_SR_TOKEN 	token;
660*7c478bd9Sstevel@tonic-gate 	DAT_RETURN 	status;
661*7c478bd9Sstevel@tonic-gate 
662*7c478bd9Sstevel@tonic-gate 	if (DAT_SUCCESS != dat_sr_get_token(file, &token)) {
663*7c478bd9Sstevel@tonic-gate 		return (DAT_INTERNAL_ERROR);
664*7c478bd9Sstevel@tonic-gate 	}
665*7c478bd9Sstevel@tonic-gate 
666*7c478bd9Sstevel@tonic-gate 	if (DAT_SR_TOKEN_STRING != token.type) {
667*7c478bd9Sstevel@tonic-gate 		status = DAT_INTERNAL_ERROR;
668*7c478bd9Sstevel@tonic-gate 	} else if (DAT_SUCCESS != dat_sr_convert_default(
669*7c478bd9Sstevel@tonic-gate 		token.value, &entry->is_default)) {
670*7c478bd9Sstevel@tonic-gate 		status = DAT_INTERNAL_ERROR;
671*7c478bd9Sstevel@tonic-gate 	} else {
672*7c478bd9Sstevel@tonic-gate 		dat_os_free(token.value,
673*7c478bd9Sstevel@tonic-gate 		    (sizeof (char) * dat_os_strlen(token.value)) + 1);
674*7c478bd9Sstevel@tonic-gate 
675*7c478bd9Sstevel@tonic-gate 		status = DAT_SUCCESS;
676*7c478bd9Sstevel@tonic-gate 	}
677*7c478bd9Sstevel@tonic-gate 
678*7c478bd9Sstevel@tonic-gate 	if (DAT_SUCCESS != status) {
679*7c478bd9Sstevel@tonic-gate 		DAT_RETURN 	status_success;
680*7c478bd9Sstevel@tonic-gate 
681*7c478bd9Sstevel@tonic-gate 		status_success = dat_sr_put_token(file, &token);
682*7c478bd9Sstevel@tonic-gate 		dat_os_assert(DAT_SUCCESS == status_success);
683*7c478bd9Sstevel@tonic-gate 	}
684*7c478bd9Sstevel@tonic-gate 
685*7c478bd9Sstevel@tonic-gate 	return (status);
686*7c478bd9Sstevel@tonic-gate }
687*7c478bd9Sstevel@tonic-gate 
688*7c478bd9Sstevel@tonic-gate 
689*7c478bd9Sstevel@tonic-gate /*
690*7c478bd9Sstevel@tonic-gate  * Function: dat_sr_parse_lib_path
691*7c478bd9Sstevel@tonic-gate  */
692*7c478bd9Sstevel@tonic-gate 
693*7c478bd9Sstevel@tonic-gate DAT_RETURN
dat_sr_parse_lib_path(DAT_OS_FILE * file,DAT_SR_CONF_ENTRY * entry)694*7c478bd9Sstevel@tonic-gate dat_sr_parse_lib_path(
695*7c478bd9Sstevel@tonic-gate     DAT_OS_FILE 	*file,
696*7c478bd9Sstevel@tonic-gate     DAT_SR_CONF_ENTRY 	*entry)
697*7c478bd9Sstevel@tonic-gate {
698*7c478bd9Sstevel@tonic-gate 	DAT_SR_TOKEN 	token;
699*7c478bd9Sstevel@tonic-gate 	DAT_RETURN 	status;
700*7c478bd9Sstevel@tonic-gate 
701*7c478bd9Sstevel@tonic-gate 	if (DAT_SUCCESS != dat_sr_get_token(file, &token)) {
702*7c478bd9Sstevel@tonic-gate 		return (DAT_INTERNAL_ERROR);
703*7c478bd9Sstevel@tonic-gate 	}
704*7c478bd9Sstevel@tonic-gate 
705*7c478bd9Sstevel@tonic-gate 	if (DAT_SR_TOKEN_STRING != token.type) {
706*7c478bd9Sstevel@tonic-gate 		status = DAT_INTERNAL_ERROR;
707*7c478bd9Sstevel@tonic-gate 	} else {
708*7c478bd9Sstevel@tonic-gate 		entry->lib_path = token.value;
709*7c478bd9Sstevel@tonic-gate 
710*7c478bd9Sstevel@tonic-gate 		status = DAT_SUCCESS;
711*7c478bd9Sstevel@tonic-gate 	}
712*7c478bd9Sstevel@tonic-gate 
713*7c478bd9Sstevel@tonic-gate 	if (DAT_SUCCESS != status) {
714*7c478bd9Sstevel@tonic-gate 		DAT_RETURN 	status_success;
715*7c478bd9Sstevel@tonic-gate 
716*7c478bd9Sstevel@tonic-gate 		status_success = dat_sr_put_token(file, &token);
717*7c478bd9Sstevel@tonic-gate 		dat_os_assert(DAT_SUCCESS == status_success);
718*7c478bd9Sstevel@tonic-gate 	}
719*7c478bd9Sstevel@tonic-gate 
720*7c478bd9Sstevel@tonic-gate 	return (status);
721*7c478bd9Sstevel@tonic-gate }
722*7c478bd9Sstevel@tonic-gate 
723*7c478bd9Sstevel@tonic-gate /*
724*7c478bd9Sstevel@tonic-gate  * Function: dat_sr_parse_provider_version
725*7c478bd9Sstevel@tonic-gate  */
726*7c478bd9Sstevel@tonic-gate 
727*7c478bd9Sstevel@tonic-gate DAT_RETURN
dat_sr_parse_provider_version(DAT_OS_FILE * file,DAT_SR_CONF_ENTRY * entry)728*7c478bd9Sstevel@tonic-gate dat_sr_parse_provider_version(
729*7c478bd9Sstevel@tonic-gate     DAT_OS_FILE 	*file,
730*7c478bd9Sstevel@tonic-gate     DAT_SR_CONF_ENTRY 	*entry)
731*7c478bd9Sstevel@tonic-gate {
732*7c478bd9Sstevel@tonic-gate 	DAT_SR_TOKEN 	token;
733*7c478bd9Sstevel@tonic-gate 	DAT_RETURN 	status;
734*7c478bd9Sstevel@tonic-gate 
735*7c478bd9Sstevel@tonic-gate 	if (DAT_SUCCESS != dat_sr_get_token(file, &token)) {
736*7c478bd9Sstevel@tonic-gate 		return (DAT_INTERNAL_ERROR);
737*7c478bd9Sstevel@tonic-gate 	}
738*7c478bd9Sstevel@tonic-gate 
739*7c478bd9Sstevel@tonic-gate 	if (DAT_SR_TOKEN_STRING != token.type) {
740*7c478bd9Sstevel@tonic-gate 		status = DAT_INTERNAL_ERROR;
741*7c478bd9Sstevel@tonic-gate 	} else if (DAT_SUCCESS != dat_sr_convert_provider_version(
742*7c478bd9Sstevel@tonic-gate 		token.value, &entry->provider_version)) {
743*7c478bd9Sstevel@tonic-gate 		status = DAT_INTERNAL_ERROR;
744*7c478bd9Sstevel@tonic-gate 	} else {
745*7c478bd9Sstevel@tonic-gate 		dat_os_free(token.value,
746*7c478bd9Sstevel@tonic-gate 		    (sizeof (char) * dat_os_strlen(token.value)) + 1);
747*7c478bd9Sstevel@tonic-gate 
748*7c478bd9Sstevel@tonic-gate 		status = DAT_SUCCESS;
749*7c478bd9Sstevel@tonic-gate 	}
750*7c478bd9Sstevel@tonic-gate 
751*7c478bd9Sstevel@tonic-gate 	if (DAT_SUCCESS != status) {
752*7c478bd9Sstevel@tonic-gate 		DAT_RETURN 	status_success;
753*7c478bd9Sstevel@tonic-gate 
754*7c478bd9Sstevel@tonic-gate 		status_success = dat_sr_put_token(file, &token);
755*7c478bd9Sstevel@tonic-gate 		dat_os_assert(DAT_SUCCESS == status_success);
756*7c478bd9Sstevel@tonic-gate 	}
757*7c478bd9Sstevel@tonic-gate 
758*7c478bd9Sstevel@tonic-gate 	return (status);
759*7c478bd9Sstevel@tonic-gate }
760*7c478bd9Sstevel@tonic-gate 
761*7c478bd9Sstevel@tonic-gate 
762*7c478bd9Sstevel@tonic-gate /*
763*7c478bd9Sstevel@tonic-gate  * Function: dat_sr_parse_ia_params
764*7c478bd9Sstevel@tonic-gate  */
765*7c478bd9Sstevel@tonic-gate 
766*7c478bd9Sstevel@tonic-gate DAT_RETURN
dat_sr_parse_ia_params(DAT_OS_FILE * file,DAT_SR_CONF_ENTRY * entry)767*7c478bd9Sstevel@tonic-gate dat_sr_parse_ia_params(
768*7c478bd9Sstevel@tonic-gate     DAT_OS_FILE *file,
769*7c478bd9Sstevel@tonic-gate     DAT_SR_CONF_ENTRY *entry)
770*7c478bd9Sstevel@tonic-gate {
771*7c478bd9Sstevel@tonic-gate 	DAT_SR_TOKEN 	token;
772*7c478bd9Sstevel@tonic-gate 	DAT_RETURN 	status;
773*7c478bd9Sstevel@tonic-gate 
774*7c478bd9Sstevel@tonic-gate 	if (DAT_SUCCESS != dat_sr_get_token(file, &token)) {
775*7c478bd9Sstevel@tonic-gate 		return (DAT_INTERNAL_ERROR);
776*7c478bd9Sstevel@tonic-gate 	}
777*7c478bd9Sstevel@tonic-gate 
778*7c478bd9Sstevel@tonic-gate 	if (DAT_SR_TOKEN_STRING != token.type) {
779*7c478bd9Sstevel@tonic-gate 		status = DAT_INTERNAL_ERROR;
780*7c478bd9Sstevel@tonic-gate 	} else {
781*7c478bd9Sstevel@tonic-gate 		entry->ia_params = token.value;
782*7c478bd9Sstevel@tonic-gate 
783*7c478bd9Sstevel@tonic-gate 		status = DAT_SUCCESS;
784*7c478bd9Sstevel@tonic-gate 	}
785*7c478bd9Sstevel@tonic-gate 
786*7c478bd9Sstevel@tonic-gate 	if (DAT_SUCCESS != status) {
787*7c478bd9Sstevel@tonic-gate 		DAT_RETURN 	status_success;
788*7c478bd9Sstevel@tonic-gate 
789*7c478bd9Sstevel@tonic-gate 		status_success = dat_sr_put_token(file, &token);
790*7c478bd9Sstevel@tonic-gate 		dat_os_assert(DAT_SUCCESS == status_success);
791*7c478bd9Sstevel@tonic-gate 	}
792*7c478bd9Sstevel@tonic-gate 
793*7c478bd9Sstevel@tonic-gate 	return (status);
794*7c478bd9Sstevel@tonic-gate }
795*7c478bd9Sstevel@tonic-gate 
796*7c478bd9Sstevel@tonic-gate 
797*7c478bd9Sstevel@tonic-gate /*
798*7c478bd9Sstevel@tonic-gate  * Function: dat_sr_parse_platform_params
799*7c478bd9Sstevel@tonic-gate  */
800*7c478bd9Sstevel@tonic-gate 
801*7c478bd9Sstevel@tonic-gate DAT_RETURN
dat_sr_parse_platform_params(DAT_OS_FILE * file,DAT_SR_CONF_ENTRY * entry)802*7c478bd9Sstevel@tonic-gate dat_sr_parse_platform_params(
803*7c478bd9Sstevel@tonic-gate     DAT_OS_FILE *file,
804*7c478bd9Sstevel@tonic-gate     DAT_SR_CONF_ENTRY *entry)
805*7c478bd9Sstevel@tonic-gate {
806*7c478bd9Sstevel@tonic-gate 	DAT_SR_TOKEN 	token;
807*7c478bd9Sstevel@tonic-gate 	DAT_RETURN 	status;
808*7c478bd9Sstevel@tonic-gate 
809*7c478bd9Sstevel@tonic-gate 	if (DAT_SUCCESS != dat_sr_get_token(file, &token)) {
810*7c478bd9Sstevel@tonic-gate 		return (DAT_INTERNAL_ERROR);
811*7c478bd9Sstevel@tonic-gate 	}
812*7c478bd9Sstevel@tonic-gate 
813*7c478bd9Sstevel@tonic-gate 	if (DAT_SR_TOKEN_STRING != token.type) {
814*7c478bd9Sstevel@tonic-gate 		status = DAT_INTERNAL_ERROR;
815*7c478bd9Sstevel@tonic-gate 	} else {
816*7c478bd9Sstevel@tonic-gate 		entry->platform_params = token.value;
817*7c478bd9Sstevel@tonic-gate 
818*7c478bd9Sstevel@tonic-gate 		status = DAT_SUCCESS;
819*7c478bd9Sstevel@tonic-gate 	}
820*7c478bd9Sstevel@tonic-gate 
821*7c478bd9Sstevel@tonic-gate 	if (DAT_SUCCESS != status) {
822*7c478bd9Sstevel@tonic-gate 		DAT_RETURN 	status_success;
823*7c478bd9Sstevel@tonic-gate 
824*7c478bd9Sstevel@tonic-gate 		status_success = dat_sr_put_token(file, &token);
825*7c478bd9Sstevel@tonic-gate 		dat_os_assert(DAT_SUCCESS == status_success);
826*7c478bd9Sstevel@tonic-gate 	}
827*7c478bd9Sstevel@tonic-gate 
828*7c478bd9Sstevel@tonic-gate 	return (status);
829*7c478bd9Sstevel@tonic-gate }
830*7c478bd9Sstevel@tonic-gate 
831*7c478bd9Sstevel@tonic-gate 
832*7c478bd9Sstevel@tonic-gate /*
833*7c478bd9Sstevel@tonic-gate  * Function: dat_sr_parse_eoe
834*7c478bd9Sstevel@tonic-gate  */
835*7c478bd9Sstevel@tonic-gate 
836*7c478bd9Sstevel@tonic-gate DAT_RETURN
dat_sr_parse_eoe(DAT_OS_FILE * file,DAT_SR_CONF_ENTRY * entry)837*7c478bd9Sstevel@tonic-gate dat_sr_parse_eoe(
838*7c478bd9Sstevel@tonic-gate     DAT_OS_FILE *file,
839*7c478bd9Sstevel@tonic-gate 	DAT_SR_CONF_ENTRY *entry) /*ARGSUSED*/
840*7c478bd9Sstevel@tonic-gate {
841*7c478bd9Sstevel@tonic-gate 	DAT_SR_TOKEN 	token;
842*7c478bd9Sstevel@tonic-gate 	DAT_RETURN 	status;
843*7c478bd9Sstevel@tonic-gate 
844*7c478bd9Sstevel@tonic-gate 	if (DAT_SUCCESS != dat_sr_get_token(file, &token)) {
845*7c478bd9Sstevel@tonic-gate 		return (DAT_INTERNAL_ERROR);
846*7c478bd9Sstevel@tonic-gate 	}
847*7c478bd9Sstevel@tonic-gate 
848*7c478bd9Sstevel@tonic-gate 	if ((DAT_SR_TOKEN_EOF != token.type) &&
849*7c478bd9Sstevel@tonic-gate 	    (DAT_SR_TOKEN_EOR != token.type)) {
850*7c478bd9Sstevel@tonic-gate 		status = DAT_INTERNAL_ERROR;
851*7c478bd9Sstevel@tonic-gate 	} else {
852*7c478bd9Sstevel@tonic-gate 		status = DAT_SUCCESS;
853*7c478bd9Sstevel@tonic-gate 	}
854*7c478bd9Sstevel@tonic-gate 
855*7c478bd9Sstevel@tonic-gate 	if (DAT_SUCCESS != status) {
856*7c478bd9Sstevel@tonic-gate 		DAT_RETURN 	status_success;
857*7c478bd9Sstevel@tonic-gate 
858*7c478bd9Sstevel@tonic-gate 		status_success = dat_sr_put_token(file, &token);
859*7c478bd9Sstevel@tonic-gate 		dat_os_assert(DAT_SUCCESS == status_success);
860*7c478bd9Sstevel@tonic-gate 	}
861*7c478bd9Sstevel@tonic-gate 
862*7c478bd9Sstevel@tonic-gate 	return (status);
863*7c478bd9Sstevel@tonic-gate }
864*7c478bd9Sstevel@tonic-gate 
865*7c478bd9Sstevel@tonic-gate 
866*7c478bd9Sstevel@tonic-gate /*
867*7c478bd9Sstevel@tonic-gate  * Function: dat_sr_convert_api
868*7c478bd9Sstevel@tonic-gate  */
869*7c478bd9Sstevel@tonic-gate 
870*7c478bd9Sstevel@tonic-gate DAT_RETURN
dat_sr_convert_api(char * str,DAT_SR_API_VERSION * api_version)871*7c478bd9Sstevel@tonic-gate dat_sr_convert_api(
872*7c478bd9Sstevel@tonic-gate     char *str,
873*7c478bd9Sstevel@tonic-gate     DAT_SR_API_VERSION *api_version)
874*7c478bd9Sstevel@tonic-gate {
875*7c478bd9Sstevel@tonic-gate 	int i;
876*7c478bd9Sstevel@tonic-gate 	int minor_i;
877*7c478bd9Sstevel@tonic-gate 
878*7c478bd9Sstevel@tonic-gate 	dat_os_assert(0 < dat_os_strlen(str));
879*7c478bd9Sstevel@tonic-gate 
880*7c478bd9Sstevel@tonic-gate 	if ('u' == str[0]) {
881*7c478bd9Sstevel@tonic-gate 		api_version->type = DAT_SR_API_UDAT;
882*7c478bd9Sstevel@tonic-gate 	} else if ('k' == str[0]) {
883*7c478bd9Sstevel@tonic-gate 		api_version->type = DAT_SR_API_KDAT;
884*7c478bd9Sstevel@tonic-gate 	} else {
885*7c478bd9Sstevel@tonic-gate 		return (DAT_INTERNAL_ERROR);
886*7c478bd9Sstevel@tonic-gate 	}
887*7c478bd9Sstevel@tonic-gate 
888*7c478bd9Sstevel@tonic-gate 	for (i = 1 /* move past initial [u|k] */; '\0' != str[i]; i++) {
889*7c478bd9Sstevel@tonic-gate 		if ('.' == str[i]) {
890*7c478bd9Sstevel@tonic-gate 			break;
891*7c478bd9Sstevel@tonic-gate 		} else if (DAT_TRUE != dat_os_isdigit(str[i])) {
892*7c478bd9Sstevel@tonic-gate 			return (DAT_INTERNAL_ERROR);
893*7c478bd9Sstevel@tonic-gate 		}
894*7c478bd9Sstevel@tonic-gate 	}
895*7c478bd9Sstevel@tonic-gate 
896*7c478bd9Sstevel@tonic-gate 	api_version->version.major = (DAT_UINT32)dat_os_strtol(str + 1, NULL,
897*7c478bd9Sstevel@tonic-gate 	    10);
898*7c478bd9Sstevel@tonic-gate 
899*7c478bd9Sstevel@tonic-gate 	/* move past '.' */
900*7c478bd9Sstevel@tonic-gate 	minor_i = ++i;
901*7c478bd9Sstevel@tonic-gate 
902*7c478bd9Sstevel@tonic-gate 	for (; '\0' != str[i]; i++) {
903*7c478bd9Sstevel@tonic-gate 		if (DAT_TRUE != dat_os_isdigit(str[i])) {
904*7c478bd9Sstevel@tonic-gate 			return (DAT_INTERNAL_ERROR);
905*7c478bd9Sstevel@tonic-gate 		}
906*7c478bd9Sstevel@tonic-gate 	}
907*7c478bd9Sstevel@tonic-gate 
908*7c478bd9Sstevel@tonic-gate 	api_version->version.minor = (DAT_UINT32)dat_os_strtol(str + minor_i,
909*7c478bd9Sstevel@tonic-gate 	    NULL, 10);
910*7c478bd9Sstevel@tonic-gate 
911*7c478bd9Sstevel@tonic-gate 	if ('\0' != str[i]) {
912*7c478bd9Sstevel@tonic-gate 		return (DAT_INTERNAL_ERROR);
913*7c478bd9Sstevel@tonic-gate 	}
914*7c478bd9Sstevel@tonic-gate 
915*7c478bd9Sstevel@tonic-gate 	return (DAT_SUCCESS);
916*7c478bd9Sstevel@tonic-gate }
917*7c478bd9Sstevel@tonic-gate 
918*7c478bd9Sstevel@tonic-gate 
919*7c478bd9Sstevel@tonic-gate /*
920*7c478bd9Sstevel@tonic-gate  * Function: dat_sr_convert_thread_safety
921*7c478bd9Sstevel@tonic-gate  */
922*7c478bd9Sstevel@tonic-gate 
923*7c478bd9Sstevel@tonic-gate static DAT_RETURN
dat_sr_convert_thread_safety(char * str,DAT_BOOLEAN * is_thread_safe)924*7c478bd9Sstevel@tonic-gate dat_sr_convert_thread_safety(
925*7c478bd9Sstevel@tonic-gate     char *str,
926*7c478bd9Sstevel@tonic-gate     DAT_BOOLEAN *is_thread_safe)
927*7c478bd9Sstevel@tonic-gate {
928*7c478bd9Sstevel@tonic-gate 	if (!dat_os_strncmp(str,
929*7c478bd9Sstevel@tonic-gate 	    DAT_SR_TOKEN_THREADSAFE,
930*7c478bd9Sstevel@tonic-gate 	    dat_os_strlen(DAT_SR_TOKEN_THREADSAFE))) {
931*7c478bd9Sstevel@tonic-gate 		*is_thread_safe = DAT_TRUE;
932*7c478bd9Sstevel@tonic-gate 		return (DAT_SUCCESS);
933*7c478bd9Sstevel@tonic-gate 	} else if (!dat_os_strncmp(str,
934*7c478bd9Sstevel@tonic-gate 	    DAT_SR_TOKEN_NONTHREADSAFE,
935*7c478bd9Sstevel@tonic-gate 	    dat_os_strlen(DAT_SR_TOKEN_NONTHREADSAFE))) {
936*7c478bd9Sstevel@tonic-gate 		*is_thread_safe = DAT_FALSE;
937*7c478bd9Sstevel@tonic-gate 		return (DAT_SUCCESS);
938*7c478bd9Sstevel@tonic-gate 	} else {
939*7c478bd9Sstevel@tonic-gate 		return (DAT_INTERNAL_ERROR);
940*7c478bd9Sstevel@tonic-gate 	}
941*7c478bd9Sstevel@tonic-gate }
942*7c478bd9Sstevel@tonic-gate 
943*7c478bd9Sstevel@tonic-gate 
944*7c478bd9Sstevel@tonic-gate /*
945*7c478bd9Sstevel@tonic-gate  * Function: dat_sr_convert_default
946*7c478bd9Sstevel@tonic-gate  */
947*7c478bd9Sstevel@tonic-gate 
948*7c478bd9Sstevel@tonic-gate static DAT_RETURN
dat_sr_convert_default(char * str,DAT_BOOLEAN * is_default)949*7c478bd9Sstevel@tonic-gate dat_sr_convert_default(
950*7c478bd9Sstevel@tonic-gate     char *str,
951*7c478bd9Sstevel@tonic-gate     DAT_BOOLEAN *is_default)
952*7c478bd9Sstevel@tonic-gate {
953*7c478bd9Sstevel@tonic-gate 	if (!dat_os_strncmp(str,
954*7c478bd9Sstevel@tonic-gate 	    DAT_SR_TOKEN_DEFAULT,
955*7c478bd9Sstevel@tonic-gate 	    dat_os_strlen(DAT_SR_TOKEN_DEFAULT))) {
956*7c478bd9Sstevel@tonic-gate 		*is_default = DAT_TRUE;
957*7c478bd9Sstevel@tonic-gate 		return (DAT_SUCCESS);
958*7c478bd9Sstevel@tonic-gate 	} else if (!dat_os_strncmp(str,
959*7c478bd9Sstevel@tonic-gate 	    DAT_SR_TOKEN_NONDEFAULT,
960*7c478bd9Sstevel@tonic-gate 	    dat_os_strlen(DAT_SR_TOKEN_NONDEFAULT))) {
961*7c478bd9Sstevel@tonic-gate 		*is_default = DAT_FALSE;
962*7c478bd9Sstevel@tonic-gate 		return (DAT_SUCCESS);
963*7c478bd9Sstevel@tonic-gate 	} else {
964*7c478bd9Sstevel@tonic-gate 		return (DAT_INTERNAL_ERROR);
965*7c478bd9Sstevel@tonic-gate 	}
966*7c478bd9Sstevel@tonic-gate }
967*7c478bd9Sstevel@tonic-gate 
968*7c478bd9Sstevel@tonic-gate 
969*7c478bd9Sstevel@tonic-gate /*
970*7c478bd9Sstevel@tonic-gate  * Function: dat_sr_convert_provider_version
971*7c478bd9Sstevel@tonic-gate  */
972*7c478bd9Sstevel@tonic-gate 
973*7c478bd9Sstevel@tonic-gate DAT_RETURN
dat_sr_convert_provider_version(char * str,DAT_SR_PROVIDER_VERSION * provider_version)974*7c478bd9Sstevel@tonic-gate dat_sr_convert_provider_version(
975*7c478bd9Sstevel@tonic-gate     char *str,
976*7c478bd9Sstevel@tonic-gate     DAT_SR_PROVIDER_VERSION *provider_version)
977*7c478bd9Sstevel@tonic-gate {
978*7c478bd9Sstevel@tonic-gate 	DAT_RETURN 	status;
979*7c478bd9Sstevel@tonic-gate 	int 		i;
980*7c478bd9Sstevel@tonic-gate 	int 		decimal_i;
981*7c478bd9Sstevel@tonic-gate 
982*7c478bd9Sstevel@tonic-gate 	dat_os_assert(0 < dat_os_strlen(str));
983*7c478bd9Sstevel@tonic-gate 	dat_os_assert(NULL == provider_version->id);
984*7c478bd9Sstevel@tonic-gate 
985*7c478bd9Sstevel@tonic-gate 	status = DAT_SUCCESS;
986*7c478bd9Sstevel@tonic-gate 
987*7c478bd9Sstevel@tonic-gate 	for (i = 0; '\0' != str[i]; i++) {
988*7c478bd9Sstevel@tonic-gate 		if ('.' == str[i]) {
989*7c478bd9Sstevel@tonic-gate 			break;
990*7c478bd9Sstevel@tonic-gate 		}
991*7c478bd9Sstevel@tonic-gate 	}
992*7c478bd9Sstevel@tonic-gate 
993*7c478bd9Sstevel@tonic-gate 	/* if no id value was found */
994*7c478bd9Sstevel@tonic-gate 	if (0 == i) {
995*7c478bd9Sstevel@tonic-gate 		status = DAT_INTERNAL_ERROR;
996*7c478bd9Sstevel@tonic-gate 		goto exit;
997*7c478bd9Sstevel@tonic-gate 	}
998*7c478bd9Sstevel@tonic-gate 
999*7c478bd9Sstevel@tonic-gate 	if (NULL == (provider_version->id = dat_os_alloc(sizeof (char) *
1000*7c478bd9Sstevel@tonic-gate 	    (i + 1)))) {
1001*7c478bd9Sstevel@tonic-gate 		status = DAT_INSUFFICIENT_RESOURCES | DAT_RESOURCE_MEMORY;
1002*7c478bd9Sstevel@tonic-gate 		goto exit;
1003*7c478bd9Sstevel@tonic-gate 	}
1004*7c478bd9Sstevel@tonic-gate 
1005*7c478bd9Sstevel@tonic-gate 	(void) dat_os_strncpy(provider_version->id, str, i);
1006*7c478bd9Sstevel@tonic-gate 	provider_version->id[i] = '\0';
1007*7c478bd9Sstevel@tonic-gate 
1008*7c478bd9Sstevel@tonic-gate 	/* move past '.' */
1009*7c478bd9Sstevel@tonic-gate 	decimal_i = ++i;
1010*7c478bd9Sstevel@tonic-gate 
1011*7c478bd9Sstevel@tonic-gate 	for (; '\0' != str[i]; i++) {
1012*7c478bd9Sstevel@tonic-gate 		if ('.' == str[i]) {
1013*7c478bd9Sstevel@tonic-gate 			break;
1014*7c478bd9Sstevel@tonic-gate 		} else if (DAT_TRUE != dat_os_isdigit(str[i])) {
1015*7c478bd9Sstevel@tonic-gate 			status = DAT_INTERNAL_ERROR;
1016*7c478bd9Sstevel@tonic-gate 			goto exit;
1017*7c478bd9Sstevel@tonic-gate 		}
1018*7c478bd9Sstevel@tonic-gate 	}
1019*7c478bd9Sstevel@tonic-gate 
1020*7c478bd9Sstevel@tonic-gate 	/* if no version value was found */
1021*7c478bd9Sstevel@tonic-gate 	if (decimal_i == i) {
1022*7c478bd9Sstevel@tonic-gate 		status = DAT_INTERNAL_ERROR;
1023*7c478bd9Sstevel@tonic-gate 		goto exit;
1024*7c478bd9Sstevel@tonic-gate 	}
1025*7c478bd9Sstevel@tonic-gate 
1026*7c478bd9Sstevel@tonic-gate 	provider_version->version.major = (DAT_UINT32)
1027*7c478bd9Sstevel@tonic-gate 	    dat_os_strtol(str + decimal_i, NULL, 10);
1028*7c478bd9Sstevel@tonic-gate 
1029*7c478bd9Sstevel@tonic-gate 	/* move past '.' */
1030*7c478bd9Sstevel@tonic-gate 	decimal_i = ++i;
1031*7c478bd9Sstevel@tonic-gate 
1032*7c478bd9Sstevel@tonic-gate 	for (; '\0' != str[i]; i++) {
1033*7c478bd9Sstevel@tonic-gate 		if (DAT_TRUE != dat_os_isdigit(str[i])) {
1034*7c478bd9Sstevel@tonic-gate 			status = DAT_INTERNAL_ERROR;
1035*7c478bd9Sstevel@tonic-gate 			goto exit;
1036*7c478bd9Sstevel@tonic-gate 		}
1037*7c478bd9Sstevel@tonic-gate 	}
1038*7c478bd9Sstevel@tonic-gate 
1039*7c478bd9Sstevel@tonic-gate 	/* if no version value was found */
1040*7c478bd9Sstevel@tonic-gate 	if (decimal_i == i) {
1041*7c478bd9Sstevel@tonic-gate 		status = DAT_INTERNAL_ERROR;
1042*7c478bd9Sstevel@tonic-gate 		goto exit;
1043*7c478bd9Sstevel@tonic-gate 	}
1044*7c478bd9Sstevel@tonic-gate 
1045*7c478bd9Sstevel@tonic-gate 	provider_version->version.minor = (DAT_UINT32)
1046*7c478bd9Sstevel@tonic-gate 	    dat_os_strtol(str + decimal_i, NULL, 10);
1047*7c478bd9Sstevel@tonic-gate 
1048*7c478bd9Sstevel@tonic-gate 	if ('\0' != str[i]) {
1049*7c478bd9Sstevel@tonic-gate 		status = DAT_INTERNAL_ERROR;
1050*7c478bd9Sstevel@tonic-gate 		goto exit;
1051*7c478bd9Sstevel@tonic-gate 	}
1052*7c478bd9Sstevel@tonic-gate 
1053*7c478bd9Sstevel@tonic-gate exit:
1054*7c478bd9Sstevel@tonic-gate 	if (DAT_SUCCESS != status) {
1055*7c478bd9Sstevel@tonic-gate 		if (NULL != provider_version->id) {
1056*7c478bd9Sstevel@tonic-gate 			dat_os_free(provider_version->id,
1057*7c478bd9Sstevel@tonic-gate 			    sizeof (char) *
1058*7c478bd9Sstevel@tonic-gate 			    (dat_os_strlen(provider_version->id) + 1));
1059*7c478bd9Sstevel@tonic-gate 			provider_version->id = NULL;
1060*7c478bd9Sstevel@tonic-gate 		}
1061*7c478bd9Sstevel@tonic-gate 	}
1062*7c478bd9Sstevel@tonic-gate 
1063*7c478bd9Sstevel@tonic-gate 	return (status);
1064*7c478bd9Sstevel@tonic-gate }
1065*7c478bd9Sstevel@tonic-gate 
1066*7c478bd9Sstevel@tonic-gate 
1067*7c478bd9Sstevel@tonic-gate /*
1068*7c478bd9Sstevel@tonic-gate  * Function: dat_sr_get_token
1069*7c478bd9Sstevel@tonic-gate  */
1070*7c478bd9Sstevel@tonic-gate 
1071*7c478bd9Sstevel@tonic-gate DAT_RETURN
dat_sr_get_token(DAT_OS_FILE * file,DAT_SR_TOKEN * token)1072*7c478bd9Sstevel@tonic-gate dat_sr_get_token(
1073*7c478bd9Sstevel@tonic-gate     DAT_OS_FILE *file,
1074*7c478bd9Sstevel@tonic-gate     DAT_SR_TOKEN *token)
1075*7c478bd9Sstevel@tonic-gate {
1076*7c478bd9Sstevel@tonic-gate 	if (NULL == g_token_stack) {
1077*7c478bd9Sstevel@tonic-gate 		return (dat_sr_read_token(file, token));
1078*7c478bd9Sstevel@tonic-gate 	} else {
1079*7c478bd9Sstevel@tonic-gate 		DAT_SR_STACK_NODE *top;
1080*7c478bd9Sstevel@tonic-gate 
1081*7c478bd9Sstevel@tonic-gate 		top = g_token_stack;
1082*7c478bd9Sstevel@tonic-gate 
1083*7c478bd9Sstevel@tonic-gate 		*token = top->token;
1084*7c478bd9Sstevel@tonic-gate 		g_token_stack = top->next;
1085*7c478bd9Sstevel@tonic-gate 
1086*7c478bd9Sstevel@tonic-gate 		dat_os_free(top, sizeof (DAT_SR_STACK_NODE));
1087*7c478bd9Sstevel@tonic-gate 
1088*7c478bd9Sstevel@tonic-gate 		return (DAT_SUCCESS);
1089*7c478bd9Sstevel@tonic-gate 	}
1090*7c478bd9Sstevel@tonic-gate }
1091*7c478bd9Sstevel@tonic-gate 
1092*7c478bd9Sstevel@tonic-gate 
1093*7c478bd9Sstevel@tonic-gate /*
1094*7c478bd9Sstevel@tonic-gate  * Function: dat_sr_put_token
1095*7c478bd9Sstevel@tonic-gate  */
1096*7c478bd9Sstevel@tonic-gate 
1097*7c478bd9Sstevel@tonic-gate DAT_RETURN
dat_sr_put_token(DAT_OS_FILE * file,DAT_SR_TOKEN * token)1098*7c478bd9Sstevel@tonic-gate dat_sr_put_token(
1099*7c478bd9Sstevel@tonic-gate     DAT_OS_FILE *file,
1100*7c478bd9Sstevel@tonic-gate 	DAT_SR_TOKEN *token) /*ARGSUSED*/
1101*7c478bd9Sstevel@tonic-gate {
1102*7c478bd9Sstevel@tonic-gate 	DAT_SR_STACK_NODE *top;
1103*7c478bd9Sstevel@tonic-gate 
1104*7c478bd9Sstevel@tonic-gate 	if (NULL == (top = dat_os_alloc(sizeof (DAT_SR_STACK_NODE)))) {
1105*7c478bd9Sstevel@tonic-gate 		return (DAT_INSUFFICIENT_RESOURCES | DAT_RESOURCE_MEMORY);
1106*7c478bd9Sstevel@tonic-gate 	}
1107*7c478bd9Sstevel@tonic-gate 
1108*7c478bd9Sstevel@tonic-gate 	top->token = *token;
1109*7c478bd9Sstevel@tonic-gate 	top->next = g_token_stack;
1110*7c478bd9Sstevel@tonic-gate 	g_token_stack = top;
1111*7c478bd9Sstevel@tonic-gate 
1112*7c478bd9Sstevel@tonic-gate 	return (DAT_SUCCESS);
1113*7c478bd9Sstevel@tonic-gate }
1114*7c478bd9Sstevel@tonic-gate 
1115*7c478bd9Sstevel@tonic-gate 
1116*7c478bd9Sstevel@tonic-gate /*
1117*7c478bd9Sstevel@tonic-gate  * Function: dat_sr_read_token
1118*7c478bd9Sstevel@tonic-gate  */
1119*7c478bd9Sstevel@tonic-gate 
1120*7c478bd9Sstevel@tonic-gate DAT_RETURN
dat_sr_read_token(DAT_OS_FILE * file,DAT_SR_TOKEN * token)1121*7c478bd9Sstevel@tonic-gate dat_sr_read_token(
1122*7c478bd9Sstevel@tonic-gate     DAT_OS_FILE 		*file,
1123*7c478bd9Sstevel@tonic-gate     DAT_SR_TOKEN 		*token)
1124*7c478bd9Sstevel@tonic-gate {
1125*7c478bd9Sstevel@tonic-gate 	DAT_OS_FILE_POS 	pos;
1126*7c478bd9Sstevel@tonic-gate 	DAT_OS_SIZE 		token_len;
1127*7c478bd9Sstevel@tonic-gate 	DAT_COUNT 		num_escape_seq;
1128*7c478bd9Sstevel@tonic-gate 	DAT_BOOLEAN 		is_quoted_str;
1129*7c478bd9Sstevel@tonic-gate 	DAT_BOOLEAN 		is_prev_char_backslash;
1130*7c478bd9Sstevel@tonic-gate 
1131*7c478bd9Sstevel@tonic-gate 	/*
1132*7c478bd9Sstevel@tonic-gate 	 * The DAT standard does not specify a maximum size for quoted strings.
1133*7c478bd9Sstevel@tonic-gate 	 * Therefore the tokenizer must be able to read in a token of arbitrary
1134*7c478bd9Sstevel@tonic-gate 	 * size. Instead of allocating a fixed length buffer, the tokenizer
1135*7c478bd9Sstevel@tonic-gate 	 * first scans the input a single character at a time looking for the
1136*7c478bd9Sstevel@tonic-gate 	 * begining and end of the token. Once the these positions are found,
1137*7c478bd9Sstevel@tonic-gate 	 * the entire token is read into memory. By using this algorithm, the
1138*7c478bd9Sstevel@tonic-gate 	 * implementation does not place an arbitrary maximum on the token size.
1139*7c478bd9Sstevel@tonic-gate 	 */
1140*7c478bd9Sstevel@tonic-gate 
1141*7c478bd9Sstevel@tonic-gate 	token_len = 0;
1142*7c478bd9Sstevel@tonic-gate 	num_escape_seq = 0;
1143*7c478bd9Sstevel@tonic-gate 	is_quoted_str = DAT_FALSE;
1144*7c478bd9Sstevel@tonic-gate 	is_prev_char_backslash = DAT_FALSE;
1145*7c478bd9Sstevel@tonic-gate 
1146*7c478bd9Sstevel@tonic-gate 	for (;;) {
1147*7c478bd9Sstevel@tonic-gate 		DAT_OS_FILE_POS cur_pos;
1148*7c478bd9Sstevel@tonic-gate 		int c;
1149*7c478bd9Sstevel@tonic-gate 
1150*7c478bd9Sstevel@tonic-gate 		/* if looking for start of the token */
1151*7c478bd9Sstevel@tonic-gate 		if (0 == token_len) {
1152*7c478bd9Sstevel@tonic-gate 			if (DAT_SUCCESS != dat_os_fgetpos(file, &cur_pos)) {
1153*7c478bd9Sstevel@tonic-gate 				return (DAT_INTERNAL_ERROR);
1154*7c478bd9Sstevel@tonic-gate 			}
1155*7c478bd9Sstevel@tonic-gate 		}
1156*7c478bd9Sstevel@tonic-gate 
1157*7c478bd9Sstevel@tonic-gate 		c = dat_os_fgetc(file);
1158*7c478bd9Sstevel@tonic-gate 
1159*7c478bd9Sstevel@tonic-gate 		/* if looking for start of the token */
1160*7c478bd9Sstevel@tonic-gate 		if (0 == token_len) {
1161*7c478bd9Sstevel@tonic-gate 			if (EOF == c) {
1162*7c478bd9Sstevel@tonic-gate 				token->type = DAT_SR_TOKEN_EOF;
1163*7c478bd9Sstevel@tonic-gate 				token->value = NULL;
1164*7c478bd9Sstevel@tonic-gate 				token->value_len = 0;
1165*7c478bd9Sstevel@tonic-gate 				goto success;
1166*7c478bd9Sstevel@tonic-gate 			} else if (DAT_SR_CHAR_NEWLINE == c) {
1167*7c478bd9Sstevel@tonic-gate 				token->type = DAT_SR_TOKEN_EOR;
1168*7c478bd9Sstevel@tonic-gate 				token->value = NULL;
1169*7c478bd9Sstevel@tonic-gate 				token->value_len = 0;
1170*7c478bd9Sstevel@tonic-gate 				goto success;
1171*7c478bd9Sstevel@tonic-gate 			} else if (dat_os_isblank(c)) {
1172*7c478bd9Sstevel@tonic-gate 				continue;
1173*7c478bd9Sstevel@tonic-gate 			} else if (DAT_SR_CHAR_COMMENT == c) {
1174*7c478bd9Sstevel@tonic-gate 				dat_sr_read_comment(file);
1175*7c478bd9Sstevel@tonic-gate 				continue;
1176*7c478bd9Sstevel@tonic-gate 			} else {
1177*7c478bd9Sstevel@tonic-gate 				if (DAT_SR_CHAR_QUOTE == c) {
1178*7c478bd9Sstevel@tonic-gate 					is_quoted_str = DAT_TRUE;
1179*7c478bd9Sstevel@tonic-gate 				}
1180*7c478bd9Sstevel@tonic-gate 
1181*7c478bd9Sstevel@tonic-gate 				pos = cur_pos;
1182*7c478bd9Sstevel@tonic-gate 				token_len++;
1183*7c478bd9Sstevel@tonic-gate 			}
1184*7c478bd9Sstevel@tonic-gate 		} else { /* looking for the end of the token */
1185*7c478bd9Sstevel@tonic-gate 			if (EOF == c) {
1186*7c478bd9Sstevel@tonic-gate 				break;
1187*7c478bd9Sstevel@tonic-gate 			} else if (DAT_SR_CHAR_NEWLINE == c) {
1188*7c478bd9Sstevel@tonic-gate 				/* put back the newline */
1189*7c478bd9Sstevel@tonic-gate 				(void) dat_os_fungetc(file);
1190*7c478bd9Sstevel@tonic-gate 				break;
1191*7c478bd9Sstevel@tonic-gate 			} else if (!is_quoted_str && dat_os_isblank(c)) {
1192*7c478bd9Sstevel@tonic-gate 				break;
1193*7c478bd9Sstevel@tonic-gate 			} else {
1194*7c478bd9Sstevel@tonic-gate 				token_len++;
1195*7c478bd9Sstevel@tonic-gate 
1196*7c478bd9Sstevel@tonic-gate 				if ((DAT_SR_CHAR_QUOTE == c) &&
1197*7c478bd9Sstevel@tonic-gate 				    !is_prev_char_backslash) {
1198*7c478bd9Sstevel@tonic-gate 					break;
1199*7c478bd9Sstevel@tonic-gate 				} else if ((DAT_SR_CHAR_BACKSLASH == c) &&
1200*7c478bd9Sstevel@tonic-gate 				    !is_prev_char_backslash) {
1201*7c478bd9Sstevel@tonic-gate 					is_prev_char_backslash = DAT_TRUE;
1202*7c478bd9Sstevel@tonic-gate 					num_escape_seq++;
1203*7c478bd9Sstevel@tonic-gate 				} else {
1204*7c478bd9Sstevel@tonic-gate 					is_prev_char_backslash = DAT_FALSE;
1205*7c478bd9Sstevel@tonic-gate 				}
1206*7c478bd9Sstevel@tonic-gate 			}
1207*7c478bd9Sstevel@tonic-gate 		}
1208*7c478bd9Sstevel@tonic-gate 	}
1209*7c478bd9Sstevel@tonic-gate 
1210*7c478bd9Sstevel@tonic-gate 	/* the token was a string */
1211*7c478bd9Sstevel@tonic-gate 	if (DAT_SUCCESS != dat_os_fsetpos(file, &pos)) {
1212*7c478bd9Sstevel@tonic-gate 		return (DAT_INTERNAL_ERROR);
1213*7c478bd9Sstevel@tonic-gate 	}
1214*7c478bd9Sstevel@tonic-gate 
1215*7c478bd9Sstevel@tonic-gate 	if (is_quoted_str) {
1216*7c478bd9Sstevel@tonic-gate 		if (DAT_SUCCESS != dat_sr_read_quoted_str(file,
1217*7c478bd9Sstevel@tonic-gate 		    token,
1218*7c478bd9Sstevel@tonic-gate 		    token_len,
1219*7c478bd9Sstevel@tonic-gate 		    num_escape_seq)) {
1220*7c478bd9Sstevel@tonic-gate 			return (DAT_INTERNAL_ERROR);
1221*7c478bd9Sstevel@tonic-gate 		}
1222*7c478bd9Sstevel@tonic-gate 	} else {
1223*7c478bd9Sstevel@tonic-gate 		if (DAT_SUCCESS != dat_sr_read_str(file,
1224*7c478bd9Sstevel@tonic-gate 		    token,
1225*7c478bd9Sstevel@tonic-gate 		    token_len)) {
1226*7c478bd9Sstevel@tonic-gate 			return (DAT_INTERNAL_ERROR);
1227*7c478bd9Sstevel@tonic-gate 		}
1228*7c478bd9Sstevel@tonic-gate 	}
1229*7c478bd9Sstevel@tonic-gate 
1230*7c478bd9Sstevel@tonic-gate success:
1231*7c478bd9Sstevel@tonic-gate 	dat_os_dbg_print(DAT_OS_DBG_TYPE_SR,
1232*7c478bd9Sstevel@tonic-gate 	    "\n"
1233*7c478bd9Sstevel@tonic-gate 	    "DAT Registry: token\n"
1234*7c478bd9Sstevel@tonic-gate 	    " type  %s\n"
1235*7c478bd9Sstevel@tonic-gate 	    " value <%s>\n"
1236*7c478bd9Sstevel@tonic-gate 	    "\n",
1237*7c478bd9Sstevel@tonic-gate 	    dat_sr_type_to_str(token->type),
1238*7c478bd9Sstevel@tonic-gate 	    ((DAT_SR_TOKEN_STRING == token->type) ? token->value : ""));
1239*7c478bd9Sstevel@tonic-gate 
1240*7c478bd9Sstevel@tonic-gate 	return (DAT_SUCCESS);
1241*7c478bd9Sstevel@tonic-gate }
1242*7c478bd9Sstevel@tonic-gate 
1243*7c478bd9Sstevel@tonic-gate 
1244*7c478bd9Sstevel@tonic-gate /*
1245*7c478bd9Sstevel@tonic-gate  * Function: dat_sr_read_str
1246*7c478bd9Sstevel@tonic-gate  */
1247*7c478bd9Sstevel@tonic-gate 
1248*7c478bd9Sstevel@tonic-gate DAT_RETURN
dat_sr_read_str(DAT_OS_FILE * file,DAT_SR_TOKEN * token,DAT_OS_SIZE token_len)1249*7c478bd9Sstevel@tonic-gate dat_sr_read_str(
1250*7c478bd9Sstevel@tonic-gate     DAT_OS_FILE *file,
1251*7c478bd9Sstevel@tonic-gate     DAT_SR_TOKEN *token,
1252*7c478bd9Sstevel@tonic-gate     DAT_OS_SIZE token_len)
1253*7c478bd9Sstevel@tonic-gate {
1254*7c478bd9Sstevel@tonic-gate 	token->type = DAT_SR_TOKEN_STRING;
1255*7c478bd9Sstevel@tonic-gate 	/* +1 for null termination */
1256*7c478bd9Sstevel@tonic-gate 	token->value_len = sizeof (char) * (token_len + 1);
1257*7c478bd9Sstevel@tonic-gate 	if (NULL == (token->value = dat_os_alloc(token->value_len))) {
1258*7c478bd9Sstevel@tonic-gate 		return (DAT_INSUFFICIENT_RESOURCES | DAT_RESOURCE_MEMORY);
1259*7c478bd9Sstevel@tonic-gate 	}
1260*7c478bd9Sstevel@tonic-gate 
1261*7c478bd9Sstevel@tonic-gate 	if (token_len != dat_os_fread(file, token->value, token_len)) {
1262*7c478bd9Sstevel@tonic-gate 		dat_os_free(token->value, token->value_len);
1263*7c478bd9Sstevel@tonic-gate 		token->value = NULL;
1264*7c478bd9Sstevel@tonic-gate 
1265*7c478bd9Sstevel@tonic-gate 		return (DAT_INTERNAL_ERROR);
1266*7c478bd9Sstevel@tonic-gate 	}
1267*7c478bd9Sstevel@tonic-gate 
1268*7c478bd9Sstevel@tonic-gate 	token->value[token->value_len - 1] = '\0';
1269*7c478bd9Sstevel@tonic-gate 
1270*7c478bd9Sstevel@tonic-gate 	return (DAT_SUCCESS);
1271*7c478bd9Sstevel@tonic-gate }
1272*7c478bd9Sstevel@tonic-gate 
1273*7c478bd9Sstevel@tonic-gate 
1274*7c478bd9Sstevel@tonic-gate /*
1275*7c478bd9Sstevel@tonic-gate  * Function: dat_sr_read_quoted_str
1276*7c478bd9Sstevel@tonic-gate  */
1277*7c478bd9Sstevel@tonic-gate 
1278*7c478bd9Sstevel@tonic-gate DAT_RETURN
dat_sr_read_quoted_str(DAT_OS_FILE * file,DAT_SR_TOKEN * token,DAT_OS_SIZE token_len,DAT_COUNT num_escape_seq)1279*7c478bd9Sstevel@tonic-gate dat_sr_read_quoted_str(
1280*7c478bd9Sstevel@tonic-gate     DAT_OS_FILE 	*file,
1281*7c478bd9Sstevel@tonic-gate     DAT_SR_TOKEN 	*token,
1282*7c478bd9Sstevel@tonic-gate     DAT_OS_SIZE 	token_len,
1283*7c478bd9Sstevel@tonic-gate     DAT_COUNT 		num_escape_seq)
1284*7c478bd9Sstevel@tonic-gate {
1285*7c478bd9Sstevel@tonic-gate 	DAT_OS_SIZE 	str_len;
1286*7c478bd9Sstevel@tonic-gate 	DAT_OS_SIZE 	i;
1287*7c478bd9Sstevel@tonic-gate 	DAT_OS_SIZE 	j;
1288*7c478bd9Sstevel@tonic-gate 	int 		c;
1289*7c478bd9Sstevel@tonic-gate 	DAT_RETURN 	status;
1290*7c478bd9Sstevel@tonic-gate 	DAT_BOOLEAN 	is_prev_char_backslash;
1291*7c478bd9Sstevel@tonic-gate 
1292*7c478bd9Sstevel@tonic-gate 	str_len = token_len - 2; /* minus 2 " characters */
1293*7c478bd9Sstevel@tonic-gate 	is_prev_char_backslash = DAT_FALSE;
1294*7c478bd9Sstevel@tonic-gate 	status = DAT_SUCCESS;
1295*7c478bd9Sstevel@tonic-gate 
1296*7c478bd9Sstevel@tonic-gate 	token->type = DAT_SR_TOKEN_STRING;
1297*7c478bd9Sstevel@tonic-gate 	/* +1 for null termination */
1298*7c478bd9Sstevel@tonic-gate 	token->value_len = sizeof (char) * (str_len - num_escape_seq + 1);
1299*7c478bd9Sstevel@tonic-gate 
1300*7c478bd9Sstevel@tonic-gate 	if (NULL == (token->value = dat_os_alloc(token->value_len))) {
1301*7c478bd9Sstevel@tonic-gate 		status = DAT_INSUFFICIENT_RESOURCES | DAT_RESOURCE_MEMORY;
1302*7c478bd9Sstevel@tonic-gate 		goto exit;
1303*7c478bd9Sstevel@tonic-gate 	}
1304*7c478bd9Sstevel@tonic-gate 
1305*7c478bd9Sstevel@tonic-gate 	/* throw away " */
1306*7c478bd9Sstevel@tonic-gate 	if (DAT_SR_CHAR_QUOTE != dat_os_fgetc(file)) {
1307*7c478bd9Sstevel@tonic-gate 		status = DAT_INTERNAL_ERROR;
1308*7c478bd9Sstevel@tonic-gate 		goto exit;
1309*7c478bd9Sstevel@tonic-gate 	}
1310*7c478bd9Sstevel@tonic-gate 
1311*7c478bd9Sstevel@tonic-gate 	for (i = 0, j = 0; i < str_len; i++) {
1312*7c478bd9Sstevel@tonic-gate 		c = dat_os_fgetc(file);
1313*7c478bd9Sstevel@tonic-gate 
1314*7c478bd9Sstevel@tonic-gate 		if (EOF == c) {
1315*7c478bd9Sstevel@tonic-gate 			status = DAT_INTERNAL_ERROR;
1316*7c478bd9Sstevel@tonic-gate 			goto exit;
1317*7c478bd9Sstevel@tonic-gate 		} else if ((DAT_SR_CHAR_BACKSLASH == c) &&
1318*7c478bd9Sstevel@tonic-gate 		    !is_prev_char_backslash) {
1319*7c478bd9Sstevel@tonic-gate 			is_prev_char_backslash = DAT_TRUE;
1320*7c478bd9Sstevel@tonic-gate 		} else {
1321*7c478bd9Sstevel@tonic-gate 			token->value[j] = c;
1322*7c478bd9Sstevel@tonic-gate 			j++;
1323*7c478bd9Sstevel@tonic-gate 
1324*7c478bd9Sstevel@tonic-gate 			is_prev_char_backslash = DAT_FALSE;
1325*7c478bd9Sstevel@tonic-gate 		}
1326*7c478bd9Sstevel@tonic-gate 	}
1327*7c478bd9Sstevel@tonic-gate 
1328*7c478bd9Sstevel@tonic-gate 	/* throw away " */
1329*7c478bd9Sstevel@tonic-gate 	if (DAT_SR_CHAR_QUOTE != dat_os_fgetc(file)) {
1330*7c478bd9Sstevel@tonic-gate 		status = DAT_INTERNAL_ERROR;
1331*7c478bd9Sstevel@tonic-gate 		goto exit;
1332*7c478bd9Sstevel@tonic-gate 	}
1333*7c478bd9Sstevel@tonic-gate 
1334*7c478bd9Sstevel@tonic-gate 	token->value[token->value_len - 1] = '\0';
1335*7c478bd9Sstevel@tonic-gate 
1336*7c478bd9Sstevel@tonic-gate exit:
1337*7c478bd9Sstevel@tonic-gate 	if (DAT_SUCCESS != status) {
1338*7c478bd9Sstevel@tonic-gate 		if (NULL != token->value) {
1339*7c478bd9Sstevel@tonic-gate 			dat_os_free(token->value, token->value_len);
1340*7c478bd9Sstevel@tonic-gate 			token->value = NULL;
1341*7c478bd9Sstevel@tonic-gate 		}
1342*7c478bd9Sstevel@tonic-gate 	}
1343*7c478bd9Sstevel@tonic-gate 
1344*7c478bd9Sstevel@tonic-gate 	return (status);
1345*7c478bd9Sstevel@tonic-gate }
1346*7c478bd9Sstevel@tonic-gate 
1347*7c478bd9Sstevel@tonic-gate 
1348*7c478bd9Sstevel@tonic-gate /*
1349*7c478bd9Sstevel@tonic-gate  * Function: dat_sr_read_comment
1350*7c478bd9Sstevel@tonic-gate  */
1351*7c478bd9Sstevel@tonic-gate 
1352*7c478bd9Sstevel@tonic-gate void
dat_sr_read_comment(DAT_OS_FILE * file)1353*7c478bd9Sstevel@tonic-gate dat_sr_read_comment(
1354*7c478bd9Sstevel@tonic-gate     DAT_OS_FILE *file)
1355*7c478bd9Sstevel@tonic-gate {
1356*7c478bd9Sstevel@tonic-gate 	int c;
1357*7c478bd9Sstevel@tonic-gate 
1358*7c478bd9Sstevel@tonic-gate 	/* read up to an EOR or EOF to move past the comment */
1359*7c478bd9Sstevel@tonic-gate 	do {
1360*7c478bd9Sstevel@tonic-gate 		c = dat_os_fgetc(file);
1361*7c478bd9Sstevel@tonic-gate 	} while ((DAT_SR_CHAR_NEWLINE != c) && (EOF != c));
1362*7c478bd9Sstevel@tonic-gate 
1363*7c478bd9Sstevel@tonic-gate 	/* put back the newline */
1364*7c478bd9Sstevel@tonic-gate 	(void) dat_os_fungetc(file);
1365*7c478bd9Sstevel@tonic-gate }
1366