locks.c revision 08cb74ca432a8c24e39f17dedce527e6a47b8001
/* Copyright 2003-2005 The Apache Software Foundation or its licensors, as
* applicable.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Generic DAV lock implementation that a DAV provider can use.
*/
#include "apr.h"
#include "apr_strings.h"
#include "apr_file_io.h"
#include "apr_uuid.h"
#define APR_WANT_MEMFUNC
#include "apr_want.h"
#include "httpd.h"
#include "http_log.h"
#include "mod_dav.h"
#include "locks.h"
/* ---------------------------------------------------------------
*
* Lock database primitives
*
*/
/*
* LOCK DATABASES
*
* Lockdiscovery information is stored in the single lock database specified
* by the DAVGenericLockDB directive. Information about this db is stored in
* the per-dir configuration.
*
* KEY
*
* The database is keyed by a key_type unsigned char (DAV_TYPE_FNAME)
* followed by full path.
*
* VALUE
*
* The value consists of a list of elements.
* DIRECT LOCK: [char (DAV_LOCK_DIRECT),
* char (dav_lock_scope),
* char (dav_lock_type),
* int depth,
* time_t expires,
* apr_uuid_t locktoken,
* char[] owner,
* char[] auth_user]
*
* INDIRECT LOCK: [char (DAV_LOCK_INDIRECT),
* apr_uuid_t locktoken,
* time_t expires,
* int key_size,
* char[] key]
* The key is to the collection lock that resulted in this indirect lock
*/
#define DAV_TRUE 1
#define DAV_FALSE 0
#define DAV_CREATE_LIST 23
#define DAV_APPEND_LIST 24
/* Stored lock_discovery prefix */
#define DAV_LOCK_DIRECT 1
#define DAV_LOCK_INDIRECT 2
#define DAV_TYPE_FNAME 11
/* Use the opaquelock scheme for locktokens */
struct dav_locktoken {
};
/* #################################################################
* ### keep these structures (internal) or move fully to dav_lock?
*/
/*
* We need to reliably size the fixed-length portion of
* dav_lock_discovery; best to separate it into another
* struct for a convenient sizeof, unless we pack lock_discovery.
*/
typedef struct dav_lock_discovery_fixed
{
char scope;
char type;
int depth;
typedef struct dav_lock_discovery
{
struct dav_lock_discovery_fixed f;
const char *owner; /* owner field from activelock */
const char *auth_user; /* authenticated user who created the lock */
struct dav_lock_discovery *next;
/* Indirect locks represent locks inherited from containing collections.
* They reference the lock token for the collection the lock is
* inherited from. A lock provider may also define a key to the
* inherited lock, for fast datbase lookup. The key is opaque outside
* the lock provider.
*/
typedef struct dav_lock_indirect
{
struct dav_lock_indirect *next;
/* ################################################################# */
/*
* Stored direct lock info - full lock_discovery length:
* prefix + Fixed length + lock token + 2 strings + 2 nulls (one for each
* string)
*/
+ sizeof(apr_uuid_t) \
+ 2)
/* Stored indirect lock info - lock token and apr_datum_t */
+ sizeof(time_t) \
/*
* The lockdb structure.
*
* The <db> field may be NULL, meaning one of two things:
* 1) That we have not actually opened the underlying database (yet). The
* <opened> field should be false.
* 2) We opened it readonly and it wasn't present.
*
* The delayed opening (determined by <opened>) makes creating a lockdb
* quick, while deferring the underlying I/O until it is actually required.
*
* We export the notion of a lockdb, but hide the details of it. Most
* implementations will use a database of some kind, but it is certainly
* possible that alternatives could be used.
*/
struct dav_lockdb_private
{
request_rec *r; /* for accessing the uuid state */
const char *lockdb_path; /* where is the lock database? */
int opened; /* we opened the database */
};
typedef struct
{
/*
* The private part of the lock structure.
*/
struct dav_lock_private
{
};
typedef struct
{
/*
* This must be forward-declared so the open_lockdb function can use it.
*/
extern const dav_hooks_locks dav_hooks_locks_generic;
{
int save_errno = errno;
int errcode;
const char *errstr;
char errbuf[200];
if (status == APR_SUCCESS) {
return NULL;
}
/* There might not be a <db> if we had problems creating it. */
errcode = 1;
errstr = "Could not open property database.";
}
else {
}
return err;
}
/* internal function for creating locks */
const dav_locktoken *locktoken)
{
}
else {
}
}
/*
* dav_generic_parse_locktoken
*
* Parse an opaquelocktoken URI into a locktoken.
*/
const char *char_token,
{
return dav_new_error(p,
"The lock token uses an unknown State-token "
"format and could not be parsed.");
}
char_token += 16;
"The opaquelocktoken has an incorrect format "
"and could not be parsed.");
}
*locktoken_p = locktoken;
return NULL;
}
/*
* dav_generic_format_locktoken
*
* Generate the URI for a locktoken
*/
static const char *dav_generic_format_locktoken(apr_pool_t *p,
const dav_locktoken *locktoken)
{
}
/*
* dav_generic_compare_locktoken
*
* Determine whether two locktokens are the same
*/
const dav_locktoken *lt2)
{
}
/*
* dav_generic_really_open_lockdb:
*
* If the database hasn't been opened yet, then open the thing.
*/
{
return NULL;
}
if (status) {
status);
"Could not open the lock database.",
err);
}
/* all right. it is opened now. */
return NULL;
}
/*
* dav_generic_open_lockdb:
*
* "open" the lock database, as specified in the global server configuration.
* If force is TRUE, then the database is opened now, rather than lazily.
*
*/
dav_lockdb **lockdb)
{
"A lock database was not specified with the "
"DAVGenericLockDB directive. One must be "
"specified to use the locking functionality.");
}
/* done initializing. return it. */
if (force) {
/* ### add a higher-level comment? */
return dav_generic_really_open_lockdb(*lockdb);
}
return NULL;
}
/*
* dav_generic_close_lockdb:
*
* Close it. Duh.
*/
{
}
}
/*
* dav_generic_build_key
*
* Given a pathname, build a DAV_TYPE_FNAME lock database key.
*/
const dav_resource *resource)
{
/* ### does this allocation have a proper lifetime? need to check */
/* ### can we use a buffer for this? */
/* size is TYPE + pathname + null */
return key;
}
/*
* dav_generic_lock_expired: return 1 (true) if the given timeout is in the
* past or present (the lock has expired), or 0 (false) if in the future
* (the lock has not yet expired).
*/
{
}
/*
* dav_generic_save_lock_record: Saves the lock information specified in the
* direct and indirect lock lists about path into the lock database.
* If direct and indirect == NULL, the key is removed.
*/
{
apr_datum_t val = { 0 };
char *ptr;
#if DAV_DEBUG
"INTERNAL DESIGN ERROR: the lockdb was opened "
"readonly, but an attempt to save locks was "
"performed.");
}
#endif
/* ### add a higher-level error? */
return err;
}
/* If nothing to save, delete key */
/* don't fail if the key is not present */
/* ### but what about other errors? */
return NULL;
}
while(dp) {
}
while(ip) {
}
/* ### can this be apr_palloc() ? */
/* ### hmmm.... investigate the use of a buffer here */
while(dp) {
/* Direct lock - lock_discovery struct follows */
*ptr++ = DAV_LOCK_DIRECT;
*ptr++ = '\0';
}
else {
}
*ptr++ = '\0';
}
else {
}
}
while(ip) {
/* Indirect lock prefix */
*ptr++ = DAV_LOCK_INDIRECT;
}
/* ### more details? add an error_id? */
status);
"Could not save lock information.",
err);
}
return NULL;
}
/*
* dav_load_lock_record: Reads lock information about key from lock db;
* creates linked lists of the direct and indirect locks.
*
* If add_method = DAV_APPEND_LIST, the result will be appended to the
* head of the direct and indirect lists supplied.
*
* Passive lock removal: If lock has timed out, it will not be returned.
* ### How much "logging" does RFC 2518 require?
*/
int add_method,
{
apr_size_t offset = 0;
apr_datum_t val = { 0 };
if (add_method != DAV_APPEND_LIST) {
}
/* ### add a higher-level error? */
return err;
}
/*
* If we opened readonly and the db wasn't there, then there are no
* locks for this resource. Just exit.
*/
return NULL;
}
}
return NULL;
}
case DAV_LOCK_DIRECT:
/* Create and fill a dav_lock_discovery structure */
/* Copy the dav_lock_discovery_fixed portion */
/* Copy the lock token. */
/* Do we have an owner field? */
++offset;
}
else {
}
++offset;
}
else {
}
}
else {
}
break;
case DAV_LOCK_INDIRECT:
/* Create and fill a dav_lock_indirect structure */
/* length of datum */
}
else {
}
break;
default:
/* ### should use a computed_desc and insert corrupt token data */
--offset;
return dav_new_error(p,
apr_psprintf(p,
"The lock database was found to "
"be corrupt. offset %"
APR_SIZE_T_FMT ", c=%02x",
}
}
/* Clean up this record if we found expired locks */
/*
* ### shouldn't do this if we've been opened READONLY. elide the
* ### timed-out locks from the response, but don't save that info back
*/
}
return NULL;
}
/* resolve <indirect>, returning <*direct> */
{
/* ### insert a higher-level description? */
return err;
}
}
return NULL;
}
}
/* No match found (but we should have found one!) */
"The lock database was found to be corrupt. "
"An indirect lock's direct lock could not "
"be found.");
}
/* ---------------------------------------------------------------
*
* Property-related lock functions
*
*/
/*
* dav_generic_get_supportedlock: Returns a static string for all
* supportedlock properties. I think we save more returning a static string
* than constructing it every time, though it might look cleaner.
*/
{
"<D:lockentry>" DEBUG_CR
"<D:lockscope><D:exclusive/></D:lockscope>" DEBUG_CR
"<D:locktype><D:write/></D:locktype>" DEBUG_CR
"</D:lockentry>" DEBUG_CR
"<D:lockentry>" DEBUG_CR
"<D:lockscope><D:shared/></D:lockscope>" DEBUG_CR
"<D:locktype><D:write/></D:locktype>" DEBUG_CR
"</D:lockentry>" DEBUG_CR;
return supported;
}
/* ---------------------------------------------------------------
*
* General lock functions
*
*/
const dav_resource *resource)
{
/* We don't need to do anything. */
return NULL;
}
const dav_resource *resource,
{
return NULL;
}
const dav_resource *resource,
int calltype,
{
#if DAV_DEBUG
if (calltype == DAV_GETLOCKS_COMPLETE) {
"INTERNAL DESIGN ERROR: DAV_GETLOCKS_COMPLETE "
"is not yet supported");
}
#endif
/* ### push a higher-level desc? */
return err;
}
/* copy all direct locks to the result list */
/* hook into the result list */
}
/* copy all the indirect locks to the result list. resolve as needed. */
if (calltype == DAV_GETLOCKS_RESOLVED) {
/* ### push a higher-level desc? */
return err;
}
}
else {
/* DAV_GETLOCKS_PARTIAL */
}
/* hook into the result list */
}
return NULL;
}
const dav_resource *resource,
const dav_locktoken *locktoken,
int partial_ok,
{
/* ### push a higher-level desc? */
return err;
}
return NULL;
}
}
/* ### nobody uses the resolving right now! */
if (partial_ok) {
}
else {
/* ### push a higher-level desc? */
return err;
}
}
return NULL;
}
}
return NULL;
}
const dav_resource *resource,
int *locks_present)
{
*locks_present = 0;
/* ### insert a higher-level error description */
return err;
}
/*
* If we opened readonly and the db wasn't there, then there are no
* locks for this resource. Just exit.
*/
return NULL;
return NULL;
}
const dav_resource *resource,
int make_indirect,
{
/* ### maybe add in a higher-level description */
return err;
}
/*
* ### when we store the lock more directly, we need to update
* ### lock->rectype and lock->is_locknull
*/
if (make_indirect) {
/* ### this works for any <lock> rectype */
/* ### shut off the const warning for now */
}
}
else {
/* create and link in the right kind of lock */
/* ### shut off the const warning for now */
}
else {
/* DAV_LOCKREC_INDIRECT(_PARTIAL) */
/* ### shut off the const warning for now */
}
}
}
/* ### maybe add a higher-level description */
return err;
}
return NULL;
}
const dav_resource *resource,
const dav_locktoken *locktoken)
{
/* ### maybe add a higher-level description */
return err;
}
if (dprev)
else
}
}
if (iprev)
else
}
}
}
/* save the modified locks, or remove all locks (dh=ih=NULL). */
/* ### maybe add a higher-level description */
return err;
}
return NULL;
}
const dav_locktoken_list *ltl,
{
int dirty = 0;
{
dirty = 1;
}
}
return dirty;
}
const dav_resource *resource,
const dav_locktoken_list *ltl,
{
int dirty = 0;
/* ### maybe add in a higher-level description */
return err;
}
/* ### we should be refreshing direct AND (resolved) indirect locks! */
/* refresh all of the direct locks on this resource */
/* the lock was refreshed. return the lock. */
dirty = 1;
}
}
/* if we refreshed any locks, then save them back. */
if (dirty
/* ### maybe add in a higher-level description */
return err;
}
/* for each indirect lock, find its direct lock and refresh it. */
/* ### push a higher-level desc? */
return err;
}
/* the lock was refreshed. return the lock. */
/* save the (resolved) direct lock back */
/* ### push a higher-level desc? */
return err;
}
}
}
return NULL;
}
{
NULL, /* lookup_resource */
NULL /* ctx */
};