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.
29 %#pragma ident "%Z%%M% %I% %E% SMI"
36 %#include "db_query_c.h"
37 %#include "db_scheme_c.h"
39 %#include "db_query.h"
40 %#include "db_scheme.h"
44 %#include "nisdb_ldap.h"
45 %#include "nisdb_rw.h"
46 %#include "ldap_parse.h"
47 %#include "ldap_map.h"
48 %#include "ldap_util.h"
49 %#include "ldap_nisdbquery.h"
50 %#include "ldap_print.h"
51 %#include "ldap_xdr.h"
53 typedef long entryp; /* specifies location of an entry within table */
55 struct db_free_entry {
57 struct db_free_entry *next;
60 typedef struct db_free_entry * db_free_entry_p;
62 #if RPC_HDR || RPC_XDR
67 __nisdb_rwlock_t free_list_rwlock;
69 typedef struct db_free_list * db_free_list_p;
76 % db_free_entry_p head;
78 % STRUCTRWLOCK(free_list);
80 % db_free_list() { /* free list constructor */
88 % void reset(); /* empty contents of free list */
90 % void init(); /* Empty free list */
92 %/* Returns the location of a free entry, or NULL, if there aren't any. */
95 %/* Adds given location to the free list.
96 % Returns TRUE if successful, FALSE otherwise (when out of memory). */
97 % bool_t push( entryp );
99 %/* Returns in a vector the information in the free list.
100 % Vector returned is of form: <n free cells><n1><n2><loc1>,..<locn>.
101 % Leave the first 'n' cells free.
102 % n1 is the number of entries that should be in the freelist.
103 % n2 is the number of entries actually found in the freelist.
104 % <loc1...locn> are the entries. n2 <= n1 because we never count beyond n1.
105 % It is up to the caller to free the returned vector when he is through. */
106 % long* stats( int n );
108 %/* Locking methods */
110 % int acqexcl(void) {
111 % return (WLOCK(free_list));
114 % int relexcl(void) {
115 % return (WULOCK(free_list));
118 % int acqnonexcl(void) {
119 % return (RLOCK(free_list));
122 % int relnonexcl(void) {
123 % return (RULOCK(free_list));
129 #if RPC_HDR || RPC_XDR
133 entry_object_p tab <>;
134 long last_used; /* last entry used; maintained for quick insertion */
135 long count; /* measures fullness of table */
136 db_free_list freelist;
137 __nisdb_rwlock_t table_rwlock;
138 __nisdb_flag_t enumMode;
139 __nisdb_ptr_t enumArray;
140 __nis_table_mapping_t mapping;
142 typedef struct db_table * db_table_p;
152 % entry_object_p *tab; /* pointer to array of pointers to entry objects */
153 % long last_used; /* last entry used; maintained for quick insertion */
154 % long count; /* measures fullness of table */
155 % db_free_list freelist;
156 % STRUCTRWLOCK(table);
157 % __nisdb_flag_t enumMode;
158 % __nisdb_flag_t enumCount;
159 % __nisdb_ptr_t enumIndex;
160 % __nisdb_ptr_t enumArray;
162 % void grow(); /* Expand the table.
163 % Fatal error if insufficient error. */
165 %/* Allocate expiration time array */
166 % db_status allocateExpire(long oldSize, long newSize);
169 % __nisdb_table_mapping_t mapping;
171 % db_table(); /* constructor for brand new, empty table. */
172 % db_table( char * ); /* constructor for creating a table by loading
173 % in an existing one. */
175 %/* Init of LDAP/MT portion of class instance */
176 % void db_table_ldap_init(void);
177 %/* Size of the non-MT/LDAP portion of the db_table structure */
178 % ulong_t oldstructsize(void) {
179 % return ((ulong_t)&(this->table_rwlock) - (ulong_t)this);
181 %/* Mark this instance as deferred */
182 % void markDeferred(void) {
183 % mapping.isDeferredTable = TRUE;
185 %/* Remove deferred mark */
186 % void unmarkDeferred(void) {
187 % mapping.isDeferredTable = FALSE;
190 %/* Return the current 'tab' */
191 % entry_object_p *gettab() { ASSERTRHELD(table); return (tab); };
192 %/* Return how many entries there are in table. */
193 % long fullness() { return count; }
195 %/* Deletes table, entries, and free list */
198 % int tryacqexcl(void) {
199 % return (TRYWLOCK(table));
202 % int acqexcl(void) {
203 % return (WLOCK(table));
206 % int relexcl(void) {
207 % return (WULOCK(table));
210 % int acqnonexcl(void) {
211 % return (RLOCK(table));
214 % int relnonexcl(void) {
215 % return (RULOCK(table));
218 %/* empties table by deleting all entries and other associated data structures */
223 %/* Returns whether location is valid. */
224 % bool_t entry_exists_p( entryp i );
226 %/* Returns table size. */
227 % long getsize() { return table_size; }
229 %/* Returns the first entry in table, also return its position in
230 % 'where'. Return NULL in both if no next entry is found. */
231 % entry_object_p first_entry( entryp * where );
233 %/* Returns the next entry in table from 'prev', also return its position in
234 % 'newentry'. Return NULL in both if no next entry is found. */
235 % entry_object_p next_entry( entryp, entryp* );
237 %/* Returns entry at location 'where', NULL if location is invalid. */
238 % entry_object_p get_entry( entryp );
240 %/* Adds given entry to table in first available slot (either look in freelist
241 % or add to end of table) and return the the position of where the record
242 % is placed. 'count' is incremented if entry is added. Table may grow
243 % as a side-effect of the addition. Copy is made of the input. */
244 % entryp add_entry(entry_object_p, int);
246 % /* Replaces object at specified location by given entry.
247 % Returns TRUE if replacement successful; FALSE otherwise.
248 % There must something already at the specified location, otherwise,
249 % replacement fails. Copy is not made of the input.
250 % The pre-existing entry is freed.*/
251 % bool_t replace_entry( entryp, entry_object_p );
253 %/* Deletes entry at specified location. Returns TRUE if location is valid;
254 % FALSE if location is invalid, or the freed location cannot be added to
255 % the freelist. 'count' is decremented if the deletion occurs. The object
256 % at that location is freed. */
257 % bool_t delete_entry( entryp );
259 %/* Returns statistics of table.
260 % <table_size><last_used><count>[freelist].
261 % It is up to the caller to free the returned vector when his is through
262 % The free list is included if 'fl' is TRUE. */
263 %long * stats( bool_t fl );
265 %/* Configure LDAP mapping */
266 % bool_t configure(char *objName);
268 %/* Initialize the mapping structure with default values */
269 % void initMappingStruct(__nisdb_table_mapping_t *mapping);
271 %/* Check if entry at 'loc' is valid (not expired) */
272 % bool_t cacheValid(entryp loc);
274 %/* Update expiration time if supplied object same as the one at 'loc' */
275 % bool_t dupEntry(entry_object *obj, entryp loc);
277 %/* Set expiration time for entry */
278 % void setEntryExp(entryp where, entry_object *obj, int initialLoad);
280 %/* Enable enum mode */
281 % void setEnumMode(long count);
282 %/* Clear enum mode */
283 % void clearEnumMode(void);
284 %/* End enum mode, return array of untouched entries */
285 % entry_object **endEnumMode(long *numEa);
286 %/* Mark the indicated entry used for enum purposes */
287 % void enumTouch(entryp loc);
288 %/* Add entry to enumIndex array */
289 % void enumSetup(entryp loc, long index);
290 %/* Touch the indicated entry */
291 % void touchEntry(entryp loc);
293 % db_status allocateEnumArray(long oldSize, long newSize);
296 %extern "C" bool_t xdr_db_table( XDR*, db_table*);
298 %extern bool_t xdr_db_table(XDR*, db_table*);
300 %typedef class db_table * db_table_p;
305 %#endif /* _DB_TABLE_H */