Alien-SVN
view release on metacpan or search on metacpan
src/subversion/subversion/mod_dav_svn/lock.c view on Meta::CPAN
{
apr_xml_parser *xml_parser = apr_xml_parser_create(pool);
apr_xml_doc *xml_doc;
apr_status_t apr_err;
const char *xml_input = apr_pstrcat
(pool, "<?xml version=\"1.0\" encoding=\"utf-8\"?>", input, (char *)NULL);
apr_err = apr_xml_parser_feed(xml_parser, xml_input, strlen(xml_input));
if (!apr_err)
apr_err = apr_xml_parser_done(xml_parser, &xml_doc);
if (apr_err)
{
char errbuf[1024];
errbuf[0] = '\0';
(void)apr_xml_parser_geterror(xml_parser, errbuf, sizeof(errbuf));
return dav_svn__new_error(pool, HTTP_INTERNAL_SERVER_ERROR,
DAV_ERR_LOCK_SAVE_LOCK, errbuf);
}
apr_xml_to_text(pool, xml_doc->root, APR_XML_X2T_INNER,
xml_doc->namespaces, NULL, output, NULL);
return NULL;
}
/* Helper func: convert a dav_lock to an svn_lock_t, allocated in pool. */
static dav_error *
dav_lock_to_svn_lock(svn_lock_t **slock,
const dav_lock *dlock,
const char *path,
dav_lockdb_private *info,
svn_boolean_t is_svn_client,
apr_pool_t *pool)
{
svn_lock_t *lock;
/* Sanity checks */
if (dlock->type != DAV_LOCKTYPE_WRITE)
return dav_svn__new_error(pool, HTTP_BAD_REQUEST,
DAV_ERR_LOCK_SAVE_LOCK,
"Only 'write' locks are supported.");
if (dlock->scope != DAV_LOCKSCOPE_EXCLUSIVE)
return dav_svn__new_error(pool, HTTP_BAD_REQUEST,
DAV_ERR_LOCK_SAVE_LOCK,
"Only exclusive locks are supported.");
lock = svn_lock_create(pool);
lock->path = apr_pstrdup(pool, path);
lock->token = apr_pstrdup(pool, dlock->locktoken->uuid_str);
/* DAV has no concept of lock creationdate, so assume 'now' */
lock->creation_date = apr_time_now();
if (dlock->auth_user)
lock->owner = apr_pstrdup(pool, dlock->auth_user);
/* We need to be very careful about stripping the <D:owner> tag away
from the cdata. It's okay to do for svn clients, but not other
DAV clients! */
if (dlock->owner)
{
if (is_svn_client)
{
/* mod_dav has forcibly xml-escaped the comment before
handing it to us; we need to xml-unescape it (and remove
the <D:owner> wrapper) when storing in the repository, so
it looks reasonable to the rest of svn. */
dav_error *derr;
lock->is_dav_comment = 0; /* comment is NOT xml-wrapped. */
derr = unescape_xml(&(lock->comment), dlock->owner, pool);
if (derr)
return derr;
}
else
{
/* The comment comes from a non-svn client; don't touch
this data at all. */
lock->comment = apr_pstrdup(pool, dlock->owner);
lock->is_dav_comment = 1; /* comment IS xml-wrapped. */
}
}
if (dlock->timeout == DAV_TIMEOUT_INFINITE)
lock->expiration_date = 0; /* never expires */
else
lock->expiration_date = ((apr_time_t)dlock->timeout) * APR_USEC_PER_SEC;
*slock = lock;
return 0;
}
/* ---------------------------------------------------------------- */
/* mod_dav locking vtable starts here: */
/* Return the supportedlock property for a resource */
static const char *
get_supportedlock(const dav_resource *resource)
{
/* This is imitating what mod_dav_fs is doing. Note that unlike
mod_dav_fs, however, we don't support "shared" locks, only
"exclusive" ones. Nor do we support locks on collections. */
static const char supported[] = DEBUG_CR
"<D:lockentry>" DEBUG_CR
"<D:lockscope><D:exclusive/></D:lockscope>" DEBUG_CR
"<D:locktype><D:write/></D:locktype>" DEBUG_CR
"</D:lockentry>" DEBUG_CR;
if (resource->collection)
return NULL;
else
return supported;
}
/* Parse a lock token URI, returning a lock token object allocated
* in the given pool.
( run in 0.410 second using v1.01-cache-2.11-cpan-d59ab9ce9b0 )