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