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(+) (limited to 'sleekxmpp/plugins') 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 (limited to 'sleekxmpp/plugins') 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 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 (limited to 'sleekxmpp/plugins') 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(-) (limited to 'sleekxmpp/plugins') 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 (limited to 'sleekxmpp/plugins') 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(-) (limited to 'sleekxmpp/plugins') 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(-) (limited to 'sleekxmpp/plugins') 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