xref: /titanic_50/usr/src/lib/libnisdb/db_dictionary_c.x (revision 1cb6af97c6f66f456d4f726ef056e1ebc0f73305)
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 2004 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 #endif
99 
100 typedef struct db_dict_desc * db_dict_desc_p;
101 
102 #if	RPC_HDR
103 struct __nisdb_dictionary_defer_struct {
104 	db_dict_desc		*dictionary;	/* Old incarnation */
105 };
106 typedef struct __nisdb_dictionary_defer_struct	__nisdb_dictionary_defer_t;
107 #ifdef	USINGC
108 %bool_t xdr___nisdb_dictionary_defer_t();
109 #endif	USINGC
110 #endif
111 
112 #ifndef USINGC
113 #ifdef RPC_HDR
114 %class db_dictionary {
115 %  db_dict_desc_p dictionary;
116 %  bool_t initialized;
117 %  char* filename;
118 %  char* tmpfilename;
119 %  char* logfilename;
120 %  db_dictlog *logfile;
121 %  bool_t logfile_opened;
122 %  bool_t changed;
123 %  __nisdb_dictionary_defer_t deferred;
124 %  __nisdb_flag_t noWriteThrough;
125 %  STRUCTRWLOCK(dict);
126 %
127 %/* Dump contents of this dictionary (minus the database representation)
128 %     to its file. Returns 0 if operation succeeds, -1 otherwise. */
129 %  int dump();
130 %
131 %/* Delete old log file and descriptor */
132 %  int reset_log();
133 %
134 %/* Open log file (and creates descriptor) if it has not been opened */
135 %  int open_log();
136 %
137 %/* Incorporate updates in log to dictionary already loaded.
138 %   Does not affect "logfile" */
139 %  int incorporate_log( char * );
140 %
141 %  /* closes log file if opened */
142 %  int close_log();
143 %
144 %/*  Log the given action and execute it.
145 %    The minor version of the dictionary is updated after the action has
146 %    been executed and the dictionary is flagged as being changed.
147 %    Return the structure db_result, or NULL if the loggin failed or the
148 %    action is unknown. */
149 %  db_status log_action(int, char* table, table_obj* tobj =0);
150 %
151 %  db_status create_table_desc(char* table_name, table_obj* table_desc,
152 %			       db_table_desc**);
153 %
154 %  db_dict_desc_p db_copy_dictionary(void);
155 %
156 % public:
157 %/* Constructor:  creates an empty, uninitialized dictionary. */
158 %  db_dictionary();
159 %
160 %/* Destructor: noop. Use db_shutdown if you really want to clean up. */
161 %  ~db_dictionary() {}
162 %
163 %  db_status merge_dict (db_dictionary&, char *, char *);
164 %
165 %  db_status massage_dict (char *, char *, char *);
166 %  int	     db_clone_bucket (db_table_desc *, db_table_desc_p *);
167 %  int	     change_table_name (db_table_desc *, char *, char *);
168 %  bool_t    extract_entries (db_dictionary&, char **, int );
169 %
170 %/* Real destructor: deletes filename and table descriptors */
171 %  db_status db_shutdown();
172 %
173 %/*  Initialize dictionary from contents in 'file'.
174 %    If there is already information in this dictionary, it is removed.
175 %    Therefore, regardless of whether the load from the file succeeds,
176 %    the contents of this dictionary will be altered.  Returns
177 %    whether table has been initialized successfully. */
178 %  bool_t init( char* fname );
179 %  bool_t inittemp( char* fname, db_dictionary&);
180 %
181 %/* closes any open log files for all tables in dictionary or 'tab'.
182 %   "tab" is an optional argument.
183 % */
184 %   db_status db_standby( char* tab = 0 );
185 %
186 %/* Write out in-memory copy of dictionary to file.
187 %   1.  Update major version.
188 %   2.  Dump contents to temporary file.
189 %   3.  Rename temporary file to real dictionary file.
190 %   4.  Remove log file.
191 %   A checkpoint is done only if it has changed since the previous checkpoint.
192 %   Returns TRUE if checkpoint was successful; FALSE otherwise. */
193 %  db_status checkpoint();
194 %
195 %/*  Checkpoints table specified by 'tab', or all tables if 'tab' is 0. */
196 %   db_status db_checkpoint( char* tab = 0 );
197 
198 %/* Add table with given name 'tab' and description 'zdesc' to dictionary.
199 %   Returns error code if table already exists, or if no memory can be found
200 %   to store the descriptor, or if dictionary has not been intialized.
201 %   Dictionary is updated to stable store before addition.
202 %   Fatal error occurs if dictionary cannot be saved.
203 %   Returns DB_SUCCESS if dictionary has been updated successfully. */
204 %  db_status add_table_aux(char* table_name, table_obj* table_desc, int mode);
205 %
206 %/* Delete table with given name 'tab' from dictionary.
207 %   Returns error code if table does not exist or if dictionary has not been
208 %   initialized.   Dictionary is updated to stable store if deletion is
209 %   successful.  Fatal error occurs if dictionary cannot be saved.
210 %   Returns DB_SUCCESS if dictionary has been updated successfully.
211 %   Note that the files associated with the table are also removed.  */
212 %  db_status delete_table_aux( char* table_name, int mode );
213 %
214 %  db_status add_table( char* table_name, table_obj* table_desc );
215 %  int copyfile( char* infile, char *outfile);
216 %
217 %  db_status delete_table( char* table_name );
218 %
219 %/* Return database structure of table named by 'table_name'.
220 %   If 'where' is set, set it to the table_desc of 'table_name.'
221 %   The database is loaded in from stable store if it has not been loaded.
222 %   If it cannot be loaded, it is initialized using the scheme stored in
223 %   the table_desc.  NULL is returned if the initialization fails.   */
224 %  db* find_table( char* table_name, db_table_desc ** where = NULL );
225 %
226 %  db *find_table(char *table_name, db_table_desc **where,
227 %			bool_t searchDeferred);
228 %  db *find_table(char *table_name, db_table_desc **where,
229 %			bool_t searchDeferred, bool_t doLDAP,
230 %			bool_t doLoad);
231 %
232 %  db *find_table_noLDAP(char *table_name, db_table_desc **where,
233 %			bool_t searchDeferred, bool_t doLoad);
234 %
235 %/* Returns db_table_desc of table name 'tab'.
236 %   Use this if you do not want table to be loaded. */
237 %  db_table_desc * find_table_desc( char* table_name );
238 %
239 %  db_table_desc * find_table_desc(char *table_name, bool_t searchDeferred);
240 %
241 %/* Translate given nis attribute list to a db_query structure.
242 %   Return FALSE if dictionary has not been initialized, or
243 %   table does not have a scheme (which should be a fatal error?). */
244 %  db_query * translate_to_query( db_table_desc*, int, nis_attr * );
245 %
246 %/* Return an array of strings of table names of all tables in dictionary. */
247 %   db_table_names * get_table_names();
248 %
249 %/* Set/clear no-write-through flag */
250 %  void setNoWriteThrough(void);
251 %  void clearNoWriteThrough(void);
252 %
253 %/* Locking */
254 %  int acqexcl(void) {
255 %	return(WLOCK(dict));
256 %  }
257 %
258 %  int relexcl(void) {
259 %	return (WULOCK(dict));
260 %  }
261 %
262 %  int acqnonexcl(void) {
263 %	return (RLOCK(dict));
264 %  }
265 %
266 %  int relnonexcl(void) {
267 %	return (RULOCK(dict));
268 %  }
269 %
270 %/* Set deferred commit mode; intended for replica resync */
271 %  db_status defer(char *table);
272 %
273 %/* Commit deferred changes; intended for replica resync */
274 %  db_status commit(char *table);
275 %
276 %/* Roll back deferred changes; intended for replica resync */
277 %  db_status rollback(char *table);
278 %};
279 %#ifdef __STDC__
280 %extern "C" bool_t xdr_db_table_desc_p(XDR *, db_table_desc_p *);
281 %extern "C" bool_t xdr_db_table_desc(XDR *, db_table_desc *);
282 %extern "C" bool_t xdr_db_dict_desc_p(XDR *, db_dict_desc_p *);
283 %extern "C" bool_t xdr_db_table_namep(XDR *, db_table_namep *);
284 %extern "C" bool_t xdr_db_table_names(XDR *, db_table_names *);
285 %#endif
286 
287 #endif RPC_HDR
288 #endif USINGC
289 
290 #if RPC_HDR
291 %#endif _DB_DICTIONARY_H
292 #endif RPC_HDR
293 
294