rpm 5.3.7

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  { "unknown",   0,POPT_ARG_VAL,         &db3dbi.dbi_type, DB_UNKNOWN,
00244         NULL, NULL },
00245 #endif
00246 
00247  { "root",      0,POPT_ARG_STRING,      &db3dbi.dbi_root, 0,
00248         NULL, NULL },
00249  { "home",      0,POPT_ARG_STRING,      &db3dbi.dbi_home, 0,
00250         NULL, NULL },
00251  { "file",      0,POPT_ARG_STRING,      &db3dbi.dbi_file, 0,
00252         NULL, NULL },
00253  { "subfile",   0,POPT_ARG_STRING,      &db3dbi.dbi_subfile, 0,
00254         NULL, NULL },
00255 #if defined(WITH_DB)
00256  { "mode",      0,POPT_ARG_INT,         &db3dbi.dbi_mode, 0,
00257         NULL, NULL },
00258 #endif
00259  { "perms",     0,POPT_ARG_INT,         &db3dbi.dbi_perms, 0,
00260         NULL, NULL },
00261 #if defined(WITH_DB)
00262  { "shmkey",    0,POPT_ARG_LONG,        &db3dbi.dbi_shmkey, 0,
00263         NULL, NULL },
00264 #endif
00265  { "tmpdir",    0,POPT_ARG_STRING,      &db3dbi.dbi_tmpdir, 0,
00266         NULL, NULL },
00267 
00268 #if defined(WITH_DB)
00269  { "host",      0,POPT_ARG_STRING,      &db3dbi.dbi_host, 0,
00270         NULL, NULL },
00271  { "server",    0,POPT_ARG_STRING,      &db3dbi.dbi_host, 0,
00272         NULL, NULL },
00273  { "cl_timeout", 0,POPT_ARG_LONG,       &db3dbi.dbi_cl_timeout, 0,
00274         NULL, NULL },
00275  { "sv_timeout", 0,POPT_ARG_LONG,       &db3dbi.dbi_sv_timeout, 0,
00276         NULL, NULL },
00277 #endif
00278 
00279 #if defined(WITH_DB)
00280  { "usedbenv",  0,POPT_ARG_NONE,        &db3dbi.dbi_use_dbenv, 0,
00281         NULL, NULL },
00282 #endif
00283  { "nofsync",   0,POPT_ARG_NONE,        &db3dbi.dbi_no_fsync, 0,
00284         NULL, NULL },
00285 #if defined(WITH_DB)
00286  { "nodbsync",  0,POPT_ARG_NONE,        &db3dbi.dbi_no_dbsync, 0,
00287         NULL, NULL },
00288  { "lockdbfd",  0,POPT_ARG_NONE,        &db3dbi.dbi_lockdbfd, 0,
00289         NULL, NULL },
00290 #endif
00291  { "primary",   0,POPT_ARG_STRING,      &db3dbi.dbi_primary, 0,
00292         NULL, NULL },
00293  { "foreign",   0,POPT_ARG_STRING,      &db3dbi.dbi_foreign, 0,
00294         NULL, NULL },
00295  { "temporary", 0,POPT_ARG_NONE,        &db3dbi.dbi_temporary, 0,
00296         NULL, NULL },
00297 #if defined(WITH_DB)
00298  { "debug",     0,POPT_ARG_NONE,        &db3dbi.dbi_debug, 0,
00299         NULL, NULL },
00300 #endif
00301 
00302 /* XXX set_alloc */
00303 #if defined(WITH_DB)
00304 /* XXX set_dup_compare */
00305 /* XXX set_encrypt */
00306  { "errpfx",    0,POPT_ARG_STRING,      &db3dbi.dbi_errpfx, 0,
00307         NULL, NULL },
00308 /* XXX set_feedback */
00309  { "lorder",    0,POPT_ARG_INT,         &db3dbi.dbi_lorder, 0,
00310         NULL, NULL },
00311 #endif
00312  { "pagesize",  0,POPT_ARG_INT,         &db3dbi.dbi_pagesize, 0,
00313         NULL, NULL },
00314 
00315 #if defined(WITH_DB)
00316  { "region_init", 0,POPT_ARG_VAL,       &db3dbi.dbi_region_init, 1,
00317         NULL, NULL },
00318 
00319  { "thread_count", 0,POPT_ARG_INT,      &db3dbi.dbi_thread_count, 0,
00320         NULL, NULL },
00321 
00322 #endif
00323 
00324 /* ==== Locking: */
00325 
00326 /* ==== Logging: */
00327 
00328 /* ==== Memory pool: */
00329 /* XXX DB_MPOOLFILE->set_clear_len */
00330 /* XXX DB_MPOOLFILE->set_fileid */
00331 /* XXX DB_MPOOLFILE->set_ftype */
00332 /* XXX DB_MPOOLFILE->set_lsn_offset */
00333 /* XXX DB_MPOOLFILE->set_maxsize */
00334 /* XXX DB_MPOOLFILE->set_pgcookie */
00335 /* XXX DB_MPOOLFILE->set_priority */
00336 
00337 /* ==== Mutexes: */
00338 
00339 /* ==== Replication: */
00340 
00341 /* ==== Sequences: */
00342 #if defined(WITH_DB)
00343  { "seq_id",    0,POPT_ARG_STRING,      &db3dbi.dbi_seq_id, 0,
00344         NULL, NULL },
00345 /* XXX DB_SEQUENCE->set_cachesize */
00346 /* XXX DB_SEQUENCE->get_cachesize */
00347  { "seq_cachesize",     0,POPT_ARG_INT, &db3dbi.dbi_seq_cachesize, 0,
00348         NULL, NULL },
00349 #endif
00350 /* XXX DB_SEQUENCE->set_flags */
00351 /* XXX DB_SEQUENCE->get_flags */
00352 #if defined(WITH_DB) && defined(DB_SEQ_DEC)
00353  { "seq_dec",   0,POPT_BIT_SET,         &db3dbi.dbi_seq_flags, DB_SEQ_DEC,
00354         NULL, NULL },
00355 #endif
00356 #if defined(WITH_DB) && defined(DB_SEQ_INC)
00357  { "seq_inc",   0,POPT_BIT_SET,         &db3dbi.dbi_seq_flags, DB_SEQ_INC,
00358         NULL, NULL },
00359 #endif
00360 #if defined(WITH_DB) && defined(DB_SEQ_WRAP)
00361  { "seq_wrap",  0,POPT_BIT_SET,         &db3dbi.dbi_seq_flags, DB_SEQ_WRAP,
00362         NULL, NULL },
00363 #endif
00364 #if defined(WITH_DB)
00365 /* XXX DB_SEQUENCE->initial_value */
00366  { "seq_initial",       0,POPT_ARG_LONG, &db3dbi.dbi_seq_initial, 0,
00367         NULL, NULL },
00368 /* XXX DB_SEQUENCE->set_range */
00369 /* XXX DB_SEQUENCE->get_range */
00370  { "seq_min",   0,POPT_ARG_LONG,        &db3dbi.dbi_seq_min, 0,
00371         NULL, NULL },
00372  { "seq_max",   0,POPT_ARG_LONG,        &db3dbi.dbi_seq_max, 0,
00373         NULL, NULL },
00374 #endif
00375 
00376 /* ==== Transactions: */
00377 
00378 /* XXX set_append_recno */
00379 /* XXX set_bt_compare */
00380 /* XXX set_bt_dup_compare */
00381 /* XXX set_bt_minkey */
00382 /* XXX set_bt_prefix */
00383 #if defined(WITH_DB) && defined(DB_DUP)
00384  { "bt_dup",    0,POPT_BIT_SET, &db3dbi.dbi_bt_flags, DB_DUP,
00385         NULL, NULL },
00386 #endif
00387 #if defined(WITH_DB) && defined(DB_DUPSORT)
00388  { "bt_dupsort",0,POPT_BIT_SET, &db3dbi.dbi_bt_flags, DB_DUPSORT,
00389         NULL, NULL },
00390 #endif
00391 #if defined(WITH_DB) && defined(DB_RECNUM)
00392  { "bt_recnum", 0,POPT_BIT_SET, &db3dbi.dbi_bt_flags, DB_RECNUM,
00393         NULL, NULL },
00394 #endif
00395 #if defined(WITH_DB) && defined(DB_REVSPLITOFF)
00396  { "bt_revsplitoff", 0,POPT_BIT_SET,    &db3dbi.dbi_bt_flags, DB_REVSPLITOFF,
00397         NULL, NULL },
00398 #endif
00399 
00400 #if defined(WITH_DB) && defined(DB_DUP)
00401  { "h_dup",     0,POPT_BIT_SET, &db3dbi.dbi_h_flags, DB_DUP,
00402         NULL, NULL },
00403 #endif
00404 #if defined(WITH_DB) && defined(DB_DUPSORT)
00405  { "h_dupsort", 0,POPT_BIT_SET, &db3dbi.dbi_h_flags, DB_DUPSORT,
00406         NULL, NULL },
00407 #endif
00408 #if defined(WITH_DB)
00409  { "h_ffactor", 0,POPT_ARG_INT,         &db3dbi.dbi_h_ffactor, 0,
00410         NULL, NULL },
00411  { "h_nelem",   0,POPT_ARG_INT,         &db3dbi.dbi_h_nelem, 0,
00412         NULL, NULL },
00413 #endif
00414 
00415 #if defined(WITH_DB) && defined(DB_RENUMBER)
00416  { "re_renumber", 0,POPT_BIT_SET,       &db3dbi.dbi_re_flags, DB_RENUMBER,
00417         NULL, NULL },
00418 #endif
00419 #if defined(WITH_DB) && defined(DB_SNAPSHOT)
00420  { "re_snapshot",0,POPT_BIT_SET,        &db3dbi.dbi_re_flags, DB_SNAPSHOT,
00421         NULL, NULL },
00422 #endif
00423 #if defined(WITH_DB)
00424  { "re_delim",  0,POPT_ARG_INT,         &db3dbi.dbi_re_delim, 0,
00425         NULL, NULL },
00426  { "re_len",    0,POPT_ARG_INT,         &db3dbi.dbi_re_len, 0,
00427         NULL, NULL },
00428  { "re_pad",    0,POPT_ARG_INT,         &db3dbi.dbi_re_pad, 0,
00429         NULL, NULL },
00430  { "re_source", 0,POPT_ARG_STRING,      &db3dbi.dbi_re_source, 0,
00431         NULL, NULL },
00432 
00433  { "q_extentsize", 0,POPT_ARG_INT,      &db3dbi.dbi_q_extentsize, 0,
00434         NULL, NULL },
00435 #endif
00436 
00437     POPT_TABLEEND
00438 };
00439 /*@=compmempass =immediatetrans =exportlocal =exportheadervar =type@*/
00440 
00441 static void dbiFini(void * _dbi)
00442         /*@*/
00443 {
00444     dbiIndex dbi = _dbi;
00445     if (dbi) {
00446         dbi->dbi_root = _free(dbi->dbi_root);
00447         dbi->dbi_home = _free(dbi->dbi_home);
00448         dbi->dbi_file = _free(dbi->dbi_file);
00449         dbi->dbi_subfile = _free(dbi->dbi_subfile);
00450         dbi->dbi_tmpdir = _free(dbi->dbi_tmpdir);
00451         dbi->dbi_bf = rpmbfFree(dbi->dbi_bf);
00452         dbi->dbi_host = _free(dbi->dbi_host);
00453         dbi->dbi_errpfx = _free(dbi->dbi_errpfx);
00454         dbi->dbi_seq_id = _free(dbi->dbi_seq_id);
00455         dbi->dbi_re_source = _free(dbi->dbi_re_source);
00456         dbi->dbi_primary = _free(dbi->dbi_primary);
00457         dbi->dbi_foreign = _free(dbi->dbi_foreign);
00458         dbi->dbi_stats = _free(dbi->dbi_stats);
00459     }
00460 }
00461 
00462 /*@unchecked@*/ /*@only@*/ /*@null@*/
00463 rpmioPool _dbiPool;
00464 
00465 static dbiIndex dbiGetPool(rpmioPool pool)
00466 {
00467     dbiIndex dbi;
00468 
00469     if (_dbiPool == NULL) {
00470         _dbiPool = rpmioNewPool("dbi", sizeof(*dbi), -1, _dbi_debug,
00471                         NULL, NULL, dbiFini);
00472         pool = _dbiPool;
00473     }
00474     return (dbiIndex) rpmioGetPool(pool, sizeof(*dbi));
00475 }
00476 
00477 dbiIndex db3New(rpmdb rpmdb, rpmTag tag)
00478 {
00479     dbiIndex dbi = dbiGetPool(_dbiPool);
00480     char * dbOpts = rpmExpand("%{?_dbi_config_", tagName(tag), "}", NULL);
00481     char *o, *oe;
00482     char *p, *pe;
00483 
00484     if (!(dbOpts != NULL && *dbOpts != '\0')) {
00485         dbOpts = _free(dbOpts);
00486         dbOpts = rpmExpand("%{?_dbi_config}", NULL);
00487     }
00488 assert(dbOpts != NULL && *dbOpts != '\0');
00489 
00490     /* Parse the options for the database element(s). */
00491     memset(&db3dbi, 0, sizeof(db3dbi));
00492 /*=========*/
00493     for (o = dbOpts; o && *o; o = oe) {
00494         struct poptOption *opt;
00495         const char * tok;
00496         int argInfo;
00497 
00498         /* Skip leading white space. */
00499         while (*o && xisspace((int)*o))
00500             o++;
00501 
00502         /* Find and terminate next key=value pair. Save next start point. */
00503         for (oe = o; oe && *oe; oe++) {
00504             if (xisspace((int)*oe))
00505                 /*@innerbreak@*/ break;
00506             if (oe[0] == ':' && !(oe[1] == '/' && oe[2] == '/'))
00507                 /*@innerbreak@*/ break;
00508         }
00509         if (oe && *oe)
00510             *oe++ = '\0';
00511         if (*o == '\0')
00512             continue;
00513 
00514         /* Separate key from value, save value start (if any). */
00515         for (pe = o; pe && *pe && *pe != '='; pe++)
00516             {};
00517         p = (pe ? *pe++ = '\0', pe : NULL);
00518 
00519         /* Skip over negation at start of token. */
00520         for (tok = o; *tok == '!'; tok++)
00521             {};
00522 
00523         /* Find key in option table. */
00524         for (opt = rdbOptions; opt->longName != NULL; opt++) {
00525             if (strcmp(tok, opt->longName))
00526                 /*@innercontinue@*/ continue;
00527             /*@innerbreak@*/ break;
00528         }
00529         if (opt->longName == NULL) {
00530             rpmlog(RPMLOG_ERR,
00531                         _("unrecognized db option: \"%s\" ignored.\n"), o);
00532             continue;
00533         }
00534 
00535         /* Toggle the flags for negated tokens, if necessary. */
00536         argInfo = opt->argInfo;
00537         if (argInfo == POPT_BIT_SET && *o == '!' && ((tok - o) % 2))
00538             argInfo = POPT_BIT_CLR;
00539 
00540         /* Save value in template as appropriate. */
00541         switch (argInfo & POPT_ARG_MASK) {
00542 
00543         case POPT_ARG_NONE:
00544             (void) poptSaveInt((int *)opt->arg, argInfo, 1L);
00545             /*@switchbreak@*/ break;
00546         case POPT_ARG_VAL:
00547             (void) poptSaveInt((int *)opt->arg, argInfo, (long)opt->val);
00548             /*@switchbreak@*/ break;
00549         case POPT_ARG_STRING:
00550         {   const char ** t = opt->arg;
00551 /*@-mods@*/
00552             if (t) {
00553 /*@-unqualifiedtrans@*/ /* FIX: opt->arg annotation in popt.h */
00554                 *t = _free(*t);
00555 /*@=unqualifiedtrans@*/
00556                 *t = xstrdup( (p ? p : "") );
00557             }
00558 /*@=mods@*/
00559         }       /*@switchbreak@*/ break;
00560         case POPT_ARG_INT:
00561         case POPT_ARG_LONG:
00562         {   long aLong = strtol(p, &pe, 0);
00563             if (pe) {
00564                 if (!xstrncasecmp(pe, "Mb", 2))
00565                     aLong *= 1024 * 1024;
00566                 else if (!xstrncasecmp(pe, "Kb", 2))
00567                     aLong *= 1024;
00568                 else if (*pe != '\0') {
00569                     rpmlog(RPMLOG_ERR,
00570                                 _("%s has invalid numeric value, skipped\n"),
00571                                 opt->longName);
00572                     continue;
00573                 }
00574             }
00575 
00576             if ((argInfo & POPT_ARG_MASK) == POPT_ARG_LONG) {
00577                 if (aLong == LONG_MIN || aLong == LONG_MAX) {
00578                     rpmlog(RPMLOG_ERR,
00579                                 _("%s has too large or too small long value, skipped\n"),
00580                                 opt->longName);
00581                     continue;
00582                 }
00583                 (void) poptSaveLong((long *)opt->arg, argInfo, aLong);
00584                 /*@switchbreak@*/ break;
00585             } else {
00586                 if (aLong > INT_MAX || aLong < INT_MIN) {
00587                     rpmlog(RPMLOG_ERR,
00588                                 _("%s has too large or too small integer value, skipped\n"),
00589                                 opt->longName);
00590                     continue;
00591                 }
00592                 (void) poptSaveInt((int *)opt->arg, argInfo, aLong);
00593             }
00594         }   /*@switchbreak@*/ break;
00595         default:
00596             /*@switchbreak@*/ break;
00597         }
00598     }
00599 /*=========*/
00600 
00601     dbOpts = _free(dbOpts);
00602 
00603 /*@-assignexpose@*/
00604     {   void *use =  dbi->_item.use;
00605         void *pool = dbi->_item.pool;
00606 /*@i@*/ *dbi = db3dbi;  /* structure assignment */
00607         dbi->_item.use = use;
00608         dbi->_item.pool = pool;
00609     }
00610 /*@=assignexpose@*/
00611 
00612     memset(&db3dbi, 0, sizeof(db3dbi));
00613 
00614     if (!(dbi->dbi_perms & 0600))
00615         dbi->dbi_perms = 0644;
00616     dbi->dbi_mode = rpmdb->db_mode;
00617     /*@-assignexpose -newreftrans@*/ /* FIX: figger rpmdb/dbi refcounts */
00618 /*@i@*/ dbi->dbi_rpmdb = rpmdb;
00619     /*@=assignexpose =newreftrans@*/
00620     dbi->dbi_rpmtag = tag;
00621     
00622 /*@-sizeoftype@*/
00623     dbi->dbi_jlen = 1 * sizeof(rpmuint32_t);
00624 /*@=sizeoftype@*/
00625 
00626 #if defined(WITH_DB)
00627     dbi->dbi_use_dbenv = 1;     /* dbenv is always used now. */
00628     dbi->dbi_eflags |= (DB_INIT_MPOOL|DB_JOINENV);
00629 #endif
00630 
00631     /*@-globstate@*/ /* FIX: *(rdbOptions->arg) reachable */
00632     return (dbiIndex)rpmioLinkPoolItem((rpmioItem)dbi, __FUNCTION__, __FILE__, __LINE__);
00633     /*@=globstate@*/
00634 }
00635 
00636 const char * prDbiOpenFlags(int dbflags, int print_dbenv_flags)
00637 {
00638     static char buf[256];
00639     struct poptOption *opt;
00640     char * oe;
00641 
00642     oe = buf;
00643     *oe = '\0';
00644     for (opt = rdbOptions; opt->longName != NULL; opt++) {
00645         if (opt->argInfo != POPT_BIT_SET)
00646             continue;
00647         if (print_dbenv_flags) {
00648             if (!(opt->arg == &db3dbi.dbi_oeflags ||
00649                   opt->arg == &db3dbi.dbi_eflags))
00650                 continue;
00651         } else {
00652             if (!(opt->arg == &db3dbi.dbi_oeflags ||
00653                   opt->arg == &db3dbi.dbi_oflags))
00654                 continue;
00655         }
00656         if ((dbflags & opt->val) != opt->val)
00657             continue;
00658         if (oe != buf)
00659             *oe++ = ':';
00660         oe = stpcpy(oe, opt->longName);
00661         dbflags &= ~opt->val;
00662     }
00663     if (dbflags) {
00664         if (oe != buf)
00665             *oe++ = ':';
00666             sprintf(oe, "0x%x", (unsigned)dbflags);
00667     }
00668     return buf;
00669 }
00670 
00671 #endif