HttpUploadComponent/plugins/upload.py

40 lines
1.4 KiB
Python
Raw Normal View History

2015-06-28 05:21:30 -04:00
from sleekxmpp.xmlstream import ElementBase, ET, JID, register_stanza_plugin
from sleekxmpp import Iq
from sleekxmpp.plugins.base import base_plugin
from sleekxmpp.xmlstream.handler.callback import Callback
from sleekxmpp.xmlstream.matcher.xpath import MatchXPath
class upload(base_plugin):
def plugin_init(self):
self.description = "upload files via http"
self.xep = "0999"
2015-06-30 14:11:20 -04:00
self.xmpp['xep_0030'].add_feature("eu:siacs:conversations:http:upload")
2015-08-05 12:38:07 -04:00
self.xmpp['xep_0030'].add_identity(category='store', itype='file', name='HTTP File Upload')
2015-06-28 05:21:30 -04:00
self.xmpp.register_handler(
Callback('Upload request',
2015-06-30 14:11:20 -04:00
MatchXPath('{%s}iq/{eu:siacs:conversations:http:upload}request' % self.xmpp.default_ns),
2015-06-28 05:21:30 -04:00
self._handleUpload))
register_stanza_plugin(Iq, UploadRequest)
register_stanza_plugin(Iq, UploadSlot)
def _handleUpload(self, iq):
if iq['type'] == 'get':
self.xmpp.event('request_upload_slot',iq)
class UploadRequest(ElementBase):
2015-06-30 14:11:20 -04:00
namespace = "eu:siacs:conversations:http:upload"
2015-06-28 05:21:30 -04:00
name = "request"
plugin_attrib = "request"
interfaces = set(('size','filename'))
sub_interfaces = interfaces
class UploadSlot(ElementBase):
2015-06-30 14:11:20 -04:00
namespace = "eu:siacs:conversations:http:upload"
2015-06-28 05:21:30 -04:00
name = "slot"
plugin_attrib = "slot"
interfaces = set(('put','get'))
sub_interfaces = interfaces