Skip to content
Snippets Groups Projects
Commit 59464c6b authored by Yann Leboulanger's avatar Yann Leboulanger
Browse files

[dman] use dnspython if available, or switch to pydns

parent bb7e4079
No related branches found
No related tags found
No related merge requests found
......@@ -32,10 +32,19 @@
from client import PlugIn
from protocol import *
# determine which DNS resolution library is available
HAVE_DNSPYTHON = False
HAVE_PYDNS = False
try:
import dns.resolver
except:
pass
import dns.resolver # http://dnspython.org/
HAVE_DNSPYTHON = True
except ImportError :
try :
import DNS # http://pydns.sf.net/
HAVE_PYDNS = True
except ImportError :
self.DEBUG("Couldn't load a supported DNS library.", 'warn')
"SRV records will not be queried and some servers may not be accessible.")
DATA_RECEIVED='DATA RECEIVED'
DATA_SENT='DATA SENT'
......@@ -60,20 +69,28 @@ def __init__(self, server=None):
self._exported_methods=[self.send,self.disconnect]
# SRV resolver
if 'dns' in globals(): # if dnspython is available support SRV
if HAVE_DNSPYTHON or HAVE_PYDNS :
host, port = server
possible_queries = ['_xmpp-client._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
if HAVE_DNSPYTHON :
answers = [x for x in dns.resolver.query(query, 'SRV')]
if answers:
host = str (answers[0].target)
port = int (answers[0].port)
break
elif HAVE_PYDNS :
DNS.ParseResolvConf() # ensure we haven't cached an old configuration
response = DNS.Request().req(query, qtype='SRV')
answers = response.answers
if len(answers) > 0 :
_, _, port, host = answers[0]['data'] # ignore the priority and weight for now
port = int(port)
break
except:
pass
self.DEBUG('An error occurred looking up %s' % query, 'warn')
server = (host, port)
# end of SRV resolver
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment