summaryrefslogtreecommitdiff
path: root/examples/http_over_xmpp.py
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2015-09-23 23:14:26 +0200
committermathieui <mathieui@mathieui.net>2015-10-02 19:00:19 +0200
commitacc52fd935b7e74919ad748f3a630596f66c62af (patch)
tree2d8988c57a63b9cec11c4bf03240a427df9632f8 /examples/http_over_xmpp.py
parente42d651d7ed56375523f91076295fc5f388a8de0 (diff)
parent4305eddb4f634803423cd53d193125a63b00769a (diff)
downloadslixmpp-acc52fd935b7e74919ad748f3a630596f66c62af.tar.gz
slixmpp-acc52fd935b7e74919ad748f3a630596f66c62af.tar.bz2
slixmpp-acc52fd935b7e74919ad748f3a630596f66c62af.tar.xz
slixmpp-acc52fd935b7e74919ad748f3a630596f66c62af.zip
Merge branch 'develop' of https://github.com/fritzy/SleekXMPP into sleek-merge
Conflicts: README.rst examples/IoT_TestDevice.py examples/disco_browser.py setup.py sleekxmpp/jid.py sleekxmpp/plugins/google/auth/stanza.py sleekxmpp/plugins/google/gmail/notifications.py sleekxmpp/plugins/google/nosave/stanza.py sleekxmpp/plugins/google/settings/settings.py sleekxmpp/thirdparty/__init__.py sleekxmpp/thirdparty/socks.py sleekxmpp/thirdparty/statemachine.py sleekxmpp/util/__init__.py sleekxmpp/xmlstream/xmlstream.py slixmpp/basexmpp.py slixmpp/plugins/xep_0004/stanza/form.py slixmpp/plugins/xep_0009/rpc.py slixmpp/plugins/xep_0050/adhoc.py slixmpp/plugins/xep_0065/proxy.py slixmpp/plugins/xep_0084/stanza.py slixmpp/plugins/xep_0202/time.py slixmpp/plugins/xep_0323/sensordata.py slixmpp/plugins/xep_0325/control.py slixmpp/plugins/xep_0325/stanza/control.py slixmpp/roster/single.py slixmpp/stanza/atom.py slixmpp/stanza/rootstanza.py slixmpp/test/slixtest.py slixmpp/util/sasl/mechanisms.py slixmpp/version.py slixmpp/xmlstream/stanzabase.py tests/test_stanza_xep_0323.py tests/test_stanza_xep_0325.py tests/test_stream_xep_0323.py tests/test_stream_xep_0325.py
Diffstat (limited to 'examples/http_over_xmpp.py')
-rw-r--r--examples/http_over_xmpp.py97
1 files changed, 97 insertions, 0 deletions
diff --git a/examples/http_over_xmpp.py b/examples/http_over_xmpp.py
new file mode 100644
index 00000000..73e4a612
--- /dev/null
+++ b/examples/http_over_xmpp.py
@@ -0,0 +1,97 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+"""
+ Slixmpp: The Slick XMPP Library
+ Implementation of HTTP over XMPP transport
+ http://xmpp.org/extensions/xep-0332.html
+ Copyright (C) 2015 Riptide IO, sangeeth@riptideio.com
+ This file is part of slixmpp.
+
+ See the file LICENSE for copying permission.
+"""
+
+from slixmpp import ClientXMPP
+
+from optparse import OptionParser
+import logging
+import getpass
+
+
+class HTTPOverXMPPClient(ClientXMPP):
+ def __init__(self, jid, password):
+ ClientXMPP.__init__(self, jid, password)
+ self.register_plugin('xep_0332') # HTTP over XMPP Transport
+ self.add_event_handler(
+ 'session_start', self.session_start, threaded=True
+ )
+ self.add_event_handler('http_request', self.http_request_received)
+ self.add_event_handler('http_response', self.http_response_received)
+
+ def http_request_received(self, iq):
+ pass
+
+ def http_response_received(self, iq):
+ print('HTTP Response Received : %s' % iq)
+ print('From : %s' % iq['from'])
+ print('To : %s' % iq['to'])
+ print('Type : %s' % iq['type'])
+ print('Headers : %s' % iq['resp']['headers'])
+ print('Code : %s' % iq['resp']['code'])
+ print('Message : %s' % iq['resp']['message'])
+ print('Data : %s' % iq['resp']['data'])
+
+ def session_start(self, event):
+ # TODO: Fill in the blanks
+ self['xep_0332'].send_request(
+ to='?', method='?', resource='?', headers={}
+ )
+ self.disconnect()
+
+
+if __name__ == '__main__':
+
+ #
+ # NOTE: To run this example, fill up the blanks in session_start() and
+ # use the following command.
+ #
+ # ./http_over_xmpp.py -J <jid> -P <pwd> -i <ip> -p <port> [-v]
+ #
+
+ parser = OptionParser()
+
+ # Output verbosity options.
+ parser.add_option(
+ '-v', '--verbose', help='set logging to DEBUG', action='store_const',
+ dest='loglevel', const=logging.DEBUG, default=logging.ERROR
+ )
+
+ # JID and password options.
+ parser.add_option('-J', '--jid', dest='jid', help='JID')
+ parser.add_option('-P', '--password', dest='password', help='Password')
+
+ # XMPP server ip and port options.
+ parser.add_option(
+ '-i', '--ipaddr', dest='ipaddr',
+ help='IP Address of the XMPP server', default=None
+ )
+ parser.add_option(
+ '-p', '--port', dest='port',
+ help='Port of the XMPP server', default=None
+ )
+
+ opts, args = parser.parse_args()
+
+ # Setup logging.
+ logging.basicConfig(level=opts.loglevel,
+ format='%(levelname)-8s %(message)s')
+
+ if opts.jid is None:
+ opts.jid = input('Username: ')
+ if opts.password is None:
+ opts.password = getpass.getpass('Password: ')
+
+ xmpp = HTTPOverXMPPClient(opts.jid, opts.password)
+ xmpp.connect()
+ xmpp.process()
+