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/include/private apr_dbm_private.h
Date Tue, 06 Nov 2001 09:36:34 GMT
gstein      01/11/06 01:36:34

  Modified:    dbm      apr_dbm.c
  Added:       dbm      apr_dbm_berkeleydb.c apr_dbm_gdbm.c apr_dbm_sdbm.c
               include/private apr_dbm_private.h
  Log:
  Begin integration of Ian's multiple DBM work. This is different from Ian's
  work (so far) in that:
  
  * first phase only: shifted macros from apr_dbm.c into the other .c files
    and simply #include'd those files (i.e. not using the vtables yet)
  
    NOTE for code review: no changes were made to the macros. This was a pure
    shift only.
  
    apr_dbm_private.h is the only new code (thus, good for review).
  
  * no per-dbm .h files; all entry points will be thru vtables. since we need
    to map names to <something> (to allow for external registration of DBM
    types), then we may as well map to a complete vtable which includes the
    open and used_names entry points.
  
  * similar to buckets, the predefined types are variables specified in
    apr_dbm_private.h for use by the dbm registration code.
  
  * removed a couple entry points from Ian's apr_dbm_type_t (set error and a
    cleanup function)
  
  Next steps: add infrastructure for using the types; revamp the macro stuff
  into real function calls; provide for multiple, available dbm types.
  
  Revision  Changes    Path
  1.29      +3 -193    apr-util/dbm/apr_dbm.c
  
  Index: apr_dbm.c
  ===================================================================
  RCS file: /home/cvs/apr-util/dbm/apr_dbm.c,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- apr_dbm.c	2001/09/27 17:12:07	1.28
  +++ apr_dbm.c	2001/11/06 09:36:33	1.29
  @@ -71,29 +71,8 @@
   
   #if APU_USE_SDBM
   
  -#include "apr_sdbm.h"
  +#include "apr_dbm_sdbm.c"
   
  -typedef apr_sdbm_t *real_file_t;
  -
  -typedef apr_sdbm_datum_t *cvt_datum_t;
  -#define CONVERT_DATUM(cvt, pinput) ((cvt) = (apr_sdbm_datum_t *)(pinput))
  -
  -typedef apr_sdbm_datum_t result_datum_t;
  -#define RETURN_DATUM(poutput, rd) (*(poutput) = *(apr_datum_t *)&(rd))
  -
  -#define APR_DBM_CLOSE(f)	apr_sdbm_close(f)
  -#define APR_DBM_FETCH(f, k, v)	apr_sdbm_fetch(f, &(v), *(k))
  -#define APR_DBM_STORE(f, k, v)	apr_sdbm_store(f, *(k), *(v), APR_SDBM_REPLACE)
  -#define APR_DBM_DELETE(f, k)	apr_sdbm_delete(f, *(k))
  -#define APR_DBM_FIRSTKEY(f, k)	apr_sdbm_firstkey(f, &(k))
  -#define APR_DBM_NEXTKEY(f, k, nk) apr_sdbm_nextkey(f, &(nk))
  -#define APR_DBM_FREEDPTR(dptr)	NOOP_FUNCTION
  -
  -#define APR_DBM_DBMODE_RO       APR_READ
  -#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)
  -
   #else /* Not using SDBM: */
   
   /* Most DBM libraries take a POSIX mode for creating files.  Don't trust
  @@ -110,187 +89,18 @@
   }
   
   #if APU_USE_GDBM
  -
  -#include <gdbm.h>
  -#include <stdlib.h>     /* for free() */
  -
  -typedef GDBM_FILE real_file_t;
   
  -typedef datum *cvt_datum_t;
  -#define CONVERT_DATUM(cvt, pinput) ((cvt) = (datum *)(pinput))
  -
  -typedef datum result_datum_t;
  -#define RETURN_DATUM(poutput, rd) (*(poutput) = *(apr_datum_t *)&(rd))
  -
  -#define APR_DBM_CLOSE(f)	gdbm_close(f)
  -#define APR_DBM_FETCH(f, k, v)	((v) = gdbm_fetch(f, *(k)), APR_SUCCESS)
  -#define APR_DBM_STORE(f, k, v)	g2s(gdbm_store(f, *(k), *(v), GDBM_REPLACE))
  -#define APR_DBM_DELETE(f, k)	g2s(gdbm_delete(f, *(k)))
  -#define APR_DBM_FIRSTKEY(f, k)	((k) = gdbm_firstkey(f), APR_SUCCESS)
  -#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
  -
  -#define APR_DBM_DBMODE_RO       GDBM_READER
  -#define APR_DBM_DBMODE_RW       GDBM_WRITER
  -#define APR_DBM_DBMODE_RWCREATE GDBM_WRCREAT
  -#define APR_DBM_DBMODE_RWTRUNC  GDBM_NEWDB
  -
  -/* map a GDBM error to an apr_status_t */
  -static apr_status_t g2s(int gerr)
  -{
  -    if (gerr == -1) {
  -        /* ### need to fix this */
  -        return APR_EGENERAL;
  -    }
  -
  -    return APR_SUCCESS;
  -}
  +#include "apr_dbm_gdbm.c"
   
   #elif APU_USE_DB
  -/*
  - * We pick up all varieties of Berkeley DB through db.h (included through
  - * apu_select_dbm.h). This code has been compiled/tested against DB1,
  - * DB_185, DB2, and DB3.
  - */
  -
  -#if   defined(DB_VERSION_MAJOR) && (DB_VERSION_MAJOR == 3)
  -#define DB_VER 3
  -#elif defined(DB_VERSION_MAJOR) && (DB_VERSION_MAJOR == 2)
  -#define DB_VER 2
  -#else
  -#define DB_VER 1
  -#endif
  -
  -typedef struct {
  -    DB *bdb;
  -#if DB_VER != 1
  -    DBC *curs;
  -#endif
  -} real_file_t;
  -
  -typedef DBT cvt_datum_t;
  -#define CONVERT_DATUM(cvt, pinput) (memset(&(cvt), 0, sizeof(cvt)), \
  -                                    (cvt).data = (pinput)->dptr, \
  -                                    (cvt).size = (pinput)->dsize)
  -
  -typedef DBT result_datum_t;
  -#define RETURN_DATUM(poutput, rd) ((poutput)->dptr = (rd).data, \
  -                                   (poutput)->dsize = (rd).size)
  -
  -#if DB_VER == 1
  -#define TXN_ARG
  -#else
  -#define TXN_ARG NULL,
  -#endif
  -
  -#if DB_VER == 1
  -#define APR_DBM_CLOSE(f)	((*(f).bdb->close)((f).bdb))
  -#else
  -#define APR_DBM_CLOSE(f)	((*(f).bdb->close)((f).bdb, 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 APR_DBM_FREEDPTR(dptr)	NOOP_FUNCTION
  -
  -#if DB_VER == 1
  -#include <sys/fcntl.h>
  -#define APR_DBM_DBMODE_RO       O_RDONLY
  -#define APR_DBM_DBMODE_RW       O_RDWR
  -#define APR_DBM_DBMODE_RWCREATE (O_CREAT | O_RDWR)
  -#define APR_DBM_DBMODE_RWTRUNC (O_CREAT | O_RDWR|O_TRUNC)
  -#else
  -#define APR_DBM_DBMODE_RO       DB_RDONLY
  -#define APR_DBM_DBMODE_RW       0
  -#define APR_DBM_DBMODE_RWCREATE DB_CREATE
  -#define APR_DBM_DBMODE_RWTRUNC  DB_TRUNCATE
  -#endif /* DBVER == 1 */
   
  -/* map a DB error to an apr_status_t */
  -static apr_status_t db2s(int dberr)
  -{
  -    if (dberr != 0) {
  -        /* ### need to fix this */
  -        return APR_OS_START_USEERR+dberr;
  -    }
  -
  -    return APR_SUCCESS;
  -}
  -
  -/* handle the FIRSTKEY functionality */
  -static apr_status_t do_firstkey(real_file_t *f, DBT *pkey)
  -{
  -    int dberr;
  -    DBT data;
  -
  -    memset(pkey,0,sizeof(DBT));
  -
  -    memset(&data,0,sizeof(DBT));
  -#if DB_VER == 1
  -    dberr = (*f->bdb->seq)(f->bdb, pkey, &data, R_FIRST);
  -#else
  -    if ((dberr = (*f->bdb->cursor)(f->bdb, NULL, &f->curs
  -#if DB_VER == 3
  -                                   , 0
  -#endif
  -                                   )) == 0) {
  -        dberr = (*f->curs->c_get)(f->curs, pkey, &data, DB_FIRST);
  -        if (dberr == DB_NOTFOUND) {
  -            memset(pkey, 0, sizeof(*pkey));
  -            (*f->curs->c_close)(f->curs);
  -            f->curs = NULL;
  -            return APR_SUCCESS;
  -        }
  -    }
  -#endif
  -
  -    return db2s(dberr);
  -}
  -
  -/* handle the NEXTKEY functionality */
  -static apr_status_t do_nextkey(real_file_t *f, DBT *pkey, DBT *pnext)
  -{
  -    int dberr;
  -    DBT data;
  -
  -#if DB_VER == 1
  -    dberr = (*f->bdb->seq)(f->bdb, pkey, &data, R_NEXT);
  -#else
  -    if (f->curs == NULL)
  -        return APR_EINVAL;
  -
  -    dberr = (*f->curs->c_get)(f->curs, pkey, &data, DB_NEXT);
  -    if (dberr == DB_NOTFOUND) {
  -        memset(pkey, 0, sizeof(*pkey));
  -        (*f->curs->c_close)(f->curs);
  -        f->curs = NULL;
  -        return APR_SUCCESS;
  -    }
  -#endif
  +#include "apr_dbm_berkeleydb.c"
   
  -    return db2s(dberr);
  -}
  -
   #else /* Not in the USE_xDBM list above */
   #error a DBM implementation was not specified
   #endif
   
   #endif /* Not USE_SDBM */
  -
  -struct apr_dbm_t
  -{
  -    apr_pool_t *pool;
  -    real_file_t file;
  -
  -    int errcode;
  -    const char *errmsg;
  -};
   
   
   #ifdef NEEDS_CLEANUP
  
  
  
  1.1                  apr-util/dbm/apr_dbm_berkeleydb.c
  
  Index: apr_dbm_berkeleydb.c
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  #include "apr_dbm_private.h"
  
  /*
   * We pick up all varieties of Berkeley DB through db.h (included through
   * apu_select_dbm.h). This code has been compiled/tested against DB1,
   * DB_185, DB2, and DB3.
   */
  
  #if   defined(DB_VERSION_MAJOR) && (DB_VERSION_MAJOR == 3)
  #define DB_VER 3
  #elif defined(DB_VERSION_MAJOR) && (DB_VERSION_MAJOR == 2)
  #define DB_VER 2
  #else
  #define DB_VER 1
  #endif
  
  typedef struct {
      DB *bdb;
  #if DB_VER != 1
      DBC *curs;
  #endif
  } real_file_t;
  
  typedef DBT cvt_datum_t;
  #define CONVERT_DATUM(cvt, pinput) (memset(&(cvt), 0, sizeof(cvt)), \
                                      (cvt).data = (pinput)->dptr, \
                                      (cvt).size = (pinput)->dsize)
  
  typedef DBT result_datum_t;
  #define RETURN_DATUM(poutput, rd) ((poutput)->dptr = (rd).data, \
                                     (poutput)->dsize = (rd).size)
  
  #if DB_VER == 1
  #define TXN_ARG
  #else
  #define TXN_ARG NULL,
  #endif
  
  #if DB_VER == 1
  #define APR_DBM_CLOSE(f)	((*(f).bdb->close)((f).bdb))
  #else
  #define APR_DBM_CLOSE(f)	((*(f).bdb->close)((f).bdb, 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 APR_DBM_FREEDPTR(dptr)	NOOP_FUNCTION
  
  #if DB_VER == 1
  #include <sys/fcntl.h>
  #define APR_DBM_DBMODE_RO       O_RDONLY
  #define APR_DBM_DBMODE_RW       O_RDWR
  #define APR_DBM_DBMODE_RWCREATE (O_CREAT | O_RDWR)
  #define APR_DBM_DBMODE_RWTRUNC (O_CREAT | O_RDWR|O_TRUNC)
  #else
  #define APR_DBM_DBMODE_RO       DB_RDONLY
  #define APR_DBM_DBMODE_RW       0
  #define APR_DBM_DBMODE_RWCREATE DB_CREATE
  #define APR_DBM_DBMODE_RWTRUNC  DB_TRUNCATE
  #endif /* DBVER == 1 */
  
  /* map a DB error to an apr_status_t */
  static apr_status_t db2s(int dberr)
  {
      if (dberr != 0) {
          /* ### need to fix this */
          return APR_OS_START_USEERR+dberr;
      }
  
      return APR_SUCCESS;
  }
  
  /* handle the FIRSTKEY functionality */
  static apr_status_t do_firstkey(real_file_t *f, DBT *pkey)
  {
      int dberr;
      DBT data;
  
      memset(pkey,0,sizeof(DBT));
  
      memset(&data,0,sizeof(DBT));
  #if DB_VER == 1
      dberr = (*f->bdb->seq)(f->bdb, pkey, &data, R_FIRST);
  #else
      if ((dberr = (*f->bdb->cursor)(f->bdb, NULL, &f->curs
  #if DB_VER == 3
                                     , 0
  #endif
                                     )) == 0) {
          dberr = (*f->curs->c_get)(f->curs, pkey, &data, DB_FIRST);
          if (dberr == DB_NOTFOUND) {
              memset(pkey, 0, sizeof(*pkey));
              (*f->curs->c_close)(f->curs);
              f->curs = NULL;
              return APR_SUCCESS;
          }
      }
  #endif
  
      return db2s(dberr);
  }
  
  /* handle the NEXTKEY functionality */
  static apr_status_t do_nextkey(real_file_t *f, DBT *pkey, DBT *pnext)
  {
      int dberr;
      DBT data;
  
  #if DB_VER == 1
      dberr = (*f->bdb->seq)(f->bdb, pkey, &data, R_NEXT);
  #else
      if (f->curs == NULL)
          return APR_EINVAL;
  
      dberr = (*f->curs->c_get)(f->curs, pkey, &data, DB_NEXT);
      if (dberr == DB_NOTFOUND) {
          memset(pkey, 0, sizeof(*pkey));
          (*f->curs->c_close)(f->curs);
          f->curs = NULL;
          return APR_SUCCESS;
      }
  #endif
  
      return db2s(dberr);
  }
  
  
  
  1.1                  apr-util/dbm/apr_dbm_gdbm.c
  
  Index: apr_dbm_gdbm.c
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  #include "apr_dbm_private.h"
  
  #include <gdbm.h>
  #include <stdlib.h>     /* for free() */
  
  typedef GDBM_FILE real_file_t;
  
  typedef datum *cvt_datum_t;
  #define CONVERT_DATUM(cvt, pinput) ((cvt) = (datum *)(pinput))
  
  typedef datum result_datum_t;
  #define RETURN_DATUM(poutput, rd) (*(poutput) = *(apr_datum_t *)&(rd))
  
  #define APR_DBM_CLOSE(f)	gdbm_close(f)
  #define APR_DBM_FETCH(f, k, v)	((v) = gdbm_fetch(f, *(k)), APR_SUCCESS)
  #define APR_DBM_STORE(f, k, v)	g2s(gdbm_store(f, *(k), *(v), GDBM_REPLACE))
  #define APR_DBM_DELETE(f, k)	g2s(gdbm_delete(f, *(k)))
  #define APR_DBM_FIRSTKEY(f, k)	((k) = gdbm_firstkey(f), APR_SUCCESS)
  #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
  
  #define APR_DBM_DBMODE_RO       GDBM_READER
  #define APR_DBM_DBMODE_RW       GDBM_WRITER
  #define APR_DBM_DBMODE_RWCREATE GDBM_WRCREAT
  #define APR_DBM_DBMODE_RWTRUNC  GDBM_NEWDB
  
  /* map a GDBM error to an apr_status_t */
  static apr_status_t g2s(int gerr)
  {
      if (gerr == -1) {
          /* ### need to fix this */
          return APR_EGENERAL;
      }
  
      return APR_SUCCESS;
  }
  
  
  
  1.1                  apr-util/dbm/apr_dbm_sdbm.c
  
  Index: apr_dbm_sdbm.c
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  #include "apr_dbm_private.h"
  
  
  #include "apr_sdbm.h"
  
  typedef apr_sdbm_t *real_file_t;
  
  typedef apr_sdbm_datum_t *cvt_datum_t;
  #define CONVERT_DATUM(cvt, pinput) ((cvt) = (apr_sdbm_datum_t *)(pinput))
  
  typedef apr_sdbm_datum_t result_datum_t;
  #define RETURN_DATUM(poutput, rd) (*(poutput) = *(apr_datum_t *)&(rd))
  
  #define APR_DBM_CLOSE(f)	apr_sdbm_close(f)
  #define APR_DBM_FETCH(f, k, v)	apr_sdbm_fetch(f, &(v), *(k))
  #define APR_DBM_STORE(f, k, v)	apr_sdbm_store(f, *(k), *(v), APR_SDBM_REPLACE)
  #define APR_DBM_DELETE(f, k)	apr_sdbm_delete(f, *(k))
  #define APR_DBM_FIRSTKEY(f, k)	apr_sdbm_firstkey(f, &(k))
  #define APR_DBM_NEXTKEY(f, k, nk) apr_sdbm_nextkey(f, &(nk))
  #define APR_DBM_FREEDPTR(dptr)	NOOP_FUNCTION
  
  #define APR_DBM_DBMODE_RO       APR_READ
  #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)
  
  
  
  1.1                  apr-util/include/private/apr_dbm_private.h
  
  Index: apr_dbm_private.h
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  #ifndef APR_DBM_PRIVATE_H
  #define APR_DBM_PRIVATE_H
  
  #include "apr.h"
  #include "apr_errno.h"
  #include "apr_pools.h"
  #include "apr_dbm.h"
  #include "apr_file_io.h"
  
  #include "apu.h"
  
  /* ### for now, include the DBM selection; this will go away once we start
     ### building and linking all of the DBMs at once. */
  #include "apu_select_dbm.h"
  
  #ifdef __cplusplus
  extern "C" {
  #endif
  
  /** @internal */
  
  /**
   * 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);
  
  /**
   * Structure to describe the operations of the DBM
   */
  typedef struct {
      /** The name of the DBM Type */
      const char *name;
  
      /** Open the DBM */
      apr_status_t (*open)(apr_dbm_t **dbm, const char *name, apr_int32_t mode,
                           apr_fileperms_t perm, apr_pool_t *cntxt);
  
      /** Close the DBM */
      void (*close)(apr_dbm_t *dbm);
  
      /** Fetch a dbm record value by key */
      apr_status_t (*fetch)(apr_dbm_t *dbm, apr_datum_t key,
                                     apr_datum_t * pvalue);
  
      /** Store a dbm record value by key */
      apr_status_t (*store)(apr_dbm_t *dbm, apr_datum_t key, apr_datum_t value);
  
      /** Delete a dbm record value by key */
      apr_status_t (*del)(apr_dbm_t *dbm, apr_datum_t key);
  
      /** Search for a key within the dbm */
      int (*exists)(apr_dbm_t *dbm, apr_datum_t key);
  
      /** Retrieve the first record key from a dbm */
      apr_status_t (*firstkey)(apr_dbm_t *dbm, apr_datum_t * pkey);
  
      /** Retrieve the next record key from a dbm */
      apr_status_t (*nextkey)(apr_dbm_t *dbm, apr_datum_t * pkey);
  
      /** Report more information when an apr_dbm function fails. */
      char *(*geterror)(apr_dbm_t *dbm, int *errcode, char *errbuf,
                        apr_size_t errbufsize);
  
      /** Proactively toss any memory associated with the apr_datum_t. */
      void (*freedatum)(apr_dbm_t *dbm, apr_datum_t data);
  
      /** Get the names that the DBM will use for a given pathname. */
      void (*apr_dbm_get_usednames)(apr_pool_t *pool,
                                    const char *pathname,
                                    const char **used1,
                                    const char **used2);
  
  } apr_dbm_type_t;
  
  
  /**
   * The actual DBM
   */
  struct apr_dbm_t
  { 
      apr_pool_t *pool;
  
      /** pointer to DB Implementation Specific data */
      void *file;
  
      int errcode;
      const char *errmsg;
  
      /** the type of DBM */
      const apr_dbm_type_t *type;
  };
  
  
  /* Declare all of the builtin DBM providers */
  APU_DECLARE_DATA extern const apr_dbm_type_t apr_dbm_type_sdbm;
  APU_DECLARE_DATA extern const apr_dbm_type_t apr_dbm_type_gdbm;
  APU_DECLARE_DATA extern const apr_dbm_type_t apr_dbm_type_db1;
  APU_DECLARE_DATA extern const apr_dbm_type_t apr_dbm_type_db2;
  APU_DECLARE_DATA extern const apr_dbm_type_t apr_dbm_type_db3;
  
  #ifdef __cplusplus
  }
  #endif
  
  #endif /* APR_DBM_PRIVATE_H */
  
  
  

Mime
View raw message