Skip to content

Commit

Permalink
Added CalDav collection plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
gedaiu committed Apr 19, 2015
1 parent a6ca649 commit c107cfb
Show file tree
Hide file tree
Showing 5 changed files with 230 additions and 208 deletions.
40 changes: 4 additions & 36 deletions source/vibedav/acldav.d
Original file line number Diff line number Diff line change
Expand Up @@ -130,56 +130,24 @@ class ACLDavResourcePlugin : ACLDavProperties, IDavResourcePlugin {
}
}

class ACLDavPlugin : IDavPlugin {
class ACLDavPlugin : BaseDavPlugin {

private IDav _dav;

this(IDav dav) {
_dav = dav;
super(dav);
}

bool exists(URL url, string username) {
return false;
}

bool canCreateCollection(URL url, string username) {
return false;
}

bool canCreateResource(URL url, string username) {
return false;
}

void removeResource(URL url, string username) {
throw new DavException(HTTPStatus.internalServerError, "Can't remove resource.");
}

DavResource getResource(URL url, string username) {
throw new DavException(HTTPStatus.internalServerError, "Can't get resource.");
}

DavResource createCollection(URL url, string username) {
throw new DavException(HTTPStatus.internalServerError, "Can't create collection.");
}

DavResource createResource(URL url, string username) {
throw new DavException(HTTPStatus.internalServerError, "Can't create resource.");
}

void bindResourcePlugins(ref DavResource resource) {
override void bindResourcePlugins(DavResource resource) {
resource.registerPlugin(new ACLDavResourcePlugin);
}

@property {
IDav dav() {
return _dav;
}

string name() {
return "ACLDavPlugin";
}

string[] support(URL url, string username) {
override string[] support(URL url, string username) {
if(matchPluginUrl(url))
return [ "access-control" ];

Expand Down
55 changes: 53 additions & 2 deletions source/vibedav/base.d
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ interface IDavResourceAccess {
DavResource createCollection(URL url, string username);
DavResource createResource(URL url, string username);

void bindResourcePlugins(ref DavResource resource);
void bindResourcePlugins(DavResource resource);
}

interface IDavPlugin : IDavResourceAccess {
Expand All @@ -84,6 +84,55 @@ interface IDavPluginHub {
bool hasPlugin(string name);
}


abstract class BaseDavPlugin : IDavPlugin {
private IDav _dav;

this(IDav dav) {
_dav = dav;
}

bool exists(URL url, string username) {
return false;
}

bool canCreateCollection(URL url, string username) {
return false;
}

bool canCreateResource(URL url, string username) {
return false;
}

void removeResource(URL url, string username) {
throw new DavException(HTTPStatus.internalServerError, "Can't remove resource.");
}

DavResource getResource(URL url, string username) {
throw new DavException(HTTPStatus.internalServerError, "Can't get resource.");
}

DavResource createCollection(URL url, string username) {
throw new DavException(HTTPStatus.internalServerError, "Can't create collection.");
}

DavResource createResource(URL url, string username) {
throw new DavException(HTTPStatus.internalServerError, "Can't create resource.");
}

void bindResourcePlugins(DavResource resource) { }

@property {
IDav dav() {
return _dav;
}

string[] support(URL url, string username) {
return [];
}
}
}

interface IDav : IDavResourceAccess, IDavPluginHub {
void options(DavRequest request, DavResponse response);
void propfind(DavRequest request, DavResponse response);
Expand Down Expand Up @@ -235,6 +284,8 @@ class Dav : IDav {
depth--;
}

list ~= tmpList;

return list;
}

Expand Down Expand Up @@ -263,7 +314,7 @@ class Dav : IDav {
}


void bindResourcePlugins(ref DavResource resource) {
void bindResourcePlugins(DavResource resource) {
foreach(plugin; plugins)
plugin.bindResourcePlugins(resource);
}
Expand Down
153 changes: 80 additions & 73 deletions source/vibedav/caldav.d
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ private bool matchPluginUrl(URL url, string username) {
return false;
}

class CalDavResourcePlugin : IDavResourcePlugin, ICalDavProperties, IDavReportSetProperties {
class CalDavResourcePlugin : BaseDavResourcePlugin, ICalDavProperties, IDavReportSetProperties {

string[] calendarHomeSet(DavResource resource) {
if(matchPluginUrl(resource.url, resource.username))
Expand Down Expand Up @@ -452,70 +452,100 @@ class CalDavResourcePlugin : IDavResourcePlugin, ICalDavProperties, IDavReportSe
return [];
}

bool canSetContent(DavResource resource) {
return false;
override {
bool canGetProperty(DavResource resource, string name) {
if(matchPluginUrl(resource.url, resource.username) && hasDavInterfaceProperty!ICalDavProperties(name))
return true;

if(matchPluginUrl(resource.url, resource.username) && hasDavInterfaceProperty!IDavReportSetProperties(name))
return true;

return false;
}

DavProp property(DavResource resource, string name) {
if(!matchPluginUrl(resource.url, resource.username))
throw new DavException(HTTPStatus.internalServerError, "Can't get property.");

if(hasDavInterfaceProperty!ICalDavProperties(name))
return getDavInterfaceProperty!ICalDavProperties(name, this, resource);

if(hasDavInterfaceProperty!IDavReportSetProperties(name))
return getDavInterfaceProperty!IDavReportSetProperties(name, this, resource);

throw new DavException(HTTPStatus.internalServerError, "Can't get property.");
}
}

bool canGetStream(DavResource resource) {
return false;
@property {
string name() {
return "ResourceBasicProperties";
}
}
}

bool canSetProperty(DavResource resource, string name) {
return false;

class CalDavCollectionPlugin : BaseDavResourcePlugin, ICalDavCollectionProperties {

string calendarDescription(DavResource resource) {
return resource.name;
}

bool canRemoveProperty(DavResource resource, string name) {
return false;
TimeZone calendarTimezone(DavResource resource) {
TimeZone t;
return t;
}

bool canGetProperty(DavResource resource, string name) {
if(matchPluginUrl(resource.url, resource.username) && hasDavInterfaceProperty!ICalDavProperties(name))
return true;
string[] supportedCalendarComponentSet(DavResource resource) {
return ["VEVENT", "VTODO", "VJOURNAL", "VFREEBUSY", "VTIMEZONE", "VALARM"];
}

if(matchPluginUrl(resource.url, resource.username) && hasDavInterfaceProperty!IDavReportSetProperties(name))
return true;
string[string][] supportedCalendarData(DavResource resource) {
string[string][] list;

return false;
}
list ~= [["content-type": "text/calendar", "version": "2.0"]];

bool[string] getChildren(DavResource resource) {
bool[string] list;
return list;
}

void setContent(DavResource resource, const ubyte[] content) {
throw new DavException(HTTPStatus.internalServerError, "Can't set content.");
ulong maxResourceSize(DavResource resource) {
return ulong.max;
}

void setContent(DavResource resource, InputStream content, ulong size) {
throw new DavException(HTTPStatus.internalServerError, "Can't set content.");
SysTime minDateTime(DavResource resource) {
return SysTime.min;
}

InputStream stream(DavResource resource) {
throw new DavException(HTTPStatus.internalServerError, "Can't get stream.");
SysTime maxDateTime(DavResource resource) {
return SysTime.max;
}

void copyPropertiesTo(URL source, URL destination) { }
ulong maxInstances(DavResource resource) {
return ulong.max;
}

DavProp property(DavResource resource, string name) {
if(!matchPluginUrl(resource.url, resource.username))
throw new DavException(HTTPStatus.internalServerError, "Can't get property.");
ulong maxAttendeesPerInstance(DavResource resource) {
return ulong.max;
}

if(hasDavInterfaceProperty!ICalDavProperties(name))
return getDavInterfaceProperty!ICalDavProperties(name, this, resource);
override {

if(hasDavInterfaceProperty!IDavReportSetProperties(name))
return getDavInterfaceProperty!IDavReportSetProperties(name, this, resource);
bool canGetProperty(DavResource resource, string name) {
if(matchPluginUrl(resource.url, resource.username) && hasDavInterfaceProperty!ICalDavCollectionProperties(name))
return true;

throw new DavException(HTTPStatus.internalServerError, "Can't get property.");
}
return false;
}

HTTPStatus setProperty(DavResource resource, string name, DavProp prop) {
throw new DavException(HTTPStatus.internalServerError, "Can't set property.");
}
DavProp property(DavResource resource, string name) {
if(!matchPluginUrl(resource.url, resource.username))
throw new DavException(HTTPStatus.internalServerError, "Can't get property.");

if(hasDavInterfaceProperty!ICalDavCollectionProperties(name))
return getDavInterfaceProperty!ICalDavCollectionProperties(name, this, resource);

HTTPStatus removeProperty(DavResource resource, string name) {
throw new DavException(HTTPStatus.internalServerError, "Can't remove property.");
throw new DavException(HTTPStatus.internalServerError, "Can't get property.");
}
}

@property {
Expand All @@ -525,56 +555,33 @@ class CalDavResourcePlugin : IDavResourcePlugin, ICalDavProperties, IDavReportSe
}
}

class CalDavPlugin : IDavPlugin {

private IDav _dav;
class CalDavPlugin : BaseDavPlugin {

this(IDav dav) {
_dav = dav;
super(dav);
}

bool exists(URL url, string username) {
return false;
}

bool canCreateCollection(URL url, string username) {
return false;
}
override void bindResourcePlugins(DavResource resource) {

bool canCreateResource(URL url, string username) {
return false;
}

void removeResource(URL url, string username) {
throw new DavException(HTTPStatus.internalServerError, "Can't remove resource.");
}

DavResource getResource(URL url, string username) {
throw new DavException(HTTPStatus.internalServerError, "Can't get resource.");
}

DavResource createCollection(URL url, string username) {
throw new DavException(HTTPStatus.internalServerError, "Can't create collection.");
}

DavResource createResource(URL url, string username) {
throw new DavException(HTTPStatus.internalServerError, "Can't create resource.");
}
if(!matchPluginUrl(resource.url, resource.username))
return;

void bindResourcePlugins(ref DavResource resource) {
resource.registerPlugin(new CalDavResourcePlugin);

if(resource.isCollection && resource.url.path.toString.stripSlashes != "principals/" ~ resource.username ~ "/calendars") {
resource.resourceType ~= "calendar:urn:ietf:params:xml:ns:caldav";
resource.registerPlugin(new CalDavCollectionPlugin);
}
}

@property {
IDav dav() {
return _dav;
}

string name() {
return "CalDavPlugin";
}

string[] support(URL url, string username) {
override string[] support(URL url, string username) {
if(matchPluginUrl(url, username))
return [ "calendar-access" ];

Expand Down
Loading

0 comments on commit c107cfb

Please sign in to comment.