apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gst...@apache.org
Subject cvs commit: apr-util/dbm apr_dbm.c apr_dbm_berkeleydb.c apr_dbm_gdbm.c apr_dbm_sdbm.c
Date Tue, 06 Nov 2001 22:23:26 GMT
gstein      01/11/06 14:23:26

  Modified:    dbm      apr_dbm.c apr_dbm_berkeleydb.c apr_dbm_gdbm.c
                        apr_dbm_sdbm.c
  Log:
  * define a default REGISTER_CLEANUP and have gdbm replace it (the only
    user of this option). shift datum_cleanup() to apr_dbm_gdbm.c.
  
  * define SET_FILE() macro so that we can properly handle the berkeley
    configuration; it uses a structure rather than a ptr, so we need
    some extra work to occur (the macro covers the work).
  
  [ the above macros are temporary until full breakout ]
  
  * shift apr_posix_perms2mode() to the end of apr_dbm.c and always
    define the thing.
  
  * add GET_BDB macro to revamp how we access the berkeley stuff (the
    APR_DBM_* macros). also tweak the apr_dbm_fetch() function to
    compensate.
  
  * add vtables and functions for each database, and fill them with
    abort() calls until their code is filled in.
  
  Revision  Changes    Path
  1.30      +20 -40    apr-util/dbm/apr_dbm.c
  
  Index: apr_dbm.c
  ===================================================================
  RCS file: /home/cvs/apr-util/dbm/apr_dbm.c,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- apr_dbm.c	2001/11/06 09:36:33	1.29
  +++ apr_dbm.c	2001/11/06 22:23:26	1.30
  @@ -68,27 +68,16 @@
      to stop "no effect" warnings from GCC. */
   #define NOOP_FUNCTION if (0) ; else
   
  +/* ### define defaults for now; these will go away in a while */
  +#define REGISTER_CLEANUP(dbm, pdatum) NOOP_FUNCTION
  +#define SET_FILE(pdb, f) ((pdb)->file = (f))
  +
   
   #if APU_USE_SDBM
   
   #include "apr_dbm_sdbm.c"
  -
  -#else /* Not using SDBM: */
   
  -/* Most DBM libraries take a POSIX mode for creating files.  Don't trust
  - * the mode_t type, some platforms may not support it, int is safe.
  - */
  -int apr_posix_perms2mode(apr_fileperms_t perm)
  -{
  -    int mode = 0;
  -
  -    mode |= 0700 & (perm >> 2); /* User  is off-by-2 bits */
  -    mode |= 0070 & (perm >> 1); /* Group is off-by-1 bit */
  -    mode |= 0007 & (perm);      /* World maps 1 for 1 */
  -    return mode;
  -}
  -
  -#if APU_USE_GDBM
  +#elif APU_USE_GDBM
   
   #include "apr_dbm_gdbm.c"
   
  @@ -100,29 +89,7 @@
   #error a DBM implementation was not specified
   #endif
   
  -#endif /* Not USE_SDBM */
   
  -
  -#ifdef NEEDS_CLEANUP
  -
  -static apr_status_t datum_cleanup(void *dptr)
  -{
  -    APR_DBM_FREEDPTR(dptr);
  -    return APR_SUCCESS;
  -}
  -
  -#define REGISTER_CLEANUP(dbm, pdatum) \
  -    if ((pdatum)->dptr) \
  -        apr_pool_cleanup_register((dbm)->pool, (pdatum)->dptr, \
  -                             datum_cleanup, apr_pool_cleanup_null); \
  -    else
  -
  -#else /* NEEDS_CLEANUP */
  -
  -#define REGISTER_CLEANUP(dbm, pdatum) NOOP_FUNCTION
  -
  -#endif /* NEEDS_CLEANUP */
  -
   static apr_status_t set_error(apr_dbm_t *dbm, apr_status_t dbm_said)
   {
       apr_status_t rv = APR_SUCCESS;
  @@ -255,7 +222,7 @@
       /* we have an open database... return it */
       *pdb = apr_pcalloc(pool, sizeof(**pdb));
       (*pdb)->pool = pool;
  -    (*pdb)->file = file;
  +    SET_FILE(*pdb, file);
   
       /* ### register a cleanup to close the DBM? */
   
  @@ -336,7 +303,7 @@
   #elif APU_USE_DB
       {
           DBT data;
  -        int dberr = do_fetch(dbm->file.bdb, ckey, data);
  +        int dberr = do_fetch(GET_BDB(dbm->file), ckey, data);
   
           /* DB returns DB_NOTFOUND if it doesn't exist. but we want to say
              that *any* error means it doesn't exist. */
  @@ -421,4 +388,17 @@
   #else
   #error apr_dbm_get_usednames has not been coded for this database type
   #endif
  +}
  +
  +/* Most DBM libraries take a POSIX mode for creating files.  Don't trust
  + * the mode_t type, some platforms may not support it, int is safe.
  + */
  +APU_DECLARE(int) apr_posix_perms2mode(apr_fileperms_t perm)
  +{
  +    int mode = 0;
  +
  +    mode |= 0700 & (perm >> 2); /* User  is off-by-2 bits */
  +    mode |= 0070 & (perm >> 1); /* Group is off-by-1 bit */
  +    mode |= 0007 & (perm);      /* World maps 1 for 1 */
  +    return mode;
   }
  
  
  
  1.2       +106 -8    apr-util/dbm/apr_dbm_berkeleydb.c
  
  Index: apr_dbm_berkeleydb.c
  ===================================================================
  RCS file: /home/cvs/apr-util/dbm/apr_dbm_berkeleydb.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- apr_dbm_berkeleydb.c	2001/11/06 09:36:33	1.1
  +++ apr_dbm_berkeleydb.c	2001/11/06 22:23:26	1.2
  @@ -75,6 +75,11 @@
   #endif
   } real_file_t;
   
  +
  +#undef SET_FILE
  +#define SET_FILE(pdb, f) ((pdb)->file = apr_pmemdup((pdb)->pool, \
  +                                                    &(f), sizeof(f)))
  +
   typedef DBT cvt_datum_t;
   #define CONVERT_DATUM(cvt, pinput) (memset(&(cvt), 0, sizeof(cvt)), \
                                       (cvt).data = (pinput)->dptr, \
  @@ -90,18 +95,20 @@
   #define TXN_ARG NULL,
   #endif
   
  +#define GET_BDB(f)      (((real_file_t *)(f))->bdb)
  +
   #if DB_VER == 1
  -#define APR_DBM_CLOSE(f)	((*(f).bdb->close)((f).bdb))
  +#define APR_DBM_CLOSE(f)	((*GET_BDB(f)->close)(GET_BDB(f)))
   #else
  -#define APR_DBM_CLOSE(f)	((*(f).bdb->close)((f).bdb, 0))
  +#define APR_DBM_CLOSE(f)	((*GET_BDB(f)->close)(GET_BDB(f), 0))
   #endif
   
  -#define do_fetch(f, k, v)       ((*(f)->get)(f, TXN_ARG &(k), &(v), 0))
  -#define APR_DBM_FETCH(f, k, v)	db2s(do_fetch((f).bdb, k, v))
  -#define APR_DBM_STORE(f, k, v)	db2s((*(f).bdb->put)((f).bdb, TXN_ARG &(k), &(v),
