Python Structures for known Data Forms, Support multiple Data Forms
Currently, if you want to process a data form from an IQ response, you need to manually check the hidden FORM_TYPE field in iq['disco_info']['form']
, manually extract the correct data fields and do your logic.
What's even worse, if you have an IQ response like the below one, the first data form in the parsed iq
response will be completely overwritten by the second one, so there is no way to extract it:
<iq id="7166059f-5b20-450e-bc7d-af127b4b2ed6-36F5" type="result" from="jabbers.one">
<query xmlns="http://jabber.org/protocol/disco#info">
<identity type="bytestreams" name="SOCKS5 Bytestreams Service" category="proxy"/>
<identity type="file" name="HTTP File Upload" category="store"/>
<identity type="pep" name="Prosody" category="pubsub"/>
<identity type="im" name="Prosody" category="server"/>
<feature var="jabber:iq:private"/>
<feature var="http://jabber.org/protocol/bytestreams"/>
<feature var="urn:xmpp:ping"/>
<feature var="jabber:iq:last"/>
<feature var="jabber:iq:register"/>
<feature var="urn:xmpp:http:upload:0"/>
<feature var="urn:xmpp:http:upload"/>
<feature var="http://jabber.org/protocol/commands"/>
<feature var="urn:xmpp:blocking"/>
<feature var="msgoffline"/>
<feature var="vcard-temp"/>
<feature var="urn:xmpp:mam:0"/>
<feature var="urn:xmpp:carbons:2"/>
<feature var="urn:xmpp:carbons:1"/>
<feature var="jabber:iq:auth"/>
<feature var="urn:xmpp:time"/>
<feature var="jabber:iq:time"/>
<feature var="http://jabber.org/protocol/pubsub#publish"/>
<feature var="jabber:iq:roster"/>
<feature var="jabber:iq:version"/>
<feature var="http://jabber.org/protocol/disco#info"/>
<feature var="http://jabber.org/protocol/disco#items"/>
<x xmlns="jabber:x:data" type="result">
<field type="hidden" var="FORM_TYPE">
<value>http://jabber.org/network/serverinfo</value>
</field>
<field type="list-multi" var="abuse-addresses">
<value>mailto:info@jabbers.one</value>
<value>xmpp:huxxer@jabbers.one</value>
</field>
<field type="list-multi" var="admin-addresses"/>
<field type="list-multi" var="feedback-addresses"/>
<field type="list-multi" var="sales-addresses"/>
<field type="list-multi" var="security-addresses"/>
<field type="list-multi" var="support-addresses"/>
</x>
<x xmlns="jabber:x:data" type="result">
<field type="hidden" var="FORM_TYPE">
<value>urn:xmpp:http:upload:0</value>
</field>
<field type="text-single" var="max-file-size">
<value>10485760</value>
</field>
</x>
<x xmlns="jabber:x:data" type="result">
<field type="hidden" var="FORM_TYPE">
<value>urn:xmpp:http:upload</value>
</field>
<field type="text-single" var="max-file-size">
<value>10485760</value>
</field>
</x>
</query>
</iq>
Please create python data structures for well-known form types, and parse the multiple forms directly into those types, or at least provide the raw forms under something like iq['disco_info']['http://jabber.org/network/serverinfo']
.