diff options
author | Graham Leggett <minfrin@apache.org> | 2021-06-21 21:26:54 +0000 |
---|---|---|
committer | Graham Leggett <minfrin@apache.org> | 2021-06-21 21:26:54 +0000 |
commit | ed965cbccdc8ef54e258941d43e21025c1abf3e4 (patch) | |
tree | 9bfd9fb42e48add52a0fc54a0e81dd4cbe96320d | |
parent | 8fad5de8706995ff249a0ddd885d8baa3e1ea35f (diff) | |
download | apr-ed965cbccdc8ef54e258941d43e21025c1abf3e4.tar.gz |
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.
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1890952 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | CHANGES | 4 | ||||
-rw-r--r-- | dbm/apr_dbm.c | 61 | ||||
-rw-r--r-- | dbm/apr_dbm_berkeleydb.c | 2 | ||||
-rw-r--r-- | dbm/apr_dbm_gdbm.c | 2 | ||||
-rw-r--r-- | dbm/apr_dbm_ndbm.c | 2 | ||||
-rw-r--r-- | dbm/apr_dbm_sdbm.c | 2 | ||||
-rw-r--r-- | include/apr_dbm.h | 48 | ||||
-rw-r--r-- | include/private/apr_dbm_private.h | 14 |
8 files changed, 114 insertions, 21 deletions
@@ -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] diff --git a/dbm/apr_dbm.c b/dbm/apr_dbm.c index 71ba113ec..0147e0ab1 100644 --- a/dbm/apr_dbm.c +++ b/dbm/apr_dbm.c @@ -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_dbm_type_t const* * vtable, #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_dbm_type_t const* * vtable, #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_dbm_type_t const* * vtable, *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_ex(apr_dbm_t **pdb, const char *type, 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(apr_dbm_t **pdb, const char *pathname, 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_usednames_ex(apr_pool_t *p, 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); diff --git a/dbm/apr_dbm_berkeleydb.c b/dbm/apr_dbm_berkeleydb.c index 37e36bd22..6c9457fae 100644 --- a/dbm/apr_dbm_berkeleydb.c +++ b/dbm/apr_dbm_berkeleydb.c @@ -386,7 +386,7 @@ static void vt_db_usednames(apr_pool_t *pool, const char *pathname, } -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, diff --git a/dbm/apr_dbm_gdbm.c b/dbm/apr_dbm_gdbm.c index 76fd86361..889d41ecf 100644 --- a/dbm/apr_dbm_gdbm.c +++ b/dbm/apr_dbm_gdbm.c @@ -248,7 +248,7 @@ static void vt_gdbm_usednames(apr_pool_t *pool, const char *pathname, *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, diff --git a/dbm/apr_dbm_ndbm.c b/dbm/apr_dbm_ndbm.c index a69ac5262..33e27880b 100644 --- a/dbm/apr_dbm_ndbm.c +++ b/dbm/apr_dbm_ndbm.c @@ -221,7 +221,7 @@ static void vt_ndbm_usednames(apr_pool_t *pool, const char *pathname, *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, diff --git a/dbm/apr_dbm_sdbm.c b/dbm/apr_dbm_sdbm.c index ac3192e63..1e7c0b40e 100644 --- a/dbm/apr_dbm_sdbm.c +++ b/dbm/apr_dbm_sdbm.c @@ -209,7 +209,7 @@ static void vt_sdbm_usednames(apr_pool_t *pool, const char *pathname, *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, diff --git a/include/apr_dbm.h b/include/apr_dbm.h index 017b9edea..77e5be541 100644 --- a/include/apr_dbm.h +++ b/include/apr_dbm.h @@ -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_ex(apr_dbm_t **dbm, const char* type, 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_ex(apr_dbm_t **dbm, const char* type, * @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, diff --git a/include/private/apr_dbm_private.h b/include/private/apr_dbm_private.h index 1844435f2..b3123a6ae 100644 --- a/include/private/apr_dbm_private.h +++ b/include/private/apr_dbm_private.h @@ -44,7 +44,7 @@ APR_DECLARE(int) apr_posix_perms2mode(apr_fileperms_t perm); /** * 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 } |