0))
  -#define APR_DBM_DELETE(f, k)	db2s((*(f).bdb->del)((f).bdb, TXN_ARG &(k), 0))
  -#define APR_DBM_FIRSTKEY(f, k)  do_firstkey(&(f), &(k))
  -#define APR_DBM_NEXTKEY(f, k, nk) do_nextkey(&(f), &(k), &(nk))
  +#define do_fetch(bdb, k, v)       ((*(bdb)->get)(bdb, TXN_ARG &(k), &(v), 0))
  +#define APR_DBM_FETCH(f, k, v)	db2s(do_fetch(GET_BDB(f), k, v))
  +#define APR_DBM_STORE(f, k, v)	db2s((*GET_BDB(f)->put)(GET_BDB(f), TXN_ARG &(k),
&(v), 0))
  +#define APR_DBM_DELETE(f, k)	db2s((*GET_BDB(f)->del)(GET_BDB(f), TXN_ARG &(k), 0))
  +#define APR_DBM_FIRSTKEY(f, k)  do_firstkey(f, &(k))
  +#define APR_DBM_NEXTKEY(f, k, nk) do_nextkey(f, &(k), &(nk))
   #define APR_DBM_FREEDPTR(dptr)	NOOP_FUNCTION
   
   #if DB_VER == 1
  @@ -181,3 +188,94 @@
   
       return db2s(dberr);
   }
  +
  +/* --------------------------------------------------------------------------
  +**
  +** DEFINE THE VTABLE FUNCTIONS FOR BERKELEY DB
  +*/
  +
  +static apr_status_t vt_db_open(apr_dbm_t **dbm, const char *name,
  +                               apr_int32_t mode, apr_fileperms_t perm,
  +                               apr_pool_t *cntxt)
  +{
  +    abort();
  +    return APR_SUCCESS;
  +}
  +
  +static void vt_db_close(apr_dbm_t *dbm)
  +{
  +    abort();
  +}
  +
  +static apr_status_t vt_db_fetch(apr_dbm_t *dbm, apr_datum_t key,
  +                                apr_datum_t * pvalue)
  +{
  +    abort();
  +    return APR_SUCCESS;
  +}
  +
  +static apr_status_t vt_db_store(apr_dbm_t *dbm, apr_datum_t key,
  +                                apr_datum_t value)
  +{
  +    abort();
  +    return APR_SUCCESS;
  +}
  +
  +static apr_status_t vt_db_del(apr_dbm_t *dbm, apr_datum_t key)
  +{
  +    abort();
  +    return APR_SUCCESS;
  +}
  +
  +static int vt_db_exists(apr_dbm_t *dbm, apr_datum_t key)
  +{
  +    abort();
  +    return 0;
  +}
  +
  +static apr_status_t vt_db_firstkey(apr_dbm_t *dbm, apr_datum_t * pkey)
  +{
  +    abort();
  +    return APR_SUCCESS;
  +}
  +
  +static apr_status_t vt_db_nextkey(apr_dbm_t *dbm, apr_datum_t * pkey)
  +{
  +    abort();
  +    return APR_SUCCESS;
  +}
  +
  +static char * vt_db_geterror(apr_dbm_t *dbm, int *errcode, char *errbuf,
  +                             apr_size_t errbufsize)
  +{
  +    abort();
  +    return NULL;
  +}
  +
  +static void vt_db_freedatum(apr_dbm_t *dbm, apr_datum_t data)
  +{
  +    abort();
  +}
  +
  +static void vt_db_usednames(apr_pool_t *pool, const char *pathname,
  +                            const char **used1, const char **used2)
  +{
  +    abort();
  +}
  +
  +
  +static const apr_dbm_type_t apr_dbm_type_db = {
  +    "db",
  +
  +    vt_db_open,
  +    vt_db_close,
  +    vt_db_fetch,
  +    vt_db_store,
  +    vt_db_del,
  +    vt_db_exists,
  +    vt_db_firstkey,
  +    vt_db_nextkey,
  +    vt_db_geterror,
  +    vt_db_freedatum,
  +    vt_db_usednames
  +};
  
  
  
  1.2       +105 -1    apr-util/dbm/apr_dbm_gdbm.c
  
  Index: apr_dbm_gdbm.c
  ===================================================================
  RCS file: /home/cvs/apr-util/dbm/apr_dbm_gdbm.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- apr_dbm_gdbm.c	2001/11/06 09:36:33	1.1
  +++ apr_dbm_gdbm.c	2001/11/06 22:23:26	1.2
  @@ -73,7 +73,12 @@
   #define APR_DBM_NEXTKEY(f, k, nk) ((nk) = gdbm_nextkey(f, *(k)), APR_SUCCESS)
   #define APR_DBM_FREEDPTR(dptr)	((dptr) ? free(dptr) : 0)
   
  -#define NEEDS_CLEANUP
  +#undef REGISTER_CLEANUP
  +#define REGISTER_CLEANUP(dbm, pdatum) \
  +    if ((pdatum)->dptr) \
  +        apr_pool_cleanup_register((dbm)->pool, (pdatum)->dptr, \
  +                             datum_cleanup, apr_pool_cleanup_null); \
  +    else
   
   #define APR_DBM_DBMODE_RO       GDBM_READER
   #define APR_DBM_DBMODE_RW       GDBM_WRITER
  @@ -90,3 +95,102 @@
   
       return APR_SUCCESS;
   }
  +
  +static apr_status_t datum_cleanup(void *dptr)
  +{
  +    if (dptr)
  +        free(dptr);
  +
  +    return APR_SUCCESS;
  +}
  +
  +/* --------------------------------------------------------------------------
  +**
  +** DEFINE THE VTABLE FUNCTIONS FOR GDBM
  +*/
  +
  +static apr_status_t vt_gdbm_open(apr_dbm_t **dbm, const char *name,
  +                                 apr_int32_t mode, apr_fileperms_t perm,
  +                                 apr_pool_t *cntxt)
  +{
  +    abort();
  +    return APR_SUCCESS;
  +}
  +
  +static void vt_gdbm_close(apr_dbm_t *dbm)
  +{
  +    abort();
  +}
  +
  +static apr_status_t vt_gdbm_fetch(apr_dbm_t *dbm, apr_datum_t key,
  +                                  apr_datum_t * pvalue)
  +{
  +    abort();
  +    return APR_SUCCESS;
  +}
  +
  +static apr_status_t vt_gdbm_store(apr_dbm_t *dbm, apr_datum_t key,
  +                                  apr_datum_t value)
  +{
  +    abort();
  +    return APR_SUCCESS;
  +}
  +
  +static apr_status_t vt_gdbm_del(apr_dbm_t *dbm, apr_datum_t key)
  +{
  +    abort();
  +    return APR_SUCCESS;
  +}
  +
  +static int vt_gdbm_exists(apr_dbm_t *dbm, apr_datum_t key)
  +{
  +    abort();
  +    return 0;
  +}
  +
  +static apr_status_t vt_gdbm_firstkey(apr_dbm_t *dbm, apr_datum_t * pkey)
  +{
  +    abort();
  +    return APR_SUCCESS;
  +}
  +
  +static apr_status_t vt_gdbm_nextkey(apr_dbm_t *dbm, apr_datum_t * pkey)
  +{
  +    abort();
  +    return APR_SUCCESS;
  +}
  +
  +static char * vt_gdbm_geterror(apr_dbm_t *dbm, int *errcode, char *errbuf,
  +                               apr_size_t errbufsize)
  +{
  +    abort();
  +    return NULL;
  +}
  +
  +static void vt_gdbm_freedatum(apr_dbm_t *dbm, apr_datum_t data)
  +{
  +    abort();
  +}
  +
  +static void vt_gdbm_usednames(apr_pool_t *pool, const char *pathname,
  +                              const char **used1, const char **used2)
  +{
  +    abort();
  +}
  +
  +
  +static const apr_dbm_type_t apr_dbm_type_gdbm = {
  +    "gdbm",
  +
  +    vt_gdbm_open,
  +    vt_gdbm_close,
  +    vt_gdbm_fetch,
  +    vt_gdbm_store,
  +    vt_gdbm_del,
  +    vt_gdbm_exists,
  +    vt_gdbm_firstkey,
  +    vt_gdbm_nextkey,
  +    vt_gdbm_geterror,
  +    vt_gdbm_freedatum,
  +    vt_gdbm_usednames
  +};
  
  
  
  1.2       +91 -0     apr-util/dbm/apr_dbm_sdbm.c
  
  Index: apr_dbm_sdbm.c
  ===================================================================
  RCS file: /home/cvs/apr-util/dbm/apr_dbm_sdbm.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- apr_dbm_sdbm.c	2001/11/06 09:36:33	1.1
  +++ apr_dbm_sdbm.c	2001/11/06 22:23:26	1.2
  @@ -77,3 +77,94 @@
   #define APR_DBM_DBMODE_RW       (APR_READ | APR_WRITE)
   #define APR_DBM_DBMODE_RWCREATE (APR_READ | APR_WRITE | APR_CREATE)
   #define APR_DBM_DBMODE_RWTRUNC  (APR_READ | APR_WRITE | APR_CREATE|APR_TRUNCATE)
  +
  +/* --------------------------------------------------------------------------
  +**
  +** DEFINE THE VTABLE FUNCTIONS FOR SDBM
  +*/
  +
  +static apr_status_t vt_sdbm_open(apr_dbm_t **dbm, const char *name,
  +                                 apr_int32_t mode, apr_fileperms_t perm,
  +                                 apr_pool_t *cntxt)
  +{
  +    abort();
  +    return APR_SUCCESS;
  +}
  +
  +static void vt_sdbm_close(apr_dbm_t *dbm)
  +{
  +    abort();
  +}
  +
  +static apr_status_t vt_sdbm_fetch(apr_dbm_t *dbm, apr_datum_t key,
  +                                  apr_datum_t * pvalue)
  +{
  +    abort();
  +    return APR_SUCCESS;
  +}
  +
  +static apr_status_t vt_sdbm_store(apr_dbm_t *dbm, apr_datum_t key,
  +                                  apr_datum_t value)
  +{
  +    abort();
  +    return APR_SUCCESS;
  +}
  +
  +static apr_status_t vt_sdbm_del(apr_dbm_t *dbm, apr_datum_t key)
  +{
  +    abort();
  +    return APR_SUCCESS;
  +}
  +
  +static int vt_sdbm_exists(apr_dbm_t *dbm, apr_datum_t key)
  +{
  +    abort();
  +    return 0;
  +}
  +
  +static apr_status_t vt_sdbm_firstkey(apr_dbm_t *dbm, apr_datum_t * pkey)
  +{
  +    abort();
  +    return APR_SUCCESS;
  +}
  +
  +static apr_status_t vt_sdbm_nextkey(apr_dbm_t *dbm, apr_datum_t * pkey)
  +{
  +    abort();
  +    return APR_SUCCESS;
  +}
  +
  +static char * vt_sdbm_geterror(apr_dbm_t *dbm, int *errcode, char *errbuf,
  +                               apr_size_t errbufsize)
  +{
  +    abort();
  +    return NULL;
  +}
  +
  +static void vt_sdbm_freedatum(apr_dbm_t *dbm, apr_datum_t data)
  +{
  +    abort();
  +}
  +
  +static void vt_sdbm_usednames(apr_pool_t *pool, const char *pathname,
  +                              const char **used1, const char **used2)
  +{
  +    abort();
  +}
  +
  +
  +static const apr_dbm_type_t apr_dbm_type_sdbm = {
  +    "sdbm",
  +
  +    vt_sdbm_open,
  +    vt_sdbm_close,
  +    vt_sdbm_fetch,
  +    vt_sdbm_store,
  +    vt_sdbm_del,
  +    vt_sdbm_exists,
  +    vt_sdbm_firstkey,
  +    vt_sdbm_nextkey,
  +    vt_sdbm_geterror,
  +    vt_sdbm_freedatum,
  +    vt_sdbm_usednames
  +};
  
  
  

Mime
View raw message