summaryrefslogtreecommitdiffstats
path: root/classes/servercontact.py
diff options
context:
space:
mode:
Diffstat (limited to 'classes/servercontact.py')
-rw-r--r--classes/servercontact.py45
1 files changed, 35 insertions, 10 deletions
diff --git a/classes/servercontact.py b/classes/servercontact.py
index 27b72f0..ea7216d 100644
--- a/classes/servercontact.py
+++ b/classes/servercontact.py
@@ -2,12 +2,13 @@
import defusedxml.ElementTree as Et
+# XEP-0157: Contact Addresses for XMPP Services
class ServerContact:
- def __init__(self, contact, msg, target):
- self.contact = contact
- self.message = msg
- self.target = target
-
+ """
+ plugin to process the server contact addresses from a disco query
+ """
+ def __init__(self):
+ # init all necessary variables
self.possible_vars = ['abuse-addresses',
'admin-addresses',
'feedback-addresses',
@@ -15,6 +16,9 @@ class ServerContact:
'security-addresses',
'support-addresses']
+ self.contact = None
+ self.target, self.opt_arg = None, None
+
def process(self):
# get etree from base xml
iq = Et.fromstring(str(self.contact))
@@ -36,8 +40,16 @@ class ServerContact:
# iterate over all x nodes
for child in xdata[x]:
+ # if one opt_arg is defined return just that one
+ if self.opt_arg in self.possible_vars:
+ if child.attrib['var'] == self.opt_arg:
+ # add section to result dict and append info
+ result[child.attrib['var']] = list()
+ for value in child:
+ result[child.attrib['var']].append(value.text)
+
# if node has a var attribute that matches our list process
- if child.attrib['var'] in self.possible_vars:
+ elif child.attrib['var'] in self.possible_vars:
# add section to result dict and append info
result[child.attrib['var']] = list()
for value in child:
@@ -45,17 +57,30 @@ class ServerContact:
return result
- def format_contact(self):
+ def format(self, query, target, opt_arg):
+ self.contact = query
+
+ self.target = target
+ self.opt_arg = opt_arg
+
result = self.process()
+ # if result is present continue
if result:
text = "contact addresses for %s are\n" % self.target
+ # if opt_arg is present and member of possible_vars change text line
+ if opt_arg in self.possible_vars:
+ text = "%s for %s are\n" % (self.opt_arg, self.target)
+
for key in result.keys():
- if result[key]:
- addr = ' , '.join(result[key])
- text += "- %s : %s\n" % (key, addr)
+ addr = ' , '.join(result[key])
+ text += "- %s : %s\n" % (key, addr)
else:
text = "%s has no contact addresses configured." % self.target
+ # if opt_arg is present and member of possible_vars but the key is empty change text line
+ if opt_arg in self.possible_vars:
+ text = "%s for %s are not defined." % (self.opt_arg, self.target)
+
return text