Skip to content

Commit

Permalink
Updated the webdav example
Browse files Browse the repository at this point in the history
  • Loading branch information
gedaiu committed Apr 7, 2015
1 parent e8a304e commit 8a25164
Show file tree
Hide file tree
Showing 14 changed files with 365 additions and 45 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ dub.selections.json
__test__library__
vibe-dav
vibe-dav.sublime-project
results.json
results.json
examples/webDav/webdavexample
examples/fileDav/filedav
examples/fileDav/dub.selections.json

73 changes: 73 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,76 @@

A library that adds DAV support to vibe.d

## Support

FileDav with locking
CalDav with basic support
CardDav no support

## How to use

### FileDav

Use

void serveFileDav(string rootUrl, string rootPath)(URLRouter router, IDavUserCollection userCollection)

to bind the fileDav handlers to a vibe router.

The next exemple will map every resource from `http://localhost/files` to `public/files`

import vibedav.filedav;

...

auto router = new URLRouter;
router.serveFileDav!("/files/", "public/files/")(userConnection);

...

listenHTTP(settings, router);

### CalDav

Use the factory class that maps resource types to url nodes:

alias T = FileDavResourceFactory!(
[rootUrl], [rootPath],
[nodeUrl], [collection type], [resource type]
...
);


Example of maping a simple cal dav folder structure (more work will be done here):

auto router = new URLRouter;

// Do some basic auth
router.any("/calendar/*", performBasicAuth("Site Realm", toDelegate(&checkPassword)));

// Create a basic user collection, used to manage CalDav users
auto userConnection = new BaseCalDavUserCollection;

// Create a custom file maping
alias factory = FileDavResourceFactory!(
// map "http://127.0.0.1/calendar" to "public/calendar"
"calendar", "public/calendar",
// map any folder to `FileDavCollection` and file to `FileDavResource`
"", FileDavCollection, FileDavResource,
// map the `personal` folder from users home
// to `FileDavCalendarCollection` and files to `FileDavCalendarResource`
":user/personal", FileDavCalendarCollection, FileDavCalendarResource
);

// Bind the custom FileDav maping to a vibe router.
router.serveFileDav!factory(userConnection);

...

listenHTTP(settings, router);


5 changes: 0 additions & 5 deletions examples/fileDav/.gitignore

This file was deleted.

14 changes: 0 additions & 14 deletions examples/fileDav/dub.json

This file was deleted.

3 changes: 0 additions & 3 deletions examples/fileDav/public/text file.txt

This file was deleted.

21 changes: 0 additions & 21 deletions examples/fileDav/source/app.d

This file was deleted.

16 changes: 16 additions & 0 deletions examples/webDav/dub.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "webDavExample",
"description": "A simple vibe.d server application.",
"copyright": "Copyright © 2015, Szabo Bogdan",
"authors": ["Szabo Bogdan"],
"dependencies": {
"vibe-d": "~>0.7.19",
"vibe-dav": {
"version": "~>0.2.0",
"path": "../.."
}
},

