xref: /titanic_50/usr/src/lib/libnisdb/db_mindex_c.x (revision 84f7a9b9dca4f23b5f50edef0e59d7eb44301114)
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  *	db_mindex_c.x
24  *
25  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
26  * Use is subject to license terms.
27  */
28 
29 %#pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #if RPC_HDR
32 %#ifndef _DB_MINDEX_H
33 %#define _DB_MINDEX_H
34 
35 #ifdef USINGC
36 %#include "db_vers_c.h"
37 %#include "db_table_c.h"
38 %#include "db_index_entry_c.h"
39 %#include "db_index_c.h"
40 %#include "db_scheme_c.h"
41 %#include "db_query_c.h"
42 #else
43 %#include "db_vers.h"
44 %#include "db_table.h"
45 %#include "db_index_entry.h"
46 %#include "db_index.h"
47 %#include "db_scheme.h"
48 %#include "db_query.h"
49 #endif /* USINGC */
50 %#include "ldap_parse.h"
51 %#include "nisdb_rw.h"
52 %#include "ldap_xdr.h"
53 #endif /* RPC_HDR */
54 
55 #if RPC_HDR
56 %struct db_next_index_desc {
57 %  entryp location;
58 %  struct db_next_index_desc *next;
59 
60 #ifndef USINGC
61 %  db_next_index_desc( entryp loc, struct db_next_index_desc *n )
62 %    { location = loc; next = n; }
63 #endif /* USINGC */
64 
65 %};
66 #endif /* RPC_HDR */
67 
68 
69 #if RPC_HDR || RPC_XDR
70 #ifdef USINGC
71 
72 struct db_mindex {
73   vers rversion;
74   db_index indices<>;                /* indices[num_indices] */
75   db_table *table;
76   db_scheme *scheme;
77   __nisdb_ptr_t objPath;
78   __nisdb_flag_t noWriteThrough;
79   __nisdb_flag_t noLDAPquery;
80   __nisdb_flag_t initialLoad;
81   __nisdb_ptr_t dbptr;
82   __nisdb_rwlock_t mindex_rwlock;
83 };
84 typedef struct db_mindex  * db_mindex_p;
85 
86 typedef	string	strP<>;
87 
88 struct xdr_nis_object_s {
89 	int		xversion;
90 	nis_object	*obj;
91 	strP		dirEntry<>;
92 };
93 typedef struct xdr_nis_object_s	xdr_nis_object_t;
94 
95 %extern bool_t	xdr_nis_object();
96 #endif /* USINGC */
97 #endif /* RPC_HDR */
98 
99 #ifndef USINGC
100 #ifdef RPC_HDR
101 %
102 %struct xdr_nis_object_s {
103 %	int				version;
104 %	nis_object			*obj;
105 %	struct {
106 %		uint_t	dirEntry_len;
107 %		char	**dirEntry_val;
108 %	}				dirEntry;
109 %};
110 %typedef struct xdr_nis_object_s	xdr_nis_object_t;
111 %
112 %extern bool_t	xdr_nis_object();
113 %
114 %class db_mindex {
115 %  vers rversion;
116 %//  int num_indices;
117 %//  db_index * indices;                /* indices[num_indices] */
118 %  struct {
119 %   int indices_len;
120 %   db_index *indices_val;
121 %  } indices;
122 %  db_table *table;
123 %  db_scheme *scheme;
124 %  __nisdb_ptr_t objPath;
125 %  __nisdb_flag_t noWriteThrough;
126 %  __nisdb_flag_t noLDAPquery;
127 %  __nisdb_flag_t initialLoad;
128 %  __nisdb_ptr_t dbptr;
129 %  STRUCTRWLOCK(mindex);
130 %
131 %/* Return a list of index_entries that satsify the given query 'q'.
132 %   Return the size of the list in 'count'. Return NULL if list is empty.
133 %   Return in 'valid' FALSE if query is not well formed. */
134 %  db_index_entry_p satisfy_query(db_query *, long *, bool_t *valid,
135 %					bool_t fromLDAP = FALSE);
136 %  db_index_entry_p satisfy_query(db_query *, long *, bool_t *valid = NULL);
137 %
138 %/* Returns a newly db_query containing the index values as
139 %   obtained from the given object.  The object itself,
140 %   along with information on the scheme given, will determine
141 %   which values are extracted from the object and placed into the query.
142 %   Returns an empty query if 'obj' is not a valid entry.
143 %   Note that space is allocated for the query and the index values
144 %   (i.e. do not share pointers with strings in 'obj'.) */
145 %  db_query * extract_index_values_from_object( entry_object * );
146 %
147 %/* Returns a newly created db_query structure containing the index values
148 %   as obtained from the record named by 'recnum'.  The record itself, along
149 %   with information on the schema definition of this table, will determine
150 %   which values are extracted from the record and placed into the result.
151 %   Returns NULL if recnum is not a valid entry.
152 %   Note that space is allocated for the query and the index values
153 %   (i.e. do not share pointers with strings in 'obj'.) */
154 %  db_query * extract_index_values_from_record( entryp );
155 %
156 %/* Returns an array of size 'count' of 'entry_object_p's, pointing to
157 %   copies of entry_objects named by the result list of db_index_entries 'res'.
158 %*/
159 %  entry_object_p * prepare_results( int, db_index_entry_p, db_status* );
160 %
161 %/* Remove the entry identified by 'recloc' from:
162 %   1.  all indices, as obtained by extracting the index values from the entry
163 %   2.  table where entry is stored. */
164 %  db_status remove_aux( entryp );
165 %
166 %/*  entry_object * get_record( entryp );*/
167 % public:
168 %
169 %/* Constructor:  Create empty table (no scheme, no table or indices). */
170 %  db_mindex();
171 %
172 %/* Constructor:  Create new table using scheme defintion supplied.
173 %   (Make copy of scheme and keep it with table.) */
174 %  db_mindex(db_scheme *, char *tablePath);
175 %
176 %/* destructor */
177 %  ~db_mindex();
178 %
179 %  db_index_entry_p satisfy_query_dbonly(db_query *, long *,
180 %					bool_t checkExpire,
181 %					bool_t *valid = NULL);
182 %
183 %/* Returns whether there table is valid (i.e. has scheme). */
184 %  bool_t good() { return scheme != NULL && table != NULL; }
185 %
186 %/* Change the version of the table to the one given. */
187 %  void change_version( vers *v ) {  rversion.assign( v );}
188 %
189 %/* Return the current version of the table. */
190 %  vers *get_version()  { return( &rversion ); }
191 %
192 %/* Reset contents of tables by: deleting indice entries, table entries */
193 %  void reset_tables();
194 %
195 %/* Reset the table by: deleting all the indices, table of entries, and its
196 %   scheme. Reset version to 0 */
197 %  void reset();
198 %
199 %/* Initialize table using information from specified file.
200 %   The table is first 'reset', then the attempt to load from the file
201 %   is made.  If the load failed, the table is again reset.
202 %   Therefore, the table will be modified regardless of the success of the
203 %   load.  Returns TRUE if successful, FALSE otherwise. */
204 %  int load( char * );
205 %
206 %/* Initialize table using information given in scheme 'how'.
207 %   Record the scheme for later use (make copy of it);
208 %   create the required number of indices; and create table for storing
209 %   entries.
210 %   The 'tablePath' is passed on to db_table in order to obtain the
211 %   NIS+/LDAP mapping information (if any). */
212 %  void init( db_scheme *);
213 %
214 %/* Write this structure (table, indices, scheme) into the specified file. */
215 %  int dump( char *);
216 %
217 %/* Removes the entry in the table named by given query 'q'.
218 %   If a NULL query is supplied, all entries in table are removed.
219 %   Returns DB_NOTFOUND if no entry is found.
220 %   Returns DB_SUCCESS if one entry is found; this entry is removed from
221 %   its record storage, and it is also removed from all the indices of the
222 %   table. If more than one entry satisfying 'q' is found, all are removed. */
223 %  db_status remove( db_query *);
224 %
225 %/* Add copy of given entry to table.  Entry is identified by query 'q'.
226 %   The entry (if any) satisfying the query is first deleted, then
227 %   added to the indices (using index values extracted form the given entry)
228 %   and the table.
229 %   Returns DB_NOTUNIQUE if more than one entry satisfies the query.
230 %   Returns DB_NOTFOUND if query is not well-formed.
231 %   Returns DB_SUCCESS if entry can be added.  */
232 %  db_status add( db_query *, entry_object* );
233 %
234 %
235 %/* Finds entry that satisfy the query 'q'.  Returns the answer by
236 %   setting the pointer 'rp' to point to the list of answers.
237 %   Note that the answers are pointers to copies of the entries.
238 %   Returns the number of answers find in 'count'.
239 %   Returns DB_SUCCESS if search found at least one answer;
240 %   returns DB_NOTFOUND if none is found. */
241 %  db_status lookup( db_query *, long *, entry_object_p ** );
242 %
243 %/* Returns the next entry in the table after 'previous' by setting 'answer' to
244 %   point to a copy of the entry_object.  Returns DB_SUCCESS if 'previous'
245 %   is valid and next entry is found; DB_NOTFOUND otherwise.  Sets 'where'
246 %   to location of where entry is found for input as subsequent 'next'
247 %   operation. */
248 %  db_status next( entryp, entryp *, entry_object ** );
249 %
250 %/* Returns the next entry in the table after 'previous' by setting 'answer' to
251 %   point to a copy of the entry_object.  Returns DB_SUCCESS if 'previous'
252 %   is valid and next entry is found; DB_NOTFOUND otherwise.  Sets 'where'
253 %   to location of where entry is found for input as subsequent 'next'
254 %   operation. */
255 %  db_status next( db_next_index_desc*, db_next_index_desc **, entry_object ** );
256 %
257 %/* Returns the first entry found in the table by setting 'answer' to
258 %   a copy of the entry_object.  Returns DB_SUCCESS if found;
259 %   DB_NOTFOUND otherwise.  */
260 %  db_status first( entryp*, entry_object ** );
261 %
262 %/* Returns the first entry that satisfies query by setting 'answer' to
263 %   a copy of the entry_object.  Returns DB_SUCCESS if found;
264 %   DB_NOTFOUND otherwise.  */
265 %  db_status first( db_query *, db_next_index_desc **, entry_object ** );
266 %
267 % /* Delete the given list of results; used when no longer interested in
268 %    the results of the first/next query that returned this list.     */
269 %  db_status db_mindex::reset_next( db_next_index_desc *orig );
270 %
271 %/* Return all entries within table.  Returns the answer by
272 %   setting the pointer 'rp' to point to the list of answers.
273 %   Note that the answers are pointers to copies of the entries.
274 %   Returns the number of answers find in 'count'.
275 %   Returns DB_SUCCESS if search found at least one answer;
276 %   returns DB_NOTFOUND if none is found. */
277 %  db_status all( long *, entry_object_p ** );
278 %
279 %  /* for debugging */
280 %/* Prints statistics of the table.  This includes the size of the table,
281 %   the number of entries, and the index sizes. */
282 %  void print_stats();
283 %
284 %/* Prints statistics about all indices of table. */
285 %  void print_all_indices();
286 %
287 %
288 %/* Prints statistics about indices identified by 'n'. */
289 %  void print_index( int n );
290 %
291 %/* Configure LDAP mapping */
292 %  bool_t configure (char *objName);
293 %
294 %/* Mark this instance deferred */
295 %  void markDeferred(void) {
296 %	if (table != NULL) table->markDeferred();
297 %  }
298 %/* Remove deferred mark */
299 %  void unmarkDeferred(void) {
300 %	if (table != NULL) table->unmarkDeferred();
301 %  }
302 %
303 %/* Retrieve, remove, or store data from/in/to LDAP */
304 %  int queryLDAP(db_query *, char *, int);
305 %  int entriesFromLDAP(__nis_table_mapping_t *, db_query *, db_query *,
306 %			char *, nis_object *, int);
307 %
308 %  int removeLDAP(db_query *, nis_object *o);
309 %
310 %  int storeObjLDAP(__nis_table_mapping_t *t, nis_object *o);
311 %  int storeLDAP(db_query *, entry_obj *, nis_object *, entry_obj *,
312 %		char *dbId);
313 %
314 %/* Set/clear no-write-through flag */
315 %  void setNoWriteThrough(void);
316 %  void clearNoWriteThrough(void);
317 %
318 %/* Set/clear no-LDAP-query flag */
319 %  void setNoLDAPquery(void);
320 %  void clearNoLDAPquery(void);
321 %
322 %/* Set/clear initialLoad flag */
323 %  void setInitialLoad(void);
324 %  void clearInitialLoad(void);
325 %
326 %/* Store/retrieve pointer to parent 'db' class instance */
327 %  void setDbPtr(void *ptr);
328 %  void *getDbPtr(void);
329 %
330 %/* Get pointer to private 'table' field */
331 %  db_table *getTable(void);
332 %
333 %/*
334 % * Update table entry per the (entry_object *). If 'replace' is set,
335 % * the entry is replaced or added; otherwise, it is removed.
336 % */
337 %  int updateTableEntry(entry_object *e, int replace, char *tableName,
338 %			nis_object *obj, nis_object *tobj, uint32_t ttime,
339 %			int *xid);
340 %
341 %/* Touch the indicated entry */
342 %  bool_t touchEntry(entry_object *e);
343 %  bool_t touchEntry(db_query *q);
344 %
345 %/* Return the 'scheme' pointer */
346 %  db_scheme *getScheme(void) {return (scheme);}
347 %
348 %/* RW lock functions */
349 %
350 %  int tryacqexcl(void) {
351 %	return (TRYWLOCK(mindex));
352 %  }
353 %
354 %  int acqexcl(void) {
355 %	return (WLOCK(mindex));
356 %  }
357 %
358 %  int relexcl(void) {
359 %	return (WULOCK(mindex));
360 %  }
361 %
362 %  int acqnonexcl(void) {
363 %	return (RLOCK(mindex));
364 %  }
365 %
366 %  int relnonexcl(void) {
367 %	return (RULOCK(mindex));
368 %  }
369 %};
370 %#ifdef __cplusplus
371 %extern "C" bool_t xdr_db_mindex(XDR*, db_mindex*);
372 %#elif __STDC__
373 %extern bool_t xdr_db_mindex(XDR*, db_mindex*);
374 %#endif
375 %typedef class db_mindex * db_mindex_p;
376 #endif /* RPC_HDR */
377 #endif /* USINGC */
378 
379 #if RPC_HDR
380 %#endif /* _DB_MINDEX_H */
381 #endif /* RPC_HDR */
382