From 29faf114a7031d5f2427ea73b862ce4e3b3fc04d Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Thu, 8 Mar 2018 12:11:26 +0100 Subject: Add max-file-size support to HTTP File Upload example. --- examples/http_upload.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/examples/http_upload.py b/examples/http_upload.py index 27b9d280..cbe4ab3f 100755 --- a/examples/http_upload.py +++ b/examples/http_upload.py @@ -53,7 +53,17 @@ class HttpUpload(slixmpp.ClientXMPP): self.disconnect() return - # TODO: check the maximum size from info_iq here. + for form in info_iq['disco_info'].iterables: + values = form['values'] + if values['FORM_TYPE'] == ['urn:xmpp:http:upload:0']: + max_file_size = int(values['max-file-size']) + if self.size > max_file_size: + log.error('File size bigger than max allowed') + self.disconnect() + return + break + else: + log.warn('Impossible to find max-file-size, assuming infinite storage space') log.info('Using service %s', info_iq['from']) slot_iq = yield from self['xep_0363'].request_slot( @@ -127,6 +137,7 @@ if __name__ == '__main__': xmpp = HttpUpload(args.jid, args.password, args.recipient, args.file) xmpp.register_plugin('xep_0071') + xmpp.register_plugin('xep_0128') xmpp.register_plugin('xep_0363') # Connect to the XMPP server and start processing XMPP stanzas. -- cgit v1.2.3