[CalendarServer-changes] [2672] CalendarServer/branches/users/sagen/xmpp/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Wed Jul 9 23:18:25 PDT 2008


Revision: 2672
          http://trac.macosforge.org/projects/calendarserver/changeset/2672
Author:   sagen at apple.com
Date:     2008-07-09 23:18:25 -0700 (Wed, 09 Jul 2008)
Log Message:
-----------
Adding DAV properties to CalendarHomeFile for supporting pubsub, based on http://tools.ietf.org/draft/draft-hildebrand-webdav-notify/draft-hildebrand-webdav-notify-00.txt

Modified Paths:
--------------
    CalendarServer/branches/users/sagen/xmpp/twistedcaldav/customxml.py
    CalendarServer/branches/users/sagen/xmpp/twistedcaldav/notify.py
    CalendarServer/branches/users/sagen/xmpp/twistedcaldav/static.py

Modified: CalendarServer/branches/users/sagen/xmpp/twistedcaldav/customxml.py
===================================================================
--- CalendarServer/branches/users/sagen/xmpp/twistedcaldav/customxml.py	2008-07-09 18:41:34 UTC (rev 2671)
+++ CalendarServer/branches/users/sagen/xmpp/twistedcaldav/customxml.py	2008-07-10 06:18:25 UTC (rev 2672)
@@ -29,6 +29,8 @@
 from twistedcaldav.ical import Component as iComponent
 
 calendarserver_namespace = "http://calendarserver.org/ns/"
