[CalendarServer-changes] [2656] CalendarServer/branches/users/sagen/xmpp
source_changes at macosforge.org
source_changes at macosforge.org
Wed Jul 2 19:09:14 PDT 2008
Revision: 2656
http://trac.macosforge.org/projects/calendarserver/changeset/2656
Author: sagen at apple.com
Date: 2008-07-02 19:09:14 -0700 (Wed, 02 Jul 2008)
Log Message:
-----------
Starting work on XMPP, as well as cleaning up config for notifications and allowing multiple notifiers to be specified
Modified Paths:
--------------
CalendarServer/branches/users/sagen/xmpp/conf/caldavd-test.plist
CalendarServer/branches/users/sagen/xmpp/twistedcaldav/cache.py
CalendarServer/branches/users/sagen/xmpp/twistedcaldav/cluster.py
CalendarServer/branches/users/sagen/xmpp/twistedcaldav/config.py
CalendarServer/branches/users/sagen/xmpp/twistedcaldav/notify.py
CalendarServer/branches/users/sagen/xmpp/twistedcaldav/tap.py
Modified: CalendarServer/branches/users/sagen/xmpp/conf/caldavd-test.plist
===================================================================
--- CalendarServer/branches/users/sagen/xmpp/conf/caldavd-test.plist 2008-07-02 21:17:27 UTC (rev 2655)
+++ CalendarServer/branches/users/sagen/xmpp/conf/caldavd-test.plist 2008-07-03 02:09:14 UTC (rev 2656)
@@ -407,20 +407,47 @@
<!--
Notifications
-->
- <key>EnableNotifications</key>
- <true/>
- <key>CoalesceSeconds</key>
- <integer>10</integer>
- <key>InternalNotificationHost</key>
- <string>localhost</string>
- <key>InternalNotificationPort</key>
- <integer>62309</integer>
- <key>ExternalNotificationService</key>
- <string>twistedcaldav.notify.SimpleLineNotifierService</string>
- <key>SimpleLineNotificationPort</key>
- <integer>62308</integer>
+ <key>Notifications</key>
+ <dict>
+ <key>Enabled</key>
+ <true/>
+ <key>CoalesceSeconds</key>
+ <integer>10</integer>
+ <key>InternalNotificationHost</key>
+ <string>localhost</string>
+ <key>InternalNotificationPort</key>
+ <integer>62309</integer>
+ <key>Services</key>
+ <array>
+ <dict>
+ <key>Service</key>
+ <string>twistedcaldav.notify.SimpleLineNotifierService</string>
+ <key>Enabled</key>
+ <true/>
+ <key>Port</key>
+ <integer>62308</integer>
+ </dict>
+ <dict>
+ <key>Service</key>
+ <string>twistedcaldav.notify.XMPPNotifierService</string>
+ <key>Enabled</key>
+ <false/>
+ <key>Host</key>
+ <string>mashmore1.apple.com</string>
+ <key>Port</key>
+ <integer>5222</integer>
+ <key>JID</key>
+ <string>jid_goes_here/resource</string>
+ <key>Password</key>
+ <string>password_goes_here</string>
+ </dict>
+ </array>
+
+ </dict>
+
+
<!--
Miscellaneous items
-->
Modified: CalendarServer/branches/users/sagen/xmpp/twistedcaldav/cache.py
===================================================================
--- CalendarServer/branches/users/sagen/xmpp/twistedcaldav/cache.py 2008-07-02 21:17:27 UTC (rev 2655)
+++ CalendarServer/branches/users/sagen/xmpp/twistedcaldav/cache.py 2008-07-03 02:09:14 UTC (rev 2656)
@@ -86,7 +86,7 @@
url = self._resource.url()
- if config.EnableNotifications:
+ if config.Notifications["Enabled"]:
self.log_debug("Notifications are enabled: %s" % (url,))
self.sendNotification(url)
Modified: CalendarServer/branches/users/sagen/xmpp/twistedcaldav/cluster.py
===================================================================
--- CalendarServer/branches/users/sagen/xmpp/twistedcaldav/cluster.py 2008-07-02 21:17:27 UTC (rev 2655)
+++ CalendarServer/branches/users/sagen/xmpp/twistedcaldav/cluster.py 2008-07-03 02:09:14 UTC (rev 2656)
@@ -309,8 +309,8 @@
monitor.addProcess('memcached', memcachedArgv, env=parentEnv)
- if (config.EnableNotifications and
- config.InternalNotificationHost == "localhost"):
+ if (config.Notifications["Enabled"] and
+ config.Notifications["InternalNotificationHost"] == "localhost"):
log.msg("Adding notification service")
notificationsArgv = [
Modified: CalendarServer/branches/users/sagen/xmpp/twistedcaldav/config.py
===================================================================
--- CalendarServer/branches/users/sagen/xmpp/twistedcaldav/config.py 2008-07-02 21:17:27 UTC (rev 2655)
+++ CalendarServer/branches/users/sagen/xmpp/twistedcaldav/config.py 2008-07-03 02:09:14 UTC (rev 2656)
@@ -171,13 +171,22 @@
#
# Notifications
#
- "EnableNotifications" : False,
- "CoalesceSeconds" : 10,
- "InternalNotificationHost" : "localhost",
- "InternalNotificationPort" : 62309,
- "ExternalNotificationService" : "twistedcaldav.notify.SimpleLineNotifierService",
- "SimpleLineNotificationPort" : 62308,
+ "Notifications" : {
+ "Enabled" : True,
+ "CoalesceSeconds" : 10,
+ "InternalNotificationHost" : "localhost",
+ "InternalNotificationPort" : 62309,
+
+ "Services" : [
+ {
+ "Service" : "twistedcaldav.notify.SimpleLineNotifierService",
+ "Enabled" : True,
+ "Port" : 62308,
+ },
+ ]
+ },
+
#
# Implementation details
#
Modified: CalendarServer/branches/users/sagen/xmpp/twistedcaldav/notify.py
===================================================================
--- CalendarServer/branches/users/sagen/xmpp/twistedcaldav/notify.py 2008-07-02 21:17:27 UTC (rev 2655)
+++ CalendarServer/branches/users/sagen/xmpp/twistedcaldav/notify.py 2008-07-03 02:09:14 UTC (rev 2656)
@@ -33,15 +33,20 @@
"""
# TODO: bindAddress to local
+# TODO: XMPP support
import os
from twisted.internet import reactor, protocol
from twisted.protocols import basic
from twisted.plugin import IPlugin
from twisted.application import internet, service
-from twistedcaldav.log import LoggingMixIn
from twisted.python.usage import Options, UsageError
from twisted.python.reflect import namedClass
+from twisted.words.protocols.jabber import xmlstream
+from twisted.words.protocols.jabber.jid import JID
+from twisted.words.protocols.jabber.client import BasicAuthenticator
+from twisted.words.xish import domish
+from twistedcaldav.log import LoggingMixIn
from twistedcaldav.config import config, parseConfig, defaultConfig
from zope.interface import Interface, implements
@@ -405,6 +410,73 @@
+
+
+
+
+
+class XMPPNotifier(object):
+ implements(INotifier)
+
+ def __init__(self):
+ self.observers = set()
+
+ def enqueue(self, uri):
+ pass
+
+
+class XMPPNotificationFactory(xmlstream.XmlStreamFactory, LoggingMixIn):
+
+ def __init__(self, notifier, jid, password):
+ self.notifier = notifier
+ self.jid = jid
+
+ xmlstream.XmlStreamFactory.__init__(self,
+ BasicAuthenticator(JID(jid), password))
+
+ self.addBootstrap('//event/stream/authd', self.handleAuthSuccess)
+ self.addBootstrap('//event/stream/authe', self.handleAuthFailure)
+ self.addBootstrap('//event/client/basicauth/invaliduser',
+ self.handleAuthFailure)
+ self.addBootstrap('//event/client/basicauth/authfailed',
+ self.handleAuthFailure)
+
+
+ def handleAuthSuccess(self, xmlstream):
+ self.log_info("XMPP authentication successful: %s" % (self.jid,))
+ self.xmlstream = xmlstream
+ presence = domish.Element(('jabber:client', 'presence'))
+ xmlstream.send(presence)
+
+ xmlstream.addObserver('/message', self.handleMessage)
+ xmlstream.addObserver('/presence', self.trafficLog)
+ xmlstream.addObserver('/iq', self.trafficLog)
+
+ def handleAuthFailure(self, e):
+ self.log_error("Failed to authenticate with XMPP: %s" % (e,))
+
+ def handleMessage(self, elem):
+ self.log_info("GOT THIS")
+ self.trafficLog(elem)
+ sender = JID(elem['from']).full()
+ body = getattr(elem, 'body', None)
+ if body:
+ message = domish.Element(('jabber:client', 'message'))
+ message['to'] = sender
+ message.addChild(body)
+ self.log_info("SENDING THIS")
+ self.trafficLog(message)
+ self.xmlstream.send(message)
+
+ def trafficLog(self, elem):
+ self.log_info(elem.toXml().encode('utf-8'))
+
+
+
+
+
+
+
#
# Notification Server service config
#
@@ -505,14 +577,15 @@
multiService = service.MultiService()
- externalServiceClass = namedClass(config.ExternalNotificationService)
- externalService = externalServiceClass()
- externalService.setServiceParent(multiService)
+ for settings in config.Notifications["Services"]:
+ if settings["Enabled"]:
+ externalService = namedClass(settings["Service"])(settings)
+ externalService.setServiceParent(multiService)
internet.TCPServer(
- config.InternalNotificationPort,
+ config.Notifications["InternalNotificationPort"],
InternalNotificationFactory(externalService,
- delaySeconds=config.CoalesceSeconds)
+ delaySeconds=config.Notifications["CoalesceSeconds"])
).setServiceParent(multiService)
return multiService
@@ -520,9 +593,9 @@
class SimpleLineNotifierService(service.Service):
- def __init__(self):
+ def __init__(self, settings):
self.notifier = SimpleLineNotifier()
- self.server = internet.TCPServer(config.SimpleLineNotificationPort,
+ self.server = internet.TCPServer(settings["Port"],
SimpleLineNotificationFactory(self.notifier))
def enqueue(self, uri):
@@ -533,3 +606,22 @@
def stopService(self):
self.server.stopService()
+
+
+class XMPPNotifierService(service.Service):
+
+ def __init__(self, settings):
+ self.notifier = XMPPNotifier()
+ self.client = internet.TCPClient(settings["Host"], settings["Port"],
+ XMPPNotificationFactory(self.notifier, settings["JID"],
+ settings["Password"]))
+
+ def enqueue(self, uri):
+ self.notifier.enqueue(uri)
+
+ def startService(self):
+ self.client.startService()
+
+ def stopService(self):
+ self.client.stopService()
+
Modified: CalendarServer/branches/users/sagen/xmpp/twistedcaldav/tap.py
===================================================================
--- CalendarServer/branches/users/sagen/xmpp/twistedcaldav/tap.py 2008-07-02 21:17:27 UTC (rev 2655)
+++ CalendarServer/branches/users/sagen/xmpp/twistedcaldav/tap.py 2008-07-03 02:09:14 UTC (rev 2656)
@@ -495,10 +495,10 @@
#
# Configure NotificationClient
#
- if config.EnableNotifications:
+ if config.Notifications["Enabled"]:
installNotificationClient(reactor,
- config.InternalNotificationHost,
- config.InternalNotificationPort)
+ config.Notifications["InternalNotificationHost"],
+ config.Notifications["InternalNotificationPort"])
#
# Setup Resource hierarchy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20080702/d4c7a0bf/attachment-0001.html
More information about the calendarserver-changes
mailing list