1 /*
2  * Please do not edit this file.
3  * It was generated using rpcgen.
4  */
5 
6 #ifndef _DB_TABLE_H_RPCGEN
7 #define	_DB_TABLE_H_RPCGEN
8 
9 #include <rpc/rpc.h>
10 #pragma ident	"%Z%%M%	%I%	%E% SMI"
11 #ifndef _DB_TABLE_H
12 #define _DB_TABLE_H
13 #include "db_query.h"
14 #include "db_scheme.h"
15 
16 #include "nisdb_ldap.h"
17 #include "nisdb_rw.h"
18 #include "ldap_parse.h"
19 #include "ldap_map.h"
20 #include "ldap_util.h"
21 #include "ldap_nisdbquery.h"
22 #include "ldap_print.h"
23 #include "ldap_xdr.h"
24 
25 
26 typedef long entryp;
27 
28 struct db_free_entry {
29 	entryp where;
30 	struct db_free_entry *next;
31 };
32 typedef struct db_free_entry db_free_entry;
33 
34 typedef db_free_entry *db_free_entry_p;
35 class db_free_list {
36   db_free_entry_p head;
37   long count;
38   STRUCTRWLOCK(free_list);
39  public:
40   db_free_list() {   /* free list constructor */
41 	head = NULL;
42 	count = 0;
43 	INITRW(free_list);
44   }
45 
46   ~db_free_list();
47 
48   void reset();   /* empty contents of free list */
49 
50   void init();		/* Empty free list */
51 
52 /* Returns the location of a free entry, or NULL, if there aren't any. */
53   entryp pop();
54 
55 /* Adds given location to the free list.
56    Returns TRUE if successful, FALSE otherwise (when out of memory). */
57   bool_t push( entryp );
58 
59 /* Returns in a vector the information in the free list.
60    Vector returned is of form: <n free cells><n1><n2><loc1>,..<locn>.
61    Leave the first 'n' cells free.
62    n1 is the number of entries that should be in the freelist.
63    n2 is the number of entries actually found in the freelist.
64    <loc1...locn> are the entries.   n2 <= n1 because we never count beyond n1.
65    It is up to the caller to free the returned vector when he is through. */
66  long* stats( int n );
67 
68 /* Locking methods */
69 
70   int acqexcl(void) {
71 	return (WLOCK(free_list));
72   }
73 
74   int relexcl(void) {
75 	return (WULOCK(free_list));
76   }
77 
78   int acqnonexcl(void) {
79 	return (RLOCK(free_list));
80   }
81 
82   int relnonexcl(void) {
83 	return (RULOCK(free_list));
84   }
85 };
86 class db_table
87 {
88   long table_size;
89   entry_object_p *tab;   /* pointer to array of pointers to entry objects */
90   long last_used;        /* last entry used; maintained for quick insertion */
91   long count;            /* measures fullness of table */
92   db_free_list freelist;
93   STRUCTRWLOCK(table);
94   __nisdb_flag_t enumMode;
95   __nisdb_flag_t enumCount;
96   __nisdb_ptr_t  enumIndex;
97   __nisdb_ptr_t  enumArray;
98 
99   void grow();           /* Expand the table.
100 			    Fatal error if insufficient error. */
101 
102 /* Allocate expiration time array */
103   db_status allocateExpire(long oldSize, long newSize);
104 
105  public:
106   __nisdb_table_mapping_t mapping;
107 
108   db_table();            /* constructor for brand new, empty table. */
109   db_table( char * );    /* constructor for creating a table by loading
110 			    in an existing one. */
111 
112 /* Init of LDAP/MT portion of class instance */
113   void db_table_ldap_init(void);
114 /* Size of the non-MT/LDAP portion of the db_table structure */
115   ulong_t oldstructsize(void) {
116 	return ((ulong_t)&(this->table_rwlock) - (ulong_t)this);
117   }
118 /* Mark this instance as deferred */
119   void markDeferred(void) {
120 	mapping.isDeferredTable = TRUE;
121   }
122 /* Remove deferred mark */
123   void unmarkDeferred(void) {
124 	mapping.isDeferredTable = FALSE;
125   }
126 
127 /* Return the current 'tab' */
128   entry_object_p *gettab() { ASSERTRHELD(table); return (tab); };
129 /* Return how many entries there are in table. */
130   long fullness() { return count; }
131 
132 /* Deletes table, entries, and free list */
133   ~db_table();
134 
135   int tryacqexcl(void) {
136 	return (TRYWLOCK(table));
137   }
138 
139   int acqexcl(void) {
140 	return (WLOCK(table));
141   }
142 
143   int relexcl(void) {
144 	return (WULOCK(table));
145   }
146 
147   int acqnonexcl(void) {
148 	return (RLOCK(table));
149   }
150 
151   int relnonexcl(void) {
152 	return (RULOCK(table));
153   }
154 
155 /* empties table by deleting all entries and other associated data structures */
156    void reset();
157 
158   int dump( char *);
159 
160 /* Returns whether location is valid. */
161   bool_t entry_exists_p( entryp i );
162 
163 /* Returns table size. */
164   long getsize()  { return table_size; }
165 
166 /* Returns the first entry in table, also return its position in
167    'where'.  Return NULL in both if no next entry is found. */
168   entry_object_p first_entry( entryp * where );
169 
170 /* Returns the next entry in table from 'prev', also return its position in
171    'newentry'.  Return NULL in both if no next entry is found. */
172   entry_object_p next_entry( entryp, entryp* );
173 
174 /* Returns entry at location 'where', NULL if location is invalid. */
175   entry_object_p get_entry( entryp );
176 
177 /* Adds given entry to table in first available slot (either look in freelist
178    or add to end of table) and return the the position of where the record
179    is placed. 'count' is incremented if entry is added. Table may grow
180    as a side-effect of the addition. Copy is made of the input. */
181   entryp add_entry(entry_object_p, int);
182 
183  /* Replaces object at specified location by given entry.
184    Returns TRUE if replacement successful; FALSE otherwise.
185    There must something already at the specified location, otherwise,
186    replacement fails. Copy is not made of the input.
187    The pre-existing entry is freed.*/
188   bool_t replace_entry( entryp, entry_object_p );
189 
190 /* Deletes entry at specified location.  Returns TRUE if location is valid;
191    FALSE if location is invalid, or the freed location cannot be added to
192    the freelist.  'count' is decremented if the deletion occurs.  The object
193    at that location is freed. */
194   bool_t delete_entry( entryp );
195 
196 /* Returns statistics of table.
197    <table_size><last_used><count>[freelist].
198    It is up to the caller to free the returned vector when his is through
199    The free list is included if 'fl' is TRUE. */
200 long * stats( bool_t fl );
201 
202 /* Configure LDAP mapping */
203   bool_t configure(char *objName);
204 
205 /* Initialize the mapping structure with default values */
206   void initMappingStruct(__nisdb_table_mapping_t *mapping);
207 
208 /* Check if entry at 'loc' is valid (not expired) */
209   bool_t cacheValid(entryp loc);
210 
211 /* Update expiration time if supplied object same as the one at 'loc' */
212   bool_t dupEntry(entry_object *obj, entryp loc);
213 
214 /* Set expiration time for entry */
215   void setEntryExp(entryp where, entry_object *obj, int initialLoad);
216 
217 /* Enable enum mode */
218   void setEnumMode(long count);
219 /* Clear enum mode */
220   void clearEnumMode(void);
221 /* End enum mode, return array of untouched entries */
222   entry_object **endEnumMode(long *numEa);
223 /* Mark the indicated entry used for enum purposes */
224   void enumTouch(entryp loc);
225 /* Add entry to enumIndex array */
226   void enumSetup(entryp loc, long index);
227 /* Touch the indicated entry */
228   void touchEntry(entryp loc);
229 
230   db_status allocateEnumArray(long oldSize, long newSize);
231 };
232 #ifdef __cplusplus
233 extern "C" bool_t xdr_db_table( XDR*, db_table*);
234 #elif __STDC__
235 extern bool_t xdr_db_table(XDR*, db_table*);
236 #endif
237 typedef class db_table * db_table_p;
238 #endif /* _DB_TABLE_H */
239 
240 /* the xdr functions */
241 extern bool_t xdr_entryp();
242 extern bool_t xdr_db_free_entry();
243 extern bool_t xdr_db_free_entry_p();
244 
245 #endif /* !_DB_TABLE_H_RPCGEN */
246