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 (the "License").
2N/A * You may not use this file except in compliance 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_mindex_c.x
2N/A *
2N/A * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A#if RPC_HDR
2N/A%#ifndef _DB_MINDEX_H
2N/A%#define _DB_MINDEX_H
2N/A
2N/A#ifdef USINGC
2N/A%#include "db_vers_c.h"
2N/A%#include "db_table_c.h"
2N/A%#include "db_index_entry_c.h"
2N/A%#include "db_index_c.h"
2N/A%#include "db_scheme_c.h"
2N/A%#include "db_query_c.h"
2N/A#else
2N/A%#include "db_vers.h"
2N/A%#include "db_table.h"
2N/A%#include "db_index_entry.h"
2N/A%#include "db_index.h"
2N/A%#include "db_scheme.h"
2N/A%#include "db_query.h"
2N/A#endif /* USINGC */
2N/A%#include "ldap_parse.h"
2N/A%#include "nisdb_rw.h"
2N/A%#include "ldap_xdr.h"
2N/A#endif /* RPC_HDR */
2N/A
2N/A#if RPC_HDR
2N/A%struct db_next_index_desc {
2N/A% entryp location;
2N/A% struct db_next_index_desc *next;
2N/A
2N/A#ifndef USINGC
2N/A% db_next_index_desc( entryp loc, struct db_next_index_desc *n )
2N/A% { location = loc; next = n; }
2N/A#endif /* USINGC */
2N/A
2N/A%};
2N/A#endif /* RPC_HDR */
2N/A
2N/A
2N/A#if RPC_HDR || RPC_XDR
2N/A#ifdef USINGC
2N/A
2N/Astruct db_mindex {
2N/A vers rversion;
2N/A db_index indices<>; /* indices[num_indices] */
2N/A db_table *table;
2N/A db_scheme *scheme;
2N/A __nisdb_ptr_t objPath;
2N/A __nisdb_flag_t noWriteThrough;
2N/A __nisdb_flag_t noLDAPquery;
2N/A __nisdb_flag_t initialLoad;
2N/A __nisdb_ptr_t dbptr;
2N/A __nisdb_rwlock_t mindex_rwlock;
2N/A};
2N/Atypedef struct db_mindex * db_mindex_p;
2N/A
2N/Atypedef string strP<>;
2N/A
2N/Astruct xdr_nis_object_s {
2N/A int xversion;
2N/A nis_object *obj;
2N/A strP dirEntry<>;
2N/A};
2N/Atypedef struct xdr_nis_object_s xdr_nis_object_t;
2N/A
2N/A%extern bool_t xdr_nis_object();
2N/A#endif /* USINGC */
2N/A#endif /* RPC_HDR */
2N/A
2N/A#ifndef USINGC
2N/A#ifdef RPC_HDR
2N/A%
2N/A%struct xdr_nis_object_s {
2N/A% int version;
2N/A% nis_object *obj;
2N/A% struct {
2N/A% uint_t dirEntry_len;
2N/A% char **dirEntry_val;
2N/A% } dirEntry;
2N/A%};
2N/A%typedef struct xdr_nis_object_s xdr_nis_object_t;
2N/A%
2N/A%extern bool_t xdr_nis_object();
2N/A%
2N/A%class db_mindex {
2N/A% vers rversion;
2N/A%// int num_indices;
2N/A%// db_index * indices; /* indices[num_indices] */
2N/A% struct {
2N/A% int indices_len;
2N/A% db_index *indices_val;
2N/A% } indices;
2N/A% db_table *table;
2N/A% db_scheme *scheme;
2N/A% __nisdb_ptr_t objPath;
2N/A% __nisdb_flag_t noWriteThrough;
2N/A% __nisdb_flag_t noLDAPquery;
2N/A% __nisdb_flag_t initialLoad;
2N/A% __nisdb_ptr_t dbptr;
2N/A% STRUCTRWLOCK(mindex);
2N/A%
2N/A%/* Return a list of index_entries that satsify the given query 'q'.
2N/A% Return the size of the list in 'count'. Return NULL if list is empty.
2N/A% Return in 'valid' FALSE if query is not well formed. */
2N/A% db_index_entry_p satisfy_query(db_query *, long *, bool_t *valid,
2N/A% bool_t fromLDAP = FALSE);
2N/A% db_index_entry_p satisfy_query(db_query *, long *, bool_t *valid = NULL);
2N/A%
2N/A%/* Returns a newly db_query containing the index values as
2N/A% obtained from the given object. The object itself,
2N/A% along with information on the scheme given, will determine
2N/A% which values are extracted from the object and placed into the query.
2N/A% Returns an empty query if 'obj' is not a valid entry.
2N/A% Note that space is allocated for the query and the index values
2N/A% (i.e. do not share pointers with strings in 'obj'.) */
2N/A% db_query * extract_index_values_from_object( entry_object * );
2N/A%
2N/A%/* Returns a newly created db_query structure containing the index values
2N/A% as obtained from the record named by 'recnum'. The record itself, along
2N/A% with information on the schema definition of this table, will determine
2N/A% which values are extracted from the record and placed into the result.
2N/A% Returns NULL if recnum is not a valid entry.
2N/A% Note that space is allocated for the query and the index values
2N/A% (i.e. do not share pointers with strings in 'obj'.) */
2N/A% db_query * extract_index_values_from_record( entryp );
2N/A%
2N/A%/* Returns an array of size 'count' of 'entry_object_p's, pointing to
2N/A% copies of entry_objects named by the result list of db_index_entries 'res'.
2N/A%*/
2N/A% entry_object_p * prepare_results( int, db_index_entry_p, db_status* );
2N/A%
2N/A%/* Remove the entry identified by 'recloc' from:
2N/A% 1. all indices, as obtained by extracting the index values from the entry
2N/A% 2. table where entry is stored. */
2N/A% db_status remove_aux( entryp );
2N/A%
2N/A%/* entry_object * get_record( entryp );*/
2N/A% public:
2N/A%
2N/A%/* Constructor: Create empty table (no scheme, no table or indices). */
2N/A% db_mindex();
2N/A%
2N/A%/* Constructor: Create new table using scheme defintion supplied.
2N/A% (Make copy of scheme and keep it with table.) */
2N/A% db_mindex(db_scheme *, char *tablePath);
2N/A%
2N/A%/* destructor */
2N/A% ~db_mindex();
2N/A%
2N/A% db_index_entry_p satisfy_query_dbonly(db_query *, long *,
2N/A% bool_t checkExpire,
2N/A% bool_t *valid = NULL);
2N/A%
2N/A%/* Returns whether there table is valid (i.e. has scheme). */
2N/A% bool_t good() { return scheme != NULL && table != NULL; }
2N/A%
2N/A%/* Change the version of the table to the one given. */
2N/A% void change_version( vers *v ) { rversion.assign( v );}
2N/A%
2N/A%/* Return the current version of the table. */
2N/A% vers *get_version() { return( &rversion ); }
2N/A%
2N/A%/* Reset contents of tables by: deleting indice entries, table entries */
2N/A% void reset_tables();
2N/A%
2N/A%/* Reset the table by: deleting all the indices, table of entries, and its
2N/A% scheme. Reset version to 0 */
2N/A% void reset();
2N/A%
2N/A%/* Initialize table using information from specified file.
2N/A% The table is first 'reset', then the attempt to load from the file
2N/A% is made. If the load failed, the table is again reset.
2N/A% Therefore, the table will be modified regardless of the success of the
2N/A% load. Returns TRUE if successful, FALSE otherwise. */
2N/A% int load( char * );
2N/A%
2N/A%/* Initialize table using information given in scheme 'how'.
2N/A% Record the scheme for later use (make copy of it);
2N/A% create the required number of indices; and create table for storing
2N/A% entries.
2N/A% The 'tablePath' is passed on to db_table in order to obtain the
2N/A% NIS+/LDAP mapping information (if any). */
2N/A% void init( db_scheme *);
2N/A%
2N/A%/* Write this structure (table, indices, scheme) into the specified file. */
2N/A% int dump( char *);
2N/A%
2N/A%/* Removes the entry in the table named by given query 'q'.
2N/A% If a NULL query is supplied, all entries in table are removed.
2N/A% Returns DB_NOTFOUND if no entry is found.
2N/A% Returns DB_SUCCESS if one entry is found; this entry is removed from
2N/A% its record storage, and it is also removed from all the indices of the
2N/A% table. If more than one entry satisfying 'q' is found, all are removed. */
2N/A% db_status remove( db_query *);
2N/A%
2N/A%/* Add copy of given entry to table. Entry is identified by query 'q'.
2N/A% The entry (if any) satisfying the query is first deleted, then
2N/A% added to the indices (using index values extracted form the given entry)
2N/A% and the table.
2N/A% Returns DB_NOTUNIQUE if more than one entry satisfies the query.
2N/A% Returns DB_NOTFOUND if query is not well-formed.
2N/A% Returns DB_SUCCESS if entry can be added. */
2N/A% db_status add( db_query *, entry_object* );
2N/A%
2N/A%
2N/A%/* Finds entry that satisfy the query 'q'. Returns the answer by
2N/A% setting the pointer 'rp' to point to the list of answers.
2N/A% Note that the answers are pointers to copies of the entries.
2N/A% Returns the number of answers find in 'count'.
2N/A% Returns DB_SUCCESS if search found at least one answer;
2N/A% returns DB_NOTFOUND if none is found. */
2N/A% db_status lookup( db_query *, long *, entry_object_p ** );
2N/A%
2N/A%/* Returns the next entry in the table after 'previous' by setting 'answer' to
2N/A% point to a copy of the entry_object. Returns DB_SUCCESS if 'previous'
2N/A% is valid and next entry is found; DB_NOTFOUND otherwise. Sets 'where'
2N/A% to location of where entry is found for input as subsequent 'next'
2N/A% operation. */
2N/A% db_status next( entryp, entryp *, entry_object ** );
2N/A%
2N/A%/* Returns the next entry in the table after 'previous' by setting 'answer' to
2N/A% point to a copy of the entry_object. Returns DB_SUCCESS if 'previous'
2N/A% is valid and next entry is found; DB_NOTFOUND otherwise. Sets 'where'
2N/A% to location of where entry is found for input as subsequent 'next'
2N/A% operation. */
2N/A% db_status next( db_next_index_desc*, db_next_index_desc **, entry_object ** );
2N/A%
2N/A%/* Returns the first entry found in the table by setting 'answer' to
2N/A% a copy of the entry_object. Returns DB_SUCCESS if found;
2N/A% DB_NOTFOUND otherwise. */
2N/A% db_status first( entryp*, entry_object ** );
2N/A%
2N/A%/* Returns the first entry that satisfies query by setting 'answer' to
2N/A% a copy of the entry_object. Returns DB_SUCCESS if found;
2N/A% DB_NOTFOUND otherwise. */
2N/A% db_status first( db_query *, db_next_index_desc **, entry_object ** );
2N/A%
2N/A% /* Delete the given list of results; used when no longer interested in
2N/A% the results of the first/next query that returned this list. */
2N/A% db_status reset_next( db_next_index_desc *orig );
2N/A%
2N/A%/* Return all entries within table. Returns the answer by
2N/A% setting the pointer 'rp' to point to the list of answers.
2N/A% Note that the answers are pointers to copies of the entries.
2N/A% Returns the number of answers find in 'count'.
2N/A% Returns DB_SUCCESS if search found at least one answer;
2N/A% returns DB_NOTFOUND if none is found. */
2N/A% db_status all( long *, entry_object_p ** );
2N/A%
2N/A% /* for debugging */
2N/A%/* Prints statistics of the table. This includes the size of the table,
2N/A% the number of entries, and the index sizes. */
2N/A% void print_stats();
2N/A%
2N/A%/* Prints statistics about all indices of table. */
2N/A% void print_all_indices();
2N/A%
2N/A%
2N/A%/* Prints statistics about indices identified by 'n'. */
2N/A% void print_index( int n );
2N/A%
2N/A%/* Configure LDAP mapping */
2N/A% bool_t configure (char *objName);
2N/A%
2N/A%/* Mark this instance deferred */
2N/A% void markDeferred(void) {
2N/A% if (table != NULL) table->markDeferred();
2N/A% }
2N/A%/* Remove deferred mark */
2N/A% void unmarkDeferred(void) {
2N/A% if (table != NULL) table->unmarkDeferred();
2N/A% }
2N/A%
2N/A%/* Retrieve, remove, or store data from/in/to LDAP */
2N/A% int queryLDAP(db_query *, char *, int);
2N/A% int entriesFromLDAP(__nis_table_mapping_t *, db_query *, db_query *,
2N/A% char *, nis_object *, int);
2N/A%
2N/A% int removeLDAP(db_query *, nis_object *o);
2N/A%
2N/A% int storeObjLDAP(__nis_table_mapping_t *t, nis_object *o);
2N/A% int storeLDAP(db_query *, entry_obj *, nis_object *, entry_obj *,
2N/A% char *dbId);
2N/A%
2N/A%/* Set/clear no-write-through flag */
2N/A% void setNoWriteThrough(void);
2N/A% void clearNoWriteThrough(void);
2N/A%
2N/A%/* Set/clear no-LDAP-query flag */
2N/A% void setNoLDAPquery(void);
2N/A% void clearNoLDAPquery(void);
2N/A%
2N/A%/* Set/clear initialLoad flag */
2N/A% void setInitialLoad(void);
2N/A% void clearInitialLoad(void);
2N/A%
2N/A%/* Store/retrieve pointer to parent 'db' class instance */
2N/A% void setDbPtr(void *ptr);
2N/A% void *getDbPtr(void);
2N/A%
2N/A%/* Get pointer to private 'table' field */
2N/A% db_table *getTable(void);
2N/A%
2N/A%/*
2N/A% * Update table entry per the (entry_object *). If 'replace' is set,
2N/A% * the entry is replaced or added; otherwise, it is removed.
2N/A% */
2N/A% int updateTableEntry(entry_object *e, int replace, char *tableName,
2N/A% nis_object *obj, nis_object *tobj, uint32_t ttime,
2N/A% int *xid);
2N/A%
2N/A%/* Touch the indicated entry */
2N/A% bool_t touchEntry(entry_object *e);
2N/A% bool_t touchEntry(db_query *q);
2N/A%
2N/A%/* Return the 'scheme' pointer */
2N/A% db_scheme *getScheme(void) {return (scheme);}
2N/A%
2N/A%/* RW lock functions */
2N/A%
2N/A% int tryacqexcl(void) {
2N/A% return (TRYWLOCK(mindex));
2N/A% }
2N/A%
2N/A% int acqexcl(void) {
2N/A% return (WLOCK(mindex));
2N/A% }
2N/A%
2N/A% int relexcl(void) {
2N/A% return (WULOCK(mindex));
2N/A% }
2N/A%
2N/A% int acqnonexcl(void) {
2N/A% return (RLOCK(mindex));
2N/A% }
2N/A%
2N/A% int relnonexcl(void) {
2N/A% return (RULOCK(mindex));
2N/A% }
2N/A%};
2N/A%#ifdef __cplusplus
2N/A%extern "C" bool_t xdr_db_mindex(XDR*, db_mindex*);
2N/A%#elif __STDC__
2N/A%extern bool_t xdr_db_mindex(XDR*, db_mindex*);
2N/A%#endif
2N/A%typedef class db_mindex * db_mindex_p;
2N/A#endif /* RPC_HDR */
2N/A#endif /* USINGC */
2N/A
2N/A#if RPC_HDR
2N/A%#endif /* _DB_MINDEX_H */
2N/A#endif /* RPC_HDR */