From 61127f521d7d810a14bb6f9b017d7834584c4206 Mon Sep 17 00:00:00 2001 From: Sangeeth Saravanaraj Date: Thu, 22 Jan 2015 11:09:47 +0530 Subject: Added PyCharm's .idea folder to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 602416e8..628d1337 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ sleekxmpp.egg-info/ *~ .baboon/ .DS_STORE +.idea/ -- cgit v1.2.3 From 2f4d811db490a69b2ba338aa45171ac15c9b5c4d Mon Sep 17 00:00:00 2001 From: Sangeeth Saravanaraj Date: Thu, 22 Jan 2015 11:13:03 +0530 Subject: Fixed a typo in docs/guide_xep_0030.rst --- docs/guide_xep_0030.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/guide_xep_0030.rst b/docs/guide_xep_0030.rst index cb8d7d25..857f7ff1 100644 --- a/docs/guide_xep_0030.rst +++ b/docs/guide_xep_0030.rst @@ -161,7 +161,7 @@ item itself, and the JID and node that will own the item. In this case, the owning JID and node are provided with the parameters ``ijid`` and ``node``. -Peforming Disco Queries +Performing Disco Queries ----------------------- The methods ``get_info()`` and ``get_items()`` are used to query remote JIDs and their nodes for disco information. Since these methods are wrappers for -- cgit v1.2.3 From 1ce42d3a2fe62f82030268923d307cb35896d4d4 Mon Sep 17 00:00:00 2001 From: Sangeeth Saravanaraj Date: Thu, 22 Jan 2015 11:30:38 +0530 Subject: Boilerplate example. --- examples/http_over_xmpp_transport.py | 69 ++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 examples/http_over_xmpp_transport.py diff --git a/examples/http_over_xmpp_transport.py b/examples/http_over_xmpp_transport.py new file mode 100644 index 00000000..7a60c6fc --- /dev/null +++ b/examples/http_over_xmpp_transport.py @@ -0,0 +1,69 @@ +from sleekxmpp import ClientXMPP +import logging + + +# def tracefunc(frame, event, arg, indent=[0]): +# prefix = "/Users/sangeeth/code/SleekXMPP/sleekxmpp/" +# if not frame.f_code.co_filename.startswith(prefix): +# return tracefunc +# if event == "call": +# indent[0] += 2 +# cn = getattr( +# getattr(frame.f_locals.get("self"), "__class__", None), +# "__name__", None +# ) +# print "{}{} {} {}".format( +# "." * indent[0], frame.f_code.co_filename[len(prefix):], +# cn, frame.f_code.co_name +# ) +# elif event == "return": +# indent[0] -= 2 +# return tracefunc +# +# +# import sys +# sys.settrace(tracefunc) + + +class HTTPOverXMPPClient(ClientXMPP): + def __init__(self, jid, password): + ClientXMPP.__init__(self, jid, password) + + # self.register_plugin('xep_0030') # Service Discovery + # self.register_plugin('xep_0004') # Data Forms + # self.register_plugin('xep_0060') # PubSub + # self.register_plugin('xep_0199') # XMPP Ping + # + # self.add_event_handler("session_start", self.session_start) + # self.add_event_handler("connected", self.connected) + # + # def session_start(self, event): + # print "Client::session_start()" + # self.send_presence() + # print self.get_roster() + # + # def connected(self, event): + # print "Client::connected()" + + +def get_cred(filename="/tmp/.cred"): + with open(filename, "r") as f: + return f.readline().split() + + +if __name__ == "__main__": + + logging.basicConfig( + level=logging.DEBUG, format='%(levelname)-8s %(message)s' + ) + + jid, password = get_cred() + xmpp = HTTPOverXMPPClient(jid, password) + if xmpp.connect(("talk.l.google.com", 5222)): + print "Connected!" + xmpp.process(block=True) + else: + print "Not connected!" + print "Goodbye...." + + -- cgit v1.2.3 From 8afba7de853be4eb3c5cb2467fa17db64cf84abc Mon Sep 17 00:00:00 2001 From: Sangeeth Saravanaraj Date: Thu, 22 Jan 2015 16:38:16 +0530 Subject: renamed example for convenience. --- examples/http_over_xmpp.py | 70 ++++++++++++++++++++++++++++++++++++ examples/http_over_xmpp_transport.py | 69 ----------------------------------- 2 files changed, 70 insertions(+), 69 deletions(-) create mode 100644 examples/http_over_xmpp.py delete mode 100644 examples/http_over_xmpp_transport.py diff --git a/examples/http_over_xmpp.py b/examples/http_over_xmpp.py new file mode 100644 index 00000000..5de8713e --- /dev/null +++ b/examples/http_over_xmpp.py @@ -0,0 +1,70 @@ +from sleekxmpp import ClientXMPP +import logging + + +# def tracefunc(frame, event, arg, indent=[0]): +# prefix = "/Users/sangeeth/code/SleekXMPP/sleekxmpp/" +# if not frame.f_code.co_filename.startswith(prefix): +# return tracefunc +# if event == "call": +# indent[0] += 2 +# cn = getattr( +# getattr(frame.f_locals.get("self"), "__class__", None), +# "__name__", None +# ) +# print "{}{} {} {}".format( +# "." * indent[0], frame.f_code.co_filename[len(prefix):], +# cn, frame.f_code.co_name +# ) +# elif event == "return": +# indent[0] -= 2 +# return tracefunc +# +# +# import sys +# sys.settrace(tracefunc) + + +class HTTPOverXMPPClient(ClientXMPP): + def __init__(self, jid, password): + ClientXMPP.__init__(self, jid, password) + + self.register_plugin('xep_0332') # HTTP over XMPP + # self.register_plugin('xep_0030') # Service Discovery + # self.register_plugin('xep_0004') # Data Forms + # self.register_plugin('xep_0060') # PubSub + # self.register_plugin('xep_0199') # XMPP Ping + # + # self.add_event_handler("session_start", self.session_start) + # self.add_event_handler("connected", self.connected) + # + # def session_start(self, event): + # print "Client::session_start()" + # self.send_presence() + # print self.get_roster() + # + # def connected(self, event): + # print "Client::connected()" + + +def get_cred(filename="/tmp/.cred"): + with open(filename, "r") as f: + return f.readline().split() + + +if __name__ == "__main__": + + logging.basicConfig( + level=logging.DEBUG, format='%(levelname)-8s %(message)s' + ) + + jid, password = get_cred() + xmpp = HTTPOverXMPPClient(jid, password) + if xmpp.connect(("talk.l.google.com", 5222)): + print "Connected!" + xmpp.process(block=True) + else: + print "Not connected!" + print "Goodbye...." + + diff --git a/examples/http_over_xmpp_transport.py b/examples/http_over_xmpp_transport.py deleted file mode 100644 index 7a60c6fc..00000000 --- a/examples/http_over_xmpp_transport.py +++ /dev/null @@ -1,69 +0,0 @@ -from sleekxmpp import ClientXMPP -import logging - - -# def tracefunc(frame, event, arg, indent=[0]): -# prefix = "/Users/sangeeth/code/SleekXMPP/sleekxmpp/" -# if not frame.f_code.co_filename.startswith(prefix): -# return tracefunc -# if event == "call": -# indent[0] += 2 -# cn = getattr( -# getattr(frame.f_locals.get("self"), "__class__", None), -# "__name__", None -# ) -# print "{}{} {} {}".format( -# "." * indent[0], frame.f_code.co_filename[len(prefix):], -# cn, frame.f_code.co_name -# ) -# elif event == "return": -# indent[0] -= 2 -# return tracefunc -# -# -# import sys -# sys.settrace(tracefunc) - - -class HTTPOverXMPPClient(ClientXMPP): - def __init__(self, jid, password): - ClientXMPP.__init__(self, jid, password) - - # self.register_plugin('xep_0030') # Service Discovery - # self.register_plugin('xep_0004') # Data Forms - # self.register_plugin('xep_0060') # PubSub - # self.register_plugin('xep_0199') # XMPP Ping - # - # self.add_event_handler("session_start", self.session_start) - # self.add_event_handler("connected", self.connected) - # - # def session_start(self, event): - # print "Client::session_start()" - # self.send_presence() - # print self.get_roster() - # - # def connected(self, event): - # print "Client::connected()" - - -def get_cred(filename="/tmp/.cred"): - with open(filename, "r") as f: - return f.readline().split() - - -if __name__ == "__main__": - - logging.basicConfig( - level=logging.DEBUG, format='%(levelname)-8s %(message)s' - ) - - jid, password = get_cred() - xmpp = HTTPOverXMPPClient(jid, password) - if xmpp.connect(("talk.l.google.com", 5222)): - print "Connected!" - xmpp.process(block=True) - else: - print "Not connected!" - print "Goodbye...." - - -- cgit v1.2.3 From 4a8951c4eeb34506d5d057a00e221500a1835c85 Mon Sep 17 00:00:00 2001 From: Sangeeth Saravanaraj Date: Thu, 22 Jan 2015 16:39:27 +0530 Subject: added xep_0332 to plugins --- sleekxmpp/plugins/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sleekxmpp/plugins/__init__.py b/sleekxmpp/plugins/__init__.py index 951f31eb..2c90d357 100644 --- a/sleekxmpp/plugins/__init__.py +++ b/sleekxmpp/plugins/__init__.py @@ -83,4 +83,5 @@ __all__ = [ 'xep_0319', # Last User Interaction in Presence 'xep_0323', # IoT Systems Sensor Data 'xep_0325', # IoT Systems Control + 'xep_0332', # HTTP Over XMPP Transport ] -- cgit v1.2.3 From ecd124dd068ea381555fca3c42c402c46da0cba1 Mon Sep 17 00:00:00 2001 From: Sangeeth Saravanaraj Date: Thu, 22 Jan 2015 16:40:03 +0530 Subject: Boilerplate for xep_0332 --- sleekxmpp/plugins/xep_0332/__init__.py | 15 ++++++++++++++ sleekxmpp/plugins/xep_0332/http.py | 37 ++++++++++++++++++++++++++++++++++ sleekxmpp/plugins/xep_0332/stanza.py | 19 +++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 sleekxmpp/plugins/xep_0332/__init__.py create mode 100644 sleekxmpp/plugins/xep_0332/http.py create mode 100644 sleekxmpp/plugins/xep_0332/stanza.py diff --git a/sleekxmpp/plugins/xep_0332/__init__.py b/sleekxmpp/plugins/xep_0332/__init__.py new file mode 100644 index 00000000..3f80ce82 --- /dev/null +++ b/sleekxmpp/plugins/xep_0332/__init__.py @@ -0,0 +1,15 @@ +""" + SleekXMPP: The Sleek 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 SleekXMPP. + + See the file LICENSE for copying permission. +""" + +from sleekxmpp.plugins.base import register_plugin + +from sleekxmpp.plugins.xep_0332.http import XEP_0332 + +register_plugin(XEP_0332) diff --git a/sleekxmpp/plugins/xep_0332/http.py b/sleekxmpp/plugins/xep_0332/http.py new file mode 100644 index 00000000..7b9628e3 --- /dev/null +++ b/sleekxmpp/plugins/xep_0332/http.py @@ -0,0 +1,37 @@ +""" + SleekXMPP: The Sleek 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 SleekXMPP. + + See the file LICENSE for copying permission. +""" + +import logging + +from sleekxmpp.plugins.base import BasePlugin + + +log = logging.getLogger(__name__) + + +class XEP_0332(BasePlugin): + """ + XEP-0332: HTTP over XMPP transport + """ + + name = 'xep_0332' + description = 'XEP-0332: HTTP over XMPP transport' + dependencies = set(['xep_0030', 'xep_0047', 'xep_0131']) #: xep 1, 137 and 166 are missing + default_config = {} + + def plugin_init(self): + log.debug("XEP_0332:: plugin_init()") + + def plugin_end(self): + log.debug("XEP_0332:: plugin_end()") + + def session_bind(self, jid): + log.debug("XEP_0332:: session_bind()") + diff --git a/sleekxmpp/plugins/xep_0332/stanza.py b/sleekxmpp/plugins/xep_0332/stanza.py new file mode 100644 index 00000000..9d651d5d --- /dev/null +++ b/sleekxmpp/plugins/xep_0332/stanza.py @@ -0,0 +1,19 @@ +""" + SleekXMPP: The Sleek 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 SleekXMPP. + + See the file LICENSE for copying permission. +""" + +from sleekxmpp.xmlstream import ElementBase + + +class Req(ElementBase): + pass + + +class Resp(ElementBase): + pass -- cgit v1.2.3 From be76dda21d93fdca8629d4b6d926d1ddd5c396af Mon Sep 17 00:00:00 2001 From: Sangeeth Saravanaraj Date: Fri, 23 Jan 2015 10:29:21 +0530 Subject: Added xep_0332 to setup --- setup.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/setup.py b/setup.py index cc4fdd5b..566683b7 100755 --- a/setup.py +++ b/setup.py @@ -123,6 +123,8 @@ packages = [ 'sleekxmpp', 'sleekxmpp/plugins/xep_0323/stanza', 'sleekxmpp/plugins/xep_0325', 'sleekxmpp/plugins/xep_0325/stanza', + 'sleekxmpp/plugins/xep_0332', + 'sleekxmpp/plugins/xep_0332/stanza', 'sleekxmpp/plugins/google', 'sleekxmpp/plugins/google/gmail', 'sleekxmpp/plugins/google/auth', -- cgit v1.2.3 From 0fe057b5c3f462275cf8dbf321c2ebec61de1bfe Mon Sep 17 00:00:00 2001 From: Sangeeth Saravanaraj Date: Tue, 27 Jan 2015 15:13:57 +0530 Subject: Boilerplate for Stanzas - request and response --- sleekxmpp/plugins/xep_0332/__init__.py | 1 + sleekxmpp/plugins/xep_0332/stanza.py | 19 ------------------- sleekxmpp/plugins/xep_0332/stanza/__init__.py | 12 ++++++++++++ sleekxmpp/plugins/xep_0332/stanza/request.py | 21 +++++++++++++++++++++ sleekxmpp/plugins/xep_0332/stanza/response.py | 21 +++++++++++++++++++++ 5 files changed, 55 insertions(+), 19 deletions(-) delete mode 100644 sleekxmpp/plugins/xep_0332/stanza.py create mode 100644 sleekxmpp/plugins/xep_0332/stanza/__init__.py create mode 100644 sleekxmpp/plugins/xep_0332/stanza/request.py create mode 100644 sleekxmpp/plugins/xep_0332/stanza/response.py diff --git a/sleekxmpp/plugins/xep_0332/__init__.py b/sleekxmpp/plugins/xep_0332/__init__.py index 3f80ce82..bdb951fc 100644 --- a/sleekxmpp/plugins/xep_0332/__init__.py +++ b/sleekxmpp/plugins/xep_0332/__init__.py @@ -11,5 +11,6 @@ from sleekxmpp.plugins.base import register_plugin from sleekxmpp.plugins.xep_0332.http import XEP_0332 +from sleekxmpp.plugins.xep_0332 import stanza register_plugin(XEP_0332) diff --git a/sleekxmpp/plugins/xep_0332/stanza.py b/sleekxmpp/plugins/xep_0332/stanza.py deleted file mode 100644 index 9d651d5d..00000000 --- a/sleekxmpp/plugins/xep_0332/stanza.py +++ /dev/null @@ -1,19 +0,0 @@ -""" - SleekXMPP: The Sleek 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 SleekXMPP. - - See the file LICENSE for copying permission. -""" - -from sleekxmpp.xmlstream import ElementBase - - -class Req(ElementBase): - pass - - -class Resp(ElementBase): - pass diff --git a/sleekxmpp/plugins/xep_0332/stanza/__init__.py b/sleekxmpp/plugins/xep_0332/stanza/__init__.py new file mode 100644 index 00000000..5d686710 --- /dev/null +++ b/sleekxmpp/plugins/xep_0332/stanza/__init__.py @@ -0,0 +1,12 @@ +""" + SleekXMPP: The Sleek 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 SleekXMPP. + + See the file LICENSE for copying permission. +""" + +from sleekxmpp.plugins.xep_0332.stanza.request import * +from sleekxmpp.plugins.xep_0332.stanza.response import * diff --git a/sleekxmpp/plugins/xep_0332/stanza/request.py b/sleekxmpp/plugins/xep_0332/stanza/request.py new file mode 100644 index 00000000..3d75b534 --- /dev/null +++ b/sleekxmpp/plugins/xep_0332/stanza/request.py @@ -0,0 +1,21 @@ +""" + SleekXMPP: The Sleek 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 SleekXMPP. + + See the file LICENSE for copying permission. +""" + +from sleekxmpp import Iq +from sleekxmpp.xmlstream import ElementBase, register_stanza_plugin +from sleekxmpp.plugins.xep_0131.stanza import Headers + + +class Request(ElementBase): + pass + + +register_stanza_plugin(Iq, Request) +register_stanza_plugin(Request, Headers) diff --git a/sleekxmpp/plugins/xep_0332/stanza/response.py b/sleekxmpp/plugins/xep_0332/stanza/response.py new file mode 100644 index 00000000..7f8180bb --- /dev/null +++ b/sleekxmpp/plugins/xep_0332/stanza/response.py @@ -0,0 +1,21 @@ +""" + SleekXMPP: The Sleek 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 SleekXMPP. + + See the file LICENSE for copying permission. +""" + +from sleekxmpp import Iq +from sleekxmpp.xmlstream import ElementBase, register_stanza_plugin +from sleekxmpp.plugins.xep_0131.stanza import Headers + + +class Response(ElementBase): + pass + + +register_stanza_plugin(Iq, Response) +register_stanza_plugin(Response, Headers) -- cgit v1.2.3 From e1f25604ecbf5d6c196080cd8394191c7ea459c9 Mon Sep 17 00:00:00 2001 From: Sangeeth Saravanaraj Date: Wed, 28 Jan 2015 14:52:15 +0530 Subject: Added callbacks, registered stanzas, added features, etc. --- sleekxmpp/plugins/xep_0332/__init__.py | 2 +- sleekxmpp/plugins/xep_0332/http.py | 40 +++++++++++++++++++++++++++ sleekxmpp/plugins/xep_0332/stanza/__init__.py | 3 +- sleekxmpp/plugins/xep_0332/stanza/request.py | 40 +++++++++++++++++++++++---- sleekxmpp/plugins/xep_0332/stanza/response.py | 37 +++++++++++++++++++++---- 5 files changed, 107 insertions(+), 15 deletions(-) diff --git a/sleekxmpp/plugins/xep_0332/__init__.py b/sleekxmpp/plugins/xep_0332/__init__.py index bdb951fc..cdbfa5d5 100644 --- a/sleekxmpp/plugins/xep_0332/__init__.py +++ b/sleekxmpp/plugins/xep_0332/__init__.py @@ -11,6 +11,6 @@ from sleekxmpp.plugins.base import register_plugin from sleekxmpp.plugins.xep_0332.http import XEP_0332 -from sleekxmpp.plugins.xep_0332 import stanza +# from sleekxmpp.plugins.xep_0332 import stanza register_plugin(XEP_0332) diff --git a/sleekxmpp/plugins/xep_0332/http.py b/sleekxmpp/plugins/xep_0332/http.py index 7b9628e3..f91cc1ff 100644 --- a/sleekxmpp/plugins/xep_0332/http.py +++ b/sleekxmpp/plugins/xep_0332/http.py @@ -10,8 +10,20 @@ import logging +from sleekxmpp import Iq + +from sleekxmpp.xmlstream import register_stanza_plugin +from sleekxmpp.xmlstream.handler import Callback +from sleekxmpp.xmlstream.matcher import StanzaPath + from sleekxmpp.plugins.base import BasePlugin +from sleekxmpp.plugins.xep_0332.stanza import NAMESPACE +from sleekxmpp.plugins.xep_0332.stanza.request import Request +from sleekxmpp.plugins.xep_0332.stanza.response import Response + +from sleekxmpp.plugins.xep_0131.stanza import Headers + log = logging.getLogger(__name__) @@ -29,9 +41,37 @@ class XEP_0332(BasePlugin): def plugin_init(self): log.debug("XEP_0332:: plugin_init()") + self.xmpp.register_handler(Callback( + 'HTTP Request', StanzaPath('iq/req'), self._handle_request + )) + self.xmpp.register_handler(Callback( + 'HTTP Response', StanzaPath('iq/resp'), self._handle_response + )) + + register_stanza_plugin(Iq, Request) + register_stanza_plugin(Iq, Response) + register_stanza_plugin(Request, Headers) + register_stanza_plugin(Response, Headers) + def plugin_end(self): log.debug("XEP_0332:: plugin_end()") + self.xmpp.remove_handler('HTTP Request') + self.xmpp.remove_handler('HTTP Response') + self.xmpp['xep_0030'].del_feature(NAMESPACE) def session_bind(self, jid): log.debug("XEP_0332:: session_bind()") + self.xmpp['xep_0030'].add_feature(NAMESPACE) + + def _handle_request(self): + log.debug("XEP_0332:: _handle_request()") + + def _handle_response(self): + log.debug("XEP_0332:: _handle_response()") + + def send_request(self, method=None, resource=None, headers=None, data=None, **kwargs): + log.debug("XEP_0332:: send_request()") + + def send_response(self, status_code=None, headers=None, data=None, **kwargs): + log.debug("XEP_0332:: send_response()") diff --git a/sleekxmpp/plugins/xep_0332/stanza/__init__.py b/sleekxmpp/plugins/xep_0332/stanza/__init__.py index 5d686710..5d9283c7 100644 --- a/sleekxmpp/plugins/xep_0332/stanza/__init__.py +++ b/sleekxmpp/plugins/xep_0332/stanza/__init__.py @@ -8,5 +8,4 @@ See the file LICENSE for copying permission. """ -from sleekxmpp.plugins.xep_0332.stanza.request import * -from sleekxmpp.plugins.xep_0332.stanza.response import * +NAMESPACE = 'urn:xmpp:http' diff --git a/sleekxmpp/plugins/xep_0332/stanza/request.py b/sleekxmpp/plugins/xep_0332/stanza/request.py index 3d75b534..ea2650c0 100644 --- a/sleekxmpp/plugins/xep_0332/stanza/request.py +++ b/sleekxmpp/plugins/xep_0332/stanza/request.py @@ -8,14 +8,42 @@ See the file LICENSE for copying permission. """ -from sleekxmpp import Iq -from sleekxmpp.xmlstream import ElementBase, register_stanza_plugin -from sleekxmpp.plugins.xep_0131.stanza import Headers +from sleekxmpp.xmlstream import ElementBase +from sleekxmpp.plugins.xep_0332.stanza import NAMESPACE class Request(ElementBase): - pass + """ + All HTTP communication is done using the `Request`/`Response` paradigm. + Each HTTP Request is made sending an `iq` stanza containing a `req` element + to the server. Each `iq` stanza sent is of type `set`. + + Examples: + + + +
b.com
+
+
+
+ + + + +
b.com
+
text/html
+
...
+
+ + <html><header/><body><p>Beautiful home page.</p></body></html> + +
+
+ """ + + name = 'request' + namespace = NAMESPACE + interfaces = set(('method', 'resource', 'version')) + plugin_attrib = 'req' -register_stanza_plugin(Iq, Request) -register_stanza_plugin(Request, Headers) diff --git a/sleekxmpp/plugins/xep_0332/stanza/response.py b/sleekxmpp/plugins/xep_0332/stanza/response.py index 7f8180bb..4dc14344 100644 --- a/sleekxmpp/plugins/xep_0332/stanza/response.py +++ b/sleekxmpp/plugins/xep_0332/stanza/response.py @@ -8,14 +8,39 @@ See the file LICENSE for copying permission. """ -from sleekxmpp import Iq -from sleekxmpp.xmlstream import ElementBase, register_stanza_plugin -from sleekxmpp.plugins.xep_0131.stanza import Headers +from sleekxmpp.xmlstream import ElementBase +from sleekxmpp.plugins.xep_0332.stanza import NAMESPACE class Response(ElementBase): - pass + """ + When the HTTP Server responds, it does so by sending an `iq` stanza + response (type=`result`) back to the client containing the `resp` element. + Since response are asynchronous, and since multiple requests may be active + at the same time, responses may be returned in a different order than the + in which the original requests were made. -register_stanza_plugin(Iq, Response) -register_stanza_plugin(Response, Headers) + Examples: + + + +
Fri, 03 May 2013 16:39:54GMT-4
+
Clayster
+
text/turtle
+
...
+
Close
+
+ + + ... + + +
+
+ """ + + name = 'response' + namespace = NAMESPACE + interfaces = set(('statusCode', 'statusMessage', 'version')) + plugin_attrib = 'resp' -- cgit v1.2.3 From a96f608469e74d39d3e7a2a86399dbb724ffadec Mon Sep 17 00:00:00 2001 From: Sangeeth Saravanaraj Date: Thu, 29 Jan 2015 08:33:40 +0530 Subject: Composing request and response. --- sleekxmpp/plugins/xep_0332/__init__.py | 3 +- sleekxmpp/plugins/xep_0332/http.py | 94 +++++++++++++++++++++------ sleekxmpp/plugins/xep_0332/stanza/__init__.py | 4 +- sleekxmpp/plugins/xep_0332/stanza/data.py | 29 +++++++++ sleekxmpp/plugins/xep_0332/stanza/request.py | 26 +++++++- sleekxmpp/plugins/xep_0332/stanza/response.py | 17 ++++- 6 files changed, 146 insertions(+), 27 deletions(-) create mode 100644 sleekxmpp/plugins/xep_0332/stanza/data.py diff --git a/sleekxmpp/plugins/xep_0332/__init__.py b/sleekxmpp/plugins/xep_0332/__init__.py index cdbfa5d5..27755faa 100644 --- a/sleekxmpp/plugins/xep_0332/__init__.py +++ b/sleekxmpp/plugins/xep_0332/__init__.py @@ -10,7 +10,8 @@ from sleekxmpp.plugins.base import register_plugin +from sleekxmpp.plugins.xep_0332 import stanza from sleekxmpp.plugins.xep_0332.http import XEP_0332 -# from sleekxmpp.plugins.xep_0332 import stanza + register_plugin(XEP_0332) diff --git a/sleekxmpp/plugins/xep_0332/http.py b/sleekxmpp/plugins/xep_0332/http.py index f91cc1ff..166e6ec3 100644 --- a/sleekxmpp/plugins/xep_0332/http.py +++ b/sleekxmpp/plugins/xep_0332/http.py @@ -17,11 +17,7 @@ from sleekxmpp.xmlstream.handler import Callback from sleekxmpp.xmlstream.matcher import StanzaPath from sleekxmpp.plugins.base import BasePlugin - -from sleekxmpp.plugins.xep_0332.stanza import NAMESPACE -from sleekxmpp.plugins.xep_0332.stanza.request import Request -from sleekxmpp.plugins.xep_0332.stanza.response import Response - +from sleekxmpp.plugins.xep_0332.stanza import Request, Response, Data from sleekxmpp.plugins.xep_0131.stanza import Headers @@ -35,8 +31,23 @@ class XEP_0332(BasePlugin): name = 'xep_0332' description = 'XEP-0332: HTTP over XMPP transport' - dependencies = set(['xep_0030', 'xep_0047', 'xep_0131']) #: xep 1, 137 and 166 are missing - default_config = {} + + #: xep_0047 not included. + #: xep_0001, 0137 and 0166 are missing + dependencies = set(['xep_0030', 'xep_0131']) + + #: TODO: Do we really need to mention the supported_headers?! + default_config = { + 'supported_headers': set([ + 'Content-Length', 'Transfer-Encoding', 'DateTime', + 'Accept-Charset', 'Location', 'Content-ID', 'Description', + 'Content-Language', 'Content-Transfer-Encoding', 'Timestamp', + 'Expires', 'User-Agent', 'Host', 'Proxy-Authorization', 'Date', + 'WWW-Authenticate', 'Accept-Encoding', 'Server', 'Error-Info', + 'Identifier', 'Content-Location', 'Content-Encoding', 'Distribute', + 'Accept', 'Proxy-Authenticate', 'ETag', 'Expect', 'Content-Type' + ]) + } def plugin_init(self): log.debug("XEP_0332:: plugin_init()") @@ -48,30 +59,75 @@ class XEP_0332(BasePlugin): 'HTTP Response', StanzaPath('iq/resp'), self._handle_response )) - register_stanza_plugin(Iq, Request) - register_stanza_plugin(Iq, Response) - register_stanza_plugin(Request, Headers) - register_stanza_plugin(Response, Headers) + register_stanza_plugin(Iq, Request, iterable=True) + register_stanza_plugin(Iq, Response, iterable=True) + register_stanza_plugin(Request, Headers, iterable=True) + register_stanza_plugin(Request, Data, iterable=True) + register_stanza_plugin(Response, Headers, iterable=True) + register_stanza_plugin(Response, Data, iterable=True) + + # TODO: Should we register any api's here? self.api.register() def plugin_end(self): log.debug("XEP_0332:: plugin_end()") self.xmpp.remove_handler('HTTP Request') self.xmpp.remove_handler('HTTP Response') - self.xmpp['xep_0030'].del_feature(NAMESPACE) + self.xmpp['xep_0030'].del_feature('urn:xmpp:http') + for header in self.supported_headers: + self.xmpp['xep_0030'].del_feature( + feature='%s#%s' % (Headers.namespace, header) + ) def session_bind(self, jid): log.debug("XEP_0332:: session_bind()") - self.xmpp['xep_0030'].add_feature(NAMESPACE) - - def _handle_request(self): + self.xmpp['xep_0030'].add_feature('urn:xmpp:http') + for header in self.supported_headers: + self.xmpp['xep_0030'].add_feature( + '%s#%s' % (Headers.namespace, header) + ) + # TODO: Do we need to add the supported headers to xep_0131? + # self.xmpp['xep_0131'].supported_headers.add(header) + + def _handle_request(self, iq): log.debug("XEP_0332:: _handle_request()") + print iq - def _handle_response(self): + def _handle_response(self, iq): log.debug("XEP_0332:: _handle_response()") + print iq - def send_request(self, method=None, resource=None, headers=None, data=None, **kwargs): + def send_request(self, to=None, method=None, resource=None, headers=None, + data=None, **kwargs): log.debug("XEP_0332:: send_request()") - - def send_response(self, status_code=None, headers=None, data=None, **kwargs): + iq = self.xmpp.Iq() + iq['from'] = self.xmpp.boundjid + iq['to'] = to + iq['type'] = 'set' + iq['req']['headers'] = headers + iq['req']['method'] = method + iq['req']['resource'] = resource + iq['req']['version'] = '1.1' # TODO: set this implicitly + iq['req']['data'] = data + print iq + # return iq.send(timeout=kwargs.get('timeout', None), + # block=kwargs.get('block', True), + # callback=kwargs.get('callback', None), + # timeout_callback=kwargs.get('timeout_callback', None)) + + def send_response(self, to=None, code=None, headers=None, data=None, + **kwargs): log.debug("XEP_0332:: send_response()") + iq = self.xmpp.Iq() + iq['from'] = self.xmpp.boundjid + iq['to'] = to + iq['type'] = 'result' + iq['resp']['headers'] = headers + iq['resp']['code'] = code + iq['resp']['version'] = '1.1' # TODO: set this implicitly + iq['resp']['data'] = data + print iq + # return iq.send(timeout=kwargs.get('timeout', None), + # block=kwargs.get('block', True), + # callback=kwargs.get('callback', None), + # timeout_callback=kwargs.get('timeout_callback', None)) diff --git a/sleekxmpp/plugins/xep_0332/stanza/__init__.py b/sleekxmpp/plugins/xep_0332/stanza/__init__.py index 5d9283c7..eeab3f31 100644 --- a/sleekxmpp/plugins/xep_0332/stanza/__init__.py +++ b/sleekxmpp/plugins/xep_0332/stanza/__init__.py @@ -8,4 +8,6 @@ See the file LICENSE for copying permission. """ -NAMESPACE = 'urn:xmpp:http' +from sleekxmpp.plugins.xep_0332.stanza.request import Request +from sleekxmpp.plugins.xep_0332.stanza.response import Response +from sleekxmpp.plugins.xep_0332.stanza.data import Data diff --git a/sleekxmpp/plugins/xep_0332/stanza/data.py b/sleekxmpp/plugins/xep_0332/stanza/data.py new file mode 100644 index 00000000..e77d2585 --- /dev/null +++ b/sleekxmpp/plugins/xep_0332/stanza/data.py @@ -0,0 +1,29 @@ +""" + SleekXMPP: The Sleek 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 SleekXMPP. + + See the file LICENSE for copying permission. +""" + +from sleekxmpp.xmlstream import ElementBase + + +class Data(ElementBase): + """ + The data element. + """ + name = 'data' + namespace = '' + interfaces = set(['data']) + plugin_attrib = 'data' + + def get_data(self): + print "Data:: get_data()" + + def set_data(self, data, encoding='text'): + print "Data:: set_data()" + self._set_sub_text(encoding, text=data) + diff --git a/sleekxmpp/plugins/xep_0332/stanza/request.py b/sleekxmpp/plugins/xep_0332/stanza/request.py index ea2650c0..51e565e5 100644 --- a/sleekxmpp/plugins/xep_0332/stanza/request.py +++ b/sleekxmpp/plugins/xep_0332/stanza/request.py @@ -9,7 +9,6 @@ """ from sleekxmpp.xmlstream import ElementBase -from sleekxmpp.plugins.xep_0332.stanza import NAMESPACE class Request(ElementBase): @@ -43,7 +42,28 @@ class Request(ElementBase): """ name = 'request' - namespace = NAMESPACE - interfaces = set(('method', 'resource', 'version')) + namespace = 'urn:xmpp:http' + interfaces = set(['method', 'resource', 'version']) plugin_attrib = 'req' + def get_method(self): + print "Request:: get_method()" + + def set_method(self, method): + print "Request:: set_method()" + self._set_attr('method', method) + + def get_resource(self): + print "Request:: get_resource()" + + def set_resource(self, resource): + print "Request:: set_resource()" + self._set_attr('resource', resource) + + def get_version(self): + print "Request:: get_version()" + + def set_version(self, version='1.1'): + print "Request:: set_version()" + self._set_attr('version', version) + diff --git a/sleekxmpp/plugins/xep_0332/stanza/response.py b/sleekxmpp/plugins/xep_0332/stanza/response.py index 4dc14344..d863efa3 100644 --- a/sleekxmpp/plugins/xep_0332/stanza/response.py +++ b/sleekxmpp/plugins/xep_0332/stanza/response.py @@ -9,7 +9,6 @@ """ from sleekxmpp.xmlstream import ElementBase -from sleekxmpp.plugins.xep_0332.stanza import NAMESPACE class Response(ElementBase): @@ -41,6 +40,18 @@ class Response(ElementBase): """ name = 'response' - namespace = NAMESPACE - interfaces = set(('statusCode', 'statusMessage', 'version')) + namespace = 'urn:xmpp:http' + interfaces = set(['code', 'version']) plugin_attrib = 'resp' + + def get_code(self): + print "Response:: get_code()" + + def set_code(self, code): + print "Response:: set_code()" + self._set_attr('statusCode', str(code)) + self._set_attr('statusMessage', str(code)) + + def set_version(self, version='1.1'): + print "Response:: set_version()" + self._set_attr('version', version) -- cgit v1.2.3 From c16b86220047e2a2b77c585d6b0d72f5087c1371 Mon Sep 17 00:00:00 2001 From: Sangeeth Saravanaraj Date: Tue, 3 Feb 2015 12:33:25 +0530 Subject: Raise http_request and http_response events. --- sleekxmpp/plugins/xep_0332/http.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/sleekxmpp/plugins/xep_0332/http.py b/sleekxmpp/plugins/xep_0332/http.py index 166e6ec3..06ba1477 100644 --- a/sleekxmpp/plugins/xep_0332/http.py +++ b/sleekxmpp/plugins/xep_0332/http.py @@ -91,10 +91,12 @@ class XEP_0332(BasePlugin): def _handle_request(self, iq): log.debug("XEP_0332:: _handle_request()") print iq + self.xmpp.event('http_request', iq) def _handle_response(self, iq): log.debug("XEP_0332:: _handle_response()") print iq + self.xmpp.event('http_response', iq) def send_request(self, to=None, method=None, resource=None, headers=None, data=None, **kwargs): @@ -107,12 +109,13 @@ class XEP_0332(BasePlugin): iq['req']['method'] = method iq['req']['resource'] = resource iq['req']['version'] = '1.1' # TODO: set this implicitly - iq['req']['data'] = data + if data: + iq['req']['data'] = data print iq - # return iq.send(timeout=kwargs.get('timeout', None), - # block=kwargs.get('block', True), - # callback=kwargs.get('callback', None), - # timeout_callback=kwargs.get('timeout_callback', None)) + return iq.send(timeout=kwargs.get('timeout', None), + block=kwargs.get('block', True), + callback=kwargs.get('callback', None), + timeout_callback=kwargs.get('timeout_callback', None)) def send_response(self, to=None, code=None, headers=None, data=None, **kwargs): @@ -124,7 +127,8 @@ class XEP_0332(BasePlugin): iq['resp']['headers'] = headers iq['resp']['code'] = code iq['resp']['version'] = '1.1' # TODO: set this implicitly - iq['resp']['data'] = data + if data: + iq['resp']['data'] = data print iq # return iq.send(timeout=kwargs.get('timeout', None), # block=kwargs.get('block', True), -- cgit v1.2.3 From 8bc70264efd17390fbe795e359a7cbb0442fd0d1 Mon Sep 17 00:00:00 2001 From: Sangeeth Saravanaraj Date: Thu, 5 Feb 2015 17:35:04 +0530 Subject: misc updates.. --- sleekxmpp/plugins/xep_0332/http.py | 62 +++++++++++++++------------ sleekxmpp/plugins/xep_0332/stanza/data.py | 9 ++-- sleekxmpp/plugins/xep_0332/stanza/request.py | 14 +++--- sleekxmpp/plugins/xep_0332/stanza/response.py | 14 +++--- 4 files changed, 53 insertions(+), 46 deletions(-) diff --git a/sleekxmpp/plugins/xep_0332/http.py b/sleekxmpp/plugins/xep_0332/http.py index 06ba1477..36b6995f 100644 --- a/sleekxmpp/plugins/xep_0332/http.py +++ b/sleekxmpp/plugins/xep_0332/http.py @@ -50,26 +50,21 @@ class XEP_0332(BasePlugin): } def plugin_init(self): - log.debug("XEP_0332:: plugin_init()") - self.xmpp.register_handler(Callback( 'HTTP Request', StanzaPath('iq/req'), self._handle_request )) self.xmpp.register_handler(Callback( 'HTTP Response', StanzaPath('iq/resp'), self._handle_response )) - register_stanza_plugin(Iq, Request, iterable=True) register_stanza_plugin(Iq, Response, iterable=True) register_stanza_plugin(Request, Headers, iterable=True) register_stanza_plugin(Request, Data, iterable=True) register_stanza_plugin(Response, Headers, iterable=True) register_stanza_plugin(Response, Data, iterable=True) - # TODO: Should we register any api's here? self.api.register() def plugin_end(self): - log.debug("XEP_0332:: plugin_end()") self.xmpp.remove_handler('HTTP Request') self.xmpp.remove_handler('HTTP Response') self.xmpp['xep_0030'].del_feature('urn:xmpp:http') @@ -79,7 +74,6 @@ class XEP_0332(BasePlugin): ) def session_bind(self, jid): - log.debug("XEP_0332:: session_bind()") self.xmpp['xep_0030'].add_feature('urn:xmpp:http') for header in self.supported_headers: self.xmpp['xep_0030'].add_feature( @@ -89,18 +83,13 @@ class XEP_0332(BasePlugin): # self.xmpp['xep_0131'].supported_headers.add(header) def _handle_request(self, iq): - log.debug("XEP_0332:: _handle_request()") - print iq self.xmpp.event('http_request', iq) def _handle_response(self, iq): - log.debug("XEP_0332:: _handle_response()") - print iq self.xmpp.event('http_response', iq) def send_request(self, to=None, method=None, resource=None, headers=None, data=None, **kwargs): - log.debug("XEP_0332:: send_request()") iq = self.xmpp.Iq() iq['from'] = self.xmpp.boundjid iq['to'] = to @@ -109,29 +98,46 @@ class XEP_0332(BasePlugin): iq['req']['method'] = method iq['req']['resource'] = resource iq['req']['version'] = '1.1' # TODO: set this implicitly - if data: + if data is not None: iq['req']['data'] = data - print iq - return iq.send(timeout=kwargs.get('timeout', None), - block=kwargs.get('block', True), - callback=kwargs.get('callback', None), - timeout_callback=kwargs.get('timeout_callback', None)) - - def send_response(self, to=None, code=None, headers=None, data=None, - **kwargs): - log.debug("XEP_0332:: send_response()") + return iq.send( + timeout=kwargs.get('timeout', None), + block=kwargs.get('block', True), + callback=kwargs.get('callback', None), + timeout_callback=kwargs.get('timeout_callback', None) + ) + + def send_response(self, to=None, code=None, message=None, headers=None, + data=None, **kwargs): iq = self.xmpp.Iq() iq['from'] = self.xmpp.boundjid iq['to'] = to iq['type'] = 'result' iq['resp']['headers'] = headers iq['resp']['code'] = code + iq['resp']['message'] = message iq['resp']['version'] = '1.1' # TODO: set this implicitly - if data: + if data is not None: iq['resp']['data'] = data - print iq - # return iq.send(timeout=kwargs.get('timeout', None), - # block=kwargs.get('block', True), - # callback=kwargs.get('callback', None), - # timeout_callback=kwargs.get('timeout_callback', None)) - + return iq.send( + timeout=kwargs.get('timeout', None), + block=kwargs.get('block', True), + callback=kwargs.get('callback', None), + timeout_callback=kwargs.get('timeout_callback', None) + ) + + def send_error(self, to=None, ecode=500, etype='wait', + econd='internal-server-error', **kwargs): + iq = self.xmpp.Iq() + iq['type'] = 'error' + iq['from'] = self.xmpp.boundjid + iq['to'] = to + iq['error']['code'] = ecode + iq['error']['type'] = etype + iq['error']['condition'] = econd + return iq.send( + timeout=kwargs.get('timeout', None), + block=kwargs.get('block', True), + callback=kwargs.get('callback', None), + timeout_callback=kwargs.get('timeout_callback', None) + ) diff --git a/sleekxmpp/plugins/xep_0332/stanza/data.py b/sleekxmpp/plugins/xep_0332/stanza/data.py index e77d2585..9a08426b 100644 --- a/sleekxmpp/plugins/xep_0332/stanza/data.py +++ b/sleekxmpp/plugins/xep_0332/stanza/data.py @@ -16,14 +16,15 @@ class Data(ElementBase): The data element. """ name = 'data' - namespace = '' + namespace = 'urn:xmpp:http' interfaces = set(['data']) plugin_attrib = 'data' + is_extension = True - def get_data(self): - print "Data:: get_data()" + def get_data(self, encoding='text'): + data = self._get_sub_text(encoding, None) + return str(data) if data is not None else data def set_data(self, data, encoding='text'): - print "Data:: set_data()" self._set_sub_text(encoding, text=data) diff --git a/sleekxmpp/plugins/xep_0332/stanza/request.py b/sleekxmpp/plugins/xep_0332/stanza/request.py index 51e565e5..07618727 100644 --- a/sleekxmpp/plugins/xep_0332/stanza/request.py +++ b/sleekxmpp/plugins/xep_0332/stanza/request.py @@ -20,7 +20,7 @@ class Request(ElementBase): Examples: - +
b.com
@@ -35,7 +35,7 @@ class Request(ElementBase):
...
- <html><header/><body><p>Beautiful home page.</p></body></html> + ...
@@ -47,23 +47,19 @@ class Request(ElementBase): plugin_attrib = 'req' def get_method(self): - print "Request:: get_method()" + return self._get_attr('method', None) def set_method(self, method): - print "Request:: set_method()" self._set_attr('method', method) def get_resource(self): - print "Request:: get_resource()" + return self._get_attr('resource', None) def set_resource(self, resource): - print "Request:: set_resource()" self._set_attr('resource', resource) def get_version(self): - print "Request:: get_version()" + return self._get_attr('version', None) def set_version(self, version='1.1'): - print "Request:: set_version()" self._set_attr('version', version) - diff --git a/sleekxmpp/plugins/xep_0332/stanza/response.py b/sleekxmpp/plugins/xep_0332/stanza/response.py index d863efa3..0fc46de8 100644 --- a/sleekxmpp/plugins/xep_0332/stanza/response.py +++ b/sleekxmpp/plugins/xep_0332/stanza/response.py @@ -41,17 +41,21 @@ class Response(ElementBase): name = 'response' namespace = 'urn:xmpp:http' - interfaces = set(['code', 'version']) + interfaces = set(['code', 'message', 'version']) plugin_attrib = 'resp' def get_code(self): - print "Response:: get_code()" + code = self._get_attr('statusCode', None) + return int(code) if code is not None else code def set_code(self, code): - print "Response:: set_code()" self._set_attr('statusCode', str(code)) - self._set_attr('statusMessage', str(code)) + + def get_message(self): + return self._get_attr('statusMessage', '') + + def set_message(self, message): + self._set_attr('statusMessage', message) def set_version(self, version='1.1'): - print "Response:: set_version()" self._set_attr('version', version) -- cgit v1.2.3 From 24264d3a07f8a1576637e6a5703682e8735c2be1 Mon Sep 17 00:00:00 2001 From: Sangeeth Saravanaraj Date: Thu, 5 Feb 2015 18:10:10 +0530 Subject: Updated Example.. --- examples/http_over_xmpp.py | 138 ++++++++++++++++++++++++++------------------- 1 file changed, 81 insertions(+), 57 deletions(-) diff --git a/examples/http_over_xmpp.py b/examples/http_over_xmpp.py index 5de8713e..5630f778 100644 --- a/examples/http_over_xmpp.py +++ b/examples/http_over_xmpp.py @@ -1,70 +1,94 @@ -from sleekxmpp import ClientXMPP -import logging +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" + SleekXMPP: The Sleek 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 SleekXMPP. + See the file LICENSE for copying permission. +""" + +from sleekxmpp import ClientXMPP -# def tracefunc(frame, event, arg, indent=[0]): -# prefix = "/Users/sangeeth/code/SleekXMPP/sleekxmpp/" -# if not frame.f_code.co_filename.startswith(prefix): -# return tracefunc -# if event == "call": -# indent[0] += 2 -# cn = getattr( -# getattr(frame.f_locals.get("self"), "__class__", None), -# "__name__", None -# ) -# print "{}{} {} {}".format( -# "." * indent[0], frame.f_code.co_filename[len(prefix):], -# cn, frame.f_code.co_name -# ) -# elif event == "return": -# indent[0] -= 2 -# return tracefunc -# -# -# import sys -# sys.settrace(tracefunc) +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 : ', iq + print 'From : ', iq['from'] + print 'To : ', iq['to'] + print 'Type : ', iq['type'] + print 'Headers : ', iq['resp']['headers'] + print 'Code : ', iq['resp']['code'] + print 'Message : ', iq['resp']['message'] + print 'Data : ', iq['resp']['data'] + + def session_start(self, event): + # TODO: Fill in the blanks + self['xep_0332'].send_request( + to='?', method='?', resource='?', headers={} + ) + self.disconnect() + - self.register_plugin('xep_0332') # HTTP over XMPP - # self.register_plugin('xep_0030') # Service Discovery - # self.register_plugin('xep_0004') # Data Forms - # self.register_plugin('xep_0060') # PubSub - # self.register_plugin('xep_0199') # XMPP Ping - # - # self.add_event_handler("session_start", self.session_start) - # self.add_event_handler("connected", self.connected) - # - # def session_start(self, event): - # print "Client::session_start()" - # self.send_presence() - # print self.get_roster() - # - # def connected(self, event): - # print "Client::connected()" - - -def get_cred(filename="/tmp/.cred"): - with open(filename, "r") as f: - return f.readline().split() - - -if __name__ == "__main__": - - logging.basicConfig( - level=logging.DEBUG, format='%(levelname)-8s %(message)s' +if __name__ == '__main__': + + 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') - jid, password = get_cred() - xmpp = HTTPOverXMPPClient(jid, password) - if xmpp.connect(("talk.l.google.com", 5222)): - print "Connected!" + if opts.jid is None: + opts.jid = raw_input('Username: ') + if opts.password is None: + opts.password = getpass.getpass('Password: ') + + xmpp = HTTPOverXMPPClient(opts.jid, opts.password) + if xmpp.connect((opts.ipaddr, int(opts.port))): + print 'Connected!' xmpp.process(block=True) else: - print "Not connected!" - print "Goodbye...." - + print 'Not connected!' + print 'Goodbye....' -- cgit v1.2.3 From 904480712157d762d35de16ce55202d641a56b3c Mon Sep 17 00:00:00 2001 From: Sangeeth Saravanaraj Date: Thu, 5 Feb 2015 18:11:41 +0530 Subject: Added help for running example.. --- examples/http_over_xmpp.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/examples/http_over_xmpp.py b/examples/http_over_xmpp.py index 5630f778..a2fbf664 100644 --- a/examples/http_over_xmpp.py +++ b/examples/http_over_xmpp.py @@ -51,6 +51,13 @@ class HTTPOverXMPPClient(ClientXMPP): 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 -P -i -p [-v] + # + parser = OptionParser() # Output verbosity options. -- cgit v1.2.3