Skip to content
Browse files

renamed error classes to have lesser verbose invocations and 'finishe…

…d' porting CardDAV. Still need to port the VObject parser
  • Loading branch information...
1 parent 3b8b6d5 commit a45a15bf55a2e026246bc8e8e1ab9e68efe83f43 @mikedeboer committed Jan 27, 2013
View
122 lib/CardDAV/VCFExportPlugin.js
@@ -0,0 +1,122 @@
+/*
+ * @package jsDAV
+ * @subpackage CardDAV
+ * @copyright Copyright(c) 2013 Mike de Boer. <info AT mikedeboer DOT nl>
+ * @author Mike de Boer <info AT mikedeboer DOT nl>
+ * @license http://github.com/mikedeboer/jsDAV/blob/master/LICENSE MIT License
+ */
+"use strict";
+
+var jsDAV_Plugin = require("./../DAV/plugin");
+var jsCardDAV_Plugin = require("./plugin");
+var jsCardDAV_iAddressBook = require("./interfaces/iAddressBook");
+var jsVObject_Reader = require("./../VObject/reader");
+
+var Exc = require("./../shared/exceptions");
+var Util = require("./../shared/util");
+
+var Url = require("url");
+
+/**
+ * VCF Exporter
+ *
+ * This plugin adds the ability to export entire address books as .vcf files.
+ * This is useful for clients that don't support CardDAV yet. They often do
+ * support vcf files.
+ */
+var jsCardDAV_VCFExportPlugin = module.exports = jsDAV_Plugin.extend({
+ /**
+ * Reference to Handler class
+ *
+ * @var jsDAV_Handler
+ */
+ handler: null,
+
+ /**
+ * Initializes the plugin and registers event handlers
+ *
+ * @param jsDAV_Handler handler
+ * @return void
+ */
+ initialize: function(handler) {
+ this.handler = handler;
+ this.handler.addEventListener("beforeMethod", this.beforeMethod.bind(this));
+ },
+
+ /**
+ * 'beforeMethod' event handles. This event handles intercepts GET requests ending
+ * with ?export
+ *
+ * @param string method
+ * @param string uri
+ * @return bool
+ */
+ beforeMethod: function(e, method, uri) {
+ if (method != "GET")
+ return e.next();
+
+ var parsedUrl = Url.parse(this.handler.httpRequest.url, true);
+ if (!("export" in parsedUrl.query))
+ return e.next();
+
+ // splitting uri
+ uri = uri.split("?")[0]
+
+ var self = this;
+ this.handler.getNodeForPath(uri, function(err, node) {
+ if (err)
+ return e.next(err);
+ if (!node.hasFeature(jsCardDAV_iAddressBook))
+ return e.next();
+
+ // Checking ACL, if available.
+ var aclPlugin = self.handler.plugins.acl;
+ if (aclPlugin) {
+ aclPlugin.checkPrivileges(uri, "{DAV:}read", function(err, hasPriv) {
+ if (err)
+ return e.next(err);
+ afterAcl();
+ });
+ }
+ else
+ afterAcl();
+
+ function afterAcl() {
+
+ self.handler.getPropertiesForPath(uri, ["{" + jsCardDAV_Plugin.NS_CARDDAV + "}address-data"], 1, function(err, nodes) {
+ if (err)
+ return e.next(err);
+
+ // e.stop() to break the event chain
+ e.stop();
+ self.handler.httpResponse.writeHead(200, {"content-type": "text/directory"});
+ self.handler.httpResponse.end(self.generateVCF(nodes));
+ });
+ }
+ });
+ },
+
+ /**
+ * Merges all vcard objects, and builds one big vcf export
+ *
+ * @param array nodes
+ * @return string
+ */
+ generateVCF: function(nodes) {
+ var output = [];
+
+ for (var node, nodeData, i = 0, l = nodes.length; i < l; ++i) {
+ node = nodes[i];
+
+ if (node["200"]["{" + jsCardDAV_Plugin.NS_CARDDAV + "}address-data"])
+ continue;
+
+ nodeData = node["200"]["{" + jsCardDAV_Plugin.NS_CARDDAV + "}address-data"];
+
+ // Parsing this node so VObject can clean up the output.
+ output.push(jsVObject_Reader.read(nodeData).serialize());
+ }
+
+ return output.join("");
+ }
+});
View
210 lib/CardDAV/addressBookQueryParser.js
@@ -0,0 +1,210 @@
+/*
+ * @package jsDAV
+ * @subpackage CardDAV
+ * @copyright Copyright(c) 2013 Mike de Boer. <info AT mikedeboer DOT nl>
+ * @author Mike de Boer <info AT mikedeboer DOT nl>
+ * @license http://github.com/mikedeboer/jsDAV/blob/master/LICENSE MIT License
+ */
+"use strict";
+
+var Base = require("./../shared/base");
+var Exc = require("./../shared/exceptions");
+var Xml = require("./../shared/xml");
+
+var Xpath = require("xpath");
+
+/**
+ * Parses the addressbook-query report request body.
+ *
+ * Whoever designed this format, and the CalDAV equivalent even more so,
+ * has no feel for design.
+ */
+var jsCardDAV_AddressBookQueryParser = module.exports = Base.extend({
+ TEST_ANYOF: "anyof",
+ TEST_ALLOF: "allof",
+
+ MATCH_TYPES: ["contains", "equals", "starts-with", "ends-with"],
+
+ /**
+ * List of requested properties the client wanted
+ *
+ * @var array
+ */
+ requestedProperties: [],
+
+ /**
+ * The number of results the client wants
+ *
+ * null means it wasn't specified, which in most cases means 'all results'.
+ *
+ * @var int|null
+ */
+ limit: null,
+
+ /**
+ * List of property filters.
+ *
+ * @var array
+ */
+ filters: [],
+
+ /**
+ * Either TEST_ANYOF or TEST_ALLOF
+ *
+ * @var string
+ */
+ test: null,
+
+ /**
+ * DOM Document
+ *
+ * @var DOMDocument
+ */
+ dom: null,
+
+ /**
+ * DOM XPath object
+ *
+ * @var DOMXPath
+ */
+ xpath: null,
+
+ /**
+ * Creates the parser
+ *
+ * @param DOMDocument dom
+ */
+ initialize: function(dom) {
+ this.dom = dom;
+ },
+
+ /**
+ * Parses the request.
+ *
+ * @return void
+ * @throws Exc.BadRequest
+ */
+ parse: function() {
+ var filterNode = null;
+ var limit = parseInt(Xpath.select("number(/card:addressbook-query/card:limit/card:nresults)"), this.dom);
+ if (isNaN(limit))
+ limit = null;
+
+ var test;
+ var filter = Xpath.select("/card:addressbook-query/card:filter", this.dom);
+
+ // According to the CardDAV spec there needs to be exactly 1 filter
+ // element. However, KDE 4.8.2 contains a bug that will encode 0 filter
+ // elements, so this is a workaround for that.
+ //
+ // See: https://bugs.kde.org/show_bug.cgi?id=300047
+ if (filter.length === 0) {
+ test = null;
+ filter = null;
+ }
+ else if (filter.length === 1) {
+ filter = filter.item(0);
+ test = Xpath.select("string(@test)", filter);
+ }
+ else {
+ throw new Exc.BadRequest("Only one filter element is allowed");
+ }
+
+ if (!test)
+ test = this.TEST_ANYOF;
+ if (test !== this.TEST_ANYOF && test !== this.TEST_ALLOF)
+ throw new Exc.BadRequest("The test attribute must either hold 'anyof' or 'allof'");
+
+ var propFilters = [];
+
+ var propFilterNodes = Xpath.select("card:prop-filter", filter);
+ for (var i = 0, l = propFilterNodes.length; i < l; ++i)
+ propFilters.push(this.parsePropFilterNode(propFilterNodes[i]));
+
+ this.filters = propFilters;
+ this.limit = limit;
+ this.requestedProperties = Object.keys(Xml.parseProperties(this.dom.firstChild));
+ this.test = test;
+ },
+
+ /**
+ * Parses the prop-filter xml element
+ *
+ * @param DOMElement propFilterNode
+ * @return array
+ * @throws Exc.BadRequest
+ */
+ parsePropFilterNode: function(propFilterNode) {
+ var propFilter = {
+ name: propFilterNode.getAttribute("name"),
+ test: propFilterNode.getAttribute("test")
+ }
+ if (!propFilter.test)
+ propFilter.test = this.TEST_ANYOF;
+
+ propFilter["is-not-defined"] = Xpath.select("card:is-not-defined", propFilterNode).length > 0;
+ var paramFilterNodes = Xpath.select("card:param-filter", propFilterNode);
+
+ propFilter["param-filters"] = [];
+
+ for (var i = 0, l = paramFilterNodes.length; i < l; ++i)
+ propFilter["param-filters"].push(this.parseParamFilterNode(paramFilterNodes[i]));
+
+ propFilter["text-matches"] = [];
+ var textMatchNodes = Xpath.select("card:text-match", propFilterNode);
+ for (i = 0, l = textMatchNodes.length; i < l; ++i)
+ propFilter["text-matches"].push(this.parseTextMatchNode(textMatchNodes[i]));
+
+ return propFilter;
+ },
+
+ /**
+ * Parses the param-filter element
+ *
+ * @param DOMElement paramFilterNode
+ * @return array
+ * @throws Exc.BadRequest
+ */
+ parseParamFilterNode: function(paramFilterNode) {
+ var paramFilter = {
+ name: paramFilterNode.getAttribute("name"),
+ "is-not-defined": Xpath.select("card:is-not-defined", paramFilterNode).length > 0,
+ "text-match": null
+ };
+
+ var textMatch = Xpath.select("card:text-match", paramFilterNode);
+ if (textMatch.length > 0)
+ paramFilter["text-match"] = this.parseTextMatchNode(textMatch[0]);
+
+ return paramFilter;
+ },
+
+ /**
+ * Text match
+ *
+ * @param DOMElement textMatchNode
+ * @return array
+ * @throws Exc.BadRequest
+ */
+ parseTextMatchNode: function(textMatchNode) {
+ var matchType = textMatchNode.getAttribute("match-type");
+ if (!matchType)
+ matchType = "contains";
+
+ if (this.MATH_TYPES.indexOf(matchType) === -1)
+ throw new Exc.BadRequest("Unknown match-type: " + matchType);
+
+ var negateCondition = textMatchNode.getAttribute("negate-condition");
+ negateCondition = negateCondition == "yes";
+ var collation = textMatchNode.getAttribute("collation");
+ if (!collation)
+ collation = "i;unicode-casemap";
+
+ return {
+ "negate-condition": negateCondition,
+ collation: collation,
+ "match-type": matchType,
+ value: textMatchNode.nodeValue
+ }
+ }
+});
View
242 lib/CardDAV/userAddressBooks.js
@@ -0,0 +1,242 @@
+/*
+ * @package jsDAV
+ * @subpackage CardDAV
+ * @copyright Copyright(c) 2013 Mike de Boer. <info AT mikedeboer DOT nl>
+ * @author Mike de Boer <info AT mikedeboer DOT nl>
+ * @license http://github.com/mikedeboer/jsDAV/blob/master/LICENSE MIT License
+ */
+"use strict";
+
+var jsDAV_Directory = require("./../DAV/directory");
+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");
+
+/**
+ * UserAddressBooks class
+ *
+ * The UserAddressBooks collection contains a list of addressbooks associated with a user
+ */
+var jsCardDAV_UserAddressBooks = module.exports = jsDAV_Directory.extend(jsDAV_iExtendedCollection, jsDAVACL_iAcl, {
+ /**
+ * Principal uri
+ *
+ * @var array
+ */
+ principalUri: null,
+
+ /**
+ * carddavBackend
+ *
+ * @var jsCardDAV_iBackend
+ */
+ carddavBackend: null,
+
+ /**
+ * Constructor
+ *
+ * @param Backend\BackendInterface carddavBackend
+ * @param string principalUri
+ */
+ initialize: function(carddavBackend, principalUri) {
+ this.carddavBackend = carddavBackend;
+ this.principalUri = principalUri;
+ },
+
+ /**
+ * Returns the name of this object
+ *
+ * @return string
+ */
+ getName: function() {
+ return Util.splitPath(this.principalUri)[1];
+ },
+
+ /**
+ * Updates the name of this object
+ *
+ * @param string name
+ * @return void
+ */
+ setName: function(name, callback) {
+ callback(new Exc.MethodNotAllowed());
+ },
+
+ /**
+ * Deletes this object
+ *
+ * @return void
+ */
+ delete: function(callback) {
+ callback(new Exc.MethodNotAllowed());
+ },
+
+ /**
+ * Returns the last modification date
+ *
+ * @return int
+ */
+ getLastModified: function(callback) {
+ callback(null, null);
+ },
+
+ /**
+ * Creates a new file under this object.
+ *
+ * This is currently not allowed
+ *
+ * @param string filename
+ * @param resource data
+ * @return void
+ */
+ createFile: function(filename, data, callback) {
+ callback(new Exc.MethodNotAllowed("Creating new files in this collection is not supported"));
+ },
+
+ /**
+ * Creates a new directory under this object.
+ *
+ * This is currently not allowed.
+ *
+ * @param string filename
+ * @return void
+ */
+ createDirectory: function(filename, callback) {
+ callback(new Exc.MethodNotAllowed("Creating new collections in this collection is not supported"));
+ },
+
+ /**
+ * Returns a single calendar, by name
+ *
+ * @param string name
+ * @todo needs optimizing
+ * @return jsCardDAV_AddressBook
+ */
+ getChild: function(name, callback) {
+ this.getChildren(function(err, children) {
+ if (err)
+ return callback(err);
+
+ for (var i = 0, l = children.length; i < l; ++i) {
+ if (children[i].getName() == name)
+ return callback(null, children[i]);
+ }
+ callback(new Exc.NotFound("Addressbook with name '" + name + "' could not be found"));
+ });
+ },
+
+ /**
+ * Returns a list of addressbooks
+ *
+ * @return array
+ */
+ getChildren: function(callback) {
+ var self = this;
+ 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);
+ });
+ callback(null, objs);
+ });
+ },
+
+ /**
+ * Creates a new addressbook
+ *
+ * @param string name
+ * @param array resourceType
+ * @param array properties
+ * @return void
+ */
+ createExtendedCollection: function(name, resourceType, properties, callback) {
+ if (resourceType.indexOf("{" + jsCardDAV_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);
+ },
+
+ /**
+ * Returns the owner principal
+ *
+ * This must be a url to a principal, or null if there's no owner
+ *
+ * @return string|null
+ */
+ getOwner: function() {
+ return this.principalUri;
+ },
+
+ /**
+ * Returns a group principal
+ *
+ * This must be a url to a principal, or null if there's no owner
+ *
+ * @return string|null
+ */
+ getGroup: function() {
+ return null;
+ },
+
+ /**
+ * Returns a list of ACE's for this node.
+ *
+ * Each ACE has the following properties:
+ * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
+ * currently the only supported privileges
+ * * 'principal', a url to the principal who owns the node
+ * * 'protected' (optional), indicating that this ACE is not allowed to
+ * be updated.
+ *
+ * @return array
+ */
+ getACL: function(callback) {
+
+ callback(null, [
+ {
+ privilege: "{DAV:}read",
+ principal: this.principalUri,
+ "protected" : true
+ },
+ {
+ privilege: "{DAV:}write",
+ principal: this.principalUri,
+ "protected": true
+ }
+ ]);
+ },
+
+ /**
+ * Updates the ACL
+ *
+ * This method will receive a list of new ACE's.
+ *
+ * @param array acl
+ * @return void
+ */
+ setACL: function(acl, callback) {
+ callback(new Exc.MethodNotAllowed("Changing ACL is not yet supported"));
+ },
+
+ /**
+ * Returns the list of supported privileges for this node.
+ *
+ * The returned data structure is a list of nested privileges.
+ * See Sabre\DAVACL\Plugin::getDefaultSupportedPrivilegeSet for a simple
+ * standard structure.
+ *
+ * If null is returned from this method, the default privilege set is used,
+ * which is fine for most common usecases.
+ *
+ * @return array|null
+ */
+ getSupportedPrivilegeSet: function(callback) {
+ callback(null, null);
+ }
+});
View
2 lib/DAV/backends/dropbox/directory.js
@@ -73,7 +73,7 @@ var jsDAV_Dropbox_Directory = module.exports = jsDAV_Dropbox_Node.extend(jsDAV_D
var path = this.path + "/" + name;
this.client.metadata(path, function(status, stat) {
if (self.client.isError(status)) {
- return cbfsgetchild(new Exc.jsDAV_Exception_FileNotFound("File with name "
+ return cbfsgetchild(new Exc.FileNotFound("File with name "
+ path + " could not be located"));
}
cbfsgetchild(null, stat.is_dir
View
8 lib/DAV/backends/dropbox/tree.js
@@ -52,13 +52,13 @@ var jsDAV_Tree_Dropbox = module.exports = jsDAV_Tree.extend({
var realPath = this.getRealPath(path);
var nicePath = this.stripSandbox(realPath);
if (!this.insideSandbox(realPath))
- return cbfstree(new Exc.jsDAV_Exception_Forbidden("You are not allowed to access " + nicePath));
+ return cbfstree(new Exc.Forbidden("You are not allowed to access " + nicePath));
var self = this;
this.client.metadata(realPath, function(status, stat) {
//console.log("RECEIVED::",status,stat);
if (isError(status))
- return cbfstree(new Exc.jsDAV_Exception_FileNotFound("File at location " + nicePath + " not found"));
+ 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)
@@ -91,7 +91,7 @@ var jsDAV_Tree_Dropbox = module.exports = jsDAV_Tree.extend({
destination = this.getRealPath(destination);
if (!this.insideSandbox(destination)) {
- return cbfscopy(new Exc.jsDAV_Exception_Forbidden("You are not allowed to copy to " +
+ return cbfscopy(new Exc.Forbidden("You are not allowed to copy to " +
this.stripSandbox(destination)));
}
@@ -115,7 +115,7 @@ var jsDAV_Tree_Dropbox = module.exports = jsDAV_Tree.extend({
source = this.getRealPath(source);
destination = this.getRealPath(destination);
if (!this.insideSandbox(destination)) {
- return cbfsmove(new Exc.jsDAV_Exception_Forbidden("You are not allowed to move to " +
+ return cbfsmove(new Exc.Forbidden("You are not allowed to move to " +
this.stripSandbox(destination)));
}
this.client.mv(source, destination, function(status, res) {
View
2 lib/DAV/backends/fs/directory.js
@@ -141,7 +141,7 @@ var jsDAV_FS_Directory = module.exports = jsDAV_FS_Node.extend(jsDAV_Directory,
Fs.stat(path, function(err, stat) {
if (err || typeof stat == "undefined") {
- return cbfsgetchild(new Exc.jsDAV_Exception_FileNotFound("File with name "
+ return cbfsgetchild(new Exc.FileNotFound("File with name "
+ path + " could not be located"));
}
cbfsgetchild(null, stat.isDirectory()
View
2 lib/DAV/backends/fs/file.js
@@ -141,7 +141,7 @@ var jsDAV_FS_File = module.exports = jsDAV_FS_Node.extend(jsDAV_File, {
var self = this;
return Fs.stat(this.path, function(err, stat) {
if (err || !stat) {
- return cbfsgetsize(new Exc.jsDAV_Exception_FileNotFound("File at location "
+ return cbfsgetsize(new Exc.FileNotFound("File at location "
+ self.path + " not found"));
}
//_self.$stat = stat;
View
8 lib/DAV/backends/fs/tree.js
@@ -40,11 +40,11 @@ var jsDAV_Tree_Filesystem = module.exports = jsDAV_Tree.extend({
var realPath = this.getRealPath(path);
var nicePath = this.stripSandbox(realPath);
if (!this.insideSandbox(realPath))
- return cbfstree(new Exc.jsDAV_Exception_Forbidden("You are not allowed to access " + nicePath));
+ return cbfstree(new Exc.Forbidden("You are not allowed to access " + nicePath));
Fs.stat(realPath, function(err, stat) {
if (!Util.empty(err))
- return cbfstree(new Exc.jsDAV_Exception_FileNotFound("File at location " + nicePath + " not found"));
+ return cbfstree(new Exc.FileNotFound("File at location " + nicePath + " not found"));
cbfstree(null, stat.isDirectory()
? jsDAV_FS_Directory.new(realPath)
: jsDAV_FS_File.new(realPath))
@@ -86,7 +86,7 @@ var jsDAV_Tree_Filesystem = module.exports = jsDAV_Tree.extend({
*/
realCopy: function(source, destination, cbfsrcopy) {
if (!this.insideSandbox(destination)) {
- return cbfsrcopy(new Exc.jsDAV_Exception_Forbidden("You are not allowed to copy to " +
+ return cbfsrcopy(new Exc.Forbidden("You are not allowed to copy to " +
this.stripSandbox(destination)));
}
@@ -113,7 +113,7 @@ var jsDAV_Tree_Filesystem = module.exports = jsDAV_Tree.extend({
source = this.getRealPath(source);
destination = this.getRealPath(destination);
if (!this.insideSandbox(destination)) {
- return cbfsmove(new Exc.jsDAV_Exception_Forbidden("You are not allowed to move to " +
+ return cbfsmove(new Exc.Forbidden("You are not allowed to move to " +
this.stripSandbox(destination)));
}
Fs.rename(source, destination, cbfsmove);
View
8 lib/DAV/backends/ftp/directory.js
@@ -73,7 +73,7 @@ var jsDAV_Ftp_Directory = module.exports = jsDAV_Ftp_Node.extend(jsDAV_Directory
*/
getChild: function(stat, cbftpgetchild) {
if (typeof stat !== "object")
- return cbftpgetchild(new Exc.jsDAV_Exception_FileNotFound("Child node could not be retrieved"));
+ return cbftpgetchild(new Exc.FileNotFound("Child node could not be retrieved"));
var ftp = this.ftp;
var path = Path.join(this.path, stat.name);
@@ -90,7 +90,7 @@ var jsDAV_Ftp_Directory = module.exports = jsDAV_Ftp_Node.extend(jsDAV_Directory
ftp.$cache[path] = new jsDAV_Ftp_File(path, ftp);
else {
return cbftpgetchild(
- new Exc.jsDAV_Exception_UnsupportedMediaType(path));
+ new Exc.UnsupportedMediaType(path));
}
ftp.$cache[path].$stat = stat;
@@ -107,7 +107,7 @@ var jsDAV_Ftp_Directory = module.exports = jsDAV_Ftp_Node.extend(jsDAV_Directory
ftp.ls(Path.dirname(targetPath), function(err, stats) {
if (err)
return cbftpgetchild(
- new Exc.jsDAV_Exception_FileNotFound(err));
+ new Exc.FileNotFound(err));
var targetStat;
for (var i = 0; i < stats.length; i++) {
@@ -121,7 +121,7 @@ var jsDAV_Ftp_Directory = module.exports = jsDAV_Ftp_Node.extend(jsDAV_Directory
getDAVObject(targetStat.type, path);
else
return cbftpgetchild(
- new Exc.jsDAV_Exception_FileNotFound(targetPath));
+ new Exc.FileNotFound(targetPath));
});
}
*/
View
3 lib/DAV/backends/ftp/file.js
@@ -73,8 +73,7 @@ var jsDAV_Ftp_File = module.exports = jsDAV_Ftp_Node.extend(jsDAV_File, {
var path = this.path;
this.ftp.raw.dele(path, function(err){
if (err)
- return cbftpfiledel(new Exc.jsDAV_Exception_FileNotFound(
- "File " + path + " not found"));
+ return cbftpfiledel(new Exc.FileNotFound("File " + path + " not found"));
delete self.ftp.$cache[path];
cbftpfiledel();
View
10 lib/DAV/backends/ftp/tree.js
@@ -100,7 +100,7 @@ var jsDAV_Tree_Ftp = module.exports = jsDAV_Tree.extend({
Util.log(err, "error");
});
else
- return next(new Exc.jsDAV_Exception_FileNotFound(err));
+ return next(new Exc.FileNotFound(err));
}
else {
var file;
@@ -128,7 +128,7 @@ var jsDAV_Tree_Ftp = module.exports = jsDAV_Tree.extend({
}
else {
- next(new Exc.jsDAV_Exception_FileNotFound(err));
+ next(new Exc.FileNotFound(err));
}
}
});
@@ -164,9 +164,9 @@ var jsDAV_Tree_Ftp = module.exports = jsDAV_Tree.extend({
* @return void
*/
copy: function(source, destination, next) {
- next(new Exc.jsDAV_Exception_NotImplemented(
- "Could not copy from " + source + " to " + destination
- + ". COPY/DUPLICATE not implemented.")
+ next(new Exc.NotImplemented(
+ "Could not copy from " + source + " to " + destination +
+ ". COPY/DUPLICATE not implemented.")
);
},
View
2 lib/DAV/backends/sftp/directory.js
@@ -63,7 +63,7 @@ var jsDAV_SFTP_Directory = module.exports = jsDAV_SFTP_Node.extend(jsDAV_Directo
this.sftp.stat(path, function(err, stat) {
if (err || typeof stat == "undefined") {
- return cbfsgetchild(new Exc.jsDAV_Exception_FileNotFound("File with name "
+ return cbfsgetchild(new Exc.FileNotFound("File with name "
+ path + " could not be located"));
}
cbfsgetchild(null, stat.isDirectory()
View
2 lib/DAV/backends/sftp/file.js
@@ -69,7 +69,7 @@ var jsDAV_SFTP_File = module.exports = jsDAV_SFTP_Node.extend(jsDAV_File, {
var self = this;
this.sftp.stat(this.path, function(err, stat) {
if (err || !stat) {
- return cbfsgetsize(new Exc.jsDAV_Exception_FileNotFound("File at location "
+ return cbfsgetsize(new Exc.FileNotFound("File at location "
+ self.path + " not found"));
}
//self.$stat = stat;
View
2 lib/DAV/backends/sftp/tree.js
@@ -63,7 +63,7 @@ var jsDAV_Tree_Sftp = module.exports = jsDAV_Tree.extend({
var self = this;
this.sftp.stat(realPath, function(err, stat) {
if (!Util.empty(err))
- return cbfstree(new Exc.jsDAV_Exception_FileNotFound("File at location " + realPath + " not found"));
+ 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))
View
12 lib/DAV/directory.js
@@ -27,7 +27,7 @@ var jsDAV_Directory = module.exports = jsDAV_Node.extend(jsDAV_iCollection, {
* Generally its wise to override this, as this can usually be optimized
*
* @param string name
- * @throws jsDAV_Exception_FileNotFound
+ * @throws Exc.FileNotFound
* @return jsDAV_INode
*/
getChild: function(name, cbgetchildabs) {
@@ -40,7 +40,7 @@ var jsDAV_Directory = module.exports = jsDAV_Node.extend(jsDAV_iCollection, {
if (child.getName() == name)
return cbgetchildabs(null, child);
}
- cbgetchildabs(new Exc.jsDAV_Exception_FileNotFound("File not found: " + name));
+ cbgetchildabs(new Exc.FileNotFound("File not found: " + name));
});
},
@@ -49,11 +49,11 @@ var jsDAV_Directory = module.exports = jsDAV_Node.extend(jsDAV_iCollection, {
*
* @param string name Name of the file
* @param string data Initial payload
- * @throws jsDAV_Exception_Forbidden
+ * @throws Exc.Forbidden
* @return void
*/
createFile: function(name, data, cbcreatefileabs) {
- cbcreatefileabs(new Exc.jsDAV_Exception_Forbidden(
+ cbcreatefileabs(new Exc.Forbidden(
"Permission denied to create file (filename " + name + ")")
);
},
@@ -62,12 +62,12 @@ var jsDAV_Directory = module.exports = jsDAV_Node.extend(jsDAV_iCollection, {
* Creates a new subdirectory
*
* @param string name
- * @throws jsDAV_Exception_Forbidden
+ * @throws Exc.Forbidden
* @return void
*/
createDirectory: function(name, cbcreatedirabs) {
cbcreatedirabs(
- new Exc.jsDAV_Exception_Forbidden("Permission denied to create directory")
+ new Exc.Forbidden("Permission denied to create directory")
);
}
});
View
4 lib/DAV/file.js
@@ -29,7 +29,7 @@ var jsDAV_File = module.exports = jsDAV_Node.extend(jsDAV_iFile, {
*/
put: function(data, cbfileputabs) {
cbfileputabs(
- new Exc.jsDAV_Exception_Forbidden("Permission denied to change data")
+ new Exc.Forbidden("Permission denied to change data")
);
},
@@ -42,7 +42,7 @@ var jsDAV_File = module.exports = jsDAV_Node.extend(jsDAV_iFile, {
*/
get: function(cbfilegetabs) {
cbfilegetabs(
- new Exc.jsDAV_Exception_Forbidden("Permission denied to read this file")
+ new Exc.Forbidden("Permission denied to read this file")
);
},
View
60 lib/DAV/handler.js
@@ -237,7 +237,7 @@ jsDAV_Handler.STATUS_MAP = {
if (stop === true)
return;
// Unsupported method
- self.handleError(stop || new Exc.jsDAV_Exception_NotImplemented());
+ self.handleError(stop || new Exc.NotImplemented());
});
}
});
@@ -379,7 +379,7 @@ jsDAV_Handler.STATUS_MAP = {
function afterCheck() {
if (!node.hasFeature(jsDAV_iFile)) {
- return self.handleError(new Exc.jsDAV_Exception_NotImplemented(
+ return self.handleError(new Exc.NotImplemented(
"GET is only implemented on File objects"));
}
@@ -446,14 +446,14 @@ jsDAV_Handler.STATUS_MAP = {
// are inclusive
end = range[1] !== null ? range[1] + 1 : nodeSize;
if (start > nodeSize) {
- return self.handleError(new Exc.jsDAV_Exception_RequestedRangeNotSatisfiable(
+ return self.handleError(new Exc.RequestedRangeNotSatisfiable(
"The start offset (" + range[0] + ") exceeded the size of the entity ("
+ nodeSize + ")")
);
}
if (end < start) {
- return self.handleError(new Exc.jsDAV_Exception_RequestedRangeNotSatisfiable(
+ return self.handleError(new Exc.RequestedRangeNotSatisfiable(
"The end offset (" + range[1] + ") is lower than the start offset ("
+ range[0] + ")")
);
@@ -812,7 +812,7 @@ jsDAV_Handler.STATUS_MAP = {
// First we'll do a check to see if the resource already exists
this.getNodeForPath(uri, function(err, node) {
if (!Util.empty(err)) {
- if (err instanceof Exc.jsDAV_Exception_FileNotFound) {
+ if (err instanceof Exc.FileNotFound) {
// If we got here, the resource didn't exist yet.
// `data` is set to `null` to use streamed write.
self.createFile(uri, null, "binary", function(err) {
@@ -837,7 +837,7 @@ jsDAV_Handler.STATUS_MAP = {
return false;
// If the node is a collection, we'll deny it
if (!node.hasFeature(jsDAV_iFile))
- return self.handleError(new Exc.jsDAV_Exception_Conflict("PUT is not allowed on non-files."));
+ return self.handleError(new Exc.Conflict("PUT is not allowed on non-files."));
self.dispatchEvent("beforeWriteContent", uri, function(stop) {
if (stop === true)
@@ -890,15 +890,15 @@ jsDAV_Handler.STATUS_MAP = {
var contentType = req.headers["content-type"];
if (contentType.indexOf("application/xml") !== 0 && contentType.indexOf("text/xml") !== 0) {
// We must throw 415 for unsupported mkcol bodies
- return self.handleError(new Exc.jsDAV_Exception_UnsupportedMediaType(
+ return self.handleError(new Exc.UnsupportedMediaType(
"The request body for the MKCOL request must have an xml Content-Type"));
}
Xml.loadDOMDocument(requestBody, self.server.options.parser, function(err, dom) {
var firstChild = dom.firstChild;
if (Xml.toClarkNotation(firstChild) !== "{DAV:}mkcol") {
// We must throw 415 for unsupport mkcol bodies
- return self.handleError(new Exc.jsDAV_Exception_UnsupportedMediaType(
+ return self.handleError(new Exc.UnsupportedMediaType(
"The request body for the MKCOL request must be a {DAV:}mkcol request construct."));
}
@@ -913,7 +913,7 @@ jsDAV_Handler.STATUS_MAP = {
properties = Util.extend(properties, Xml.parseProperties(childNode, self.propertyMap));
}
if (!properties["{DAV:}resourcetype"]) {
- return self.handleError(new Exc.jsDAV_Exception_BadRequest(
+ return self.handleError(new Exc.BadRequest(
"The mkcol request must include a {DAV:}resourcetype property")
);
}
@@ -1077,7 +1077,7 @@ jsDAV_Handler.STATUS_MAP = {
self.dispatchEvent("report", reportName, dom, function(stop) {
if (stop !== true) {
// if dispatchEvent didn't return true, it means the report was not supported
- return self.handleError(new Exc.jsDAV_Exception_ReportNotImplemented());
+ return self.handleError(new Exc.ReportNotImplemented());
}
});
});
@@ -1197,7 +1197,7 @@ jsDAV_Handler.STATUS_MAP = {
else {
buff = Util.concatBuffers(buff);
if (contentLength && parseInt(contentLength, 10) != buff.length) {
- readDone(new Exc.jsDAV_Exception_BadRequest("Content-Length mismatch: Request Header claimed "
+ readDone(new Exc.BadRequest("Content-Length mismatch: Request Header claimed "
+ contentLength + " bytes, but received " + buff.length + " bytes"), buff);
}
else
@@ -1245,7 +1245,7 @@ jsDAV_Handler.STATUS_MAP = {
* Calculates the uri for a request, making sure that the base uri is stripped out
*
* @param {String} uri
- * @throws {jsDAV_Exception_Forbidden} A permission denied exception is thrown
+ * @throws {Exc.Forbidden} A permission denied exception is thrown
* whenever there was an attempt to supply a uri outside of the base uri
* @return {String}
*/
@@ -1270,7 +1270,7 @@ jsDAV_Handler.STATUS_MAP = {
return "";
}
else {
- throw new Exc.jsDAV_Exception_Forbidden("Requested uri (" + uri
+ throw new Exc.Forbidden("Requested uri (" + uri
+ ") is out of base uri (" + this.server.baseUri + ")");
}
};
@@ -1323,7 +1323,7 @@ jsDAV_Handler.STATUS_MAP = {
// request succeed if a resource exists at that url.
this.getNodeForPath(uri, function(err, n) {
if (!Util.empty(err)) {
- return cbprecond(new Exc.jsDAV_Exception_PreconditionFailed(
+ return cbprecond(new Exc.PreconditionFailed(
"An If-Match header was specified and the resource did not exist",
"If-Match"));
}
@@ -1338,7 +1338,7 @@ jsDAV_Handler.STATUS_MAP = {
return cbprecond(err);
if (etag !== ifMatch) {
- return cbprecond(new Exc.jsDAV_Exception_PreconditionFailed(
+ return cbprecond(new Exc.PreconditionFailed(
"An If-Match header was specified, but the ETag did not match",
"If-Match")
);
@@ -1383,7 +1383,7 @@ jsDAV_Handler.STATUS_MAP = {
// @todo call cbprecond() differently here?
}
else {
- cbprecond(new Exc.jsDAV_Exception_PreconditionFailed(
+ cbprecond(new Exc.PreconditionFailed(
"An If-None-Match header was specified, but the ETag "
+ "matched (or * was specified).", "If-None-Match")
);
@@ -1469,7 +1469,7 @@ jsDAV_Handler.STATUS_MAP = {
if (lastMod) {
lastMod = new Date("@" + lastMod);
if (lastMod > date) {
- return cbprecond(new Exc.jsDAV_Exception_PreconditionFailed(
+ return cbprecond(new Exc.PreconditionFailed(
"An If-Unmodified-Since header was specified, but the "
+ "entity has been changed since the specified date.",
"If-Unmodified-Since")
@@ -2228,30 +2228,30 @@ jsDAV_Handler.STATUS_MAP = {
// Making sure {DAV:}collection was specified as resourceType
if (resourceType.indexOf("{DAV:}collection") == -1) {
- return cbcreatecoll(new Exc.jsDAV_Exception_InvalidResourceType(
+ return cbcreatecoll(new Exc.InvalidResourceType(
"The resourceType for this collection must at least include {DAV:}collection")
);
}
// Making sure the parent exists
this.getNodeForPath(parentUri, function(err, parent) {
if (!Util.empty(err))
- return cbcreatecoll(new Exc.jsDAV_Exception_Conflict("Parent node does not exist"));
+ return cbcreatecoll(new Exc.Conflict("Parent node does not exist"));
// Making sure the parent is a collection
if (!parent.hasFeature(jsDAV_iCollection))
- return cbcreatecoll(new Exc.jsDAV_Exception_Conflict("Parent node is not a collection"));
+ return cbcreatecoll(new Exc.Conflict("Parent node is not a collection"));
// Making sure the child does not already exist
parent.getChild(newName, function(err, ch) {
// If we got here.. it means there's already a node on that url,
// and we need to throw a 405
if (typeof ch != "undefined") {
- return cbcreatecoll(new Exc.jsDAV_Exception_MethodNotAllowed(
+ return cbcreatecoll(new Exc.MethodNotAllowed(
"The resource you tried to create already exists")
);
}
- if (err && err.type != "jsDAV_Exception_FileNotFound")
+ if (err && err.type != "FileNotFound")
return cbcreatecoll(err);
self.dispatchEvent("beforeBind", uri, function(stop) {
@@ -2267,7 +2267,7 @@ jsDAV_Handler.STATUS_MAP = {
else {
// No special resourcetypes are supported
if (resourceType.length > 1) {
- return cbcreatecoll(new Exc.jsDAV_Exception_InvalidResourceType(
+ return cbcreatecoll(new Exc.InvalidResourceType(
"The {DAV:}resourcetype you specified is not supported here.")
);
}
@@ -2334,7 +2334,7 @@ jsDAV_Handler.STATUS_MAP = {
// Collecting the relevant HTTP headers
if (!this.httpRequest.headers["destination"])
- return cbcopymove(new Exc.jsDAV_Exception_BadRequest("The destination header was not supplied"));
+ return cbcopymove(new Exc.BadRequest("The destination header was not supplied"));
try {
destination = this.calculateUri(this.httpRequest.headers["destination"]);
@@ -2353,7 +2353,7 @@ jsDAV_Handler.STATUS_MAP = {
}
else {
// We need to throw a bad request exception, if the header was invalid
- return cbcopymove(new Exc.jsDAV_Exception_BadRequest(
+ return cbcopymove(new Exc.BadRequest(
"The HTTP Overwrite header should be either T or F")
);
}
@@ -2365,28 +2365,28 @@ jsDAV_Handler.STATUS_MAP = {
this.getNodeForPath(destinationDir, function(err, destinationParent) {
if (!Util.empty(err)) {
// If the destination parent node is not found, we throw a 409
- return cbcopymove(err.type == "jsDAV_Exception_FileNotFound"
- ? new Exc.jsDAV_Exception_Conflict("The destination node is not found")
+ return cbcopymove(err.type == "FileNotFound"
+ ? new Exc.Conflict("The destination node is not found")
: err);
}
if (!destinationParent.hasFeature(jsDAV_iCollection)) {
- return cbcopymove(new Exc.jsDAV_Exception_UnsupportedMediaType(
+ return cbcopymove(new Exc.UnsupportedMediaType(
"The destination node is not a collection")
);
}
self.getNodeForPath(destination, function(err, destinationNode) {
// Destination didn't exist, we're all good
if (!Util.empty(err)) {
- if (err.type == "jsDAV_Exception_FileNotFound")
+ if (err.type == "FileNotFound")
destinationNode = false;
else
return cbcopymove(err);
}
// If this succeeded, it means the destination already exists
// we"ll need to throw precondition failed in case overwrite is false
if (destinationNode && !overwrite) {
- return cbcopymove(new Exc.jsDAV_Exception_PreconditionFailed(
+ return cbcopymove(new Exc.PreconditionFailed(
"The destination node already exists, and the overwrite header is set to false",
"Overwrite"));
}
View
10 lib/DAV/node.js
@@ -34,21 +34,17 @@ var jsDAV_Node = module.exports = jsDAV_iNode.extend({
* @return void
*/
"delete": function(cbnodedel) {
- cbnodedel(
- new Exc.jsDAV_Exception_Forbidden("Permission denied to delete node")
- );
+ cbnodedel(new Exc.Forbidden("Permission denied to delete node"));
},
/**
* Renames the node
*
- * @throws jsDAV_Exception_Forbidden
+ * @throws Exc.Forbidden
* @param string name The new name
* @return void
*/
setName: function(name, cbnodesetname) {
- cbnodesetname(
- new Exc.jsDAV_Exception_Forbidden("Permission denied to rename file")
- );
+ cbnodesetname(new Exc.Forbidden("Permission denied to rename file"));
}
});
View
3 lib/DAV/objectTree.js
@@ -44,8 +44,7 @@ var jsDAV_ObjectTree = module.exports = jsDAV_Tree.extend({
// If this part of the path is just a dot, it actually means we can skip it
if (pathPart == "." || pathPart === "")
if (!currentNode || !currentNode.hasFeature(jsDAV_iCollection))
- return cbnextnpath();
- return cbnextnpath(new Exc.jsDAV_Exception_FileNotFound("Could not find node at path: " + path));
+ return cbnextnpath(new Exc.FileNotFound("Could not find node at path: " + path));
currentNode.getChild(pathPart, function(err, crt) {
if (err)
View
2 lib/DAV/plugins/auth.js
@@ -59,7 +59,7 @@ var jsDAV_Auth_Plugin = module.exports = jsDAV_ServerPlugin.extend({
* This method is called before any HTTP method and forces users to be authenticated
*
* @param string method
- * @throws jsDAV_Exception_NotAuthenticated
+ * @throws Exc.NotAuthenticated
* @return bool
*/
beforeMethod: function(e, method) {
View
2 lib/DAV/plugins/auth/abstractBasic.js
@@ -64,7 +64,7 @@ var jsDAV_Auth_Backend_AbstractBasic = module.exports = jsDAV_Auth_iBackend.exte
* If authentication is succesful, true must be returned.
* If authentication fails, an exception must be thrown.
*
- * @throws jsDAV_Exception_NotAuthenticated
+ * @throws Exc.NotAuthenticated
* @return bool
*/
authenticate: function(handler, realm, cbauth) {
View
34 lib/DAV/plugins/locks.js
@@ -74,7 +74,7 @@ var jsDAV_Locks_Plugin = module.exports = jsDAV_ServerPlugin.extend({
else {
self.handler.getNodeForPath(path, function(err, node) {
if (err)
- return next((err instanceof Exc.jsDAV_Exception_FileNotFound) ? null : err);
+ return next((err instanceof Exc.FileNotFound) ? null : err);
if (node.hasFeature(jsDAV_iLockable))
val = true;
afterGetNode();
@@ -126,22 +126,22 @@ var jsDAV_Locks_Plugin = module.exports = jsDAV_ServerPlugin.extend({
case "PROPPATCH" :
case "PUT" :
this.validateLock(null, false, function(err, isValid, lastLock) {
- e.next(err ? err : !isValid ? new Exc.jsDAV_Exception_Locked(lastLock) : null);
+ e.next(err ? err : !isValid ? new Exc.Locked(lastLock) : null);
});
break;
case "MOVE" :
this.validateLock([
this.handler.getRequestUri(),
this.handler.calculateUri(req.headers["destination"])
], false, function(err, isValid, lastLock) {
- e.next(err ? err : !isValid ? new Exc.jsDAV_Exception_Locked(lastLock) : null);
+ e.next(err ? err : !isValid ? new Exc.Locked(lastLock) : null);
});
break;
case "COPY" :
this.validateLock(this.handler.calculateUri(req.headers["destination"]),
false,
function(err, isValid, lastLock) {
- e.next(err ? err : !isValid ? new Exc.jsDAV_Exception_Locked(lastLock) : null);
+ e.next(err ? err : !isValid ? new Exc.Locked(lastLock) : null);
});
break;
default:
@@ -204,7 +204,7 @@ var jsDAV_Locks_Plugin = module.exports = jsDAV_ServerPlugin.extend({
currentPath += uriPart;
self.handler.getNodeForPath(currentPath, function(err, node) {
if (err)
- return next((err instanceof Exc.jsDAV_Exception_FileNotFound) ? null : err);
+ return next((err instanceof Exc.FileNotFound) ? null : err);
if (node.hasFeature(jsDAV_iLockable)) {
node.getLocks(function(err, locks) {
@@ -270,7 +270,7 @@ var jsDAV_Locks_Plugin = module.exports = jsDAV_ServerPlugin.extend({
if (!isValid) {
// If the existing lock was an exclusive lock, we need to fail
if (!lastLock || lastLock.scope == jsDAV_Locks_LockInfo.EXCLUSIVE)
- return e.next(new Exc.jsDAV_Exception_ConflictingLock(lastLock));
+ return e.next(new Exc.ConflictingLock(lastLock));
}
self.handler.getRequestBody("utf8", function(err, body) {
@@ -284,7 +284,7 @@ var jsDAV_Locks_Plugin = module.exports = jsDAV_ServerPlugin.extend({
lockInfo.depth = self.handler.getHTTPDepth();
lockInfo.uri = uri;
if (lastLock && lockInfo.scope != jsDAV_Locks_LockInfo.SHARED)
- return e.next(new Exc.jsDAV_Exception_ConflictingLock(lastLock));
+ return e.next(new Exc.ConflictingLock(lastLock));
}
else if (lastLock) {
// This must have been a lock refresh
@@ -295,7 +295,7 @@ var jsDAV_Locks_Plugin = module.exports = jsDAV_ServerPlugin.extend({
}
else {
// There was neither a lock refresh nor a new lock request
- return e.next(new Exc.jsDAV_Exception_BadRequest("An xml body is required for lock requests"));
+ return e.next(new Exc.BadRequest("An xml body is required for lock requests"));
}
try {
@@ -312,7 +312,7 @@ var jsDAV_Locks_Plugin = module.exports = jsDAV_ServerPlugin.extend({
// If this is not the case, we need to create it first
self.handler.getNodeForPath(uri, function(err, node) {
if (err) {
- if (err instanceof Exc.jsDAV_Exception_FileNotFound) {
+ if (err instanceof Exc.FileNotFound) {
// It didn't, lets create it
self.handler.createFile(uri, new Buffer(0), "utf8", function(err) {
if (err)
@@ -364,7 +364,7 @@ var jsDAV_Locks_Plugin = module.exports = jsDAV_ServerPlugin.extend({
// If the locktoken header is not supplied, we need to throw a bad request exception
if (!lockToken)
- return e.next(new Exc.jsDAV_Exception_BadRequest("No lock token was supplied"));
+ return e.next(new Exc.BadRequest("No lock token was supplied"));
this.getLocks(uri, false, function(err, locks) {
if (err)
@@ -392,7 +392,7 @@ var jsDAV_Locks_Plugin = module.exports = jsDAV_ServerPlugin.extend({
}
else {
// If we got here, it means the locktoken was invalid
- e.next(new Exc.jsDAV_Exception_LockTokenMatchesRequestUri());
+ e.next(new Exc.LockTokenMatchesRequestUri());
}
});
},
@@ -421,7 +421,7 @@ var jsDAV_Locks_Plugin = module.exports = jsDAV_ServerPlugin.extend({
self.handler.getNodeForPath(uri, function(err, node) {
// In case the node didn't exist, this could be a lock-null request
- if (err && !(err instanceof Exc.jsDAV_Exception_FileNotFound))
+ if (err && !(err instanceof Exc.FileNotFound))
return cblock(err);
if (node && node.hasFeature(jsDAV_iLockable))
@@ -430,7 +430,7 @@ var jsDAV_Locks_Plugin = module.exports = jsDAV_ServerPlugin.extend({
if (self.locksBackend)
return self.locksBackend.lock(uri, lockInfo, cblock);
- cblock(new Exc.jsDAV_Exception_MethodNotAllowed("Locking support is not "
+ cblock(new Exc.MethodNotAllowed("Locking support is not "
+ "enabled for this resource. No Locking backend was found so if you "
+ "didn't expect this error, please check your configuration."));
});
@@ -459,7 +459,7 @@ var jsDAV_Locks_Plugin = module.exports = jsDAV_ServerPlugin.extend({
self.handler.getNodeForPath(uri, function(err, node) {
// In case the node didn't exist, this could be a lock-null request
- if (err && !(err instanceof Exc.jsDAV_Exception_FileNotFound))
+ if (err && !(err instanceof Exc.FileNotFound))
return cbunlock(err);
if (node && node.hasFeature(jsDAV_iLockable))
@@ -488,7 +488,7 @@ var jsDAV_Locks_Plugin = module.exports = jsDAV_ServerPlugin.extend({
else if (header.toLowerCase() == "infinite")
header = jsDAV_Locks_LockInfo.TIMEOUT_INFINITE;
else
- throw new Exc.jsDAV_Exception_BadRequest("Invalid HTTP timeout header");
+ throw new Exc.BadRequest("Invalid HTTP timeout header");
}
else {
header = 0;
@@ -612,7 +612,7 @@ var jsDAV_Locks_Plugin = module.exports = jsDAV_ServerPlugin.extend({
}
self.handler.getNodeForPath(uri, function(err, node) {
if (err)
- return next3((err instanceof Exc.jsDAV_Exception_FileNotFound) ? null : err);
+ return next3((err instanceof Exc.FileNotFound) ? null : err);
node.getETag(function(err, etag) {
if (err)
return next3(err);
@@ -663,7 +663,7 @@ var jsDAV_Locks_Plugin = module.exports = jsDAV_ServerPlugin.extend({
return next2(err);
if (!tokensStopped) {
// No conditions matched, so we fail
- return next2(new Exc.jsDAV_Exception_PreconditionFailed("The tokens "
+ return next2(new Exc.PreconditionFailed("The tokens "
+ "provided in the if header did not match", "If"));
}
stopped = true;
View
2 lib/DAV/plugins/temporaryfilefilter.js
@@ -187,7 +187,7 @@ var jsDAV_TemporaryFileFilter_Plugin = module.exports = jsDAV_ServerPlugin.exten
var self = this;
Fs.exists(tempLocation, function(exists) {
if (exists && self.handler.httpRequest.headers["if-none-match"]) {
- return e.next(new Exc.jsDAV_Exception_PreconditionFailed(
+ return e.next(new Exc.PreconditionFailed(
"The resource already exists, and an If-None-Match header was supplied")
);
}
View
4 lib/DAV/simpleDirectory.js
@@ -78,14 +78,14 @@ var jsDAV_SimpleDirectory = module.exports = jsDAV_Directory.extend({
* Generally its wise to override this, as this can usually be optimized
*
* @param string name
- * @throws jsDAV_Exception_FileNotFound
+ * @throws Exc.FileNotFound
* @return jsDAV_iNode
*/
getChild: function(name, callback) {
if (this.children[name])
callback(null, this.children[name]);
else
- callback(new Exc.jsDAV_Exception_FileNotFound("File not found: " + name));
+ callback(new Exc.FileNotFound("File not found: " + name));
},
/**
View
6 lib/DAV/tree.js
@@ -74,7 +74,7 @@ var jsDAV_Tree = module.exports = Base.extend({
/**
* This function must return an iNode object for a path
- * If a Path doesn't exist, thrown an jsDAV_Exception_FileNotFound
+ * If a Path doesn't exist, thrown an Exc.FileNotFound
*
* @param string path
* @throws Exception_FileNotFound
@@ -92,7 +92,7 @@ var jsDAV_Tree = module.exports = Base.extend({
copy: function(sourcePath, destinationPath, cbcopytree) {
var self = this;
if (!this.insideSandbox(destinationPath)) {
- return cbcopytree(new Exc.jsDAV_Exception_Forbidden("You are not allowed to copy to " +
+ return cbcopytree(new Exc.Forbidden("You are not allowed to copy to " +
this.stripSandbox(destinationPath)));
}
this.getNodeForPath(sourcePath, function(err, sourceNode) {
@@ -124,7 +124,7 @@ var jsDAV_Tree = module.exports = Base.extend({
var sourceName = parts[1];
parts = Util.splitPath(destinationPath);
if (!this.insideSandbox(destinationPath)) {
- return cbmovetree(new Exc.jsDAV_Exception_Forbidden("You are not allowed to move to " +
+ return cbmovetree(new Exc.Forbidden("You are not allowed to move to " +
this.stripSandbox(destinationPath)));
}
var destinationDir = parts[0];
View
2 lib/DAVACL/abstractPrincipalCollection.js
@@ -120,7 +120,7 @@ var jsDAVACL_AbstractPrincipalCollection = module.exports = jsDAV_Directory.exte
*
* @param string name
* @param Function callback
- * @throws jsDAV_Exception_NotFound
+ * @throws Exc.NotFound
* @return IPrincipal
*/
getChild: function(name, callback) {
View
1,843 lib/DAVACL/plugin.js
543 additions, 1,300 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
124 lib/shared/exceptions.js
@@ -79,7 +79,7 @@ exports.jsDAV_Exception = function(msg, extra) {
}
};
};
-require('util').inherits(exports.jsDAV_Exception, Error);
+require("util").inherits(exports.jsDAV_Exception, Error);
/**
@@ -88,35 +88,35 @@ require('util').inherits(exports.jsDAV_Exception, Error);
* The BadRequest is thrown when the user submitted an invalid HTTP request
* BadRequest
*/
-exports.jsDAV_Exception_BadRequest = function(msg, extra) {
+exports.BadRequest = function(msg, extra) {
this.code = 400;
- this.type = "jsDAV_Exception_BadRequest";
+ this.type = "BadRequest";
this.message = msg || this.type;
};
-exports.jsDAV_Exception_BadRequest.prototype = new exports.jsDAV_Exception();
+exports.BadRequest.prototype = new exports.jsDAV_Exception();
/**
* Conflict
*
* A 409 Conflict is thrown when a user tried to make a directory over an existing
* file or in a parent directory that doesn't exist.
*/
-exports.jsDAV_Exception_Conflict = function(msg, extra) {
+exports.Conflict = function(msg, extra) {
this.code = 409;
- this.type = "jsDAV_Exception_Conflict";
+ this.type = "Conflict";
this.message = msg || this.type;
};
-exports.jsDAV_Exception_Conflict.prototype = new exports.jsDAV_Exception();
+exports.Conflict.prototype = new exports.jsDAV_Exception();
/**
* Locked
*
* The 423 is thrown when a client tried to access a resource that was locked,
* without supplying a valid lock token
*/
-exports.jsDAV_Exception_Locked = function(lock) {
+exports.Locked = function(lock) {
this.code = 423;
- this.type = this.message = "jsDAV_Exception_Locked";
+ this.type = this.message = "Locked";
this.lock = lock;
this.serialize = function(handler, errorNode) {
@@ -127,16 +127,16 @@ exports.jsDAV_Exception_Locked = function(lock) {
return errorNode;
};
};
-exports.jsDAV_Exception_Locked.prototype = new exports.jsDAV_Exception();
+exports.Locked.prototype = new exports.jsDAV_Exception();
/**
* ConflictingLock
*
* Similar to Exception_Locked, this exception thrown when a LOCK request
* was made, on a resource which was already locked
*/
-exports.jsDAV_Exception_ConflictingLock = function(lock) {
- this.type = this.message = "jsDAV_Exception_ConflictingLock";
+exports.ConflictingLock = function(lock) {
+ this.type = this.message = "ConflictingLock";
this.lock = lock;
this.serialize = function(handler, errorNode) {
@@ -147,46 +147,46 @@ exports.jsDAV_Exception_ConflictingLock = function(lock) {
return errorNode;
};
};
-exports.jsDAV_Exception_ConflictingLock.prototype = new exports.jsDAV_Exception_Locked();
+exports.ConflictingLock.prototype = new exports.Locked();
/**
* FileNotFound
*
* This Exception is thrown when a Node couldn't be found. It returns HTTP error
* code 404
*/
-exports.jsDAV_Exception_FileNotFound = function(msg, extra) {
+exports.FileNotFound = function(msg, extra) {
this.code = 404;
- this.type = "jsDAV_Exception_FileNotFound";
+ this.type = "FileNotFound";
this.message = msg || this.type;
};
-exports.jsDAV_Exception_FileNotFound.prototype = new exports.jsDAV_Exception();
+exports.FileNotFound.prototype = new exports.jsDAV_Exception();
/**
* Forbidden
*
* This exception is thrown whenever a user tries to do an operation he's not
* allowed to
*/
-exports.jsDAV_Exception_Forbidden = function(msg, extra) {
+exports.Forbidden = function(msg, extra) {
this.code = 403;
- this.type = "jsDAV_Exception_Forbidden";
+ this.type = "Forbidden";
this.message = msg || this.type;
};
-exports.jsDAV_Exception_Forbidden.prototype = new exports.jsDAV_Exception();
+exports.Forbidden.prototype = new exports.jsDAV_Exception();
/**
* InsufficientStorage
*
* This Exception can be thrown, when for example a harddisk is full or a quota
* is exceeded
*/
-exports.jsDAV_Exception_InsufficientStorage = function(msg, extra) {
+exports.InsufficientStorage = function(msg, extra) {
this.code = 507;
- this.type = "jsDAV_Exception_InsufficientStorage";
+ this.type = "InsufficientStorage";
this.message = msg || this.type;
};
-exports.jsDAV_Exception_InsufficientStorage.prototype = new exports.jsDAV_Exception();
+exports.InsufficientStorage.prototype = new exports.jsDAV_Exception();
/**
* InvalidResourceType
@@ -196,39 +196,39 @@ exports.jsDAV_Exception_InsufficientStorage.prototype = new exports.jsDAV_Except
*
* See RFC5689 section 3.3
*/
-exports.jsDAV_Exception_InvalidResourceType = function(msg, extra) {
- this.type = "jsDAV_Exception_InvalidResourceType";
+exports.InvalidResourceType = function(msg, extra) {
+ this.type = "InvalidResourceType";
this.message = msg || this.type;
this.serialize = function(handler, errorNode) {
return errorNode + "<d:valid-resourcetype />";
};
};
-exports.jsDAV_Exception_InvalidResourceType.prototype = new exports.jsDAV_Exception_Forbidden();
+exports.InvalidResourceType.prototype = new exports.Forbidden();
/**
* LockTokenMatchesRequestUri
*
* This exception is thrown by UNLOCK if a supplied lock-token is invalid
*/
-exports.jsDAV_Exception_LockTokenMatchesRequestUri = function() {
- this.type = "jsDAV_Exception_LockTokenMatchesRequestUri";
+exports.LockTokenMatchesRequestUri = function() {
+ this.type = "LockTokenMatchesRequestUri";
this.message = "The locktoken supplied does not match any locks on this entity";
this.serialize = function(handler, errorNode) {
return errorNode + "<d:lock-token-matches-request-uri />";
};
};
-exports.jsDAV_Exception_LockTokenMatchesRequestUri.prototype = new exports.jsDAV_Exception_Conflict();
+exports.LockTokenMatchesRequestUri.prototype = new exports.Conflict();
/**
* MethodNotAllowed
*
* The 405 is thrown when a client tried to create a directory on an already existing directory
*/
-exports.jsDAV_Exception_MethodNotAllowed = function(msg, extra) {
+exports.MethodNotAllowed = function(msg, extra) {
this.code = 405;
- this.type = "jsDAV_Exception_MethodNotAllowed";
+ this.type = "MethodNotAllowed";
this.message = msg || this.type;
this.getHTTPHeaders = function(handler, cbmethods) {
@@ -239,33 +239,46 @@ exports.jsDAV_Exception_MethodNotAllowed = function(msg, extra) {
});
};
};
-exports.jsDAV_Exception_MethodNotAllowed.prototype = new exports.jsDAV_Exception();
+exports.MethodNotAllowed.prototype = new exports.jsDAV_Exception();
/**
* NotAuthenticated
*
* This exception is thrown when the client did not provide valid
* authentication credentials.
*/
-exports.jsDAV_Exception_NotAuthenticated = function(msg, extra) {
+exports.NotAuthenticated = function(msg, extra) {
this.code = 401;
- this.type = "jsDAV_Exception_NotAuthenticated";
+ this.type = "NotAuthenticated";
this.message = msg || this.type;
};
-exports.jsDAV_Exception_NotAuthenticated.prototype = new exports.jsDAV_Exception();
+exports.NotAuthenticated.prototype = new exports.jsDAV_Exception();
/**
* NotImplemented
*
* This exception is thrown when the client tried to call an unsupported HTTP
* method or other feature
*/
-exports.jsDAV_Exception_NotImplemented = function(msg, extra) {
+exports.NotImplemented = function(msg, extra) {
this.code = 501;
- this.type = "jsDAV_Exception_NotImplemented";
+ this.type = "NotImplemented";
this.message = msg || this.type;
};
-exports.jsDAV_Exception_NotImplemented.prototype = new exports.jsDAV_Exception();
+exports.NotImplemented.prototype = new exports.jsDAV_Exception();
+
+/**
+ * Payment Required
+ *
+ * The PaymentRequired exception may be thrown in a case where a user must pay
+ * to access a certain resource or operation.
+ */
+exports.PaymentRequired = function(msg, extra) {
+ this.code = 402;
+ this.type = "PaymentRequired";
+ this.message = msg || this.type;
+};
+exports.PaymentRequired.prototype = new exports.jsDAV_Exception();
/**
* PreconditionFailed
@@ -274,9 +287,9 @@ exports.jsDAV_Exception_NotImplemented.prototype = new exports.jsDAV_Exception()
* like for example an If, If-None-Match or If-Match header, which caused the HTTP
* request to not execute (the condition of the header failed)
*/
-exports.jsDAV_Exception_PreconditionFailed = function(msg, extra) {
+exports.PreconditionFailed = function(msg, extra) {
this.code = 412;
- this.type = "jsDAV_Exception_PreconditionFailed";
+ this.type = "PreconditionFailed";
this.message = msg || this.type;
this.header = extra;
@@ -286,46 +299,59 @@ exports.jsDAV_Exception_PreconditionFailed = function(msg, extra) {
: errorNode;
};
};
-exports.jsDAV_Exception_PreconditionFailed.prototype = new exports.jsDAV_Exception();
+exports.PreconditionFailed.prototype = new exports.jsDAV_Exception();
/**
* ReportNotImplemented
*
* This exception is thrown when the client requested an unknown report through
* the REPORT method
*/
-exports.jsDAV_Exception_ReportNotImplemented = function(msg, extra) {
- this.type = "jsDAV_Exception_ReportNotImplemented";
+exports.ReportNotImplemented = function(msg, extra) {
+ this.type = "ReportNotImplemented";
this.message = msg || this.type;
this.serialize = function(handler, errorNode) {
return errorNode + "<d:supported-report/>";
};
};
-exports.jsDAV_Exception_ReportNotImplemented.prototype = new exports.jsDAV_Exception_NotImplemented();
+exports.ReportNotImplemented.prototype = new exports.NotImplemented();
/**
* RequestedRangeNotSatisfiable
*
* This exception is normally thrown when the user
* request a range that is out of the entity bounds.
*/
-exports.jsDAV_Exception_RequestedRangeNotSatisfiable = function(msg, extra) {
+exports.RequestedRangeNotSatisfiable = function(msg, extra) {
this.code = 416;
- this.type = "jsDAV_Exception_RequestedRangeNotSatisfiable";
+ this.type = "RequestedRangeNotSatisfiable";
+ this.message = msg || this.type;
+};
+exports.RequestedRangeNotSatisfiable.prototype = new exports.jsDAV_Exception();
+
+/**
+ * ServiceUnavailable
+ *
+ * This exception is thrown in case the service
+ * is currently not available (e.g. down for maintenance).
+ */
+exports.ServiceUnavailable = function(msg, extra) {
+ this.code = 503;
+ this.type = "ServiceUnavailable";
this.message = msg || this.type;
};
-exports.jsDAV_Exception_RequestedRangeNotSatisfiable.prototype = new exports.jsDAV_Exception();
+exports.ServiceUnavailable.prototype = new exports.jsDAV_Exception();
/**
* UnSupportedMediaType
*
* The 415 Unsupported Media Type status code is generally sent back when the client
* tried to call an HTTP method, with a body the server didn't understand
*/
-exports.jsDAV_Exception_UnsupportedMediaType = function(msg, extra) {
+exports.UnsupportedMediaType = function(msg, extra) {
this.code = 415;
- this.type = "jsDAV_Exception_UnsupportedMediaType";
+ this.type = "UnsupportedMediaType";
this.message = msg || this.type;
};
-exports.jsDAV_Exception_UnsupportedMediaType.prototype = new exports.jsDAV_Exception();
+exports.UnsupportedMediaType.prototype = new exports.jsDAV_Exception();
View
10 lib/shared/xml.js
@@ -146,17 +146,17 @@ exports.escapeXml = function(str) {
/**
* This method provides a generic way to load a DOMDocument for WebDAV use.
*
- * This method throws a jsDAV_Exception_BadRequest exception for any xml errors.
+ * This method throws a Exc.BadRequest exception for any xml errors.
* It does not preserve whitespace, and it converts the DAV: namespace to urn:DAV.
*
* @param string xml
* @param string which 'libxml' or 'xmldom'. Default: 'xmldom'
- * @throws jsDAV_Exception_BadRequest
+ * @throws Exc.BadRequest
* @return DOMDocument
*/
exports.loadDOMDocument = function(xml, which, callback) {
if (!xml)
- return callback(new Exc.jsDAV_Exception_BadRequest("Empty XML document sent"));
+ return callback(new Exc.BadRequest("Empty XML document sent"));
which = which || "xmldom";
var root;
@@ -171,8 +171,8 @@ exports.loadDOMDocument = function(xml, which, callback) {
: exports.xmlParseError(parser.parseFromString(xml).documentElement);
}
catch (ex) {
- return callback(new Exc.jsDAV_Exception_BadRequest(
- "The request body had an invalid XML body. (message: " + ex.message + ")"));
+ return callback(new Exc.BadRequest("The request body had an invalid XML body. (message: " +
+ ex.message + ")"));
}
callback(null, root);

0 comments on commit a45a15b

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