Skip to content
Browse files

Tested the chat-server example against recent changes.

  • Loading branch information...
1 parent 7868298 commit a3c7a2e81e7bffa8ed9e441246fd37ce30ae8f20 @weaver weaver committed Feb 5, 2010
Showing with 22 additions and 20 deletions.
  1. +10 −9 examples/chat-server.py
  2. +12 −11 xmpp/core.py
View
19 examples/chat-server.py
@@ -2,20 +2,20 @@
class ChatServer(xmpp.Plugin):
- @xmpp.stanza('{jabber:client}iq/{vcard-temp}vCard')
+ @xmpp.iq('{vcard-temp}vCard')
def vcard(self, iq):
if iq.get('type') == 'get':
return self.iq('result', iq, self.E.vCard(
{ 'xmlns': 'vcard-temp' },
self.E('FN', 'No Name')
))
- @xmpp.stanza('{jabber:client}iq/{jabber:iq:roster}query')
+ @xmpp.iq('{jabber:iq:roster}query')
def roster(self, iq):
assert iq.get('type') == 'get'
return self.iq('result', iq, self.E.query(xmlns='jabber:iq:roster'))
- @xmpp.stanza('{jabber:client}iq/{urn:xmpp:ping}ping')
+ @xmpp.iq('{urn:xmpp:ping}ping')
def ping(self, iq):
return self.iq('result', iq)
@@ -30,14 +30,15 @@ def presense(self, elem):
pass
if __name__ == '__main__':
-
- #create a server with 2 users: user1@example.net and user2@example.net
+
+ ## Create a server application with 2 users: user1@example.net and
+ ## user2@example.net.
server = xmpp.Server({
'plugins': [ChatServer],
- 'auth': xmpp.ServerAuth('xmpp', 'example.net', { 'user1': 'password1', 'user2': 'password2' }),
- 'resources': xmpp.state.Resources()
- # 'certfile': os.path.join(os.path.dirname(__file__), 'certs/self.crt'),
- # 'keyfile': os.path.join(os.path.dirname(__file__), 'certs/self.key')
+ 'host': 'example.net',
+ 'users': { 'user1': 'password1', 'user2': 'password2' },
+ 'certfile': os.path.join(os.path.dirname(__file__), 'certs/self.crt'),
+ 'keyfile': os.path.join(os.path.dirname(__file__), 'certs/self.key')
})
SP = xmpp.TCPServer(server).bind('127.0.0.1', 5222)
View
23 xmpp/core.py
@@ -65,7 +65,7 @@ def on_stream_authorized(self, auth):
def on_stream_bound(self, bindings):
self.authJID = bindings.jid
- self.bindings = bindings
+ self.resources = bindings.resources
def timeout(self, delay, callback):
self.stream.io.add_timeout(time.time() + delay, callback)
@@ -209,7 +209,7 @@ def stanza_error(self, elem, kind, condition, text=None):
error.append(self.E.text({ 'xmlns': self.STANZAS }, text))
stanza = self.E(elem.tag, {
- 'from': self.fromJID,
+ 'from': self.serverJID,
'type': 'error',
'id': elem.get('id')
})
@@ -226,7 +226,7 @@ def install_features(self, features=None):
## Bind. They are updated by event listeners; see listen().
self.secured = False
self.authJID = None
- self.bindings = None
+ self.resources = None
self.features = features.install(self.state) if features else ()
return self
@@ -309,13 +309,10 @@ def iq_send(self, kind, ident, *data):
*data
))
- def message(self, elem):
- if not self.authJID:
- return self.stream_error('not-authorized')
-
- def presense(self, elem):
- if not self.authJID:
- return self.stream_error('not-authorized')
+ def routes(self, jid):
+ if self.resources is None:
+ raise state.NoRoute(jid)
+ return self.resources.routes(jid)
### ---------- Private ----------
@@ -389,7 +386,11 @@ class TLS(plugin.Feature):
def __init__(self, **options):
self.options = options
- self._active = True
+ self._active = (
+ not options.get('server_side')
+ or (options.get('keyfile') and options.get('certfile'))
+ )
+ print 'active?', options, self._active
def active(self):
return self._active and self.use_tls()

0 comments on commit a3c7a2e

Please sign in to comment.
Something went wrong with that request. Please try again.