apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From minf...@apache.org
Subject svn commit: r1890952 - in /apr/apr/trunk: CHANGES dbm/apr_dbm.c dbm/apr_dbm_berkeleydb.c dbm/apr_dbm_gdbm.c dbm/apr_dbm_ndbm.c dbm/apr_dbm_sdbm.c include/apr_dbm.h include/private/apr_dbm_private.h
Date Mon, 21 Jun 2021 21:26:54 GMT
Author: minfrin
Date: Mon Jun 21 21:26:54 2021
New Revision: 1890952

URL: http://svn.apache.org/viewvc?rev=1890952&view=rev
Log:
apr_dbm: Add dedicated apr_dbm_get_driver() function that returns
details of the driver selected and any error encountered. Add the
apr_dbm_open2() function that references the driver.

Modified:
    apr/apr/trunk/CHANGES
    apr/apr/trunk/dbm/apr_dbm.c
    apr/apr/trunk/dbm/apr_dbm_berkeleydb.c
    apr/apr/trunk/dbm/apr_dbm_gdbm.c
    apr/apr/trunk/dbm/apr_dbm_ndbm.c
    apr/apr/trunk/dbm/apr_dbm_sdbm.c
    apr/apr/trunk/include/apr_dbm.h
    apr/apr/trunk/include/private/apr_dbm_private.h

Modified: apr/apr/trunk/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr/trunk/CHANGES?rev=1890952&r1=1890951&r2=1890952&view=diff
==============================================================================
--- apr/apr/trunk/CHANGES [utf-8] (original)
+++ apr/apr/trunk/CHANGES [utf-8] Mon Jun 21 21:26:54 2021
@@ -1,6 +1,10 @@
                                                      -*- coding: utf-8 -*-
 Changes for APR 2.0.0
 
+  *) apr_dbm: Add dedicated apr_dbm_get_driver() function that returns
+     details of the driver selected and any error encountered. Add the
+     apr_dbm_open2() function that references the driver. [Graham Leggett]
+
   *) apr_mmap_t members pstart, psize and poffset are used internally only
      on Windows, remove them.  [Yann Yalvic]
 

Modified: apr/apr/trunk/dbm/apr_dbm.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/dbm/apr_dbm.c?rev=1890952&r1=1890951&r2=1890952&view=diff
==============================================================================
--- apr/apr/trunk/dbm/apr_dbm.c (original)
+++ apr/apr/trunk/dbm/apr_dbm.c Mon Jun 21 21:26:54 2021
@@ -57,6 +57,8 @@
 #error a DBM implementation was not specified
 #endif
 
+#define ERROR_SIZE 1024
+
 #if APR_HAVE_MODULAR_DSO
 
 static apr_hash_t *drivers = NULL;
@@ -75,12 +77,15 @@ static apr_status_t dbm_term(void *ptr)
 
 #endif /* APR_HAVE_MODULAR_DSO */
 
