Some improvments in class handling

master
Stephane Bortzmeyer 10 years ago
parent eb7561780d
commit 661cc0165b
  1. 32
      DNSLG/Formatter.py
  2. 5
      DNSLG/__init__.py
  3. 2
      setup.py
  4. 12
      tests.sh

@ -47,9 +47,9 @@ class Formatter():
self.myversion = "VERSION UNKNOWN"
self.domain = domain
def format(self, answer, qtype, flags, querier):
def format(self, answer, qtype, qclass, flags, querier):
""" Parameter "answer" must be of type
Answer.ExtendedAnswer. "qtype" is a string, flags an integer
Answer.ExtendedAnswer. "qtype" and "qclass" are strings, flags an integer
and querier a DNSLG.Querier. This method changes the internal
state of the Formatter, it returns nothing."""
pass
@ -61,14 +61,18 @@ class Formatter():
# TEXT
class TextFormatter(Formatter):
def format(self, answer, qtype, flags, querier):
def format(self, answer, qtype, qclass, flags, querier):
# TODO: it would be nice one day to have a short format to
# have only data, not headers. Or may be several short
# formats, suitable for typical Unix text parsing tools. In
# the mean time, use "zone" for that.
self.output = ""
self.output += "Query for: %s, type %s\n" % (self.domain.encode(querier.encoding),
qtype)
if qclass != 'IN':
qclass_text = ", class %s" % qclass
else:
qclass_text = ""
self.output += "Query for: %s, type %s%s\n" % (self.domain.encode(querier.encoding),
qtype, qclass_text)
str_flags = ""
if flags & dns.flags.AD:
str_flags += "/ Authentic Data "
@ -163,10 +167,14 @@ class TextFormatter(Formatter):
# ZONE FILE
class ZoneFormatter(Formatter):
def format(self, answer, qtype, flags, querier):
def format(self, answer, qtype, qclass, flags, querier):
self.output = ""
self.output += "; Question: %s, type %s\n" % (self.domain.encode(querier.encoding),
qtype)
if qclass != 'IN':
qclass_text = ", class %s" % qclass
else:
qclass_text = ""
self.output += "; Question: %s, type %s%s\n" % (self.domain.encode(querier.encoding),
qtype, qclass_text)
str_flags = ""
if flags & dns.flags.AD:
str_flags += " ad "
@ -255,10 +263,10 @@ import json
# http://docs.python.org/library/json.html
class JsonFormatter(Formatter):
def format(self, answer, qtype, flags, querier):
def format(self, answer, qtype, qclass, flags, querier):
self.object = {}
self.object['ReturnCode'] = "NOERROR"
self.object['QuestionSection'] = {'Qname': self.domain, 'Qtype': qtype}
self.object['QuestionSection'] = {'Qname': self.domain, 'Qtype': qtype, 'Qclass': qclass}
if flags & dns.flags.AD:
self.object['AD'] = True
if flags & dns.flags.AA:
@ -452,7 +460,7 @@ unknown_xml_template = """
# That's strange in a non-binary format like XML.
class XmlFormatter(Formatter):
def format(self, answer, qtype, flags, querier):
def format(self, answer, qtype, qclass, flags, querier):
self.xml_template = simpleTAL.compileXMLTemplate (xml_template)
self.set_template = simpleTAL.compileXMLTemplate (set_xml_template)
self.a_template = simpleTAL.compileXMLTemplate (a_xml_template)
@ -844,7 +852,7 @@ class HtmlFormatter(Formatter):
result += "%i second%s" % (seconds, plural)
return result
def format(self, answer, qtype, flags, querier):
def format(self, answer, qtype, qclass, flags, querier):
self.template = simpleTAL.compileXMLTemplate (html_template)
self.address_template = simpleTAL.compileXMLTemplate (address_html_template)
self.version_template = simpleTAL.compileXMLTemplate (version_html_template)

@ -189,6 +189,7 @@ Disallow: /
else:
domain = args
qtype = 'ADDR'
qclass = 'IN'
else:
if reverse:
domain = str(dns.reversename.from_address(args[:slashpos]))
@ -273,13 +274,13 @@ Disallow: /
if answer is None:
query_end = datetime.now()
self.delay = query_end - query_start
formatter.format(None, qtype, 0, self)
formatter.format(None, qtype, qclass, 0, self)
output = formatter.result(self)
send_response(start_response, '200 OK', output, mtype)
return [output]
query_end = datetime.now()
self.delay = query_end - query_start
formatter.format(answer, qtype, answer.flags, self)
formatter.format(answer, qtype, qclass, answer.flags, self)
output = formatter.result(self)
send_response(start_response, '200 OK', output, mtype)
except Resolver.UnknownRRtype:

@ -6,7 +6,7 @@ use_setuptools()
from setuptools import setup
setup(name='DNS-LG',
version='2013020202',
version='2013020203',
description='DNS Looking Glass',
license='BSD',
author='Stephane Bortzmeyer',

@ -176,6 +176,18 @@ done
echo ""
delay
echo Existing classes
${WEB} ${URL}/fr/SOA/IN
# Will fail, since the name servers do not serve this class
${WEB} ${URL}/fr/SOA/CH
echo ""
delay
echo Unknown class
${WEB} ${URL}/fr/SOA/XX
echo ""
delay
echo IDN
# Important to test all output formats since they have very different
# Unicode capabilities

Loading…
Cancel
Save