Fix usage of the 0004 plugin interface

form['fields'] is an ordered list of fields while most plugins expect a
dict there. Fixes, among other things, a caps bug.
This commit is contained in:
mathieui 2018-02-11 16:42:59 +01:00
parent 20e88fda50
commit e177726387
No known key found for this signature in database
GPG Key ID: C59F84CEEFD616E3
6 changed files with 13 additions and 13 deletions

View File

@ -23,7 +23,7 @@ class Form(ElementBase):
namespace = 'jabber:x:data'
name = 'x'
plugin_attrib = 'form'
interfaces = OrderedSet(('instructions', 'reported', 'title', 'type', 'items', ))
interfaces = OrderedSet(('instructions', 'reported', 'title', 'type', 'items', 'values'))
sub_interfaces = {'title'}
form_types = {'cancel', 'form', 'result', 'submit'}

View File

@ -185,14 +185,14 @@ class XEP_0060(BasePlugin):
if config is not None:
form_type = 'http://jabber.org/protocol/pubsub#node_config'
if 'FORM_TYPE' in config['fields']:
if 'FORM_TYPE' in config.get_fields():
config.field['FORM_TYPE']['value'] = form_type
else:
config.add_field(var='FORM_TYPE',
ftype='hidden',
value=form_type)
if ntype:
if 'pubsub#node_type' in config['fields']:
if 'pubsub#node_type' in config.get_fields():
config.field['pubsub#node_type']['value'] = ntype
else:
config.add_field(var='pubsub#node_type', value=ntype)

View File

@ -97,7 +97,7 @@ class XEP_0095(BasePlugin):
extension='bad-profile',
extension_ns=SI.namespace)
neg = iq['si']['feature_neg']['form']['fields']
neg = iq['si']['feature_neg']['form'].get_fields()
options = neg['stream-method']['options'] or []
methods = []
for opt in options:

View File

@ -199,8 +199,8 @@ class XEP_0115(BasePlugin):
log.debug("Non form extension found, ignoring for caps")
caps.xml.remove(stanza.xml)
continue
if 'FORM_TYPE' in stanza['fields']:
f_type = tuple(stanza['fields']['FORM_TYPE']['value'])
if 'FORM_TYPE' in stanza.get_fields():
f_type = tuple(stanza.get_fields()['FORM_TYPE']['value'])
form_types.append(f_type)
deduped_form_types.add(f_type)
if len(form_types) != len(deduped_form_types):
@ -214,7 +214,7 @@ class XEP_0115(BasePlugin):
log.debug("Extra FORM_TYPE data, invalid for caps")
return False
if stanza['fields']['FORM_TYPE']['type'] != 'hidden':
if stanza.get_fields()['FORM_TYPE']['type'] != 'hidden':
log.debug("Field FORM_TYPE type not 'hidden', " + \
"ignoring form for caps")
caps.xml.remove(stanza.xml)
@ -253,7 +253,7 @@ class XEP_0115(BasePlugin):
for stanza in info['substanzas']:
if isinstance(stanza, self.xmpp['xep_0004'].stanza.Form):
if 'FORM_TYPE' in stanza['fields']:
if 'FORM_TYPE' in stanza.get_fields():
f_type = stanza['values']['FORM_TYPE']
if len(f_type):
f_type = f_type[0]
@ -265,11 +265,11 @@ class XEP_0115(BasePlugin):
for f_type in sorted_forms:
for form in form_types[f_type]:
S += '%s<' % f_type
fields = sorted(form['fields'].keys())
fields = sorted(form.get_fields().keys())
fields.remove('FORM_TYPE')
for field in fields:
S += '%s<' % field
vals = form['fields'][field].get_value(convert=False)
vals = form.get_fields()[field].get_value(convert=False)
if vals is None:
S += '<'
else:

View File

@ -73,11 +73,11 @@ class XEP_0222(BasePlugin):
ftype='hidden',
value='http://jabber.org/protocol/pubsub#publish-options')
fields = options['fields']
fields = options.get_fields()
for field, value in self.profile.items():
if field not in fields:
options.add_field(var=field)
options['fields'][field]['value'] = value
options.get_fields()[field]['value'] = value
return self.xmpp['xep_0163'].publish(stanza, node,
options=options,

View File

@ -78,7 +78,7 @@ class XEP_0223(BasePlugin):
for field, value in self.profile.items():
if field not in fields:
options.add_field(var=field)
options['fields'][field]['value'] = value
options.get_fields()[field]['value'] = value
return self.xmpp['xep_0163'].publish(stanza, node, options=options,
ifrom=ifrom, callback=callback,