From 123ad7437083380cc8d1688ffac8e92355118b74 Mon Sep 17 00:00:00 2001 From: Nikos Kouremenos Date: Tue, 14 Jun 2005 14:32:30 +0000 Subject: [PATCH] patch xmpppy to have srv [via optional dep dnspython] --- src/common/xmpp/transports.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/common/xmpp/transports.py b/src/common/xmpp/transports.py index c5fade570..44228a987 100644 --- a/src/common/xmpp/transports.py +++ b/src/common/xmpp/transports.py @@ -32,6 +32,12 @@ from simplexml import ustr from client import PlugIn from protocol import * +try: + import dns.resolver +except: + pass + + class error: """An exception to be raised in case of low-level errors in methods of 'transports' module.""" def __init__(self,comment): @@ -52,6 +58,27 @@ class TCPsocket(PlugIn): self._exported_methods=[self.send,self.disconnect] self._server = server + # SRV resolver + if 'dns' in globals(): # if dnspython is available support SRV + host, port = server + possible_queries = [ + "_xmpp-client._tcp." + host, + "_jabber._tcp." + host, + ] + + for query in possible_queries: + try: + answers = [x for x in dns.resolver.query(query, 'SRV')] + if answers: + host = str (answers[0].target) + port = int (answers[0].port) + break + except: + pass + + server = (host, port) + # end of SRV resolver + def plugin(self, owner): """ Fire up connection. Return non-empty string on success. Also registers self.disconnected method in the owner's dispatcher.