00001 #ifndef H_RPMDB
00002 #define H_RPMDB
00003
00004
00010 #include <assert.h>
00011 #include "rpmlib.h"
00012 #include "rpmsw.h"
00013 #include "db.h"
00014
00015
00016
00017 extern int _rpmdb_debug;
00018
00019
00020 #ifdef NOTYET
00021
00024 typedef struct rpmdb_s * rpmdb;
00025
00029 typedef struct _rpmdbMatchIterator * rpmdbMatchIterator;
00030 #endif
00031
00035 typedef enum rpmMireMode_e {
00036 RPMMIRE_DEFAULT = 0,
00037 RPMMIRE_STRCMP = 1,
00038 RPMMIRE_REGEX = 2,
00039 RPMMIRE_GLOB = 3
00040 } rpmMireMode;
00041
00044 typedef struct _dbiIndexItem * dbiIndexItem;
00045
00049 typedef struct _dbiIndexSet * dbiIndexSet;
00050
00053 typedef struct _dbiIndex * dbiIndex;
00054
00055
00061 struct _dbiIndexItem {
00062 unsigned int hdrNum;
00063 unsigned int tagNum;
00064 unsigned int fpNum;
00065 };
00066
00070 struct _dbiIndexSet {
00071 struct _dbiIndexItem * recs;
00072 int count;
00073 };
00074
00078 struct _dbiVec {
00079 int dbv_major;
00080 int dbv_minor;
00081 int dbv_patch;
00089 int (*open) (rpmdb rpmdb, rpmTag rpmtag, dbiIndex * dbip)
00090
00091 ;
00092
00099 int (*close) ( dbiIndex dbi, unsigned int flags)
00100
00101 ;
00102
00109 int (*sync) (dbiIndex dbi, unsigned int flags)
00110
00111 ;
00112
00121 int (*associate) (dbiIndex dbi, dbiIndex dbisecondary,
00122 int (*callback) (DB *, const DBT *, const DBT *, DBT *),
00123 unsigned int flags)
00124
00125 ;
00126
00135 int (*join) (dbiIndex dbi, DBC ** curslist, DBC ** dbcp,
00136 unsigned int flags)
00137
00138 ;
00139
00148 int (*copen) (dbiIndex dbi, DB_TXN * txnid,
00149 DBC ** dbcp, unsigned int dbiflags)
00150
00151 ;
00152
00160 int (*cclose) (dbiIndex dbi, DBC * dbcursor, unsigned int flags)
00161
00162 ;
00163
00172 int (*cdup) (dbiIndex dbi, DBC * dbcursor, DBC ** dbcp,
00173 unsigned int flags)
00174
00175 ;
00176
00186 int (*cdel) (dbiIndex dbi, DBC * dbcursor, DBT * key, DBT * data,
00187 unsigned int flags)
00188
00189 ;
00190
00200 int (*cget) (dbiIndex dbi, DBC * dbcursor, DBT * key, DBT * data,
00201 unsigned int flags)
00202
00203 ;
00204
00215 int (*cpget) (dbiIndex dbi, DBC * dbcursor,
00216 DBT * key, DBT * pkey, DBT * data, unsigned int flags)
00217
00218 ;
00219
00229 int (*cput) (dbiIndex dbi, DBC * dbcursor, DBT * key, DBT * data,
00230 unsigned int flags)
00231
00232 ;
00233
00242 int (*ccount) (dbiIndex dbi, DBC * dbcursor,
00243 unsigned int * countp,
00244 unsigned int flags)
00245
00246 ;
00247
00253 int (*byteswapped) (dbiIndex dbi)
00254
00255 ;
00256
00263 int (*stat) (dbiIndex dbi, unsigned int flags)
00264
00265 ;
00266 };
00267
00271 struct _dbiIndex {
00272
00273 const char * dbi_root;
00274
00275 const char * dbi_home;
00276
00277 const char * dbi_file;
00278
00279 const char * dbi_subfile;
00280
00281 const char * dbi_tmpdir;
00283 int dbi_ecflags;
00284 int dbi_cflags;
00285 int dbi_oeflags;
00286 int dbi_eflags;
00287 int dbi_oflags;
00288 int dbi_tflags;
00290 int dbi_type;
00291 unsigned dbi_mode;
00292 int dbi_perms;
00293 long dbi_shmkey;
00294 int dbi_api;
00296 int dbi_verify_on_close;
00297 int dbi_use_dbenv;
00298 int dbi_permit_dups;
00299 int dbi_no_fsync;
00300 int dbi_no_dbsync;
00301 int dbi_lockdbfd;
00302 int dbi_temporary;
00303 int dbi_debug;
00304 int dbi_byteswapped;
00305
00306
00307 char * dbi_host;
00308 unsigned long dbi_cl_timeout;
00309 unsigned long dbi_sv_timeout;
00310
00311
00312 int dbi_lorder;
00313
00314
00315 void (*db_errcall) (void * dbenv, const char *db_errpfx, char *buffer)
00316
00317 ;
00318
00319 FILE * dbi_errfile;
00320 const char * dbi_errpfx;
00321 int dbi_verbose;
00322 int dbi_region_init;
00323 int dbi_tas_spins;
00324
00325 int dbi_mmapsize;
00326 int dbi_cachesize;
00327
00328 unsigned int dbi_lk_max;
00329 unsigned int dbi_lk_detect;
00330 int dbi_lk_nmodes;
00331 unsigned char * dbi_lk_conflicts;
00332
00333 unsigned int dbi_lg_max;
00334 unsigned int dbi_lg_bsize;
00335
00336 unsigned int dbi_tx_max;
00337 #if 0
00338 int (*dbi_tx_recover) (DB_ENV *dbenv, DBT *log_rec,
00339 DB_LSN *lsnp, int redo, void *info)
00340
00341 ;
00342 #endif
00343
00344 int dbi_pagesize;
00345
00346 void * (*dbi_malloc) (size_t nbytes)
00347 ;
00348
00349 unsigned int dbi_h_ffactor;
00350 unsigned int (*dbi_h_hash_fcn) (DB *, const void *bytes,
00351 unsigned int length)
00352 ;
00353 unsigned int dbi_h_nelem;
00354 unsigned int dbi_h_flags;
00355 int (*dbi_h_dup_compare_fcn) (DB *, const DBT *, const DBT *)
00356 ;
00357
00358 int dbi_bt_flags;
00359 int dbi_bt_minkey;
00360 int (*dbi_bt_compare_fcn) (DB *, const DBT *, const DBT *)
00361 ;
00362 int (*dbi_bt_dup_compare_fcn) (DB *, const DBT *, const DBT *)
00363 ;
00364 size_t (*dbi_bt_prefix_fcn) (DB *, const DBT *, const DBT *)
00365 ;
00366
00367 int dbi_re_flags;
00368 int dbi_re_delim;
00369 unsigned int dbi_re_len;
00370 int dbi_re_pad;
00371 const char * dbi_re_source;
00372
00373 unsigned int dbi_q_extentsize;
00374
00375
00376 rpmdb dbi_rpmdb;
00377 rpmTag dbi_rpmtag;
00378 int dbi_jlen;
00380
00381 DB * dbi_db;
00382
00383 DB_TXN * dbi_txnid;
00384
00385 void * dbi_stats;
00387
00388 const struct _dbiVec * dbi_vec;
00390 };
00391
00395 struct rpmdb_s {
00396
00397 const char * db_root;
00398
00399 const char * db_home;
00400 int db_flags;
00401 int db_mode;
00402 int db_perms;
00403 int db_api;
00404
00405 const char * db_errpfx;
00406 int db_remove_env;
00407 int db_filter_dups;
00408 int db_chrootDone;
00409 void (*db_errcall) (const char *db_errpfx, char *buffer)
00410 ;
00411
00412 FILE * db_errfile;
00413
00414 void * (*db_malloc) (size_t nbytes)
00415 ;
00416
00417 void * (*db_realloc) ( void * ptr,
00418 size_t nbytes)
00419 ;
00420 void (*db_free) ( void * ptr)
00421 ;
00422
00423 unsigned char * db_bits;
00424 int db_nbits;
00425 rpmdb db_next;
00426 int db_opens;
00427
00428 void * db_dbenv;
00429 int db_ndbi;
00430 dbiIndex * _dbi;
00432 struct rpmop_s db_getops;
00433 struct rpmop_s db_putops;
00434 struct rpmop_s db_delops;
00435
00436
00437 int nrefs;
00438 };
00439
00440
00441
00444 enum rpmdbFlags {
00445 RPMDB_FLAG_JUSTCHECK = (1 << 0),
00446 RPMDB_FLAG_MINIMAL = (1 << 1),
00447
00448 RPMDB_FLAG_CHROOT = (1 << 2)
00449
00450 };
00451
00452 #ifdef __cplusplus
00453 extern "C" {
00454 #endif
00455
00456
00463
00464 dbiIndex db3New(rpmdb rpmdb, rpmTag rpmtag)
00465
00466 ;
00467
00473
00474 dbiIndex db3Free( dbiIndex dbi)
00475 ;
00476
00483
00484
00485 extern const char *const prDbiOpenFlags(int dbflags, int print_dbenv_flags)
00486 ;
00487
00488
00496 dbiIndex dbiOpen( rpmdb db, rpmTag rpmtag,
00497 unsigned int flags)
00498
00499 ;
00500
00501
00510 static inline
00511 int dbiCopen(dbiIndex dbi, DB_TXN * txnid,
00512 DBC ** dbcp, unsigned int flags)
00513
00514
00515 {
00516 return (*dbi->dbi_vec->copen) (dbi, txnid, dbcp, flags);
00517 }
00518
00526 static inline
00527 int dbiCclose(dbiIndex dbi, DBC * dbcursor, unsigned int flags)
00528
00529
00530 {
00531 return (*dbi->dbi_vec->cclose) (dbi, dbcursor, flags);
00532 }
00533
00542 static inline
00543 int dbiCdup(dbiIndex dbi, DBC * dbcursor, DBC ** dbcp,
00544 unsigned int flags)
00545
00546 {
00547 return (*dbi->dbi_vec->cdup) (dbi, dbcursor, dbcp, flags);
00548 }
00549
00559 static inline
00560 int dbiDel(dbiIndex dbi, DBC * dbcursor, DBT * key, DBT * data,
00561 unsigned int flags)
00562
00563
00564 {
00565 int rc;
00566 assert(key->data != NULL && key->size > 0);
00567 (void) rpmswEnter(&dbi->dbi_rpmdb->db_delops, 0);
00568 rc = (dbi->dbi_vec->cdel) (dbi, dbcursor, key, data, flags);
00569 (void) rpmswExit(&dbi->dbi_rpmdb->db_delops, data->size);
00570 return rc;
00571 }
00572
00582 static inline
00583 int dbiGet(dbiIndex dbi, DBC * dbcursor, DBT * key, DBT * data,
00584 unsigned int flags)
00585
00586
00587 {
00588 int rc;
00589 assert((flags == DB_NEXT) || (key->data != NULL && key->size > 0));
00590 (void) rpmswEnter(&dbi->dbi_rpmdb->db_getops, 0);
00591 rc = (dbi->dbi_vec->cget) (dbi, dbcursor, key, data, flags);
00592 (void) rpmswExit(&dbi->dbi_rpmdb->db_getops, data->size);
00593 return rc;
00594 }
00595
00606 static inline
00607 int dbiPget(dbiIndex dbi, DBC * dbcursor,
00608 DBT * key, DBT * pkey, DBT * data, unsigned int flags)
00609
00610
00611 {
00612 int rc;
00613 assert((flags == DB_NEXT) || (key->data != NULL && key->size > 0));
00614 (void) rpmswEnter(&dbi->dbi_rpmdb->db_getops, 0);
00615 rc = (dbi->dbi_vec->cpget) (dbi, dbcursor, key, pkey, data, flags);
00616 (void) rpmswExit(&dbi->dbi_rpmdb->db_getops, data->size);
00617 return rc;
00618 }
00619
00629 static inline
00630 int dbiPut(dbiIndex dbi, DBC * dbcursor, DBT * key, DBT * data,
00631 unsigned int flags)
00632
00633
00634 {
00635 int rc;
00636 assert(key->data != NULL && key->size > 0 && data->data != NULL && data->size > 0);
00637 (void) rpmswEnter(&dbi->dbi_rpmdb->db_putops, 0);
00638 rc = (dbi->dbi_vec->cput) (dbi, dbcursor, key, data, flags);
00639 (void) rpmswExit(&dbi->dbi_rpmdb->db_putops, data->size);
00640 return rc;
00641 }
00642
00651 static inline
00652 int dbiCount(dbiIndex dbi, DBC * dbcursor, unsigned int * countp,
00653 unsigned int flags)
00654
00655
00656 {
00657 return (*dbi->dbi_vec->ccount) (dbi, dbcursor, countp, flags);
00658 }
00659
00666 static inline
00667 int dbiVerify( dbiIndex dbi, unsigned int flags)
00668
00669
00670 {
00671 dbi->dbi_verify_on_close = 1;
00672 return (*dbi->dbi_vec->close) (dbi, flags);
00673 }
00674
00681 static inline
00682 int dbiClose( dbiIndex dbi, unsigned int flags)
00683
00684
00685 {
00686 return (*dbi->dbi_vec->close) (dbi, flags);
00687 }
00688
00695 static inline
00696 int dbiSync (dbiIndex dbi, unsigned int flags)
00697
00698
00699 {
00700 return (*dbi->dbi_vec->sync) (dbi, flags);
00701 }
00702
00711 static inline
00712 int dbiAssociate(dbiIndex dbi, dbiIndex dbisecondary,
00713 int (*callback) (DB *, const DBT *, const DBT *, DBT *),
00714 unsigned int flags)
00715
00716
00717 {
00718 return (*dbi->dbi_vec->associate) (dbi, dbisecondary, callback, flags);
00719 }
00720
00729 static inline
00730 int dbiJoin(dbiIndex dbi, DBC ** curslist, DBC ** dbcp,
00731 unsigned int flags)
00732
00733
00734 {
00735 return (*dbi->dbi_vec->join) (dbi, curslist, dbcp, flags);
00736 }
00737
00743 static inline
00744 int dbiByteSwapped(dbiIndex dbi)
00745
00746 {
00747 if (dbi->dbi_byteswapped == -1)
00748 dbi->dbi_byteswapped = (*dbi->dbi_vec->byteswapped) (dbi);
00749 return dbi->dbi_byteswapped;
00750 }
00757 static inline
00758 int dbiStat(dbiIndex dbi, unsigned int flags)
00759
00760 {
00761 return (*dbi->dbi_vec->stat) (dbi, flags);
00762 }
00763
00764
00765
00766
00769 unsigned int rpmdbGetIteratorFileNum(rpmdbMatchIterator mi)
00770 ;
00771
00777 dbiIndexSet dbiFreeIndexSet( dbiIndexSet set)
00778 ;
00779
00785 unsigned int dbiIndexSetCount(dbiIndexSet set)
00786 ;
00787
00794 unsigned int dbiIndexRecordOffset(dbiIndexSet set, int recno)
00795 ;
00796
00803 unsigned int dbiIndexRecordFileNumber(dbiIndexSet set, int recno)
00804 ;
00805
00809
00810
00811 extern int * dbiTags;
00812
00813 extern int dbiTagsMax;
00814
00815
00822
00823 rpmdb rpmdbUnlink ( rpmdb db, const char * msg)
00824 ;
00825
00827
00828
00829 rpmdb XrpmdbUnlink ( rpmdb db, const char * msg,
00830 const char * fn, unsigned ln)
00831 ;
00832
00833 #define rpmdbUnlink(_db, _msg) XrpmdbUnlink(_db, _msg, __FILE__, __LINE__)
00834
00841
00842 rpmdb rpmdbLink (rpmdb db, const char * msg)
00843 ;
00844
00846
00847 rpmdb XrpmdbLink (rpmdb db, const char * msg,
00848 const char * fn, unsigned ln)
00849 ;
00850
00851 #define rpmdbLink(_db, _msg) XrpmdbLink(_db, _msg, __FILE__, __LINE__)
00852
00861 int rpmdbOpen ( const char * prefix, rpmdb * dbp,
00862 int mode, int perms)
00863
00864 ;
00865
00872 int rpmdbInit( const char * prefix, int perms)
00873
00874 ;
00875
00881 int rpmdbVerify( const char * prefix)
00882
00883 ;
00884
00891 int rpmdbCloseDBI( rpmdb db, int rpmtag)
00892
00893 ;
00894
00900 int rpmdbClose ( rpmdb db)
00901
00902 ;
00903
00909 int rpmdbSync ( rpmdb db)
00910
00911 ;
00912
00918
00919 int rpmdbOpenAll ( rpmdb db)
00920
00921 ;
00922
00923
00930 int rpmdbCountPackages( rpmdb db, const char * name)
00931
00932 ;
00933
00939 unsigned int rpmdbGetIteratorOffset( rpmdbMatchIterator mi)
00940 ;
00941
00947 int rpmdbGetIteratorCount( rpmdbMatchIterator mi)
00948 ;
00949
00957 int rpmdbAppendIterator( rpmdbMatchIterator mi,
00958 const int * hdrNums, int nHdrNums)
00959 ;
00960
00970 int rpmdbPruneIterator( rpmdbMatchIterator mi,
00971 int * hdrNums, int nHdrNums, int sorted)
00972 ;
00973
00982 int rpmdbSetIteratorRE( rpmdbMatchIterator mi, rpmTag tag,
00983 rpmMireMode mode, const char * pattern)
00984
00985 ;
00986
00994 int rpmdbSetIteratorRewrite( rpmdbMatchIterator mi, int rewrite)
00995 ;
00996
01003 int rpmdbSetIteratorModified( rpmdbMatchIterator mi, int modified)
01004 ;
01005
01013 int rpmdbSetHdrChk( rpmdbMatchIterator mi, rpmts ts,
01014 rpmRC (*hdrchk) (rpmts ts, const void * uh, size_t uc, const char ** msg))
01015 ;
01016
01025
01026 rpmdbMatchIterator rpmdbInitIterator( rpmdb db, rpmTag rpmtag,
01027 const void * keyp, size_t keylen)
01028
01029 ;
01030
01036
01037 Header rpmdbNextIterator( rpmdbMatchIterator mi)
01038
01039 ;
01040
01044
01045 int rpmdbCheckSignals(void)
01046
01047 ;
01048
01057 int rpmdbCheckTerminate(int terminate);
01058
01064
01065 rpmdbMatchIterator rpmdbFreeIterator( rpmdbMatchIterator mi)
01066
01067 ;
01068
01078 int rpmdbAdd( rpmdb db, int iid, Header h, rpmts ts,
01079 rpmRC (*hdrchk) (rpmts ts, const void *uh, size_t uc, const char ** msg))
01080
01081 ;
01082
01092 int rpmdbRemove( rpmdb db, int rid, unsigned int hdrNum,
01093 rpmts ts,
01094 rpmRC (*hdrchk) (rpmts ts, const void *uh, size_t uc, const char ** msg))
01095
01096 ;
01097
01105 int rpmdbRebuild( const char * prefix, rpmts ts,
01106 rpmRC (*hdrchk) (rpmts ts, const void *uh, size_t uc, const char ** msg))
01107
01108 ;
01109
01110 #ifndef __APPLE__
01111
01114
01115 int mergesort(void *base, size_t nmemb, size_t size,
01116 int (*cmp) (const void *, const void *))
01117
01118 ;
01119 #else
01120
01121 #endif
01122
01123 #ifdef __cplusplus
01124 }
01125 #endif
01126
01127
01128 #endif