17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 237c478bd9Sstevel@tonic-gate * db_table_c.x 247c478bd9Sstevel@tonic-gate * 25*a506a34cSth160488 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 26*a506a34cSth160488 * Use is subject to license terms. 277c478bd9Sstevel@tonic-gate */ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate %#pragma ident "%Z%%M% %I% %E% SMI" 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #if RPC_HDR 327c478bd9Sstevel@tonic-gate %#ifndef _DB_TABLE_H 337c478bd9Sstevel@tonic-gate %#define _DB_TABLE_H 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate #ifdef USINGC 367c478bd9Sstevel@tonic-gate %#include "db_query_c.h" 377c478bd9Sstevel@tonic-gate %#include "db_scheme_c.h" 387c478bd9Sstevel@tonic-gate #else 397c478bd9Sstevel@tonic-gate %#include "db_query.h" 407c478bd9Sstevel@tonic-gate %#include "db_scheme.h" 41*a506a34cSth160488 #endif /* USINGC */ 42*a506a34cSth160488 #endif /* RPC_HDR */ 437c478bd9Sstevel@tonic-gate % 447c478bd9Sstevel@tonic-gate %#include "nisdb_ldap.h" 457c478bd9Sstevel@tonic-gate %#include "nisdb_rw.h" 467c478bd9Sstevel@tonic-gate %#include "ldap_parse.h" 477c478bd9Sstevel@tonic-gate %#include "ldap_map.h" 487c478bd9Sstevel@tonic-gate %#include "ldap_util.h" 497c478bd9Sstevel@tonic-gate %#include "ldap_nisdbquery.h" 507c478bd9Sstevel@tonic-gate %#include "ldap_print.h" 517c478bd9Sstevel@tonic-gate %#include "ldap_xdr.h" 527c478bd9Sstevel@tonic-gate % 537c478bd9Sstevel@tonic-gate typedef long entryp; /* specifies location of an entry within table */ 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate struct db_free_entry { 567c478bd9Sstevel@tonic-gate entryp where; 577c478bd9Sstevel@tonic-gate struct db_free_entry *next; 587c478bd9Sstevel@tonic-gate }; 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate typedef struct db_free_entry * db_free_entry_p; 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate #if RPC_HDR || RPC_XDR 637c478bd9Sstevel@tonic-gate #ifdef USINGC 647c478bd9Sstevel@tonic-gate struct db_free_list { 657c478bd9Sstevel@tonic-gate db_free_entry_p head; 667c478bd9Sstevel@tonic-gate long count; 677c478bd9Sstevel@tonic-gate __nisdb_rwlock_t free_list_rwlock; 687c478bd9Sstevel@tonic-gate }; 697c478bd9Sstevel@tonic-gate typedef struct db_free_list * db_free_list_p; 70*a506a34cSth160488 #endif /* USINGC */ 71*a506a34cSth160488 #endif /* RPC_HDR */ 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate #ifndef USINGC 747c478bd9Sstevel@tonic-gate #ifdef RPC_HDR 757c478bd9Sstevel@tonic-gate %class db_free_list { 767c478bd9Sstevel@tonic-gate % db_free_entry_p head; 777c478bd9Sstevel@tonic-gate % long count; 787c478bd9Sstevel@tonic-gate % STRUCTRWLOCK(free_list); 797c478bd9Sstevel@tonic-gate % public: 807c478bd9Sstevel@tonic-gate % db_free_list() { /* free list constructor */ 817c478bd9Sstevel@tonic-gate % head = NULL; 827c478bd9Sstevel@tonic-gate % count = 0; 837c478bd9Sstevel@tonic-gate % INITRW(free_list); 847c478bd9Sstevel@tonic-gate % } 857c478bd9Sstevel@tonic-gate % 867c478bd9Sstevel@tonic-gate % ~db_free_list(); 877c478bd9Sstevel@tonic-gate % 887c478bd9Sstevel@tonic-gate % void reset(); /* empty contents of free list */ 897c478bd9Sstevel@tonic-gate % 907c478bd9Sstevel@tonic-gate % void init(); /* Empty free list */ 917c478bd9Sstevel@tonic-gate % 927c478bd9Sstevel@tonic-gate %/* Returns the location of a free entry, or NULL, if there aren't any. */ 937c478bd9Sstevel@tonic-gate % entryp pop(); 947c478bd9Sstevel@tonic-gate % 957c478bd9Sstevel@tonic-gate %/* Adds given location to the free list. 967c478bd9Sstevel@tonic-gate % Returns TRUE if successful, FALSE otherwise (when out of memory). */ 977c478bd9Sstevel@tonic-gate % bool_t push( entryp ); 987c478bd9Sstevel@tonic-gate % 997c478bd9Sstevel@tonic-gate %/* Returns in a vector the information in the free list. 1007c478bd9Sstevel@tonic-gate % Vector returned is of form: <n free cells><n1><n2><loc1>,..<locn>. 1017c478bd9Sstevel@tonic-gate % Leave the first 'n' cells free. 1027c478bd9Sstevel@tonic-gate % n1 is the number of entries that should be in the freelist. 1037c478bd9Sstevel@tonic-gate % n2 is the number of entries actually found in the freelist. 1047c478bd9Sstevel@tonic-gate % <loc1...locn> are the entries. n2 <= n1 because we never count beyond n1. 1057c478bd9Sstevel@tonic-gate % It is up to the caller to free the returned vector when he is through. */ 1067c478bd9Sstevel@tonic-gate % long* stats( int n ); 1077c478bd9Sstevel@tonic-gate % 1087c478bd9Sstevel@tonic-gate %/* Locking methods */ 1097c478bd9Sstevel@tonic-gate % 1107c478bd9Sstevel@tonic-gate % int acqexcl(void) { 1117c478bd9Sstevel@tonic-gate % return (WLOCK(free_list)); 1127c478bd9Sstevel@tonic-gate % } 1137c478bd9Sstevel@tonic-gate % 1147c478bd9Sstevel@tonic-gate % int relexcl(void) { 1157c478bd9Sstevel@tonic-gate % return (WULOCK(free_list)); 1167c478bd9Sstevel@tonic-gate % } 1177c478bd9Sstevel@tonic-gate % 1187c478bd9Sstevel@tonic-gate % int acqnonexcl(void) { 1197c478bd9Sstevel@tonic-gate % return (RLOCK(free_list)); 1207c478bd9Sstevel@tonic-gate % } 1217c478bd9Sstevel@tonic-gate % 1227c478bd9Sstevel@tonic-gate % int relnonexcl(void) { 1237c478bd9Sstevel@tonic-gate % return (RULOCK(free_list)); 1247c478bd9Sstevel@tonic-gate % } 1257c478bd9Sstevel@tonic-gate %}; 126*a506a34cSth160488 #endif /* RPC_HDR */ 127*a506a34cSth160488 #endif /* USINGC */ 1287c478bd9Sstevel@tonic-gate 1297c478bd9Sstevel@tonic-gate #if RPC_HDR || RPC_XDR 1307c478bd9Sstevel@tonic-gate #ifdef USINGC 1317c478bd9Sstevel@tonic-gate struct db_table 1327c478bd9Sstevel@tonic-gate { 1337c478bd9Sstevel@tonic-gate entry_object_p tab <>; 1347c478bd9Sstevel@tonic-gate long last_used; /* last entry used; maintained for quick insertion */ 1357c478bd9Sstevel@tonic-gate long count; /* measures fullness of table */ 1367c478bd9Sstevel@tonic-gate db_free_list freelist; 1377c478bd9Sstevel@tonic-gate __nisdb_rwlock_t table_rwlock; 1387c478bd9Sstevel@tonic-gate __nisdb_flag_t enumMode; 1397c478bd9Sstevel@tonic-gate __nisdb_ptr_t enumArray; 1407c478bd9Sstevel@tonic-gate __nis_table_mapping_t mapping; 1417c478bd9Sstevel@tonic-gate }; 1427c478bd9Sstevel@tonic-gate typedef struct db_table * db_table_p; 1437c478bd9Sstevel@tonic-gate 144*a506a34cSth160488 #endif /* USINGC */ 145*a506a34cSth160488 #endif /* RPC_HDR */ 1467c478bd9Sstevel@tonic-gate 1477c478bd9Sstevel@tonic-gate #ifndef USINGC 1487c478bd9Sstevel@tonic-gate #ifdef RPC_HDR 1497c478bd9Sstevel@tonic-gate %class db_table 1507c478bd9Sstevel@tonic-gate %{ 1517c478bd9Sstevel@tonic-gate % long table_size; 1527c478bd9Sstevel@tonic-gate % entry_object_p *tab; /* pointer to array of pointers to entry objects */ 1537c478bd9Sstevel@tonic-gate % long last_used; /* last entry used; maintained for quick insertion */ 1547c478bd9Sstevel@tonic-gate % long count; /* measures fullness of table */ 1557c478bd9Sstevel@tonic-gate % db_free_list freelist; 1567c478bd9Sstevel@tonic-gate % STRUCTRWLOCK(table); 1577c478bd9Sstevel@tonic-gate % __nisdb_flag_t enumMode; 1587c478bd9Sstevel@tonic-gate % __nisdb_flag_t enumCount; 1597c478bd9Sstevel@tonic-gate % __nisdb_ptr_t enumIndex; 1607c478bd9Sstevel@tonic-gate % __nisdb_ptr_t enumArray; 1617c478bd9Sstevel@tonic-gate % 1627c478bd9Sstevel@tonic-gate % void grow(); /* Expand the table. 1637c478bd9Sstevel@tonic-gate % Fatal error if insufficient error. */ 1647c478bd9Sstevel@tonic-gate % 1657c478bd9Sstevel@tonic-gate %/* Allocate expiration time array */ 1667c478bd9Sstevel@tonic-gate % db_status allocateExpire(long oldSize, long newSize); 1677c478bd9Sstevel@tonic-gate % 1687c478bd9Sstevel@tonic-gate % public: 1697c478bd9Sstevel@tonic-gate % __nisdb_table_mapping_t mapping; 1707c478bd9Sstevel@tonic-gate % 1717c478bd9Sstevel@tonic-gate % db_table(); /* constructor for brand new, empty table. */ 1727c478bd9Sstevel@tonic-gate % db_table( char * ); /* constructor for creating a table by loading 1737c478bd9Sstevel@tonic-gate % in an existing one. */ 1747c478bd9Sstevel@tonic-gate % 1757c478bd9Sstevel@tonic-gate %/* Init of LDAP/MT portion of class instance */ 1767c478bd9Sstevel@tonic-gate % void db_table_ldap_init(void); 1777c478bd9Sstevel@tonic-gate %/* Size of the non-MT/LDAP portion of the db_table structure */ 1787c478bd9Sstevel@tonic-gate % ulong_t oldstructsize(void) { 1797c478bd9Sstevel@tonic-gate % return ((ulong_t)&(this->table_rwlock) - (ulong_t)this); 1807c478bd9Sstevel@tonic-gate % } 1817c478bd9Sstevel@tonic-gate %/* Mark this instance as deferred */ 1827c478bd9Sstevel@tonic-gate % void markDeferred(void) { 1837c478bd9Sstevel@tonic-gate % mapping.isDeferredTable = TRUE; 1847c478bd9Sstevel@tonic-gate % } 1857c478bd9Sstevel@tonic-gate %/* Remove deferred mark */ 1867c478bd9Sstevel@tonic-gate % void unmarkDeferred(void) { 1877c478bd9Sstevel@tonic-gate % mapping.isDeferredTable = FALSE; 1887c478bd9Sstevel@tonic-gate % } 1897c478bd9Sstevel@tonic-gate % 1907c478bd9Sstevel@tonic-gate %/* Return the current 'tab' */ 1917c478bd9Sstevel@tonic-gate % entry_object_p *gettab() { ASSERTRHELD(table); return (tab); }; 1927c478bd9Sstevel@tonic-gate %/* Return how many entries there are in table. */ 1937c478bd9Sstevel@tonic-gate % long fullness() { return count; } 1947c478bd9Sstevel@tonic-gate % 1957c478bd9Sstevel@tonic-gate %/* Deletes table, entries, and free list */ 1967c478bd9Sstevel@tonic-gate % ~db_table(); 1977c478bd9Sstevel@tonic-gate % 1987c478bd9Sstevel@tonic-gate % int tryacqexcl(void) { 1997c478bd9Sstevel@tonic-gate % return (TRYWLOCK(table)); 2007c478bd9Sstevel@tonic-gate % } 2017c478bd9Sstevel@tonic-gate % 2027c478bd9Sstevel@tonic-gate % int acqexcl(void) { 2037c478bd9Sstevel@tonic-gate % return (WLOCK(table)); 2047c478bd9Sstevel@tonic-gate % } 2057c478bd9Sstevel@tonic-gate % 2067c478bd9Sstevel@tonic-gate % int relexcl(void) { 2077c478bd9Sstevel@tonic-gate % return (WULOCK(table)); 2087c478bd9Sstevel@tonic-gate % } 2097c478bd9Sstevel@tonic-gate % 2107c478bd9Sstevel@tonic-gate % int acqnonexcl(void) { 2117c478bd9Sstevel@tonic-gate % return (RLOCK(table)); 2127c478bd9Sstevel@tonic-gate % } 2137c478bd9Sstevel@tonic-gate % 2147c478bd9Sstevel@tonic-gate % int relnonexcl(void) { 2157c478bd9Sstevel@tonic-gate % return (RULOCK(table)); 2167c478bd9Sstevel@tonic-gate % } 2177c478bd9Sstevel@tonic-gate % 2187c478bd9Sstevel@tonic-gate %/* empties table by deleting all entries and other associated data structures */ 2197c478bd9Sstevel@tonic-gate % void reset(); 2207c478bd9Sstevel@tonic-gate % 2217c478bd9Sstevel@tonic-gate % int dump( char *); 2227c478bd9Sstevel@tonic-gate % 2237c478bd9Sstevel@tonic-gate %/* Returns whether location is valid. */ 2247c478bd9Sstevel@tonic-gate % bool_t entry_exists_p( entryp i ); 2257c478bd9Sstevel@tonic-gate % 2267c478bd9Sstevel@tonic-gate %/* Returns table size. */ 2277c478bd9Sstevel@tonic-gate % long getsize() { return table_size; } 2287c478bd9Sstevel@tonic-gate % 2297c478bd9Sstevel@tonic-gate %/* Returns the first entry in table, also return its position in 2307c478bd9Sstevel@tonic-gate % 'where'. Return NULL in both if no next entry is found. */ 2317c478bd9Sstevel@tonic-gate % entry_object_p first_entry( entryp * where ); 2327c478bd9Sstevel@tonic-gate % 2337c478bd9Sstevel@tonic-gate %/* Returns the next entry in table from 'prev', also return its position in 2347c478bd9Sstevel@tonic-gate % 'newentry'. Return NULL in both if no next entry is found. */ 2357c478bd9Sstevel@tonic-gate % entry_object_p next_entry( entryp, entryp* ); 2367c478bd9Sstevel@tonic-gate % 2377c478bd9Sstevel@tonic-gate %/* Returns entry at location 'where', NULL if location is invalid. */ 2387c478bd9Sstevel@tonic-gate % entry_object_p get_entry( entryp ); 2397c478bd9Sstevel@tonic-gate % 2407c478bd9Sstevel@tonic-gate %/* Adds given entry to table in first available slot (either look in freelist 2417c478bd9Sstevel@tonic-gate % or add to end of table) and return the the position of where the record 2427c478bd9Sstevel@tonic-gate % is placed. 'count' is incremented if entry is added. Table may grow 2437c478bd9Sstevel@tonic-gate % as a side-effect of the addition. Copy is made of the input. */ 2447c478bd9Sstevel@tonic-gate % entryp add_entry(entry_object_p, int); 2457c478bd9Sstevel@tonic-gate % 2467c478bd9Sstevel@tonic-gate % /* Replaces object at specified location by given entry. 2477c478bd9Sstevel@tonic-gate % Returns TRUE if replacement successful; FALSE otherwise. 2487c478bd9Sstevel@tonic-gate % There must something already at the specified location, otherwise, 2497c478bd9Sstevel@tonic-gate % replacement fails. Copy is not made of the input. 2507c478bd9Sstevel@tonic-gate % The pre-existing entry is freed.*/ 2517c478bd9Sstevel@tonic-gate % bool_t replace_entry( entryp, entry_object_p ); 2527c478bd9Sstevel@tonic-gate % 2537c478bd9Sstevel@tonic-gate %/* Deletes entry at specified location. Returns TRUE if location is valid; 2547c478bd9Sstevel@tonic-gate % FALSE if location is invalid, or the freed location cannot be added to 2557c478bd9Sstevel@tonic-gate % the freelist. 'count' is decremented if the deletion occurs. The object 2567c478bd9Sstevel@tonic-gate % at that location is freed. */ 2577c478bd9Sstevel@tonic-gate % bool_t delete_entry( entryp ); 2587c478bd9Sstevel@tonic-gate % 2597c478bd9Sstevel@tonic-gate %/* Returns statistics of table. 2607c478bd9Sstevel@tonic-gate % <table_size><last_used><count>[freelist]. 2617c478bd9Sstevel@tonic-gate % It is up to the caller to free the returned vector when his is through 2627c478bd9Sstevel@tonic-gate % The free list is included if 'fl' is TRUE. */ 2637c478bd9Sstevel@tonic-gate %long * stats( bool_t fl ); 2647c478bd9Sstevel@tonic-gate % 2657c478bd9Sstevel@tonic-gate %/* Configure LDAP mapping */ 2667c478bd9Sstevel@tonic-gate % bool_t configure(char *objName); 2677c478bd9Sstevel@tonic-gate % 2687c478bd9Sstevel@tonic-gate %/* Initialize the mapping structure with default values */ 2697c478bd9Sstevel@tonic-gate % void initMappingStruct(__nisdb_table_mapping_t *mapping); 2707c478bd9Sstevel@tonic-gate % 2717c478bd9Sstevel@tonic-gate %/* Check if entry at 'loc' is valid (not expired) */ 2727c478bd9Sstevel@tonic-gate % bool_t cacheValid(entryp loc); 2737c478bd9Sstevel@tonic-gate % 2747c478bd9Sstevel@tonic-gate %/* Update expiration time if supplied object same as the one at 'loc' */ 2757c478bd9Sstevel@tonic-gate % bool_t dupEntry(entry_object *obj, entryp loc); 2767c478bd9Sstevel@tonic-gate % 2777c478bd9Sstevel@tonic-gate %/* Set expiration time for entry */ 2787c478bd9Sstevel@tonic-gate % void setEntryExp(entryp where, entry_object *obj, int initialLoad); 2797c478bd9Sstevel@tonic-gate % 2807c478bd9Sstevel@tonic-gate %/* Enable enum mode */ 2817c478bd9Sstevel@tonic-gate % void setEnumMode(long count); 2827c478bd9Sstevel@tonic-gate %/* Clear enum mode */ 2837c478bd9Sstevel@tonic-gate % void clearEnumMode(void); 2847c478bd9Sstevel@tonic-gate %/* End enum mode, return array of untouched entries */ 2857c478bd9Sstevel@tonic-gate % entry_object **endEnumMode(long *numEa); 2867c478bd9Sstevel@tonic-gate %/* Mark the indicated entry used for enum purposes */ 2877c478bd9Sstevel@tonic-gate % void enumTouch(entryp loc); 2887c478bd9Sstevel@tonic-gate %/* Add entry to enumIndex array */ 2897c478bd9Sstevel@tonic-gate % void enumSetup(entryp loc, long index); 2907c478bd9Sstevel@tonic-gate %/* Touch the indicated entry */ 2917c478bd9Sstevel@tonic-gate % void touchEntry(entryp loc); 2927c478bd9Sstevel@tonic-gate % 2937c478bd9Sstevel@tonic-gate % db_status allocateEnumArray(long oldSize, long newSize); 2947c478bd9Sstevel@tonic-gate %}; 2957c478bd9Sstevel@tonic-gate %#ifdef __cplusplus 2967c478bd9Sstevel@tonic-gate %extern "C" bool_t xdr_db_table( XDR*, db_table*); 2977c478bd9Sstevel@tonic-gate %#elif __STDC__ 2987c478bd9Sstevel@tonic-gate %extern bool_t xdr_db_table(XDR*, db_table*); 2997c478bd9Sstevel@tonic-gate %#endif 3007c478bd9Sstevel@tonic-gate %typedef class db_table * db_table_p; 301*a506a34cSth160488 #endif /* RPC_HDR */ 302*a506a34cSth160488 #endif /* USINGC */ 3037c478bd9Sstevel@tonic-gate 3047c478bd9Sstevel@tonic-gate #if RPC_HDR 305*a506a34cSth160488 %#endif /* _DB_TABLE_H */ 306*a506a34cSth160488 #endif /* RPC_HDR */ 307