Permalink
Browse files

Core works with ping-pong example. Still needs real TLS wrapper.

  • Loading branch information...
1 parent e4830fe commit dd66f56d64e05800d35aa86d2ae1cb96db030647 Ben Weaver committed Jan 27, 2010
Showing with 535 additions and 33 deletions.
  1. +1 −0 .gitignore
  2. +8 −5 examples/ping-pong.py
  3. +38 −6 xmpp/application.py
  4. +293 −19 xmpp/core.py
  5. +2 −2 xmpp/state.py
  6. +193 −0 xmpp/xml.py
  7. +0 −1 xmpp/xmppstream.py
View
@@ -4,3 +4,4 @@ build
dist
*.#*
*.egg-info
+old*.py
View
@@ -50,7 +50,7 @@ def stop(self):
def ping(self, elem):
self.trigger(ReceivedPing)
if self.stopped:
- return self.close_stream()
+ return self.close()
return self.send_pong()
@xmpp.stanza
@@ -68,7 +68,7 @@ def send_pong(self):
class Client(xmpp.Plugin):
- PONG_LIMIT = 5
+ PONG_LIMIT = 2
def __init__(self):
self.pongs = 0
@@ -97,6 +97,7 @@ def __init__(self, name, app, dest):
self.name = name
self.dest = dest
self.reader = None
+ self.socket = None
print '%s: OPEN' % self.name
self.target = app(('127.0.0.1', 0), self)
@@ -115,10 +116,12 @@ def close(self):
print '%s: CLOSED' % self.name
if __name__ == '__main__':
- server = xmpp.Server([PingPong])
- client = xmpp.Client([PingPong, Client])
+ CA = xmpp.ClientAuth('xmpp', 'example.net', 'user@example.net', 'secret')
+ client = xmpp.Client(CA, [PingPong, Client])
+ CP = Stream('C', client, lambda d: SP.reader(d))
+ SA = xmpp.ServerAuth('xmpp', 'example.net', { 'user@example.net': 'secret' })
+ server = xmpp.Server(SA, [PingPong])
SP = Stream('S', server, lambda d: CP.reader(d))
- CP = Stream('C', client, lambda d: SP.reader(d))
Stream.loop()
View
@@ -4,19 +4,19 @@
"""application -- XMPP application and plugins"""
from __future__ import absolute_import
-import functools, collections
+import functools, collections, sasl
from . import xml, interfaces, core
__all__ = (
- 'Server', 'Client', 'Application',
+ 'Server', 'Client', 'Application', 'ServerAuth', 'ClientAuth',
'bind', 'stanza', 'Plugin', 'PluginError'
)
-def Server(*args, **kwargs):
- return Application(core.ServerCore, *args, **kwargs)
+def Server(auth, *args, **kwargs):
+ return Application(core.ServerCore, *args, auth=auth, **kwargs)
-def Client(*args, **kwargs):
- return Application(core.ClientCore, *args, **kwargs)
+def Client(auth, *args, **kwargs):
+ return Application(core.ClientCore, *args, auth=auth, **kwargs)
def Application(Core, plugins=(), **kwargs):
"""Declare an XMPP Application. An application is an XMLHandler
@@ -26,6 +26,34 @@ def Application(Core, plugins=(), **kwargs):
plugins = CompiledPlugins(plugins)
return functools.partial(Core, plugins=plugins, **kwargs)
+def ServerAuth(serv_type, host, users):
+
+ def user():
+ raise NotImplementedError
+
+ def password():
+ raise NotImplementedError
+
+ return sasl.SimpleAuth(
+ sasl.DigestMD5Password,
+ users,
+ user,
+ password,
+ lambda: serv_type,
+ lambda: host
+ )
+
+def ClientAuth(serv_type, host, username, password):
+
+ return sasl.SimpleAuth(
+ sasl.DigestMD5Password,
+ {},
+ lambda: username,
+ lambda: password,
+ lambda: serv_type,
+ lambda: host
+ )
+
### Static plugin decorators
@@ -465,6 +493,10 @@ def close(self):
self.__core.close()
return None
+ def error(self, *args, **kwargs):
+ self.__core.error(*args, **kwargs)
+ return None
+
## ---------- Events ----------
def stanza(self, *args, **kwargs):
Oops, something went wrong.

0 comments on commit dd66f56

Please sign in to comment.