5910 libnisdb won't build with modern GCC
[unleashed.git] / usr / src / lib / libnisdb / db_mindex_c.x
blobacb6309fbe8c22afaf3d07fe6d7c7186ca1e2af4
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
22  *      db_mindex_c.x
23  *
24  * Copyright 2015 Gary Mills
25  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
26  * Use is subject to license terms.
27  */
29 #if RPC_XDR
30 %#include "ldap_xdr.h"
31 %#include "nis_clnt.h"
32 #endif /* RPC_XDR */
34 #if RPC_HDR
35 %#ifndef _DB_MINDEX_H
36 %#define _DB_MINDEX_H
38 #ifdef USINGC
39 %#include "db_vers_c.h"
40 %#include "db_table_c.h"
41 %#include "db_index_entry_c.h"
42 %#include "db_index_c.h"
43 %#include "db_scheme_c.h"
44 %#include "db_query_c.h"
45 #else
46 %#include "db_vers.h"
47 %#include "db_table.h"
48 %#include "db_index_entry.h"
49 %#include "db_index.h"
50 %#include "db_scheme.h"
51 %#include "db_query.h"
52 #endif /* USINGC */
53 %#include "ldap_parse.h"
54 %#include "nisdb_rw.h"
55 %#include "ldap_xdr.h"
56 #endif /* RPC_HDR */
58 #if RPC_HDR
59 %struct db_next_index_desc {
60 %  entryp location;
61 %  struct db_next_index_desc *next;
63 #ifndef USINGC  
64 %  db_next_index_desc( entryp loc, struct db_next_index_desc *n )
65 %    { location = loc; next = n; }
66 #endif /* USINGC */
68 %};
69 #endif /* RPC_HDR */
72 #if RPC_HDR || RPC_XDR
73 #ifdef USINGC
75 struct db_mindex {
76   vers rversion;
77   db_index indices<>;                /* indices[num_indices] */
78   db_table *table;
79   db_scheme *scheme;
80   __nisdb_ptr_t objPath;
81   __nisdb_flag_t noWriteThrough;
82   __nisdb_flag_t noLDAPquery;
83   __nisdb_flag_t initialLoad;
84   __nisdb_ptr_t dbptr;
85   __nisdb_rwlock_t mindex_rwlock;
87 typedef struct db_mindex  * db_mindex_p;
89 typedef string  strP<>;
91 struct xdr_nis_object_s {
92         int             xversion;
93         nis_object      *obj;
94         strP            dirEntry<>;
96 typedef struct xdr_nis_object_s xdr_nis_object_t;
98 #endif /* USINGC */
99 #endif /* RPC_HDR */
101 #ifndef USINGC
102 #ifdef RPC_HDR
104 %struct xdr_nis_object_s {
105 %       int                             version;
106 %       nis_object                      *obj;
107 %       struct {
108 %               uint_t  dirEntry_len;
109 %               char    **dirEntry_val;
110 %       }                               dirEntry;
112 %typedef struct xdr_nis_object_s        xdr_nis_object_t;
114 %class db_mindex {
115 %  vers rversion;
116 %//  int num_indices;
117 %//  db_index * indices;                /* indices[num_indices] */
118 %  struct {
119 %   int indices_len;
120 %   db_index *indices_val;
121 %  } indices;
122 %  db_table *table;
123 %  db_scheme *scheme;
124 %  __nisdb_ptr_t objPath;
125 %  __nisdb_flag_t noWriteThrough;
126 %  __nisdb_flag_t noLDAPquery;
127 %  __nisdb_flag_t initialLoad;
128 %  __nisdb_ptr_t dbptr;
129 %  STRUCTRWLOCK(mindex);
131 %/* Return a list of index_entries that satsify the given query 'q'.
132 %   Return the size of the list in 'count'. Return NULL if list is empty.
133 %   Return in 'valid' FALSE if query is not well formed. */
134 %  db_index_entry_p satisfy_query(db_query *, long *, bool_t *valid,
135 %                                       bool_t fromLDAP = FALSE);
136 %  db_index_entry_p satisfy_query(db_query *, long *, bool_t *valid = NULL);
138 %/* Returns a newly db_query containing the index values as
139 %   obtained from the given object.  The object itself, 
140 %   along with information on the scheme given, will determine 
141 %   which values are extracted from the object and placed into the query.
142 %   Returns an empty query if 'obj' is not a valid entry.
143 %   Note that space is allocated for the query and the index values 
144 %   (i.e. do not share pointers with strings in 'obj'.) */
145 %  db_query * extract_index_values_from_object( entry_object * ); 
147 %/* Returns a newly created db_query structure containing the index values
148 %   as obtained from the record named by 'recnum'.  The record itself, along
149 %   with information on the schema definition of this table, will determine
150 %   which values are extracted from the record and placed into the result.
151 %   Returns NULL if recnum is not a valid entry.
152 %   Note that space is allocated for the query and the index values 
153 %   (i.e. do not share pointers with strings in 'obj'.) */
154 %  db_query * extract_index_values_from_record( entryp );
156 %/* Returns an array of size 'count' of 'entry_object_p's, pointing to
157 %   copies of entry_objects named by the result list of db_index_entries 'res'.
159 %  entry_object_p * prepare_results( int, db_index_entry_p, db_status* );
161 %/* Remove the entry identified by 'recloc' from:
162 %   1.  all indices, as obtained by extracting the index values from the entry
163 %   2.  table where entry is stored. */
164 %  db_status remove_aux( entryp );
166 %/*  entry_object * get_record( entryp );*/
167 % public:
169 %/* Constructor:  Create empty table (no scheme, no table or indices). */
170 %  db_mindex();
172 %/* Constructor:  Create new table using scheme defintion supplied.
173 %   (Make copy of scheme and keep it with table.) */
174 %  db_mindex(db_scheme *, char *tablePath);
176 %/* destructor */
177 %  ~db_mindex();
179 %  db_index_entry_p satisfy_query_dbonly(db_query *, long *,
180 %                                       bool_t checkExpire,
181 %                                       bool_t *valid = NULL);
183 %/* Returns whether there table is valid (i.e. has scheme). */
184 %  bool_t good() { return scheme != NULL && table != NULL; }
186 %/* Change the version of the table to the one given. */
187 %  void change_version( vers *v ) {  rversion.assign( v );}
189 %/* Return the current version of the table. */
190 %  vers *get_version()  { return( &rversion ); }
192 %/* Reset contents of tables by: deleting indice entries, table entries */
193 %  void reset_tables();
195 %/* Reset the table by: deleting all the indices, table of entries, and its
196 %   scheme. Reset version to 0 */
197 %  void reset();
199 %/* Initialize table using information from specified file.
200 %   The table is first 'reset', then the attempt to load from the file
201 %   is made.  If the load failed, the table is again reset.
202 %   Therefore, the table will be modified regardless of the success of the 
203 %   load.  Returns TRUE if successful, FALSE otherwise. */
204 %  int load( char * );
206 %/* Initialize table using information given in scheme 'how'.
207 %   Record the scheme for later use (make copy of it);
208 %   create the required number of indices; and create table for storing 
209 %   entries.
210 %   The 'tablePath' is passed on to db_table in order to obtain the
211 %   NIS+/LDAP mapping information (if any). */
212 %  void init( db_scheme *);
214 %/* Write this structure (table, indices, scheme) into the specified file. */
215 %  int dump( char *);
217 %/* Removes the entry in the table named by given query 'q'.
218 %   If a NULL query is supplied, all entries in table are removed.
219 %   Returns DB_NOTFOUND if no entry is found.
220 %   Returns DB_SUCCESS if one entry is found; this entry is removed from
221 %   its record storage, and it is also removed from all the indices of the
222 %   table. If more than one entry satisfying 'q' is found, all are removed. */
223 %  db_status remove( db_query *);
225 %/* Add copy of given entry to table.  Entry is identified by query 'q'.
226 %   The entry (if any) satisfying the query is first deleted, then
227 %   added to the indices (using index values extracted form the given entry)
228 %   and the table.
229 %   Returns DB_NOTUNIQUE if more than one entry satisfies the query.
230 %   Returns DB_NOTFOUND if query is not well-formed.
231 %   Returns DB_SUCCESS if entry can be added.  */
232 %  db_status add( db_query *, entry_object* );
235 %/* Finds entry that satisfy the query 'q'.  Returns the answer by
236 %   setting the pointer 'rp' to point to the list of answers.
237 %   Note that the answers are pointers to copies of the entries.
238 %   Returns the number of answers find in 'count'.  
239 %   Returns DB_SUCCESS if search found at least one answer; 
240 %   returns DB_NOTFOUND if none is found. */
241 %  db_status lookup( db_query *, long *, entry_object_p ** );
243 %/* Returns the next entry in the table after 'previous' by setting 'answer' to
244 %   point to a copy of the entry_object.  Returns DB_SUCCESS if 'previous' 
245 %   is valid and next entry is found; DB_NOTFOUND otherwise.  Sets 'where' 
246 %   to location of where entry is found for input as subsequent 'next' 
247 %   operation. */
248 %  db_status next( entryp, entryp *, entry_object ** );
250 %/* Returns the next entry in the table after 'previous' by setting 'answer' to
251 %   point to a copy of the entry_object.  Returns DB_SUCCESS if 'previous' 
252 %   is valid and next entry is found; DB_NOTFOUND otherwise.  Sets 'where' 
253 %   to location of where entry is found for input as subsequent 'next' 
254 %   operation. */
255 %  db_status next( db_next_index_desc*, db_next_index_desc **, entry_object ** );
257 %/* Returns the first entry found in the table by setting 'answer' to
258 %   a copy of the entry_object.  Returns DB_SUCCESS if found; 
259 %   DB_NOTFOUND otherwise.  */
260 %  db_status first( entryp*, entry_object ** );
262 %/* Returns the first entry that satisfies query by setting 'answer' to
263 %   a copy of the entry_object.  Returns DB_SUCCESS if found; 
264 %   DB_NOTFOUND otherwise.  */
265 %  db_status first( db_query *, db_next_index_desc **, entry_object ** );
267 % /* Delete the given list of results; used when no longer interested in 
268 %    the results of the first/next query that returned this list.     */
269 %  db_status reset_next( db_next_index_desc *orig );
271 %/* Return all entries within table.  Returns the answer by
272 %   setting the pointer 'rp' to point to the list of answers.
273 %   Note that the answers are pointers to copies of the entries.
274 %   Returns the number of answers find in 'count'.  
275 %   Returns DB_SUCCESS if search found at least one answer; 
276 %   returns DB_NOTFOUND if none is found. */
277 %  db_status all( long *, entry_object_p ** );
279 %  /* for debugging */
280 %/* Prints statistics of the table.  This includes the size of the table,
281 %   the number of entries, and the index sizes. */
282 %  void print_stats();
284 %/* Prints statistics about all indices of table. */
285 %  void print_all_indices();
288 %/* Prints statistics about indices identified by 'n'. */
289 %  void print_index( int n );
291 %/* Configure LDAP mapping */
292 %  bool_t configure (char *objName);
294 %/* Mark this instance deferred */
295 %  void markDeferred(void) {
296 %       if (table != NULL) table->markDeferred();
297 %  }
298 %/* Remove deferred mark */
299 %  void unmarkDeferred(void) {
300 %       if (table != NULL) table->unmarkDeferred();
301 %  }
303 %/* Retrieve, remove, or store data from/in/to LDAP */
304 %  int queryLDAP(db_query *, char *, int);
305 %  int entriesFromLDAP(__nis_table_mapping_t *, db_query *, db_query *,
306 %                       char *, nis_object *, int);
308 %  int removeLDAP(db_query *, nis_object *o);
310 %  int storeObjLDAP(__nis_table_mapping_t *t, nis_object *o);
311 %  int storeLDAP(db_query *, entry_obj *, nis_object *, entry_obj *,
312 %               char *dbId);
314 %/* Set/clear no-write-through flag */
315 %  void setNoWriteThrough(void);
316 %  void clearNoWriteThrough(void);
318 %/* Set/clear no-LDAP-query flag */
319 %  void setNoLDAPquery(void);
320 %  void clearNoLDAPquery(void);
322 %/* Set/clear initialLoad flag */
323 %  void setInitialLoad(void);
324 %  void clearInitialLoad(void);
326 %/* Store/retrieve pointer to parent 'db' class instance */
327 %  void setDbPtr(void *ptr);
328 %  void *getDbPtr(void);
330 %/* Get pointer to private 'table' field */
331 %  db_table *getTable(void);
334 % * Update table entry per the (entry_object *). If 'replace' is set,
335 % * the entry is replaced or added; otherwise, it is removed.
336 % */
337 %  int updateTableEntry(entry_object *e, int replace, char *tableName,
338 %                       nis_object *obj, nis_object *tobj, uint32_t ttime,
339 %                       int *xid);
341 %/* Touch the indicated entry */
342 %  bool_t touchEntry(entry_object *e);
343 %  bool_t touchEntry(db_query *q);
345 %/* Return the 'scheme' pointer */
346 %  db_scheme *getScheme(void) {return (scheme);}
348 %/* RW lock functions */
350 %  int tryacqexcl(void) {
351 %       return (TRYWLOCK(mindex));
352 %  }
354 %  int acqexcl(void) {
355 %       return (WLOCK(mindex));
356 %  }
358 %  int relexcl(void) {
359 %       return (WULOCK(mindex));
360 %  }
362 %  int acqnonexcl(void) {
363 %       return (RLOCK(mindex));
364 %  }
366 %  int relnonexcl(void) {
367 %       return (RULOCK(mindex));
368 %  }
370 %#ifdef __cplusplus
371 %extern "C" bool_t xdr_db_mindex(XDR*, db_mindex*);
372 %#elif __STDC__
373 %extern bool_t xdr_db_mindex(XDR*, db_mindex*);
374 %#endif
375 %typedef class db_mindex * db_mindex_p;
376 #endif /* RPC_HDR */
377 #endif /* USINGC */
379 #if RPC_HDR
380 %#endif /* _DB_MINDEX_H */
381 #endif /* RPC_HDR */