Skip to content

Commit

Permalink
Draft: mod_dav_fs: add DAVLockDBType directive.
Browse files Browse the repository at this point in the history
  • Loading branch information
notroj committed Sep 27, 2023
1 parent c6d7943 commit 7b4d680
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 16 deletions.
22 changes: 13 additions & 9 deletions modules/dav/fs/dbm.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
#include "http_log.h"
#include "http_main.h" /* for ap_server_conf */

#ifndef DEFAULT_PROPDB_DBM_TYPE
#define DEFAULT_PROPDB_DBM_TYPE "default"
#endif

APLOG_USE_MODULE(dav_fs);

struct dav_db {
Expand Down Expand Up @@ -129,8 +133,8 @@ void dav_fs_ensure_state_dir(apr_pool_t * p, const char *dirname)
/* dav_dbm_open_direct: Opens a *dbm database specified by path.
* ro = boolean read-only flag.
*/
dav_error * dav_dbm_open_direct(apr_pool_t *p, const char *pathname, int ro,
dav_db **pdb)
dav_error * dav_dbm_open_direct(apr_pool_t *p, const char *pathname,
const char *dbmtype, int ro, dav_db **pdb)
{
#if APU_MAJOR_VERSION > 1 || (APU_MAJOR_VERSION == 1 && APU_MINOR_VERSION >= 7)
const apr_dbm_driver_t *driver;
Expand All @@ -142,10 +146,10 @@ dav_error * dav_dbm_open_direct(apr_pool_t *p, const char *pathname, int ro,
*pdb = NULL;

#if APU_MAJOR_VERSION > 1 || (APU_MAJOR_VERSION == 1 && APU_MINOR_VERSION >= 7)
if ((status = apr_dbm_get_driver(&driver, NULL, &err, p)) != APR_SUCCESS) {
if ((status = apr_dbm_get_driver(&driver, dbmtype, &err, p)) != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_ERR, status, ap_server_conf, APLOGNO(10289)
"mod_dav_fs: The DBM library '%s' could not be loaded: %s",
err->reason, err->msg);
"mod_dav_fs: The DBM library '%s' for '%s' could not be loaded: %s",
err->reason, dbmtype, err->msg);
return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 1, status,
"Could not load library for database.");
}
Expand All @@ -156,9 +160,9 @@ dav_error * dav_dbm_open_direct(apr_pool_t *p, const char *pathname, int ro,
return dav_fs_dbm_error(NULL, p, status);
}
#else
if ((status = apr_dbm_open(&file, pathname,
ro ? APR_DBM_READONLY : APR_DBM_RWCREATE,
APR_OS_DEFAULT, p))
if ((status = apr_dbm_open_ex(&file, dbmtype, pathname,
ro ? APR_DBM_READONLY : APR_DBM_RWCREATE,
APR_OS_DEFAULT, p))
!= APR_SUCCESS
&& !ro) {
/* ### do something with 'status' */
Expand Down Expand Up @@ -206,7 +210,7 @@ static dav_error * dav_dbm_open(apr_pool_t * p, const dav_resource *resource,

/* ### do we need to deal with the umask? */

return dav_dbm_open_direct(p, pathname, ro, pdb);
return dav_dbm_open_direct(p, pathname, DEFAULT_PROPDB_DBM_TYPE, ro, pdb);
}

void dav_dbm_close(dav_db *db)
Expand Down
4 changes: 3 additions & 1 deletion modules/dav/fs/lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ struct dav_lockdb_private
request_rec *r; /* for accessing the uuid state */
apr_pool_t *pool; /* a pool to use */
const char *lockdb_path; /* where is the lock database? */
const char *lockdb_type; /* where is the lock database? */

int opened; /* we opened the database */
dav_db *db; /* if non-NULL, the lock database */
Expand Down Expand Up @@ -306,6 +307,7 @@ static dav_error * dav_fs_really_open_lockdb(dav_lockdb *lockdb)

err = dav_dbm_open_direct(lockdb->info->pool,
lockdb->info->lockdb_path,
lockdb->info->lockdb_type,
lockdb->ro,
&lockdb->info->db);
if (err != NULL) {
Expand Down Expand Up @@ -342,7 +344,7 @@ static dav_error * dav_fs_open_lockdb(request_rec *r, int ro, int force,
comb->priv.r = r;
comb->priv.pool = r->pool;

comb->priv.lockdb_path = dav_get_lockdb_path(r);
comb->priv.lockdb_path = dav_get_lockdb_path(r, &comb->priv.lockdb_type);
if (comb->priv.lockdb_path == NULL) {
return dav_new_error(r->pool, HTTP_INTERNAL_SERVER_ERROR,
DAV_ERR_LOCK_NO_DB, 0,
Expand Down
31 changes: 29 additions & 2 deletions modules/dav/fs/mod_dav_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,27 @@ typedef struct {
/* per-server configuration */
typedef struct {
const char *lockdb_path;

const char *lockdb_type;
} dav_fs_server_conf;

extern module AP_MODULE_DECLARE_DATA dav_fs_module;

#ifndef DEFAULT_DAV_LOCKDB
#define DEFAULT_DAV_LOCKDB "davlockdb"
#endif
#ifndef DEFAULT_DAV_LOCKDB_TYPE
#define DEFAULT_DAV_LOCKDB_TYPE "default"
#endif

const char *dav_get_lockdb_path(const request_rec *r)

const char *dav_get_lockdb_path(const request_rec *r, const char **dbmtype)
{
dav_fs_server_conf *conf;

conf = ap_get_module_config(r->server->module_config, &dav_fs_module);

*dbmtype = conf->lockdb_type;

return conf->lockdb_path;
}

Expand Down Expand Up @@ -119,6 +126,8 @@ static void *dav_fs_merge_server_config(apr_pool_t *p,

newconf->lockdb_path =
child->lockdb_path ? child->lockdb_path : parent->lockdb_path;
newconf->lockdb_type =
child->lockdb_type ? child->lockdb_type : parent->lockdb_type;

return newconf;
}
Expand Down Expand Up @@ -167,6 +176,9 @@ static apr_status_t dav_fs_post_config(apr_pool_t *p, apr_pool_t *plog,
if (!conf->lockdb_path) {
conf->lockdb_path = ap_state_dir_relative(p, DEFAULT_DAV_LOCKDB);
}
if (!conf->lockdb_type) {
conf->lockdb_type = DEFAULT_DAV_LOCKDB_TYPE;
}
}

return OK;
Expand All @@ -191,6 +203,19 @@ static const char *dav_fs_cmd_davlockdb(cmd_parms *cmd, void *config,
return NULL;
}

/*
* Command handler for the DAVLockDBType directive, which is TAKE1
*/
static const char *dav_fs_cmd_davlockdbtype(cmd_parms *cmd, void *config,
const char *arg1)
{
dav_fs_server_conf *conf = ap_get_module_config(cmd->server->module_config,
&dav_fs_module);
conf->lockdb_type = arg1;

return NULL;
}

/*
* Command handler for the DAVquota directive, which is TAKE1
*/
Expand All @@ -215,6 +240,8 @@ static const command_rec dav_fs_cmds[] =
/* per server */
AP_INIT_TAKE1("DAVLockDB", dav_fs_cmd_davlockdb, NULL, RSRC_CONF,
"specify a lock database"),
AP_INIT_TAKE1("DAVLockDBType", dav_fs_cmd_davlockdbtype, NULL, RSRC_CONF,
"specify a lock database DBM type"),

/* per directory */
AP_INIT_TAKE1("DAVquota", dav_fs_cmd_quota, NULL, ACCESS_CONF|RSRC_CONF,
Expand Down
9 changes: 5 additions & 4 deletions modules/dav/fs/repos.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ dav_error * dav_fs_get_locknull_members(const dav_resource *resource,
/* DBM functions used by the repository and locking providers */
extern const dav_hooks_db dav_hooks_db_dbm;

dav_error * dav_dbm_open_direct(apr_pool_t *p, const char *pathname, int ro,
dav_db **pdb);
dav_error * dav_dbm_open_direct(apr_pool_t *p, const char *pathname,
const char *dbmtype, int ro, dav_db **pdb);
void dav_dbm_get_statefiles(apr_pool_t *p, const char *fname,
const char **state1, const char **state2);
dav_error * dav_dbm_delete(dav_db *db, apr_datum_t key);
Expand All @@ -77,8 +77,9 @@ void dav_dbm_freedatum(dav_db *db, apr_datum_t data);
int dav_dbm_exists(dav_db *db, apr_datum_t key);
void dav_dbm_close(dav_db *db);

/* where is the lock database located? */
const char *dav_get_lockdb_path(const request_rec *r);
/* Returns path to lock database and configured dbm type as
* *dbmtype. */
const char *dav_get_lockdb_path(const request_rec *r, const char **dbmtype);

dav_error *dav_fs_get_quota(const request_rec *r, const char *path,
apr_off_t *quota_bytes);
Expand Down

0 comments on commit 7b4d680

Please sign in to comment.