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