[CalendarServer-changes] [915] CalendarServer/trunk/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Thu Jan 4 08:51:06 PST 2007


Revision: 915
          http://trac.macosforge.org/projects/calendarserver/changeset/915
Author:   cdaboo at apple.com
Date:     2007-01-04 08:51:06 -0800 (Thu, 04 Jan 2007)

Log Message:
-----------
Switch to using POST instead of X-APPLE-xxx for notifcation subscribe/unsubscribe.

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/customxml.py
    CalendarServer/trunk/twistedcaldav/dropbox.py
    CalendarServer/trunk/twistedcaldav/static.py

Modified: CalendarServer/trunk/twistedcaldav/customxml.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/customxml.py	2007-01-04 16:39:22 UTC (rev 914)
+++ CalendarServer/trunk/twistedcaldav/customxml.py	2007-01-04 16:51:06 UTC (rev 915)
@@ -176,6 +176,22 @@
 
     allowed_children = { (davxml.dav_namespace, "principal"): (0, None) }
 
+class Subscribe (davxml.WebDAVEmptyElement):
+    """
+    Used in the body of a POST to subscribe to notifications.
+    (Apple Extension to CalDAV)
+    """
+    namespace = calendarserver_namespace
+    name = "subscribe"
+
+class Unsubscribe (davxml.WebDAVEmptyElement):
+    """
+    Used in the body of a POST to unsubscribe from notifications.
+    (Apple Extension to CalDAV)
+    """
+    namespace = calendarserver_namespace
+    name = "unsubscribe"
+
 ##
 # Extensions to davxml.ResourceType
 ##

Modified: CalendarServer/trunk/twistedcaldav/dropbox.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/dropbox.py	2007-01-04 16:39:22 UTC (rev 914)
+++ CalendarServer/trunk/twistedcaldav/dropbox.py	2007-01-04 16:51:06 UTC (rev 915)
@@ -35,9 +35,9 @@
 from twisted.python import log
 from twisted.web2 import responsecode
 from twisted.web2.dav import davxml
-from twisted.web2.dav.http import HTTPError, ErrorResponse
+from twisted.web2.dav.http import HTTPError, ErrorResponse, StatusResponse
 from twisted.web2.dav.resource import DAVResource, DAVPrincipalResource, TwistedACLInheritable
-from twisted.web2.dav.util import parentForURL
+from twisted.web2.dav.util import davXMLFromStream, parentForURL
 
 from twistedcaldav import customxml
 from twistedcaldav.config import config
@@ -198,7 +198,46 @@
             (calendarserver_namespace, "valid-drop-box")
         )
 
-    def http_X_APPLE_SUBSCRIBE(self, request):
+    def http_POST(self, request):
+        """
+        Handle subscribe/unsubscribe requests only.
+        """
+        
+        # Read request body
+        try:
+            doc = waitForDeferred(davXMLFromStream(request.stream))
+            yield doc
+            doc = doc.getResult()
+        except ValueError, e:
+            error = "Must have valid XML request body for POST on a dropbox: %s" % (e,)
+            log.err(error)
+            raise HTTPError(StatusResponse(responsecode.BAD_REQUEST, error))
+        
+        # Determine whether we are subscribing or unsubscribing and handle that
+        if doc is not None:
+            root = doc.root_element
+            if isinstance(root, customxml.Subscribe):
+                action = self.subscribe
+            elif isinstance(root, customxml.Unsubscribe):
+                action = self.unsubscribe
+            else:
+                error = "XML request body for POST on a dropbox must contain a single <subscribe> or <unsubscribe> element"
+                log.err(error)
+                raise HTTPError(StatusResponse(responsecode.BAD_REQUEST, error))
+        else:
+            # If we get here we got an invalid request
+            error = "Must have valid XML request body for POST on a dropbox"
+            log.err(error)
+            raise HTTPError(StatusResponse(responsecode.BAD_REQUEST, error))
+
+        d = waitForDeferred(action(request))
+        yield d
+        result = d.getResult()
+        yield result
+
+    http_POST = deferredGenerator(http_POST)
+
+    def subscribe(self, request):
         d = waitForDeferred(self.authorize(request, (davxml.Read(),)))
         yield d
         d.getResult()
@@ -223,9 +262,9 @@
 
         yield responsecode.OK
 
-    http_X_APPLE_SUBSCRIBE = deferredGenerator(http_X_APPLE_SUBSCRIBE)
+    subscribe = deferredGenerator(subscribe)
 
-    def http_X_APPLE_UNSUBSCRIBE(self, request):
+    def unsubscribe(self, request):
         # We do not check any privileges. If a principal is subscribed we always allow them to
         # unsubscribe provided they have at least authenticated.
         d = waitForDeferred(self.authorize(request, ()))
@@ -252,7 +291,7 @@
 
         yield responsecode.OK
 
-    http_X_APPLE_UNSUBSCRIBE = deferredGenerator(http_X_APPLE_UNSUBSCRIBE)
+    unsubscribe = deferredGenerator(unsubscribe)
 
 class DropBoxChildResource (DAVResource):
     def http_MKCOL(self, request):

Modified: CalendarServer/trunk/twistedcaldav/static.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/static.py	2007-01-04 16:39:22 UTC (rev 914)
+++ CalendarServer/trunk/twistedcaldav/static.py	2007-01-04 16:51:06 UTC (rev 915)
@@ -580,8 +580,7 @@
     http_DELETE =              DropBoxCollectionResource.http_DELETE
     http_PUT =                 DropBoxCollectionResource.http_PUT
     http_MKCALENDAR =          DropBoxCollectionResource.http_MKCALENDAR
-    http_X_APPLE_SUBSCRIBE =   DropBoxCollectionResource.http_X_APPLE_SUBSCRIBE
-    http_X_APPLE_UNSUBSCRIBE = DropBoxCollectionResource.http_X_APPLE_SUBSCRIBE
+    http_POST =                DropBoxCollectionResource.http_POST
 
 class DropBoxChildFile (DropBoxChildResource, CalDAVFile):
     def __init__(self, path, parent):

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20070104/25f34c6e/attachment.html


More information about the calendarserver-changes mailing list