xref: /titanic_44/usr/src/lib/libnisdb/db_dictionary_c.x (revision 56b2bdd1f04d465cfe4a95b88ae5cba5884154e4)
1 /*
2  * CDDL HEADER START
3  *
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
7  * with the License.
8  *
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.
13  *
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]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  *	db_dictionary_c.x
24  *
25  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
26  * Use is subject to license terms.
27  */
28 
29 %#pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #if RPC_HDR
32 %#ifndef _DB_DICTIONARY_H
33 %#define _DB_DICTIONARY_H
34 
35 #ifdef USINGC
36 %#include "nisdb_rw.h"
37 %#include "nisdb_ldap.h"
38 %#include "db_entry_c.h"
39 %#include "db_scheme_c.h"
40 %#include "db_vers_c.h"
41 %#include "ldap_xdr.h"
42 %typedef void *nullptr;
43 %typedef u_int db_dict_version;
44 #else
45 %#include "nisdb_rw.h"
46 %#include "nisdb_ldap.h"
47 %#include "db_entry.h"
48 %#include "db_scheme.h"
49 %#include "db.h"
50 %#include "db_vers.h"
51 %#include "db_dictlog.h"
52 %#include "ldap_xdr.h"
53 #endif /* USINGC */
54 #endif /* RPC_HDR */
55 
56 struct db_table_desc {
57   string table_name<NIS_MAXNAMELEN>;
58   u_long hashval;
59   db_scheme * scheme;
60 #ifdef USINGC
61   nullptr database;   /* for XDR, keep database from descriptor */
62 #else
63   db *database;        /* for program use in c++ code */
64 #endif /* USINGC */
65   db_table_desc *next;
66 };
67 typedef struct db_table_desc * db_table_desc_p;
68 
69 /* Defining own version of xdr_db_dict_version */
70 #if RPC_HDR
71 #ifndef USINGC
72 typedef u_int db_dict_version;
73 %bool_t xdr_db_dict_version();
74 #endif /* USINGC */
75 
76 typedef char * db_table_namep;
77 typedef db_table_namep db_table_names<>;
78 
79 /* Defining own version of xdr_db_dict_desc */
80 #ifndef USINGC
81 struct db_dict_desc {
82 	db_dict_version impl_vers;
83 	db_table_desc_p tables<>;
84 	int count;
85 };
86 #else
87 %struct db_dict_desc {
88 %	db_dict_version impl_vers;
89 %	struct {
90 %		u_int tables_len;
91 %		db_table_desc_p *tables_val;
92 %	} tables;
93 %	int count;
94 %};
95 %typedef struct db_dict_desc db_dict_desc;
96 %bool_t xdr_db_dict_desc();
97 #endif /* USINGC */
98 
99 #endif
100 
101 typedef struct db_dict_desc * db_dict_desc_p;
102 
103 #if	RPC_HDR
104 struct __nisdb_dictionary_defer_struct {
105 	db_dict_desc		*dictionary;	/* Old incarnation */
106 };
107 typedef struct __nisdb_dictionary_defer_struct	__nisdb_dictionary_defer_t;
108 #ifdef	USINGC
109 %bool_t xdr___nisdb_dictionary_defer_t();
110 #endif	/* USINGC */
111 #endif
112 
113 #ifndef USINGC
114 #ifdef RPC_HDR
115 %class db_dictionary {
116 %  db_dict_desc_p dictionary;
117 %  bool_t initialized;
118 %  char* filename;
119 %  char* tmpfilename;
120 %  char* logfilename;
121 %  db_dictlog *logfile;
122 %  bool_t logfile_opened;
123 %  bool_t changed;
124 %  __nisdb_dictionary_defer_t deferred;
125 %  __nisdb_flag_t noWriteThrough;
126 %  STRUCTRWLOCK(dict);
127 %
128 %/* Dump contents of this dictionary (minus the database representation)
129 %     to its file. Returns 0 if operation succeeds, -1 otherwise. */
130 %  int dump();
131 %
132 %/* Delete old log file and descriptor */
133 %  int reset_log();
134 %
135 %/* Open log file (and creates descriptor) if it has not been opened */
136 %  int open_log();
137 %
138 %/* Incorporate updates in log to dictionary already loaded.
139 %   Does not affect "logfile" */
140 %  int incorporate_log( char * );
141 %
142 %  /* closes log file if opened */
143 %  int close_log();
144 %
145 %/*  Log the given action and execute it.
146 %    The minor version of the dictionary is updated after the action has
147 %    been executed and the dictionary is flagged as being changed.
148 %    Return the structure db_result, or NULL if the loggin failed or the
149 %    action is unknown. */
150 %  db_status log_action(int, char* table, table_obj* tobj =0);
151 %
152 %  db_status create_table_desc(char* table_name, table_obj* table_desc,
153 %			       db_table_desc**);
154 %
155 %  db_dict_desc_p db_copy_dictionary(void);
156 %
157 % public:
158 %/* Constructor:  creates an empty, uninitialized dictionary. */
159 %  db_dictionary();
160 %
161 %/* Destructor: noop. Use db_shutdown if you really want to clean up. */
162 %  ~db_dictionary() {}
163 %
164 %  db_status merge_dict (db_dictionary&, char *, char *);
165 %
166 %  db_status massage_dict (char *, char *, char *);
167 %  int	     db_clone_bucket (db_table_desc *, db_table_desc_p *);
168 %  int	     change_table_name (db_table_desc *, char *, char *);
169 %  bool_t    extract_entries (db_dictionary&, char **, int );
170 %
171 %/* Real destructor: deletes filename and table descriptors */
172 %  db_status db_shutdown();
173 %
174 %/*  Initialize dictionary from contents in 'file'.
175 %    If there is already information in this dictionary, it is removed.
176 %    Therefore, regardless of whether the load from the file succeeds,
177 %    the contents of this dictionary will be altered.  Returns
178 %    whether table has been initialized successfully. */
179 %  bool_t init( char* fname );
180 %  bool_t inittemp( char* fname, db_dictionary&);
181 %
182 %/* closes any open log files for all tables in dictionary or 'tab'.
183 %   "tab" is an optional argument.
184 % */
185 %   db_status db_standby( char* tab = 0 );
186 %
187 %/* Write out in-memory copy of dictionary to file.
188 %   1.  Update major version.
189 %   2.  Dump contents to temporary file.
190 %   3.  Rename temporary file to real dictionary file.
191 %   4.  Remove log file.
192 %   A checkpoint is done only if it has changed since the previous checkpoint.
193 %   Returns TRUE if checkpoint was successful; FALSE otherwise. */
194 %  db_status checkpoint();
195 %
196 %/*  Checkpoints table specified by 'tab', or all tables if 'tab' is 0. */
197 %   db_status db_checkpoint( char* tab = 0 );
198 
199 %/* Add table with given name 'tab' and description 'zdesc' to dictionary.
200 %   Returns error code if table already exists, or if no memory can be found
201 %   to store the descriptor, or if dictionary has not been intialized.
202 %   Dictionary is updated to stable store before addition.
203 %   Fatal error occurs if dictionary cannot be saved.
204 %   Returns DB_SUCCESS if dictionary has been updated successfully. */
205 %  db_status add_table_aux(char* table_name, table_obj* table_desc, int mode);
206 %
207 %/* Delete table with given name 'tab' from dictionary.
208 %   Returns error code if table does not exist or if dictionary has not been
209 %   initialized.   Dictionary is updated to stable store if deletion is
210 %   successful.  Fatal error occurs if dictionary cannot be saved.
211 %   Returns DB_SUCCESS if dictionary has been updated successfully.
212 %   Note that the files associated with the table are also removed.  */
213 %  db_status delete_table_aux( char* table_name, int mode );
214 %
215 %  db_status add_table( char* table_name, table_obj* table_desc );
216 %  int copyfile( char* infile, char *outfile);
217 %
218 %  db_status delete_table( char* table_name );
219 %
220 %/* Return database structure of table named by 'table_name'.
221 %   If 'where' is set, set it to the table_desc of 'table_name.'
222 %   The database is loaded in from stable store if it has not been loaded.
223 %   If it cannot be loaded, it is initialized using the scheme stored in
224 %   the table_desc.  NULL is returned if the initialization fails.   */
225 %  db* find_table( char* table_name, db_table_desc ** where = NULL );
226 %
227 %  db *find_table(char *table_name, db_table_desc **where,
228 %			bool_t searchDeferred);
229 %  db *find_table(char *table_name, db_table_desc **where,
230 %			bool_t searchDeferred, bool_t doLDAP,
231 %			bool_t doLoad);
232 %
233 %  db *find_table_noLDAP(char *table_name, db_table_desc **where,
234 %			bool_t searchDeferred, bool_t doLoad);
235 %
236 %/* Returns db_table_desc of table name 'tab'.
237 %   Use this if you do not want table to be loaded. */
238 %  db_table_desc * find_table_desc( char* table_name );
239 %
240 %  db_table_desc * find_table_desc(char *table_name, bool_t searchDeferred);
241 %
242 %/* Translate given nis attribute list to a db_query structure.
243 %   Return FALSE if dictionary has not been initialized, or
244 %   table does not have a scheme (which should be a fatal error?). */
245 %  db_query * translate_to_query( db_table_desc*, int, nis_attr * );
246 %
247 %/* Return an array of strings of table names of all tables in dictionary. */
248 %   db_table_names * get_table_names();
249 %
250 %/* Set/clear no-write-through flag */
251 %  void setNoWriteThrough(void);
252 %  void clearNoWriteThrough(void);
253 %
254 %/* Locking */
255 %  int acqexcl(void) {
256 %	return(WLOCK(dict));
257 %  }
258 %
259 %  int relexcl(void) {
260 %	return (WULOCK(dict));
261 %  }
262 %
263 %  int acqnonexcl(void) {
264 %	return (RLOCK(dict));
265 %  }
266 %
267 %  int relnonexcl(void) {
268 %	return (RULOCK(dict));
269 %  }
270 %
271 %/* Set deferred commit mode; intended for replica resync */
272 %  db_status defer(char *table);
273 %
274 %/* Commit deferred changes; intended for replica resync */
275 %  db_status commit(char *table);
276 %
277 %/* Roll back deferred changes; intended for replica resync */
278 %  db_status rollback(char *table);
279 %};
280 %#ifdef __STDC__
281 %extern "C" bool_t xdr_db_table_desc_p(XDR *, db_table_desc_p *);
282 %extern "C" bool_t xdr_db_table_desc(XDR *, db_table_desc *);
283 %extern "C" bool_t xdr_db_dict_desc_p(XDR *, db_dict_desc_p *);
284 %extern "C" bool_t xdr_db_table_namep(XDR *, db_table_namep *);
285 %extern "C" bool_t xdr_db_table_names(XDR *, db_table_names *);
286 %#endif
287 
288 #endif /* RPC_HDR */
289 #endif /* USINGC */
290 
291 #if RPC_HDR
292 %#endif /* _DB_DICTIONARY_H */
293 #endif /* RPC_HDR */
294 
295