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_dictlog_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_DICTLOG_H 337c478bd9Sstevel@tonic-gate %#define _DB_DICTLOG_H 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate % 367c478bd9Sstevel@tonic-gate %/* A log entry that describes an action to be performed and its parameters. */ 377c478bd9Sstevel@tonic-gate % 38*a506a34cSth160488 #endif /* RPC_HDR */ 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate #if RPC_HDR || RPC_XDR 417c478bd9Sstevel@tonic-gate #ifdef USINGC 427c478bd9Sstevel@tonic-gate %#include "db_vers_c.h" 437c478bd9Sstevel@tonic-gate #else 447c478bd9Sstevel@tonic-gate %#include "db_vers.h" 457c478bd9Sstevel@tonic-gate %#include "db_pickle.h" 46*a506a34cSth160488 #endif /* USINGC */ 477c478bd9Sstevel@tonic-gate %#include <rpcsvc/nis.h> 48*a506a34cSth160488 #endif /* RPC_HDR */ 497c478bd9Sstevel@tonic-gate % 507c478bd9Sstevel@tonic-gate %#include "nisdb_rw.h" 517c478bd9Sstevel@tonic-gate % 527c478bd9Sstevel@tonic-gate %#define DB_ADD_TABLE 1 537c478bd9Sstevel@tonic-gate %#define DB_REMOVE_TABLE 2 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate #if RPC_HDR || RPC_XDR 567c478bd9Sstevel@tonic-gate #ifdef USINGC 577c478bd9Sstevel@tonic-gate struct db_dictlog_entry { 587c478bd9Sstevel@tonic-gate vers aversion; /* version of log entry */ 597c478bd9Sstevel@tonic-gate int action; /* action to be invoked */ 607c478bd9Sstevel@tonic-gate string table_name<>; /* table_name supplied with action */ 617c478bd9Sstevel@tonic-gate table_obj *table_object; /* object involved in action (if any) */ 627c478bd9Sstevel@tonic-gate struct db_dictlog_entry *next; /* Used in constructing list */ 637c478bd9Sstevel@tonic-gate vers bversion; /* sanity check;should be same as aversion*/ 647c478bd9Sstevel@tonic-gate }; 657c478bd9Sstevel@tonic-gate typedef struct db_dictlog_entry* db_dictlog_entry_p; 66*a506a34cSth160488 #endif /* USINGC */ 67*a506a34cSth160488 #endif /* RPC_HDR */ 687c478bd9Sstevel@tonic-gate 697c478bd9Sstevel@tonic-gate #ifdef USINGC 707c478bd9Sstevel@tonic-gate #if RPC_HDR 717c478bd9Sstevel@tonic-gate %bool_t xdr_table_obj(); 727c478bd9Sstevel@tonic-gate #endif 73*a506a34cSth160488 #endif /* USINGC */ 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate #ifndef USINGC 767c478bd9Sstevel@tonic-gate #ifdef RPC_HDR 777c478bd9Sstevel@tonic-gate %class db_dictlog_entry { 787c478bd9Sstevel@tonic-gate % vers aversion; /* version of log entry */ 797c478bd9Sstevel@tonic-gate % int action; /* action to be invoked */ 807c478bd9Sstevel@tonic-gate % char *table_name; /* table_name supplied with action (if any) */ 817c478bd9Sstevel@tonic-gate % table_obj *table_object; /* object involved in action (if any) */ 827c478bd9Sstevel@tonic-gate % db_dictlog_entry *next; /* Used in constructing list */ 837c478bd9Sstevel@tonic-gate % vers bversion; /* sanity check */ 847c478bd9Sstevel@tonic-gate % public: 857c478bd9Sstevel@tonic-gate % 867c478bd9Sstevel@tonic-gate %/*Constructor: Create an empty log entry, with no table_name and not object */ 877c478bd9Sstevel@tonic-gate % db_dictlog_entry() { table_name = NULL, table_object = NULL; next = NULL; } 887c478bd9Sstevel@tonic-gate % 897c478bd9Sstevel@tonic-gate %/*Constructor: Create a log entry using the given parameters. Note that 907c478bd9Sstevel@tonic-gate % pointers to table_name and table_object are simply assigned, not copied. */ 917c478bd9Sstevel@tonic-gate % db_dictlog_entry(int, vers *, char*, table_obj*); 927c478bd9Sstevel@tonic-gate % 937c478bd9Sstevel@tonic-gate % ~db_dictlog_entry(); 947c478bd9Sstevel@tonic-gate % 957c478bd9Sstevel@tonic-gate %/* Print this log entry to stdout */ 967c478bd9Sstevel@tonic-gate % void print(); 977c478bd9Sstevel@tonic-gate % 987c478bd9Sstevel@tonic-gate %/* Accessor: return version of log entry */ 997c478bd9Sstevel@tonic-gate % vers *get_version() { return( &aversion ); } 1007c478bd9Sstevel@tonic-gate % 1017c478bd9Sstevel@tonic-gate %/* Accessor: return pointer to action of log entry */ 1027c478bd9Sstevel@tonic-gate % int get_action() { return( action ); } 1037c478bd9Sstevel@tonic-gate % 1047c478bd9Sstevel@tonic-gate %/* Accessor: return pointer to table_name part of log entry */ 1057c478bd9Sstevel@tonic-gate % char* get_table_name() { return( table_name ); } 1067c478bd9Sstevel@tonic-gate % 1077c478bd9Sstevel@tonic-gate %/* Predicate: return whether log entry is complete and not truncated */ 1087c478bd9Sstevel@tonic-gate % bool_t sane() { return( aversion.equal( &bversion ) ); } 1097c478bd9Sstevel@tonic-gate % 1107c478bd9Sstevel@tonic-gate %/* Accessor: return pointer to copy of object in log entry */ 1117c478bd9Sstevel@tonic-gate % table_obj *get_table_object() { return( table_object ); } 1127c478bd9Sstevel@tonic-gate % 1137c478bd9Sstevel@tonic-gate %/* Accessor: return pointer to to next log entry */ 1147c478bd9Sstevel@tonic-gate % db_dictlog_entry * getnextptr() { return( next ); } 1157c478bd9Sstevel@tonic-gate % 1167c478bd9Sstevel@tonic-gate %/* Accessor: return pointer to copy of object in log entry */ 1177c478bd9Sstevel@tonic-gate % void setnextptr( db_dictlog_entry *p ) { next = p; } 1187c478bd9Sstevel@tonic-gate %}; 1197c478bd9Sstevel@tonic-gate %#ifdef __cplusplus 1207c478bd9Sstevel@tonic-gate %extern "C" bool_t xdr_db_dictlog_entry(XDR*, db_dictlog_entry*); 1217c478bd9Sstevel@tonic-gate %#elif __STDC__ 1227c478bd9Sstevel@tonic-gate %extern bool_t xdr_db_dictlog_entry(XDR*, db_dictlog_entry*); 1237c478bd9Sstevel@tonic-gate %#endif 1247c478bd9Sstevel@tonic-gate %typedef class db_dictlog_entry * db_dictlog_entry_p; 125*a506a34cSth160488 #endif /* RPC_HDR */ 126*a506a34cSth160488 #endif /* USINGC */ 1277c478bd9Sstevel@tonic-gate 1287c478bd9Sstevel@tonic-gate struct db_dictlog_list { 1297c478bd9Sstevel@tonic-gate db_dictlog_entry_p list<>; 1307c478bd9Sstevel@tonic-gate }; 1317c478bd9Sstevel@tonic-gate 1327c478bd9Sstevel@tonic-gate #ifndef USINGC 1337c478bd9Sstevel@tonic-gate #ifdef RPC_HDR 1347c478bd9Sstevel@tonic-gate %class db_dictlog: public pickle_file { 1357c478bd9Sstevel@tonic-gate % STRUCTRWLOCK(dictlog); 1367c478bd9Sstevel@tonic-gate % public: 1377c478bd9Sstevel@tonic-gate % 1387c478bd9Sstevel@tonic-gate %/* Constructor: create log file; default is PICKLE_READ mode. */ 1397c478bd9Sstevel@tonic-gate % db_dictlog( char* f, pickle_mode m = PICKLE_READ ): pickle_file(f,m) { 1407c478bd9Sstevel@tonic-gate % INITRW(dictlog); 1417c478bd9Sstevel@tonic-gate % } 1427c478bd9Sstevel@tonic-gate % 1437c478bd9Sstevel@tonic-gate % ~db_dictlog(void) { 1447c478bd9Sstevel@tonic-gate % DESTROYRW(dictlog); 1457c478bd9Sstevel@tonic-gate % } 1467c478bd9Sstevel@tonic-gate % 1477c478bd9Sstevel@tonic-gate %/* Execute given function 'func' on log. 1487c478bd9Sstevel@tonic-gate % function takes as arguments: pointer to log entry, character pointer to 1497c478bd9Sstevel@tonic-gate % another argument, and pointer to an integer, which is used as a counter. 1507c478bd9Sstevel@tonic-gate % 'func' should increment this value for each successful application. 1517c478bd9Sstevel@tonic-gate % The log is traversed until either 'func' returns FALSE, or when the log 1527c478bd9Sstevel@tonic-gate % is exhausted. The second argument to 'execute_on_log' is passed as the 1537c478bd9Sstevel@tonic-gate % second argument to 'func'. The third argument, 'clean' determines whether 1547c478bd9Sstevel@tonic-gate % the log entry is deleted after the function has been applied. 1557c478bd9Sstevel@tonic-gate % Returns the number of times that 'func' incremented its third argument. */ 1567c478bd9Sstevel@tonic-gate % int execute_on_log( bool_t(* func) (db_dictlog_entry *, char *, int *), 1577c478bd9Sstevel@tonic-gate % char *, bool_t = TRUE ); 1587c478bd9Sstevel@tonic-gate % 1597c478bd9Sstevel@tonic-gate %/* Print contents of log file to stdout */ 1607c478bd9Sstevel@tonic-gate % int print(); 1617c478bd9Sstevel@tonic-gate % 1627c478bd9Sstevel@tonic-gate %/*Append given log entry to log. */ 1637c478bd9Sstevel@tonic-gate % int append( db_dictlog_entry * ); 1647c478bd9Sstevel@tonic-gate % 1657c478bd9Sstevel@tonic-gate %/* Return the next element in current log; return NULL if end of log or error. 1667c478bd9Sstevel@tonic-gate % Log must have been opened for READ. */ 1677c478bd9Sstevel@tonic-gate % db_dictlog_entry *get(); 1687c478bd9Sstevel@tonic-gate % 1697c478bd9Sstevel@tonic-gate %/* 1707c478bd9Sstevel@tonic-gate % * Locking methods. Protect the db_dictlog as well as db_dictlog_entries 1717c478bd9Sstevel@tonic-gate % * hanging off of it. 1727c478bd9Sstevel@tonic-gate % */ 1737c478bd9Sstevel@tonic-gate % int acqexcl(void) { 1747c478bd9Sstevel@tonic-gate % return (WLOCK(dictlog)); 1757c478bd9Sstevel@tonic-gate % } 1767c478bd9Sstevel@tonic-gate % 1777c478bd9Sstevel@tonic-gate % int relexcl(void) { 1787c478bd9Sstevel@tonic-gate % return (WULOCK(dictlog)); 1797c478bd9Sstevel@tonic-gate % } 1807c478bd9Sstevel@tonic-gate % 1817c478bd9Sstevel@tonic-gate % int acqnonexcl(void) { 1827c478bd9Sstevel@tonic-gate % return (RLOCK(dictlog)); 1837c478bd9Sstevel@tonic-gate % } 1847c478bd9Sstevel@tonic-gate % 1857c478bd9Sstevel@tonic-gate % int relnonexcl(void) { 1867c478bd9Sstevel@tonic-gate % return (RULOCK(dictlog)); 1877c478bd9Sstevel@tonic-gate % } 1887c478bd9Sstevel@tonic-gate % 1897c478bd9Sstevel@tonic-gate %}; 190*a506a34cSth160488 #endif /* RPC_HDR */ 191*a506a34cSth160488 #endif /* USINGC */ 1927c478bd9Sstevel@tonic-gate 1937c478bd9Sstevel@tonic-gate #if RPC_HDR 194*a506a34cSth160488 %#endif /* _DB_DICTLOG_H */ 195*a506a34cSth160488 #endif /* RPC_HDR */ 196