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