Skip to content
Browse files

many fixes in getPropertiesForPath handling

  • Loading branch information...
1 parent 5902f97 commit 38e9e047da1941461f01b90be5691dcc416a2ec8 @mikedeboer committed Feb 7, 2013
View
6 examples/addressbookserver.js
@@ -35,7 +35,7 @@ var Db = require("./../lib/shared/db");
// This can be for example the root / or a complete path to your server script
var baseUri = "/";
-/* Database */
+// Database
var redis = Db.redisConnection();
// set it up for demo use:
redis.multi([
@@ -48,7 +48,9 @@ redis.multi([
["HMSET", "principals/principals/admin/calendar-proxy-read", "email", "", "displayname", ""],
["HMSET", "principals/principals/admin/calendar-proxy-write", "email", "", "displayname", ""],
// create the first addressbook
- ["HMSET", "addressbooks/principals/admin", "displayname", "default calendar", "uri", "default", "description", "", "ctag", "1"]
+ ["SET", "addressbooks/ID", "1"],
+ ["HMSET", "addressbooks/1", "principaluri", "principals/admin", "displayname", "default calendar", "uri", "default", "description", "", "ctag", "1"],
+ ["HMSET", "addressbooks/principalUri", "principals/admin", "[1]"]
]).exec(function(err) {
if (err)
throw(err);
View
2 lib/CardDAV/VCFExportPlugin.js
@@ -72,7 +72,7 @@ var jsCardDAV_VCFExportPlugin = module.exports = jsDAV_Plugin.extend({
// Checking ACL, if available.
var aclPlugin = self.handler.plugins.acl;
if (aclPlugin) {
- aclPlugin.checkPrivileges(uri, "{DAV:}read", function(err, hasPriv) {
+ aclPlugin.checkPrivileges(uri, "{DAV:}read", null, function(err, hasPriv) {
if (err)
return e.next(err);
afterAcl();
View
2 lib/CardDAV/addressBook.js
@@ -202,7 +202,7 @@ var jsCardDAV_AddressBook = module.exports = jsDAV_Collection.extend(jsCardDAV_i
response[propertyName] = self.addressBookInfo[propertyName];
});
- return response;
+ callback(null, response);
},
/**
View
31 lib/CardDAV/backends/redis.js
@@ -59,10 +59,13 @@ var jsCardDAV_Backend_Redis = module.exports = jsCardDAV_iBackend.extend({
*/
getAddressBooksForUser: function(principalUri, callback) {
var self = this;
- this.redis.hget(this.addressBooksTableName + "/pricipalUri", principalUri, function(err, res) {
+ this.redis.hget(this.addressBooksTableName + "/principalUri", principalUri, function(err, res) {
if (err)
return callback(err);
+ if (!res)
+ return callback(null, []);
+
var ids;
try {
ids = JSON.parse(res.toString("utf8"));
@@ -72,7 +75,7 @@ var jsCardDAV_Backend_Redis = module.exports = jsCardDAV_iBackend.extend({
}
var commands = ids.map(function(id) {
- return ["HMGET", self.addressBooksTableName + "/" + id, "uri", "principaluri", "description", "ctag"];
+ return ["HMGET", self.addressBooksTableName + "/" + id, "uri", "principaluri", "displayname", "description", "ctag"];
});
self.redis.multi(commands).exec(function(err, res) {
@@ -182,7 +185,7 @@ var jsCardDAV_Backend_Redis = module.exports = jsCardDAV_iBackend.extend({
}
var self = this;
- this.redis.hget(this.addressBooksTableName + "/pricipalUri", principalUri, function(err, res) {
+ this.redis.hget(this.addressBooksTableName + "/principalUri", principalUri, function(err, res) {
if (err)
return callback(err);
@@ -200,7 +203,7 @@ var jsCardDAV_Backend_Redis = module.exports = jsCardDAV_iBackend.extend({
ids.push(id);
var commands = [
- ["HSET", self.addressBooksTableName + "/pricipalUri", principalUri, JSON.stringify(ids)]
+ ["HSET", self.addressBooksTableName + "/principalUri", principalUri, JSON.stringify(ids)]
];
var hmset = ["HMSET", self.addressBooksTableName + "/" + id, "ctag", 1];
for (var property in values) {
@@ -225,14 +228,14 @@ var jsCardDAV_Backend_Redis = module.exports = jsCardDAV_iBackend.extend({
];
var self = this;
// fetch the principalUri to be able to retrieve the array of addressbooks.
- this.redis.hget(this.addressBooksTableName + "/" + addressBookId, "pricipaluri", function(err, res) {
+ this.redis.hget(this.addressBooksTableName + "/" + addressBookId, "principaluri", function(err, res) {
if (err)
return callback(err);
var principalUri = res.toString("utf8");
// fetch the addressbook array for this principalUri
- self.redis.hget(self.addressBooksTableName + "/pricipalUri", principalUri, function(err, res) {
- if (err)
+ self.redis.hget(self.addressBooksTableName + "/principalUri", principalUri, function(err, res) {
+ if (err || !res)
return callback(err);
var ids;
@@ -246,15 +249,17 @@ var jsCardDAV_Backend_Redis = module.exports = jsCardDAV_iBackend.extend({
if (idx > -1)
ids.splice(idx, 1);
- commands.push(["HSET", self.addressBooksTableName + "/pricipalUri", principalUri, JSON.stringify(ids)]);
+ commands.push(["HSET", self.addressBooksTableName + "/principalUri", principalUri, JSON.stringify(ids)]);
// fetch the list of card IDs
self.redis.zrange(self.addressBooksTableName + "/" + addressBookId + "/" + self.cardsTableName, 0, -1, function(err, res) {
if (err)
return callback(err);
- Db.fromMultiBulk(res).forEach(function(cardUri) {
- commands.push(["DEL", self.cardsTableName + "/" + addressBookId + "/" + cardUri]);
- });
+ if (res) {
+ Db.fromMultiBulk(res).forEach(function(cardUri) {
+ commands.push(["DEL", self.cardsTableName + "/" + addressBookId + "/" + cardUri]);
+ });
+ }
self.redis.multi(commands).exec(callback)
});
});
@@ -294,6 +299,8 @@ var jsCardDAV_Backend_Redis = module.exports = jsCardDAV_iBackend.extend({
self.redis.multi(commands).exec(function(err, res) {
if (err)
return callback(err);
+ if (!res)
+ return callback(null, []);
var cards = Db.fromMultiBulk(res).map(function(data, idx) {
return {
@@ -324,7 +331,7 @@ var jsCardDAV_Backend_Redis = module.exports = jsCardDAV_iBackend.extend({
res = Db.fromMultiBulk(res);
if (!res || !res.length)
- return callback
+ return callback();
callback(null, res && res.length
? {
uri: cardUri,
View
4 lib/CardDAV/card.js
@@ -232,7 +232,7 @@ var jsCardDAV_Card = module.exports = jsDAV_File.extend(jsCardDAV_iCard, jsDAVAC
*
* @return array|null
*/
- getSupportedPrivilegeSet: function(callback) {
- callback(null, null);
+ getSupportedPrivilegeSet: function() {
+ return null;
}
});
View
9 lib/CardDAV/plugin.js
@@ -97,6 +97,7 @@ var jsCardDAV_Plugin = module.exports = jsDAV_Plugin.extend({
"{" + this.NS_CARDDAV + "}addressbook-home-set",
"{" + this.NS_CARDDAV + "}supported-collation-set"
);
+ handler.protectedProperties = Util.makeUnique(handler.protectedProperties);
handler.propertyMap["{http://calendarserver.org/ns/}me-card"] = jsDAV_Property_Href;
@@ -416,7 +417,7 @@ var jsCardDAV_Plugin = module.exports = jsDAV_Plugin.extend({
* @return void
*/
addressbookQueryReport: function(e, dom) {
- var query = new jsCardDAV_AddressBookQueryParser(dom);
+ var query = jsCardDAV_AddressBookQueryParser.new(dom);
try {
query.parse();
}
@@ -713,16 +714,14 @@ var jsCardDAV_Plugin = module.exports = jsDAV_Plugin.extend({
if (!node.hasFeature(jsCardDAV_UserAddressBooks))
return e.next();
- output.push(
- '<tr><td colspan="2"><form method="post" action="">' +
+ output.html = '<tr><td colspan="2"><form method="post" action="">' +
'<h3>Create new address book</h3>' +
'<input type="hidden" name="jsdavAction" value="mkaddressbook" />' +
'<label>Name (uri):</label> <input type="text" name="name" /><br />' +
'<label>Display name:</label> <input type="text" name="{DAV:}displayname" /><br />' +
'<input type="submit" value="create" />' +
'</form>' +
- '</td></tr>'
- );
+ '</td></tr>';
e.stop();
},
View
11 lib/CardDAV/userAddressBooks.js
@@ -11,7 +11,6 @@ var jsDAV_Collection = require("./../DAV/collection");
var jsDAV_iExtendedCollection = require("./../DAV/interfaces/iExtendedCollection");
var jsDAVACL_iAcl = require("./../DAVACL/interfaces/iAcl")
var jsCardDAV_AddressBook = require("./addressBook");
-var jsCardDAV_Plugin = require("./plugin");
var Exc = require("./../shared/exceptions");
var Util = require("./../shared/util");
@@ -136,12 +135,12 @@ var jsCardDAV_UserAddressBooks = module.exports = jsDAV_Collection.extend(jsDAV_
*/
getChildren: function(callback) {
var self = this;
- this.carddavBackend.getAddressbooksForUser(this.principalUri, function(err, addressbooks) {
+ this.carddavBackend.getAddressBooksForUser(this.principalUri, function(err, addressbooks) {
if (err)
return callback(err);
var objs = addressbooks.map(function(addressbook) {
- return new jsCardDAV_AddressBook(self.carddavBackend, addressbook);
+ return jsCardDAV_AddressBook.new(self.carddavBackend, addressbook);
});
callback(null, objs);
});
@@ -156,7 +155,7 @@ var jsCardDAV_UserAddressBooks = module.exports = jsDAV_Collection.extend(jsDAV_
* @return void
*/
createExtendedCollection: function(name, resourceType, properties, callback) {
- if (resourceType.indexOf("{" + jsCardDAV_Plugin.NS_CARDDAV + "}addressbook") === -1 || resourceType.length !== 2)
+ if (resourceType.indexOf("{" + require("./plugin").NS_CARDDAV + "}addressbook") === -1 || resourceType.length !== 2)
return callback(Exc.InvalidResourceType("Unknown resourceType for this collection"));
this.carddavBackend.createAddressBook(this.principalUri, name, properties, callback);
@@ -235,7 +234,7 @@ var jsCardDAV_UserAddressBooks = module.exports = jsDAV_Collection.extend(jsDAV_
*
* @return array|null
*/
- getSupportedPrivilegeSet: function(callback) {
- callback(null, null);
+ getSupportedPrivilegeSet: function() {
+ return null;
}
});
View
4 lib/DAV/backends/dropbox/directory.js
@@ -77,8 +77,8 @@ var jsDAV_Dropbox_Directory = module.exports = jsDAV_Dropbox_Node.extend(jsDAV_C
+ path + " could not be located"));
}
cbfsgetchild(null, stat.is_dir
- ? new jsDAV_Dropbox_Directory(path, self.client)
- : new jsDAV_Dropbox_File(path, self.client)
+ ? jsDAV_Dropbox_Directory.new(path, self.client)
+ : jsDAV_Dropbox_File.new(path, self.client)
);
});
},
View
4 lib/DAV/backends/dropbox/tree.js
@@ -60,8 +60,8 @@ var jsDAV_Tree_Dropbox = module.exports = jsDAV_Tree.extend({
if (isError(status))
return cbfstree(new Exc.FileNotFound("File at location " + nicePath + " not found"));
cbfstree(null, stat.is_dir
- ? new jsDAV_Dropbox_Directory(realPath, self.client)
- : new jsDAV_Dropbox_File(realPath, self.client)
+ ? jsDAV_Dropbox_Directory.new(realPath, self.client)
+ : jsDAV_Dropbox_File.new(realPath, self.client)
);
});
},
View
4 lib/DAV/backends/fs/directory.js
@@ -65,7 +65,7 @@ var jsDAV_FS_Directory = module.exports = jsDAV_FS_Node.extend(jsDAV_Collection,
var stream = Fs.createWriteStream(newPath, {
encoding: enc
});
- handler.getRequestBody(enc, stream, cbfscreatefile);
+ handler.getRequestBody(enc, stream, false, cbfscreatefile);
}
},
@@ -115,7 +115,7 @@ var jsDAV_FS_Directory = module.exports = jsDAV_FS_Node.extend(jsDAV_Collection,
});
})
- handler.getRequestBody(type, stream, cbfswritechunk);
+ handler.getRequestBody(type, stream, false, cbfswritechunk);
},
/**
View
2 lib/DAV/backends/fs/file.js
@@ -55,7 +55,7 @@ var jsDAV_FS_File = module.exports = jsDAV_FS_Node.extend(jsDAV_File, {
var stream = Fs.createWriteStream(path, {
encoding: type
});
- handler.getRequestBody(type, stream, cbfsput);
+ handler.getRequestBody(type, stream, false, cbfsput);
}
},
View
8 lib/DAV/backends/ftp/directory.js
@@ -38,7 +38,7 @@ var jsDAV_Ftp_Directory = module.exports = jsDAV_Ftp_Node.extend(jsDAV_Collectio
enc = "binary";
}
- var newFile = new jsDAV_Ftp_File(newPath, this.ftp);
+ var newFile = jsDAV_Ftp_File.new(newPath, this.ftp);
newFile.put(data, enc, function(err) {
if(err)
return cbftpcreatefile(err);
@@ -60,7 +60,7 @@ var jsDAV_Ftp_Directory = module.exports = jsDAV_Ftp_Node.extend(jsDAV_Collectio
if (err)
return cbftpcreatedir(err);
- cbftpcreatedir(null, new jsDAV_Ftp_Directory(newPath, self.ftp));
+ cbftpcreatedir(null, jsDAV_Ftp_Directory.new(newPath, self.ftp));
});
},
@@ -85,9 +85,9 @@ var jsDAV_Ftp_Directory = module.exports = jsDAV_Ftp_Node.extend(jsDAV_Collectio
// a type (file or directory, 0 or 1) and a destination path.
function getDAVObject(type /*int*/, path) {
if (type === 1)
- ftp.$cache[path] = new jsDAV_Ftp_Directory(path, ftp);
+ ftp.$cache[path] = jsDAV_Ftp_Directory.new(path, ftp);
else if (type === 0)
- ftp.$cache[path] = new jsDAV_Ftp_File(path, ftp);
+ ftp.$cache[path] = jsDAV_Ftp_File.new(path, ftp);
else {
return cbftpgetchild(
new Exc.UnsupportedMediaType(path));
View
6 lib/DAV/backends/ftp/tree.js
@@ -81,7 +81,7 @@ var jsDAV_Tree_Ftp = module.exports = jsDAV_Tree.extend({
// Root node requires special treatment because it will not be listed
if (path === this.basePath) {
- var baseDir = new jsDAV_Ftp_Directory(path, ftp);
+ var baseDir = jsDAV_Ftp_Directory.new(path, ftp);
baseDir.isRoot = true;
return next(null, ftp.$cache[path] = baseDir);
}
@@ -114,9 +114,9 @@ var jsDAV_Tree_Ftp = module.exports = jsDAV_Tree.extend({
if (file) {
if (file.type === 1) // Is it a directory?
- ftp.$cache[path] = new jsDAV_Ftp_Directory(path, ftp);
+ ftp.$cache[path] = jsDAV_Ftp_Directory.new(path, ftp);
else if (file.type === 0)
- ftp.$cache[path] = new jsDAV_Ftp_File(path, ftp);
+ ftp.$cache[path] = jsDAV_Ftp_File.new(path, ftp);
if (ftp.$cache[path]) {
ftp.$cache[path].$stat = file;
View
8 lib/DAV/backends/sftp/directory.js
@@ -67,8 +67,8 @@ var jsDAV_SFTP_Directory = module.exports = jsDAV_SFTP_Node.extend(jsDAV_Collect
+ path + " could not be located"));
}
cbfsgetchild(null, stat.isDirectory()
- ? new jsDAV_SFTP_Directory(path, self.sftp)
- : new jsDAV_SFTP_File(path, self.sftp));
+ ? jsDAV_SFTP_Directory.new(path, self.sftp)
+ : jsDAV_SFTP_File.new(path, self.sftp));
});
},
@@ -90,8 +90,8 @@ var jsDAV_SFTP_Directory = module.exports = jsDAV_SFTP_Node.extend(jsDAV_Collect
if (err)
return cbnext();
nodes.push(stat.isDirectory()
- ? new jsDAV_SFTP_Directory(path, self.sftp)
- : new jsDAV_SFTP_File(path, self.sftp)
+ ? jsDAV_SFTP_Directory.new(path, self.sftp)
+ : jsDAV_SFTP_File.new(path, self.sftp)
);
cbnext();
});
View
4 lib/DAV/backends/sftp/tree.js
@@ -66,8 +66,8 @@ var jsDAV_Tree_Sftp = module.exports = jsDAV_Tree.extend({
if (!Util.empty(err))
return cbfstree(new Exc.FileNotFound("File at location " + realPath + " not found"));
cbfstree(null, stat.isDirectory()
- ? new jsDAV_SFTP_Directory(realPath, self.sftp)
- : new jsDAV_SFTP_File(realPath, self.sftp))
+ ? jsDAV_SFTP_Directory.new(realPath, self.sftp)
+ : jsDAV_SFTP_File.new(realPath, self.sftp))
});
},
View
359 lib/DAV/handler.js
@@ -706,7 +706,7 @@ jsDAV_Handler.STATUS_MAP = {
*/
this.httpPropfind = function() {
var self = this;
- this.getRequestBody("utf8", null, function(err, data) {
+ this.getRequestBody("utf8", null, false, function(err, data) {
if (!Util.empty(err))
return self.handleError(err);
//if (jsDAV.debugMode)
@@ -769,7 +769,7 @@ jsDAV_Handler.STATUS_MAP = {
*/
this.httpProppatch = function() {
var self = this;
- this.getRequestBody("utf8", null, function(err, data) {
+ this.getRequestBody("utf8", null, false, function(err, data) {
if (!Util.empty(err))
return self.handleError(err);
//if (jsDAV.debugMode)
@@ -865,7 +865,7 @@ jsDAV_Handler.STATUS_MAP = {
node.putStream(self, "binary", afterPut);
}
else {
- self.getRequestBody("binary", null, function(err, body) {
+ self.getRequestBody("binary", null, false, function(err, body) {
if (!Util.empty(err))
return self.handleError(err);
@@ -900,7 +900,7 @@ jsDAV_Handler.STATUS_MAP = {
var self = this;
var req = this.httpRequest;
- this.getRequestBody("utf8", null, function(err, requestBody) {
+ this.getRequestBody("utf8", null, false, function(err, requestBody) {
if (!Util.empty(err))
return self.handleError(err);
@@ -1089,7 +1089,7 @@ jsDAV_Handler.STATUS_MAP = {
*/
this.httpReport = function() {
var self = this;
- this.getRequestBody("utf8", null, function(err, data) {
+ this.getRequestBody("utf8", null, false, function(err, data) {
Xml.loadDOMDocument(data, self.server.options.parser, function(err, dom) {
var reportName = Xml.toClarkNotation(dom);
self.dispatchEvent("report", reportName, dom, function(stop) {
@@ -1156,19 +1156,24 @@ jsDAV_Handler.STATUS_MAP = {
* write it to a WritableStream instance.
*
* @param {String} enc
- * @param {WritableStream} [callback]
+ * @param {WritableStream} [stream]
+ * @param {Boolean} [forceStream]
* @param {Function} callback
* @return {void}
*/
- this.getRequestBody = function(enc, stream, cbreqbody) {
+ this.getRequestBody = function(enc, stream, forceStream, cbreqbody) {
if (!cbreqbody) {
cbreqbody = stream;
stream = null;
+ forceStream = false;
}
var ctype;
- var req = this.httpRequest;
- var isStream = (!(ctype = req.headers["content-type"]) || !ctype.match(/(urlencoded|multipart)/i));
+ var self = this;
+ var req = this.httpRequest;
+ var isStream = forceStream === true
+ ? true
+ : (!(ctype = req.headers["content-type"]) || !ctype.match(/(urlencoded|multipart)/i));
// HACK: MacOSX Finder and NodeJS don't play nice together with files
// that start with '._'
@@ -1253,6 +1258,8 @@ jsDAV_Handler.STATUS_MAP = {
req.$data = data;
if (err)
req.$data.err = err;
+ if (jsDAV.debugMode && enc != "binary")
+ Util.log("{" + self.id + "}", req.$data.toString("utf8"));
cbreqbody(err, enc == "binary"
? req.$data
: req.$data.toString(enc));
@@ -1640,10 +1647,8 @@ jsDAV_Handler.STATUS_MAP = {
if (!Util.empty(err))
return cbgetpropspath(err);
for (var i = 0, l = cNodes.length; i < l; ++i) {
- if (!cNodes[i].path)
- continue;
- nodes[cNodes[i].path] = cNodes[i];
- nodesPath.push(cNodes[i].path);
+ nodes[path + "/" + cNodes[i].getName()] = cNodes[i];
+ nodesPath.push(path + "/" + cNodes[i].getName());
}
afterGetChildren(nodes, nodesPath);
});
@@ -1657,8 +1662,31 @@ jsDAV_Handler.STATUS_MAP = {
// We shouldn't actually return everything we know though, and only return a
// sensible list.
var allProperties = (propertyNames.length === 0);
+ if (allProperties) {
+ // Default list of propertyNames, when all properties were requested.
+ propertyNames = [
+ "{DAV:}getlastmodified",
+ "{DAV:}getcontentlength",
+ "{DAV:}resourcetype",
+ "{DAV:}quota-used-bytes",
+ "{DAV:}quota-available-bytes",
+ "{DAV:}getetag",
+ "{DAV:}getcontenttype"
+ ];
+ }
+
+
+ // If the resourceType was not part of the list, we manually add it
+ // and mark it for removal. We need to know the resourcetype in order
+ // to make certain decisions about the entry.
+ // WebDAV dictates we should add a / and the end of href's for collections
+ var removeRT = false;
+ if (propertyNames.indexOf("{DAV:}resourcetype") === -1) {
+ propertyNames.push("{DAV:}resourcetype");
+ removeRT = true;
+ }
- function afterGetProperty(rprop, rpath, remRT, newProps, cbnext) {
+ function afterGetProperty(rprop, rpath, newProps, cbnext) {
// If we were unable to find the property, we will list it as 404.
if (!allProperties && !newProps["200"][rprop])
newProps["404"][rprop] = null;
@@ -1689,196 +1717,141 @@ jsDAV_Handler.STATUS_MAP = {
// If the resourcetype property was manually added to the requested property list,
// we will remove it again.
- if (remRT)
+ if (removeRT)
delete newProps["200"]["{DAV:}resourcetype"];
returnPropertyList[rpath] = newProps;
cbnext();
});
}
- function notFound(rprop, newProps, cbnext) {
- // If we were unable to find the property, we will list it as 404.
- if (!allProperties && !newProps["200"][rprop])
- newProps["404"][rprop] = null;
- cbnext();
- }
-
Async.list(nodesPath)
.delay(0, 10)
.each(function(myPath, cbnextpfp) {
- var node = nodes[myPath];
- var newProperties = {
+ var node = nodes[myPath];
+ var newProperties = {
"200" : {},
+ "403" : {},
"404" : {}
- };
-
- if (allProperties) {
- // Default list of propertyNames, when all properties were requested.
- propertyNames = [
- "{DAV:}getlastmodified",
- "{DAV:}getcontentlength",
- "{DAV:}resourcetype",
- "{DAV:}quota-used-bytes",
- "{DAV:}quota-available-bytes",
- "{DAV:}getetag",
- "{DAV:}getcontenttype"
- ];
- }
-
- // If the resourceType was not part of the list, we manually add it
- // and mark it for removal. We need to know the resourcetype in order
- // to make certain decisions about the entry.
- // WebDAV dictates we should add a / and the end of href's for collections
- var removeRT = false;
- if (propertyNames.indexOf("{DAV:}resourcetype") === -1) {
- propertyNames.push("{DAV:}resourcetype");
- removeRT = true;
- }
-
- var propertyMap = Util.arrayToMap(propertyNames);
- self.dispatchEvent("beforeGetProperties", myPath, node, propertyMap, newProperties, function(stop) {
- if (stop === true)
+ };
+
+ var myProperties = [].concat(propertyNames);
+
+ var propertyMap = Util.arrayToMap(myProperties);
+ self.dispatchEvent("beforeGetProperties", myPath, node, propertyMap, newProperties, function(stop) {
+ if (stop === true)
return cbnextpfp();
- propertyNames = Object.keys(propertyMap);
- if (node.hasFeature(jsDAV_iProperties)) {
- node.getProperties(propertyNames, function(err, props) {
- if (!err && props)
- newProperties["200"] = props;
-
- // The getProperties method may give us too much,
- // properties, in case the implementor was lazy.
- //
- // So as we loop through this list, we will only take the
- // properties that were actually requested and discard the
- // rest.
- for (var i = propertyNames.length - 1; i >= 0; --i) {
- if (props[propertyNames[i]]) {
- newProperties["200"][propertyNames[i]] = props[propertyNames[i]];
- propertyNames.splice(i, 1);
- }
- }
- buildProperties();
- });
- }
- else
- buildProperties();
-
- function buildProperties() {
- // next loop!
- Async.list(propertyNames)
- .delay(0, 10)
- .each(function(prop, cbnextprops) {
- if (typeof newProperties["200"][prop] != "undefined")
- return cbnextprops();
-
- if (prop == "{DAV:}getlastmodified") {
- node.getLastModified(function(err, dt) {
- if (!err && dt)
- newProperties["200"][prop] = jsDAV_Property_GetLastModified.new(dt);
- afterGetProperty(prop, myPath, removeRT, newProperties, cbnextprops);
- });
- }
- else if (prop == "{DAV:}getcontentlength") {
- if (node.hasFeature(jsDAV_iFile)) {
- node.getSize(function(err, size) {
- if (!err && typeof size != "undefined")
- newProperties["200"][prop] = parseInt(size, 10);
- afterGetProperty(prop, myPath, removeRT, newProperties, cbnextprops);
- });
- }
- else {
- notFound(prop, newProperties, cbnextprops);
- }
- }
- else if (prop == "{DAV:}quota-used-bytes") {
- if (node.hasFeature(jsDAV_iQuota)) {
- node.getQuotaInfo(function(err, quotaInfoUsed) {
- if (!err && quotaInfoUsed.length)
- newProperties["200"][prop] = quotaInfoUsed[0];
- afterGetProperty(prop, myPath, removeRT, newProperties, cbnextprops);
- });
- }
- else {
- notFound(prop, newProperties, cbnextprops);
- }
- }
- else if (prop == "{DAV:}quota-available-bytes") {
- if (node.hasFeature(jsDAV_iQuota)) {
- node.getQuotaInfo(function(err, quotaInfoAvail) {
- if (!err && quotaInfoAvail.length)
- newProperties["200"][prop] = quotaInfoAvail[1];
- afterGetProperty(prop, myPath, removeRT, newProperties, cbnextprops);
- });
- }
- else {
- notFound(prop, newProperties, cbnextprops);
- }
- }
- else if (prop == "{DAV:}getetag") {
- if (node.hasFeature(jsDAV_iFile)) {
- node.getETag(function(err, etag) {
- if (!err && etag)
- newProperties["200"][prop] = etag;
- afterGetProperty(prop, myPath, removeRT, newProperties, cbnextprops);
- });
- }
- else {
- notFound(prop, newProperties, cbnextprops);
- }
- }
- else if (prop == "{DAV:}getcontenttype") {
- if (node.hasFeature(jsDAV_iFile)) {
- node.getContentType(function(err, ct) {
- if (!err && ct)
- newProperties["200"][prop] = ct;
- afterGetProperty(prop, myPath, removeRT, newProperties, cbnextprops);
- });
- }
- else {
- notFound(prop, newProperties, cbnextprops);
- }
- }
- else if (prop == "{DAV:}supported-report-set") {
- var reports = [];
- Async.list(reportPlugins)
- .each(function(plugin, cbnextplugin) {
- plugin.getSupportedReportSet(myPath, function(err, rset) {
- if (!err && rset.length)
- reports = reports.concat(rset);
- cbnextplugin();
- });
- })
- .end(function() {
- newProperties["200"][prop] = jsDAV_Property_SupportedReportSet.new(reports);
- afterGetProperty(prop, myPath, removeRT, newProperties, cbnextprops);
- });
- }
- else if (prop == "{DAV:}resourcetype") {
- newProperties["200"][prop] = jsDAV_Property_ResourceType.new();
- for (var resourceType in self.resourceTypeMapping) {
- if (node.hasFeature(self.resourceTypeMapping[resourceType]))
- newProperties["200"][prop].add(resourceType);
- }
- afterGetProperty(prop, myPath, removeRT, newProperties, cbnextprops);
- }
- else {
- notFound(prop, newProperties, cbnextprops);
- }
- })
- .end(function(err) {
- cbnextpfp(err);
- });
- }
- });
- })
- .end(function(err) {
- if (!Util.empty(err))
- return cbgetpropspath(err);
-
- cbgetpropspath(null, returnPropertyList);
- });
+ myProperties = Object.keys(propertyMap);
+ if (node.hasFeature(jsDAV_iProperties)) {
+ node.getProperties(myProperties, function(err, props) {
+ // The getProperties method may give us too much,
+ // properties, in case the implementor was lazy.
+ //
+ // So as we loop through this list, we will only take the
+ // properties that were actually requested and discard the
+ // rest.
+ for (var i = myProperties.length - 1; i >= 0; --i) {
+ if (props[myProperties[i]]) {
+ newProperties["200"][myProperties[i]] = props[myProperties[i]];
+ myProperties.splice(i, 1);
+ }
+ }
+ buildProperties();
+ });
+ }
+ else
+ buildProperties();
+
+ function buildProperties() {
+ // next loop!
+ Async.list(myProperties)
+ .delay(0, 10)
+ .each(function(prop, cbnextprops) {
+ if (typeof newProperties["200"][prop] != "undefined")
+ return cbnextprops();
+
+ if (prop == "{DAV:}getlastmodified") {
+ node.getLastModified(function(err, dt) {
+ if (!err && dt)
+ newProperties["200"][prop] = jsDAV_Property_GetLastModified.new(dt);
+ afterGetProperty(prop, myPath, newProperties, cbnextprops);
+ });
+ }
+ else if (prop == "{DAV:}getcontentlength" && node.hasFeature(jsDAV_iFile)) {
+ node.getSize(function(err, size) {
+ if (!err && typeof size != "undefined")
+ newProperties["200"][prop] = parseInt(size, 10);
+ afterGetProperty(prop, myPath, newProperties, cbnextprops);
+ });
+ }
+ else if (prop == "{DAV:}quota-used-bytes" && node.hasFeature(jsDAV_iQuota)) {
+ node.getQuotaInfo(function(err, quotaInfoUsed) {
+ if (!err && quotaInfoUsed.length)
+ newProperties["200"][prop] = quotaInfoUsed[0];
+ afterGetProperty(prop, myPath, newProperties, cbnextprops);
+ });
+ }
+ else if (prop == "{DAV:}quota-available-bytes" && node.hasFeature(jsDAV_iQuota)) {
+ node.getQuotaInfo(function(err, quotaInfoAvail) {
+ if (!err && quotaInfoAvail.length)
+ newProperties["200"][prop] = quotaInfoAvail[1];
+ afterGetProperty(prop, myPath, newProperties, cbnextprops);
+ });
+ }
+ else if (prop == "{DAV:}getetag" && node.hasFeature(jsDAV_iFile)) {
+ node.getETag(function(err, etag) {
+ if (!err && etag)
+ newProperties["200"][prop] = etag;
+ afterGetProperty(prop, myPath, newProperties, cbnextprops);
+ });
+ }
+ else if (prop == "{DAV:}getcontenttype" && node.hasFeature(jsDAV_iFile)) {
+ node.getContentType(function(err, ct) {
+ if (!err && ct)
+ newProperties["200"][prop] = ct;
+ afterGetProperty(prop, myPath, newProperties, cbnextprops);
+ });
+ }
+ else if (prop == "{DAV:}supported-report-set") {
+ var reports = [];
+ Async.list(reportPlugins)
+ .each(function(plugin, cbnextplugin) {
+ plugin.getSupportedReportSet(myPath, function(err, rset) {
+ if (!err && rset.length)
+ reports = reports.concat(rset);
+ cbnextplugin();
+ });
+ })
+ .end(function() {
+ newProperties["200"][prop] = jsDAV_Property_SupportedReportSet.new(reports);
+ afterGetProperty(prop, myPath, newProperties, cbnextprops);
+ });
+ }
+ else if (prop == "{DAV:}resourcetype") {
+ newProperties["200"][prop] = jsDAV_Property_ResourceType.new();
+ for (var resourceType in self.resourceTypeMapping) {
+ if (node.hasFeature(self.resourceTypeMapping[resourceType]))
+ newProperties["200"][prop].add(resourceType);
+ }
+ afterGetProperty(prop, myPath, newProperties, cbnextprops);
+ }
+ else {
+ afterGetProperty(prop, myPath, newProperties, cbnextprops);
+ }
+ })
+ .end(function(err) {
+ cbnextpfp(err);
+ });
+ }
+ });
+ })
+ .end(function(err) {
+ if (!Util.empty(err))
+ return cbgetpropspath(err);
+
+ cbgetpropspath(null, returnPropertyList);
+ });
}
});
};
@@ -2211,7 +2184,7 @@ jsDAV_Handler.STATUS_MAP = {
if (dataOrStream === null) {
if (!parent.createFileStream) {
- self.getRequestBody(enc, null, function(err, body) {
+ self.getRequestBody(enc, null, false, function(err, body) {
if (err)
return cbcreatefile(err);
@@ -2294,8 +2267,8 @@ jsDAV_Handler.STATUS_MAP = {
return cbcreatecoll(err);
self.dispatchEvent("beforeBind", uri, function(stop) {
- if (stop === true)
- return cbcreatecoll();
+ if (stop)
+ return cbcreatecoll(stop === true ? null : stop);
// There are 2 modes of operation. The standard collection
// creates the directory, and then updates properties
View
2 lib/DAV/plugins/auth/abstractDigest.js
@@ -165,7 +165,7 @@ var jsDAV_Auth_Backend_AbstractDigest = module.exports = jsDAV_Auth_iBackend.ext
if (!(this.qop & QOP_AUTHINT))
return cbvalidate(false);
// We need to add an md5 of the entire request body to the A2 part of the hash
- handler.getRequestBody("utf8", function(noop, body) {
+ handler.getRequestBody("utf8", null, false, function(noop, body) {
A2 += ":" + Util.md5(body);
afterBody();
});
View
49 lib/DAV/plugins/browser.js
@@ -13,7 +13,7 @@ var jsDAV_ServerPlugin = require("./../plugin");
var jsDAV_iFile = require("./../interfaces/iFile");
var jsDAV_iCollection = require("./../interfaces/iCollection");
var jsDAV_SimpleCollection = require("./../simpleCollection");
-var jsDAVACL_iPricipal = require("./../../DAVACL/interfaces/iPrincipal");
+var jsDAVACL_iPrincipal = require("./../../DAVACL/interfaces/iPrincipal");
//var jsCalDAV_iCalendar = require("./../../CalDAV/interfaces/iCalendar");
var jsCardDAV_iAddressBook = require("./../../CardDAV/interfaces/iAddressBook");
var jsCardDAV_iCard = require("./../../CardDAV/interfaces/iCard");
@@ -24,8 +24,8 @@ var Util = require("./../../shared/util");
var Fs = require("fs");
var Path = require("path");
var Url = require("url");
+var Qs = require("querystring");
var Async = require("asyncjs");
-var Formidable = require("formidable");
/**
* Browser Plugin
@@ -58,7 +58,7 @@ var jsDAV_Browser_Plugin = module.exports = jsDAV_ServerPlugin.extend({
iconMap: {
"icons/file": jsDAV_iFile,
"icons/collection": jsDAV_iCollection,
- "icons/principal": jsDAVACL_iPricipal,
+ "icons/principal": jsDAVACL_iPrincipal,
// "icons/calendar": jsCalDAV_iCalendar,
"icons/addressbook": jsCardDAV_iAddressBook,
"icons/card": jsCardDAV_iCard
@@ -145,28 +145,11 @@ var jsDAV_Browser_Plugin = module.exports = jsDAV_ServerPlugin.extend({
}
var self = this;
- var postVars = {};
- var hadError = false;
- var form = new Formidable.IncomingForm();
- form.uploadDir = this.handler.server.tmpDir;
-
- form.on("field", function(field, value) {
- postVars[field] = value;
- });
-
- form.on("file", function(field, file) {
- postVars.tmp_name = file.path;
- });
-
- form.addListener("error", function(err) {
- hadError = true;
- e.next(err);
- });
-
- form.on("end", function() {
- if (hadError)
- return;
-
+ self.handler.getRequestBody("utf8", null, true, function(err, body) {
+ if (err)
+ return e.next(err);
+
+ var postVars = Qs.parse(body);
if (!postVars.jsdavAction)
return e.next();
@@ -198,6 +181,10 @@ var jsDAV_Browser_Plugin = module.exports = jsDAV_ServerPlugin.extend({
}
}
+ else if (stop !== true)
+ return e.next(err);
+ else
+ finish();
function finish(err) {
if (err)
@@ -210,8 +197,6 @@ var jsDAV_Browser_Plugin = module.exports = jsDAV_ServerPlugin.extend({
}
});
});
-
- form.parse(this.handler.httpRequest);
},
/**
@@ -381,11 +366,11 @@ var jsDAV_Browser_Plugin = module.exports = jsDAV_ServerPlugin.extend({
.end(function() {
html += "<tr><td colspan=\"5\"><hr /></td></tr>\n";
- var output = [];
+ var output = {};
if (self.enablePost) {
self.handler.dispatchEvent("onHTMLActionsPanel", parent, output, function() {
- html += output.join("");
+ html += (output["html"] || "");
onEnd();
});
}
@@ -425,7 +410,7 @@ var jsDAV_Browser_Plugin = module.exports = jsDAV_ServerPlugin.extend({
if (node.hasFeature(jsDAV_SimpleCollection))
return e.next();
- output.push('<tr><td colspan="2"><form method="post" action="">' +
+ output.html = '<tr><td colspan="2"><form method="post" action="">' +
'<h3>Create new folder</h3>' +
'<input type="hidden" name="jsdavAction" value="mkcol" />' +
'Name: <input type="text" name="name" /><br />' +
@@ -438,8 +423,8 @@ var jsDAV_Browser_Plugin = module.exports = jsDAV_ServerPlugin.extend({
'File: <input type="file" name="file" /><br />' +
'<input type="submit" value="upload" />' +
'</form>' +
- '</td></tr>'
- );
+ '</td></tr>';
+
e.stop();
},
View
2 lib/DAV/plugins/locks.js
@@ -280,7 +280,7 @@ var jsDAV_Locks_Plugin = module.exports = jsDAV_ServerPlugin.extend({
return e.next(new Exc.ConflictingLock(lastLock));
}
- self.handler.getRequestBody("utf8", function(err, body) {
+ self.handler.getRequestBody("utf8", null, false, function(err, body) {
if (err)
return e.next(err);
View
4 lib/DAV/plugins/temporaryfilefilter.js
@@ -199,7 +199,7 @@ var jsDAV_TemporaryFileFilter_Plugin = module.exports = jsDAV_ServerPlugin.exten
);
}
- self.handler.getRequestBody("binary", function(err, body, cleanup) {
+ self.handler.getRequestBody("binary", null, false, function(err, body, cleanup) {
if (err)
return e.next(err);
Fs.writeFile(tempLocation, body, "binary", function(err) {
@@ -257,7 +257,7 @@ var jsDAV_TemporaryFileFilter_Plugin = module.exports = jsDAV_ServerPlugin.exten
if (err || !stat)
return e.next();
- self.handler.getRequestBody("utf8", function(err, data) {
+ self.handler.getRequestBody("utf8", null, false, function(err, data) {
if (err)
return e.next(err);
self.handler.parsePropfindRequest(data, function(err, requestedProps) {
View
15 lib/DAV/property/supportedReportSet.js
@@ -71,23 +71,26 @@ var jsDAV_Property_SupportedReportSet = module.exports = jsDAV_Property.extend({
var repReportName, repMatches, repNS, repElement, repPrefix;
var repCnt = 0;
var repLen = this.reports.length;
+ var out = [];
for (; repCnt < repLen; ++repCnt) {
repReportName = this.reports[repCnt];
- dom += "<d:supported-report>"
- + "<d:report>";
+ out.push("<d:supported-report><d:report>");
- repMatches = repReportName.match(/^\{([^\}]*)\}(.*)/g);
+ repMatches = repReportName.match(/^\{([^\}]*)\}(.*)$/);
repNS = repMatches[1];
repElement = repMatches[2];
repPrefix = Xml.xmlNamespaces[repNS] ? Xml.xmlNamespaces[repNS] : null;
if (repPrefix)
- dom += "<" + repPrefix + ":" + repElement + "/>";
+ out.push("<" + repPrefix + ":" + repElement + "/>");
else
- dom += "<x:" + repElement + " xmlns:x=\"" + repNS + "\"/>";
+ out.push("<x:" + repElement + " xmlns:x=\"" + repNS + "\"/>");
+
+ out.push("</d:report></d:supported-report>");
}
- return dom;
+
+ return dom + out.join("");
}
});
View
3 lib/DAVACL/abstractPrincipalCollection.js
@@ -74,7 +74,7 @@ var jsDAVACL_AbstractPrincipalCollection = module.exports = jsDAV_Collection.ext
* @param Function callback
* @return jsDAV_iPrincipal
*/
- getChildForPrincipal: function(principalInfo) {},
+ getChildForPrincipal: function(principalInfo, callback) {},
/**
* Returns the name of this collection.
@@ -101,7 +101,6 @@ var jsDAVACL_AbstractPrincipalCollection = module.exports = jsDAV_Collection.ext
if (err)
return callback(err);
- console.log("PRINCIPALS:",JSON.stringify(principals));
var children = principals.map(function(principalInfo) {
return self.getChildForPrincipal(principalInfo);
});
View
6 lib/DAVACL/interfaces/iPrincipal.js
@@ -25,14 +25,14 @@ var jsDAVACL_iPrincipal = module.exports = Base.extend(jsDAV_iNode, {
*
* @return array
*/
- getAlternateUriSet: function(callback) { callback(Exc.notImplementedYet()); },
+ getAlternateUriSet: function() { throw Exc.notImplementedYet(); },
/**
* Returns the full principal url
*
* @return string
*/
- getPrincipalUrl: function(callback) { callback(Exc.notImplementedYet()); },
+ getPrincipalUrl: function() { throw Exc.notImplementedYet(); },
/**
* Returns the list of group members
@@ -75,5 +75,5 @@ var jsDAVACL_iPrincipal = module.exports = Base.extend(jsDAV_iNode, {
*
* @return string
*/
- getDisplayName: function(callback) { callback(Exc.notImplementedYet()); }
+ getDisplayName: function() { throw Exc.notImplementedYet(); }
});
View
33 lib/DAVACL/plugin.js
@@ -183,14 +183,15 @@ var jsDAVACL_Plugin = module.exports = jsDAV_ServerPlugin.extend({
"{DAV:}owner",
"{DAV:}group"
);
+ handler.protectedProperties = Util.makeUnique(handler.protectedProperties);
// Automatically mapping nodes implementing IPrincipal to the
// {DAV:}principal resourcetype.
- handler.resourceTypeMapping["jsDAVACL_iPrincipal"] = "{DAV:}principal";
+ handler.resourceTypeMapping["{DAV:}principal"] = jsDAVACL_iPrincipal;
// Mapping the group-member-set property to the HrefList property
// class.
- handler.propertyMap["{DAV:}group-member-set"] = "jsDAV_Property_HrefList";
+ handler.propertyMap["{DAV:}group-member-set"] = jsDAV_Property_HrefList;
},
/**
@@ -224,12 +225,12 @@ var jsDAVACL_Plugin = module.exports = jsDAV_ServerPlugin.extend({
* @param string uri
* @return array
*/
- getSupportedReportSet: function(uri) {
- return [
+ getSupportedReportSet: function(uri, callback) {
+ callback(null, [
"{DAV:}expand-property",
"{DAV:}principal-property-search",
"{DAV:}principal-search-property-set",
- ];
+ ]);
},
/**
@@ -672,8 +673,8 @@ var jsDAVACL_Plugin = module.exports = jsDAV_ServerPlugin.extend({
* If this is ommitted, the standard
* principal collection-set will be used.
* @return array This method returns an array structure similar to
- * Sabre\DAV\Server::getPropertiesForPath. Returned
- * properties are index by a HTTP status code.
+ * jsDAV_Handler.getPropertiesForPath. Returned
+ * properties are index by a HTTP status code.
*
*/
principalSearch: function(searchProperties, requestedProperties, collectionUri, callback) {
@@ -799,7 +800,7 @@ var jsDAVACL_Plugin = module.exports = jsDAV_ServerPlugin.extend({
*/
beforeBind: function(e, uri) {
var parentUri = Util.splitPath(uri)[0];
- this.checkPrivileges(parentUri, "{DAV:}bind", null, e.next);
+ this.checkPrivileges(parentUri, "{DAV:}bind", null, e.next.bind(e));
},
/**
@@ -813,7 +814,7 @@ var jsDAVACL_Plugin = module.exports = jsDAV_ServerPlugin.extend({
*/
beforeUnbind: function(e, uri) {
var parentUri = Util.splitPath(uri)[0];
- this.checkPrivileges(parentUri, "{DAV:}unbind", this.R_RECURSIVEPARENTS, e.next);
+ this.checkPrivileges(parentUri, "{DAV:}unbind", this.R_RECURSIVEPARENTS, e.next.bind(e));
},
/**
@@ -856,14 +857,15 @@ var jsDAVACL_Plugin = module.exports = jsDAV_ServerPlugin.extend({
}
var propHandlers = {
- "{DAV:}alternate-URI-set": function(prop, next) {
+ "{DAV:}alternate-uri-set": function(prop, next) {
delete requestedProperties[prop];
returnedProperties["200"]["{DAV:}alternate-URI-set"] = jsDAV_Property_HrefList.new(node.getAlternateUriSet());
next();
},
- "{DAV:}principal-URL": function(prop, next) {
+ "{DAV:}principal-url": function(prop, next) {
delete requestedProperties[prop];
returnedProperties["200"]["{DAV:}principal-URL"] = jsDAV_Property_Href.new(node.getPrincipalUrl() + "/");
+ next();
},
"{DAV:}group-member-set": function(prop, next) {
delete requestedProperties[prop];
@@ -918,7 +920,7 @@ var jsDAVACL_Plugin = module.exports = jsDAV_ServerPlugin.extend({
});
},
"{DAV:}current-user-privilege-set": function(prop, next) {
- self.checkPrivileges(uri, "{DAV:}read-current-user-privilege-set", self.R_PARENT, false, function(err, hasPriv) {
+ self.checkPrivileges(uri, "{DAV:}read-current-user-privilege-set", self.R_PARENT, function(err, hasPriv) {
if (!hasPriv) {
returnedProperties["403"]["{DAV:}current-user-privilege-set"] = null;
delete requestedProperties[prop];
@@ -939,7 +941,7 @@ var jsDAVACL_Plugin = module.exports = jsDAV_ServerPlugin.extend({
});
},
"{DAV:}acl": function(prop, next) {
- self.checkPrivileges(uri, "{DAV:}read-acl", self.R_PARENT, false, function(err, hasPriv) {
+ self.checkPrivileges(uri, "{DAV:}read-acl", self.R_PARENT, function(err, hasPriv) {
if (!hasPriv) {
delete requestedProperties[prop];
returnedProperties["403"]["{DAV:}acl"] = null;
@@ -976,7 +978,7 @@ var jsDAVACL_Plugin = module.exports = jsDAV_ServerPlugin.extend({
"{DAV:}acl", "{DAV:}acl-restrictions"];
// Adding principal properties
if (node.hasFeature(jsDAVACL_iPrincipal)) {
- propsToCheck.push("{DAV:}alternate-URI-set", "{DAV:}principal-URL",
+ propsToCheck.push("{DAV:}alternate-uri-set", "{DAV:}principal-url",
"{DAV:}group-member-set", "{DAV:}group-membership", "{DAV:}displayname");
}
// Adding ACL properties
@@ -989,6 +991,7 @@ var jsDAVACL_Plugin = module.exports = jsDAV_ServerPlugin.extend({
});
Async.list(propsToCheck)
+ .delay(0, 10)
.each(function(prop, next) {
if (propHandlers[prop])
propHandlers[prop](prop, next);
@@ -1090,7 +1093,7 @@ var jsDAVACL_Plugin = module.exports = jsDAV_ServerPlugin.extend({
*/
httpACL: function(e, uri) {
var self = this;
- this.handler.getRequestBody("utf8", null, function(err, body) {
+ this.handler.getRequestBody("utf8", null, false, function(err, body) {
if (err)
return e.next(err);
View
8 lib/DAVACL/principal.js
@@ -151,15 +151,15 @@ var jsDAVACL_Principal = module.exports = jsDAV_Node.extend(jsDAVACL_iPrincipal,
* @param array requestedProperties
* @return array
*/
- getProperties: function(requestedProperties) {
+ getProperties: function(requestedProperties, callback) {
var newProperties = {};
for (var propName, i = 0, l = requestedProperties.length; i < l; ++i) {
propName = requestedProperties[i];
if (this.principalProperties[propName])
newProperties[propName] = this.principalProperties[propName];
}
- return newProperties;
+ callback(null, newProperties);
},
/**
@@ -226,8 +226,8 @@ var jsDAVACL_Principal = module.exports = jsDAV_Node.extend(jsDAVACL_iPrincipal,
* @param array acl
* @return void
*/
- setACL: function(acl) {
- throw new Exc.MethodNotAllowed("Updating ACLs is not allowed here");
+ setACL: function(acl, callback) {
+ callback(new Exc.MethodNotAllowed("Updating ACLs is not allowed here"));
},
/**
View
2 lib/DAVACL/property/acl.js
@@ -171,7 +171,7 @@ var jsDAV_Acl = module.exports = jsDAV_Property.extend({
aXml.push("<d:href>", (this.prefixBaseUrl ? handler.server.getBaseUri() : "") + ace.principal + "/", "</d:href>");
}
- aXml.push("</d:pricipal><d:grant>");
+ aXml.push("</d:principal><d:grant>");
var privParts = ace.privilege.match(/^\{([^}]*)\}(.*)/);
aXml.push("<d:privilege>", "<d:" + privParts[2] + "/>", "</d:privilege>", "</d:grant>");
if (ace["protected"])
View
2 lib/VObject/component/VCalendar.js
@@ -91,7 +91,7 @@ var jsVObject_Component_VCalendar = module.exports = jsVObject_Component.extend(
if (!uid)
throw new Error("Event did not have a UID!");
- var it = new jsVObject_RecurrenceIterator(self, vevent.uid);
+ var it = jsVObject_RecurrenceIterator.new(self, vevent.uid);
it.fastForward(start);
while (it.valid() && it.getDTStart() < end) {
View
2 lib/VObject/component/VEvent.js
@@ -31,7 +31,7 @@ var jsVObject_Component_VEvent = module.exports = jsVObject_Component.extend({
*/
isInTimeRange: function(start, end) {
if (this.RRULE) {
- var it = new jsVObject_RecurrenceIterator(this);
+ var it = jsVObject_RecurrenceIterator.new(this);
it.fastForward(start);
// We fast-forwarded to a spot where the end-time of the
View
137 lib/shared/exceptions.js
@@ -112,6 +112,28 @@ exports.Conflict = function(msg, extra) {
exports.Conflict.prototype = new exports.jsDAV_Exception();
/**
+ * This exception is thrown when a client attempts to set conflicting
+ * permissions.
+ */
+exports.AceConflict = function(msg, extra) {
+ this.msg = msg || this.msg;
+
+ /**
+ * Adds in extra information in the xml response.
+ *
+ * This method adds the {DAV:}no-ace-conflict element as defined in rfc3744
+ *
+ * @param jsDAV_Handler handler
+ * @param String errorNode
+ * @return void
+ */
+ this.serialize = function(handler, errorNode) {
+ return errorNode + "<d:no-ace-conflict/>";
+ };
+};
+exports.AceConflict.prototype = new exports.Conflict();
+
+/**
* Locked
*
* The 423 is thrown when a client tried to access a resource that was locked,
@@ -158,6 +180,7 @@ exports.ConflictingLock.prototype = new exports.Locked();
* This Exception is thrown when a Node couldn't be found. It returns HTTP error
* code 404
*/
+exports.NotFound =
exports.FileNotFound = function(msg, extra) {
this.code = 404;
this.type = "FileNotFound";
@@ -179,6 +202,54 @@ exports.Forbidden = function(msg, extra) {
exports.Forbidden.prototype = new exports.jsDAV_Exception();
/**
+ * NeedPrivileges
+ *
+ * The 403-need privileges is thrown when a user didn't have the appropriate
+ * permissions to perform an operation
+ */
+exports.NeedPrivileges = function(uri, privileges) {
+ /**
+ * The relevant uri
+ *
+ * @var string
+ */
+ this.uri = uri
+
+ /**
+ * The privileges the user didn't have.
+ *
+ * @var array
+ */
+ this.privileges = privileges;
+
+ this.msg = "User did not have the required privileges (" + privileges.join("") + ") for path '" + uri + "'";
+
+ /**
+ * Adds in extra information in the xml response.
+ *
+ * This method adds the {DAV:}need-privileges element as defined in rfc3744
+ *
+ * @param jsDAV_Handler handler
+ * @param String errorNode
+ * @return void
+ */
+ this.serialize = function(handler, errorNode) {
+ var out = ["<d:need-privileges>"];
+
+ var privilege, privilegeParts;
+ for (var i = 0, l = this.privileges.length; i < l; ++i) {
+ privilege = this.privileges[i];
+ privilegeParts = privilege.match(/^\{([^}]*)\}(.*)$/);
+ out.push("<d:resource><d:href>", handler.server.getBaseUri() + this.uri,
+ "</d:href><d:privilege><d:" + privilegeParts[2] + "/></d:privilege></d:resource>");
+ }
+
+ return errorNode + out.join("") + "</d:need-privileges>";
+ };
+};
+exports.NeedPrivileges.prototype = new exports.Forbidden();
+
+/**
* InsufficientStorage
*
* This Exception can be thrown, when for example a harddisk is full or a quota
@@ -305,6 +376,72 @@ exports.PreconditionFailed = function(msg, extra) {
exports.PreconditionFailed.prototype = new exports.jsDAV_Exception();
/**
+ * This exception is thrown when a user tries to set a privilege that's marked
+ * as abstract.
+ */
+exports.NoAbstract = function(msg, extra) {
+ this.msg = msg || this.msg;
+
+ /**
+ * Adds in extra information in the xml response.
+ *
+ * This method adds the {DAV:}no-abstract element as defined in rfc3744
+ *
+ * @param jsDAV_Handler handler
+ * @param String errorNode
+ * @return void
+ */
+ this.serialize = function(server, errorNode) {
+ return errorNode + "<d:no-abstract/>";
+ };
+};
+exports.NoAbstract.prototype = new exports.PreconditionFailed();
+
+/**
+ * If a client tried to set a privilege assigned to a non-existant principal,
+ * this exception will be thrown.
+ */
+exports.NotRecognizedPrincipal = function(msg, extra) {
+ this.msg = msg || this.msg;
+
+ /**
+ * Adds in extra information in the xml response.
+ *
+ * This method adds the {DAV:}recognized-principal element as defined in rfc3744
+ *
+ * @param jsDAV_Handler handler
+ * @param String errorNode
+ * @return void
+ */
+ this.serialize = function(handler, errorNode) {
+ return errorNode + "<d:recognized-principal/>";
+ };
+};
+exports.NotRecognizedPrincipal.prototype = new exports.PreconditionFailed();
+
+/**
+ * If a client tried to set a privilege that doesn't exist, this exception will
+ * be thrown.
+ */
+exports.NotSupportedPrivilege = function(msg, extra) {
+ this.msg = msg || this.msg;
+
+ /**
+ * Adds in extra information in the xml response.
+ *
+ * This method adds the {DAV:}not-supported-privilege element as defined in rfc3744
+ *
+ * @param jsDAV_Handler handler
+ * @param String errorNode
+ * @return void
+ */
+ this.serialize = function(handler, errorNode) {
+ return errorNode + "<d:not-supported-privilege/>";
+ };
+};
+exports.NotSupportedPrivilege.prototype = new exports.PreconditionFailed();
+
+/**
* ReportNotImplemented
*
* This exception is thrown when the client requested an unknown report through

0 comments on commit 38e9e04

Please sign in to comment.
Something went wrong with that request. Please try again.