0
|
1 /*
|
|
2 * CDDL HEADER START
|
|
3 *
|
|
4 * The contents of this file are subject to the terms of the
|
|
5 * Common Development and Distribution License, Version 1.0 only
|
|
6 * (the "License"). You may not use this file except in compliance
|
|
7 * with the License.
|
|
8 *
|
|
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
|
10 * or http://www.opensolaris.org/os/licensing.
|
|
11 * See the License for the specific language governing permissions
|
|
12 * and limitations under the License.
|
|
13 *
|
|
14 * When distributing Covered Code, include this CDDL HEADER in each
|
|
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
|
16 * If applicable, add the following below this CDDL HEADER, with the
|
|
17 * fields enclosed by brackets "[]" replaced with your own identifying
|
|
18 * information: Portions Copyright [yyyy] [name of copyright owner]
|
|
19 *
|
|
20 * CDDL HEADER END
|
|
21 */
|
|
22 /*
|
|
23 * Copyright (c) 1998 by Sun Microsystems, Inc.
|
|
24 * All rights reserved.
|
|
25 */
|
|
26
|
|
27 #pragma ident "@(#)node.c 1.7 05/06/12 SMI"
|
|
28
|
|
29 #include <stdlib.h>
|
|
30 #include <stdio.h>
|
|
31 #include <string.h>
|
|
32 #include <sys/types.h>
|
|
33
|
|
34 #include "impl.h"
|
|
35 #include "error.h"
|
|
36 #include "trace.h"
|
|
37
|
|
38 #include "agent_msg.h"
|
|
39 #include "node.h"
|
|
40
|
|
41
|
|
42 /***** STATIC VARIABLES ******/
|
|
43
|
|
44 static Node *root_node = &node_table[0];
|
|
45
|
|
46
|
|
47 /*****************************************************************/
|
|
48
|
|
49 Node *node_find(int search_type, Oid *name, Oid *suffix)
|
|
50 {
|
|
51 int i;
|
|
52 Node *parent;
|
|
53 Node *previous;
|
|
54 Node *node;
|
|
55
|
|
56
|
|
57 if( (name == NULL)
|
|
58 || (name->len < 1)
|
|
59 || (name->subids[0] != root_node->subid) )
|
|
60 {
|
|
61 suffix->subids = NULL;
|
|
62 suffix->len = 0;
|
|
63
|
|
64 if(trace_level > 0)
|
|
65 {
|
|
66 trace("node_find() returned NULL\n\n");
|
|
67 }
|
|
68
|
|
69 return NULL;
|
|
70 }
|
|
71
|
|
72 parent = root_node;
|
|
73 for(i = 1; i < name->len; i++)
|
|
74 {
|
|
75 previous = NULL;
|
|
76
|
|
77 for(node = parent->first_child; node; node = node->next_peer)
|
|
78 {
|
|
79 if(node->subid > name->subids[i])
|
|
80 {
|
|
81 switch(search_type)
|
|
82 {
|
|
83 case NEXT_ENTRY:
|
|
84 suffix->len = 0;
|
|
85 suffix->subids = NULL;
|
|
86
|
|
87 if(trace_level > 0)
|
|
88 {
|
|
89 trace("node_find() returned %s with no suffix\n\n",
|
|
90 node->label);
|
|
91 }
|
|
92
|
|
93 return node;
|
|
94
|
|
95 case EXACT_ENTRY:
|
|
96 node = NULL;
|
|
97 break;
|
|
98 }
|
|
99
|
|
100 break;
|
|
101 }
|
|
102
|
|
103 if(node->subid == name->subids[i])
|
|
104 {
|
|
105 parent = node;
|
|
106 break;
|
|
107 }
|
|
108
|
|
109 previous = node;
|
|
110 }
|
|
111
|
|
112 if(node == NULL)
|
|
113 {
|
|
114 switch(search_type)
|
|
115 {
|
|
116 case NEXT_ENTRY:
|
|
117 suffix->subids = NULL;
|
|
118 suffix->len = 0;
|
|
119
|
|
120 if(previous)
|
|
121 {
|
|
122 if(trace_level > 0)
|
|
123 {
|
|
124 if(previous->next)
|
|
125 {
|
|
126 trace("node_find() returned %s with no suffix\n\n",
|
|
127 previous->next->label);
|
|
128 }
|
|
129 else
|
|
130 {
|
|
131 trace("node_find() returned NULL\n\n");
|
|
132 }
|
|
133 }
|
|
134
|
|
135 return previous->next;
|
|
136 }
|
|
137 else
|
|
138 {
|
|
139 if(trace_level > 0)
|
|
140 {
|
|
141 if(parent->next)
|
|
142 {
|
|
143 trace("node_find() returned %s with no suffix\n\n",
|
|
144 parent->next->label);
|
|
145 }
|
|
146 else
|
|
147 {
|
|
148 trace("node_find() returned NULL\n\n");
|
|
149 }
|
|
150 }
|
|
151
|
|
152 return parent->next;
|
|
153 }
|
|
154
|
|
155 case EXACT_ENTRY:
|
|
156 suffix->subids = NULL;
|
|
157 suffix->len = 0;
|
|
158
|
|
159 if(trace_level > 0)
|
|
160 {
|
|
161 trace("node_find() returned NULL\n\n");
|
|
162 }
|
|
163
|
|
164 return NULL;
|
|
165 }
|
|
166 }
|
|
167
|
|
168 if( (node->type == COLUMN)
|
|
169 || (node->type == OBJECT) ) {
|
|
170 suffix->len = name->len - (i + 1);
|
|
171 if (suffix->len) {
|
|
172 suffix->subids = (Subid *) malloc(suffix->len *
|
|
173 (int32_t)sizeof(Subid));
|
|
174 if (suffix->subids == NULL) {
|
|
175 error(ERR_MSG_ALLOC);
|
|
176 return NULL;
|
|
177 }
|
|
178
|
|
179 (void)memcpy(suffix->subids, &(name->subids[i + 1]),
|
|
180 suffix->len * (int32_t)sizeof(Subid));
|
|
181 } else
|
|
182 suffix->subids = NULL;
|
|
183
|
|
184 if(trace_level > 0) {
|
|
185 trace("node_find() returned %s with suffix %s\n\n",
|
|
186 parent->label, SSAOidString(suffix));
|
|
187 }
|
|
188
|
|
189 return node;
|
|
190 }
|
|
191 }
|
|
192
|
|
193 suffix->len = 0;
|
|
194 suffix->subids = NULL;
|
|
195
|
|
196 if(trace_level > 0)
|
|
197 {
|
|
198 trace("node_find() returned %s with no suffix\n\n",
|
|
199 node->label);
|
|
200 }
|
|
201
|
|
202 return node;
|
|
203 }
|
|
204
|
|
205
|
|
206 /*****************************************************************/
|
|
207
|
|
208
|
|
209
|
|
210
|