[Calypso] [PATCH] Support the current-user-principal property (RFC5397).

Jelmer Vernooij jelmer at samba.org
Sat Mar 8 17:19:28 PST 2014


---
 calypso/__init__.py | 3 ++-
 calypso/config.py   | 1 +
 calypso/xmlutils.py | 6 +++++-
 config              | 3 +++
 4 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/calypso/__init__.py b/calypso/__init__.py
index ba53288..36349b9 100644
--- a/calypso/__init__.py
+++ b/calypso/__init__.py
@@ -374,7 +374,8 @@ class CollectionHTTPHandler(server.BaseHTTPRequestHandler):
             log.debug("PROPFIND %s", xml_request)
             self._answer = xmlutils.propfind(
                 self.path, xml_request, self._collection,
-                self.headers.get("depth", "infinity"))
+                self.headers.get("depth", "infinity"),
+                context)
             log.debug("PROPFIND ANSWER %s", self._answer)
 
             self.send_calypso_response(client.MULTI_STATUS, len(self._answer))
diff --git a/calypso/config.py b/calypso/config.py
index 20c96ef..b66bd91 100644
--- a/calypso/config.py
+++ b/calypso/config.py
@@ -47,6 +47,7 @@ INITIAL_CONFIG = {
         "key": "/etc/apache2/ssl/server.key",
         "pidfile": "/var/run/calypso.pid",
         "base_prefix": "/",
+        "user_principal": "/+%(user)s/",
     },
     "encoding": {
         "request": "utf-8",
diff --git a/calypso/xmlutils.py b/calypso/xmlutils.py
index a1e8c8c..b10b8f7 100644
--- a/calypso/xmlutils.py
+++ b/calypso/xmlutils.py
@@ -86,7 +86,7 @@ def delete(path, collection, context):
     return ET.tostring(multistatus, config.get("encoding", "request"))
 
 
-def propfind(path, xml_request, collection, depth):
+def propfind(path, xml_request, collection, depth, context):
     """Read and answer PROPFIND requests.
 
     Read rfc4918-9.1 for info.
@@ -210,6 +210,10 @@ def propfind(path, xml_request, collection, depth):
 #                element.text = time.strftime("%a, %d %b %Y %H:%M:%S +0000", item.last_modified)
 #                element.text = email.utils.formatdate(item.last_modified)
                 element.text = email.utils.formatdate(time.mktime(item.last_modified))
+            elif tag == _tag("D", "current-user-principal"):
+                tag = ET.Element(_tag("D", "href"))
+                tag.text = (config.get("server", "user_principal") % context)
+                element.append(tag)
             prop.append(element)
 
         status = ET.Element(_tag("D", "status"))
diff --git a/config b/config
index 1c5105e..85b9597 100644
--- a/config
+++ b/config
@@ -22,6 +22,9 @@ key = /etc/apache2/ssl/server.key
 # pidfile = /var/run/calypso.pid
 # base URL if / is not the CalDAV root
 base_prefix = /
+# current user principal; path to the default collection for a user
+# for clients that use it (RFC5397)
+user_principal = /+%(user)s/
 
 [encoding]
 # Encoding for responding requests
-- 
1.9.0.279.gdc9e3eb



More information about the Calypso mailing list