[CalendarServer-changes] [6331] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Tue Sep 21 15:35:52 PDT 2010


Revision: 6331
          http://trac.macosforge.org/projects/calendarserver/changeset/6331
Author:   sagen at apple.com
Date:     2010-09-21 15:35:48 -0700 (Tue, 21 Sep 2010)
Log Message:
-----------
Split Apple push notification DAV properties into distinct values for calendar homes and addressbook homes

Modified Paths:
--------------
    CalendarServer/trunk/conf/caldavd-test.plist
    CalendarServer/trunk/twistedcaldav/notify.py
    CalendarServer/trunk/twistedcaldav/resource.py
    CalendarServer/trunk/twistedcaldav/stdconfig.py
    CalendarServer/trunk/twistedcaldav/test/test_notify.py

Modified: CalendarServer/trunk/conf/caldavd-test.plist
===================================================================
--- CalendarServer/trunk/conf/caldavd-test.plist	2010-09-21 21:21:59 UTC (rev 6330)
+++ CalendarServer/trunk/conf/caldavd-test.plist	2010-09-21 22:35:48 UTC (rev 6331)
@@ -533,10 +533,20 @@
           <string>pubsub.xmpp.host.name</string>
 
           <!-- Apple-specific config -->
-          <key>SubscriptionURL</key>
-          <string></string>
-          <key>APSBundleID</key>
-          <string></string>
+          <key>CalDAV</key>
+          <dict>
+              <key>APSBundleID</key>
+              <string></string>
+              <key>SubscriptionURL</key>
+              <string></string>
+          </dict>
+          <key>CardDAV</key>
+          <dict>
+              <key>APSBundleID</key>
+              <string></string>
+              <key>SubscriptionURL</key>
+              <string></string>
+          </dict>
 
           <key>NodeConfiguration</key>
           <dict>

Modified: CalendarServer/trunk/twistedcaldav/notify.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/notify.py	2010-09-21 21:21:59 UTC (rev 6330)
+++ CalendarServer/trunk/twistedcaldav/notify.py	2010-09-21 22:35:48 UTC (rev 6331)
@@ -72,10 +72,12 @@
     "XMPPNotificationFactory",
     "XMPPNotifier",
     "getNodeCacher",
+    "getPubSubAPSConfiguration",
     "getPubSubConfiguration",
     "getPubSubHeartbeatURI",
     "getPubSubPath",
     "getPubSubXMPPURI",
+    "getXMPPSettings",
 ]
 
 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -1213,30 +1215,60 @@
         self.log_debug("SEND: %s" % unicode(buf, 'utf-8').encode('ascii',
             'replace'))
 
+def getXMPPSettings(config):
+    """ Return the XMPP settings if both overall notifications are enabled
+        and XMPP is enabled; None otherwise.
+    """
+    if config.Notifications.Enabled:
+        # return the first enabled xmpp service settings in the config file
+        for key, settings in config.Notifications.Services.iteritems():
+            if (settings["Service"] == "twistedcaldav.notify.XMPPNotifierService"
+                and settings["Enabled"]):
+                return settings
+    return None
 
 def getPubSubConfiguration(config):
     # TODO: Should probably cache this
     results = { 'enabled' : False }
+    settings = getXMPPSettings(config)
+    if settings is not None:
+        results['enabled'] = True
+        results['service'] = settings['ServiceAddress']
+        results['host'] = config.ServerHostName
+        results['port'] = config.SSLPort or config.HTTPPort
+        results['xmpp-server'] = (
+            settings['Host'] if settings['Port'] == 5222
+            else "%s:%d" % (settings['Host'], settings['Port'])
+        )
+        results['heartrate'] = settings['HeartbeatMinutes']
 
-    # return the first enabled xmpp service settings in the config file
-    for key, settings in config.Notifications.Services.iteritems():
-        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
-            results['xmpp-server'] = (
-                settings['Host'] if settings['Port'] == 5222
-                else "%s:%d" % (settings['Host'], settings['Port'])
-            )
-            results['subscription-url'] = settings['SubscriptionURL']
-            results['aps-bundle-id'] = settings['APSBundleID']
-            results['heartrate'] = settings['HeartbeatMinutes']
-            break
-
     return results
 
