Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

more changes to locks plugin and fixed getHTTPHeaders() to not send o…

…bjects as values
  • Loading branch information...
commit fa019d5ac6dadc20115537cc4cb93ded26b032ea 1 parent 1ff8034
@mikedeboer authored
Showing with 157 additions and 151 deletions.
  1. +1 −1  lib/DAV/handler.js
  2. +156 −150 lib/DAV/plugins/locks.js
View
2  lib/DAV/handler.js
@@ -1504,7 +1504,7 @@ jsDAV_Handler.STATUS_MAP = {
// GetLastModified gets special cased
if (properties[prop].hasFeature && properties[prop].hasFeature(jsDAV_Property_GetLastModified))
headers[header] = Util.dateFormat(properties[prop].getTime(), Util.DATE_RFC1123);
- else
+ else if (typeof properties[prop] != "object")
headers[header] = properties[prop];
}
}
View
306 lib/DAV/plugins/locks.js
@@ -196,47 +196,49 @@ var jsDAV_Locks_Plugin = module.exports = jsDAV_ServerPlugin.extend({
var currentPath = "";
var self = this;
- Async.list(uri.split("/")).each(function(uriPart, next) {
- if (currentPath)
- currentPath += "/";
- currentPath += uriPart;
- self.handler.getNodeForPath(currentPath, function(err, node) {
- if (err)
- return next((err instanceof Exc.jsDAV_Exception_FileNotFound) ? null : err);
+ Async.list(uri.split("/"))
+ .delay(0, 10)
+ .each(function(uriPart, next) {
+ if (currentPath)
+ currentPath += "/";
+ currentPath += uriPart;
+ self.handler.getNodeForPath(currentPath, function(err, node) {
+ if (err)
+ return next((err instanceof Exc.jsDAV_Exception_FileNotFound) ? null : err);
- if (node.hasFeature(jsDAV_iLockable)) {
- node.getLocks(function(err, locks) {
- if (err)
- return next(err);
- uriLocks = locks;
+ if (node.hasFeature(jsDAV_iLockable)) {
+ node.getLocks(function(err, locks) {
+ if (err)
+ return next(err);
+ uriLocks = locks;
+ next();
+ });
+ }
+ else {
next();
- });
+ }
+ });
+ })
+ .end(function(err) {
+ if (err)
+ return cbgetlocks(err);
+
+ for (var i = 0, l = uriLocks.length; i < l; ++i) {// as uriLock) {
+ var uriLock = uriLocks[i];
+ // Unless we're on the leaf of the uri-tree we should ingore locks with depth 0
+ if (uri == currentPath || uriLock.depth !== 0) {
+ uriLock.uri = currentPath;
+ lockList.push(uriLock);
+ }
}
- else {
- next();
+ if (self.locksBackend) {
+ self.locksBackend.getLocks(uri, returnChildLocks, function(err, locks) {
+ cbgetlocks(err, lockList.concat(locks));
+ });
}
+ else
+ cbgetlocks(null, lockList);
});
- })
- .end(function(err) {
- if (err)
- return cbgetlocks(err);
-
- for (var i = 0, l = uriLocks.length; i < l; ++i) {// as uriLock) {
- var uriLock = uriLocks[i];
- // Unless we're on the leaf of the uri-tree we should ingore locks with depth 0
- if (uri == currentPath || uriLock.depth !== 0) {
- uriLock.uri = currentPath;
- lockList.push(uriLock);
- }
- }
- if (self.locksBackend) {
- self.locksBackend.getLocks(uri, returnChildLocks, function(err, locks) {
- cbgetlocks(err, lockList.concat(locks));
- });
- }
- else
- cbgetlocks(null, lockList);
- });
},
/**
@@ -549,136 +551,140 @@ var jsDAV_Locks_Plugin = module.exports = jsDAV_ServerPlugin.extend({
var ret, locks;
var stopped = false;
- var conditions = this.getIfConditions(urls);
+ var conditions = this.getIfConditions();
var self = this;
// We're going to loop through the urls and make sure all lock conditions
// are satisfied
- Async.list(urls).each(function(url, next) {
- self.getLocks(url, false, function(err, aLocks) {
- if (err)
- return next(err);
-
- locks = [].concat(aLocks);
-
- // If there were no conditions, but there were locks, we fail
- if (!conditions.length && locks.length) {
- ret = false;
- cbvalidate(null, ret, locks[0]);
- stopped = true;
- return next(Async.STOP);
- }
+ Async.list(urls)
+ .delay(0, 10)
+ .each(function(url, next) {
+ self.getLocks(url, false, function(err, aLocks) {
+ if (err)
+ return next(err);
- // If there were no locks or conditions, we go to the next url
- if (!locks.length && !conditions.length)
- return next();
+ locks = [].concat(aLocks);
- Async.list(conditions).each(function(condition, next2) {
- var conditionUri;
- try {
- conditionUri = condition.uri ? self.handler.calculateUri(condition.uri) : "";
- }
- catch (ex) {
- return next2(ex);
+ // If there were no conditions, but there were locks, we fail
+ if (!conditions.length && locks.length) {
+ ret = false;
+ cbvalidate(null, ret, locks[0]);
+ stopped = true;
+ return next(Async.STOP);
}
- // If the condition has a url, and it isn't part of the affected
- // url at all, check the next condition
- if (conditionUri && url.indexOf(conditionUri) !== 0)
- return next2();
-
- // The tokens array contains arrays with 2 elements. 0=true/false
- // for normal/not condition, 1=locktoken
- // At least 1 condition has to be satisfied
- var tokensStopped = true;
- Async.list(condition.tokens).each(function(conditionToken, next3) {
- var etagValid = true;
- var lockValid = true;
-
- // condition can contain an etag
- if (conditionToken.etag) {
- var uri;
+ // If there were no locks or conditions, we go to the next url
+ if (!locks.length && !conditions.length)
+ return next();
+
+ Async.list(conditions)
+ .delay(0, 10)
+ .each(function(condition, next2) {
+ var conditionUri;
try {
- uri = conditionUri ? conditionUri : self.handler.getRequestUri();
+ conditionUri = condition.uri ? self.handler.calculateUri(condition.uri) : "";
}
catch (ex) {
- return next3(ex);
+ return next2(ex);
}
- self.handler.getNodeForPath(uri, function(err, node) {
- if (err)
- return next3((err instanceof Exc.jsDAV_Exception_FileNotFound) ? null : err);
- node.getETag(function(err, etag) {
- if (err)
- return next3(err);
- etagValid = etag == conditionToken.etag;
- afterEtag();
- });
- });
- }
- else
- afterEtag();
-
- function afterEtag() {
- // condition can contain a lock token
- if (conditionToken.token) {
- lockValid = false;
- // Match all the locks
- for (var lock, lockToken, lockIndex = 0, l = locks.length; lockIndex < l; ++lockIndex) {
- lock = locks[lockIndex];
- lockToken = "opaquelocktoken:" + lock.token;
- // Checking NOT
- if (conditionToken.not && lockToken != conditionToken.token) {
- // Condition valid, onto the next
- lockValid = true;
- break;
+
+ // If the condition has a url, and it isn't part of the affected
+ // url at all, check the next condition
+ if (conditionUri && url.indexOf(conditionUri) !== 0)
+ return next2();
+
+ // The tokens array contains arrays with 2 elements. 0=true/false
+ // for normal/not condition, 1=locktoken
+ // At least 1 condition has to be satisfied
+ var tokensStopped = true;
+ Async.list(condition.tokens).each(function(conditionToken, next3) {
+ var etagValid = true;
+ var lockValid = true;
+
+ // condition can contain an etag
+ if (conditionToken.etag) {
+ var uri;
+ try {
+ uri = conditionUri ? conditionUri : self.handler.getRequestUri();
}
- if (!conditionToken.not && lockToken == conditionToken.token) {
- lastLock = lock;
- // Condition valid and lock matched
- locks.splice(lockIndex, 1);
- lockValid = true;
- break;
+ catch (ex) {
+ return next3(ex);
}
+ self.handler.getNodeForPath(uri, function(err, node) {
+ if (err)
+ return next3((err instanceof Exc.jsDAV_Exception_FileNotFound) ? null : err);
+ node.getETag(function(err, etag) {
+ if (err)
+ return next3(err);
+ etagValid = etag == conditionToken.etag;
+ afterEtag();
+ });
+ });
}
- }
+ else
+ afterEtag();
- // If, after checking both etags and locks they are stil valid,
- // we can continue with the next condition.
- if (etagValid && lockValid) {
- tokensStopped = true;
- next3(Async.STOP);
- }
- else
- next3();
- }
- })
- .end(function(err) {
- if (err)
- return next2(err);
- if (!tokensStopped) {
- // No conditions matched, so we fail
- return next2(new Exc.jsDAV_Exception_PreconditionFailed("The tokens "
- + "provided in the if header did not match", "If"));
- }
- stopped = true;
- next2(Async.STOP);
- });
- })
- .end(next);
- });
- })
- .end(function(err) {
- if (err && !stopped)
- return cbvalidate(err, false, lastLock);
+ function afterEtag() {
+ // condition can contain a lock token
+ if (conditionToken.token) {
+ lockValid = false;
+ // Match all the locks
+ for (var lock, lockToken, lockIndex = 0, l = locks.length; lockIndex < l; ++lockIndex) {
+ lock = locks[lockIndex];
+ lockToken = "opaquelocktoken:" + lock.token;
+ // Checking NOT
+ if (conditionToken.not && lockToken != conditionToken.token) {
+ // Condition valid, onto the next
+ lockValid = true;
+ break;
+ }
+ if (!conditionToken.not && lockToken == conditionToken.token) {
+ lastLock = lock;
+ // Condition valid and lock matched
+ locks.splice(lockIndex, 1);
+ lockValid = true;
+ break;
+ }
+ }
+ }
- // Conditions were met, we'll also need to check if all the locks are gone
- if (locks.length) {
- // There's still locks, we fail
- return cbvalidate(err, false, locks[0]);
- }
- // We got here, this means every condition was satisfied
- cbvalidate(null, true, lastLock);
- });
+ // If, after checking both etags and locks they are stil valid,
+ // we can continue with the next condition.
+ if (etagValid && lockValid) {
+ tokensStopped = true;
+ next3(Async.STOP);
+ }
+ else
+ next3();
+ }
+ })
+ .end(function(err) {
+ if (err)
+ return next2(err);
+ if (!tokensStopped) {
+ // No conditions matched, so we fail
+ return next2(new Exc.jsDAV_Exception_PreconditionFailed("The tokens "
+ + "provided in the if header did not match", "If"));
+ }
+ stopped = true;
+ next2(Async.STOP);
+ });
+ })
+ .end(next);
+ });
+ })
+ .end(function(err) {
+ if (err && !stopped)
+ return cbvalidate(err, false, lastLock);
+
+ // Conditions were met, we'll also need to check if all the locks are gone
+ if (locks.length) {
+ // There's still locks, we fail
+ return cbvalidate(err, false, locks[0]);
+ }
+ // We got here, this means every condition was satisfied
+ cbvalidate(null, true, lastLock);
+ });
},
/**
@@ -698,7 +704,7 @@ var jsDAV_Locks_Plugin = module.exports = jsDAV_ServerPlugin.extend({
*
* @return void
*/
- getIfConditions: function(urls) {
+ getIfConditions: function() {
var header = this.handler.httpRequest.headers["if"];
if (!header)
return [];
Please sign in to comment.
Something went wrong with that request. Please try again.