4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
25 * Copyright 2015 Gary Mills
26 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
27 * Use is subject to license terms.
31 %#include "xdr_nullptr.h"
35 %#ifndef _DB_DICTIONARY_H
36 %#define _DB_DICTIONARY_H
39 %#include "nisdb_rw.h"
40 %#include "nisdb_ldap.h"
41 %#include "db_entry_c.h"
42 %#include "db_scheme_c.h"
43 %#include "db_vers_c.h"
44 %#include "ldap_xdr.h"
45 %typedef void *nullptr;
46 %typedef u_int db_dict_version;
48 %#include "nisdb_rw.h"
49 %#include "nisdb_ldap.h"
50 %#include "db_entry.h"
51 %#include "db_scheme.h"
54 %#include "db_dictlog.h"
55 %#include "ldap_xdr.h"
59 struct db_table_desc {
60 string table_name<NIS_MAXNAMELEN>;
64 nullptr database; /* for XDR, keep database from descriptor */
66 db *database; /* for program use in c++ code */
70 typedef struct db_table_desc * db_table_desc_p;
72 /* Defining own version of xdr_db_dict_version */
75 typedef u_int db_dict_version;
76 %bool_t xdr_db_dict_version();
79 typedef char * db_table_namep;
80 typedef db_table_namep db_table_names<>;
82 /* Defining own version of xdr_db_dict_desc */
85 db_dict_version impl_vers;
86 db_table_desc_p tables<>;
90 %struct db_dict_desc {
91 % db_dict_version impl_vers;
94 % db_table_desc_p *tables_val;
98 %typedef struct db_dict_desc db_dict_desc;
99 %bool_t xdr_db_dict_desc();
104 typedef struct db_dict_desc * db_dict_desc_p;
107 struct __nisdb_dictionary_defer_struct {
108 db_dict_desc *dictionary; /* Old incarnation */
110 typedef struct __nisdb_dictionary_defer_struct __nisdb_dictionary_defer_t;
112 %bool_t xdr___nisdb_dictionary_defer_t();
118 %class db_dictionary {
119 % db_dict_desc_p dictionary;
120 % bool_t initialized;
124 % db_dictlog *logfile;
125 % bool_t logfile_opened;
127 % __nisdb_dictionary_defer_t deferred;
128 % __nisdb_flag_t noWriteThrough;
129 % STRUCTRWLOCK(dict);
131 %/* Dump contents of this dictionary (minus the database representation)
132 % to its file. Returns 0 if operation succeeds, -1 otherwise. */
135 %/* Delete old log file and descriptor */
138 %/* Open log file (and creates descriptor) if it has not been opened */
141 %/* Incorporate updates in log to dictionary already loaded.
142 % Does not affect "logfile" */
143 % int incorporate_log( char * );
145 % /* closes log file if opened */
148 %/* Log the given action and execute it.
149 % The minor version of the dictionary is updated after the action has
150 % been executed and the dictionary is flagged as being changed.
151 % Return the structure db_result, or NULL if the loggin failed or the
152 % action is unknown. */
153 % db_status log_action(int, char* table, table_obj* tobj =0);
155 % db_status create_table_desc(char* table_name, table_obj* table_desc,
158 % db_dict_desc_p db_copy_dictionary(void);
161 %/* Constructor: creates an empty, uninitialized dictionary. */
164 %/* Destructor: noop. Use db_shutdown if you really want to clean up. */
165 % ~db_dictionary() {}
167 % db_status merge_dict (db_dictionary&, char *, char *);
169 % db_status massage_dict (char *, char *, char *);
170 % int db_clone_bucket (db_table_desc *, db_table_desc_p *);
171 % int change_table_name (db_table_desc *, char *, char *);
172 % bool_t extract_entries (db_dictionary&, char **, int );
174 %/* Real destructor: deletes filename and table descriptors */
175 % db_status db_shutdown();
177 %/* Initialize dictionary from contents in 'file'.
178 % If there is already information in this dictionary, it is removed.
179 % Therefore, regardless of whether the load from the file succeeds,
180 % the contents of this dictionary will be altered. Returns
181 % whether table has been initialized successfully. */
182 % bool_t init( char* fname );
183 % bool_t inittemp( char* fname, db_dictionary&);
185 %/* closes any open log files for all tables in dictionary or 'tab'.
186 % "tab" is an optional argument.
188 % db_status db_standby( char* tab = 0 );
190 %/* Write out in-memory copy of dictionary to file.
191 % 1. Update major version.
192 % 2. Dump contents to temporary file.
193 % 3. Rename temporary file to real dictionary file.
194 % 4. Remove log file.
195 % A checkpoint is done only if it has changed since the previous checkpoint.
196 % Returns TRUE if checkpoint was successful; FALSE otherwise. */
197 % db_status checkpoint();
199 %/* Checkpoints table specified by 'tab', or all tables if 'tab' is 0. */
200 % db_status db_checkpoint( char* tab = 0 );
202 %/* Add table with given name 'tab' and description 'zdesc' to dictionary.
203 % Returns error code if table already exists, or if no memory can be found
204 % to store the descriptor, or if dictionary has not been intialized.
205 % Dictionary is updated to stable store before addition.
206 % Fatal error occurs if dictionary cannot be saved.
207 % Returns DB_SUCCESS if dictionary has been updated successfully. */
208 % db_status add_table_aux(char* table_name, table_obj* table_desc, int mode);
210 %/* Delete table with given name 'tab' from dictionary.
211 % Returns error code if table does not exist or if dictionary has not been
212 % initialized. Dictionary is updated to stable store if deletion is
213 % successful. Fatal error occurs if dictionary cannot be saved.
214 % Returns DB_SUCCESS if dictionary has been updated successfully.
215 % Note that the files associated with the table are also removed. */
216 % db_status delete_table_aux( char* table_name, int mode );
218 % db_status add_table( char* table_name, table_obj* table_desc );
219 % int copyfile( char* infile, char *outfile);
221 % db_status delete_table( char* table_name );
223 %/* Return database structure of table named by 'table_name'.
224 % If 'where' is set, set it to the table_desc of 'table_name.'
225 % The database is loaded in from stable store if it has not been loaded.
226 % If it cannot be loaded, it is initialized using the scheme stored in
227 % the table_desc. NULL is returned if the initialization fails. */
228 % db* find_table( char* table_name, db_table_desc ** where = NULL );
230 % db *find_table(char *table_name, db_table_desc **where,
231 % bool_t searchDeferred);
232 % db *find_table(char *table_name, db_table_desc **where,
233 % bool_t searchDeferred, bool_t doLDAP,
236 % db *find_table_noLDAP(char *table_name, db_table_desc **where,
237 % bool_t searchDeferred, bool_t doLoad);
239 %/* Returns db_table_desc of table name 'tab'.
240 % Use this if you do not want table to be loaded. */
241 % db_table_desc * find_table_desc( char* table_name );
243 % db_table_desc * find_table_desc(char *table_name, bool_t searchDeferred);
245 %/* Translate given nis attribute list to a db_query structure.
246 % Return FALSE if dictionary has not been initialized, or
247 % table does not have a scheme (which should be a fatal error?). */
248 % db_query * translate_to_query( db_table_desc*, int, nis_attr * );
250 %/* Return an array of strings of table names of all tables in dictionary. */
251 % db_table_names * get_table_names();
253 %/* Set/clear no-write-through flag */
254 % void setNoWriteThrough(void);
255 % void clearNoWriteThrough(void);
258 % int acqexcl(void) {
259 % return(WLOCK(dict));
262 % int relexcl(void) {
263 % return (WULOCK(dict));
266 % int acqnonexcl(void) {
267 % return (RLOCK(dict));
270 % int relnonexcl(void) {
271 % return (RULOCK(dict));
274 %/* Set deferred commit mode; intended for replica resync */
275 % db_status defer(char *table);
277 %/* Commit deferred changes; intended for replica resync */
278 % db_status commit(char *table);
280 %/* Roll back deferred changes; intended for replica resync */
281 % db_status rollback(char *table);
284 %extern "C" bool_t xdr_db_table_desc_p(XDR *, db_table_desc_p *);
285 %extern "C" bool_t xdr_db_table_desc(XDR *, db_table_desc *);
286 %extern "C" bool_t xdr_db_dict_desc_p(XDR *, db_dict_desc_p *);
287 %extern "C" bool_t xdr_db_table_namep(XDR *, db_table_namep *);
288 %extern "C" bool_t xdr_db_table_names(XDR *, db_table_names *);
295 %#endif /* _DB_DICTIONARY_H */