rpm  5.4.4
rpmdb/dbconfig.c
Go to the documentation of this file.
00001 
00005 #include "system.h"
00006 
00007 #include <rpmio.h>
00008 #include <popt.h>
00009 #include <rpmlog.h>
00010 #include <rpmmacro.h>
00011 
00012 #include <rpmtag.h>
00013 #define _RPMDB_INTERNAL
00014 #include <rpmdb.h>
00015 #include "debug.h"
00016 
00017 /*@access rpmdb@*/
00018 /*@access dbiIndex@*/
00019 /*@access dbiIndexSet@*/
00020 
00021 /*@unchecked@*/
00022 int _dbi_debug;
00023 
00024 #if defined(WITH_DB) || defined(WITH_SQLITE)
00025 
00026 /*@-exportlocal -exportheadervar@*/
00027 /*@unchecked@*/
00028 struct _dbiIndex db3dbi;
00029 /*@=exportlocal =exportheadervar@*/
00030 
00031 /*@-compmempass -immediatetrans -exportlocal -exportheadervar -type@*/
00034 /*@unchecked@*/
00035 struct poptOption rdbOptions[] = {
00036  /* XXX DB_CXX_NO_EXCEPTIONS */
00037 #if defined(WITH_DB) && defined(DB_CLIENT)
00038  { "client",    0,POPT_BIT_SET, &db3dbi.dbi_ecflags, DB_CLIENT,
00039         NULL, NULL },
00040 #endif
00041 #if defined(WITH_DB) && defined(DB_RPCCLIENT)
00042  { "client",    0,POPT_BIT_SET, &db3dbi.dbi_ecflags, DB_RPCCLIENT,
00043         NULL, NULL },
00044  { "rpcclient", 0,POPT_BIT_SET, &db3dbi.dbi_ecflags, DB_RPCCLIENT,
00045         NULL, NULL },
00046 #endif
00047 
00048 /* DB_ENV->open and DB->open */
00049 #if defined(WITH_DB) && defined(DB_CREATE)
00050  { "create",    0,POPT_BIT_SET, &db3dbi.dbi_oeflags, DB_CREATE,
00051         NULL, NULL },
00052 #endif
00053 #if defined(WITH_DB) && defined(DB_THREAD)
00054  { "thread",    0,POPT_BIT_SET, &db3dbi.dbi_oeflags, DB_THREAD,
00055         NULL, NULL },
00056 #endif
00057 #if defined(WITH_DB) && defined(DB_MULTIVERSION)
00058  { "multiversion", 0,POPT_BIT_SET, &db3dbi.dbi_oeflags, DB_MULTIVERSION,
00059         NULL, NULL },
00060 #endif
00061 #if defined(WITH_DB) && defined(DB_NOMMAP)
00062  { "nommap",    0,POPT_BIT_SET, &db3dbi.dbi_oeflags, DB_NOMMAP,
00063         NULL, NULL },
00064 #endif
00065 
00066 #if defined(WITH_DB) && defined(DB_FORCE)
00067  { "force",     0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_FORCE,
00068         NULL, NULL },
00069 #endif
00070 
00071 /* DB_ENV->set_flags */
00072 /* DB_ENV->get_flags */
00073 #if defined(WITH_DB) && defined(DB_INIT_CDB)
00074  { "cdb",       0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_INIT_CDB,
00075         NULL, NULL },
00076 #endif
00077 #if defined(WITH_DB) && defined(DB_INIT_LOCK)
00078  { "lock",      0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_INIT_LOCK,
00079         NULL, NULL },
00080 #endif
00081 #if defined(WITH_DB) && defined(DB_INIT_LOG)
00082  { "log",       0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_INIT_LOG,
00083         NULL, NULL },
00084 #endif
00085 #if defined(WITH_DB) && defined(DB_INIT_MPOOL)
00086  { "mpool",     0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_INIT_MPOOL,
00087         NULL, NULL },
00088 #endif
00089 #if defined(WITH_DB) && defined(DB_INIT_REP)
00090  { "rep", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_INIT_REP,
00091         NULL, NULL },
00092 #endif
00093 #if defined(WITH_DB) && defined(DB_INIT_TXN)
00094  { "txn",       0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_INIT_TXN,
00095         NULL, NULL },
00096 #endif
00097 
00098 #ifdef  DYING   /* XXX compatibly defined to 0 in db-4.5.20 */
00099  { "joinenv",   0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_JOINENV,
00100         NULL, NULL },
00101 #endif
00102 #if defined(WITH_DB) && defined(DB_LOCKDOWN)
00103  { "lockdown",  0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_LOCKDOWN,
00104         NULL, NULL },
00105 #endif
00106 #if (defined(WITH_DB) || defined(WITH_SQLITE)) && defined(DB_PRIVATE)
00107  { "private",   0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_PRIVATE,
00108         NULL, NULL },
00109 #endif
00110 #if defined(WITH_DB) && defined(DB_RECOVER)
00111  { "recover",   0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_RECOVER,
00112         NULL, NULL },
00113 #endif
00114 #if defined(WITH_DB) && defined(DB_RECOVER_FATAL)
00115  { "recover_fatal", 0,POPT_BIT_SET,     &db3dbi.dbi_eflags, DB_RECOVER_FATAL,
00116         NULL, NULL },
00117 #endif
00118 #if defined(WITH_DB) && defined(DB_REGISTER)
00119  { "register", 0,POPT_BIT_SET,  &db3dbi.dbi_eflags, DB_REGISTER,
00120         NULL, NULL },
00121 #endif
00122 #if defined(WITH_DB) && defined(DB_SYSTEM_MEM)
00123  { "shared",    0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_SYSTEM_MEM,
00124         NULL, NULL },
00125 #endif
00126 #if defined(WITH_DB) && defined(DB_TXN_NOSYNC)
00127  { "txn_nosync", 0,POPT_BIT_SET,        &db3dbi.dbi_eflags, DB_TXN_NOSYNC,
00128         NULL, NULL },
00129 #endif
00130 #if defined(WITH_DB) && defined(DB_USE_ENVIRON_ROOT)
00131  { "use_environ_root", 0,POPT_BIT_SET,  &db3dbi.dbi_eflags, DB_USE_ENVIRON_ROOT,
00132         NULL, NULL },
00133 #endif
00134 #if defined(WITH_DB) && defined(DB_USE_ENVIRON)
00135  { "use_environ", 0,POPT_BIT_SET,       &db3dbi.dbi_eflags, DB_USE_ENVIRON,
00136         NULL, NULL },
00137 #endif
00138 #if defined(WITH_DB) && defined(DB_IGNORE_LEASE)
00139  { "ignore_lease", 0,POPT_BIT_SET,      &db3dbi.dbi_eflags, DB_IGNORE_LEASE,
00140         NULL, NULL },
00141 #endif
00142 
00143 #if defined(WITH_DB) && defined(DB_TXN_SYNC)
00144  { "txn_sync",  0,POPT_BIT_SET, &db3dbi.dbi_tflags, DB_TXN_SYNC,
00145         NULL, NULL },
00146 #endif
00147 #if defined(WITH_DB) && defined(DB_TXN_NOWAIT)
00148  { "txn_nowait",0,POPT_BIT_SET, &db3dbi.dbi_tflags, DB_TXN_NOWAIT,
00149         NULL, NULL },
00150 #endif
00151 #if defined(WITH_DB) && defined(DB_TXN_WAIT)
00152  { "txn_wait",0,POPT_BIT_SET,   &db3dbi.dbi_tflags, DB_TXN_WAIT,
00153         NULL, NULL },
00154 #endif
00155 
00156 #if defined(WITH_DB) && defined(NOTYET)
00157 DB_AUTO_COMMIT
00158 DB_CDB_ALLDB
00159 DB_DIRECT_DB
00160 DB_DIRECT_LOG
00161 DB_DSYNC_DB
00162 DB_DSYNC_LOG
00163 DB_LOG_AUTOREMOVE
00164 DB_LOG_BUFFER_FULL      /* ??? */
00165 DB_LOG_INMEMORY
00166 DB_NOLOCKING
00167 DB_MULTIVERSION
00168 DB_NOMMAP
00169 DB_NOPANIC
00170 DB_OVERWRITE
00171 DB_PANIC_ENVIRONMENT
00172 DB_REGION_INIT
00173 DB_TIME_NOTGRANTED
00174 DB_TXN_NOSYNC
00175 DB_TXN_SNAPSHOT
00176 DB_WRITE_NOSYNC
00177 DB_YIELDCPU
00178 #endif
00179 
00180 /* DB->set_flags */
00181 /* DB->get_flags */
00182 #if defined(WITH_DB) && defined(NOTYET)
00183 DB_CHKSUM
00184 DB_ENCRYPT
00185 DB_TXN_NOT_DURABLE
00186 
00187 DB_DUP          BTREE HASH
00188 DB_DUPSORT      BTREE HASH
00189 DB_RECNUM       BTREE
00190 DB_REVSPLITOFF  BTREE
00191 
00192 DB_INORDER      QUEUE
00193 DB_RENUMBER     RECNO
00194 DB_SNAPSHOT     RECNO
00195 #endif
00196 
00197 /* DB->open */
00198 #if defined(WITH_DB) && defined(DB_RDONLY)
00199  { "rdonly",    0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_RDONLY,
00200         NULL, NULL },
00201 #endif
00202 #if (defined(WITH_DB) || defined(WITH_SQLITE)) && defined(DB_EXCL)
00203  { "excl",      0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_EXCL,
00204         NULL, NULL },
00205 #endif
00206 #if defined(WITH_DB) && defined(DB_TRUNCATE)
00207  { "truncate",  0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_TRUNCATE,
00208         NULL, NULL },
00209 #endif
00210 #if defined(WITH_DB) && defined(DB_FCNTL_LOCKING)
00211  { "fcntl_locking",0,POPT_BIT_SET,      &db3dbi.dbi_oflags, DB_FCNTL_LOCKING,
00212         NULL, NULL },
00213 #endif
00214 #if defined(WITH_DB) && defined(DB_AUTO_COMMIT)
00215  { "auto_commit", 0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_AUTO_COMMIT,
00216         NULL, NULL },
00217 #endif
00218 #if defined(WITH_DB) && defined(DB_NO_AUTO_COMMIT) && defined(NOTYET)
00219  { "noautocommit", 0,POPT_BIT_SET,      &db3dbi.dbi_oflags, DB_NO_AUTO_COMMIT,
00220         NULL, NULL },
00221 #endif
00222 #if defined(WITH_DB) && defined(DB_RDWRMASTER) && defined(NOTYET)
00223  { "rdwrmaster", 0,POPT_BIT_SET,        &db3dbi.dbi_oflags, DB_RDWRMASTER,
00224         NULL, NULL },
00225 #endif
00226 #if defined(WITH_DB) && defined(NOTYET)
00227 DB_READ_UNCOMITTED
00228 #endif
00229 #if defined(WITH_DB) && defined(DB_WRITEOPEN)
00230  { "writeopen", 0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_WRITEOPEN,
00231         NULL, NULL },
00232 #endif
00233 
00234 #if defined(WITH_DB)
00235  { "btree",     0,POPT_ARG_VAL,         &db3dbi.dbi_type, DB_BTREE,
00236         NULL, NULL },
00237  { "hash",      0,POPT_ARG_VAL,         &db3dbi.dbi_type, DB_HASH,
00238         NULL, NULL },
00239  { "recno",     0,POPT_ARG_VAL,         &db3dbi.dbi_type, DB_RECNO,
00240         NULL, NULL },
00241  { "queue",     0,POPT_ARG_VAL,         &db3dbi.dbi_type, DB_QUEUE,
00242         NULL, NULL },
00243 #if defined(DB_HEAP)
00244  { "heap",      0,POPT_ARG_VAL,         &db3dbi.dbi_type, DB_HEAP,
00245         NULL, NULL },
00246 #endif
00247  { "unknown",   0,POPT_ARG_VAL,         &db3dbi.dbi_type, DB_UNKNOWN,
00248         NULL, NULL },
00249 #endif
00250 
00251  { "root",      0,POPT_ARG_STRING,      &db3dbi.dbi_root, 0,
00252         NULL, NULL },
00253  { "home",      0,POPT_ARG_STRING,      &db3dbi.dbi_home, 0,
00254         NULL, NULL },
00255  { "file",      0,POPT_ARG_STRING,      &db3dbi.dbi_file, 0,
00256         NULL, NULL },
00257  { "subfile",   0,POPT_ARG_STRING,      &db3dbi.dbi_subfile, 0,
00258         NULL, NULL },
00259 #if defined(WITH_DB)
00260  { "mode",      0,POPT_ARG_INT,         &db3dbi.dbi_mode, 0,
00261         NULL, NULL },
00262 #endif
00263  { "perms",     0,POPT_ARG_INT,         &db3dbi.dbi_perms, 0,
00264         NULL, NULL },
00265 #if defined(WITH_DB)
00266  { "shmkey",    0,POPT_ARG_LONG,        &db3dbi.dbi_shmkey, 0,
00267         NULL, NULL },
00268 #endif
00269  { "tmpdir",    0,POPT_ARG_STRING,      &db3dbi.dbi_tmpdir, 0,
00270         NULL, NULL },
00271 
00272 #if defined(WITH_DB)
00273  { "host",      0,POPT_ARG_STRING,      &db3dbi.dbi_host, 0,
00274         NULL, NULL },
00275  { "server",    0,POPT_ARG_STRING,      &db3dbi.dbi_host, 0,
00276         NULL, NULL },
00277  { "cl_timeout", 0,POPT_ARG_LONG,       &db3dbi.dbi_cl_timeout, 0,
00278         NULL, NULL },
00279  { "sv_timeout", 0,POPT_ARG_LONG,       &db3dbi.dbi_sv_timeout, 0,
00280         NULL, NULL },
00281 #endif
00282 
00283 #if defined(WITH_DB)
00284  { "usedbenv",  0,POPT_ARG_NONE,        &db3dbi.dbi_use_dbenv, 0,
00285         NULL, NULL },
00286 #endif
00287  { "nofsync",   0,POPT_ARG_NONE,        &db3dbi.dbi_no_fsync, 0,
00288         NULL, NULL },
00289 #if defined(WITH_DB)
00290  { "nodbsync",  0,POPT_ARG_NONE,        &db3dbi.dbi_no_dbsync, 0,
00291         NULL, NULL },
00292  { "lockdbfd",  0,POPT_ARG_NONE,        &db3dbi.dbi_lockdbfd, 0,
00293         NULL, NULL },
00294 #endif
00295  { "primary",   0,POPT_ARG_STRING,      &db3dbi.dbi_primary, 0,
00296         NULL, NULL },
00297  { "foreign",   0,POPT_ARG_STRING,      &db3dbi.dbi_foreign, 0,
00298         NULL, NULL },
00299  { "temporary", 0,POPT_ARG_NONE,        &db3dbi.dbi_temporary, 0,
00300         NULL, NULL },
00301 #if defined(WITH_DB)
00302  { "debug",     0,POPT_ARG_NONE,        &db3dbi.dbi_debug, 0,
00303         NULL, NULL },
00304 #endif
00305 
00306 /* XXX set_alloc */
00307 #if defined(WITH_DB)
00308 /* XXX set_dup_compare */
00309 /* XXX set_encrypt */
00310  { "errpfx",    0,POPT_ARG_STRING,      &db3dbi.dbi_errpfx, 0,
00311         NULL, NULL },
00312 /* XXX set_feedback */
00313  { "lorder",    0,POPT_ARG_INT,         &db3dbi.dbi_lorder, 0,
00314         NULL, NULL },
00315 #endif
00316  { "pagesize",  0,POPT_ARG_INT,         &db3dbi.dbi_pagesize, 0,
00317         NULL, NULL },
00318  { "heapsize",  0,POPT_ARG_INT,         &db3dbi.dbi_heapsize, 0,
00319         NULL, NULL },
00320 
00321 #if defined(WITH_DB)
00322  { "region_init", 0,POPT_ARG_VAL,       &db3dbi.dbi_region_init, 1,
00323         NULL, NULL },
00324 
00325  { "thread_count", 0,POPT_ARG_INT,      &db3dbi.dbi_thread_count, 0,
00326         NULL, NULL },
00327 
00328 #endif
00329 
00330 /* ==== Locking: */
00331 
00332 /* ==== Logging: */
00333 
00334 /* ==== Memory pool: */
00335 /* XXX DB_MPOOLFILE->set_clear_len */
00336 /* XXX DB_MPOOLFILE->set_fileid */
00337 /* XXX DB_MPOOLFILE->set_ftype */
00338 /* XXX DB_MPOOLFILE->set_lsn_offset */
00339 /* XXX DB_MPOOLFILE->set_maxsize */
00340 /* XXX DB_MPOOLFILE->set_pgcookie */
00341 /* XXX DB_MPOOLFILE->set_priority */
00342 
00343 /* ==== Mutexes: */
00344 
00345 /* ==== Replication: */
00346 
00347 /* ==== Sequences: */
00348 #if defined(WITH_DB)
00349  { "seq_id",    0,POPT_ARG_STRING,      &db3dbi.dbi_seq_id, 0,
00350         NULL, NULL },
00351 /* XXX DB_SEQUENCE->set_cachesize */
00352 /* XXX DB_SEQUENCE->get_cachesize */
00353  { "seq_cachesize",     0,POPT_ARG_INT, &db3dbi.dbi_seq_cachesize, 0,
00354         NULL, NULL },
00355 #endif
00356 /* XXX DB_SEQUENCE->set_flags */
00357 /* XXX DB_SEQUENCE->get_flags */
00358 #if defined(WITH_DB) && defined(DB_SEQ_DEC)
00359  { "seq_dec",   0,POPT_BIT_SET,         &db3dbi.dbi_seq_flags, DB_SEQ_DEC,
00360         NULL, NULL },
00361 #endif
00362 #if defined(WITH_DB) && defined(DB_SEQ_INC)
00363  { "seq_inc",   0,POPT_BIT_SET,         &db3dbi.dbi_seq_flags, DB_SEQ_INC,
00364         NULL, NULL },
00365 #endif
00366 #if defined(WITH_DB) && defined(DB_SEQ_WRAP)
00367  { "seq_wrap",  0,POPT_BIT_SET,         &db3dbi.dbi_seq_flags, DB_SEQ_WRAP,
00368         NULL, NULL },
00369 #endif
00370 #if defined(WITH_DB)
00371 /* XXX DB_SEQUENCE->initial_value */
00372  { "seq_initial",       0,POPT_ARG_LONG, &db3dbi.dbi_seq_initial, 0,
00373         NULL, NULL },
00374 /* XXX DB_SEQUENCE->set_range */
00375 /* XXX DB_SEQUENCE->get_range */
00376  { "seq_min",   0,POPT_ARG_LONG,        &db3dbi.dbi_seq_min, 0,
00377         NULL, NULL },
00378  { "seq_max",   0,POPT_ARG_LONG,        &db3dbi.dbi_seq_max, 0,
00379         NULL, NULL },
00380 #endif
00381 
00382 /* ==== Transactions: */
00383 
00384 /* XXX set_append_recno */
00385 /* XXX set_bt_compare */
00386 /* XXX set_bt_dup_compare */
00387 /* XXX set_bt_minkey */
00388 /* XXX set_bt_prefix */
00389 #if defined(WITH_DB) && defined(DB_DUP)
00390  { "bt_dup",    0,POPT_BIT_SET, &db3dbi.dbi_bt_flags, DB_DUP,
00391         NULL, NULL },
00392 #endif
00393 #if defined(WITH_DB) && defined(DB_DUPSORT)
00394  { "bt_dupsort",0,POPT_BIT_SET, &db3dbi.dbi_bt_flags, DB_DUPSORT,
00395         NULL, NULL },
00396 #endif
00397 #if defined(WITH_DB) && defined(DB_RECNUM)
00398  { "bt_recnum", 0,POPT_BIT_SET, &db3dbi.dbi_bt_flags, DB_RECNUM,
00399         NULL, NULL },
00400 #endif
00401 #if defined(WITH_DB) && defined(DB_REVSPLITOFF)
00402  { "bt_revsplitoff", 0,POPT_BIT_SET,    &db3dbi.dbi_bt_flags, DB_REVSPLITOFF,
00403         NULL, NULL },
00404 #endif
00405 
00406 #if defined(WITH_DB) && defined(DB_DUP)
00407  { "h_dup",     0,POPT_BIT_SET, &db3dbi.dbi_h_flags, DB_DUP,
00408         NULL, NULL },
00409 #endif
00410 #if defined(WITH_DB) && defined(DB_DUPSORT)
00411  { "h_dupsort", 0,POPT_BIT_SET, &db3dbi.dbi_h_flags, DB_DUPSORT,
00412         NULL, NULL },
00413 #endif
00414 #if defined(WITH_DB)
00415  { "h_ffactor", 0,POPT_ARG_INT,         &db3dbi.dbi_h_ffactor, 0,
00416         NULL, NULL },
00417  { "h_nelem",   0,POPT_ARG_INT,         &db3dbi.dbi_h_nelem, 0,
00418         NULL, NULL },
00419 #endif
00420 
00421 #if defined(WITH_DB) && defined(DB_RENUMBER)
00422  { "re_renumber", 0,POPT_BIT_SET,       &db3dbi.dbi_re_flags, DB_RENUMBER,
00423         NULL, NULL },
00424 #endif
00425 #if defined(WITH_DB) && defined(DB_SNAPSHOT)
00426  { "re_snapshot",0,POPT_BIT_SET,        &db3dbi.dbi_re_flags, DB_SNAPSHOT,
00427         NULL, NULL },
00428 #endif
00429 #if defined(WITH_DB)
00430  { "re_delim",  0,POPT_ARG_INT,         &db3dbi.dbi_re_delim, 0,
00431         NULL, NULL },
00432  { "re_len",    0,POPT_ARG_INT,         &db3dbi.dbi_re_len, 0,
00433         NULL, NULL },
00434  { "re_pad",    0,POPT_ARG_INT,         &db3dbi.dbi_re_pad, 0,
00435         NULL, NULL },
00436  { "re_source", 0,POPT_ARG_STRING,      &db3dbi.dbi_re_source, 0,
00437         NULL, NULL },
00438 
00439  { "q_extentsize", 0,POPT_ARG_INT,      &db3dbi.dbi_q_extentsize, 0,
00440         NULL, NULL },
00441 #endif
00442 
00443     POPT_TABLEEND
00444 };
00445 /*@=compmempass =immediatetrans =exportlocal =exportheadervar =type@*/
00446 
00447 static void dbiFini(void * _dbi)
00448         /*@*/
00449 {
00450     dbiIndex dbi = _dbi;
00451     if (dbi) {
00452         dbi->dbi_root = _free(dbi->dbi_root);
00453         dbi->dbi_home = _free(dbi->dbi_home);
00454         dbi->dbi_file = _free(dbi->dbi_file);
00455         dbi->dbi_subfile = _free(dbi->dbi_subfile);
00456         dbi->dbi_tmpdir = _free(dbi->dbi_tmpdir);
00457         dbi->dbi_bf = rpmbfFree(dbi->dbi_bf);
00458         dbi->dbi_host = _free(dbi->dbi_host);
00459         dbi->dbi_errpfx = _free(dbi->dbi_errpfx);
00460         dbi->dbi_seq_id = _free(dbi->dbi_seq_id);
00461         dbi->dbi_re_source = _free(dbi->dbi_re_source);
00462         dbi->dbi_primary = _free(dbi->dbi_primary);
00463         dbi->dbi_foreign = _free(dbi->dbi_foreign);
00464         dbi->dbi_stats = _free(dbi->dbi_stats);
00465     }
00466 }
00467 
00468 /*@unchecked@*/ /*@only@*/ /*@null@*/
00469 rpmioPool _dbiPool;
00470 
00471 static dbiIndex dbiGetPool(rpmioPool pool)
00472 {
00473     dbiIndex dbi;
00474 
00475     if (_dbiPool == NULL) {
00476         _dbiPool = rpmioNewPool("dbi", sizeof(*dbi), -1, _dbi_debug,
00477                         NULL, NULL, dbiFini);
00478         pool = _dbiPool;
00479     }
00480     return (dbiIndex) rpmioGetPool(pool, sizeof(*dbi));
00481 }
00482 
00483 dbiIndex db3New(rpmdb rpmdb, rpmTag tag)
00484 {
00485     dbiIndex dbi = dbiGetPool(_dbiPool);
00486     char * dbOpts = rpmExpand("%{?_dbi_config_", tagName(tag), "}", NULL);
00487     char *o, *oe;
00488     char *p, *pe;
00489 
00490     if (!(dbOpts != NULL && *dbOpts != '\0')) {
00491         dbOpts = _free(dbOpts);
00492         dbOpts = rpmExpand("%{?_dbi_config}", NULL);
00493     }
00494 assert(dbOpts != NULL && *dbOpts != '\0');
00495 
00496     /* Parse the options for the database element(s). */
00497     memset(&db3dbi, 0, sizeof(db3dbi));
00498 /*=========*/
00499     for (o = dbOpts; o && *o; o = oe) {
00500         struct poptOption *opt;
00501         const char * tok;
00502         int argInfo;
00503 
00504         /* Skip leading white space. */
00505         while (*o && xisspace((int)*o))
00506             o++;
00507 
00508         /* Find and terminate next key=value pair. Save next start point. */
00509         for (oe = o; oe && *oe; oe++) {
00510             if (xisspace((int)*oe))
00511                 /*@innerbreak@*/ break;
00512             if (oe[0] == ':' && !(oe[1] == '/' && oe[2] == '/'))
00513                 /*@innerbreak@*/ break;
00514         }
00515         if (oe && *oe)
00516             *oe++ = '\0';
00517         if (*o == '\0')
00518             continue;
00519 
00520         /* Separate key from value, save value start (if any). */
00521         for (pe = o; pe && *pe && *pe != '='; pe++)
00522             {};
00523         p = (pe ? *pe++ = '\0', pe : NULL);
00524 
00525         /* Skip over negation at start of token. */
00526         for (tok = o; *tok == '!'; tok++)
00527             {};
00528 
00529         /* Find key in option table. */
00530         for (opt = rdbOptions; opt->longName != NULL; opt++) {
00531             if (strcmp(tok, opt->longName))
00532                 /*@innercontinue@*/ continue;
00533             /*@innerbreak@*/ break;
00534         }
00535         if (opt->longName == NULL) {
00536             rpmlog(RPMLOG_ERR,
00537                         _("unrecognized db option: \"%s\" ignored.\n"), o);
00538             continue;
00539         }
00540 
00541         /* Toggle the flags for negated tokens, if necessary. */
00542         argInfo = opt->argInfo;
00543         if (argInfo == POPT_BIT_SET && *o == '!' && ((tok - o) % 2))
00544             argInfo = POPT_BIT_CLR;
00545 
00546         /* Save value in template as appropriate. */
00547         switch (argInfo & POPT_ARG_MASK) {
00548 
00549         case POPT_ARG_NONE:
00550             (void) poptSaveInt((int *)opt->arg, argInfo, 1L);
00551             /*@switchbreak@*/ break;
00552         case POPT_ARG_VAL:
00553             (void) poptSaveInt((int *)opt->arg, argInfo, (long)opt->val);
00554             /*@switchbreak@*/ break;
00555         case POPT_ARG_STRING:
00556         {   const char ** t = opt->arg;
00557 /*@-mods@*/
00558             if (t) {
00559 /*@-unqualifiedtrans@*/ /* FIX: opt->arg annotation in popt.h */
00560                 *t = _free(*t);
00561 /*@=unqualifiedtrans@*/
00562                 *t = xstrdup( (p ? p : "") );
00563             }
00564 /*@=mods@*/
00565         }       /*@switchbreak@*/ break;
00566         case POPT_ARG_INT:
00567         case POPT_ARG_LONG:
00568         {   long aLong = strtol(p, &pe, 0);
00569             if (pe) {
00570                 if (!xstrncasecmp(pe, "Mb", 2))
00571                     aLong *= 1024 * 1024;
00572                 else if (!xstrncasecmp(pe, "Kb", 2))
00573                     aLong *= 1024;
00574                 else if (*pe != '\0') {
00575                     rpmlog(RPMLOG_ERR,
00576                                 _("%s has invalid numeric value, skipped\n"),
00577                                 opt->longName);
00578                     continue;
00579                 }
00580             }
00581 
00582             if ((argInfo & POPT_ARG_MASK) == POPT_ARG_LONG) {
00583                 if (aLong == LONG_MIN || aLong == LONG_MAX) {
00584                     rpmlog(RPMLOG_ERR,
00585                                 _("%s has too large or too small long value, skipped\n"),
00586                                 opt->longName);
00587                     continue;
00588                 }
00589                 (void) poptSaveLong((long *)opt->arg, argInfo, aLong);
00590                 /*@switchbreak@*/ break;
00591             } else {
00592                 if (aLong > INT_MAX || aLong < INT_MIN) {
00593                     rpmlog(RPMLOG_ERR,
00594                                 _("%s has too large or too small integer value, skipped\n"),
00595                                 opt->longName);
00596                     continue;
00597                 }
00598                 (void) poptSaveInt((int *)opt->arg, argInfo, aLong);
00599             }
00600         }   /*@switchbreak@*/ break;
00601         default:
00602             /*@switchbreak@*/ break;
00603         }
00604     }
00605 /*=========*/
00606 
00607     dbOpts = _free(dbOpts);
00608 
00609 /*@-assignexpose@*/
00610     {   void *use =  dbi->_item.use;
00611         void *pool = dbi->_item.pool;
00612 /*@i@*/ *dbi = db3dbi;  /* structure assignment */
00613         dbi->_item.use = use;
00614         dbi->_item.pool = pool;
00615     }
00616 /*@=assignexpose@*/
00617 
00618     memset(&db3dbi, 0, sizeof(db3dbi));
00619 
00620     if (!(dbi->dbi_perms & 0600))
00621         dbi->dbi_perms = 0644;
00622     dbi->dbi_mode = rpmdb->db_mode;
00623     /*@-assignexpose -newreftrans@*/ /* FIX: figger rpmdb/dbi refcounts */
00624 /*@i@*/ dbi->dbi_rpmdb = rpmdb;
00625     /*@=assignexpose =newreftrans@*/
00626     dbi->dbi_rpmtag = tag;
00627     
00628 /*@-sizeoftype@*/
00629     dbi->dbi_jlen = 1 * sizeof(rpmuint32_t);
00630 /*@=sizeoftype@*/
00631 
00632 #if defined(WITH_DB)
00633     dbi->dbi_use_dbenv = 1;     /* dbenv is always used now. */
00634     dbi->dbi_eflags |= (DB_INIT_MPOOL|DB_JOINENV);
00635 #endif
00636 
00637     /*@-globstate@*/ /* FIX: *(rdbOptions->arg) reachable */
00638     return (dbiIndex)rpmioLinkPoolItem((rpmioItem)dbi, __FUNCTION__, __FILE__, __LINE__);
00639     /*@=globstate@*/
00640 }
00641 
00642 const char * prDbiOpenFlags(int dbflags, int print_dbenv_flags)
00643 {
00644     static char buf[256];
00645     struct poptOption *opt;
00646     char * oe;
00647 
00648     oe = buf;
00649     *oe = '\0';
00650     for (opt = rdbOptions; opt->longName != NULL; opt++) {
00651         if (opt->argInfo != POPT_BIT_SET)
00652             continue;
00653         if (print_dbenv_flags) {
00654             if (!(opt->arg == &db3dbi.dbi_oeflags ||
00655                   opt->arg == &db3dbi.dbi_eflags))
00656                 continue;
00657         } else {
00658             if (!(opt->arg == &db3dbi.dbi_oeflags ||
00659                   opt->arg == &db3dbi.dbi_oflags))
00660                 continue;
00661         }
00662         if ((dbflags & opt->val) != opt->val)
00663             continue;
00664         if (oe != buf)
00665             *oe++ = ':';
00666         oe = stpcpy(oe, opt->longName);
00667         dbflags &= ~opt->val;
00668     }
00669     if (dbflags) {
00670         if (oe != buf)
00671             *oe++ = ':';
00672             sprintf(oe, "0x%x", (unsigned)dbflags);
00673     }
00674     return buf;
00675 }
00676 
00677 #endif