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 #pragma ident "%Z%%M% %I% %E% SMI"
32*7c478bd9Sstevel@tonic-gate
33*7c478bd9Sstevel@tonic-gate /*
34*7c478bd9Sstevel@tonic-gate *
35*7c478bd9Sstevel@tonic-gate * MODULE: dat_dictionary.c
36*7c478bd9Sstevel@tonic-gate *
37*7c478bd9Sstevel@tonic-gate * PURPOSE: dictionary data structure
38*7c478bd9Sstevel@tonic-gate *
39*7c478bd9Sstevel@tonic-gate * $Id: dat_dictionary.c,v 1.11 2003/08/05 19:01:48 jlentini Exp $
40*7c478bd9Sstevel@tonic-gate */
41*7c478bd9Sstevel@tonic-gate
42*7c478bd9Sstevel@tonic-gate
43*7c478bd9Sstevel@tonic-gate #include "dat_dictionary.h"
44*7c478bd9Sstevel@tonic-gate
45*7c478bd9Sstevel@tonic-gate
46*7c478bd9Sstevel@tonic-gate /*
47*7c478bd9Sstevel@tonic-gate *
48*7c478bd9Sstevel@tonic-gate * Structures
49*7c478bd9Sstevel@tonic-gate *
50*7c478bd9Sstevel@tonic-gate */
51*7c478bd9Sstevel@tonic-gate
52*7c478bd9Sstevel@tonic-gate typedef struct DAT_DICTIONARY_NODE
53*7c478bd9Sstevel@tonic-gate {
54*7c478bd9Sstevel@tonic-gate DAT_PROVIDER_INFO key;
55*7c478bd9Sstevel@tonic-gate DAT_DICTIONARY_DATA data;
56*7c478bd9Sstevel@tonic-gate struct DAT_DICTIONARY_NODE *prev;
57*7c478bd9Sstevel@tonic-gate struct DAT_DICTIONARY_NODE *next;
58*7c478bd9Sstevel@tonic-gate } DAT_DICTIONARY_NODE;
59*7c478bd9Sstevel@tonic-gate
60*7c478bd9Sstevel@tonic-gate
61*7c478bd9Sstevel@tonic-gate struct DAT_DICTIONARY
62*7c478bd9Sstevel@tonic-gate {
63*7c478bd9Sstevel@tonic-gate DAT_DICTIONARY_NODE *head;
64*7c478bd9Sstevel@tonic-gate DAT_DICTIONARY_NODE *tail;
65*7c478bd9Sstevel@tonic-gate DAT_COUNT size;
66*7c478bd9Sstevel@tonic-gate };
67*7c478bd9Sstevel@tonic-gate
68*7c478bd9Sstevel@tonic-gate /*
69*7c478bd9Sstevel@tonic-gate *
70*7c478bd9Sstevel@tonic-gate * Function Declarations
71*7c478bd9Sstevel@tonic-gate *
72*7c478bd9Sstevel@tonic-gate */
73*7c478bd9Sstevel@tonic-gate
74*7c478bd9Sstevel@tonic-gate static DAT_RETURN
75*7c478bd9Sstevel@tonic-gate dat_dictionary_key_dup(
76*7c478bd9Sstevel@tonic-gate const DAT_PROVIDER_INFO *old_key,
77*7c478bd9Sstevel@tonic-gate DAT_PROVIDER_INFO *new_key);
78*7c478bd9Sstevel@tonic-gate
79*7c478bd9Sstevel@tonic-gate static DAT_BOOLEAN
80*7c478bd9Sstevel@tonic-gate dat_dictionary_key_is_equal(
81*7c478bd9Sstevel@tonic-gate const DAT_PROVIDER_INFO *key_a,
82*7c478bd9Sstevel@tonic-gate const DAT_PROVIDER_INFO *key_b);
83*7c478bd9Sstevel@tonic-gate
84*7c478bd9Sstevel@tonic-gate
85*7c478bd9Sstevel@tonic-gate /*
86*7c478bd9Sstevel@tonic-gate *
87*7c478bd9Sstevel@tonic-gate * External Functions
88*7c478bd9Sstevel@tonic-gate *
89*7c478bd9Sstevel@tonic-gate */
90*7c478bd9Sstevel@tonic-gate
91*7c478bd9Sstevel@tonic-gate
92*7c478bd9Sstevel@tonic-gate /*
93*7c478bd9Sstevel@tonic-gate * Function: dat_dictionary_create
94*7c478bd9Sstevel@tonic-gate */
95*7c478bd9Sstevel@tonic-gate
96*7c478bd9Sstevel@tonic-gate DAT_RETURN
dat_dictionary_create(OUT DAT_DICTIONARY ** pp_dictionary)97*7c478bd9Sstevel@tonic-gate dat_dictionary_create(
98*7c478bd9Sstevel@tonic-gate OUT DAT_DICTIONARY **pp_dictionary)
99*7c478bd9Sstevel@tonic-gate {
100*7c478bd9Sstevel@tonic-gate DAT_DICTIONARY *p_dictionary;
101*7c478bd9Sstevel@tonic-gate DAT_RETURN status;
102*7c478bd9Sstevel@tonic-gate
103*7c478bd9Sstevel@tonic-gate dat_os_assert(NULL != pp_dictionary);
104*7c478bd9Sstevel@tonic-gate
105*7c478bd9Sstevel@tonic-gate status = DAT_SUCCESS;
106*7c478bd9Sstevel@tonic-gate
107*7c478bd9Sstevel@tonic-gate /* create the dictionary */
108*7c478bd9Sstevel@tonic-gate p_dictionary = dat_os_alloc(sizeof (DAT_DICTIONARY));
109*7c478bd9Sstevel@tonic-gate if (NULL == p_dictionary) {
110*7c478bd9Sstevel@tonic-gate status = DAT_ERROR(DAT_INSUFFICIENT_RESOURCES,
111*7c478bd9Sstevel@tonic-gate DAT_RESOURCE_MEMORY);
112*7c478bd9Sstevel@tonic-gate goto bail;
113*7c478bd9Sstevel@tonic-gate }
114*7c478bd9Sstevel@tonic-gate
115*7c478bd9Sstevel@tonic-gate (void) dat_os_memset(p_dictionary, '\0', sizeof (DAT_DICTIONARY));
116*7c478bd9Sstevel@tonic-gate
117*7c478bd9Sstevel@tonic-gate /* create the head node */
118*7c478bd9Sstevel@tonic-gate p_dictionary->head = dat_os_alloc(sizeof (DAT_DICTIONARY_NODE));
119*7c478bd9Sstevel@tonic-gate if (NULL == p_dictionary->head) {
120*7c478bd9Sstevel@tonic-gate status = DAT_ERROR(DAT_INSUFFICIENT_RESOURCES,
121*7c478bd9Sstevel@tonic-gate DAT_RESOURCE_MEMORY);
122*7c478bd9Sstevel@tonic-gate goto bail;
123*7c478bd9Sstevel@tonic-gate }
124*7c478bd9Sstevel@tonic-gate
125*7c478bd9Sstevel@tonic-gate (void) dat_os_memset(p_dictionary->head, '\0',
126*7c478bd9Sstevel@tonic-gate sizeof (DAT_DICTIONARY_NODE));
127*7c478bd9Sstevel@tonic-gate
128*7c478bd9Sstevel@tonic-gate /* create the tail node */
129*7c478bd9Sstevel@tonic-gate p_dictionary->tail = dat_os_alloc(sizeof (DAT_DICTIONARY_NODE));
130*7c478bd9Sstevel@tonic-gate if (NULL == p_dictionary->tail) {
131*7c478bd9Sstevel@tonic-gate status = DAT_ERROR(DAT_INSUFFICIENT_RESOURCES,
132*7c478bd9Sstevel@tonic-gate DAT_RESOURCE_MEMORY);
133*7c478bd9Sstevel@tonic-gate goto bail;
134*7c478bd9Sstevel@tonic-gate }
135*7c478bd9Sstevel@tonic-gate
136*7c478bd9Sstevel@tonic-gate (void) dat_os_memset(p_dictionary->tail, '\0',
137*7c478bd9Sstevel@tonic-gate sizeof (DAT_DICTIONARY_NODE));
138*7c478bd9Sstevel@tonic-gate
139*7c478bd9Sstevel@tonic-gate p_dictionary->head->next = p_dictionary->tail;
140*7c478bd9Sstevel@tonic-gate p_dictionary->tail->prev = p_dictionary->head;
141*7c478bd9Sstevel@tonic-gate
142*7c478bd9Sstevel@tonic-gate *pp_dictionary = p_dictionary;
143*7c478bd9Sstevel@tonic-gate
144*7c478bd9Sstevel@tonic-gate bail:
145*7c478bd9Sstevel@tonic-gate if (DAT_SUCCESS != status) {
146*7c478bd9Sstevel@tonic-gate if (NULL != p_dictionary) {
147*7c478bd9Sstevel@tonic-gate dat_os_free(p_dictionary, sizeof (DAT_DICTIONARY));
148*7c478bd9Sstevel@tonic-gate
149*7c478bd9Sstevel@tonic-gate if (NULL != p_dictionary->head) {
150*7c478bd9Sstevel@tonic-gate dat_os_free(p_dictionary->head,
151*7c478bd9Sstevel@tonic-gate sizeof (DAT_DICTIONARY_NODE));
152*7c478bd9Sstevel@tonic-gate }
153*7c478bd9Sstevel@tonic-gate
154*7c478bd9Sstevel@tonic-gate if (NULL != p_dictionary->tail) {
155*7c478bd9Sstevel@tonic-gate dat_os_free(p_dictionary->tail,
156*7c478bd9Sstevel@tonic-gate sizeof (DAT_DICTIONARY_NODE));
157*7c478bd9Sstevel@tonic-gate }
158*7c478bd9Sstevel@tonic-gate }
159*7c478bd9Sstevel@tonic-gate }
160*7c478bd9Sstevel@tonic-gate
161*7c478bd9Sstevel@tonic-gate return (status);
162*7c478bd9Sstevel@tonic-gate }
163*7c478bd9Sstevel@tonic-gate
164*7c478bd9Sstevel@tonic-gate
165*7c478bd9Sstevel@tonic-gate /*
166*7c478bd9Sstevel@tonic-gate * Function: dat_dictionary_destroy
167*7c478bd9Sstevel@tonic-gate */
168*7c478bd9Sstevel@tonic-gate
169*7c478bd9Sstevel@tonic-gate DAT_RETURN
dat_dictionary_destroy(IN DAT_DICTIONARY * p_dictionary)170*7c478bd9Sstevel@tonic-gate dat_dictionary_destroy(
171*7c478bd9Sstevel@tonic-gate IN DAT_DICTIONARY *p_dictionary)
172*7c478bd9Sstevel@tonic-gate {
173*7c478bd9Sstevel@tonic-gate DAT_DICTIONARY_NODE *cur_node;
174*7c478bd9Sstevel@tonic-gate
175*7c478bd9Sstevel@tonic-gate dat_os_assert(NULL != p_dictionary);
176*7c478bd9Sstevel@tonic-gate
177*7c478bd9Sstevel@tonic-gate while (NULL != p_dictionary->head) {
178*7c478bd9Sstevel@tonic-gate cur_node = p_dictionary->head;
179*7c478bd9Sstevel@tonic-gate p_dictionary->head = cur_node->next;
180*7c478bd9Sstevel@tonic-gate
181*7c478bd9Sstevel@tonic-gate dat_os_free(cur_node, sizeof (DAT_DICTIONARY_NODE));
182*7c478bd9Sstevel@tonic-gate }
183*7c478bd9Sstevel@tonic-gate
184*7c478bd9Sstevel@tonic-gate dat_os_free(p_dictionary, sizeof (DAT_DICTIONARY));
185*7c478bd9Sstevel@tonic-gate
186*7c478bd9Sstevel@tonic-gate return (DAT_SUCCESS);
187*7c478bd9Sstevel@tonic-gate }
188*7c478bd9Sstevel@tonic-gate
189*7c478bd9Sstevel@tonic-gate
190*7c478bd9Sstevel@tonic-gate /*
191*7c478bd9Sstevel@tonic-gate * Function: dat_dictionary_size
192*7c478bd9Sstevel@tonic-gate */
193*7c478bd9Sstevel@tonic-gate
194*7c478bd9Sstevel@tonic-gate DAT_RETURN
dat_dictionary_size(IN DAT_DICTIONARY * p_dictionary,OUT DAT_COUNT * p_size)195*7c478bd9Sstevel@tonic-gate dat_dictionary_size(
196*7c478bd9Sstevel@tonic-gate IN DAT_DICTIONARY *p_dictionary,
197*7c478bd9Sstevel@tonic-gate OUT DAT_COUNT *p_size)
198*7c478bd9Sstevel@tonic-gate {
199*7c478bd9Sstevel@tonic-gate dat_os_assert(NULL != p_dictionary);
200*7c478bd9Sstevel@tonic-gate dat_os_assert(NULL != p_size);
201*7c478bd9Sstevel@tonic-gate
202*7c478bd9Sstevel@tonic-gate *p_size = p_dictionary->size;
203*7c478bd9Sstevel@tonic-gate
204*7c478bd9Sstevel@tonic-gate return (DAT_SUCCESS);
205*7c478bd9Sstevel@tonic-gate }
206*7c478bd9Sstevel@tonic-gate
207*7c478bd9Sstevel@tonic-gate
208*7c478bd9Sstevel@tonic-gate /*
209*7c478bd9Sstevel@tonic-gate * Function: dat_dictionary_entry_create
210*7c478bd9Sstevel@tonic-gate */
211*7c478bd9Sstevel@tonic-gate
212*7c478bd9Sstevel@tonic-gate DAT_RETURN
dat_dictionary_entry_create(OUT DAT_DICTIONARY_ENTRY * p_entry)213*7c478bd9Sstevel@tonic-gate dat_dictionary_entry_create(
214*7c478bd9Sstevel@tonic-gate OUT DAT_DICTIONARY_ENTRY *p_entry)
215*7c478bd9Sstevel@tonic-gate {
216*7c478bd9Sstevel@tonic-gate DAT_DICTIONARY_NODE *node;
217*7c478bd9Sstevel@tonic-gate DAT_RETURN dat_status;
218*7c478bd9Sstevel@tonic-gate
219*7c478bd9Sstevel@tonic-gate dat_os_assert(NULL != p_entry);
220*7c478bd9Sstevel@tonic-gate
221*7c478bd9Sstevel@tonic-gate dat_status = DAT_SUCCESS;
222*7c478bd9Sstevel@tonic-gate
223*7c478bd9Sstevel@tonic-gate node = dat_os_alloc(sizeof (DAT_DICTIONARY_NODE));
224*7c478bd9Sstevel@tonic-gate if (NULL == node) {
225*7c478bd9Sstevel@tonic-gate dat_status = DAT_ERROR(DAT_INSUFFICIENT_RESOURCES,
226*7c478bd9Sstevel@tonic-gate DAT_RESOURCE_MEMORY);
227*7c478bd9Sstevel@tonic-gate goto bail;
228*7c478bd9Sstevel@tonic-gate }
229*7c478bd9Sstevel@tonic-gate
230*7c478bd9Sstevel@tonic-gate *p_entry = node;
231*7c478bd9Sstevel@tonic-gate
232*7c478bd9Sstevel@tonic-gate bail:
233*7c478bd9Sstevel@tonic-gate return (dat_status);
234*7c478bd9Sstevel@tonic-gate }
235*7c478bd9Sstevel@tonic-gate
236*7c478bd9Sstevel@tonic-gate
237*7c478bd9Sstevel@tonic-gate /*
238*7c478bd9Sstevel@tonic-gate * Function: dat_dictionary_entry_destroy
239*7c478bd9Sstevel@tonic-gate */
240*7c478bd9Sstevel@tonic-gate
241*7c478bd9Sstevel@tonic-gate DAT_RETURN
dat_dictionary_entry_destroy(OUT DAT_DICTIONARY_ENTRY entry)242*7c478bd9Sstevel@tonic-gate dat_dictionary_entry_destroy(
243*7c478bd9Sstevel@tonic-gate OUT DAT_DICTIONARY_ENTRY entry)
244*7c478bd9Sstevel@tonic-gate {
245*7c478bd9Sstevel@tonic-gate dat_os_free(entry, sizeof (DAT_DICTIONARY_NODE));
246*7c478bd9Sstevel@tonic-gate return (DAT_SUCCESS);
247*7c478bd9Sstevel@tonic-gate }
248*7c478bd9Sstevel@tonic-gate
249*7c478bd9Sstevel@tonic-gate
250*7c478bd9Sstevel@tonic-gate /*
251*7c478bd9Sstevel@tonic-gate * Function: dat_dictionary_insert
252*7c478bd9Sstevel@tonic-gate */
253*7c478bd9Sstevel@tonic-gate
254*7c478bd9Sstevel@tonic-gate DAT_RETURN
dat_dictionary_insert(IN DAT_DICTIONARY * p_dictionary,IN DAT_DICTIONARY_ENTRY entry,IN const DAT_PROVIDER_INFO * key,IN DAT_DICTIONARY_DATA data)255*7c478bd9Sstevel@tonic-gate dat_dictionary_insert(
256*7c478bd9Sstevel@tonic-gate IN DAT_DICTIONARY *p_dictionary,
257*7c478bd9Sstevel@tonic-gate IN DAT_DICTIONARY_ENTRY entry,
258*7c478bd9Sstevel@tonic-gate IN const DAT_PROVIDER_INFO *key,
259*7c478bd9Sstevel@tonic-gate IN DAT_DICTIONARY_DATA data)
260*7c478bd9Sstevel@tonic-gate {
261*7c478bd9Sstevel@tonic-gate DAT_RETURN dat_status;
262*7c478bd9Sstevel@tonic-gate DAT_DICTIONARY_NODE *cur_node, *prev_node, *next_node;
263*7c478bd9Sstevel@tonic-gate
264*7c478bd9Sstevel@tonic-gate dat_os_assert(NULL != p_dictionary);
265*7c478bd9Sstevel@tonic-gate dat_os_assert(NULL != entry);
266*7c478bd9Sstevel@tonic-gate
267*7c478bd9Sstevel@tonic-gate cur_node = entry;
268*7c478bd9Sstevel@tonic-gate
269*7c478bd9Sstevel@tonic-gate if (DAT_SUCCESS == dat_dictionary_search(p_dictionary, key, NULL)) {
270*7c478bd9Sstevel@tonic-gate dat_status = DAT_ERROR(DAT_PROVIDER_ALREADY_REGISTERED, 0);
271*7c478bd9Sstevel@tonic-gate goto bail;
272*7c478bd9Sstevel@tonic-gate }
273*7c478bd9Sstevel@tonic-gate
274*7c478bd9Sstevel@tonic-gate dat_status = dat_dictionary_key_dup(key, &cur_node->key);
275*7c478bd9Sstevel@tonic-gate if (DAT_SUCCESS != dat_status) {
276*7c478bd9Sstevel@tonic-gate goto bail;
277*7c478bd9Sstevel@tonic-gate }
278*7c478bd9Sstevel@tonic-gate
279*7c478bd9Sstevel@tonic-gate /* insert node at end of list to preserve registration order */
280*7c478bd9Sstevel@tonic-gate prev_node = p_dictionary->tail->prev;
281*7c478bd9Sstevel@tonic-gate next_node = p_dictionary->tail;
282*7c478bd9Sstevel@tonic-gate
283*7c478bd9Sstevel@tonic-gate cur_node->data = data;
284*7c478bd9Sstevel@tonic-gate cur_node->next = next_node;
285*7c478bd9Sstevel@tonic-gate cur_node->prev = prev_node;
286*7c478bd9Sstevel@tonic-gate
287*7c478bd9Sstevel@tonic-gate prev_node->next = cur_node;
288*7c478bd9Sstevel@tonic-gate next_node->prev = cur_node;
289*7c478bd9Sstevel@tonic-gate
290*7c478bd9Sstevel@tonic-gate p_dictionary->size++;
291*7c478bd9Sstevel@tonic-gate
292*7c478bd9Sstevel@tonic-gate bail:
293*7c478bd9Sstevel@tonic-gate return (dat_status);
294*7c478bd9Sstevel@tonic-gate }
295*7c478bd9Sstevel@tonic-gate
296*7c478bd9Sstevel@tonic-gate
297*7c478bd9Sstevel@tonic-gate /*
298*7c478bd9Sstevel@tonic-gate * Function: dat_dictionary_search
299*7c478bd9Sstevel@tonic-gate */
300*7c478bd9Sstevel@tonic-gate
301*7c478bd9Sstevel@tonic-gate DAT_RETURN
dat_dictionary_search(IN DAT_DICTIONARY * p_dictionary,IN const DAT_PROVIDER_INFO * key,OUT DAT_DICTIONARY_DATA * p_data)302*7c478bd9Sstevel@tonic-gate dat_dictionary_search(
303*7c478bd9Sstevel@tonic-gate IN DAT_DICTIONARY *p_dictionary,
304*7c478bd9Sstevel@tonic-gate IN const DAT_PROVIDER_INFO *key,
305*7c478bd9Sstevel@tonic-gate OUT DAT_DICTIONARY_DATA *p_data)
306*7c478bd9Sstevel@tonic-gate {
307*7c478bd9Sstevel@tonic-gate DAT_DICTIONARY_NODE *cur_node;
308*7c478bd9Sstevel@tonic-gate DAT_RETURN status;
309*7c478bd9Sstevel@tonic-gate
310*7c478bd9Sstevel@tonic-gate dat_os_assert(NULL != p_dictionary);
311*7c478bd9Sstevel@tonic-gate
312*7c478bd9Sstevel@tonic-gate status = DAT_ERROR(DAT_NAME_NOT_FOUND, 0);
313*7c478bd9Sstevel@tonic-gate
314*7c478bd9Sstevel@tonic-gate for (cur_node = p_dictionary->head->next;
315*7c478bd9Sstevel@tonic-gate p_dictionary->tail != cur_node;
316*7c478bd9Sstevel@tonic-gate cur_node = cur_node->next) {
317*7c478bd9Sstevel@tonic-gate if (DAT_TRUE == dat_dictionary_key_is_equal(&cur_node->key,
318*7c478bd9Sstevel@tonic-gate key)) {
319*7c478bd9Sstevel@tonic-gate if (NULL != p_data) {
320*7c478bd9Sstevel@tonic-gate *p_data = cur_node->data;
321*7c478bd9Sstevel@tonic-gate }
322*7c478bd9Sstevel@tonic-gate
323*7c478bd9Sstevel@tonic-gate status = DAT_SUCCESS;
324*7c478bd9Sstevel@tonic-gate goto bail;
325*7c478bd9Sstevel@tonic-gate }
326*7c478bd9Sstevel@tonic-gate }
327*7c478bd9Sstevel@tonic-gate
328*7c478bd9Sstevel@tonic-gate bail:
329*7c478bd9Sstevel@tonic-gate return (status);
330*7c478bd9Sstevel@tonic-gate }
331*7c478bd9Sstevel@tonic-gate
332*7c478bd9Sstevel@tonic-gate
333*7c478bd9Sstevel@tonic-gate /*
334*7c478bd9Sstevel@tonic-gate * Function: dat_dictionary_enumerate
335*7c478bd9Sstevel@tonic-gate */
336*7c478bd9Sstevel@tonic-gate
337*7c478bd9Sstevel@tonic-gate DAT_RETURN
dat_dictionary_enumerate(IN DAT_DICTIONARY * p_dictionary,IN DAT_DICTIONARY_DATA array[],IN DAT_COUNT array_size)338*7c478bd9Sstevel@tonic-gate dat_dictionary_enumerate(
339*7c478bd9Sstevel@tonic-gate IN DAT_DICTIONARY *p_dictionary,
340*7c478bd9Sstevel@tonic-gate IN DAT_DICTIONARY_DATA array[],
341*7c478bd9Sstevel@tonic-gate IN DAT_COUNT array_size)
342*7c478bd9Sstevel@tonic-gate {
343*7c478bd9Sstevel@tonic-gate DAT_DICTIONARY_NODE *cur_node;
344*7c478bd9Sstevel@tonic-gate DAT_COUNT i;
345*7c478bd9Sstevel@tonic-gate DAT_RETURN status;
346*7c478bd9Sstevel@tonic-gate
347*7c478bd9Sstevel@tonic-gate dat_os_assert(NULL != p_dictionary);
348*7c478bd9Sstevel@tonic-gate dat_os_assert(NULL != array);
349*7c478bd9Sstevel@tonic-gate
350*7c478bd9Sstevel@tonic-gate status = DAT_SUCCESS;
351*7c478bd9Sstevel@tonic-gate
352*7c478bd9Sstevel@tonic-gate if (array_size < p_dictionary->size) {
353*7c478bd9Sstevel@tonic-gate status = DAT_ERROR(DAT_INSUFFICIENT_RESOURCES, 0);
354*7c478bd9Sstevel@tonic-gate goto bail;
355*7c478bd9Sstevel@tonic-gate }
356*7c478bd9Sstevel@tonic-gate
357*7c478bd9Sstevel@tonic-gate for (cur_node = p_dictionary->head->next, i = 0;
358*7c478bd9Sstevel@tonic-gate p_dictionary->tail != cur_node;
359*7c478bd9Sstevel@tonic-gate cur_node = cur_node->next, i++) {
360*7c478bd9Sstevel@tonic-gate array[i] = cur_node->data;
361*7c478bd9Sstevel@tonic-gate }
362*7c478bd9Sstevel@tonic-gate
363*7c478bd9Sstevel@tonic-gate bail:
364*7c478bd9Sstevel@tonic-gate return (status);
365*7c478bd9Sstevel@tonic-gate }
366*7c478bd9Sstevel@tonic-gate
367*7c478bd9Sstevel@tonic-gate
368*7c478bd9Sstevel@tonic-gate /*
369*7c478bd9Sstevel@tonic-gate * Function: dat_dictionary_remove
370*7c478bd9Sstevel@tonic-gate */
371*7c478bd9Sstevel@tonic-gate
372*7c478bd9Sstevel@tonic-gate DAT_RETURN
dat_dictionary_remove(IN DAT_DICTIONARY * p_dictionary,IN DAT_DICTIONARY_ENTRY * p_entry,IN const DAT_PROVIDER_INFO * key,OUT DAT_DICTIONARY_DATA * p_data)373*7c478bd9Sstevel@tonic-gate dat_dictionary_remove(
374*7c478bd9Sstevel@tonic-gate IN DAT_DICTIONARY *p_dictionary,
375*7c478bd9Sstevel@tonic-gate IN DAT_DICTIONARY_ENTRY *p_entry,
376*7c478bd9Sstevel@tonic-gate IN const DAT_PROVIDER_INFO *key,
377*7c478bd9Sstevel@tonic-gate OUT DAT_DICTIONARY_DATA *p_data)
378*7c478bd9Sstevel@tonic-gate {
379*7c478bd9Sstevel@tonic-gate DAT_DICTIONARY_NODE *cur_node, *prev_node, *next_node;
380*7c478bd9Sstevel@tonic-gate DAT_RETURN status;
381*7c478bd9Sstevel@tonic-gate
382*7c478bd9Sstevel@tonic-gate dat_os_assert(NULL != p_dictionary);
383*7c478bd9Sstevel@tonic-gate dat_os_assert(NULL != p_entry);
384*7c478bd9Sstevel@tonic-gate
385*7c478bd9Sstevel@tonic-gate status = DAT_ERROR(DAT_NAME_NOT_FOUND, 0);
386*7c478bd9Sstevel@tonic-gate
387*7c478bd9Sstevel@tonic-gate for (cur_node = p_dictionary->head->next;
388*7c478bd9Sstevel@tonic-gate p_dictionary->tail != cur_node;
389*7c478bd9Sstevel@tonic-gate cur_node = cur_node->next) {
390*7c478bd9Sstevel@tonic-gate if (DAT_TRUE == dat_dictionary_key_is_equal(&cur_node->key,
391*7c478bd9Sstevel@tonic-gate key)) {
392*7c478bd9Sstevel@tonic-gate if (NULL != p_data) {
393*7c478bd9Sstevel@tonic-gate *p_data = cur_node->data;
394*7c478bd9Sstevel@tonic-gate }
395*7c478bd9Sstevel@tonic-gate
396*7c478bd9Sstevel@tonic-gate prev_node = cur_node->prev;
397*7c478bd9Sstevel@tonic-gate next_node = cur_node->next;
398*7c478bd9Sstevel@tonic-gate
399*7c478bd9Sstevel@tonic-gate prev_node->next = next_node;
400*7c478bd9Sstevel@tonic-gate next_node->prev = prev_node;
401*7c478bd9Sstevel@tonic-gate
402*7c478bd9Sstevel@tonic-gate *p_entry = cur_node;
403*7c478bd9Sstevel@tonic-gate
404*7c478bd9Sstevel@tonic-gate p_dictionary->size--;
405*7c478bd9Sstevel@tonic-gate
406*7c478bd9Sstevel@tonic-gate status = DAT_SUCCESS;
407*7c478bd9Sstevel@tonic-gate goto bail;
408*7c478bd9Sstevel@tonic-gate }
409*7c478bd9Sstevel@tonic-gate }
410*7c478bd9Sstevel@tonic-gate
411*7c478bd9Sstevel@tonic-gate bail:
412*7c478bd9Sstevel@tonic-gate return (status);
413*7c478bd9Sstevel@tonic-gate }
414*7c478bd9Sstevel@tonic-gate
415*7c478bd9Sstevel@tonic-gate
416*7c478bd9Sstevel@tonic-gate /*
417*7c478bd9Sstevel@tonic-gate *
418*7c478bd9Sstevel@tonic-gate * Internal Function Definitions
419*7c478bd9Sstevel@tonic-gate *
420*7c478bd9Sstevel@tonic-gate */
421*7c478bd9Sstevel@tonic-gate
422*7c478bd9Sstevel@tonic-gate
423*7c478bd9Sstevel@tonic-gate /*
424*7c478bd9Sstevel@tonic-gate * Function: dat_dictionary_key_create
425*7c478bd9Sstevel@tonic-gate */
426*7c478bd9Sstevel@tonic-gate
427*7c478bd9Sstevel@tonic-gate DAT_RETURN
dat_dictionary_key_dup(const DAT_PROVIDER_INFO * old_key,DAT_PROVIDER_INFO * new_key)428*7c478bd9Sstevel@tonic-gate dat_dictionary_key_dup(
429*7c478bd9Sstevel@tonic-gate const DAT_PROVIDER_INFO *old_key,
430*7c478bd9Sstevel@tonic-gate DAT_PROVIDER_INFO *new_key)
431*7c478bd9Sstevel@tonic-gate {
432*7c478bd9Sstevel@tonic-gate dat_os_assert(NULL != old_key);
433*7c478bd9Sstevel@tonic-gate dat_os_assert(NULL != new_key);
434*7c478bd9Sstevel@tonic-gate
435*7c478bd9Sstevel@tonic-gate (void) dat_os_strncpy(new_key->ia_name, old_key->ia_name,
436*7c478bd9Sstevel@tonic-gate DAT_NAME_MAX_LENGTH);
437*7c478bd9Sstevel@tonic-gate new_key->dapl_version_major = old_key->dapl_version_major;
438*7c478bd9Sstevel@tonic-gate new_key->dapl_version_minor = old_key->dapl_version_minor;
439*7c478bd9Sstevel@tonic-gate new_key->is_thread_safe = old_key->is_thread_safe;
440*7c478bd9Sstevel@tonic-gate
441*7c478bd9Sstevel@tonic-gate return (DAT_SUCCESS);
442*7c478bd9Sstevel@tonic-gate }
443*7c478bd9Sstevel@tonic-gate
444*7c478bd9Sstevel@tonic-gate
445*7c478bd9Sstevel@tonic-gate /*
446*7c478bd9Sstevel@tonic-gate * Function: dat_dictionary_key_is_equal
447*7c478bd9Sstevel@tonic-gate */
448*7c478bd9Sstevel@tonic-gate
449*7c478bd9Sstevel@tonic-gate DAT_BOOLEAN
dat_dictionary_key_is_equal(const DAT_PROVIDER_INFO * key_a,const DAT_PROVIDER_INFO * key_b)450*7c478bd9Sstevel@tonic-gate dat_dictionary_key_is_equal(
451*7c478bd9Sstevel@tonic-gate const DAT_PROVIDER_INFO *key_a,
452*7c478bd9Sstevel@tonic-gate const DAT_PROVIDER_INFO *key_b)
453*7c478bd9Sstevel@tonic-gate {
454*7c478bd9Sstevel@tonic-gate if ((dat_os_strlen(key_a->ia_name) == dat_os_strlen(key_b->ia_name)) &&
455*7c478bd9Sstevel@tonic-gate (!dat_os_strncmp(key_a->ia_name, key_b->ia_name,
456*7c478bd9Sstevel@tonic-gate dat_os_strlen(key_a->ia_name))) &&
457*7c478bd9Sstevel@tonic-gate (key_a->dapl_version_major == key_b->dapl_version_major) &&
458*7c478bd9Sstevel@tonic-gate (key_a->dapl_version_minor == key_b->dapl_version_minor) &&
459*7c478bd9Sstevel@tonic-gate (key_a->is_thread_safe == key_b->is_thread_safe)) {
460*7c478bd9Sstevel@tonic-gate return (DAT_TRUE);
461*7c478bd9Sstevel@tonic-gate } else {
462*7c478bd9Sstevel@tonic-gate return (DAT_FALSE);
463*7c478bd9Sstevel@tonic-gate }
464*7c478bd9Sstevel@tonic-gate }
465