+pubsubnode_namespace = "urn:ietf:params:xml:ns:webdav-event:prop:node"
+pubsubnotify_namespace = "urn:ietf:params:xml:ns:webdav-event:prop:notify"
 
 calendarserver_proxy_compliance = (
     "calendar-proxy",
@@ -244,6 +246,46 @@
     namespace = calendarserver_namespace
     name = "utc-offset"
 
+class PubSubNotifyProperty (davxml.WebDAVTextElement):
+    """
+    A calendarhomefile property to indicate whether pubsub notifications are
+    published for the resource.
+    (http://tools.ietf.org/draft/draft-hildebrand-webdav-notify/draft-hildebrand-webdav-notify-00.txt)
+    """
+    namespace = pubsubnotify_namespace
+    name = "notify"
+
+class PubSubNodeProperty (davxml.WebDAVElement):
+    """
+    A calendarhomefile property to indicate the pubsub service and node to
+    subscribe to for notifications.
+    (http://tools.ietf.org/draft/draft-hildebrand-webdav-notify/draft-hildebrand-webdav-notify-00.txt)
+    """
+    namespace = pubsubnode_namespace
+    name = "node"
+
+    allowed_children = {
+        (pubsubnode_namespace, "service"): (0, 1),
+        (pubsubnode_namespace, "nodeid"): (0, 1),
+    }
+
+class PubSubNodeId (davxml.WebDAVTextElement):
+    """
+    A pubsub node path
+    """
+    namespace = pubsubnode_namespace
+    name = "nodeid"
+
+class PubSubService (davxml.WebDAVTextElement):
+    """
+    A pubsub service name
+    """
+    namespace = pubsubnode_namespace
+    name = "service"
+
+
+
+
 ##
 # Extensions to davxml.ResourceType
 ##

Modified: CalendarServer/branches/users/sagen/xmpp/twistedcaldav/notify.py
===================================================================
--- CalendarServer/branches/users/sagen/xmpp/twistedcaldav/notify.py	2008-07-09 18:41:34 UTC (rev 2671)
+++ CalendarServer/branches/users/sagen/xmpp/twistedcaldav/notify.py	2008-07-10 06:18:25 UTC (rev 2672)
@@ -51,7 +51,9 @@
 from zope.interface import Interface, implements
 
 __all__ = '''
-Coalescer getNotificationClient INotifier installNotificationClient
+Coalescer getNotificationClient
+getPubSubConfiguration getPubSubPath
+INotifier installNotificationClient
 InternalNotificationFactory InternalNotificationProtocol
 NotificationClient NotificationClientFactory NotificationClientLineProtocol
 NotificationClientUserMixIn NotificationOptions NotificationServiceMaker
@@ -78,6 +80,7 @@
         getNotificationClient().send(uri)
 
 
+
 class NotificationClientLineProtocol(basic.LineReceiver, LoggingMixIn):
     """
     Notification Client Line Protocol
@@ -423,7 +426,6 @@
     implements(INotifier)
 
     pubsubNS = 'http://jabber.org/protocol/pubsub'
-    nodeNameFormat = '/Public/CalDAV/%s/%s'
 
     nodeConfiguration = {
         'pubsub#deliver_payloads' : '0',
@@ -447,7 +449,7 @@
 
     def uriToNodeName(self, uri):
         principal = uri.split('/')[3]
-        return self.nodeNameFormat % ('test', principal)
+        return getPubSubPath(principal, getPubSubConfiguration())
 
     def publishNode(self, nodeName):
         if self.xmlStream is not None:
@@ -648,12 +650,25 @@
             'replace'))
 
 
+def getPubSubConfiguration():
+    # TODO: Should probably cache this
+    results = { 'enabled' : False }
 
+    # return the first enabled xmpp service settings in the config file
+    for settings in config.Notifications["Services"]:
+        if (settings["Service"] == "twistedcaldav.notify.XMPPNotifierService"
+            and settings["Enabled"]):
+            results['enabled'] = True
+            results['service'] = settings['ServiceAddress']
+            results['host'] = config.ServerHostName
+            results['port'] = config.SSLPort or config.HTTPPort
 
+    return results
 
+def getPubSubPath(guid, pubSubConfiguration):
+    return ("/Public/CalDAV/%s-%d/%s/" % (pubSubConfiguration['host'],
+        pubSubConfiguration['port'], guid))
 
-
-
 #
 # Notification Server service config
 #

Modified: CalendarServer/branches/users/sagen/xmpp/twistedcaldav/static.py
===================================================================
--- CalendarServer/branches/users/sagen/xmpp/twistedcaldav/static.py	2008-07-09 18:41:34 UTC (rev 2671)
+++ CalendarServer/branches/users/sagen/xmpp/twistedcaldav/static.py	2008-07-10 06:18:25 UTC (rev 2672)
@@ -72,6 +72,7 @@
 from twistedcaldav.timezoneservice import TimezoneServiceResource
 
 from twistedcaldav.cache import DisabledCacheNotifier, PropfindCacheMixin
+from twistedcaldav.notify import getPubSubConfiguration, getPubSubPath
 
 log = Logger()
 
@@ -559,6 +560,12 @@
     """
     cacheNotifierFactory = DisabledCacheNotifier
 
+    # TODO: "node" should only be live if pubsub is enabled
+    liveProperties = CalDAVFile.liveProperties + (
+        (customxml.pubsubnode_namespace, "node"),
+        (customxml.pubsubnotify_namespace, "notify"),
+    )
+
     def __init__(self, path, parent, record):
         """
         @param path: the path to the file which will back the resource.
@@ -602,6 +609,27 @@
         return super(CalendarHomeFile, self).getChild(name)
 
 
+    def readProperty(self, property, request):
+        if type(property) is tuple:
+            qname = property
+        else:
+            qname = property.qname()
+
+        if qname == (customxml.pubsubnode_namespace, "node"):
+            pubSubConfiguration = getPubSubConfiguration()
+            if pubSubConfiguration['enabled']:
+                return succeed(customxml.PubSubNodeProperty(
+                    customxml.PubSubService(pubSubConfiguration['service']),
+                    customxml.PubSubNodeId(getPubSubPath(self.record.guid,
+                        pubSubConfiguration))))
+
+        elif qname == (customxml.pubsubnotify_namespace, "notify"):
+            pubSubConfiguration = getPubSubConfiguration()
+            return succeed(customxml.PubSubNotifyProperty("true" if
+                pubSubConfiguration['enabled'] else "false"))
+
+        return super(CalendarHomeFile, self).readProperty(property, request)
+
 class ScheduleFile (AutoProvisioningFileMixIn, CalDAVFile):
     def __init__(self, path, parent):
         super(ScheduleFile, self).__init__(path, principalCollections=parent.principalCollections())
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20080709/b7f46fd4/attachment-0001.html 


More information about the calendarserver-changes mailing list