xref: /illumos-gate/usr/src/lib/libnisdb/db_table_c.x (revision 1da57d55)
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 #if RPC_HDR
307c478bd9Sstevel@tonic-gate %#ifndef _DB_TABLE_H
317c478bd9Sstevel@tonic-gate %#define _DB_TABLE_H
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #ifdef USINGC
347c478bd9Sstevel@tonic-gate %#include "db_query_c.h"
357c478bd9Sstevel@tonic-gate %#include "db_scheme_c.h"
367c478bd9Sstevel@tonic-gate #else
377c478bd9Sstevel@tonic-gate %#include "db_query.h"
387c478bd9Sstevel@tonic-gate %#include "db_scheme.h"
39*a506a34cSth160488 #endif /* USINGC */
40*a506a34cSth160488 #endif /* RPC_HDR */
417c478bd9Sstevel@tonic-gate %
427c478bd9Sstevel@tonic-gate %#include "nisdb_ldap.h"
437c478bd9Sstevel@tonic-gate %#include "nisdb_rw.h"
447c478bd9Sstevel@tonic-gate %#include "ldap_parse.h"
457c478bd9Sstevel@tonic-gate %#include "ldap_map.h"
467c478bd9Sstevel@tonic-gate %#include "ldap_util.h"
477c478bd9Sstevel@tonic-gate %#include "ldap_nisdbquery.h"
487c478bd9Sstevel@tonic-gate %#include "ldap_print.h"
497c478bd9Sstevel@tonic-gate %#include "ldap_xdr.h"
507c478bd9Sstevel@tonic-gate %
517c478bd9Sstevel@tonic-gate typedef long entryp;      /* specifies location of an entry within table */
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate struct db_free_entry {
547c478bd9Sstevel@tonic-gate   entryp where;
557c478bd9Sstevel@tonic-gate   struct db_free_entry *next;
567c478bd9Sstevel@tonic-gate };
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate typedef struct db_free_entry * db_free_entry_p;
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate #if RPC_HDR || RPC_XDR
617c478bd9Sstevel@tonic-gate #ifdef USINGC
627c478bd9Sstevel@tonic-gate struct db_free_list {
637c478bd9Sstevel@tonic-gate   db_free_entry_p head;
647c478bd9Sstevel@tonic-gate   long count;
657c478bd9Sstevel@tonic-gate   __nisdb_rwlock_t free_list_rwlock;
667c478bd9Sstevel@tonic-gate };
677c478bd9Sstevel@tonic-gate typedef struct db_free_list * db_free_list_p;
68*a506a34cSth160488 #endif /* USINGC */
69*a506a34cSth160488 #endif /* RPC_HDR */
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate #ifndef USINGC
727c478bd9Sstevel@tonic-gate #ifdef RPC_HDR
737c478bd9Sstevel@tonic-gate %class db_free_list {
747c478bd9Sstevel@tonic-gate %  db_free_entry_p head;
757c478bd9Sstevel@tonic-gate %  long count;
767c478bd9Sstevel@tonic-gate %  STRUCTRWLOCK(free_list);
777c478bd9Sstevel@tonic-gate % public:
787c478bd9Sstevel@tonic-gate %  db_free_list() {   /* free list constructor */
797c478bd9Sstevel@tonic-gate %	head = NULL;
807c478bd9Sstevel@tonic-gate %	count = 0;
817c478bd9Sstevel@tonic-gate %	INITRW(free_list);
827c478bd9Sstevel@tonic-gate %  }
837c478bd9Sstevel@tonic-gate %
847c478bd9Sstevel@tonic-gate %  ~db_free_list();
857c478bd9Sstevel@tonic-gate %
867c478bd9Sstevel@tonic-gate %  void reset();   /* empty contents of free list */
877c478bd9Sstevel@tonic-gate %
887c478bd9Sstevel@tonic-gate %  void init();		/* Empty free list */
897c478bd9Sstevel@tonic-gate %
907c478bd9Sstevel@tonic-gate %/* Returns the location of a free entry, or NULL, if there aren't any. */
917c478bd9Sstevel@tonic-gate %  entryp pop();
927c478bd9Sstevel@tonic-gate %
937c478bd9Sstevel@tonic-gate %/* Adds given location to the free list.
947c478bd9Sstevel@tonic-gate %   Returns TRUE if successful, FALSE otherwise (when out of memory). */
957c478bd9Sstevel@tonic-gate %  bool_t push( entryp );
967c478bd9Sstevel@tonic-gate %
977c478bd9Sstevel@tonic-gate %/* Returns in a vector the information in the free list.
987c478bd9Sstevel@tonic-gate %   Vector returned is of form: <n free cells><n1><n2><loc1>,..<locn>.
997c478bd9Sstevel@tonic-gate %   Leave the first 'n' cells free.
1007c478bd9Sstevel@tonic-gate %   n1 is the number of entries that should be in the freelist.
1017c478bd9Sstevel@tonic-gate %   n2 is the number of entries actually found in the freelist.
1027c478bd9Sstevel@tonic-gate %   <loc1...locn> are the entries.   n2 <= n1 because we never count beyond n1.
1037c478bd9Sstevel@tonic-gate %   It is up to the caller to free the returned vector when he is through. */
1047c478bd9Sstevel@tonic-gate % long* stats( int n );
1057c478bd9Sstevel@tonic-gate %
1067c478bd9Sstevel@tonic-gate %/* Locking methods */
1077c478bd9Sstevel@tonic-gate %
1087c478bd9Sstevel@tonic-gate %  int acqexcl(void) {
1097c478bd9Sstevel@tonic-gate %	return (WLOCK(free_list));
1107c478bd9Sstevel@tonic-gate %  }
1117c478bd9Sstevel@tonic-gate %
1127c478bd9Sstevel@tonic-gate %  int relexcl(void) {
1137c478bd9Sstevel@tonic-gate %	return (WULOCK(free_list));
1147c478bd9Sstevel@tonic-gate %  }
1157c478bd9Sstevel@tonic-gate %
1167c478bd9Sstevel@tonic-gate %  int acqnonexcl(void) {
1177c478bd9Sstevel@tonic-gate %	return (RLOCK(free_list));
1187c478bd9Sstevel@tonic-gate %  }
1197c478bd9Sstevel@tonic-gate %
1207c478bd9Sstevel@tonic-gate %  int relnonexcl(void) {
1217c478bd9Sstevel@tonic-gate %	return (RULOCK(free_list));
1227c478bd9Sstevel@tonic-gate %  }
1237c478bd9Sstevel@tonic-gate %};
124*a506a34cSth160488 #endif /* RPC_HDR */
125*a506a34cSth160488 #endif /* USINGC */
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate #if RPC_HDR || RPC_XDR
1287c478bd9Sstevel@tonic-gate #ifdef USINGC
1297c478bd9Sstevel@tonic-gate struct db_table
1307c478bd9Sstevel@tonic-gate {
1317c478bd9Sstevel@tonic-gate   entry_object_p tab <>;
1327c478bd9Sstevel@tonic-gate   long last_used;        /* last entry used; maintained for quick insertion */
1337c478bd9Sstevel@tonic-gate   long count;            /* measures fullness of table */
1347c478bd9Sstevel@tonic-gate   db_free_list freelist;
1357c478bd9Sstevel@tonic-gate   __nisdb_rwlock_t table_rwlock;
1367c478bd9Sstevel@tonic-gate   __nisdb_flag_t enumMode;
1377c478bd9Sstevel@tonic-gate   __nisdb_ptr_t  enumArray;
1387c478bd9Sstevel@tonic-gate   __nis_table_mapping_t mapping;
1397c478bd9Sstevel@tonic-gate };
1407c478bd9Sstevel@tonic-gate typedef struct db_table * db_table_p;
1417c478bd9Sstevel@tonic-gate 
142*a506a34cSth160488 #endif /* USINGC */
143*a506a34cSth160488 #endif /* RPC_HDR */
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate #ifndef USINGC
1467c478bd9Sstevel@tonic-gate #ifdef RPC_HDR
1477c478bd9Sstevel@tonic-gate %class db_table
1487c478bd9Sstevel@tonic-gate %{
1497c478bd9Sstevel@tonic-gate %  long table_size;
1507c478bd9Sstevel@tonic-gate %  entry_object_p *tab;   /* pointer to array of pointers to entry objects */
1517c478bd9Sstevel@tonic-gate %  long last_used;        /* last entry used; maintained for quick insertion */
1527c478bd9Sstevel@tonic-gate %  long count;            /* measures fullness of table */
1537c478bd9Sstevel@tonic-gate %  db_free_list freelist;
1547c478bd9Sstevel@tonic-gate %  STRUCTRWLOCK(table);
1557c478bd9Sstevel@tonic-gate %  __nisdb_flag_t enumMode;
1567c478bd9Sstevel@tonic-gate %  __nisdb_flag_t enumCount;
1577c478bd9Sstevel@tonic-gate %  __nisdb_ptr_t  enumIndex;
1587c478bd9Sstevel@tonic-gate %  __nisdb_ptr_t  enumArray;
1597c478bd9Sstevel@tonic-gate %
1607c478bd9Sstevel@tonic-gate %  void grow();           /* Expand the table.
1617c478bd9Sstevel@tonic-gate %			    Fatal error if insufficient error. */
1627c478bd9Sstevel@tonic-gate %
1637c478bd9Sstevel@tonic-gate %/* Allocate expiration time array */
1647c478bd9Sstevel@tonic-gate %  db_status allocateExpire(long oldSize, long newSize);
1657c478bd9Sstevel@tonic-gate %
1667c478bd9Sstevel@tonic-gate % public:
1677c478bd9Sstevel@tonic-gate %  __nisdb_table_mapping_t mapping;
1687c478bd9Sstevel@tonic-gate %
1697c478bd9Sstevel@tonic-gate %  db_table();            /* constructor for brand new, empty table. */
1707c478bd9Sstevel@tonic-gate %  db_table( char * );    /* constructor for creating a table by loading
1717c478bd9Sstevel@tonic-gate %			    in an existing one. */
1727c478bd9Sstevel@tonic-gate %
1737c478bd9Sstevel@tonic-gate %/* Init of LDAP/MT portion of class instance */
1747c478bd9Sstevel@tonic-gate %  void db_table_ldap_init(void);
1757c478bd9Sstevel@tonic-gate %/* Size of the non-MT/LDAP portion of the db_table structure */
1767c478bd9Sstevel@tonic-gate %  ulong_t oldstructsize(void) {
1777c478bd9Sstevel@tonic-gate %	return ((ulong_t)&(this->table_rwlock) - (ulong_t)this);
1787c478bd9Sstevel@tonic-gate %  }
1797c478bd9Sstevel@tonic-gate %/* Mark this instance as deferred */
1807c478bd9Sstevel@tonic-gate %  void markDeferred(void) {
1817c478bd9Sstevel@tonic-gate %	mapping.isDeferredTable = TRUE;
1827c478bd9Sstevel@tonic-gate %  }
1837c478bd9Sstevel@tonic-gate %/* Remove deferred mark */
1847c478bd9Sstevel@tonic-gate %  void unmarkDeferred(void) {
1857c478bd9Sstevel@tonic-gate %	mapping.isDeferredTable = FALSE;
1867c478bd9Sstevel@tonic-gate %  }
1877c478bd9Sstevel@tonic-gate %
1887c478bd9Sstevel@tonic-gate %/* Return the current 'tab' */
1897c478bd9Sstevel@tonic-gate %  entry_object_p *gettab() { ASSERTRHELD(table); return (tab); };
1907c478bd9Sstevel@tonic-gate %/* Return how many entries there are in table. */
1917c478bd9Sstevel@tonic-gate %  long fullness() { return count; }
1927c478bd9Sstevel@tonic-gate %
1937c478bd9Sstevel@tonic-gate %/* Deletes table, entries, and free list */
1947c478bd9Sstevel@tonic-gate %  ~db_table();
1957c478bd9Sstevel@tonic-gate %
1967c478bd9Sstevel@tonic-gate %  int tryacqexcl(void) {
1977c478bd9Sstevel@tonic-gate %	return (TRYWLOCK(table));
1987c478bd9Sstevel@tonic-gate %  }
1997c478bd9Sstevel@tonic-gate %
2007c478bd9Sstevel@tonic-gate %  int acqexcl(void) {
2017c478bd9Sstevel@tonic-gate %	return (WLOCK(table));
2027c478bd9Sstevel@tonic-gate %  }
2037c478bd9Sstevel@tonic-gate %
2047c478bd9Sstevel@tonic-gate %  int relexcl(void) {
2057c478bd9Sstevel@tonic-gate %	return (WULOCK(table));
2067c478bd9Sstevel@tonic-gate %  }
2077c478bd9Sstevel@tonic-gate %
2087c478bd9Sstevel@tonic-gate %  int acqnonexcl(void) {
2097c478bd9Sstevel@tonic-gate %	return (RLOCK(table));
2107c478bd9Sstevel@tonic-gate %  }
2117c478bd9Sstevel@tonic-gate %
2127c478bd9Sstevel@tonic-gate %  int relnonexcl(void) {
2137c478bd9Sstevel@tonic-gate %	return (RULOCK(table));
2147c478bd9Sstevel@tonic-gate %  }
2157c478bd9Sstevel@tonic-gate %
2167c478bd9Sstevel@tonic-gate %/* empties table by deleting all entries and other associated data structures */
2177c478bd9Sstevel@tonic-gate %   void reset();
2187c478bd9Sstevel@tonic-gate %
2197c478bd9Sstevel@tonic-gate %  int dump( char *);
2207c478bd9Sstevel@tonic-gate %
2217c478bd9Sstevel@tonic-gate %/* Returns whether location is valid. */
2227c478bd9Sstevel@tonic-gate %  bool_t entry_exists_p( entryp i );
2237c478bd9Sstevel@tonic-gate %
2247c478bd9Sstevel@tonic-gate %/* Returns table size. */
2257c478bd9Sstevel@tonic-gate %  long getsize()  { return table_size; }
2267c478bd9Sstevel@tonic-gate %
2277c478bd9Sstevel@tonic-gate %/* Returns the first entry in table, also return its position in
2287c478bd9Sstevel@tonic-gate %   'where'.  Return NULL in both if no next entry is found. */
2297c478bd9Sstevel@tonic-gate %  entry_object_p first_entry( entryp * where );
2307c478bd9Sstevel@tonic-gate %
2317c478bd9Sstevel@tonic-gate %/* Returns the next entry in table from 'prev', also return its position in
2327c478bd9Sstevel@tonic-gate %   'newentry'.  Return NULL in both if no next entry is found. */
2337c478bd9Sstevel@tonic-gate %  entry_object_p next_entry( entryp, entryp* );
2347c478bd9Sstevel@tonic-gate %
2357c478bd9Sstevel@tonic-gate %/* Returns entry at location 'where', NULL if location is invalid. */
2367c478bd9Sstevel@tonic-gate %  entry_object_p get_entry( entryp );
2377c478bd9Sstevel@tonic-gate %
2387c478bd9Sstevel@tonic-gate %/* Adds given entry to table in first available slot (either look in freelist
2397c478bd9Sstevel@tonic-gate %   or add to end of table) and return the the position of where the record
2407c478bd9Sstevel@tonic-gate %   is placed. 'count' is incremented if entry is added. Table may grow
2417c478bd9Sstevel@tonic-gate %   as a side-effect of the addition. Copy is made of the input. */
2427c478bd9Sstevel@tonic-gate %  entryp add_entry(entry_object_p, int);
2437c478bd9Sstevel@tonic-gate %
2447c478bd9Sstevel@tonic-gate % /* Replaces object at specified location by given entry.
2457c478bd9Sstevel@tonic-gate %   Returns TRUE if replacement successful; FALSE otherwise.
2467c478bd9Sstevel@tonic-gate %   There must something already at the specified location, otherwise,
2477c478bd9Sstevel@tonic-gate %   replacement fails. Copy is not made of the input.
2487c478bd9Sstevel@tonic-gate %   The pre-existing entry is freed.*/
2497c478bd9Sstevel@tonic-gate %  bool_t replace_entry( entryp, entry_object_p );
2507c478bd9Sstevel@tonic-gate %
2517c478bd9Sstevel@tonic-gate %/* Deletes entry at specified location.  Returns TRUE if location is valid;
2527c478bd9Sstevel@tonic-gate %   FALSE if location is invalid, or the freed location cannot be added to
2537c478bd9Sstevel@tonic-gate %   the freelist.  'count' is decremented if the deletion occurs.  The object
2547c478bd9Sstevel@tonic-gate %   at that location is freed. */
2557c478bd9Sstevel@tonic-gate %  bool_t delete_entry( entryp );
2567c478bd9Sstevel@tonic-gate %
2577c478bd9Sstevel@tonic-gate %/* Returns statistics of table.
2587c478bd9Sstevel@tonic-gate %   <table_size><last_used><count>[freelist].
2597c478bd9Sstevel@tonic-gate %   It is up to the caller to free the returned vector when his is through
2607c478bd9Sstevel@tonic-gate %   The free list is included if 'fl' is TRUE. */
2617c478bd9Sstevel@tonic-gate %long * stats( bool_t fl );
2627c478bd9Sstevel@tonic-gate %
2637c478bd9Sstevel@tonic-gate %/* Configure LDAP mapping */
2647c478bd9Sstevel@tonic-gate %  bool_t configure(char *objName);
2657c478bd9Sstevel@tonic-gate %
2667c478bd9Sstevel@tonic-gate %/* Initialize the mapping structure with default values */
2677c478bd9Sstevel@tonic-gate %  void initMappingStruct(__nisdb_table_mapping_t *mapping);
2687c478bd9Sstevel@tonic-gate %
2697c478bd9Sstevel@tonic-gate %/* Check if entry at 'loc' is valid (not expired) */
2707c478bd9Sstevel@tonic-gate %  bool_t cacheValid(entryp loc);
2717c478bd9Sstevel@tonic-gate %
2727c478bd9Sstevel@tonic-gate %/* Update expiration time if supplied object same as the one at 'loc' */
2737c478bd9Sstevel@tonic-gate %  bool_t dupEntry(entry_object *obj, entryp loc);
2747c478bd9Sstevel@tonic-gate %
2757c478bd9Sstevel@tonic-gate %/* Set expiration time for entry */
2767c478bd9Sstevel@tonic-gate %  void setEntryExp(entryp where, entry_object *obj, int initialLoad);
2777c478bd9Sstevel@tonic-gate %
2787c478bd9Sstevel@tonic-gate %/* Enable enum mode */
2797c478bd9Sstevel@tonic-gate %  void setEnumMode(long count);
2807c478bd9Sstevel@tonic-gate %/* Clear enum mode */
2817c478bd9Sstevel@tonic-gate %  void clearEnumMode(void);
2827c478bd9Sstevel@tonic-gate %/* End enum mode, return array of untouched entries */
2837c478bd9Sstevel@tonic-gate %  entry_object **endEnumMode(long *numEa);
2847c478bd9Sstevel@tonic-gate %/* Mark the indicated entry used for enum purposes */
2857c478bd9Sstevel@tonic-gate %  void enumTouch(entryp loc);
2867c478bd9Sstevel@tonic-gate %/* Add entry to enumIndex array */
2877c478bd9Sstevel@tonic-gate %  void enumSetup(entryp loc, long index);
2887c478bd9Sstevel@tonic-gate %/* Touch the indicated entry */
2897c478bd9Sstevel@tonic-gate %  void touchEntry(entryp loc);
2907c478bd9Sstevel@tonic-gate %
2917c478bd9Sstevel@tonic-gate %  db_status allocateEnumArray(long oldSize, long newSize);
2927c478bd9Sstevel@tonic-gate %};
2937c478bd9Sstevel@tonic-gate %#ifdef __cplusplus
2947c478bd9Sstevel@tonic-gate %extern "C" bool_t xdr_db_table( XDR*, db_table*);
2957c478bd9Sstevel@tonic-gate %#elif __STDC__
2967c478bd9Sstevel@tonic-gate %extern bool_t xdr_db_table(XDR*, db_table*);
2977c478bd9Sstevel@tonic-gate %#endif
2987c478bd9Sstevel@tonic-gate %typedef class db_table * db_table_p;
299*a506a34cSth160488 #endif /* RPC_HDR */
300*a506a34cSth160488 #endif /* USINGC */
3017c478bd9Sstevel@tonic-gate 
3027c478bd9Sstevel@tonic-gate #if RPC_HDR
303*a506a34cSth160488 %#endif /* _DB_TABLE_H */
304*a506a34cSth160488 #endif /* RPC_HDR */
305