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