Skip to content

Commit

Permalink
Updated caldav and acldav properties
Browse files Browse the repository at this point in the history
  • Loading branch information
gedaiu committed Apr 20, 2015
1 parent c107cfb commit 71d2550
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 327 deletions.
37 changes: 32 additions & 5 deletions source/vibedav/acldav.d
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ interface ACLDavProperties {
@ResourceProperty("principal-collection-set", "DAV:")
@ResourcePropertyTagText("href", "DAV:")
string[] principalCollectionSet(DavResource resource);

@ResourceProperty("owner", "DAV:")
@ResourcePropertyTagText("href", "DAV:")
string owner(DavResource resource);
}
}

Expand All @@ -42,29 +46,40 @@ private bool matchPluginUrl(URL url) {
return false;
}

class ACLDavResourcePlugin : ACLDavProperties, IDavResourcePlugin {
class ACLDavResourcePlugin : ACLDavProperties, IDavResourcePlugin, IDavReportSetProperties {

string currentUserPrincipal(DavResource resource) {
if(matchPluginUrl(resource.url))
return "/principals/" ~ resource.username;
return "/principals/" ~ resource.username ~ "/";

throw new DavException(HTTPStatus.notFound, "not found");
}

string principalURL(DavResource resource) {
if(matchPluginUrl(resource.url))
return "/principals/" ~ resource.username;
return "/principals/" ~ resource.username ~ "/";

throw new DavException(HTTPStatus.notFound, "not found");
}

string owner(DavResource resource) {
return principalURL(resource);
}

string[] principalCollectionSet(DavResource resource) {
if(matchPluginUrl(resource.url))
return [ "/principals/" ];

throw new DavException(HTTPStatus.notFound, "not found");
}

string[] supportedReportSet(DavResource resource) {
if(matchPluginUrl(resource.url))
return ["expand-property:DAV:", "principal-property-search:DAV:", "principal-search-property-set:DAV:"];

return [];
}


bool canSetContent(DavResource resource) {
return false;
Expand All @@ -83,7 +98,13 @@ class ACLDavResourcePlugin : ACLDavProperties, IDavResourcePlugin {
}

bool canGetProperty(DavResource resource, string name) {
if(matchPluginUrl(resource.url) && hasDavInterfaceProperty!ACLDavProperties(name))
if(!matchPluginUrl(resource.url))
return false;

if(hasDavInterfaceProperty!ACLDavProperties(name))
return true;

if(hasDavInterfaceProperty!IDavReportSetProperties(name))
return true;

return false;
Expand All @@ -109,9 +130,15 @@ class ACLDavResourcePlugin : ACLDavProperties, IDavResourcePlugin {
void copyPropertiesTo(URL source, URL destination) { }

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

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

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

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

Expand Down
11 changes: 7 additions & 4 deletions source/vibedav/base.d
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ interface IDav : IDavResourceAccess, IDavPluginHub {
void remove(DavRequest request, DavResponse response);
void move(DavRequest request, DavResponse response);
void copy(DavRequest request, DavResponse response);

void report(DavRequest request, DavResponse response);

@property
Path rootUrl();
Expand Down Expand Up @@ -265,9 +265,6 @@ class Dav : IDav {

tmpList ~= getResource(url, username);

if(depth == 0)
list ~= tmpList;

while(tmpList.length > 0 && depth > 0) {
auto oldLen = tmpList.length;

Expand Down Expand Up @@ -536,6 +533,10 @@ class Dav : IDav {
response.flush;
}

void report(DavRequest request, DavResponse response) {

}

void copy(DavRequest request, DavResponse response) {
string username = request.username;

Expand Down Expand Up @@ -655,6 +656,8 @@ HTTPServerRequestDelegate serveDav(T : IDav)(T dav) {
dav.copy(request, response);
} else if(req.method == HTTPMethod.MOVE) {
dav.move(request, response);
} else if(req.method == HTTPMethod.REPORT) {
dav.report(request, response);
} else {
res.statusCode = HTTPStatus.notImplemented;
res.writeBody("", "text/plain");
Expand Down
Loading

0 comments on commit 71d2550

Please sign in to comment.