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_dictionary_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_DICTIONARY_H
2N/A%#define _DB_DICTIONARY_H
2N/A
2N/A#ifdef USINGC
2N/A%#include "nisdb_rw.h"
2N/A%#include "nisdb_ldap.h"
2N/A%#include "db_entry_c.h"
2N/A%#include "db_scheme_c.h"
2N/A%#include "db_vers_c.h"
2N/A%#include "ldap_xdr.h"
2N/A%typedef void *nullptr;
2N/A%typedef u_int db_dict_version;
2N/A#else
2N/A%#include "nisdb_rw.h"
2N/A%#include "nisdb_ldap.h"
2N/A%#include "db_entry.h"
2N/A%#include "db_scheme.h"
2N/A%#include "db.h"
2N/A%#include "db_vers.h"
2N/A%#include "db_dictlog.h"
2N/A%#include "ldap_xdr.h"
2N/A#endif /* USINGC */
2N/A#endif /* RPC_HDR */
2N/A
2N/Astruct db_table_desc {
2N/A string table_name<NIS_MAXNAMELEN>;
2N/A u_long hashval;
2N/A db_scheme * scheme;
2N/A#ifdef USINGC
2N/A nullptr database; /* for XDR, keep database from descriptor */
2N/A#else
2N/A db *database; /* for program use in c++ code */
2N/A#endif /* USINGC */
2N/A db_table_desc *next;
2N/A};
2N/Atypedef struct db_table_desc * db_table_desc_p;
2N/A
2N/A/* Defining own version of xdr_db_dict_version */
2N/A#if RPC_HDR
2N/A#ifndef USINGC
2N/Atypedef u_int db_dict_version;
2N/A%bool_t xdr_db_dict_version();
2N/A#endif /* USINGC */
2N/A
2N/Atypedef char * db_table_namep;
2N/Atypedef db_table_namep db_table_names<>;
2N/A
2N/A/* Defining own version of xdr_db_dict_desc */
2N/A#ifndef USINGC
2N/Astruct db_dict_desc {
2N/A db_dict_version impl_vers;
2N/A db_table_desc_p tables<>;
2N/A int count;
2N/A};
2N/A#else
2N/A%struct db_dict_desc {
2N/A% db_dict_version impl_vers;
2N/A% struct {
2N/A% u_int tables_len;
2N/A% db_table_desc_p *tables_val;
2N/A% } tables;
2N/A% int count;
2N/A%};
2N/A%typedef struct db_dict_desc db_dict_desc;
2N/A%bool_t xdr_db_dict_desc();
2N/A#endif /* USINGC */
2N/A
2N/A#endif
2N/A
2N/Atypedef struct db_dict_desc * db_dict_desc_p;
2N/A
2N/A#if RPC_HDR
2N/Astruct __nisdb_dictionary_defer_struct {
2N/A db_dict_desc *dictionary; /* Old incarnation */
2N/A};
2N/Atypedef struct __nisdb_dictionary_defer_struct __nisdb_dictionary_defer_t;
2N/A#ifdef USINGC
2N/A%bool_t xdr___nisdb_dictionary_defer_t();
2N/A#endif /* USINGC */
2N/A#endif
2N/A
2N/A#ifndef USINGC
2N/A#ifdef RPC_HDR
2N/A%class db_dictionary {
2N/A% db_dict_desc_p dictionary;
2N/A% bool_t initialized;
2N/A% char* filename;
2N/A% char* tmpfilename;
2N/A% char* logfilename;
2N/A% db_dictlog *logfile;
2N/A% bool_t logfile_opened;
2N/A% bool_t changed;
2N/A% __nisdb_dictionary_defer_t deferred;
2N/A% __nisdb_flag_t noWriteThrough;
2N/A% STRUCTRWLOCK(dict);
2N/A%
2N/A%/* Dump contents of this dictionary (minus the database representation)
2N/A% to its file. Returns 0 if operation succeeds, -1 otherwise. */
2N/A% int dump();
2N/A%
2N/A%/* Delete old log file and descriptor */
2N/A% int reset_log();
2N/A%
2N/A%/* Open log file (and creates descriptor) if it has not been opened */
2N/A% int open_log();
2N/A%
2N/A%/* Incorporate updates in log to dictionary already loaded.
2N/A% Does not affect "logfile" */
2N/A% int incorporate_log( char * );
2N/A%
2N/A% /* closes log file if opened */
2N/A% int close_log();
2N/A%
2N/A%/* Log the given action and execute it.
2N/A% The minor version of the dictionary is updated after the action has
2N/A% been executed and the dictionary is flagged as being changed.
2N/A% Return the structure db_result, or NULL if the loggin failed or the
2N/A% action is unknown. */
2N/A% db_status log_action(int, char* table, table_obj* tobj =0);
2N/A%
2N/A% db_status create_table_desc(char* table_name, table_obj* table_desc,
2N/A% db_table_desc**);
2N/A%
2N/A% db_dict_desc_p db_copy_dictionary(void);
2N/A%
2N/A% public:
2N/A%/* Constructor: creates an empty, uninitialized dictionary. */
2N/A% db_dictionary();
2N/A%
2N/A%/* Destructor: noop. Use db_shutdown if you really want to clean up. */
2N/A% ~db_dictionary() {}
2N/A%
2N/A% db_status merge_dict (db_dictionary&, char *, char *);
2N/A%
2N/A% db_status massage_dict (char *, char *, char *);
2N/A% int db_clone_bucket (db_table_desc *, db_table_desc_p *);
2N/A% int change_table_name (db_table_desc *, char *, char *);
2N/A% bool_t extract_entries (db_dictionary&, char **, int );
2N/A%
2N/A%/* Real destructor: deletes filename and table descriptors */
2N/A% db_status db_shutdown();
2N/A%
2N/A%/* Initialize dictionary from contents in 'file'.
2N/A% If there is already information in this dictionary, it is removed.
2N/A% Therefore, regardless of whether the load from the file succeeds,
2N/A% the contents of this dictionary will be altered. Returns
2N/A% whether table has been initialized successfully. */
2N/A% bool_t init( char* fname );
2N/A% bool_t inittemp( char* fname, db_dictionary&);
2N/A%
2N/A%/* closes any open log files for all tables in dictionary or 'tab'.
2N/A% "tab" is an optional argument.
2N/A% */
2N/A% db_status db_standby( char* tab = 0 );
2N/A%
2N/A%/* Write out in-memory copy of dictionary to file.
2N/A% 1. Update major version.
2N/A% 2. Dump contents to temporary file.
2N/A% 3. Rename temporary file to real dictionary file.
2N/A% 4. Remove log file.
2N/A% A checkpoint is done only if it has changed since the previous checkpoint.
2N/A% Returns TRUE if checkpoint was successful; FALSE otherwise. */
2N/A% db_status checkpoint();
2N/A%
2N/A%/* Checkpoints table specified by 'tab', or all tables if 'tab' is 0. */
2N/A% db_status db_checkpoint( char* tab = 0 );
2N/A
2N/A%/* Add table with given name 'tab' and description 'zdesc' to dictionary.
2N/A% Returns error code if table already exists, or if no memory can be found
2N/A% to store the descriptor, or if dictionary has not been intialized.
2N/A% Dictionary is updated to stable store before addition.
2N/A% Fatal error occurs if dictionary cannot be saved.
2N/A% Returns DB_SUCCESS if dictionary has been updated successfully. */
2N/A% db_status add_table_aux(char* table_name, table_obj* table_desc, int mode);
2N/A%
2N/A%/* Delete table with given name 'tab' from dictionary.
2N/A% Returns error code if table does not exist or if dictionary has not been
2N/A% initialized. Dictionary is updated to stable store if deletion is
2N/A% successful. Fatal error occurs if dictionary cannot be saved.
2N/A% Returns DB_SUCCESS if dictionary has been updated successfully.
2N/A% Note that the files associated with the table are also removed. */
2N/A% db_status delete_table_aux( char* table_name, int mode );
2N/A%
2N/A% db_status add_table( char* table_name, table_obj* table_desc );
2N/A% int copyfile( char* infile, char *outfile);
2N/A%
2N/A% db_status delete_table( char* table_name );
2N/A%
2N/A%/* Return database structure of table named by 'table_name'.
2N/A% If 'where' is set, set it to the table_desc of 'table_name.'
2N/A% The database is loaded in from stable store if it has not been loaded.
2N/A% If it cannot be loaded, it is initialized using the scheme stored in
2N/A% the table_desc. NULL is returned if the initialization fails. */
2N/A% db* find_table( char* table_name, db_table_desc ** where = NULL );
2N/A%
2N/A% db *find_table(char *table_name, db_table_desc **where,
2N/A% bool_t searchDeferred);
2N/A% db *find_table(char *table_name, db_table_desc **where,
2N/A% bool_t searchDeferred, bool_t doLDAP,
2N/A% bool_t doLoad);
2N/A%
2N/A% db *find_table_noLDAP(char *table_name, db_table_desc **where,
2N/A% bool_t searchDeferred, bool_t doLoad);
2N/A%
2N/A%/* Returns db_table_desc of table name 'tab'.
2N/A% Use this if you do not want table to be loaded. */
2N/A% db_table_desc * find_table_desc( char* table_name );
2N/A%
2N/A% db_table_desc * find_table_desc(char *table_name, bool_t searchDeferred);
2N/A%
2N/A%/* Translate given nis attribute list to a db_query structure.
2N/A% Return FALSE if dictionary has not been initialized, or
2N/A% table does not have a scheme (which should be a fatal error?). */
2N/A% db_query * translate_to_query( db_table_desc*, int, nis_attr * );
2N/A%
2N/A%/* Return an array of strings of table names of all tables in dictionary. */
2N/A% db_table_names * get_table_names();
2N/A%
2N/A%/* Set/clear no-write-through flag */
2N/A% void setNoWriteThrough(void);
2N/A% void clearNoWriteThrough(void);
2N/A%
2N/A%/* Locking */
2N/A% int acqexcl(void) {
2N/A% return(WLOCK(dict));
2N/A% }
2N/A%
2N/A% int relexcl(void) {
2N/A% return (WULOCK(dict));
2N/A% }
2N/A%
2N/A% int acqnonexcl(void) {
2N/A% return (RLOCK(dict));
2N/A% }
2N/A%
2N/A% int relnonexcl(void) {
2N/A% return (RULOCK(dict));
2N/A% }
2N/A%
2N/A%/* Set deferred commit mode; intended for replica resync */
2N/A% db_status defer(char *table);
2N/A%
2N/A%/* Commit deferred changes; intended for replica resync */
2N/A% db_status commit(char *table);
2N/A%
2N/A%/* Roll back deferred changes; intended for replica resync */
2N/A% db_status rollback(char *table);
2N/A%};
2N/A%#ifdef __STDC__
2N/A%extern "C" bool_t xdr_db_table_desc_p(XDR *, db_table_desc_p *);
2N/A%extern "C" bool_t xdr_db_table_desc(XDR *, db_table_desc *);
2N/A%extern "C" bool_t xdr_db_dict_desc_p(XDR *, db_dict_desc_p *);
2N/A%extern "C" bool_t xdr_db_table_namep(XDR *, db_table_namep *);
2N/A%extern "C" bool_t xdr_db_table_names(XDR *, db_table_names *);
2N/A%#endif
2N/A
2N/A#endif /* RPC_HDR */
2N/A#endif /* USINGC */
2N/A
2N/A#if RPC_HDR
2N/A%#endif /* _DB_DICTIONARY_H */
2N/A#endif /* RPC_HDR */
2N/A