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
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.
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]
25 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
26 * Use is subject to license terms.
34 %#include "db_query_c.h"
35 %#include "db_scheme_c.h"
37 %#include "db_query.h"
38 %#include "db_scheme.h"
42 %#include "nisdb_ldap.h"
43 %#include "nisdb_rw.h"
44 %#include "ldap_parse.h"
45 %#include "ldap_map.h"
46 %#include "ldap_util.h"
47 %#include "ldap_nisdbquery.h"
48 %#include "ldap_print.h"
49 %#include "ldap_xdr.h"
51 typedef long entryp; /* specifies location of an entry within table */
53 struct db_free_entry {
55 struct db_free_entry *next;
58 typedef struct db_free_entry * db_free_entry_p;
60 #if RPC_HDR || RPC_XDR
65 __nisdb_rwlock_t free_list_rwlock;
67 typedef struct db_free_list * db_free_list_p;
74 % db_free_entry_p head;
76 % STRUCTRWLOCK(free_list);
78 % db_free_list() { /* free list constructor */
86 % void reset(); /* empty contents of free list */
88 % void init(); /* Empty free list */
90 %/* Returns the location of a free entry, or NULL, if there aren't any. */
93 %/* Adds given location to the free list.
94 % Returns TRUE if successful, FALSE otherwise (when out of memory). */
95 % bool_t push( entryp );
97 %/* Returns in a vector the information in the free list.
98 % Vector returned is of form: <n free cells><n1><n2><loc1>,..<locn>.
99 % Leave the first 'n' cells free.
100 % n1 is the number of entries that should be in the freelist.
101 % n2 is the number of entries actually found in the freelist.
102 % <loc1...locn> are the entries. n2 <= n1 because we never count beyond n1.
103 % It is up to the caller to free the returned vector when he is through. */
104 % long* stats( int n );
106 %/* Locking methods */
108 % int acqexcl(void) {
109 % return (WLOCK(free_list));
112 % int relexcl(void) {
113 % return (WULOCK(free_list));
116 % int acqnonexcl(void) {
117 % return (RLOCK(free_list));
120 % int relnonexcl(void) {
121 % return (RULOCK(free_list));
127 #if RPC_HDR || RPC_XDR
131 entry_object_p tab <>;
132 long last_used; /* last entry used; maintained for quick insertion */
133 long count; /* measures fullness of table */
134 db_free_list freelist;
135 __nisdb_rwlock_t table_rwlock;
136 __nisdb_flag_t enumMode;
137 __nisdb_ptr_t enumArray;
138 __nis_table_mapping_t mapping;
140 typedef struct db_table * db_table_p;
150 % entry_object_p *tab; /* pointer to array of pointers to entry objects */
151 % long last_used; /* last entry used; maintained for quick insertion */
152 % long count; /* measures fullness of table */
153 % db_free_list freelist;
154 % STRUCTRWLOCK(table);
155 % __nisdb_flag_t enumMode;
156 % __nisdb_flag_t enumCount;
157 % __nisdb_ptr_t enumIndex;
158 % __nisdb_ptr_t enumArray;
160 % void grow(); /* Expand the table.
161 % Fatal error if insufficient error. */
163 %/* Allocate expiration time array */
164 % db_status allocateExpire(long oldSize, long newSize);
167 % __nisdb_table_mapping_t mapping;
169 % db_table(); /* constructor for brand new, empty table. */
170 % db_table( char * ); /* constructor for creating a table by loading
171 % in an existing one. */
173 %/* Init of LDAP/MT portion of class instance */
174 % void db_table_ldap_init(void);
175 %/* Size of the non-MT/LDAP portion of the db_table structure */
176 % ulong_t oldstructsize(void) {
177 % return ((ulong_t)&(this->table_rwlock) - (ulong_t)this);
179 %/* Mark this instance as deferred */
180 % void markDeferred(void) {
181 % mapping.isDeferredTable = TRUE;
183 %/* Remove deferred mark */
184 % void unmarkDeferred(void) {
185 % mapping.isDeferredTable = FALSE;
188 %/* Return the current 'tab' */
189 % entry_object_p *gettab() { ASSERTRHELD(table); return (tab); };
190 %/* Return how many entries there are in table. */
191 % long fullness() { return count; }
193 %/* Deletes table, entries, and free list */
196 % int tryacqexcl(void) {
197 % return (TRYWLOCK(table));
200 % int acqexcl(void) {
201 % return (WLOCK(table));
204 % int relexcl(void) {
205 % return (WULOCK(table));
208 % int acqnonexcl(void) {
209 % return (RLOCK(table));
212 % int relnonexcl(void) {
213 % return (RULOCK(table));
216 %/* empties table by deleting all entries and other associated data structures */
221 %/* Returns whether location is valid. */
222 % bool_t entry_exists_p( entryp i );
224 %/* Returns table size. */
225 % long getsize() { return table_size; }
227 %/* Returns the first entry in table, also return its position in
228 % 'where'. Return NULL in both if no next entry is found. */
229 % entry_object_p first_entry( entryp * where );
231 %/* Returns the next entry in table from 'prev', also return its position in
232 % 'newentry'. Return NULL in both if no next entry is found. */
233 % entry_object_p next_entry( entryp, entryp* );
235 %/* Returns entry at location 'where', NULL if location is invalid. */
236 % entry_object_p get_entry( entryp );
238 %/* Adds given entry to table in first available slot (either look in freelist
239 % or add to end of table) and return the the position of where the record
240 % is placed. 'count' is incremented if entry is added. Table may grow
241 % as a side-effect of the addition. Copy is made of the input. */
242 % entryp add_entry(entry_object_p, int);
244 % /* Replaces object at specified location by given entry.
245 % Returns TRUE if replacement successful; FALSE otherwise.
246 % There must something already at the specified location, otherwise,
247 % replacement fails. Copy is not made of the input.
248 % The pre-existing entry is freed.*/
249 % bool_t replace_entry( entryp, entry_object_p );
251 %/* Deletes entry at specified location. Returns TRUE if location is valid;
252 % FALSE if location is invalid, or the freed location cannot be added to
253 % the freelist. 'count' is decremented if the deletion occurs. The object
254 % at that location is freed. */
255 % bool_t delete_entry( entryp );
257 %/* Returns statistics of table.
258 % <table_size><last_used><count>[freelist].
259 % It is up to the caller to free the returned vector when his is through
260 % The free list is included if 'fl' is TRUE. */
261 %long * stats( bool_t fl );
263 %/* Configure LDAP mapping */
264 % bool_t configure(char *objName);
266 %/* Initialize the mapping structure with default values */
267 % void initMappingStruct(__nisdb_table_mapping_t *mapping);
269 %/* Check if entry at 'loc' is valid (not expired) */
270 % bool_t cacheValid(entryp loc);
272 %/* Update expiration time if supplied object same as the one at 'loc' */
273 % bool_t dupEntry(entry_object *obj, entryp loc);
275 %/* Set expiration time for entry */
276 % void setEntryExp(entryp where, entry_object *obj, int initialLoad);
278 %/* Enable enum mode */
279 % void setEnumMode(long count);
280 %/* Clear enum mode */
281 % void clearEnumMode(void);
282 %/* End enum mode, return array of untouched entries */
283 % entry_object **endEnumMode(long *numEa);
284 %/* Mark the indicated entry used for enum purposes */
285 % void enumTouch(entryp loc);
286 %/* Add entry to enumIndex array */
287 % void enumSetup(entryp loc, long index);
288 %/* Touch the indicated entry */
289 % void touchEntry(entryp loc);
291 % db_status allocateEnumArray(long oldSize, long newSize);
294 %extern "C" bool_t xdr_db_table( XDR*, db_table*);
296 %extern bool_t xdr_db_table(XDR*, db_table*);
298 %typedef class db_table * db_table_p;
303 %#endif /* _DB_TABLE_H */