annotate src/plugins/plugin_xep_0055.py @ 918:1597fb8b9108

bridge: remove unecessary signals/methods declarations
author souliane <souliane@mailoo.org>
date Fri, 21 Mar 2014 09:09:51 +0100
parents 40ad5a344332
children 301b342c697a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
1fe00f0c9a91 dates update
Goffi <goffi@goffi.org>
parents: 809
diff changeset
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_
631
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
21 from logging import debug, info, warning, error
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from twisted.words.protocols.jabber.xmlstream import IQ
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from twisted.words.protocols.jabber import jid
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from wokkel import data_form
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
25 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
26 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
27 from sat.tools import xml_tools
631
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
28
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
29 NS_SEARCH = 'jabber:iq:search'
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 PLUGIN_INFO = {
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
32 "name": "Jabber Search",
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
33 "import_name": "XEP-0055",
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
34 "type": "XEP",
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
35 "protocols": ["XEP-0055"],
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
36 "main": "XEP_0055",
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
37 "handler": "no",
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
38 "description": _("""Implementation of Jabber Search""")
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
39 }
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
40
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
41
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
42 class XEP_0055(object):
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 def __init__(self, host):
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
45 info(_("Jabber search plugin initialization"))
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
46 self.host = host
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
47 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
48 method=self._getSearchUI,
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
49 async=True)
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
50 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
51 method=self._searchRequest,
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
52 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
53 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
54 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
55 self.__search_request_id = host.registerCallback(self._xmluiSearchRequest, with_data=True)
809
743b757777d3 core: security limit in menus
Goffi <goffi@goffi.org>
parents: 802
diff changeset
56 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
57
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 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
59 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
60 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
61 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
62 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
63 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
64 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
65 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
66 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
67 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
68 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
69
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
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 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
72 """ 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
73 @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
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 """
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 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
77 form_ui.addText(_("Please enter the search jid"), 'instructions')
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 799
diff changeset
78 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
79 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
80 # 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
81 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
82 return {'xmlui': form_ui.toXml()}
631
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
83
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
84 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
85 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
86 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
87 return d
631
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
88
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
89 def getSearchUI(self, to_jid, profile_key):
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
90 """ Ask for a search interface
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
91 @param to_jid: XEP-0055 compliant search entity
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
92 @param profile_key: %(doc_profile_key)s
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
93 @return: XMLUI search interface """
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
94 client = self.host.getClient(profile_key)
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
95 fields_request = IQ(client.xmlstream, 'get')
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
96 fields_request["from"] = client.jid.full()
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
97 fields_request["to"] = to_jid.full()
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
98 fields_request.addElement('query', NS_SEARCH)
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
99 d = fields_request.send(to_jid.full())
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
100 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
101 return d
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
102
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
103 def _fieldsOk(self, answer, profile):
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
104 """got fields available"""
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
105 try:
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
106 query_elts = answer.elements('jabber:iq:search', 'query').next()
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
107 except StopIteration:
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
108 info(_("No query element found"))
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
109 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
110 try:
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
111 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
112 except StopIteration:
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
113 info(_("No data form found"))
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
114 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
115 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
116 return xml_tools.dataForm2XMLUI(parsed_form, "")
631
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
117
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
118 def _fieldsErr(self, failure, profile):
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
119 """ Called when something is wrong with fields request """
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
120 info(_("Fields request failure: %s") % str(failure.value))
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
121 return failure
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
122
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
123 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
124 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
125 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
126 except KeyError:
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 warning ("session id doesn't exist, session has probably expired")
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 # 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
129 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
130
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
131 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
132 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
133 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
134 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
135 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
136 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
137
631
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
138 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
139 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
140 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
141 return d
631
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
142
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
143 def searchRequest(self, to_jid, search_dict, profile_key):
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
144 """ Actually do a search, according to filled data
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
145 @param to_jid: XEP-0055 compliant search entity
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
146 @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
147 @param profile_key: %(doc_profile_key)s
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
148 @return: XMLUI search result """
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
149 client = self.host.getClient(profile_key)
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
150 search_request = IQ(client.xmlstream, 'set')
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
151 search_request["from"] = client.jid.full()
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
152 search_request["to"] = to_jid.full()
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
153 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
154 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
155 x_form.makeFields(search_dict)
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
156 query_elt.addChild(x_form.toElement())
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
157 d = search_request.send(to_jid.full())
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
158 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
159 return d
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
160
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
161 def _searchOk(self, answer, profile):
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
162 """got search available"""
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
163 try:
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
164 query_elts = answer.elements('jabber:iq:search', 'query').next()
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
165 except StopIteration:
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
166 info(_("No query element found"))
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
167 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
168 try:
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
169 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
170 except StopIteration:
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
171 info(_("No data form found"))
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
172 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
173 return xml_tools.dataFormResult2XMLUI(form_elt)
631
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
174
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
175 def _searchErr(self, failure, profile):
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
176 """ Called when something is wrong with search request """
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
177 info(_("Search request failure: %s") % str(failure.value))
694f118d0cd5 plugin XEP-0055: implementation of Jabber Search
Goffi <goffi@goffi.org>
parents:
diff changeset
178 return failure