/* Licensed to the Apache Software Foundation (ASF) under one or more *contributorlicenseagreements.SeetheNOTICEfiledistributedwith *thisworkforadditionalinformationregardingcopyrightownership. *TheASFlicensesthisfiletoYouundertheApacheLicense,Version2.0 *(the"License");youmaynotusethisfileexceptincompliancewith *theLicense.YoumayobtainacopyoftheLicenseat * *http://www.apache.org/licenses/LICENSE-2.0 * *Unlessrequiredbyapplicablelaworagreedtoinwriting,software *distributedundertheLicenseisdistributedonan"ASIS"BASIS, *WITHOUTWARRANTIESORCONDITIONSOFANYKIND,eitherexpressorimplied. *SeetheLicenseforthespecificlanguagegoverningpermissionsand *limitationsundertheLicense.
*/
dav_locktoken *locktoken; constchar *owner; /* owner field from activelock */ constchar *auth_user; /* authenticated user who created the lock */ struct dav_lock_discovery *next;
} dav_lock_discovery;
/* *Thelockdbstructure. * *The<db>fieldmaybeNULL,meaningoneoftwothings: *1)Thatwehavenotactuallyopenedtheunderlyingdatabase(yet).The *<opened>fieldshouldbefalse. *2)Weopeneditreadonlyanditwasn'tpresent. * *Thedelayedopening(determinedby<opened>)makescreatingalockdb *quick,whiledeferringtheunderlyingI/Ountilitisactuallyrequired. * *Weexportthenotionofalockdb,buthidethedetailsofit.Most *implementationswilluseadatabaseofsomekind,butitiscertainly *possiblethatalternativescouldbeused.
*/ struct dav_lockdb_private
{
request_rec *r; /* for accessing the uuid state */
apr_pool_t *pool; /* a pool to use */ constchar *lockdb_path; /* where is the lock database? */
int opened; /* we opened the database */
apr_dbm_t *db; /* if non-NULL, the lock database */
};
/* There might not be a <db> if we had problems creating it. */ if (db == NULL) {
errcode = 1;
errstr = "Could not open property database.";
} else {
(void) apr_dbm_geterror(db, &errcode, errbuf, sizeof(errbuf));
errstr = apr_pstrdup(p, errbuf);
}
if (ap_strstr_c(char_token, "opaquelocktoken:") != char_token) { return dav_new_error(p,
HTTP_BAD_REQUEST, DAV_ERR_LOCK_UNK_STATE_TOKEN, 0, "The lock token uses an unknown State-token " "format and could not be parsed.");
}
char_token += 16;
locktoken = apr_pcalloc(p, sizeof(*locktoken)); if (apr_uuid_parse(&locktoken->uuid, char_token)) { return dav_new_error(p, HTTP_BAD_REQUEST, DAV_ERR_LOCK_PARSE_TOKEN, 0, "The opaquelocktoken has an incorrect format " "and could not be parsed.");
}
if (status) {
ap_log_error(APLOG_MARK, APLOG_ERR, status, ap_server_conf, APLOGNO(10288) "mod_dav_lock: The DBM library '%s' could not be loaded: %s",
er->reason, er->msg); return dav_new_error(lockdb->info->pool, HTTP_INTERNAL_SERVER_ERROR, 1,
status, "Could not load library for property database.");
}
if (status) {
err = dav_generic_dbm_new_error(lockdb->info->db, lockdb->info->pool,
status); return dav_push_error(lockdb->info->pool,
HTTP_INTERNAL_SERVER_ERROR,
DAV_ERR_LOCK_OPENDB, "Could not open the lock database.",
err);
}
/* all right. it is opened now. */
lockdb->info->opened = 1;
comb->priv.lockdb_path = dav_generic_get_lockdb_path(r); if (comb->priv.lockdb_path == NULL) { return dav_new_error(r->pool, HTTP_INTERNAL_SERVER_ERROR,
DAV_ERR_LOCK_NO_DB, 0, "A lock database was not specified with the " "DAVGenericLockDB directive. One must be " "specified to use the locking functionality.");
}
/* done initializing. return it. */
*lockdb = &comb->pub;
if (force) { /* ### add a higher-level comment? */ return dav_generic_really_open_lockdb(*lockdb);
}
#if DAV_DEBUG if (lockdb->ro) { return dav_new_error(lockdb->info->pool,
HTTP_INTERNAL_SERVER_ERROR, 0, 0, "INTERNAL DESIGN ERROR: the lockdb was opened " "readonly, but an attempt to save locks was " "performed.");
} #endif
if ((err = dav_generic_really_open_lockdb(lockdb)) != NULL) { /* ### add a higher-level error? */ return err;
}
/* If nothing to save, delete key */ if (dp == NULL && ip == NULL) { /* don't fail if the key is not present */ /* ### but what about other errors? */
apr_dbm_delete(lockdb->info->db, key); return NULL;
}
while (dp) {
val.dsize += dav_size_direct(dp);
dp = dp->next;
} while (ip) {
val.dsize += dav_size_indirect(ip);
ip = ip->next;
}
/* ### can this be apr_palloc() ? */ /* ### hmmm.... investigate the use of a buffer here */
ptr = val.dptr = apr_pcalloc(lockdb->info->pool, val.dsize);
dp = direct;
ip = indirect;
/* ### should use a computed_desc and insert corrupt token data */
--offset; return dav_new_error(p,
HTTP_INTERNAL_SERVER_ERROR,
DAV_ERR_LOCK_CORRUPT_DB, 0,
apr_psprintf(p, "The lock database was found to " "be corrupt. offset %"
APR_SIZE_T_FMT ", c=%02x",
offset, val.dptr[offset]));
}
}
apr_dbm_freedatum(lockdb->info->db, val);
/* Clean up this record if we found expired locks */ /* *###shouldn'tdothisifwe'vebeenopenedREADONLY.elidethe *###timed-outlocksfromtheresponse,butdon'tsavethatinfoback
*/ if (need_save == DAV_TRUE) { return dav_generic_save_lock_record(lockdb, key, *direct, *indirect);
}
for (; dir != NULL; dir = dir->next) { if (!dav_compare_locktoken(indirect->locktoken, dir->locktoken)) {
*direct = dir; return NULL;
}
}
/* No match found (but we should have found one!) */
/* ### use a different description and/or error ID? */ return dav_new_error(lockdb->info->pool,
HTTP_INTERNAL_SERVER_ERROR,
DAV_ERR_LOCK_CORRUPT_DB, 0, "The lock database was found to be corrupt. " "An indirect lock's direct lock could not " "be found.");
}
static dav_error * dav_generic_remove_locknull_state(dav_lockdb *lockdb, const dav_resource *resource)
{ /* We don't need to do anything. */ return NULL;
}
/* copy all direct locks to the result list */ for (; dp != NULL; dp = dp->next) {
newlock = dav_generic_alloc_lock(lockdb, key, dp->locktoken);
newlock->is_locknull = !resource->exists;
newlock->scope = dp->f.scope;
newlock->type = dp->f.type;
newlock->depth = dp->f.depth;
newlock->timeout = dp->f.timeout;
newlock->owner = dp->owner;
newlock->auth_user = dp->auth_user;
/* hook into the result list */
newlock->next = lock;
lock = newlock;
}
/* copy all the indirect locks to the result list. resolve as needed. */ for (; ip != NULL; ip = ip->next) {
newlock = dav_generic_alloc_lock(lockdb, ip->key, ip->locktoken);
newlock->is_locknull = !resource->exists;
if (calltype == DAV_GETLOCKS_RESOLVED) {
err = dav_generic_resolve(lockdb, ip, &dp, NULL, NULL); if (err != NULL) { /* ### push a higher-level desc? */ return err;
}
if (make_indirect) { for (; lock != NULL; lock = lock->next) {
/* ### this works for any <lock> rectype */
dav_lock_indirect *newi = apr_pcalloc(p, sizeof(*newi));
/* ### shut off the const warning for now */
newi->locktoken = (dav_locktoken *)lock->locktoken;
newi->timeout = lock->timeout;
newi->key = lock->info->key;
newi->next = ip;
ip = newi;
}
} else { for (; lock != NULL; lock = lock->next) { /* create and link in the right kind of lock */
if (lock->rectype == DAV_LOCKREC_DIRECT) {
dav_lock_discovery *newd = apr_pcalloc(p, sizeof(*newd));
key = dav_generic_build_key(lockdb->info->pool, resource); if ((err = dav_generic_load_lock_record(lockdb, key, DAV_CREATE_LIST,
&dp, &ip)) != NULL) { /* ### 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 */ for (dp_scan = dp; dp_scan != NULL; dp_scan = dp_scan->next) { if (dav_generic_do_refresh(dp_scan, ltl, new_time)) { /* the lock was refreshed. return the lock. */
newlock = dav_generic_alloc_lock(lockdb, key, dp_scan->locktoken);
newlock->is_locknull = !resource->exists;
newlock->scope = dp_scan->f.scope;
newlock->type = dp_scan->f.type;
newlock->depth = dp_scan->f.depth;
newlock->timeout = dp_scan->f.timeout;
newlock->owner = dp_scan->owner;
newlock->auth_user = dp_scan->auth_user;
newlock->next = *locks;
*locks = newlock;
dirty = 1;
}
}
/* if we refreshed any locks, then save them back. */ if (dirty
&& (err = dav_generic_save_lock_record(lockdb, key, dp, ip)) != NULL) { /* ### maybe add in a higher-level description */ return err;
}
/* for each indirect lock, find its direct lock and refresh it. */ for (; ip != NULL; ip = ip->next) {
dav_lock_discovery *ref_dp;
dav_lock_indirect *ref_ip;
/* save the (resolved) direct lock back */ if ((err = dav_generic_save_lock_record(lockdb, ip->key, ref_dp,
ref_ip)) != NULL) { /* ### push a higher-level desc? */ return err;
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.