13 #define _RPMDB_INTERNAL
24 #if defined(WITH_DB) || defined(WITH_SQLITE)
28 struct _dbiIndex db3dbi;
35 struct poptOption rdbOptions[] = {
37 #if defined(WITH_DB) && defined(DB_CLIENT)
38 {
"client", 0,POPT_BIT_SET, &db3dbi.dbi_ecflags, DB_CLIENT,
41 #if defined(WITH_DB) && defined(DB_RPCCLIENT)
42 {
"client", 0,POPT_BIT_SET, &db3dbi.dbi_ecflags, DB_RPCCLIENT,
44 {
"rpcclient", 0,POPT_BIT_SET, &db3dbi.dbi_ecflags, DB_RPCCLIENT,
49 #if defined(DB_CREATE)
50 {
"create", 0,POPT_BIT_SET, &db3dbi.dbi_oeflags,
DB_CREATE,
53 #if defined(DB_THREAD)
54 {
"thread", 0,POPT_BIT_SET, &db3dbi.dbi_oeflags,
DB_THREAD,
57 #if defined(WITH_DB) && defined(DB_MULTIVERSION)
58 {
"multiversion", 0,POPT_BIT_SET, &db3dbi.dbi_oeflags, DB_MULTIVERSION,
61 #if defined(WITH_DB) && defined(DB_NOMMAP)
62 {
"nommap", 0,POPT_BIT_SET, &db3dbi.dbi_oeflags, DB_NOMMAP,
66 #if defined(WITH_DB) && defined(DB_FORCE)
67 {
"force", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_FORCE,
73 #if defined(WITH_DB) && defined(DB_INIT_CDB)
74 {
"cdb", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_INIT_CDB,
77 #if defined(DB_INIT_LOCK)
78 {
"lock", 0,POPT_BIT_SET, &db3dbi.dbi_eflags,
DB_INIT_LOCK,
81 #if defined(DB_INIT_LOG)
82 {
"log", 0,POPT_BIT_SET, &db3dbi.dbi_eflags,
DB_INIT_LOG,
85 #if defined(DB_INIT_MPOOL)
89 #if defined(WITH_DB) && defined(DB_INIT_REP)
90 {
"rep", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_INIT_REP,
93 #if defined(DB_INIT_TXN)
94 {
"txn", 0,POPT_BIT_SET, &db3dbi.dbi_eflags,
DB_INIT_TXN,
99 {
"joinenv", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_JOINENV,
102 #if defined(WITH_DB) && defined(DB_LOCKDOWN)
103 {
"lockdown", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_LOCKDOWN,
106 #if (defined(WITH_DB) || defined(WITH_SQLITE)) && defined(DB_PRIVATE)
107 {
"private", 0,POPT_BIT_SET, &db3dbi.dbi_eflags,
DB_PRIVATE,
110 #if defined(WITH_DB) && defined(DB_RECOVER)
111 {
"recover", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_RECOVER,
114 #if defined(WITH_DB) && defined(DB_RECOVER_FATAL)
115 {
"recover_fatal", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_RECOVER_FATAL,
118 #if defined(WITH_DB) && defined(DB_REGISTER)
119 {
"register", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_REGISTER,
122 #if defined(WITH_DB) && defined(DB_SYSTEM_MEM)
123 {
"shared", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_SYSTEM_MEM,
126 #if defined(WITH_DB) && defined(DB_TXN_NOSYNC)
127 {
"txn_nosync", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_TXN_NOSYNC,
130 #if defined(WITH_DB) && defined(DB_USE_ENVIRON_ROOT)
131 {
"use_environ_root", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_USE_ENVIRON_ROOT,
134 #if defined(WITH_DB) && defined(DB_USE_ENVIRON)
135 {
"use_environ", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_USE_ENVIRON,
138 #if defined(WITH_DB) && defined(DB_IGNORE_LEASE)
139 {
"ignore_lease", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_IGNORE_LEASE,
143 #if defined(WITH_DB) && defined(DB_TXN_SYNC)
144 {
"txn_sync", 0,POPT_BIT_SET, &db3dbi.dbi_tflags, DB_TXN_SYNC,
147 #if defined(WITH_DB) && defined(DB_TXN_NOWAIT)
148 {
"txn_nowait",0,POPT_BIT_SET, &db3dbi.dbi_tflags, DB_TXN_NOWAIT,
151 #if defined(WITH_DB) && defined(DB_TXN_WAIT)
152 {
"txn_wait",0,POPT_BIT_SET, &db3dbi.dbi_tflags, DB_TXN_WAIT,
156 #if defined(WITH_DB) && defined(NOTYET)
182 #if defined(WITH_DB) && defined(NOTYET)
198 #if defined(WITH_DB) && defined(DB_RDONLY)
199 {
"rdonly", 0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_RDONLY,
202 #if (defined(WITH_DB) || defined(WITH_SQLITE)) && defined(DB_EXCL)
203 {
"excl", 0,POPT_BIT_SET, &db3dbi.dbi_oflags,
DB_EXCL,
206 #if defined(WITH_DB) && defined(DB_TRUNCATE)
207 {
"truncate", 0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_TRUNCATE,
210 #if defined(WITH_DB) && defined(DB_FCNTL_LOCKING)
211 {
"fcntl_locking",0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_FCNTL_LOCKING,
214 #if defined(DB_AUTO_COMMIT)
215 {
"auto_commit", 0,POPT_BIT_SET, &db3dbi.dbi_oflags,
DB_AUTO_COMMIT,
218 #if defined(WITH_DB) && defined(DB_NO_AUTO_COMMIT) && defined(NOTYET)
219 {
"noautocommit", 0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_NO_AUTO_COMMIT,
222 #if defined(WITH_DB) && defined(DB_RDWRMASTER) && defined(NOTYET)
223 {
"rdwrmaster", 0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_RDWRMASTER,
226 #if defined(WITH_DB) && defined(NOTYET)
229 #if defined(WITH_DB) && defined(DB_WRITEOPEN)
230 {
"writeopen", 0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_WRITEOPEN,
234 {
"btree", 0,POPT_ARG_VAL, &db3dbi.dbi_type,
DB_BTREE,
236 {
"hash", 0,POPT_ARG_VAL, &db3dbi.dbi_type,
DB_HASH,
239 {
"recno", 0,POPT_ARG_VAL, &db3dbi.dbi_type,
DB_RECNO,
241 {
"queue", 0,POPT_ARG_VAL, &db3dbi.dbi_type,
DB_QUEUE,
244 {
"heap", 0,POPT_ARG_VAL, &db3dbi.dbi_type,
DB_HEAP,
247 {
"unknown", 0,POPT_ARG_VAL, &db3dbi.dbi_type,
DB_UNKNOWN,
251 {
"root", 0,POPT_ARG_STRING, &db3dbi.dbi_root, 0,
253 {
"home", 0,POPT_ARG_STRING, &db3dbi.dbi_home, 0,
255 {
"file", 0,POPT_ARG_STRING, &db3dbi.dbi_file, 0,
257 {
"subfile", 0,POPT_ARG_STRING, &db3dbi.dbi_subfile, 0,
260 {
"mode", 0,POPT_ARG_INT, &db3dbi.dbi_mode, 0,
263 {
"perms", 0,POPT_ARG_INT, &db3dbi.dbi_perms, 0,
266 {
"shmkey", 0,POPT_ARG_LONG, &db3dbi.dbi_shmkey, 0,
269 {
"tmpdir", 0,POPT_ARG_STRING, &db3dbi.dbi_tmpdir, 0,
273 {
"host", 0,POPT_ARG_STRING, &db3dbi.dbi_host, 0,
275 {
"server", 0,POPT_ARG_STRING, &db3dbi.dbi_host, 0,
277 {
"cl_timeout", 0,POPT_ARG_LONG, &db3dbi.dbi_cl_timeout, 0,
279 {
"sv_timeout", 0,POPT_ARG_LONG, &db3dbi.dbi_sv_timeout, 0,
284 {
"usedbenv", 0,POPT_ARG_NONE, &db3dbi.dbi_use_dbenv, 0,
287 {
"nofsync", 0,POPT_ARG_NONE, &db3dbi.dbi_no_fsync, 0,
290 {
"nodbsync", 0,POPT_ARG_NONE, &db3dbi.dbi_no_dbsync, 0,
292 {
"lockdbfd", 0,POPT_ARG_NONE, &db3dbi.dbi_lockdbfd, 0,
295 {
"primary", 0,POPT_ARG_STRING, &db3dbi.dbi_primary, 0,
297 {
"foreign", 0,POPT_ARG_STRING, &db3dbi.dbi_foreign, 0,
299 {
"temporary", 0,POPT_ARG_NONE, &db3dbi.dbi_temporary, 0,
301 {
"debug", 0,POPT_ARG_NONE, &db3dbi.dbi_debug, 0,
308 {
"errpfx", 0,POPT_ARG_STRING, &db3dbi.dbi_errpfx, 0,
311 {
"lorder", 0,POPT_ARG_INT, &db3dbi.dbi_lorder, 0,
314 {
"pagesize", 0,POPT_ARG_INT, &db3dbi.dbi_pagesize, 0,
316 {
"heapsize", 0,POPT_ARG_INT, &db3dbi.dbi_heapsize, 0,
318 {
"heap_regionsize", 0,POPT_ARG_INT, &db3dbi.dbi_heap_regionsize, 0,
322 {
"region_init", 0,POPT_ARG_VAL, &db3dbi.dbi_region_init, 1,
326 {
"thread_count", 0,POPT_ARG_INT, &db3dbi.dbi_thread_count, 0,
347 {
"seq_id", 0,POPT_ARG_STRING, &db3dbi.dbi_seq_id, 0,
352 {
"seq_cachesize", 0,POPT_ARG_INT, &db3dbi.dbi_seq_cachesize, 0,
357 #if defined(WITH_DB) && defined(DB_SEQ_DEC)
358 {
"seq_dec", 0,POPT_BIT_SET, &db3dbi.dbi_seq_flags, DB_SEQ_DEC,
361 #if defined(WITH_DB) && defined(DB_SEQ_INC)
362 {
"seq_inc", 0,POPT_BIT_SET, &db3dbi.dbi_seq_flags, DB_SEQ_INC,
365 #if defined(WITH_DB) && defined(DB_SEQ_WRAP)
366 {
"seq_wrap", 0,POPT_BIT_SET, &db3dbi.dbi_seq_flags, DB_SEQ_WRAP,
371 {
"seq_initial", 0,POPT_ARG_LONG, &db3dbi.dbi_seq_initial, 0,
375 {
"seq_min", 0,POPT_ARG_LONG, &db3dbi.dbi_seq_min, 0,
377 {
"seq_max", 0,POPT_ARG_LONG, &db3dbi.dbi_seq_max, 0,
389 {
"bt_dup", 0,POPT_BIT_SET, &db3dbi.dbi_bt_flags,
DB_DUP,
392 #if defined(DB_DUPSORT)
393 {
"bt_dupsort",0,POPT_BIT_SET, &db3dbi.dbi_bt_flags,
DB_DUPSORT,
396 #if defined(WITH_DB) && defined(DB_RECNUM)
397 {
"bt_recnum", 0,POPT_BIT_SET, &db3dbi.dbi_bt_flags, DB_RECNUM,
400 #if defined(WITH_DB) && defined(DB_REVSPLITOFF)
401 {
"bt_revsplitoff", 0,POPT_BIT_SET, &db3dbi.dbi_bt_flags, DB_REVSPLITOFF,
406 {
"h_dup", 0,POPT_BIT_SET, &db3dbi.dbi_h_flags,
DB_DUP,
409 #if defined(DB_DUPSORT)
410 {
"h_dupsort", 0,POPT_BIT_SET, &db3dbi.dbi_h_flags,
DB_DUPSORT,
414 {
"h_ffactor", 0,POPT_ARG_INT, &db3dbi.dbi_h_ffactor, 0,
416 {
"h_nelem", 0,POPT_ARG_INT, &db3dbi.dbi_h_nelem, 0,
420 #if defined(WITH_DB) && defined(DB_RENUMBER)
421 {
"re_renumber", 0,POPT_BIT_SET, &db3dbi.dbi_re_flags, DB_RENUMBER,
424 #if defined(WITH_DB) && defined(DB_SNAPSHOT)
425 {
"re_snapshot",0,POPT_BIT_SET, &db3dbi.dbi_re_flags, DB_SNAPSHOT,
429 {
"re_delim", 0,POPT_ARG_INT, &db3dbi.dbi_re_delim, 0,
431 {
"re_len", 0,POPT_ARG_INT, &db3dbi.dbi_re_len, 0,
433 {
"re_pad", 0,POPT_ARG_INT, &db3dbi.dbi_re_pad, 0,
435 {
"re_source", 0,POPT_ARG_STRING, &db3dbi.dbi_re_source, 0,
438 {
"q_extentsize", 0,POPT_ARG_INT, &db3dbi.dbi_q_extentsize, 0,
446 static void dbiFini(
void * _dbi)
451 dbi->dbi_root =
_free(dbi->dbi_root);
452 dbi->dbi_home =
_free(dbi->dbi_home);
453 dbi->dbi_file =
_free(dbi->dbi_file);
454 dbi->dbi_subfile =
_free(dbi->dbi_subfile);
455 dbi->dbi_tmpdir =
_free(dbi->dbi_tmpdir);
457 dbi->dbi_host =
_free(dbi->dbi_host);
458 dbi->dbi_errpfx =
_free(dbi->dbi_errpfx);
459 dbi->dbi_seq_id =
_free(dbi->dbi_seq_id);
460 dbi->dbi_re_source =
_free(dbi->dbi_re_source);
461 dbi->dbi_primary =
_free(dbi->dbi_primary);
462 dbi->dbi_foreign =
_free(dbi->dbi_foreign);
463 dbi->dbi_stats =
_free(dbi->dbi_stats);
474 if (_dbiPool == NULL) {
476 NULL, NULL, dbiFini);
484 dbiIndex dbi = dbiGetPool(_dbiPool);
489 if (!(dbOpts != NULL && *dbOpts !=
'\0')) {
490 dbOpts =
_free(dbOpts);
491 dbOpts =
rpmExpand(
"%{?_dbi_config}", NULL);
493 assert(dbOpts != NULL && *dbOpts !=
'\0');
496 memset(&db3dbi, 0,
sizeof(db3dbi));
498 for (o = dbOpts; o && *o; o = oe) {
499 struct poptOption *opt;
508 for (oe = o; oe && *oe; oe++) {
511 if (oe[0] ==
':' && !(oe[1] ==
'/' && oe[2] ==
'/'))
520 for (pe = o; pe && *pe && *pe !=
'='; pe++)
522 p = (pe ? *pe++ =
'\0', pe : NULL);
525 for (tok = o; *tok ==
'!'; tok++)
529 for (opt = rdbOptions; opt->longName != NULL; opt++) {
530 if (strcmp(tok, opt->longName))
534 if (opt->longName == NULL) {
536 _(
"unrecognized db option: \"%s\" ignored.\n"), o);
541 argInfo = opt->argInfo;
542 if (argInfo == POPT_BIT_SET && *o ==
'!' && ((tok - o) % 2))
543 argInfo = POPT_BIT_CLR;
546 switch (argInfo & POPT_ARG_MASK) {
549 (void) poptSaveInt((
int *)opt->arg, argInfo, 1
L);
552 (void) poptSaveInt((
int *)opt->arg, argInfo, (long)opt->val);
554 case POPT_ARG_STRING:
555 {
const char ** t = (
const char **) opt->arg;
567 {
long aLong = strtol(p, &pe, 0);
570 aLong *= 1024 * 1024;
573 else if (*pe !=
'\0') {
575 _(
"%s has invalid numeric value, skipped\n"),
581 if ((argInfo & POPT_ARG_MASK) == POPT_ARG_LONG) {
582 if (aLong == LONG_MIN || aLong == LONG_MAX) {
584 _(
"%s has too large or too small long value, skipped\n"),
588 (void) poptSaveLong((
long *)opt->arg, argInfo, aLong);
591 if (aLong > INT_MAX || aLong < INT_MIN) {
593 _(
"%s has too large or too small integer value, skipped\n"),
597 (void) poptSaveInt((
int *)opt->arg, argInfo, aLong);
606 dbOpts =
_free(dbOpts);
610 void *pool = dbi->_item.
pool;
612 dbi->_item.use = use;
613 dbi->_item.pool = pool;
617 memset(&db3dbi, 0,
sizeof(db3dbi));
619 if (!(dbi->dbi_perms & 0600))
620 dbi->dbi_perms = 0644;
621 dbi->dbi_mode = rpmdb->db_mode;
623 dbi->dbi_rpmdb =
rpmdb;
625 dbi->dbi_rpmtag = tag;
632 dbi->dbi_use_dbenv = 1;
641 const char * prDbiOpenFlags(
int dbflags,
int print_dbenv_flags)
643 static char buf[256];
644 struct poptOption *opt;
649 for (opt = rdbOptions; opt->longName != NULL; opt++) {
650 if (opt->argInfo != POPT_BIT_SET)
652 if (print_dbenv_flags) {
653 if (!(opt->arg == &db3dbi.dbi_oeflags ||
654 opt->arg == &db3dbi.dbi_eflags))
657 if (!(opt->arg == &db3dbi.dbi_oeflags ||
658 opt->arg == &db3dbi.dbi_oflags))
661 if ((dbflags & opt->val) != opt->val)
665 oe =
stpcpy(oe, opt->longName);
666 dbflags &= ~opt->val;
671 sprintf(oe,
"0x%x", (
unsigned)dbflags);
char * xstrdup(const char *str)
rpmioItem rpmioLinkPoolItem(rpmioItem item, const char *msg, const char *fn, unsigned ln)
Increment a pool item refcount.
int xstrncasecmp(const char *s1, const char *s2, size_t n)
Locale insensitive strncasecmp(3).
static void rpmlog(int code, const char *fmt,...)
Yet Another syslog(3) API clone.
rpmbf rpmbfFree(rpmbf bf)
Destroy a Bloom filter.
rpmioItem rpmioGetPool(rpmioPool pool, size_t size)
Get unused item from pool, or alloc a new item.
static int xisspace(int c)
const char * tagName(rpmTag tag)
Return tag name from value.
struct rpmdb_s * rpmdb
Database of headers and tag value indices.
char * rpmExpand(const char *arg,...)
Return (malloc'ed) concatenated macro expansion(s).
rpmioPool rpmioNewPool(const char *name, size_t size, int limit, int flags, char *(*dbg)(void *item), void(*init)(void *item), void(*fini)(void *item))
Create a memory pool.
char * stpcpy(char *dest, const char *src)
static void * _free(const void *p)
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
Access RPM indices using Berkeley DB interface(s).
struct _dbiIndex * dbiIndex