+def getPubSubAPSConfiguration(id, config):
+    """
+    Returns the Apple push notification settings specific to the notifier
+    ID, which includes a prefix that is either "CalDAV" or "CardDAV"
+    """
+    settings = getXMPPSettings(config)
+    if settings is None:
+        return None
+
+    try:
+        prefix, id = id.split("|", 1)
+    except ValueError:
+        # id has no prefix, so we can't look up APS config
+        return None
+
+    if (settings.has_key(prefix) and
+        settings[prefix]["APSBundleID"] and
+        settings[prefix]["SubscriptionURL"]):
+        return settings[prefix]
+
+    return None
+
+
+
+
 def getPubSubPath(id, pubSubConfiguration):
     """
     Generate a pubsub node path from an id and the pubsub configuration

Modified: CalendarServer/trunk/twistedcaldav/resource.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/resource.py	2010-09-21 21:21:59 UTC (rev 6330)
+++ CalendarServer/trunk/twistedcaldav/resource.py	2010-09-21 22:35:48 UTC (rev 6331)
@@ -79,7 +79,7 @@
 from twistedcaldav.index import SyncTokenValidException, Index
 from twistedcaldav.linkresource import LinkResource
 from twistedcaldav.notify import getPubSubConfiguration, getPubSubPath,\
-    getPubSubXMPPURI, getPubSubHeartbeatURI
+    getPubSubXMPPURI, getPubSubHeartbeatURI, getPubSubAPSConfiguration
 from twistedcaldav.sharing import SharedCollectionMixin, SharedHomeMixin
 from twistedcaldav.vcard import Component as vComponent
 from twistedcaldav.vcardindex import AddressBookIndex
@@ -2235,22 +2235,25 @@
         if qname == (customxml.calendarserver_namespace, "push-transports"):
             notifierID = self._newStoreHome.notifierID()
             if notifierID is not None and config.Notifications.Services.XMPPNotifier.Enabled:
-                pubSubConfiguration = getPubSubConfiguration(config)
                 children = []
-                if pubSubConfiguration['aps-bundle-id']:
+
+                apsConfiguration = getPubSubAPSConfiguration(notifierID, config)
+                if apsConfiguration:
                     children.append(
                         customxml.PubSubTransportProperty(
                             customxml.PubSubSubscriptionProperty(
                                 davxml.HRef(
-                                    pubSubConfiguration['subscription-url']
+                                    apsConfiguration["SubscriptionURL"]
                                 ),
                             ),
                             customxml.PubSubAPSBundleIDProperty(
-                                pubSubConfiguration['aps-bundle-id']
+                                apsConfiguration["APSBundleID"]
                             ),
                             type="APSD",
                         )
                     )
+
+                pubSubConfiguration = getPubSubConfiguration(config)
                 if pubSubConfiguration['xmpp-server']:
                     children.append(
                         customxml.PubSubTransportProperty(

Modified: CalendarServer/trunk/twistedcaldav/stdconfig.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/stdconfig.py	2010-09-21 21:21:59 UTC (rev 6330)
+++ CalendarServer/trunk/twistedcaldav/stdconfig.py	2010-09-21 22:35:48 UTC (rev 6331)
@@ -458,8 +458,14 @@
                 "JID" : "", # "jid at xmpp.host.name/resource"
                 "Password" : "",
                 "ServiceAddress" : "", # "pubsub.xmpp.host.name"
-                "APSBundleID" : "",
-                "SubscriptionURL" : "",
+                "CalDAV" : {
+                    "APSBundleID" : "",
+                    "SubscriptionURL" : "",
+                },
+                "CardDAV" : {
+                    "APSBundleID" : "",
+                    "SubscriptionURL" : "",
+                },
                 "NodeConfiguration" : {
                     "pubsub#deliver_payloads" : "1",
                     "pubsub#persist_items" : "1",

Modified: CalendarServer/trunk/twistedcaldav/test/test_notify.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/test/test_notify.py	2010-09-21 21:21:59 UTC (rev 6330)
+++ CalendarServer/trunk/twistedcaldav/test/test_notify.py	2010-09-21 22:35:48 UTC (rev 6331)
@@ -362,6 +362,7 @@
 class XMPPNotifierTests(TestCase):
 
     xmppEnabledConfig = Config(PListConfigProvider(DEFAULT_CONFIG))
+    xmppEnabledConfig.Notifications["Enabled"] = True
     xmppEnabledConfig.Notifications["Services"]["XMPPNotifier"]["Enabled"] = True
     xmppEnabledConfig.ServerHostName = "server.example.com"
     xmppEnabledConfig.HTTPPort = 80
@@ -498,6 +499,7 @@
     def test_sendHeartbeat(self):
 
         xmppConfig = Config(PListConfigProvider(DEFAULT_CONFIG))
+        xmppConfig.Notifications["Enabled"] = True
         xmppConfig.Notifications["Services"]["XMPPNotifier"]["Enabled"] = True
         xmppConfig.ServerHostName = "server.example.com"
         xmppConfig.HTTPPort = 80
@@ -559,3 +561,47 @@
         factory.disconnected(xmlStream)
         clock.advance(5)
         self.assertEquals(len(xmlStream.elements), 3)
+
+
+
+class ConfigurationTests(TestCase):
+
+    def test_disabled(self):
+        disabledConfig = Config(PListConfigProvider(DEFAULT_CONFIG))
+
+        # Overall notifications are disabled
+        disabledConfig.Notifications["Enabled"] = False
+        conf = getPubSubConfiguration(disabledConfig)
+        self.assertEquals(conf, { "enabled" : False })
+        conf = getXMPPSettings(disabledConfig)
+        self.assertEquals(conf, None)
+
+        # Overall notifications are enabled, but XMPP disabled
+        disabledConfig.Notifications["Enabled"] = True
+        settings = getXMPPSettings(disabledConfig)
+        self.assertEquals(settings, None)
+
+        # Overall notifications are enabled, XMPP enabled, but no APS
+        service = disabledConfig.Notifications["Services"]["XMPPNotifier"]
+        service.Enabled = True
+        conf = getPubSubAPSConfiguration("CalDAV|foo", disabledConfig)
+        self.assertEquals(conf, None)
+
+    def test_enabled(self):
+        enabledConfig = Config(PListConfigProvider(DEFAULT_CONFIG))
+        enabledConfig.Notifications["Enabled"] = True
+        service = enabledConfig.Notifications["Services"]["XMPPNotifier"]
+        service.Enabled = True
+        service.Host = "example.com"
+        service.Port = 5222
+        service.ServiceAddress = "pubsub.example.com"
+        service.CalDAV.APSBundleID = "CalDAVAPSBundleID"
+        service.CalDAV.SubscriptionURL = "CalDAVSubscriptionURL"
+        conf = getPubSubConfiguration(enabledConfig)
+        self.assertEquals(conf, {'heartrate': 30, 'service': 'pubsub.example.com', 'xmpp-server': 'example.com', 'enabled': True, 'host': '', 'port': 0} )
+        conf = getPubSubAPSConfiguration("CalDAV|foo", enabledConfig)
+        self.assertEquals(conf, {'SubscriptionURL': 'CalDAVSubscriptionURL', 'APSBundleID': 'CalDAVAPSBundleID'} )
+        conf = getPubSubAPSConfiguration("noprefix", enabledConfig)
+        self.assertEquals(conf, None)
+        conf = getPubSubAPSConfiguration("UnknownPrefix|foo", enabledConfig)
+        self.assertEquals(conf, None)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100921/2a21ede9/attachment-0001.html>


More information about the calendarserver-changes mailing list