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