Skip to content

Commit

Permalink
Merge branch 'master' into caldav-backend
Browse files Browse the repository at this point in the history
Conflicts:
	lib/VObject/property/dateTime.js
  • Loading branch information
mikedeboer committed Oct 8, 2015
2 parents 98aa5c6 + fb29d50 commit 5cd753d
Show file tree
Hide file tree
Showing 36 changed files with 1,910 additions and 144 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ improvements and bugfixes, to see if they can be ported to jsDAV.
* Supporting class 1, 2 and 3 Webdav servers
* Custom property support
* Locking support
* Pass all Litmus tests

## Features in development

* Pass all Litmus tests
* CalDAV (to be tested with Evolution, iCal, iPhone and Lightning).

## Supported RFC's
Expand Down Expand Up @@ -55,4 +55,4 @@ See the [wiki](https://github.com/mikedeboer/jsDAV/wiki) for more information or
ask a question in the [mailing list](https://groups.google.com/d/forum/jsdav)!


Amsterdam, 2010. Mike de Boer.
Amsterdam, 2010. Mike de Boer.
75 changes: 75 additions & 0 deletions examples/data/addressbook/postgres.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* @package jsDAV
* @subpackage CalDAV
* @copyright Copyright(c) 2013 Mike de Boer. <info AT mikedeboer DOT nl>
* @author Daniel Laxar
* @license http://github.com/mikedeboer/jsDAV/blob/master/LICENSE MIT License
*/
"use strict";

var Async = require("asyncjs");

exports.init = function(pg, skipInit, callback) {
if (skipInit)
return callback(null);

var operations = [
// Create unique indexes.
{
query: "CREATE TABLE users (" +
"username VARCHAR(50)," +
"password TEXT" +
")"
},
{
query: "CREATE TABLE principals (" +
"uri VARCHAR(150) primary key, " +
"displayname VARCHAR(50), " +
"email TEXT, " +
"vcardurl TEXT " +
")"
},
{
query: "CREATE TABLE groupmembers (" +
"\"group\" VARCHAR(150) references principals(uri)," +
"member VARCHAR(150) references principals(uri)" +
")"
},
{
query: "CREATE TABLE addressbooks (" +
"id SERIAL PRIMARY KEY, " +
"uri VARCHAR(150), " +
"principaluri VARCHAR(150) references principals(uri)," +
"description TEXT, " +
"displayname VARCHAR(50), " +
"ctag INT " +
")"
},
{
query: "CREATE TABLE cards (" +
"uri VARCHAR(250), " +
"lastmodified TIMESTAMP," +
"addressbookid INT references addressbooks(id), " +
"carddata TEXT " +
")"
},
{
query: "INSERT INTO users (username, password) VALUES($1, $2)",
values: ["admin", "6838d8a7454372f68a6abffbdb58911c"]
},
{
query: "INSERT INTO principals (uri, email, displayname, vcardurl) VALUES($1, $2, $3, $4)",
values: ["principals/admin", "[email protected]", "Administrator", ""]
},
{
query: "INSERT INTO addressbooks (principaluri, displayname, uri, description, ctag) VALUES($1, $2, $3, $4, $5)",
values: ["principals/admin", "default addressbook", "admin", "", 0]
}
];

Async.list(operations)
.each(function(op, next) {
pg.query(op.query, op.values || [], next);
})
.end(callback);
};
2 changes: 1 addition & 1 deletion lib/CalDAV/calendarObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ var jsCalDAV_Card = module.exports = jsDAV_File.extend(jsCalDAV_iCalendarObject,
this.get(function(err, data) {
if (err)
return callback(err);
callback(null, '"' + Util.md5(data) + '"');
callback(null, '"' + Util.createHash(data) + '"');
});
},

Expand Down
27 changes: 16 additions & 11 deletions lib/CalDAV/calendarQueryValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
* @license http://github.com/mikedeboer/jsDAV/blob/master/LICENSE MIT License
*/

"use strict";

'use strict';

var Base = require('./../shared/base');
var Base = require("./../shared/base");
var Exc = require("./../shared/exceptions");
var Util = require("./../shared/util");
var jsVObject_Node = require('./../VObject/node');
var jsVObject_Node = require("./../VObject/node");

/**
*
Expand Down Expand Up @@ -60,8 +59,8 @@ var jsDAV_CalendarQueryValidator = module.exports = Base.extend({
*/
if (filter) {
if (vObject.name == filter.name) {
return this._validateFilterSet(vObject, filter['comp-filters'], this._validateCompFilter) &&
this._validateFilterSet(vObject, filter['prop-filters'], this._validatePropFilter);
return this._validateFilterSet(vObject, filter["comp-filters"], this._validateCompFilter) &&
this._validateFilterSet(vObject, filter["prop-filters"], this._validatePropFilter);
}
else
return false;
Expand Down Expand Up @@ -125,13 +124,19 @@ var jsDAV_CalendarQueryValidator = module.exports = Base.extend({
},

_validateCompFilter: mkCommonValidator(function(children, filter) {
var node = children[0];
if (!this._validateTimeRangeOnComponent(children[0], filter["time-range"]))
return false;
var childrenMatchesRange;

return this._validateFilterSet(node, filter["comp-filters"], this._validateCompFilter) &&
this._validateFilterSet(node, filter["prop-filters"], this._validatePropFilter);
childrenMatchesRange = children.filter(function(child){
return this._validateTimeRangeOnComponent(child, filter["time-range"]);
}, this);

if (childrenMatchesRange.length === 0)
return false;

return childrenMatchesRange.some(function(child){
return this._validateFilterSet(child, filter["comp-filters"], this._validateCompFilter) &&
this._validateFilterSet(child, filter["prop-filters"], this._validatePropFilter);
}, this);
}),

_validatePropFilter: mkCommonValidator(function(children, filter) {
Expand Down
44 changes: 22 additions & 22 deletions lib/CalDAV/interfaces/iBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var jsCalDAV_iBackend = module.exports = Base.extend({
* Furthermore it can contain webdav properties in clark notation. A very
* common one is '{DAV:}displayname'.
*
* @param string $principalUri
* @param string principalUri
* @return array
*/
getCalendarsForUser: function(principalUri, callback) { callback(Exc.notImplementedYet()); },
Expand All @@ -42,9 +42,9 @@ var jsCalDAV_iBackend = module.exports = Base.extend({
* If the creation was a success, an id must be returned that can be used to reference
* this calendar in other methods, such as updateCalendar.
*
* @param string $principalUri
* @param string $calendarUri
* @param array $properties
* @param string principalUri
* @param string calendarUri
* @param array properties
* @return void
*/
createCalendar: function(principalUri, url, properties, callback) { callback(Exc.notImplementedYet()); },
Expand Down Expand Up @@ -81,16 +81,16 @@ var jsCalDAV_iBackend = module.exports = Base.extend({
* (403 Forbidden), which in turn also caused {DAV:}owner to fail
* (424 Failed Dependency) because the request needs to be atomic.
*
* @param mixed $calendarId
* @param array $mutations
* @param mixed calendarId
* @param array mutations
* @return bool|array
*/
updateCalendar: function(calendarId, mutations, callback) { callback(Exc.notImplementedYet()); },

/**
* Delete a calendar and all it's objects
*
* @param mixed $calendarId
* @param mixed calendarId
* @return void
*/
deleteCalendar: function(calendarId, callback) { callback(Exc.notImplementedYet()); },
Expand Down Expand Up @@ -119,7 +119,7 @@ var jsCalDAV_iBackend = module.exports = Base.extend({
* used/fetched to determine these numbers. If both are specified the
* amount of times this is needed is reduced by a great degree.
*
* @param mixed $calendarId
* @param mixed calendarId
* @return array
*/
getCalendarObjects: function(calendarId, callback) { callback(Exc.notImplementedYet()); },
Expand All @@ -134,8 +134,8 @@ var jsCalDAV_iBackend = module.exports = Base.extend({
*
* This method must return null if the object did not exist.
*
* @param mixed $calendarId
* @param string $objectUri
* @param mixed calendarId
* @param string objectUri
* @return array|null
*/
getCalendarObject: function(calendarId, objectUri, callback) { callback(Exc.notImplementedYet()); },
Expand All @@ -151,9 +151,9 @@ var jsCalDAV_iBackend = module.exports = Base.extend({
* calendar-data. If the result of a subsequent GET to this object is not
* the exact same as this request body, you should omit the ETag.
*
* @param mixed $calendarId
* @param string $objectUri
* @param string $calendarData
* @param mixed calendarId
* @param string objectUri
* @param string calendarData
* @return string|null
*/
createCalendarObject: function(calendarId, objectUri, calendarData, callback) { callback(Exc.notImplementedYet()); },
Expand All @@ -169,18 +169,18 @@ var jsCalDAV_iBackend = module.exports = Base.extend({
* calendar-data. If the result of a subsequent GET to this object is not
* the exact same as this request body, you should omit the ETag.
*
* @param mixed $calendarId
* @param string $objectUri
* @param string $calendarData
* @param mixed calendarId
* @param string objectUri
* @param string calendarData
* @return string|null
*/
updateCalendarObject: function(calendarId, objectUri, calendarData, callback) { callback(Exc.notImplementedYet()); },

/**
* Deletes an existing calendar object.
*
* @param mixed $calendarId
* @param string $objectUri
* @param mixed calendarId
* @param string objectUri
* @return void
*/
deleteCalendarObject: function(calendarId, objectUri, callback) { callback(Exc.notImplementedYet()); },
Expand All @@ -197,7 +197,7 @@ var jsCalDAV_iBackend = module.exports = Base.extend({
* query.
*
* The list of filters are specified as an array. The exact array is
* documented by Sabre\CalDAV\CalendarQueryParser.
* documented by jsCalDAV_CalendarQueryParser.
*
* Note that it is extremely likely that getCalendarObject for every path
* returned from this method will be called almost immediately after. You
Expand Down Expand Up @@ -226,12 +226,12 @@ var jsCalDAV_iBackend = module.exports = Base.extend({
* time-range filter specified on a VEVENT must for instance also handle
* recurrence rules correctly.
* A good example of how to interprete all these filters can also simply
* be found in Sabre\CalDAV\CalendarQueryFilter. This class is as correct
* be found in jsCalDAV_CalendarQueryFilter. This class is as correct
* as possible, so it gives you a good idea on what type of stuff you need
* to think of.
*
* @param mixed $calendarId
* @param array $filters
* @param mixed calendarId
* @param array filters
* @return array
*/
calendarQuery: function(calendarId, filters, callback) { callback(Exc.notImplementedYet()); },
Expand Down
2 changes: 1 addition & 1 deletion lib/CalDAV/interfaces/iCalendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var jsCalDAV_iCalendar = module.exports = jsDAV_iCollection.extend({
* query.
*
* The list of filters are specified as an array. The exact array is
* documented by \Sabre\CalDAV\CalendarQueryParser.
* documented by jsCalDAV_CalendarQueryParser.
*
* @param {Array} filters
* @return array
Expand Down
14 changes: 7 additions & 7 deletions lib/CalDAV/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ var jsCalDAV_iCalendar = require("./interfaces/iCalendar");
var jsCalDAV_iCalendarObject = require("./interfaces/iCalendarObject");
var jsDAVACL_iPrincipal = require("./../DAVACL/interfaces/iPrincipal");
var jsVObject_Reader = require("./../VObject/reader").new();
var jsCalDAV_CalendarQueryParser = require('./calendarQueryParser');
var jsCalDAV_CalendarQueryValidator = require('./calendarQueryValidator');
var jsCalDAV_CalendarQueryParser = require("./calendarQueryParser");
var jsCalDAV_CalendarQueryValidator = require("./calendarQueryValidator");

var AsyncEventEmitter = require("./../shared/asyncEvents").EventEmitter;
var Exc = require("./../shared/exceptions");
Expand All @@ -32,7 +32,7 @@ var NS_CALENDARSERVER = "http://calendarserver.org/ns/";
// Namespaces
Xml.xmlNamespaces[NS_CALDAV] = "cal";
Xml.xmlNamespaces[NS_CALENDARSERVER] = "cs";
Xml.xmlNamespaces['urn:DAV'] = 'dav';
Xml.xmlNamespaces["urn:DAV"] = "dav";

/**
* CalDAV plugin
Expand Down Expand Up @@ -74,7 +74,7 @@ var jsCalDAV_Plugin = module.exports = jsDAV_Plugin.extend({
* This method is passed a uri. It should only return HTTP methods that are
* available for the specified uri.
*
* @param string $uri
* @param string uri
* @return array
*/
getHTTPMethods: function(uri) {
Expand All @@ -84,7 +84,7 @@ var jsCalDAV_Plugin = module.exports = jsDAV_Plugin.extend({

// @TODO: check as described above, need to make getHTTPMethods async

return ['MKCALENDAR'];
return ["MKCALENDAR"];

},

Expand All @@ -96,7 +96,7 @@ var jsCalDAV_Plugin = module.exports = jsDAV_Plugin.extend({
* @return array
*/
getFeatures: function() {
return ['calendar-access'];
return ["calendar-access"];
},


Expand Down Expand Up @@ -239,7 +239,7 @@ var jsCalDAV_Plugin = module.exports = jsDAV_Plugin.extend({
// $this->server->httpResponse->setHeader('Content-Length',0);

this.handler.httpResponse.writeHead(500);
this.handler.httpResponse.end('Not Implemented Yet');
this.handler.httpResponse.end("Not Implemented Yet");
},

/**
Expand Down
6 changes: 3 additions & 3 deletions lib/CardDAV/backends/mongo.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ var jsCardDAV_Backend_Mongo = module.exports = jsCardDAV_iBackend.extend({
}, function(err, docs) {
if (err)
return callback(err)
callback(null, "\"" + Util.md5(cardData) + "\"");
callback(null, "\"" + Util.createHash(cardData) + "\"");
});
});
},
Expand Down Expand Up @@ -366,7 +366,7 @@ var jsCardDAV_Backend_Mongo = module.exports = jsCardDAV_iBackend.extend({
}, function(err, docs) {
if (err)
return callback(err)
callback(null, "\"" + Util.md5(cardData) + "\"");
callback(null, "\"" + Util.createHash(cardData) + "\"");
});
})
},
Expand Down Expand Up @@ -399,4 +399,4 @@ var jsCardDAV_Backend_Mongo = module.exports = jsCardDAV_iBackend.extend({
});
});
}
});
});
Loading

0 comments on commit 5cd753d

Please sign in to comment.