xref: /illumos-gate/usr/src/lib/libnisdb/db_table_c.x (revision 7a6d80f1660abd4755c68cbd094d4a914681d26e)
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_table_c.x
24  *
25  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
26  * Use is subject to license terms.
27  */
28 
29 #if RPC_HDR
30 %#ifndef _DB_TABLE_H
31 %#define _DB_TABLE_H
32 
33 #ifdef USINGC
34 %#include "db_query_c.h"
35 %#include "db_scheme_c.h"
36 #else
37 %#include "db_query.h"
38 %#include "db_scheme.h"
39 #endif /* USINGC */
40 #endif /* RPC_HDR */
41 %
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"
50 %
51 typedef long entryp;      /* specifies location of an entry within table */
52 
53 struct db_free_entry {
54   entryp where;
55   struct db_free_entry *next;
56 };
57 
58 typedef struct db_free_entry * db_free_entry_p;
59 
60 #if RPC_HDR || RPC_XDR
61 #ifdef USINGC
62 struct db_free_list {
63   db_free_entry_p head;
64   long count;
65   __nisdb_rwlock_t free_list_rwlock;
66 };
67 typedef struct db_free_list * db_free_list_p;
68 #endif /* USINGC */
69 #endif /* RPC_HDR */
70 
71 #ifndef USINGC
72 #ifdef RPC_HDR
73 %class db_free_list {
74 %  db_free_entry_p head;
75 %  long count;
76 %  STRUCTRWLOCK(free_list);
77 % public:
78 %  db_free_list() {   /* free list constructor */
79 %	head = NULL;
80 %	count = 0;
81 %	INITRW(free_list);
82 %  }
83 %
84 %  ~db_free_list();
85 %
86 %  void reset();   /* empty contents of free list */
87 %
88 %  void init();		/* Empty free list */
89 %
90 %/* Returns the location of a free entry, or NULL, if there aren't any. */
91 %  entryp pop();
92 %
93 %/* Adds given location to the free list.
94 %   Returns TRUE if successful, FALSE otherwise (when out of memory). */
95 %  bool_t push( entryp );
96 %
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 );
105 %
106 %/* Locking methods */
107 %
108 %  int acqexcl(void) {
109 %	return (WLOCK(free_list));
110 %  }
111 %
112 %  int relexcl(void) {
113 %	return (WULOCK(free_list));
114 %  }
115 %
116 %  int acqnonexcl(void) {
117 %	return (RLOCK(free_list));
118 %  }
119 %
120 %  int relnonexcl(void) {
121 %	return (RULOCK(free_list));
122 %  }
123 %};
124 #endif /* RPC_HDR */
125 #endif /* USINGC */
126 
127 #if RPC_HDR || RPC_XDR
128 #ifdef USINGC
129 struct db_table
130 {
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;
139 };
140 typedef struct db_table * db_table_p;
141 
142 #endif /* USINGC */
143 #endif /* RPC_HDR */
144 
145 #ifndef USINGC
146 #ifdef RPC_HDR
147 %class db_table
148 %{
149 %  long table_size;
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;
159 %
160 %  void grow();           /* Expand the table.
161 %			    Fatal error if insufficient error. */
162 %
163 %/* Allocate expiration time array */
164 %  db_status allocateExpire(long oldSize, long newSize);
165 %
166 % public:
167 %  __nisdb_table_mapping_t mapping;
168 %
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. */
172 %
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);
178 %  }
179 %/* Mark this instance as deferred */
180 %  void markDeferred(void) {
181 %	mapping.isDeferredTable = TRUE;
182 %  }
183 %/* Remove deferred mark */
184 %  void unmarkDeferred(void) {
185 %	mapping.isDeferredTable = FALSE;
186 %  }
187 %
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; }
192 %
193 %/* Deletes table, entries, and free list */
194 %  ~db_table();
195 %
196 %  int tryacqexcl(void) {
197 %	return (TRYWLOCK(table));
198 %  }
199 %
200 %  int acqexcl(void) {
201 %	return (WLOCK(table));
202 %  }
203 %
204 %  int relexcl(void) {
205 %	return (WULOCK(table));
206 %  }
207 %
208 %  int acqnonexcl(void) {
209 %	return (RLOCK(table));
210 %  }
211 %
212 %  int relnonexcl(void) {
213 %	return (RULOCK(table));
214 %  }
215 %
216 %/* empties table by deleting all entries and other associated data structures */
217 %   void reset();
218 %
219 %  int dump( char *);
220 %
221 %/* Returns whether location is valid. */
222 %  bool_t entry_exists_p( entryp i );
223 %
224 %/* Returns table size. */
225 %  long getsize()  { return table_size; }
226 %
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 );
230 %
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* );
234 %
235 %/* Returns entry at location 'where', NULL if location is invalid. */
236 %  entry_object_p get_entry( entryp );
237 %
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);
243 %
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 );
250 %
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 );
256 %
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 );
262 %
263 %/* Configure LDAP mapping */
264 %  bool_t configure(char *objName);
265 %
266 %/* Initialize the mapping structure with default values */
267 %  void initMappingStruct(__nisdb_table_mapping_t *mapping);
268 %
269 %/* Check if entry at 'loc' is valid (not expired) */
270 %  bool_t cacheValid(entryp loc);
271 %
272 %/* Update expiration time if supplied object same as the one at 'loc' */
273 %  bool_t dupEntry(entry_object *obj, entryp loc);
274 %
275 %/* Set expiration time for entry */
276 %  void setEntryExp(entryp where, entry_object *obj, int initialLoad);
277 %
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);
290 %
291 %  db_status allocateEnumArray(long oldSize, long newSize);
292 %};
293 %#ifdef __cplusplus
294 %extern "C" bool_t xdr_db_table( XDR*, db_table*);
295 %#elif __STDC__
296 %extern bool_t xdr_db_table(XDR*, db_table*);
297 %#endif
298 %typedef class db_table * db_table_p;
299 #endif /* RPC_HDR */
300 #endif /* USINGC */
301 
302 #if RPC_HDR
303 %#endif /* _DB_TABLE_H */
304 #endif /* RPC_HDR */
305