"versions": ["VibeDefaultMain"],
"targetType": "executable"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Apple Inc.//Mac OS X 10.10.3//EN
CALSCALE:GREGORIAN
BEGIN:VTIMEZONE
TZID:Europe/Stockholm
BEGIN:DAYLIGHT
TZOFFSETFROM:+0100
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
DTSTART:19810329T020000
TZNAME:CEST
TZOFFSETTO:+0200
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:+0200
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
DTSTART:19961027T030000
TZNAME:CET
TZOFFSETTO:+0100
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
TRANSP:OPAQUE
DTEND;TZID=Europe/Stockholm:20150408T170000
PRIORITY:0
UID:6837CB82-AE37-4E57-9C89-D39D62BBBC01
DTSTAMP:20150407T131647Z
X-YAHOO-USER-STATUS:BUSY
X-YAHOO-USER-STATUS:BUSY
STATUS:CONFIRMED
SEQUENCE:0
CLASS:PUBLIC
X-YAHOO-YID:szabobogdan
X-YAHOO-YID:szabobogdan
X-YAHOO-EVENT-STATUS:BUSY
X-YAHOO-EVENT-STATUS:BUSY
SUMMARY:test event
DTSTART;TZID=Europe/Stockholm:20150407T160000
CREATED:20150407T131647Z
END:VEVENT
END:VCALENDAR
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Apple Inc.//Mac OS X 10.10.3//EN
CALSCALE:GREGORIAN
BEGIN:VTIMEZONE
TZID:Europe/Stockholm
BEGIN:DAYLIGHT
TZOFFSETFROM:+0100
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
DTSTART:19810329T020000
TZNAME:CEST
TZOFFSETTO:+0200
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:+0200
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
DTSTART:19961027T030000
TZNAME:CET
TZOFFSETTO:+0100
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
CREATED:20150407T194949Z
UID:7B508AD5-FE51-4C7B-8E21-0104F5412923
DTEND;TZID=Europe/Stockholm:20150422T100000
TRANSP:OPAQUE
SUMMARY:cucu
DTSTART;TZID=Europe/Stockholm:20150422T090000
DTSTAMP:20150407T194949Z
SEQUENCE:0
END:VEVENT
END:VCALENDAR
77 changes: 77 additions & 0 deletions examples/webDav/public/calendar/admin/personal/main.ics
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
BEGIN:VCALENDAR
METHOD:PUBLISH
VERSION:2.0
X-WR-CALNAME:Home
X-WR-CALDESC:
X-APPLE-CALENDAR-COLOR:#1BADF8
X-WR-TIMEZONE:Europe/Bucharest
CALSCALE:GREGORIAN
BEGIN:VTIMEZONE
TZID:Europe/Bucharest
BEGIN:DAYLIGHT
TZOFFSETFROM:+0200
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
DTSTART:19970330T030000
TZNAME:EEST
TZOFFSETTO:+0300
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:+0300
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
DTSTART:19971026T040000
TZNAME:EET
TZOFFSETTO:+0200
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
CREATED:20140214T081455Z
UID:489F8C95-B5B3-49E3-BA4D-0CE0F820E022
DTEND;TZID=Europe/Bucharest:20140214T120000
TRANSP:OPAQUE
SUMMARY:New Event
DTSTART;TZID=Europe/Bucharest:20140214T110000
DTSTAMP:20140214T081455Z
SEQUENCE:1
END:VEVENT
BEGIN:VEVENT
CREATED:20140912T181025Z
UID:BAF9FA4C-C758-4E73-87C2-847A879AC884
DTEND;TZID=Europe/Bucharest:20200724T130000
TRANSP:OPAQUE
SUMMARY:New Event
DTSTART;TZID=Europe/Bucharest:20200724T120000
DTSTAMP:20140911T200404Z
LAST-MODIFIED:20140131T143908Z
SEQUENCE:0
END:VEVENT
BEGIN:VEVENT
CREATED:20140912T181025Z
UID:349C7C65-CD2F-44B6-8467-FF9C22F58832
RRULE:FREQ=WEEKLY;COUNT=1
DTEND;TZID=Europe/Bucharest:20140212T130000
TRANSP:OPAQUE
SUMMARY:New Event
DTSTART;TZID=Europe/Bucharest:20140212T120000
DTSTAMP:20140911T200404Z
LAST-MODIFIED:20140201T082515Z
SEQUENCE:0
BEGIN:VALARM
X-WR-ALARMUID:95787692-6F0A-48A3-B4FE-B4C4CB0540F7
UID:95787692-6F0A-48A3-B4FE-B4C4CB0540F7
TRIGGER:-PT30M
DESCRIPTION:Event reminder
ACTION:DISPLAY
END:VALARM
END:VEVENT
BEGIN:VEVENT
CREATED:20140912T181025Z
UID:8FC79E15-43C5-409A-B541-4DD21F2E9C89
DTEND;TZID=Europe/Bucharest:20131230T130000
TRANSP:OPAQUE
SUMMARY:Eveniment nou
DTSTART;TZID=Europe/Bucharest:20131230T120000
DTSTAMP:20140911T200404Z
LAST-MODIFIED:20140131T124833Z
SEQUENCE:0
END:VEVENT
END:VCALENDAR
1 change: 1 addition & 0 deletions examples/webDav/public/files/hello.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello world!
63 changes: 63 additions & 0 deletions examples/webDav/source/app.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* Authors: Szabo Bogdan <szabobogdan@yahoo.com>
* Date: 2 13, 2015
* License: Subject to the terms of the MIT license, as written in the included LICENSE.txt file.
* Copyright: Public Domain
*/
import vibe.core.file;
import vibe.core.log;
import vibe.inet.message;
import vibe.inet.mimetypes;
import vibe.http.router : URLRouter;
import vibe.http.server;
import vibe.http.fileserver;
import vibe.http.auth.basic_auth;

import vibedav.filedav;
import vibedav.caldav;
import vibedav.user;
import vibedav.prop;
import vibedav.userhome;

import core.time;
import std.conv : to;
import std.stdio;
import std.file;
import std.path;
import std.digest.md;
import std.datetime;
import std.functional : toDelegate;

bool checkPassword(string user, string password)
{
return user == "admin" && password == "secret";
}

shared static this()
{
writeln("Starting WebDav server.");

auto router = new URLRouter;

// now any request is matched and checked for authentication:
router.any("/calendar/*", performBasicAuth("Site Realm", toDelegate(&checkPassword)));

auto userConnection = new BaseCalDavUserCollection;

alias factory = FileDavResourceFactory!(
"calendar", "public/calendar",
"", FileDavCollection, FileDavResource,
":user/", FileDavCollection, FileDavResource,
":user/inbox", FileDavCollection, FileDavResource,
":user/outbox", FileDavCollection, FileDavResource,
":user/personal", FileDavCalendarCollection, FileDavCalendarResource
);

router.serveFileDav!("/files/", "public/files/")(userConnection);
router.serveFileDav!factory(userConnection);

auto settings = new HTTPServerSettings;
settings.port = 8080;
settings.bindAddresses = ["::1", "127.0.0.1"];
listenHTTP(settings, router);
}
Loading

0 comments on commit 8a25164

Please sign in to comment.