00001
00005 #include "system.h"
00006
00007 #include <rpmlib.h>
00008 #include <rpmmacro.h>
00009
00010 #define _RPMDB_INTERNAL
00011 #include "rpmdb.h"
00012 #include "debug.h"
00013
00014
00015
00016
00017
00018 #if (DB_VERSION_MAJOR == 3) || (DB_VERSION_MAJOR == 4)
00019 #define __USE_DB3 1
00020
00021
00022
00023 struct _dbiIndex db3dbi;
00024
00025
00026
00027 static int dbi_use_cursors;
00028
00029
00030 static int dbi_tear_down;
00031
00032
00035
00036 struct poptOption rdbOptions[] = {
00037
00038 #if defined(DB_CLIENT)
00039 { "client", 0,POPT_BIT_SET, &db3dbi.dbi_ecflags, DB_CLIENT,
00040 NULL, NULL },
00041 #endif
00042 #if defined(DB_RPCCLIENT)
00043 { "client", 0,POPT_BIT_SET, &db3dbi.dbi_ecflags, DB_RPCCLIENT,
00044 NULL, NULL },
00045 { "rpcclient", 0,POPT_BIT_SET, &db3dbi.dbi_ecflags, DB_RPCCLIENT,
00046 NULL, NULL },
00047 #endif
00048
00049 { "xa_create", 0,POPT_BIT_SET, &db3dbi.dbi_cflags, DB_XA_CREATE,
00050 NULL, NULL },
00051
00052
00053 #if defined(DB_AUTO_COMMIT)
00054 { "auto_commit", 0,POPT_BIT_SET, &db3dbi.dbi_oeflags, DB_AUTO_COMMIT,
00055 NULL, NULL },
00056 #endif
00057 { "create", 0,POPT_BIT_SET, &db3dbi.dbi_oeflags, DB_CREATE,
00058 NULL, NULL },
00059 #if defined(DB_MULTIVERSION)
00060 { "multiversion", 0,POPT_BIT_SET, &db3dbi.dbi_oeflags, DB_MULTIVERSION,
00061 NULL, NULL },
00062 #endif
00063 { "nommap", 0,POPT_BIT_SET, &db3dbi.dbi_oeflags, DB_NOMMAP,
00064 NULL, NULL },
00065 { "thread", 0,POPT_BIT_SET, &db3dbi.dbi_oeflags, DB_THREAD,
00066 NULL, NULL },
00067
00068 { "force", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_FORCE,
00069 NULL, NULL },
00070
00071
00072
00073 { "cdb", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_INIT_CDB,
00074 NULL, NULL },
00075 { "lock", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_INIT_LOCK,
00076 NULL, NULL },
00077 { "log", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_INIT_LOG,
00078 NULL, NULL },
00079 { "mpool", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_INIT_MPOOL,
00080 NULL, NULL },
00081 #if defined(DB_INIT_REP)
00082 { "rep", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_INIT_REP,
00083 NULL, NULL },
00084 #endif
00085 { "txn", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_INIT_TXN,
00086 NULL, NULL },
00087
00088 #ifdef DYING
00089 { "joinenv", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_JOINENV,
00090 NULL, NULL },
00091 #endif
00092 { "lockdown", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_LOCKDOWN,
00093 NULL, NULL },
00094 { "private", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_PRIVATE,
00095 NULL, NULL },
00096 { "recover", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_RECOVER,
00097 NULL, NULL },
00098 { "recover_fatal", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_RECOVER_FATAL,
00099 NULL, NULL },
00100 #if defined(DB_REGISTER)
00101 { "register", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_REGISTER,
00102 NULL, NULL },
00103 #endif
00104 { "shared", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_SYSTEM_MEM,
00105 NULL, NULL },
00106 { "txn_nosync", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_TXN_NOSYNC,
00107 NULL, NULL },
00108 { "use_environ_root", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_USE_ENVIRON_ROOT,
00109 NULL, NULL },
00110 { "use_environ", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_USE_ENVIRON,
00111 NULL, NULL },
00112
00113 { "txn_sync", 0,POPT_BIT_SET, &db3dbi.dbi_tflags, DB_TXN_SYNC,
00114 NULL, NULL },
00115 { "txn_nowait",0,POPT_BIT_SET, &db3dbi.dbi_tflags, DB_TXN_NOWAIT,
00116 NULL, NULL },
00117
00118 #if defined(NOTYET)
00119 DB_AUTO_COMMIT
00120 DB_CDB_ALLDB
00121 DB_DIRECT_DB
00122 DB_DIRECT_LOG
00123 DB_DSYNC_DB
00124 DB_DSYNC_LOG
00125 DB_LOG_AUTOREMOVE
00126 DB_LOG_BUFFER_FULL ???
00127 DB_LOG_INMEMORY
00128 DB_NOLOCKING
00129 DB_MULTIVERSION
00130 DB_NOMMAP
00131 DB_NOPANIC
00132 DB_OVERWRITE
00133 DB_PANIC_ENVIRONMENT
00134 DB_REGION_INIT
00135 DB_TIME_NOTGRANTED
00136 DB_TXN_NOSYNC
00137 DB_TXN_SNAPSHOT
00138 DB_WRITE_NOSYNC
00139 DB_YIELDCPU
00140 #endif
00141
00142
00143
00144 #if defined(NOTYET)
00145 DB_CHKSUM
00146 DB_ENCRYPT
00147 DB_TXN_NOT_DURABLE
00148
00149 DB_DUP BTREE HASH
00150 DB_DUPSORT BTREE HASH
00151 DB_RECNUM BTREE
00152 DB_REVSPLITOFF BTREE
00153
00154 DB_INORDER QUEUE
00155 DB_RENUMBER RECNO
00156 DB_SNAPSHOT RECNO
00157 #endif
00158
00159
00160 { "excl", 0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_EXCL,
00161 NULL, NULL },
00162 { "fcntl_locking",0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_FCNTL_LOCKING,
00163 NULL, NULL },
00164 #if defined(DB_NO_AUTO_COMMIT) && defined(NOTYET)
00165 { "noautocommit", 0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_NO_AUTO_COMMIT,
00166 NULL, NULL },
00167 #endif
00168 { "rdonly", 0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_RDONLY,
00169 NULL, NULL },
00170 #if defined(DB_RDWRMASTER) && defined(NOTYET)
00171 { "rdwrmaster", 0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_RDWRMASTER,
00172 NULL, NULL },
00173 #endif
00174 #if defined(NOTYET)
00175 DB_READ_UNCOMITTED
00176 #endif
00177 { "truncate", 0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_TRUNCATE,
00178 NULL, NULL },
00179 #if defined(DB_WRITEOPEN)
00180 { "writeopen", 0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_WRITEOPEN,
00181 NULL, NULL },
00182 #endif
00183
00184 { "btree", 0,POPT_ARG_VAL, &db3dbi.dbi_type, DB_BTREE,
00185 NULL, NULL },
00186 { "hash", 0,POPT_ARG_VAL, &db3dbi.dbi_type, DB_HASH,
00187 NULL, NULL },
00188 { "recno", 0,POPT_ARG_VAL, &db3dbi.dbi_type, DB_RECNO,
00189 NULL, NULL },
00190 { "queue", 0,POPT_ARG_VAL, &db3dbi.dbi_type, DB_QUEUE,
00191 NULL, NULL },
00192 { "unknown", 0,POPT_ARG_VAL, &db3dbi.dbi_type, DB_UNKNOWN,
00193 NULL, NULL },
00194
00195 { "root", 0,POPT_ARG_STRING, &db3dbi.dbi_root, 0,
00196 NULL, NULL },
00197 { "home", 0,POPT_ARG_STRING, &db3dbi.dbi_home, 0,
00198 NULL, NULL },
00199 { "file", 0,POPT_ARG_STRING, &db3dbi.dbi_file, 0,
00200 NULL, NULL },
00201 { "subfile", 0,POPT_ARG_STRING, &db3dbi.dbi_subfile, 0,
00202 NULL, NULL },
00203 { "mode", 0,POPT_ARG_INT, &db3dbi.dbi_mode, 0,
00204 NULL, NULL },
00205 { "perms", 0,POPT_ARG_INT, &db3dbi.dbi_perms, 0,
00206 NULL, NULL },
00207 { "shmkey", 0,POPT_ARG_LONG, &db3dbi.dbi_shmkey, 0,
00208 NULL, NULL },
00209 { "tmpdir", 0,POPT_ARG_STRING, &db3dbi.dbi_tmpdir, 0,
00210 NULL, NULL },
00211
00212 { "host", 0,POPT_ARG_STRING, &db3dbi.dbi_host, 0,
00213 NULL, NULL },
00214 { "server", 0,POPT_ARG_STRING, &db3dbi.dbi_host, 0,
00215 NULL, NULL },
00216 { "cl_timeout", 0,POPT_ARG_LONG, &db3dbi.dbi_cl_timeout, 0,
00217 NULL, NULL },
00218 { "sv_timeout", 0,POPT_ARG_LONG, &db3dbi.dbi_sv_timeout, 0,
00219 NULL, NULL },
00220
00221 { "verify", 0,POPT_ARG_NONE, &db3dbi.dbi_verify_on_close, 0,
00222 NULL, NULL },
00223 { "teardown", 0,POPT_ARG_NONE, &dbi_tear_down, 0,
00224 NULL, NULL },
00225 { "usecursors",0,POPT_ARG_NONE, &dbi_use_cursors, 0,
00226 NULL, NULL },
00227 { "usedbenv", 0,POPT_ARG_NONE, &db3dbi.dbi_use_dbenv, 0,
00228 NULL, NULL },
00229 { "nofsync", 0,POPT_ARG_NONE, &db3dbi.dbi_no_fsync, 0,
00230 NULL, NULL },
00231 { "nodbsync", 0,POPT_ARG_NONE, &db3dbi.dbi_no_dbsync, 0,
00232 NULL, NULL },
00233 { "lockdbfd", 0,POPT_ARG_NONE, &db3dbi.dbi_lockdbfd, 0,
00234 NULL, NULL },
00235 { "temporary", 0,POPT_ARG_NONE, &db3dbi.dbi_temporary, 0,
00236 NULL, NULL },
00237 { "debug", 0,POPT_ARG_NONE, &db3dbi.dbi_debug, 0,
00238 NULL, NULL },
00239
00240
00241 { "cachesize", 0,POPT_ARG_INT, &db3dbi.dbi_cachesize, 0,
00242 NULL, NULL },
00243
00244
00245 { "errpfx", 0,POPT_ARG_STRING, &db3dbi.dbi_errpfx, 0,
00246 NULL, NULL },
00247
00248 { "lorder", 0,POPT_ARG_INT, &db3dbi.dbi_lorder, 0,
00249 NULL, NULL },
00250 { "pagesize", 0,POPT_ARG_INT, &db3dbi.dbi_pagesize, 0,
00251 NULL, NULL },
00252
00253 { "region_init", 0,POPT_ARG_VAL, &db3dbi.dbi_region_init, 1,
00254 NULL, NULL },
00255
00256 { "thread_count", 0,POPT_ARG_INT, &db3dbi.dbi_thread_count, 0,
00257 NULL, NULL },
00258
00259 #if defined(DB_VERB_CHKPOINT)
00260 { "chkpoint", 0,POPT_BIT_SET, &db3dbi.dbi_verbose, DB_VERB_CHKPOINT,
00261 NULL, NULL },
00262 #endif
00263 { "deadlock", 0,POPT_BIT_SET, &db3dbi.dbi_verbose, DB_VERB_DEADLOCK,
00264 NULL, NULL },
00265 { "recovery", 0,POPT_BIT_SET, &db3dbi.dbi_verbose, DB_VERB_RECOVERY,
00266 NULL, NULL },
00267 #if defined(DB_VERB_REGISTER)
00268 { "register", 0,POPT_BIT_SET, &db3dbi.dbi_verbose, DB_VERB_REGISTER,
00269 NULL, NULL },
00270 #endif
00271 #if defined(DB_VERB_REPLICATION)
00272 { "replication", 0,POPT_BIT_SET, &db3dbi.dbi_verbose, DB_VERB_REPLICATION,
00273 NULL, NULL },
00274 #endif
00275 { "waitsfor", 0,POPT_BIT_SET, &db3dbi.dbi_verbose, DB_VERB_WAITSFOR,
00276 NULL, NULL },
00277 { "verbose", 0,POPT_ARG_VAL, &db3dbi.dbi_verbose, -1,
00278 NULL, NULL },
00279
00280
00281
00282
00283
00284 { "lk_default",0,POPT_ARG_VAL, &db3dbi.dbi_lk_detect, DB_LOCK_DEFAULT,
00285 NULL, NULL },
00286 { "lk_expire", 0,POPT_ARG_VAL, &db3dbi.dbi_lk_detect, DB_LOCK_EXPIRE,
00287 NULL, NULL },
00288 #if defined(DB_LOCK_MAXLOCKS)
00289 { "lk_maxlocks", 0,POPT_ARG_VAL, &db3dbi.dbi_lk_detect, DB_LOCK_MAXLOCKS,
00290 NULL, NULL },
00291 #endif
00292 #if defined(DB_LOCK_MAXWRITE)
00293 { "lk_maxwrite", 0,POPT_ARG_VAL, &db3dbi.dbi_lk_detect, DB_LOCK_MAXWRITE,
00294 NULL, NULL },
00295 #endif
00296 #if defined(DB_LOCK_MINLOCKS)
00297 { "lk_minlocks", 0,POPT_ARG_VAL, &db3dbi.dbi_lk_detect, DB_LOCK_MINLOCKS,
00298 NULL, NULL },
00299 #endif
00300 #if defined(DB_LOCK_MINWRITE)
00301 { "lk_minwrite", 0,POPT_ARG_VAL, &db3dbi.dbi_lk_detect, DB_LOCK_MINWRITE,
00302 NULL, NULL },
00303 #endif
00304 { "lk_oldest", 0,POPT_ARG_VAL, &db3dbi.dbi_lk_detect, DB_LOCK_OLDEST,
00305 NULL, NULL },
00306 { "lk_random", 0,POPT_ARG_VAL, &db3dbi.dbi_lk_detect, DB_LOCK_RANDOM,
00307 NULL, NULL },
00308 { "lk_youngest",0, POPT_ARG_VAL, &db3dbi.dbi_lk_detect, DB_LOCK_YOUNGEST,
00309 NULL, NULL },
00310
00311
00312
00313
00314 #if defined(NOTYET)
00315 DB_LOCK_NOWAIT
00316
00317 DB_LOCK_READ
00318 DB_LOCK_WRITE
00319 DB_LOCK_IWRITE
00320 DB_LOCK_IREAD
00321 DB_LOCK_IWR
00322 #endif
00323
00324
00325
00326 { "lk_max_lockers", 0,POPT_ARG_INT, &db3dbi.dbi_lk_max_lockers, 0,
00327 NULL, NULL },
00328
00329
00330 { "lk_max_locks", 0,POPT_ARG_INT, &db3dbi.dbi_lk_max_locks, 0,
00331 NULL, NULL },
00332
00333
00334 { "lk_max_objects", 0,POPT_ARG_INT, &db3dbi.dbi_lk_max_objects, 0,
00335 NULL, NULL },
00336
00337
00338
00339
00340
00341
00342
00343 { "lg_bsize", 0,POPT_ARG_INT, &db3dbi.dbi_lg_bsize, 0,
00344 NULL, NULL },
00345
00346
00347 { "lg_dir", 0,POPT_ARG_STRING, &db3dbi.dbi_lg_dir, 0,
00348 NULL, NULL },
00349
00350
00351 { "lg_filemode", 0,POPT_ARG_INT, &db3dbi.dbi_lg_filemode, 0,
00352 NULL, NULL },
00353
00354
00355 { "lg_max", 0,POPT_ARG_INT, &db3dbi.dbi_lg_max, 0,
00356 NULL, NULL },
00357
00358
00359 { "lg_regionmax", 0,POPT_ARG_INT, &db3dbi.dbi_lg_regionmax, 0,
00360 NULL, NULL },
00361
00362
00363 { "mp_size", 0,POPT_ARG_INT, &db3dbi.dbi_cachesize, 0,
00364 NULL, NULL },
00365
00366
00367 { "mmapsize", 0,POPT_ARG_INT, &db3dbi.dbi_mmapsize, 0,
00368 NULL, NULL },
00369 { "mp_mmapsize", 0,POPT_ARG_INT, &db3dbi.dbi_mmapsize, 0,
00370 NULL, NULL },
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380 #if defined(NOTYET)
00381 DB_MUTEX_PROCESS_ONLY mutex_alloc
00382 DB_MUTEX_SELF_BLOCK mutex_alloc
00383 DB_STAT_CLEAR mutex_stat*
00384 #endif
00385
00386
00387 { "mutex_align", 0,POPT_ARG_INT, &db3dbi.dbi_mutex_align, 0,
00388 NULL, NULL },
00389
00390
00391 { "mutex_increment", 0,POPT_ARG_INT, &db3dbi.dbi_mutex_increment, 0,
00392 NULL, NULL },
00393
00394
00395 { "mutex_max", 0,POPT_ARG_INT, &db3dbi.dbi_mutex_max, 0,
00396 NULL, NULL },
00397
00398
00399 { "mutex_tas_spins", 0,POPT_ARG_INT, &db3dbi.dbi_mutex_tas_spins, 0,
00400 NULL, NULL },
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413 { "seq_cachesize", 0,POPT_ARG_INT, &db3dbi.dbi_seq_cachesize, 0,
00414 NULL, NULL },
00415
00416
00417 #if defined(DB_SEQ_DEC)
00418 { "seq_dec", 0,POPT_BIT_SET, &db3dbi.dbi_seq_flags, DB_SEQ_DEC,
00419 NULL, NULL },
00420 #endif
00421 #if defined(DB_SEQ_INC)
00422 { "seq_inc", 0,POPT_BIT_SET, &db3dbi.dbi_seq_flags, DB_SEQ_INC,
00423 NULL, NULL },
00424 #endif
00425 #if defined(DB_SEQ_WRAP)
00426 { "seq_wrap", 0,POPT_BIT_SET, &db3dbi.dbi_seq_flags, DB_SEQ_WRAP,
00427 NULL, NULL },
00428 #endif
00429
00430
00431 #if defined(NOTYET)
00432 { "seq_min", 0,POPT_ARG_INT, &db3dbi.dbi_seq_min, 0,
00433 NULL, NULL },
00434 { "seq_max", 0,POPT_ARG_INT, &db3dbi.dbi_seq_max, 0,
00435 NULL, NULL },
00436 #endif
00437
00438
00439
00440
00441
00442
00443
00444 { "tx_max", 0,POPT_ARG_INT, &db3dbi.dbi_tx_max, 0,
00445 NULL, NULL },
00446
00447
00448
00449
00450
00451
00452
00453 { "bt_dup", 0,POPT_BIT_SET, &db3dbi.dbi_bt_flags, DB_DUP,
00454 NULL, NULL },
00455 { "bt_dupsort",0,POPT_BIT_SET, &db3dbi.dbi_bt_flags, DB_DUPSORT,
00456 NULL, NULL },
00457 { "bt_recnum", 0,POPT_BIT_SET, &db3dbi.dbi_bt_flags, DB_RECNUM,
00458 NULL, NULL },
00459 { "bt_revsplitoff", 0,POPT_BIT_SET, &db3dbi.dbi_bt_flags, DB_REVSPLITOFF,
00460 NULL, NULL },
00461
00462 { "h_dup", 0,POPT_BIT_SET, &db3dbi.dbi_h_flags, DB_DUP,
00463 NULL, NULL },
00464 { "h_dupsort", 0,POPT_BIT_SET, &db3dbi.dbi_h_flags, DB_DUPSORT,
00465 NULL, NULL },
00466 { "h_ffactor", 0,POPT_ARG_INT, &db3dbi.dbi_h_ffactor, 0,
00467 NULL, NULL },
00468 { "h_nelem", 0,POPT_ARG_INT, &db3dbi.dbi_h_nelem, 0,
00469 NULL, NULL },
00470
00471 { "re_renumber", 0,POPT_BIT_SET, &db3dbi.dbi_re_flags, DB_RENUMBER,
00472 NULL, NULL },
00473 { "re_snapshot",0,POPT_BIT_SET, &db3dbi.dbi_re_flags, DB_SNAPSHOT,
00474 NULL, NULL },
00475 { "re_delim", 0,POPT_ARG_INT, &db3dbi.dbi_re_delim, 0,
00476 NULL, NULL },
00477 { "re_len", 0,POPT_ARG_INT, &db3dbi.dbi_re_len, 0,
00478 NULL, NULL },
00479 { "re_pad", 0,POPT_ARG_INT, &db3dbi.dbi_re_pad, 0,
00480 NULL, NULL },
00481 { "re_source", 0,POPT_ARG_STRING, &db3dbi.dbi_re_source, 0,
00482 NULL, NULL },
00483
00484 { "q_extentsize", 0,POPT_ARG_INT, &db3dbi.dbi_q_extentsize, 0,
00485 NULL, NULL },
00486
00487 POPT_TABLEEND
00488 };
00489
00490
00491 dbiIndex db3Free(dbiIndex dbi)
00492 {
00493 if (dbi) {
00494 dbi->dbi_root = _free(dbi->dbi_root);
00495 dbi->dbi_home = _free(dbi->dbi_home);
00496 dbi->dbi_file = _free(dbi->dbi_file);
00497 dbi->dbi_subfile = _free(dbi->dbi_subfile);
00498 dbi->dbi_tmpdir = _free(dbi->dbi_tmpdir);
00499 dbi->dbi_host = _free(dbi->dbi_host);
00500 dbi->dbi_errpfx = _free(dbi->dbi_errpfx);
00501 dbi->dbi_re_source = _free(dbi->dbi_re_source);
00502 dbi->dbi_stats = _free(dbi->dbi_stats);
00503 dbi = _free(dbi);
00504 }
00505 return dbi;
00506 }
00507
00508
00509 static const char *db3_config_default =
00510 "hash tmpdir=/var/tmp create cdb mpool mp_mmapsize=16Mb mp_size=1Mb perms=0644";
00511
00512
00513 dbiIndex db3New(rpmdb rpmdb, rpmTag rpmtag)
00514 {
00515 dbiIndex dbi = xcalloc(1, sizeof(*dbi));
00516 char dbiTagMacro[128];
00517 char * dbOpts;
00518
00519 sprintf(dbiTagMacro, "%%{_dbi_config_%s}", tagName(rpmtag));
00520 dbOpts = rpmExpand(dbiTagMacro, NULL);
00521 if (!(dbOpts && *dbOpts && *dbOpts != '%')) {
00522 dbOpts = _free(dbOpts);
00523 dbOpts = rpmExpand("%{_dbi_config}", NULL);
00524 if (!(dbOpts && *dbOpts && *dbOpts != '%')) {
00525 dbOpts = rpmExpand(db3_config_default, NULL);
00526 }
00527 }
00528
00529
00530
00531 if (dbOpts && *dbOpts && *dbOpts != '%') {
00532 char *o, *oe;
00533 char *p, *pe;
00534
00535 memset(&db3dbi, 0, sizeof(db3dbi));
00536
00537 for (o = dbOpts; o && *o; o = oe) {
00538 struct poptOption *opt;
00539 const char * tok;
00540 int argInfo;
00541
00542
00543 while (*o && xisspace(*o))
00544 o++;
00545
00546
00547 for (oe = o; oe && *oe; oe++) {
00548 if (xisspace(*oe))
00549 break;
00550 if (oe[0] == ':' && !(oe[1] == '/' && oe[2] == '/'))
00551 break;
00552 }
00553 if (oe && *oe)
00554 *oe++ = '\0';
00555 if (*o == '\0')
00556 continue;
00557
00558
00559 for (pe = o; pe && *pe && *pe != '='; pe++)
00560 {};
00561 p = (pe ? *pe++ = '\0', pe : NULL);
00562
00563
00564 for (tok = o; *tok == '!'; tok++)
00565 {};
00566
00567
00568 for (opt = rdbOptions; opt->longName != NULL; opt++) {
00569 if (strcmp(tok, opt->longName))
00570 continue;
00571 break;
00572 }
00573 if (opt->longName == NULL) {
00574 rpmError(RPMERR_DBCONFIG,
00575 _("unrecognized db option: \"%s\" ignored.\n"), o);
00576 continue;
00577 }
00578
00579
00580 argInfo = opt->argInfo;
00581 if (argInfo == POPT_BIT_SET && *o == '!' && ((tok - o) % 2))
00582 argInfo = POPT_BIT_CLR;
00583
00584
00585 switch (argInfo & POPT_ARG_MASK) {
00586
00587 case POPT_ARG_NONE:
00588 (void) poptSaveInt((int *)opt->arg, argInfo, 1L);
00589 break;
00590 case POPT_ARG_VAL:
00591 (void) poptSaveInt((int *)opt->arg, argInfo, (long)opt->val);
00592 break;
00593 case POPT_ARG_STRING:
00594 { const char ** t = opt->arg;
00595
00596 if (t) {
00597
00598 *t = _free(*t);
00599
00600 *t = xstrdup( (p ? p : "") );
00601 }
00602
00603 } break;
00604
00605 case POPT_ARG_INT:
00606 case POPT_ARG_LONG:
00607 { long aLong = strtol(p, &pe, 0);
00608 if (pe) {
00609 if (!xstrncasecmp(pe, "Mb", 2))
00610 aLong *= 1024 * 1024;
00611 else if (!xstrncasecmp(pe, "Kb", 2))
00612 aLong *= 1024;
00613 else if (*pe != '\0') {
00614 rpmError(RPMERR_DBCONFIG,
00615 _("%s has invalid numeric value, skipped\n"),
00616 opt->longName);
00617 continue;
00618 }
00619 }
00620
00621 if ((argInfo & POPT_ARG_MASK) == POPT_ARG_LONG) {
00622 if (aLong == LONG_MIN || aLong == LONG_MAX) {
00623 rpmError(RPMERR_DBCONFIG,
00624 _("%s has too large or too small long value, skipped\n"),
00625 opt->longName);
00626 continue;
00627 }
00628 (void) poptSaveLong((long *)opt->arg, argInfo, aLong);
00629 break;
00630 } else {
00631 if (aLong > INT_MAX || aLong < INT_MIN) {
00632 rpmError(RPMERR_DBCONFIG,
00633 _("%s has too large or too small integer value, skipped\n"),
00634 opt->longName);
00635 continue;
00636 }
00637 (void) poptSaveInt((int *)opt->arg, argInfo, aLong);
00638 }
00639 } break;
00640 default:
00641 break;
00642 }
00643 }
00644
00645 }
00646
00647
00648 dbOpts = _free(dbOpts);
00649
00650
00651 *dbi = db3dbi;
00652
00653 memset(&db3dbi, 0, sizeof(db3dbi));
00654
00655 if (!(dbi->dbi_perms & 0600))
00656 dbi->dbi_perms = 0644;
00657 dbi->dbi_mode = rpmdb->db_mode;
00658
00659 dbi->dbi_rpmdb = rpmdb;
00660
00661 dbi->dbi_rpmtag = rpmtag;
00662
00663
00664
00665
00666
00667 switch (rpmtag) {
00668 case RPMDBI_PACKAGES:
00669 case RPMDBI_DEPENDS:
00670 dbi->dbi_jlen = 1 * sizeof(int_32);
00671 break;
00672 default:
00673 dbi->dbi_jlen = 2 * sizeof(int_32);
00674 break;
00675 }
00676
00677
00678 dbi->dbi_byteswapped = -1;
00679
00680 if (!dbi->dbi_use_dbenv) {
00681 dbi->dbi_use_dbenv = 1;
00682 dbi->dbi_eflags |= (DB_INIT_MPOOL|DB_JOINENV);
00683 dbi->dbi_mmapsize = 16 * 1024 * 1024;
00684 dbi->dbi_cachesize = 1 * 1024 * 1024;
00685 }
00686
00687 if ((dbi->dbi_bt_flags | dbi->dbi_h_flags) & DB_DUP)
00688 dbi->dbi_permit_dups = 1;
00689
00690
00691 return dbi;
00692
00693 }
00694
00695
00696
00697 const char * prDbiOpenFlags(int dbflags, int print_dbenv_flags)
00698 {
00699 static char buf[256];
00700 struct poptOption *opt;
00701 char * oe;
00702
00703 oe = buf;
00704 *oe = '\0';
00705 for (opt = rdbOptions; opt->longName != NULL; opt++) {
00706 if (opt->argInfo != POPT_BIT_SET)
00707 continue;
00708 if (print_dbenv_flags) {
00709 if (!(opt->arg == &db3dbi.dbi_oeflags ||
00710 opt->arg == &db3dbi.dbi_eflags))
00711 continue;
00712 } else {
00713 if (!(opt->arg == &db3dbi.dbi_oeflags ||
00714 opt->arg == &db3dbi.dbi_oflags))
00715 continue;
00716 }
00717 if ((dbflags & opt->val) != opt->val)
00718 continue;
00719 if (oe != buf)
00720 *oe++ = ':';
00721 oe = stpcpy(oe, opt->longName);
00722 dbflags &= ~opt->val;
00723 }
00724 if (dbflags) {
00725 if (oe != buf)
00726 *oe++ = ':';
00727 sprintf(oe, "0x%x", (unsigned)dbflags);
00728 }
00729 return buf;
00730 }
00731
00732
00733 #endif