-static apr_status_t dbm_open_type(apr_dbm_type_t const* * vtable,
-                                  const char *type, 
-                                  apr_pool_t *pool)
+APR_DECLARE(apr_status_t) apr_dbm_get_driver(const apr_dbm_driver_t **vtable,
+        const char *type, const apu_err_t **result, apr_pool_t *pool)
 {
 #if !APR_HAVE_MODULAR_DSO
 
+    if (result) {
+        *result = NULL; /* until further notice */
+    }
+
     *vtable = NULL;
     if (!strcasecmp(type, "default"))     *vtable = &DBM_VTABLE;
 #if APU_HAVE_DB
@@ -98,18 +103,36 @@ static apr_status_t dbm_open_type(apr_db
 #endif
         /* avoid empty block */ ;
     }
-    if (*vtable)
+    if (*vtable) {
         return APR_SUCCESS;
+    }
+
+    if (result && !*result) {
+        char *buffer = apr_pcalloc(pool, ERROR_SIZE);
+        apu_err_t *err = apr_pcalloc(pool, sizeof(apu_err_t));
+        if (err && buffer) {
+            apr_strerror(APR_ENOTIMPL, buffer, ERROR_SIZE - 1);
+            err->msg = buffer;
+            err->reason = apr_pstrdup(pool, type);
+            *result = err;
+        }
+    }
+
     return APR_ENOTIMPL;
 
 #else /* APR_HAVE_MODULAR_DSO */
 
     char modname[32];
     char symname[34];
+    apr_dso_handle_t *dso;
     apr_dso_handle_sym_t symbol;
     apr_status_t rv;
     int usertype = 0;
 
+    if (result) {
+        *result = NULL; /* until further notice */
+    }
+
     if (!strcasecmp(type, "default"))        type = DBM_NAME;
     else if (!strcasecmp(type, "db"))        type = "db";
     else if (*type && !strcasecmp(type + 1, "dbm")) {
@@ -173,7 +196,7 @@ static apr_status_t dbm_open_type(apr_db
 #endif
     apr_snprintf(symname, sizeof(symname), "apr_dbm_type_%s", type);
 
-    rv = apu_dso_load(NULL, &symbol, modname, symname, pool);
+    rv = apu_dso_load(&dso, &symbol, modname, symname, pool);
     if (rv == APR_SUCCESS || rv == APR_EINIT) { /* previously loaded?!? */
         *vtable = symbol;
         if (usertype)
@@ -185,6 +208,18 @@ static apr_status_t dbm_open_type(apr_db
         *vtable = NULL;
 
     apu_dso_mutex_unlock();
+
+    if (APR_SUCCESS != rv && result && !*result) {
+        char *buffer = apr_pcalloc(pool, ERROR_SIZE);
+        apu_err_t *err = apr_pcalloc(pool, sizeof(apu_err_t));
+        if (err && buffer) {
+            apr_dso_error(dso, buffer, ERROR_SIZE - 1);
+            err->msg = buffer;
+            err->reason = apr_pstrdup(pool, modname);
+            *result = err;
+        }
+    }
+
     return rv;
 
 #endif /* APR_HAVE_MODULAR_DSO */
@@ -196,8 +231,8 @@ APR_DECLARE(apr_status_t) apr_dbm_open_e
                                           apr_fileperms_t perm,
                                           apr_pool_t *pool)
 {
-    apr_dbm_type_t const* vtable = NULL;
-    apr_status_t rv = dbm_open_type(&vtable, type, pool);
+    apr_dbm_driver_t const* vtable = NULL;
+    apr_status_t rv = apr_dbm_get_driver(&vtable, type, NULL, pool);
 
     if (rv == APR_SUCCESS) {
         rv = (vtable->open)(pdb, pathname, mode, perm, pool);
@@ -212,6 +247,14 @@ APR_DECLARE(apr_status_t) apr_dbm_open(a
     return apr_dbm_open_ex(pdb, DBM_NAME, pathname, mode, perm, pool);
 }
 
+APR_DECLARE(apr_status_t) apr_dbm_open2(apr_dbm_t **pdb,
+                                        const apr_dbm_driver_t *vtable,
+                                        const char *pathname, apr_int32_t mode,
+                                        apr_fileperms_t perm, apr_pool_t *pool)
+{
+    return (vtable->open)(pdb, pathname, mode, perm, pool);
+}
+
 APR_DECLARE(void) apr_dbm_close(apr_dbm_t *dbm)
 {
     (*dbm->type->close)(dbm);
@@ -275,8 +318,8 @@ APR_DECLARE(apr_status_t) apr_dbm_get_us
                                                    const char **used1,
                                                    const char **used2)
 {
-    apr_dbm_type_t const* vtable;
-    apr_status_t rv = dbm_open_type(&vtable, type, p);
+    apr_dbm_driver_t const* vtable;
+    apr_status_t rv = apr_dbm_get_driver(&vtable, type, NULL, p);
 
     if (rv == APR_SUCCESS) {
         (vtable->getusednames)(p, pathname, used1, used2);

Modified: apr/apr/trunk/dbm/apr_dbm_berkeleydb.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/dbm/apr_dbm_berkeleydb.c?rev=1890952&r1=1890951&r2=1890952&view=diff
==============================================================================
--- apr/apr/trunk/dbm/apr_dbm_berkeleydb.c (original)
+++ apr/apr/trunk/dbm/apr_dbm_berkeleydb.c Mon Jun 21 21:26:54 2021
@@ -386,7 +386,7 @@ static void vt_db_usednames(apr_pool_t *
 }
 
 
-APR_MODULE_DECLARE_DATA const apr_dbm_type_t apr_dbm_type_db = {
+APR_MODULE_DECLARE_DATA const apr_dbm_driver_t apr_dbm_type_db = {
     "db",
 
     vt_db_open,

Modified: apr/apr/trunk/dbm/apr_dbm_gdbm.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/dbm/apr_dbm_gdbm.c?rev=1890952&r1=1890951&r2=1890952&view=diff
==============================================================================
--- apr/apr/trunk/dbm/apr_dbm_gdbm.c (original)
+++ apr/apr/trunk/dbm/apr_dbm_gdbm.c Mon Jun 21 21:26:54 2021
@@ -248,7 +248,7 @@ static void vt_gdbm_usednames(apr_pool_t
     *used2 = NULL;
 }
 
-APR_MODULE_DECLARE_DATA const apr_dbm_type_t apr_dbm_type_gdbm = {
+APR_MODULE_DECLARE_DATA const apr_dbm_driver_t apr_dbm_type_gdbm = {
     "gdbm",
     vt_gdbm_open,
     vt_gdbm_close,

Modified: apr/apr/trunk/dbm/apr_dbm_ndbm.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/dbm/apr_dbm_ndbm.c?rev=1890952&r1=1890951&r2=1890952&view=diff
==============================================================================
--- apr/apr/trunk/dbm/apr_dbm_ndbm.c (original)
+++ apr/apr/trunk/dbm/apr_dbm_ndbm.c Mon Jun 21 21:26:54 2021
@@ -221,7 +221,7 @@ static void vt_ndbm_usednames(apr_pool_t
     *used2 = NULL;
 }
 
-APR_MODULE_DECLARE_DATA const apr_dbm_type_t apr_dbm_type_ndbm = {
+APR_MODULE_DECLARE_DATA const apr_dbm_driver_t apr_dbm_type_ndbm = {
     "ndbm",
     vt_ndbm_open,
     vt_ndbm_close,

Modified: apr/apr/trunk/dbm/apr_dbm_sdbm.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/dbm/apr_dbm_sdbm.c?rev=1890952&r1=1890951&r2=1890952&view=diff
==============================================================================
--- apr/apr/trunk/dbm/apr_dbm_sdbm.c (original)
+++ apr/apr/trunk/dbm/apr_dbm_sdbm.c Mon Jun 21 21:26:54 2021
@@ -209,7 +209,7 @@ static void vt_sdbm_usednames(apr_pool_t
     *used2 = apr_pstrcat(pool, pathname, APR_SDBM_PAGFEXT, NULL);
 }
 
-APR_MODULE_DECLARE_DATA const apr_dbm_type_t apr_dbm_type_sdbm = {
+APR_MODULE_DECLARE_DATA const apr_dbm_driver_t apr_dbm_type_sdbm = {
     "sdbm",
     vt_sdbm_open,
     vt_sdbm_close,

Modified: apr/apr/trunk/include/apr_dbm.h
URL: http://svn.apache.org/viewvc/apr/apr/trunk/include/apr_dbm.h?rev=1890952&r1=1890951&r2=1890952&view=diff
==============================================================================
--- apr/apr/trunk/include/apr_dbm.h (original)
+++ apr/apr/trunk/include/apr_dbm.h Mon Jun 21 21:26:54 2021
@@ -20,6 +20,7 @@
 #include "apu.h"
 #include "apr.h"
 #include "apr_errno.h"
+#include "apu_errno.h"
 #include "apr_pools.h"
 #include "apr_file_info.h"
 
@@ -37,6 +38,11 @@ extern "C" {
  * @{
  */
 /**
+ * Structure representing a dbm driver.
+ */
+typedef struct apr_dbm_driver_t apr_dbm_driver_t;
+
+/**
  * Structure for referencing a dbm
  */
 typedef struct apr_dbm_t apr_dbm_t;
@@ -58,6 +64,25 @@ typedef struct
 #define APR_DBM_RWCREATE        3       /**< open for r/w, create if needed */
 #define APR_DBM_RWTRUNC         4       /**< open for r/w, truncating an existing
                                           DB if present */
+
+/**
+ * apr_dm_get_driver: get the driver struct for a name
+ *
+ * If the driver cannot be found, or cannot be opened, details of the
+ * error are returned in apu_err_t.
+ *
+ * @param driver - pointer to driver struct.
+ * @param name - driver name
+ * @param result - result and error message on failure
+ * @param pool - (process) pool to register cleanup
+ * @return APR_SUCCESS for success
+ * @return APR_ENOTIMPL for no driver (when DSO not enabled)
+ * @return APR_EDSOOPEN if DSO driver file can't be opened
+ * @return APR_ESYMNOTFOUND if the driver file doesn't contain a driver
+ */
+APR_DECLARE(apr_status_t) apr_dbm_get_driver(const apr_dbm_driver_t **driver,
+        const char *name, const apu_err_t **result, apr_pool_t *pool);
+
 /**
  * Open a dbm file by file name and type of DBM
  * @param dbm The newly opened database
@@ -91,6 +116,27 @@ APR_DECLARE(apr_status_t) apr_dbm_open_e
                                        apr_int32_t mode, apr_fileperms_t perm,
                                        apr_pool_t *cntxt);
 
+/**
+ * Open a dbm file by file name and driver
+ * @param pdb The newly opened database
+ * @param driver The dbm driver to use
+ * @param name The dbm file name to open
+ * @param mode The flag value
+ * <PRE>
+ *           APR_DBM_READONLY   open for read-only access
+ *           APR_DBM_READWRITE  open for read-write access
+ *           APR_DBM_RWCREATE   open for r/w, create if needed
+ *           APR_DBM_RWTRUNC    open for r/w, truncate if already there
+ * </PRE>
+ * @param perm Permissions to apply to if created
+ * @param pool The pool to use when creating the dbm
+ * @remark The dbm name may not be a true file name, as many dbm packages
+ * append suffixes for separate data and index files.
+ */
+APR_DECLARE(apr_status_t) apr_dbm_open2(apr_dbm_t **pdb,
+                                        const apr_dbm_driver_t *driver,
+                                        const char *name, apr_int32_t mode,
+                                        apr_fileperms_t perm, apr_pool_t *pool);
 
 /**
  * Open a dbm file by file name
@@ -106,7 +152,7 @@ APR_DECLARE(apr_status_t) apr_dbm_open_e
  * @param perm Permissions to apply to if created
  * @param cntxt The pool to use when creating the dbm
  * @remark The dbm name may not be a true file name, as many dbm packages
- * append suffixes for seperate data and index files.
+ * append suffixes for separate data and index files.
  */
 APR_DECLARE(apr_status_t) apr_dbm_open(apr_dbm_t **dbm, const char *name, 
                                        apr_int32_t mode, apr_fileperms_t perm,

Modified: apr/apr/trunk/include/private/apr_dbm_private.h
URL: http://svn.apache.org/viewvc/apr/apr/trunk/include/private/apr_dbm_private.h?rev=1890952&r1=1890951&r2=1890952&view=diff
==============================================================================
--- apr/apr/trunk/include/private/apr_dbm_private.h (original)
+++ apr/apr/trunk/include/private/apr_dbm_private.h Mon Jun 21 21:26:54 2021
@@ -44,7 +44,7 @@ APR_DECLARE(int) apr_posix_perms2mode(ap
 /**
  * Structure to describe the operations of the DBM
  */
-typedef struct {
+struct apr_dbm_driver_t {
     /** The name of the DBM Type */
     const char *name;
 
@@ -84,7 +84,7 @@ typedef struct {
                          const char **used1,
                          const char **used2);
 
-} apr_dbm_type_t;
+};
 
 
 /**
@@ -104,15 +104,15 @@ struct apr_dbm_t
     const char *errmsg;
 
     /** the type of DBM */
-    const apr_dbm_type_t *type;
+    const apr_dbm_driver_t *type;
 };
 
 
 /* Declare all of the DBM provider tables */
-APR_MODULE_DECLARE_DATA extern const apr_dbm_type_t apr_dbm_type_sdbm;
-APR_MODULE_DECLARE_DATA extern const apr_dbm_type_t apr_dbm_type_gdbm;
-APR_MODULE_DECLARE_DATA extern const apr_dbm_type_t apr_dbm_type_ndbm;
-APR_MODULE_DECLARE_DATA extern const apr_dbm_type_t apr_dbm_type_db;
+APR_MODULE_DECLARE_DATA extern const apr_dbm_driver_t apr_dbm_type_sdbm;
+APR_MODULE_DECLARE_DATA extern const apr_dbm_driver_t apr_dbm_type_gdbm;
+APR_MODULE_DECLARE_DATA extern const apr_dbm_driver_t apr_dbm_type_ndbm;
+APR_MODULE_DECLARE_DATA extern const apr_dbm_driver_t apr_dbm_type_db;
 
 #ifdef __cplusplus
 }



Mime
View raw message