2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License, Version 1.0 only
2N/A * (the "License"). You may not use this file except in compliance
2N/A * with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * db_table_c.x
2N/A *
2N/A * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A%#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A#if RPC_HDR
2N/A%#ifndef _DB_TABLE_H
2N/A%#define _DB_TABLE_H
2N/A
2N/A#ifdef USINGC
2N/A%#include "db_query_c.h"
2N/A%#include "db_scheme_c.h"
2N/A#else
2N/A%#include "db_query.h"
2N/A%#include "db_scheme.h"
2N/A#endif /* USINGC */
2N/A#endif /* RPC_HDR */
2N/A%
2N/A%#include "nisdb_ldap.h"
2N/A%#include "nisdb_rw.h"
2N/A%#include "ldap_parse.h"
2N/A%#include "ldap_map.h"
2N/A%#include "ldap_util.h"
2N/A%#include "ldap_nisdbquery.h"
2N/A%#include "ldap_print.h"
2N/A%#include "ldap_xdr.h"
2N/A%
2N/Atypedef long entryp; /* specifies location of an entry within table */
2N/A
2N/Astruct db_free_entry {
2N/A entryp where;
2N/A struct db_free_entry *next;
2N/A};
2N/A
2N/Atypedef struct db_free_entry * db_free_entry_p;
2N/A
2N/A#if RPC_HDR || RPC_XDR
2N/A#ifdef USINGC
2N/Astruct db_free_list {
2N/A db_free_entry_p head;
2N/A long count;
2N/A __nisdb_rwlock_t free_list_rwlock;
2N/A};
2N/Atypedef struct db_free_list * db_free_list_p;
2N/A#endif /* USINGC */
2N/A#endif /* RPC_HDR */
2N/A
2N/A#ifndef USINGC
2N/A#ifdef RPC_HDR
2N/A%class db_free_list {
2N/A% db_free_entry_p head;
2N/A% long count;
2N/A% STRUCTRWLOCK(free_list);
2N/A% public:
2N/A% db_free_list() { /* free list constructor */
2N/A% head = NULL;
2N/A% count = 0;
2N/A% INITRW(free_list);
2N/A% }
2N/A%
2N/A% ~db_free_list();
2N/A%
2N/A% void reset(); /* empty contents of free list */
2N/A%
2N/A% void init(); /* Empty free list */
2N/A%
2N/A%/* Returns the location of a free entry, or NULL, if there aren't any. */
2N/A% entryp pop();
2N/A%
2N/A%/* Adds given location to the free list.
2N/A% Returns TRUE if successful, FALSE otherwise (when out of memory). */
2N/A% bool_t push( entryp );
2N/A%
2N/A%/* Returns in a vector the information in the free list.
2N/A% Vector returned is of form: <n free cells><n1><n2><loc1>,..<locn>.
2N/A% Leave the first 'n' cells free.
2N/A% n1 is the number of entries that should be in the freelist.
2N/A% n2 is the number of entries actually found in the freelist.
2N/A% <loc1...locn> are the entries. n2 <= n1 because we never count beyond n1.
2N/A% It is up to the caller to free the returned vector when he is through. */
2N/A% long* stats( int n );
2N/A%
2N/A%/* Locking methods */
2N/A%
2N/A% int acqexcl(void) {
2N/A% return (WLOCK(free_list));
2N/A% }
2N/A%
2N/A% int relexcl(void) {
2N/A% return (WULOCK(free_list));
2N/A% }
2N/A%
2N/A% int acqnonexcl(void) {
2N/A% return (RLOCK(free_list));
2N/A% }
2N/A%
2N/A% int relnonexcl(void) {
2N/A% return (RULOCK(free_list));
2N/A% }
2N/A%};
2N/A#endif /* RPC_HDR */
2N/A#endif /* USINGC */
2N/A
2N/A#if RPC_HDR || RPC_XDR
2N/A#ifdef USINGC
2N/Astruct db_table
2N/A{
2N/A entry_object_p tab <>;
2N/A long last_used; /* last entry used; maintained for quick insertion */
2N/A long count; /* measures fullness of table */
2N/A db_free_list freelist;
2N/A __nisdb_rwlock_t table_rwlock;
2N/A __nisdb_flag_t enumMode;
2N/A __nisdb_ptr_t enumArray;
2N/A __nis_table_mapping_t mapping;
2N/A};
2N/Atypedef struct db_table * db_table_p;
2N/A
2N/A#endif /* USINGC */
2N/A#endif /* RPC_HDR */
2N/A
2N/A#ifndef USINGC
2N/A#ifdef RPC_HDR
2N/A%class db_table
2N/A%{
2N/A% long table_size;
2N/A% entry_object_p *tab; /* pointer to array of pointers to entry objects */
2N/A% long last_used; /* last entry used; maintained for quick insertion */
2N/A% long count; /* measures fullness of table */
2N/A% db_free_list freelist;
2N/A% STRUCTRWLOCK(table);
2N/A% __nisdb_flag_t enumMode;
2N/A% __nisdb_flag_t enumCount;
2N/A% __nisdb_ptr_t enumIndex;
2N/A% __nisdb_ptr_t enumArray;
2N/A%
2N/A% void grow(); /* Expand the table.
2N/A% Fatal error if insufficient error. */
2N/A%
2N/A%/* Allocate expiration time array */
2N/A% db_status allocateExpire(long oldSize, long newSize);
2N/A%
2N/A% public:
2N/A% __nisdb_table_mapping_t mapping;
2N/A%
2N/A% db_table(); /* constructor for brand new, empty table. */
2N/A% db_table( char * ); /* constructor for creating a table by loading
2N/A% in an existing one. */
2N/A%
2N/A%/* Init of LDAP/MT portion of class instance */
2N/A% void db_table_ldap_init(void);
2N/A%/* Size of the non-MT/LDAP portion of the db_table structure */
2N/A% ulong_t oldstructsize(void) {
2N/A% return ((ulong_t)&(this->table_rwlock) - (ulong_t)this);
2N/A% }
2N/A%/* Mark this instance as deferred */
2N/A% void markDeferred(void) {
2N/A% mapping.isDeferredTable = TRUE;
2N/A% }
2N/A%/* Remove deferred mark */
2N/A% void unmarkDeferred(void) {
2N/A% mapping.isDeferredTable = FALSE;
2N/A% }
2N/A%
2N/A%/* Return the current 'tab' */
2N/A% entry_object_p *gettab() { ASSERTRHELD(table); return (tab); };
2N/A%/* Return how many entries there are in table. */
2N/A% long fullness() { return count; }
2N/A%
2N/A%/* Deletes table, entries, and free list */
2N/A% ~db_table();
2N/A%
2N/A% int tryacqexcl(void) {
2N/A% return (TRYWLOCK(table));
2N/A% }
2N/A%
2N/A% int acqexcl(void) {
2N/A% return (WLOCK(table));
2N/A% }
2N/A%
2N/A% int relexcl(void) {
2N/A% return (WULOCK(table));
2N/A% }
2N/A%
2N/A% int acqnonexcl(void) {
2N/A% return (RLOCK(table));
2N/A% }
2N/A%
2N/A% int relnonexcl(void) {
2N/A% return (RULOCK(table));
2N/A% }
2N/A%
2N/A%/* empties table by deleting all entries and other associated data structures */
2N/A% void reset();
2N/A%
2N/A% int dump( char *);
2N/A%
2N/A%/* Returns whether location is valid. */
2N/A% bool_t entry_exists_p( entryp i );
2N/A%
2N/A%/* Returns table size. */
2N/A% long getsize() { return table_size; }
2N/A%
2N/A%/* Returns the first entry in table, also return its position in
2N/A% 'where'. Return NULL in both if no next entry is found. */
2N/A% entry_object_p first_entry( entryp * where );
2N/A%
2N/A%/* Returns the next entry in table from 'prev', also return its position in
2N/A% 'newentry'. Return NULL in both if no next entry is found. */
2N/A% entry_object_p next_entry( entryp, entryp* );
2N/A%
2N/A%/* Returns entry at location 'where', NULL if location is invalid. */
2N/A% entry_object_p get_entry( entryp );
2N/A%
2N/A%/* Adds given entry to table in first available slot (either look in freelist
2N/A% or add to end of table) and return the the position of where the record
2N/A% is placed. 'count' is incremented if entry is added. Table may grow
2N/A% as a side-effect of the addition. Copy is made of the input. */
2N/A% entryp add_entry(entry_object_p, int);
2N/A%
2N/A% /* Replaces object at specified location by given entry.
2N/A% Returns TRUE if replacement successful; FALSE otherwise.
2N/A% There must something already at the specified location, otherwise,
2N/A% replacement fails. Copy is not made of the input.
2N/A% The pre-existing entry is freed.*/
2N/A% bool_t replace_entry( entryp, entry_object_p );
2N/A%
2N/A%/* Deletes entry at specified location. Returns TRUE if location is valid;
2N/A% FALSE if location is invalid, or the freed location cannot be added to
2N/A% the freelist. 'count' is decremented if the deletion occurs. The object
2N/A% at that location is freed. */
2N/A% bool_t delete_entry( entryp );
2N/A%
2N/A%/* Returns statistics of table.
2N/A% <table_size><last_used><count>[freelist].
2N/A% It is up to the caller to free the returned vector when his is through
2N/A% The free list is included if 'fl' is TRUE. */
2N/A%long * stats( bool_t fl );
2N/A%
2N/A%/* Configure LDAP mapping */
2N/A% bool_t configure(char *objName);
2N/A%
2N/A%/* Initialize the mapping structure with default values */
2N/A% void initMappingStruct(__nisdb_table_mapping_t *mapping);
2N/A%
2N/A%/* Check if entry at 'loc' is valid (not expired) */
2N/A% bool_t cacheValid(entryp loc);
2N/A%
2N/A%/* Update expiration time if supplied object same as the one at 'loc' */
2N/A% bool_t dupEntry(entry_object *obj, entryp loc);
2N/A%
2N/A%/* Set expiration time for entry */
2N/A% void setEntryExp(entryp where, entry_object *obj, int initialLoad);
2N/A%
2N/A%/* Enable enum mode */
2N/A% void setEnumMode(long count);
2N/A%/* Clear enum mode */
2N/A% void clearEnumMode(void);
2N/A%/* End enum mode, return array of untouched entries */
2N/A% entry_object **endEnumMode(long *numEa);
2N/A%/* Mark the indicated entry used for enum purposes */
2N/A% void enumTouch(entryp loc);
2N/A%/* Add entry to enumIndex array */
2N/A% void enumSetup(entryp loc, long index);
2N/A%/* Touch the indicated entry */
2N/A% void touchEntry(entryp loc);
2N/A%
2N/A% db_status allocateEnumArray(long oldSize, long newSize);
2N/A%};
2N/A%#ifdef __cplusplus
2N/A%extern "C" bool_t xdr_db_table( XDR*, db_table*);
2N/A%#elif __STDC__
2N/A%extern bool_t xdr_db_table(XDR*, db_table*);
2N/A%#endif
2N/A%typedef class db_table * db_table_p;
2N/A#endif /* RPC_HDR */
2N/A#endif /* USINGC */
2N/A
2N/A#if RPC_HDR
2N/A%#endif /* _DB_TABLE_H */
2N/A#endif /* RPC_HDR */