summaryrefslogtreecommitdiff
path: root/sleekxmpp/componentxmpp.py
diff options
context:
space:
mode:
authorJoe Hildebrand <joe-github@cursive.net>2010-07-20 13:55:48 -0700
committerJoe Hildebrand <joe-github@cursive.net>2010-07-20 13:55:48 -0700
commitd70a6e6f32d5d5f9bd4d4d97f987f1667f6eab40 (patch)
treeee5879c94c1cd4c9c27e7d91eded360f548604ac /sleekxmpp/componentxmpp.py
parent66e92c6c9fece2ce5a2b62230a003c09f3ec0a7f (diff)
downloadslixmpp-d70a6e6f32d5d5f9bd4d4d97f987f1667f6eab40.tar.gz
slixmpp-d70a6e6f32d5d5f9bd4d4d97f987f1667f6eab40.tar.bz2
slixmpp-d70a6e6f32d5d5f9bd4d4d97f987f1667f6eab40.tar.xz
slixmpp-d70a6e6f32d5d5f9bd4d4d97f987f1667f6eab40.zip
Issue 26. Only set from address in reply() for components
Diffstat (limited to 'sleekxmpp/componentxmpp.py')
-rwxr-xr-xsleekxmpp/componentxmpp.py101
1 files changed, 51 insertions, 50 deletions
diff --git a/sleekxmpp/componentxmpp.py b/sleekxmpp/componentxmpp.py
index 4d39ce80..818d800b 100755
--- a/sleekxmpp/componentxmpp.py
+++ b/sleekxmpp/componentxmpp.py
@@ -30,59 +30,60 @@ from . import stanza
import hashlib
srvsupport = True
try:
- import dns.resolver
+ import dns.resolver
except ImportError:
- srvsupport = False
+ srvsupport = False
class ComponentXMPP(basexmpp, XMLStream):
- """SleekXMPP's client class. Use only for good, not evil."""
+ """SleekXMPP's client class. Use only for good, not evil."""
- def __init__(self, jid, secret, host, port, plugin_config = {}, plugin_whitelist=[], use_jc_ns=False):
- XMLStream.__init__(self)
- if use_jc_ns:
- self.default_ns = 'jabber:client'
- else:
- self.default_ns = 'jabber:component:accept'
- basexmpp.__init__(self)
- self.auto_authorize = None
- self.stream_header = "<stream:stream xmlns='jabber:component:accept' xmlns:stream='http://etherx.jabber.org/streams' to='%s'>" % jid
- self.stream_footer = "</stream:stream>"
- self.server_host = host
- self.server_port = port
- self.set_jid(jid)
- self.secret = secret
- self.registerHandler(Callback('Handshake', MatchXPath('{jabber:component:accept}handshake'), self._handleHandshake))
-
- def __getitem__(self, key):
- if key in self.plugin:
- return self.plugin[key]
- else:
- logging.warning("""Plugin "%s" is not loaded.""" % key)
- return False
-
- def get(self, key, default):
- return self.plugin.get(key, default)
-
- def incoming_filter(self, xmlobj):
- if xmlobj.tag.startswith('{jabber:client}'):
- xmlobj.tag = xmlobj.tag.replace('jabber:client', self.default_ns)
- for sub in xmlobj:
- self.incoming_filter(sub)
- return xmlobj
+ def __init__(self, jid, secret, host, port, plugin_config = {}, plugin_whitelist=[], use_jc_ns=False):
+ XMLStream.__init__(self)
+ if use_jc_ns:
+ self.default_ns = 'jabber:client'
+ else:
+ self.default_ns = 'jabber:component:accept'
+ basexmpp.__init__(self)
+ self.auto_authorize = None
+ self.stream_header = "<stream:stream xmlns='jabber:component:accept' xmlns:stream='http://etherx.jabber.org/streams' to='%s'>" % jid
+ self.stream_footer = "</stream:stream>"
+ self.server_host = host
+ self.server_port = port
+ self.set_jid(jid)
+ self.secret = secret
+ self.is_component = True
+ self.registerHandler(Callback('Handshake', MatchXPath('{jabber:component:accept}handshake'), self._handleHandshake))
+
+ def __getitem__(self, key):
+ if key in self.plugin:
+ return self.plugin[key]
+ else:
+ logging.warning("""Plugin "%s" is not loaded.""" % key)
+ return False
+
+ def get(self, key, default):
+ return self.plugin.get(key, default)
+
+ def incoming_filter(self, xmlobj):
+ if xmlobj.tag.startswith('{jabber:client}'):
+ xmlobj.tag = xmlobj.tag.replace('jabber:client', self.default_ns)
+ for sub in xmlobj:
+ self.incoming_filter(sub)
+ return xmlobj
- def start_stream_handler(self, xml):
- sid = xml.get('id', '')
- handshake = ET.Element('{jabber:component:accept}handshake')
- if sys.version_info < (3,0):
- handshake.text = hashlib.sha1("%s%s" % (sid, self.secret)).hexdigest().lower()
- else:
- handshake.text = hashlib.sha1(bytes("%s%s" % (sid, self.secret), 'utf-8')).hexdigest().lower()
- self.sendXML(handshake)
-
- def _handleHandshake(self, xml):
- self.event("session_start")
-
- def connect(self):
- logging.debug("Connecting to %s:%s" % (self.server_host, self.server_port))
- return xmlstreammod.XMLStream.connect(self, self.server_host, self.server_port)
+ def start_stream_handler(self, xml):
+ sid = xml.get('id', '')
+ handshake = ET.Element('{jabber:component:accept}handshake')
+ if sys.version_info < (3,0):
+ handshake.text = hashlib.sha1("%s%s" % (sid, self.secret)).hexdigest().lower()
+ else:
+ handshake.text = hashlib.sha1(bytes("%s%s" % (sid, self.secret), 'utf-8')).hexdigest().lower()
+ self.sendXML(handshake)
+
+ def _handleHandshake(self, xml):
+ self.event("session_start")
+
+ def connect(self):
+ logging.debug("Connecting to %s:%s" % (self.server_host, self.server_port))
+ return xmlstreammod.XMLStream.connect(self, self.server_host, self.server_port)