Mercurial > libervia-backend
annotate src/plugins/plugin_xep_0055.py @ 1296:ebf72fe68d1c frontends_multi_profiles
quick_frontend: fix the history log message
author | souliane <souliane@mailoo.org> |
---|---|
date | Fri, 06 Feb 2015 10:50:01 +0100 |
parents | 16484ebb695b |
children | 069ad98b360d |
rev | line source |
---|---|
631
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/python |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 # SAT plugin for Jabber Search (xep-0055) |
811 | 5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Jérôme Poisson (goffi@goffi.org) |
631
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 # (at your option) any later version. |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 # GNU Affero General Public License for more details. |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
799
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
20 from sat.core.i18n import _, D_ |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
867
diff
changeset
|
21 from sat.core.log import getLogger |
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
867
diff
changeset
|
22 log = getLogger(__name__) |
631
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 from twisted.words.protocols.jabber.xmlstream import IQ |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 from twisted.words.protocols.jabber import jid |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
867
diff
changeset
|
25 from twisted.internet import defer |
631
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 from wokkel import data_form |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 from sat.core.exceptions import DataError |
799
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
28 from sat.memory.memory import Sessions |
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
29 from sat.tools import xml_tools |
631
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 NS_SEARCH = 'jabber:iq:search' |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 PLUGIN_INFO = { |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 "name": "Jabber Search", |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 "import_name": "XEP-0055", |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 "type": "XEP", |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 "protocols": ["XEP-0055"], |
1219
16484ebb695b
plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
38 "dependencies": [], |
16484ebb695b
plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
39 "recommendations": ["XEP-0059"], |
631
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 "main": "XEP_0055", |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 "handler": "no", |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 "description": _("""Implementation of Jabber Search""") |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 } |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 class XEP_0055(object): |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 def __init__(self, host): |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
867
diff
changeset
|
49 log.info(_("Jabber search plugin initialization")) |
631
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 self.host = host |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 host.bridge.addMethod("getSearchUI", ".plugin", in_sign='ss', out_sign='s', |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 method=self._getSearchUI, |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 async=True) |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 host.bridge.addMethod("searchRequest", ".plugin", in_sign='sa{ss}s', out_sign='s', |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 method=self._searchRequest, |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 async=True) |
799
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
57 self._sessions = Sessions() |
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
58 self.__menu_cb_id = host.registerCallback(self._menuCb, with_data=True) |
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
59 self.__search_request_id = host.registerCallback(self._xmluiSearchRequest, with_data=True) |
809 | 60 host.importMenu((D_("Communication"), D_("Search directory")), self._searchMenu, security_limit=1, help_string=D_("Search use directory")) |
799
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
61 |
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
62 def _menuCb(self, data, profile): |
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
63 entity = jid.JID(data[xml_tools.SAT_FORM_PREFIX+'jid']) |
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
64 d = self.getSearchUI(entity, profile) |
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
65 def gotXMLUI(xmlui): |
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
66 session_id, session_data = self._sessions.newSession(profile=profile) |
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
67 session_data['jid'] = entity |
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
68 xmlui.session_id = session_id # we need to keep track of the session |
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
69 xmlui.submit_id = self.__search_request_id |
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
70 return {'xmlui': xmlui.toXml()} |
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
71 d.addCallback(gotXMLUI) |
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
72 return d |
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
73 |
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
74 |
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
75 def _searchMenu(self, menu_data, profile): |
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
76 """ First XMLUI activated by menu: ask for target jid |
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
77 @param profile: %(doc_profile)s |
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
78 |
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
79 """ |
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
80 form_ui = xml_tools.XMLUI("form", title=_("Search directory"), submit_id=self.__menu_cb_id) |
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
81 form_ui.addText(_("Please enter the search jid"), 'instructions') |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
799
diff
changeset
|
82 form_ui.changeContainer("pairs") |
799
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
83 form_ui.addLabel("jid") |
867
40ad5a344332
plugin XEP-0055: salut.libervia.org is temporarly used as default value
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
84 # form_ui.addString("jid", value="users.jabberfr.org") # TODO: replace users.jabberfr.org by any XEP-0055 compatible service discovered on current server |
40ad5a344332
plugin XEP-0055: salut.libervia.org is temporarly used as default value
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
85 form_ui.addString("jid", value="salut.libervia.org") # TODO: replace salut.libervia.org by any XEP-0055 compatible service discovered on current server |
799
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
86 return {'xmlui': form_ui.toXml()} |
631
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 def _getSearchUI(self, to_jid_s, profile_key): |
799
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
89 d = self.getSearchUI(jid.JID(to_jid_s), profile_key) |
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
90 d.addCallback(lambda xmlui: xmlui.toXml()) |
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
91 return d |
631
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 def getSearchUI(self, to_jid, profile_key): |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 """ Ask for a search interface |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 @param to_jid: XEP-0055 compliant search entity |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 @param profile_key: %(doc_profile_key)s |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 @return: XMLUI search interface """ |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 client = self.host.getClient(profile_key) |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 fields_request = IQ(client.xmlstream, 'get') |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 fields_request["from"] = client.jid.full() |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 fields_request["to"] = to_jid.full() |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 fields_request.addElement('query', NS_SEARCH) |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 d = fields_request.send(to_jid.full()) |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 d.addCallbacks(self._fieldsOk, self._fieldsErr, callbackArgs=[client.profile], errbackArgs=[client.profile]) |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 return d |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
107 def _fieldsOk(self, answer, profile): |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 """got fields available""" |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
109 try: |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
110 query_elts = answer.elements('jabber:iq:search', 'query').next() |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
111 except StopIteration: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
867
diff
changeset
|
112 log.info(_("No query element found")) |
631
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
113 raise DataError # FIXME: StanzaError is probably more appropriate, check the RFC |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 try: |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 form_elt = query_elts.elements(data_form.NS_X_DATA, 'x').next() |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 except StopIteration: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
867
diff
changeset
|
117 log.info(_("No data form found")) |
631
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 raise NotImplementedError("Only search through data form is implemented so far") |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 parsed_form = data_form.Form.fromElement(form_elt) |
799
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
120 return xml_tools.dataForm2XMLUI(parsed_form, "") |
631
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 def _fieldsErr(self, failure, profile): |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 """ Called when something is wrong with fields request """ |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
867
diff
changeset
|
124 log.info(_("Fields request failure: %s") % str(failure.value)) |
631
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 return failure |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 |
799
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
127 def _xmluiSearchRequest(self, raw_data, profile): |
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
128 try: |
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
129 session_data = self._sessions.profileGet(raw_data["session_id"], profile) |
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
130 except KeyError: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
867
diff
changeset
|
131 log.warning ("session id doesn't exist, session has probably expired") |
799
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
132 # TODO: send error dialog |
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
133 return defer.succeed({}) |
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
134 |
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
135 data = xml_tools.XMLUIResult2DataFormResult(raw_data) |
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
136 entity =session_data['jid'] |
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
137 d = self.searchRequest(entity, data, profile) |
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
138 d.addCallback(lambda xmlui: {'xmlui':xmlui.toXml()}) |
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
139 del self._sessions[raw_data["session_id"]] |
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
140 return d |
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
141 |
631
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 def _searchRequest(self, to_jid_s, search_dict, profile_key): |
799
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
143 d = self.searchRequest(jid.JID(to_jid_s), search_dict, profile_key) |
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
144 d.addCallback(lambda xmlui: xmlui.toXml()) |
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
145 return d |
631
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
146 |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 def searchRequest(self, to_jid, search_dict, profile_key): |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 """ Actually do a search, according to filled data |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
149 @param to_jid: XEP-0055 compliant search entity |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
150 @param search_dict: filled data, corresponding to the form obtained in getSearchUI |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 @param profile_key: %(doc_profile_key)s |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 @return: XMLUI search result """ |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 client = self.host.getClient(profile_key) |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 search_request = IQ(client.xmlstream, 'set') |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 search_request["from"] = client.jid.full() |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 search_request["to"] = to_jid.full() |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
157 query_elt = search_request.addElement('query', NS_SEARCH) |
725
7c806491c76a
plugin XEP-0055: fixed form's namespace
Goffi <goffi@goffi.org>
parents:
631
diff
changeset
|
158 x_form = data_form.Form('submit', formNamespace = NS_SEARCH) |
631
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 x_form.makeFields(search_dict) |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 query_elt.addChild(x_form.toElement()) |
1219
16484ebb695b
plugin XEP-0059: first draft, pubsub and jabber search do not exploit it yet
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
161 # TODO: XEP-0059 could be used here (with the needed new method attributes) |
631
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 d = search_request.send(to_jid.full()) |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
163 d.addCallbacks(self._searchOk, self._searchErr, callbackArgs=[client.profile], errbackArgs=[client.profile]) |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 return d |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 def _searchOk(self, answer, profile): |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 """got search available""" |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 try: |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
169 query_elts = answer.elements('jabber:iq:search', 'query').next() |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
170 except StopIteration: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
867
diff
changeset
|
171 log.info(_("No query element found")) |
631
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
172 raise DataError # FIXME: StanzaError is probably more appropriate, check the RFC |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
173 try: |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
174 form_elt = query_elts.elements(data_form.NS_X_DATA, 'x').next() |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
175 except StopIteration: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
867
diff
changeset
|
176 log.info(_("No data form found")) |
631
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
177 raise NotImplementedError("Only search through data form is implemented so far") |
799
7f2082b192ed
plugin XEP-0055, Primitivus: Directory search dialogs are now entirely done in plugin XEP-0055, specific code in frontend is not needed anymore
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
178 return xml_tools.dataFormResult2XMLUI(form_elt) |
631
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
180 def _searchErr(self, failure, profile): |
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
181 """ Called when something is wrong with search request """ |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
867
diff
changeset
|
182 log.info(_("Search request failure: %s") % str(failure.value)) |
631
694f118d0cd5
plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
183 return failure |