annotate src/plugins/plugin_xep_0060.py @ 2444:30278ea1ca7c

plugin XEP-0060: added node watching methods to bridge: new methods psNodeWatchAdd and psNodeWatchRemove allows to set a watch for the time of the session on one node, to have a signal called when something change on this node. This signal (psEventRaw) send raw data (raw XML), in opposition to psEvent which is there to send high level data (e.g. parsed blog data). Those method are primarely there to let frontends manage local cache for pubsub nodes.
author Goffi <goffi@goffi.org>
date Sun, 19 Nov 2017 16:51:39 +0100
parents b8ffb7f8056b
children a9c092bf4ee9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1934
2daf7b4c6756 use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents: 1904
diff changeset
1 #!/usr/bin/env python2
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
3
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
4 # SAT plugin for Publish-Subscribe (xep-0060)
2414
8b37a62336c3 misc: date update (yes it's a bit late :p )
Goffi <goffi@goffi.org>
parents: 2413
diff changeset
5 # Copyright (C) 2009-2017 Jérôme Poisson (goffi@goffi.org)
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
6
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
7 # This program is free software: you can redistribute it and/or modify
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
10 # (at your option) any later version.
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
11
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
12 # This program is distributed in the hope that it will be useful,
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
15 # GNU Affero General Public License for more details.
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
16
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
19
771
bfabeedbf32e core: i18n refactoring:
Goffi <goffi@goffi.org>
parents: 745
diff changeset
20 from sat.core.i18n import _
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 891
diff changeset
21 from sat.core.constants import Const as C
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
22 from sat.core.log import getLogger
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 916
diff changeset
23 log = getLogger(__name__)
1483
0f0889028eea plugin XEP-0060: implemented getFeatures, data has a "service" key if service is found for this profile
Goffi <goffi@goffi.org>
parents: 1459
diff changeset
24 from sat.core import exceptions
1449
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
25 from sat.tools import sat_defer
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
26
1678
c2d96f74105e plugin XEP-0060: trap failure when subscription to a node is not possible
souliane <souliane@mailoo.org>
parents: 1552
diff changeset
27 from twisted.words.protocols.jabber import jid, error
1451
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
28 from twisted.internet import defer
1449
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
29 from wokkel import disco
1777
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
30 from wokkel import data_form
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
31 from zope.interface import implements
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
32 from collections import namedtuple
1829
6079752ffeae plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents: 1778
diff changeset
33 import urllib
1777
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
34 import datetime
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
35 from dateutil import tz
2413
70399d1acb47 tmp: removed sat.tmp hierarchy and fixed references to it as it is now an independant sat_tmp repository
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
36 # XXX: sat_tmp.wokkel.pubsub is actually use instead of wokkel version
70399d1acb47 tmp: removed sat.tmp hierarchy and fixed references to it as it is now an independant sat_tmp repository
Goffi <goffi@goffi.org>
parents: 2393
diff changeset
37 # mam and rsm come from sat_tmp.wokkel too
1449
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
38 from wokkel import pubsub
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
39 from wokkel import rsm
1777
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
40 from wokkel import mam
1449
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
41
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
42
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
43 PLUGIN_INFO = {
2145
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
44 C.PI_NAME: "Publish-Subscribe",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
45 C.PI_IMPORT_NAME: "XEP-0060",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
46 C.PI_TYPE: "XEP",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
47 C.PI_PROTOCOLS: ["XEP-0060"],
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
48 C.PI_DEPENDENCIES: [],
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
49 C.PI_RECOMMENDATIONS: ["XEP-0313"],
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
50 C.PI_MAIN: "XEP_0060",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
51 C.PI_HANDLER: "yes",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
52 C.PI_DESCRIPTION: _("""Implementation of PubSub Protocol""")
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
53 }
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
54
1777
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
55 UNSPECIFIED = "unspecified error"
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
56 MAM_FILTER = "mam_filter_"
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
57
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
58
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
59 Extra = namedtuple('Extra', ('rsm_request', 'extra'))
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
60 # rsm_request is the rsm.RSMRequest build with rsm_ prefixed keys, or None
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
61 # extra is a potentially empty dict
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
62
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
63
588
beaf6bec2fcd Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
64 class XEP_0060(object):
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
65 OPT_ACCESS_MODEL = 'pubsub#access_model'
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
66 OPT_PERSIST_ITEMS = 'pubsub#persist_items'
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
67 OPT_MAX_ITEMS = 'pubsub#max_items'
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
68 OPT_DELIVER_PAYLOADS = 'pubsub#deliver_payloads'
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
69 OPT_SEND_ITEM_SUBSCRIBE = 'pubsub#send_item_subscribe'
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
70 OPT_NODE_TYPE = 'pubsub#node_type'
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
71 OPT_SUBSCRIPTION_TYPE = 'pubsub#subscription_type'
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
72 OPT_SUBSCRIPTION_DEPTH = 'pubsub#subscription_depth'
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
73 OPT_ROSTER_GROUPS_ALLOWED = 'pubsub#roster_groups_allowed'
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
74 OPT_PUBLISH_MODEL = 'pubsub#publish_model'
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
75 ACCESS_OPEN = 'open'
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
76 ACCESS_PRESENCE = 'presence'
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
77 ACCESS_ROSTER = 'roster'
2201
40dd9eb2692c plugin groupblog, XEP-0060: added ACCESS_PUBLISHER_ROSTER and switched to it in groupblog
Goffi <goffi@goffi.org>
parents: 2198
diff changeset
78 ACCESS_PUBLISHER_ROSTER = 'publisher-roster'
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
79 ACCESS_AUTHORIZE = 'authorize'
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
80 ACCESS_WHITELIST = 'whitelist'
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
81
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
82 def __init__(self, host):
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1261
diff changeset
83 log.info(_(u"PubSub plugin initialization"))
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
84 self.host = host
1777
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
85 self._mam = host.plugins.get('XEP-0313')
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
86 self._node_cb = {} # dictionnary of callbacks for node (key: node, value: list of callbacks)
1449
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
87 self.rt_sessions = sat_defer.RTDeferredSessions()
2218
6a2fa651d7fa plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents: 2206
diff changeset
88 host.bridge.addMethod("psNodeCreate", ".plugin", in_sign='ssa{ss}s', out_sign='s', method=self._createNode, async=True)
2196
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
89 host.bridge.addMethod("psNodeConfigurationGet", ".plugin", in_sign='sss', out_sign='a{ss}', method=self._getNodeConfiguration, async=True)
2198
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
90 host.bridge.addMethod("psNodeConfigurationSet", ".plugin", in_sign='ssa{ss}s', out_sign='', method=self._setNodeConfiguration, async=True)
2203
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
91 host.bridge.addMethod("psNodeAffiliationsGet", ".plugin", in_sign='sss', out_sign='a{ss}', method=self._getNodeAffiliations, async=True)
2206
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
92 host.bridge.addMethod("psNodeAffiliationsSet", ".plugin", in_sign='ssa{ss}s', out_sign='', method=self._setNodeAffiliations, async=True)
2338
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
93 host.bridge.addMethod("psNodeSubscriptionsGet", ".plugin", in_sign='sss', out_sign='a{ss}', method=self._getNodeSubscriptions, async=True)
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
94 host.bridge.addMethod("psNodeSubscriptionsSet", ".plugin", in_sign='ssa{ss}s', out_sign='', method=self._setNodeSubscriptions, async=True)
2444
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
95 host.bridge.addMethod("psNodeDelete", ".plugin", in_sign='sss', out_sign='', method=self._deleteNode, async=True)
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
96 host.bridge.addMethod("psNodeWatchAdd", ".plugin", in_sign='sss', out_sign='', method=self._addWatch, async=False)
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
97 host.bridge.addMethod("psNodeWatchRemove", ".plugin", in_sign='sss', out_sign='', method=self._removeWatch, async=False)
2338
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
98 host.bridge.addMethod("psAffiliationsGet", ".plugin", in_sign='sss', out_sign='a{ss}', method=self._getAffiliations, async=True)
2272
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
99 host.bridge.addMethod("psItemsGet", ".plugin", in_sign='ssiassa{ss}s', out_sign='(asa{ss})', method=self._getItems, async=True)
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
100 host.bridge.addMethod("psItemSend", ".plugin", in_sign='ssssa{ss}s', out_sign='s', method=self._sendItem, async=True)
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
101 host.bridge.addMethod("psRetractItem", ".plugin", in_sign='sssbs', out_sign='', method=self._retractItem, async=True)
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
102 host.bridge.addMethod("psRetractItems", ".plugin", in_sign='ssasbs', out_sign='', method=self._retractItems, async=True)
2442
b8ffb7f8056b plugin XEP-0060: added "options" argument to psSubscribe, and return subscription id if present
Goffi <goffi@goffi.org>
parents: 2432
diff changeset
103 host.bridge.addMethod("psSubscribe", ".plugin", in_sign='ssa{ss}s', out_sign='s', method=self._subscribe, async=True)
2352
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
104 host.bridge.addMethod("psUnsubscribe", ".plugin", in_sign='sss', out_sign='', method=self._unsubscribe, async=True)
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
105 host.bridge.addMethod("psSubscriptionsGet", ".plugin", in_sign='sss', out_sign='aa{ss}', method=self._subscriptions, async=True)
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
106 host.bridge.addMethod("psSubscribeToMany", ".plugin", in_sign='a(ss)sa{ss}s', out_sign='s', method=self._subscribeToMany)
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
107 host.bridge.addMethod("psGetSubscribeRTResult", ".plugin", in_sign='ss', out_sign='(ua(sss))', method=self._manySubscribeRTResult, async=True)
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
108 host.bridge.addMethod("psGetFromMany", ".plugin", in_sign='a(ss)ia{ss}s', out_sign='s', method=self._getFromMany)
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
109 host.bridge.addMethod("psGetFromManyRTResult", ".plugin", in_sign='ss', out_sign='(ua(sssasa{ss}))', method=self._getFromManyRTResult, async=True)
2444
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
110
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
111 # high level observer method
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
112 host.bridge.addSignal("psEvent", ".plugin", signature='ssssa{ss}s') # args: category, service(jid), node, type (C.PS_ITEMS, C.PS_DELETE), data, profile
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
113
2444
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
114 # low level observer method, used if service/node is in watching list (see psNodeWatch* methods)
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
115 host.bridge.addSignal("psEventRaw", ".plugin", signature='sssass') # args: service(jid), node, type (C.PS_ITEMS, C.PS_DELETE), list of item_xml, profile
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
116
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
117 def getHandler(self, client):
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
118 client.pubsub_client = SatPubSubClient(self.host, self)
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
119 return client.pubsub_client
1282
74d558e6c9fd plugin XEP-0060: free SatPubSubClient instance on profile disconnection
souliane <souliane@mailoo.org>
parents: 1268
diff changeset
120
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
121 @defer.inlineCallbacks
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
122 def profileConnected(self, client):
2444
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
123 client.pubsub_watching = set()
2432
c6d859df4b27 plugin XEP-0060: use new findServiceEntity to get default pubsub service
Goffi <goffi@goffi.org>
parents: 2423
diff changeset
124 client.pubsub_service = yield self.host.findServiceEntity(client, "pubsub", "service")
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
125
1483
0f0889028eea plugin XEP-0060: implemented getFeatures, data has a "service" key if service is found for this profile
Goffi <goffi@goffi.org>
parents: 1459
diff changeset
126 def getFeatures(self, profile):
0f0889028eea plugin XEP-0060: implemented getFeatures, data has a "service" key if service is found for this profile
Goffi <goffi@goffi.org>
parents: 1459
diff changeset
127 try:
0f0889028eea plugin XEP-0060: implemented getFeatures, data has a "service" key if service is found for this profile
Goffi <goffi@goffi.org>
parents: 1459
diff changeset
128 client = self.host.getClient(profile)
0f0889028eea plugin XEP-0060: implemented getFeatures, data has a "service" key if service is found for this profile
Goffi <goffi@goffi.org>
parents: 1459
diff changeset
129 except exceptions.ProfileNotSetError:
0f0889028eea plugin XEP-0060: implemented getFeatures, data has a "service" key if service is found for this profile
Goffi <goffi@goffi.org>
parents: 1459
diff changeset
130 return {}
0f0889028eea plugin XEP-0060: implemented getFeatures, data has a "service" key if service is found for this profile
Goffi <goffi@goffi.org>
parents: 1459
diff changeset
131 try:
0f0889028eea plugin XEP-0060: implemented getFeatures, data has a "service" key if service is found for this profile
Goffi <goffi@goffi.org>
parents: 1459
diff changeset
132 return {'service': client.pubsub_service.full() if client.pubsub_service is not None else ''}
0f0889028eea plugin XEP-0060: implemented getFeatures, data has a "service" key if service is found for this profile
Goffi <goffi@goffi.org>
parents: 1459
diff changeset
133 except AttributeError:
0f0889028eea plugin XEP-0060: implemented getFeatures, data has a "service" key if service is found for this profile
Goffi <goffi@goffi.org>
parents: 1459
diff changeset
134 if self.host.isConnected(profile):
0f0889028eea plugin XEP-0060: implemented getFeatures, data has a "service" key if service is found for this profile
Goffi <goffi@goffi.org>
parents: 1459
diff changeset
135 log.debug("Profile is not connected, service is not checked yet")
0f0889028eea plugin XEP-0060: implemented getFeatures, data has a "service" key if service is found for this profile
Goffi <goffi@goffi.org>
parents: 1459
diff changeset
136 else:
0f0889028eea plugin XEP-0060: implemented getFeatures, data has a "service" key if service is found for this profile
Goffi <goffi@goffi.org>
parents: 1459
diff changeset
137 log.error("Service should be available !")
0f0889028eea plugin XEP-0060: implemented getFeatures, data has a "service" key if service is found for this profile
Goffi <goffi@goffi.org>
parents: 1459
diff changeset
138 return {}
0f0889028eea plugin XEP-0060: implemented getFeatures, data has a "service" key if service is found for this profile
Goffi <goffi@goffi.org>
parents: 1459
diff changeset
139
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
140 def parseExtra(self, extra):
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
141 """Parse extra dictionnary
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
142
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
143 used bridge's extra dictionnaries
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
144 @param extra(dict): extra data used to configure request
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
145 @return(Extra): filled Extra instance
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
146 """
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
147 if extra is not None:
1777
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
148 # rsm
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
149 rsm_args = {}
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
150 for arg in ('max', 'after', 'before', 'index'):
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
151 try:
1777
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
152 argname = "max_" if arg == 'max' else arg
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
153 rsm_args[argname] = extra.pop('rsm_{}'.format(arg))
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
154 except KeyError:
1777
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
155 continue
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
156
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
157 if rsm_args:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
158 rsm_request = rsm.RSMRequest(**rsm_args)
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
159 else:
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
160 rsm_request = None
1777
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
161
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
162 # mam
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
163 mam_args = {}
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
164 for arg in ('start', 'end'):
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
165 try:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
166 mam_args[arg] = datetime.datetime.fromtimestamp(int(extra.pop('{}{}'.format(MAM_FILTER, arg))), tz.tzutc())
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
167 except (TypeError, ValueError):
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
168 log.warning(u"Bad value for {} filter".format(arg))
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
169 except KeyError:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
170 continue
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
171
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
172 try:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
173 mam_args['with_jid'] = jid.JID(extra.pop('{}jid'.format(MAM_FILTER)))
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
174 except (jid.InvalidFormat):
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
175 log.warning(u"Bad value for jid filter")
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
176 except KeyError:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
177 pass
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
178
1778
442303b62a16 plugin XEP-0060: fixed extra mam filters parsing
Goffi <goffi@goffi.org>
parents: 1777
diff changeset
179 for name, value in extra.iteritems():
1777
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
180 if name.startswith(MAM_FILTER):
1778
442303b62a16 plugin XEP-0060: fixed extra mam filters parsing
Goffi <goffi@goffi.org>
parents: 1777
diff changeset
181 var = name[len(MAM_FILTER):]
1777
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
182 extra_fields = mam_args.setdefault('extra_fields', [])
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
183 extra_fields.append(data_form.Field(var=var, value=value))
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
184
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
185 if mam_args:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
186 assert 'mam' not in extra
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
187 extra['mam'] = mam.MAMRequest(mam.buildForm(**mam_args))
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
188 else:
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
189 rsm_request = None
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
190 extra = {}
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
191 return Extra(rsm_request, extra)
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
192
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
193 def addManagedNode(self, node, **kwargs):
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
194 """Add a handler for a node
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
195
1760
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
196 @param node(unicode): node to monitor
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
197 all node *prefixed* with this one will be triggered
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
198 @param **kwargs: method(s) to call when the node is found
2305
972e33507609 plugin XEP-0060: addManagedNode callbacks now use client syntax instead of profile
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
199 the method must be named after PubSub constants in lower case
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
200 and suffixed with "_cb"
2305
972e33507609 plugin XEP-0060: addManagedNode callbacks now use client syntax instead of profile
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
201 e.g.: "items_cb" for C.PS_ITEMS, "delete_cb" for C.PS_DELETE
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
202 """
1760
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
203 assert node is not None
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
204 assert kwargs
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
205 callbacks = self._node_cb.setdefault(node, {})
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
206 for event, cb in kwargs.iteritems():
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
207 event_name = event[:-3]
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
208 assert event_name in C.PS_EVENTS
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
209 callbacks.setdefault(event_name,[]).append(cb)
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
210
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
211 def removeManagedNode(self, node, *args):
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
212 """Add a handler for a node
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
213
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
214 @param node(unicode): node to monitor
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
215 @param *args: callback(s) to remove
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
216 """
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
217 assert args
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
218 try:
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
219 registred_cb = self._node_cb[node]
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
220 except KeyError:
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
221 pass
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
222 else:
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
223 for callback in args:
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
224 for event, cb_list in registred_cb.iteritems():
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
225 try:
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
226 cb_list.remove(callback)
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
227 except ValueError:
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
228 pass
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
229 else:
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
230 log.debug(u"removed callback {cb} for event {event} on node {node}".format(
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
231 cb=callback, event=event, node=node))
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
232 if not cb_list:
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
233 del registred_cb[event]
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
234 if not registred_cb:
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
235 del self._node_cb[node]
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
236 return
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
237 log.error(u"Trying to remove inexistant callback {cb} for node {node}".format(cb=callback, node=node))
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
238
1446
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
239 # def listNodes(self, service, nodeIdentifier='', profile=C.PROF_KEY_NONE):
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
240 # """Retrieve the name of the nodes that are accessible on the target service.
1242
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
241
1446
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
242 # @param service (JID): target service
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
243 # @param nodeIdentifier (str): the parent node name (leave empty to retrieve first-level nodes)
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
244 # @param profile (str): %(doc_profile)s
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
245 # @return: deferred which fire a list of nodes
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
246 # """
2148
a543eda2c923 core (memory/disco): getInfos now handle node + use client instead of profile in many methods
Goffi <goffi@goffi.org>
parents: 2145
diff changeset
247 # client = self.host.getClient(profile)
a543eda2c923 core (memory/disco): getInfos now handle node + use client instead of profile in many methods
Goffi <goffi@goffi.org>
parents: 2145
diff changeset
248 # d = self.host.getDiscoItems(client, service, nodeIdentifier)
1446
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
249 # d.addCallback(lambda result: [item.getAttribute('node') for item in result.toElement().children if item.hasAttribute('node')])
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
250 # return d
1242
f584fbda4773 plugin XEP-0060: fixes listing the nodes on the pubsub service
souliane <souliane@mailoo.org>
parents: 1219
diff changeset
251
1446
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
252 # def listSubscribedNodes(self, service, nodeIdentifier='', filter_='subscribed', profile=C.PROF_KEY_NONE):
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
253 # """Retrieve the name of the nodes to which the profile is subscribed on the target service.
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
254
1446
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
255 # @param service (JID): target service
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
256 # @param nodeIdentifier (str): the parent node name (leave empty to retrieve all subscriptions)
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
257 # @param filter_ (str): filter the result according to the given subscription type:
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
258 # - None: do not filter
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
259 # - 'pending': subscription has not been approved yet by the node owner
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
260 # - 'unconfigured': subscription options have not been configured yet
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
261 # - 'subscribed': subscription is complete
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
262 # @param profile (str): %(doc_profile)s
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
263 # @return: Deferred list[str]
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
264 # """
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
265 # d = self.subscriptions(service, nodeIdentifier, profile_key=profile)
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
266 # d.addCallback(lambda subs: [sub.getAttribute('node') for sub in subs if sub.getAttribute('subscription') == filter_])
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
267 # return d
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
268
2272
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
269 def _sendItem(self, service, nodeIdentifier, payload, item_id=None, extra=None, profile_key=C.PROF_KEY_NONE):
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
270 client = self.host.getClient(profile_key)
2272
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
271 service = None if not service else jid.JID(service)
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
272 d = self.sendItem(client, service, nodeIdentifier, payload, item_id or None, extra)
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
273 d.addCallback(lambda ret: ret or u'')
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
274 return d
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
275
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
276 def _getPublishedItemId(self, iq_elt, original_id):
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
277 """return item of published id if found in answer
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
278
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
279 if not found original_id is returned, or empty string if it is None or empty string
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
280 """
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
281 try:
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
282 item_id = iq_elt.pubsub.publish.item['id']
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
283 except (AttributeError, KeyError):
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
284 item_id = None
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
285 return item_id or original_id
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
286
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
287 def sendItem(self, client, service, nodeIdentifier, payload, item_id=None, extra=None):
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
288 """high level method to send one item
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
289
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
290 @param service(jid.JID, None): service to send the item to
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
291 None to use PEP
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
292 @param NodeIdentifier(unicode): PubSub node to use
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
293 @param item_id(unicode, None): id to use or None to create one
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
294 @param payload(domish.Element, unicode): payload of the item to send
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
295 @param extra(dict, None): extra option, not used yet
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
296 @return (unicode, None): id of the created item
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
297 """
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
298 item_elt = pubsub.Item(id=item_id, payload=payload)
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
299 d = self.publish(client, service, nodeIdentifier, [item_elt])
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
300 d.addCallback(self._getPublishedItemId, item_id)
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
301 return d
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
302
b5befe7722d3 plugin XEP-0060: added sendItem and psItemSend bridge method as a way to send directly raw XML for an item + use client instead of profile_key in publish + renamed psItemGet to psItemsGet
Goffi <goffi@goffi.org>
parents: 2226
diff changeset
303 def publish(self, client, service, nodeIdentifier, items=None):
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
304 return client.pubsub_client.publish(service, nodeIdentifier, items, client.pubsub_client.parent.jid)
286
3b382fa0ac28 plugin xep-0163: added mood publishing
Goffi <goffi@goffi.org>
parents: 283
diff changeset
305
1777
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
306 def _unwrapMAMMessage(self, message_elt):
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
307 try:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
308 item_elt = (message_elt.elements(mam.NS_MAM, 'result').next()
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
309 .elements(C.NS_FORWARD, 'forwarded').next()
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
310 .elements(C.NS_CLIENT, 'message').next()
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
311 .elements('http://jabber.org/protocol/pubsub#event', 'event').next()
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
312 .elements('http://jabber.org/protocol/pubsub#event', 'items').next()
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
313 .elements('http://jabber.org/protocol/pubsub#event', 'item').next())
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
314 except StopIteration:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
315 raise exceptions.DataError(u"Can't find Item in MAM message element")
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
316 return item_elt
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
317
2185
dd53d7a3219a plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents: 2148
diff changeset
318 def _getItems(self, service='', node='', max_items=10, item_ids=None, sub_id=None, extra_dict=None, profile_key=C.PROF_KEY_NONE):
dd53d7a3219a plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents: 2148
diff changeset
319 """Get items from pubsub node
dd53d7a3219a plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents: 2148
diff changeset
320
dd53d7a3219a plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents: 2148
diff changeset
321 @param max_items(int): maximum number of item to get, C.NO_LIMIT for no limit
dd53d7a3219a plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents: 2148
diff changeset
322 """
2360
72cbb6478f97 plugin XEP-0060: use client instead of profile_key in getItems
Goffi <goffi@goffi.org>
parents: 2352
diff changeset
323 client = self.host.getClient(profile_key)
2185
dd53d7a3219a plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents: 2148
diff changeset
324 service = jid.JID(service) if service else None
dd53d7a3219a plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents: 2148
diff changeset
325 max_items = None if max_items == C.NO_LIMIT else max_items
dd53d7a3219a plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents: 2148
diff changeset
326 extra = self.parseExtra(extra_dict)
2360
72cbb6478f97 plugin XEP-0060: use client instead of profile_key in getItems
Goffi <goffi@goffi.org>
parents: 2352
diff changeset
327 d = self.getItems(client, service, node or None, max_items or None, item_ids, sub_id or None, extra.rsm_request, extra.extra)
2185
dd53d7a3219a plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents: 2148
diff changeset
328 d.addCallback(self.serItemsData)
dd53d7a3219a plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents: 2148
diff changeset
329 return d
dd53d7a3219a plugin XEP-0060: added psGet bridge method
Goffi <goffi@goffi.org>
parents: 2148
diff changeset
330
2360
72cbb6478f97 plugin XEP-0060: use client instead of profile_key in getItems
Goffi <goffi@goffi.org>
parents: 2352
diff changeset
331 def getItems(self, client, service, node, max_items=None, item_ids=None, sub_id=None, rsm_request=None, extra=None):
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1267
diff changeset
332 """Retrieve pubsub items from a node.
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1267
diff changeset
333
1865
fc6eeacf31bc plugin XEP-0277: service can be None in mbGet, resulting in a request on default pubsub service of profile (i.e. profile's PEP)
Goffi <goffi@goffi.org>
parents: 1854
diff changeset
334 @param service (JID, None): pubsub service.
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1267
diff changeset
335 @param node (str): node id.
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1267
diff changeset
336 @param max_items (int): optional limit on the number of retrieved items.
1452
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
337 @param item_ids (list[str]): identifiers of the items to be retrieved (can't be used with rsm_request).
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1267
diff changeset
338 @param sub_id (str): optional subscription identifier.
1452
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
339 @param rsm_request (rsm.RSMRequest): RSM request data
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1267
diff changeset
340 @return: a deferred couple (list[dict], dict) containing:
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1267
diff changeset
341 - list of items
1446
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
342 - metadata with the following keys:
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
343 - rsm_first, rsm_last, rsm_count, rsm_index: first, last, count and index value of RSMResponse
1903
29564cec913f plugin XEP-0060: service, node and uri are added to metadata when doing a getItems
Goffi <goffi@goffi.org>
parents: 1865
diff changeset
344 - service, node: service and node used
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1267
diff changeset
345 """
2319
e715a29c4f9b plugin XEP-0060: remove max_items when item_ids is set on getItems
Goffi <goffi@goffi.org>
parents: 2314
diff changeset
346 if item_ids and max_items is not None:
e715a29c4f9b plugin XEP-0060: remove max_items when item_ids is set on getItems
Goffi <goffi@goffi.org>
parents: 2314
diff changeset
347 max_items = None
1452
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
348 if rsm_request and item_ids:
1773
6e867caf4621 plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
349 raise ValueError(u"items_id can't be used with rsm")
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
350 if extra is None:
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
351 extra = {}
1777
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
352 try:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
353 mam_query = extra['mam']
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
354 except KeyError:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
355 d = client.pubsub_client.items(service, node, max_items, item_ids, sub_id, None, rsm_request)
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
356 else:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
357 # if mam is requested, we have to do a totally different query
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
358 if self._mam is None:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
359 raise exceptions.NotFound(u"MAM (XEP-0313) plugin is not available")
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
360 if max_items is not None:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
361 raise exceptions.DataError(u"max_items parameter can't be used with MAM")
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
362 if item_ids:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
363 raise exceptions.DataError(u"items_ids parameter can't be used with MAM")
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
364 if mam_query.node is None:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
365 mam_query.node = node
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
366 elif mam_query.node != node:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
367 raise exceptions.DataError(u"MAM query node is incoherent with getItems's node")
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
368 if mam_query.rsm is None:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
369 mam_query.rsm = rsm_request
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
370 else:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
371 if mam_query.rsm != rsm_request:
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
372 raise exceptions.DataError(u"Conflict between RSM request and MAM's RSM request")
8b18e5f55a90 plugin XEP-0060: MAM integration:
Goffi <goffi@goffi.org>
parents: 1773
diff changeset
373 d = self._mam.getArchives(client, mam_query, service, self._unwrapMAMMessage)
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
374
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
375 try:
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
376 subscribe = C.bool(extra['subscribe'])
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
377 except KeyError:
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
378 subscribe = False
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
379
1678
c2d96f74105e plugin XEP-0060: trap failure when subscription to a node is not possible
souliane <souliane@mailoo.org>
parents: 1552
diff changeset
380 def subscribeEb(failure, service, node):
c2d96f74105e plugin XEP-0060: trap failure when subscription to a node is not possible
souliane <souliane@mailoo.org>
parents: 1552
diff changeset
381 failure.trap(error.StanzaError)
1773
6e867caf4621 plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
382 log.warning(u"Could not subscribe to node {} on service {}: {}".format(node, unicode(service), unicode(failure.value)))
1760
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
383
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
384 def doSubscribe(items):
2423
e3edbccd26d7 XEP-0060: fixed bad attribute in getItems
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
385 self.subscribe(service, node, profile_key=client.profile).addErrback(subscribeEb, service, node)
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
386 return items
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
387
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
388 if subscribe:
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
389 d.addCallback(doSubscribe)
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
390
1773
6e867caf4621 plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
391 def addMetadata(result):
6e867caf4621 plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
392 items, rsm_response = result
2314
01f0a954d506 plugin XEP-0060: fixed service in metadata for PEP
Goffi <goffi@goffi.org>
parents: 2305
diff changeset
393 service_jid = service if service else client.jid.userhostJID()
1904
614f3abb2c69 plugin XEP-0060: fixed traceback if service was None
Goffi <goffi@goffi.org>
parents: 1903
diff changeset
394 metadata = {'service': service_jid,
1903
29564cec913f plugin XEP-0060: service, node and uri are added to metadata when doing a getItems
Goffi <goffi@goffi.org>
parents: 1865
diff changeset
395 'node': node,
1904
614f3abb2c69 plugin XEP-0060: fixed traceback if service was None
Goffi <goffi@goffi.org>
parents: 1903
diff changeset
396 'uri': self.getNodeURI(service_jid, node),
1903
29564cec913f plugin XEP-0060: service, node and uri are added to metadata when doing a getItems
Goffi <goffi@goffi.org>
parents: 1865
diff changeset
397 }
1773
6e867caf4621 plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
398 if rsm_request is not None and rsm_response is not None:
1903
29564cec913f plugin XEP-0060: service, node and uri are added to metadata when doing a getItems
Goffi <goffi@goffi.org>
parents: 1865
diff changeset
399 metadata.update({'rsm_{}'.format(key): value for key, value in rsm_response.toDict().iteritems()})
1446
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
400 return (items, metadata)
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
401
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
402 d.addCallback(addMetadata)
1268
bb30bf3ae932 plugins XEP-0060, XEP-0277, groupblog: make use of RSM (XEP-0059)
souliane <souliane@mailoo.org>
parents: 1267
diff changeset
403 return d
303
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
404
1446
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
405 # @defer.inlineCallbacks
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
406 # def getItemsFromMany(self, service, data, max_items=None, sub_id=None, rsm=None, profile_key=C.PROF_KEY_NONE):
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
407 # """Massively retrieve pubsub items from many nodes.
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
408 # @param service (JID): target service.
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
409 # @param data (dict): dictionnary binding some arbitrary keys to the node identifiers.
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
410 # @param max_items (int): optional limit on the number of retrieved items *per node*.
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
411 # @param sub_id (str): optional subscription identifier.
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
412 # @param rsm (dict): RSM request data
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
413 # @param profile_key (str): %(doc_profile_key)s
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
414 # @return: a deferred dict with:
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
415 # - key: a value in (a subset of) data.keys()
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
416 # - couple (list[dict], dict) containing:
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
417 # - list of items
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
418 # - RSM response data
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
419 # """
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
420 # client = self.host.getClient(profile_key)
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
421 # found_nodes = yield self.listNodes(service, profile=client.profile)
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
422 # d_dict = {}
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
423 # for publisher, node in data.items():
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
424 # if node not in found_nodes:
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
425 # log.debug(u"Skip the items retrieval for [{node}]: node doesn't exist".format(node=node))
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
426 # continue # avoid pubsub "item-not-found" error
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
427 # d_dict[publisher] = self.getItems(service, node, max_items, None, sub_id, rsm, client.profile)
e8c8e467964b plugins xep-0060, xep-0277: code simplification/cleaning/fix:
Goffi <goffi@goffi.org>
parents: 1420
diff changeset
428 # defer.returnValue(d_dict)
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
429
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 891
diff changeset
430 def getOptions(self, service, nodeIdentifier, subscriber, subscriptionIdentifier=None, profile_key=C.PROF_KEY_NONE):
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
431 client = self.host.getClient(profile_key)
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
432 return client.pubsub_client.getOptions(service, nodeIdentifier, subscriber, subscriptionIdentifier)
303
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
433
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 891
diff changeset
434 def setOptions(self, service, nodeIdentifier, subscriber, options, subscriptionIdentifier=None, profile_key=C.PROF_KEY_NONE):
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
435 client = self.host.getClient(profile_key)
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
436 return client.pubsub_client.setOptions(service, nodeIdentifier, subscriber, options, subscriptionIdentifier)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
437
2218
6a2fa651d7fa plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents: 2206
diff changeset
438 def _createNode(self, service_s, nodeIdentifier, options, profile_key):
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
439 client = self.host.getClient(profile_key)
2218
6a2fa651d7fa plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents: 2206
diff changeset
440 return self.createNode(client, jid.JID(service_s) if service_s else None, nodeIdentifier, options)
6a2fa651d7fa plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents: 2206
diff changeset
441
6a2fa651d7fa plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents: 2206
diff changeset
442 def createNode(self, client, service, nodeIdentifier=None, options=None):
6a2fa651d7fa plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents: 2206
diff changeset
443 """Create a new node
6a2fa651d7fa plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents: 2206
diff changeset
444
6a2fa651d7fa plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents: 2206
diff changeset
445 @param service(jid.JID): PubSub service,
6a2fa651d7fa plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents: 2206
diff changeset
446 @param NodeIdentifier(unicode, None): node name
6a2fa651d7fa plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents: 2206
diff changeset
447 use None to create instant node (identifier will be returned by this method)
6a2fa651d7fa plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents: 2206
diff changeset
448 @param option(dict[unicode, unicode], None): node configuration options
6a2fa651d7fa plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents: 2206
diff changeset
449 @return (unicode): identifier of the created node (may be different from requested name)
6a2fa651d7fa plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents: 2206
diff changeset
450 """
2393
8ed4ac10cb5e plugin tickets import: create comments nodes with open access/publishing
Goffi <goffi@goffi.org>
parents: 2389
diff changeset
451 # TODO: if pubsub service doesn't hande publish-options, configure it in a second time
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
452 return client.pubsub_client.createNode(service, nodeIdentifier, options)
303
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
453
2389
5675af905725 plugin XEP-0060: added createIfNewNode method which doesn't fail in case of conflict.
Goffi <goffi@goffi.org>
parents: 2360
diff changeset
454 @defer.inlineCallbacks
5675af905725 plugin XEP-0060: added createIfNewNode method which doesn't fail in case of conflict.
Goffi <goffi@goffi.org>
parents: 2360
diff changeset
455 def createIfNewNode(self, client, service, nodeIdentifier, options=None):
5675af905725 plugin XEP-0060: added createIfNewNode method which doesn't fail in case of conflict.
Goffi <goffi@goffi.org>
parents: 2360
diff changeset
456 """Helper method similar to createNode, but will not fail in case of conflict"""
5675af905725 plugin XEP-0060: added createIfNewNode method which doesn't fail in case of conflict.
Goffi <goffi@goffi.org>
parents: 2360
diff changeset
457 try:
5675af905725 plugin XEP-0060: added createIfNewNode method which doesn't fail in case of conflict.
Goffi <goffi@goffi.org>
parents: 2360
diff changeset
458 yield self.createNode(client, service, nodeIdentifier, options)
5675af905725 plugin XEP-0060: added createIfNewNode method which doesn't fail in case of conflict.
Goffi <goffi@goffi.org>
parents: 2360
diff changeset
459 except error.StanzaError as e:
5675af905725 plugin XEP-0060: added createIfNewNode method which doesn't fail in case of conflict.
Goffi <goffi@goffi.org>
parents: 2360
diff changeset
460 if e.condition == 'conflict':
5675af905725 plugin XEP-0060: added createIfNewNode method which doesn't fail in case of conflict.
Goffi <goffi@goffi.org>
parents: 2360
diff changeset
461 pass
5675af905725 plugin XEP-0060: added createIfNewNode method which doesn't fail in case of conflict.
Goffi <goffi@goffi.org>
parents: 2360
diff changeset
462 else:
5675af905725 plugin XEP-0060: added createIfNewNode method which doesn't fail in case of conflict.
Goffi <goffi@goffi.org>
parents: 2360
diff changeset
463 raise e
5675af905725 plugin XEP-0060: added createIfNewNode method which doesn't fail in case of conflict.
Goffi <goffi@goffi.org>
parents: 2360
diff changeset
464
2196
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
465 def _getNodeConfiguration(self, service_s, nodeIdentifier, profile_key):
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
466 client = self.host.getClient(profile_key)
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
467 d = self.getConfiguration(client, jid.JID(service_s) if service_s else None, nodeIdentifier)
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
468 def serialize(form):
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
469 # FIXME: better more generic dataform serialisation should be available in SàT
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
470 return {f.var: unicode(f.value) for f in form.fields.values()}
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
471 d.addCallback(serialize)
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
472 return d
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
473
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
474 def getConfiguration(self, client, service, nodeIdentifier):
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
475 request = pubsub.PubSubRequest('configureGet')
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
476 request.recipient = service
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
477 request.nodeIdentifier = nodeIdentifier
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
478
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
479 def cb(iq):
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
480 form = data_form.findForm(iq.pubsub.configure,
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
481 pubsub.NS_PUBSUB_NODE_CONFIG)
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
482 form.typeCheck()
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
483 return form
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
484
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
485 d = request.send(client.xmlstream)
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
486 d.addCallback(cb)
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
487 return d
d3e48c9a255e plugin XEP-0060: added getConfiguration ad psNodeConfigurationGet bridge method
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
488
2198
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
489 def _setNodeConfiguration(self, service_s, nodeIdentifier, options, profile_key):
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
490 client = self.host.getClient(profile_key)
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
491 d = self.setConfiguration(client, jid.JID(service_s) if service_s else None, nodeIdentifier, options)
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
492 return d
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
493
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
494 def setConfiguration(self, client, service, nodeIdentifier, options):
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
495 request = pubsub.PubSubRequest('configureSet')
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
496 request.recipient = service
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
497 request.nodeIdentifier = nodeIdentifier
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
498
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
499 form = data_form.Form(formType='submit',
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
500 formNamespace=pubsub.NS_PUBSUB_NODE_CONFIG)
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
501 form.makeFields(options)
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
502 request.options = form
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
503
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
504 d = request.send(client.xmlstream)
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
505 return d
44f12990e275 plugin XEP-0060: added setConfiguration/psNodeConfigurationSet + fix in tmp.wokkel.pubsub
Goffi <goffi@goffi.org>
parents: 2196
diff changeset
506
2203
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
507 def _getAffiliations(self, service_s, nodeIdentifier, profile_key):
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
508 client = self.host.getClient(profile_key)
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
509 d = self.getAffiliations(client, jid.JID(service_s) if service_s else None, nodeIdentifier or None)
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
510 return d
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
511
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
512 def getAffiliations(self, client, service, nodeIdentifier=None):
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
513 """Retrieve affiliations of an entity
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
514
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
515 @param nodeIdentifier(unicode, None): node to get affiliation from
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
516 None to get all nodes affiliations for this service
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
517 """
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
518 request = pubsub.PubSubRequest('affiliations')
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
519 request.recipient = service
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
520 request.nodeIdentifier = nodeIdentifier
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
521
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
522 def cb(iq_elt):
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
523 try:
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
524 affiliations_elt = next(iq_elt.pubsub.elements((pubsub.NS_PUBSUB, 'affiliations')))
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
525 except StopIteration:
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
526 raise ValueError(_(u"Invalid result: missing <affiliations> element: {}").format(iq_elt.toXml))
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
527 try:
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
528 return {e['node']: e['affiliation'] for e in affiliations_elt.elements((pubsub.NS_PUBSUB, 'affiliation'))}
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
529 except KeyError:
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
530 raise ValueError(_(u"Invalid result: bad <affiliation> element: {}").format(iq_elt.toXml))
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
531
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
532 d = request.send(client.xmlstream)
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
533 d.addCallback(cb)
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
534 return d
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
535
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
536 def _getNodeAffiliations(self, service_s, nodeIdentifier, profile_key):
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
537 client = self.host.getClient(profile_key)
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
538 d = self.getNodeAffiliations(client, jid.JID(service_s) if service_s else None, nodeIdentifier)
2226
6856b7225c5b plugin XEP-0060: getNodeAffiliations use jid.JID as keys instead of jids as unicode
Goffi <goffi@goffi.org>
parents: 2218
diff changeset
539 d.addCallback(lambda affiliations: {j.full(): a for j, a in affiliations.iteritems()})
2203
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
540 return d
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
541
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
542 def getNodeAffiliations(self, client, service, nodeIdentifier):
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
543 """Retrieve affiliations of a node owned by profile"""
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
544 request = pubsub.PubSubRequest('affiliationsGet')
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
545 request.recipient = service
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
546 request.nodeIdentifier = nodeIdentifier
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
547
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
548 def cb(iq_elt):
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
549 try:
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
550 affiliations_elt = next(iq_elt.pubsub.elements((pubsub.NS_PUBSUB_OWNER, 'affiliations')))
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
551 except StopIteration:
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
552 raise ValueError(_(u"Invalid result: missing <affiliations> element: {}").format(iq_elt.toXml))
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
553 try:
2226
6856b7225c5b plugin XEP-0060: getNodeAffiliations use jid.JID as keys instead of jids as unicode
Goffi <goffi@goffi.org>
parents: 2218
diff changeset
554 return {jid.JID(e['jid']): e['affiliation'] for e in affiliations_elt.elements((pubsub.NS_PUBSUB_OWNER, 'affiliation'))}
2203
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
555 except KeyError:
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
556 raise ValueError(_(u"Invalid result: bad <affiliation> element: {}").format(iq_elt.toXml))
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
557
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
558 d = request.send(client.xmlstream)
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
559 d.addCallback(cb)
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
560 return d
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
561
2206
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
562 def _setNodeAffiliations(self, service_s, nodeIdentifier, affiliations, profile_key=C.PROF_KEY_NONE):
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
563 client = self.host.getClient(profile_key)
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
564 affiliations = {jid.JID(jid_): affiliation for jid_, affiliation in affiliations.iteritems()}
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
565 d = self.setNodeAffiliations(client, jid.JID(service_s) if service_s else None, nodeIdentifier, affiliations)
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
566 return d
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
567
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
568 def setNodeAffiliations(self, client, service, nodeIdentifier, affiliations):
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
569 """Update affiliations of a node owned by profile
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
570
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
571 @param affiliations(dict[jid.JID, unicode]): affiliations to set
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
572 check https://xmpp.org/extensions/xep-0060.html#affiliations for a list of possible affiliations
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
573 """
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
574 request = pubsub.PubSubRequest('affiliationsSet')
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
575 request.recipient = service
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
576 request.nodeIdentifier = nodeIdentifier
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
577 request.affiliations = affiliations
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
578 d = request.send(client.xmlstream)
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
579 return d
59d3de85a0cb plugin XEP-0060: added setNodeAffiliations and its bridge method (psNodeAffiliationsSet)
Goffi <goffi@goffi.org>
parents: 2203
diff changeset
580
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
581 def _deleteNode(self, service_s, nodeIdentifier, profile_key):
2218
6a2fa651d7fa plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents: 2206
diff changeset
582 client = self.host.getClient(profile_key)
6a2fa651d7fa plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents: 2206
diff changeset
583 return self.deleteNode(client, jid.JID(service_s) if service_s else None, nodeIdentifier)
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
584
2218
6a2fa651d7fa plugin XEP-0060: node create/delete improvments:
Goffi <goffi@goffi.org>
parents: 2206
diff changeset
585 def deleteNode(self, client, service, nodeIdentifier):
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
586 return client.pubsub_client.deleteNode(service, nodeIdentifier)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
587
2444
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
588 def _addWatch(self, service_s, node, profile_key):
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
589 """watch modifications on a node
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
590
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
591 This method should only be called from bridge
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
592 """
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
593 client = self.host.getClient(profile_key)
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
594 service = jid.JID(service_s) if service_s else client.jid.userhostJID()
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
595 client.pubsub_watching.add((service, node))
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
596
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
597 def _removeWatch(self, service_s, node, profile_key):
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
598 """remove a node watch
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
599
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
600 This method should only be called from bridge
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
601 """
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
602 client = self.host.getClient(profile_key)
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
603 service = jid.JID(service_s) if service_s else client.jid.userhostJID()
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
604 client.pubsub_watching.remove((service, node))
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
605
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
606 def _retractItem(self, service_s, nodeIdentifier, itemIdentifier, notify, profile_key):
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
607 return self._retractItems(service_s, nodeIdentifier, (itemIdentifier,), notify, profile_key)
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
608
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
609 def _retractItems(self, service_s, nodeIdentifier, itemIdentifiers, notify, profile_key):
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
610 return self.retractItems(jid.JID(service_s) if service_s else None, nodeIdentifier, itemIdentifiers, notify, profile_key)
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
611
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
612 def retractItems(self, service, nodeIdentifier, itemIdentifiers, notify=True, profile_key=C.PROF_KEY_NONE):
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
613 client = self.host.getClient(profile_key)
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
614 return client.pubsub_client.retractItems(service, nodeIdentifier, itemIdentifiers, notify=True)
745
812dc38c0094 plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 704
diff changeset
615
2442
b8ffb7f8056b plugin XEP-0060: added "options" argument to psSubscribe, and return subscription id if present
Goffi <goffi@goffi.org>
parents: 2432
diff changeset
616 def _subscribe(self, service, nodeIdentifier, options, profile_key=C.PROF_KEY_NONE):
2352
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
617 client = self.host.getClient(profile_key)
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
618 service = None if not service else jid.JID(service)
2442
b8ffb7f8056b plugin XEP-0060: added "options" argument to psSubscribe, and return subscription id if present
Goffi <goffi@goffi.org>
parents: 2432
diff changeset
619 d = self.subscribe(client, service, nodeIdentifier, options=options or None)
b8ffb7f8056b plugin XEP-0060: added "options" argument to psSubscribe, and return subscription id if present
Goffi <goffi@goffi.org>
parents: 2432
diff changeset
620 d.addCallback(lambda subscription: subscription.subscriptionIdentifier or u'')
b8ffb7f8056b plugin XEP-0060: added "options" argument to psSubscribe, and return subscription id if present
Goffi <goffi@goffi.org>
parents: 2432
diff changeset
621 return d
2352
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
622
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
623 def subscribe(self, client, service, nodeIdentifier, sub_jid=None, options=None):
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
624 # TODO: reimplement a subscribtion cache, checking that we have not subscription before trying to subscribe
2352
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
625 return client.pubsub_client.subscribe(service, nodeIdentifier, sub_jid or client.jid.userhostJID(), options=options)
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
626
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
627 def _unsubscribe(self, service, nodeIdentifier, profile_key=C.PROF_KEY_NONE):
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
628 client = self.host.getClient(profile_key)
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
629 service = None if not service else jid.JID(service)
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
630 return self.unsubscribe(client, service, nodeIdentifier)
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
631
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
632 def unsubscribe(self, client, service, nodeIdentifier, sub_jid=None, subscriptionIdentifier=None, sender=None):
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
633 return client.pubsub_client.unsubscribe(service, nodeIdentifier, sub_jid or client.jid.userhostJID(), subscriptionIdentifier, sender)
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
634
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
635 def _subscriptions(self, service, nodeIdentifier='', profile_key=C.PROF_KEY_NONE):
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
636 client = self.host.getClient(profile_key)
2352
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
637 service = None if not service else jid.JID(service)
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
638
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
639 def gotSubscriptions(subscriptions):
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
640 # we replace pubsub.Subscription instance by dict that we can serialize
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
641 for idx, sub in enumerate(subscriptions):
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
642 sub_dict = {'node': sub.nodeIdentifier,
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
643 'subscriber': sub.subscriber.full(),
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
644 'state': sub.state
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
645 }
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
646 if sub.subscriptionIdentifier is not None:
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
647 sub_dict['id'] = sub.subscriptionIdentifier
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
648 subscriptions[idx] = sub_dict
303
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
649
2352
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
650 return subscriptions
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
651
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
652 d = self.subscriptions(client, service, nodeIdentifier or None)
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
653 d.addCallback(gotSubscriptions)
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
654 return d
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
655
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
656 def subscriptions(self, client, service, nodeIdentifier=None):
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
657 """retrieve subscriptions from a service
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
658
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
659 @param service(jid.JID): PubSub service
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
660 @param nodeIdentifier(unicode, None): node to check
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
661 None to get all subscriptions
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
662 """
1420
7c0acb966fd6 plugins groupblog, xep-0060: first pass of simplification
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
663 return client.pubsub_client.subscriptions(service, nodeIdentifier)
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
664
1829
6079752ffeae plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents: 1778
diff changeset
665 ## misc tools ##
6079752ffeae plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents: 1778
diff changeset
666
6079752ffeae plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents: 1778
diff changeset
667 def getNodeURI(self, service, node, item=None):
6079752ffeae plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents: 1778
diff changeset
668 """Return XMPP URI of a PubSub node
6079752ffeae plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents: 1778
diff changeset
669
2352
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
670 @param service(jid.JID): PubSub service
1829
6079752ffeae plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents: 1778
diff changeset
671 @param node(unicode): node
6079752ffeae plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents: 1778
diff changeset
672 @return (unicode): URI of the node
6079752ffeae plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents: 1778
diff changeset
673 """
1904
614f3abb2c69 plugin XEP-0060: fixed traceback if service was None
Goffi <goffi@goffi.org>
parents: 1903
diff changeset
674 assert service is not None
1854
3c0bb714a80b plugin XEP-0060: fixed bad xmpp: URI generation in getNodeURI
Goffi <goffi@goffi.org>
parents: 1829
diff changeset
675 # XXX: urllib.urlencode use "&" to separate value, while XMPP URL (cf. RFC 5122)
3c0bb714a80b plugin XEP-0060: fixed bad xmpp: URI generation in getNodeURI
Goffi <goffi@goffi.org>
parents: 1829
diff changeset
676 # use ";" as a separator. So if more than one value is used in query_data,
3c0bb714a80b plugin XEP-0060: fixed bad xmpp: URI generation in getNodeURI
Goffi <goffi@goffi.org>
parents: 1829
diff changeset
677 # urlencode MUST NOT BE USED.
1829
6079752ffeae plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents: 1778
diff changeset
678 query_data = [('node', node.encode('utf-8'))]
6079752ffeae plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents: 1778
diff changeset
679 if item is not None:
6079752ffeae plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents: 1778
diff changeset
680 query_data.append(('item', item.encode('utf-8')))
1854
3c0bb714a80b plugin XEP-0060: fixed bad xmpp: URI generation in getNodeURI
Goffi <goffi@goffi.org>
parents: 1829
diff changeset
681 return "xmpp:{service}?;{query}".format(
1829
6079752ffeae plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents: 1778
diff changeset
682 service=service.userhost(),
6079752ffeae plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents: 1778
diff changeset
683 query=urllib.urlencode(query_data)
6079752ffeae plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents: 1778
diff changeset
684 ).decode('utf-8')
6079752ffeae plugin XEP-0060, XEP-0277: added getNodeURI method
Goffi <goffi@goffi.org>
parents: 1778
diff changeset
685
1449
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
686 ## methods to manage several stanzas/jids at once ##
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
687
1452
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
688 # generic #
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
689
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
690 def getRTResults(self, session_id, on_success=None, on_error=None, profile=C.PROF_KEY_NONE):
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
691 return self.rt_sessions.getResults(session_id, on_success, on_error, profile)
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
692
1451
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
693 def serItemsData(self, items_data, item_cb=lambda item: item.toXml()):
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
694 """Helper method to serialise result from [getItems]
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
695
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
696 the items_data must be a tuple(list[domish.Element], dict[unicode, unicode])
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
697 as returned by [getItems]. metadata values are then casted to unicode and
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
698 each item is passed to items_cb
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
699 @param items_data(tuple): tuple returned by [getItems]
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
700 @param item_cb(callable): method to transform each item
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
701 @return (tuple): a serialised form ready to go throught bridge
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
702 """
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
703 items, metadata = items_data
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
704 return [item_cb(item) for item in items], {key: unicode(value) for key, value in metadata.iteritems()}
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
705
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
706 def serItemsDataD(self, items_data, item_cb):
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
707 """Helper method to serialise result from [getItems], deferred version
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
708
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
709 the items_data must be a tuple(list[domish.Element], dict[unicode, unicode])
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
710 as returned by [getItems]. metadata values are then casted to unicode and
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
711 each item is passed to items_cb
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
712 An errback is added to item_cb, and when it is fired the value is filtered from final items
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
713 @param items_data(tuple): tuple returned by [getItems]
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
714 @param item_cb(callable): method to transform each item (must return a deferred)
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
715 @return (tuple): a deferred which fire a serialised form ready to go throught bridge
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
716 """
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
717 items, metadata = items_data
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
718 def eb(failure):
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
719 log.warning("Error while serialising/parsing item: {}".format(unicode(failure.value)))
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
720 d = defer.gatherResults([item_cb(item).addErrback(eb) for item in items])
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
721 def finishSerialisation(serialised_items):
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
722 return [item for item in serialised_items if item is not None], {key: unicode(value) for key, value in metadata.iteritems()}
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
723 d.addCallback(finishSerialisation)
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
724 return d
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
725
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
726 def serDList(self, results, failure_result=None):
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
727 """Serialise a DeferredList result
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
728
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
729 @param results: DeferredList results
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
730 @param failure_result: value to use as value for failed Deferred
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
731 (default: empty tuple)
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
732 @return (list): list with:
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
733 - failure: empty in case of success, else error message
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
734 - result
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
735 """
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
736 if failure_result is None:
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
737 failure_result = ()
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
738 return [('', result) if success else (unicode(result.result) or UNSPECIFIED, failure_result) for success, result in results]
9b88b19b1ca8 plugins xep-0060, xep-0277: added methods to serialise getItems result (before bridge transmission):
Goffi <goffi@goffi.org>
parents: 1449
diff changeset
739
1449
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
740 # subscribe #
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
741
2338
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
742 def _getNodeSubscriptions(self, service_s, nodeIdentifier, profile_key):
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
743 client = self.host.getClient(profile_key)
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
744 d = self.getNodeSubscriptions(client, jid.JID(service_s) if service_s else None, nodeIdentifier)
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
745 d.addCallback(lambda subscriptions: {j.full(): a for j, a in subscriptions.iteritems()})
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
746 return d
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
747
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
748 def getNodeSubscriptions(self, client, service, nodeIdentifier):
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
749 """Retrieve subscriptions to a node
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
750
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
751 @param nodeIdentifier(unicode): node to get subscriptions from
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
752 """
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
753 if not nodeIdentifier:
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
754 raise exceptions.DataError("node identifier can't be empty")
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
755 request = pubsub.PubSubRequest('subscriptionsGet')
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
756 request.recipient = service
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
757 request.nodeIdentifier = nodeIdentifier
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
758
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
759 def cb(iq_elt):
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
760 try:
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
761 subscriptions_elt = next(iq_elt.pubsub.elements((pubsub.NS_PUBSUB, 'subscriptions')))
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
762 except StopIteration:
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
763 raise ValueError(_(u"Invalid result: missing <subscriptions> element: {}").format(iq_elt.toXml))
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
764 except AttributeError as e:
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
765 raise ValueError(_(u"Invalid result: {}").format(e))
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
766 try:
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
767 return {jid.JID(s['jid']): s['subscription'] for s in subscriptions_elt.elements((pubsub.NS_PUBSUB, 'subscription'))}
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
768 except KeyError:
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
769 raise ValueError(_(u"Invalid result: bad <subscription> element: {}").format(iq_elt.toXml))
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
770
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
771 d = request.send(client.xmlstream)
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
772 d.addCallback(cb)
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
773 return d
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
774
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
775 def _setNodeSubscriptions(self, service_s, nodeIdentifier, subscriptions, profile_key=C.PROF_KEY_NONE):
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
776 client = self.host.getClient(profile_key)
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
777 subscriptions = {jid.JID(jid_): subscription for jid_, subscription in subscriptions.iteritems()}
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
778 d = self.setNodeSubscriptions(client, jid.JID(service_s) if service_s else None, nodeIdentifier, subscriptions)
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
779 return d
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
780
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
781 def setNodeSubscriptions(self, client, service, nodeIdentifier, subscriptions):
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
782 """Set or update subscriptions of a node owned by profile
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
783
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
784 @param subscriptions(dict[jid.JID, unicode]): subscriptions to set
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
785 check https://xmpp.org/extensions/xep-0060.html#substates for a list of possible subscriptions
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
786 """
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
787 request = pubsub.PubSubRequest('subscriptionsSet')
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
788 request.recipient = service
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
789 request.nodeIdentifier = nodeIdentifier
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
790 request.subscriptions = {pubsub.Subscription(nodeIdentifier, jid_, state) for jid_, state in subscriptions.iteritems()}
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
791 d = request.send(client.xmlstream)
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
792 return d
b1bbd2994ceb plugin XEP-0060: implemented subscriptions management method for node owner:
Goffi <goffi@goffi.org>
parents: 2319
diff changeset
793
1449
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
794 def _manySubscribeRTResult(self, session_id, profile_key=C.PROF_KEY_DEFAULT):
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
795 """Get real-time results for subcribeToManu session
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
796
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
797 @param session_id: id of the real-time deferred session
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
798 @param return (tuple): (remaining, results) where:
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
799 - remaining is the number of still expected results
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
800 - results is a list of tuple(unicode, unicode, bool, unicode) with:
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
801 - service: pubsub service
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
802 - and node: pubsub node
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
803 - failure(unicode): empty string in case of success, error message else
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
804 @param profile_key: %(doc_profile_key)s
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
805 """
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
806 profile = self.host.getClient(profile_key).profile
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
807 d = self.rt_sessions.getResults(session_id, on_success=lambda result:'', on_error=lambda failure:unicode(failure.value), profile=profile)
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
808 # we need to convert jid.JID to unicode with full() to serialise it for the bridge
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
809 d.addCallback(lambda ret: (ret[0], [(service.full(), node, '' if success else failure or UNSPECIFIED)
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
810 for (service, node), (success, failure) in ret[1].iteritems()]))
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
811 return d
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
812
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
813 def _subscribeToMany(self, node_data, subscriber=None, options=None, profile_key=C.PROF_KEY_NONE):
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
814 return self.subscribeToMany([(jid.JID(service), unicode(node)) for service, node in node_data], jid.JID(subscriber), options, profile_key)
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
815
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
816 def subscribeToMany(self, node_data, subscriber, options=None, profile_key=C.PROF_KEY_NONE):
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
817 """Subscribe to several nodes at once.
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
818
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
819 @param node_data (iterable[tuple]): iterable of tuple (service, node) where:
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
820 - service (jid.JID) is the pubsub service
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
821 - node (unicode) is the node to subscribe to
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
822 @param subscriber (jid.JID): optional subscription identifier.
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
823 @param options (dict): subscription options
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
824 @param profile_key (str): %(doc_profile_key)s
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
825 @return (str): RT Deferred session id
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
826 """
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
827 client = self.host.getClient(profile_key)
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
828 deferreds = {}
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
829 for service, node in node_data:
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
830 deferreds[(service, node)] = client.pubsub_client.subscribe(service, node, subscriber, options=options)
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
831 return self.rt_sessions.newSession(deferreds, client.profile)
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
832 # found_nodes = yield self.listNodes(service, profile=client.profile)
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
833 # subscribed_nodes = yield self.listSubscribedNodes(service, profile=client.profile)
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
834 # d_list = []
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
835 # for nodeIdentifier in (set(nodeIdentifiers) - set(subscribed_nodes)):
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
836 # if nodeIdentifier not in found_nodes:
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
837 # log.debug(u"Skip the subscription to [{node}]: node doesn't exist".format(node=nodeIdentifier))
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
838 # continue # avoid sat-pubsub "SubscriptionExists" error
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
839 # d_list.append(client.pubsub_client.subscribe(service, nodeIdentifier, sub_jid or client.pubsub_client.parent.jid.userhostJID(), options=options))
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
840 # defer.returnValue(d_list)
389357fd79ce plugin XEP-0060: use of new RTDeferredSession to subscribe many nodes at once + subscribeToMany can now subscribe on separate services
Goffi <goffi@goffi.org>
parents: 1446
diff changeset
841
1452
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
842 # get #
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
843
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
844 def _getFromManyRTResult(self, session_id, profile_key=C.PROF_KEY_DEFAULT):
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
845 """Get real-time results for getFromMany session
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
846
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
847 @param session_id: id of the real-time deferred session
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
848 @param profile_key: %(doc_profile_key)s
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
849 @param return (tuple): (remaining, results) where:
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
850 - remaining is the number of still expected results
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
851 - results is a list of tuple with
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
852 - service (unicode): pubsub service
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
853 - node (unicode): pubsub node
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
854 - failure (unicode): empty string in case of success, error message else
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
855 - items (list[s]): raw XML of items
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
856 - metadata(dict): serialised metadata
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
857 """
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
858 profile = self.host.getClient(profile_key).profile
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
859 d = self.rt_sessions.getResults(session_id,
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
860 on_success=lambda result: ('', self.serItemsData(result)),
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
861 on_error=lambda failure: (unicode(failure.value) or UNSPECIFIED, ([],{})),
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
862 profile=profile)
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
863 d.addCallback(lambda ret: (ret[0],
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
864 [(service.full(), node, failure, items, metadata)
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
865 for (service, node), (success, (failure, (items, metadata))) in ret[1].iteritems()]))
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
866 return d
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
867
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
868 def _getFromMany(self, node_data, max_item=10, extra_dict=None, profile_key=C.PROF_KEY_NONE):
1452
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
869 """
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
870 @param max_item(int): maximum number of item to get, C.NO_LIMIT for no limit
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
871 """
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
872 max_item = None if max_item == C.NO_LIMIT else max_item
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
873 extra = self.parseExtra(extra_dict)
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
874 return self.getFromMany([(jid.JID(service), unicode(node)) for service, node in node_data], max_item, extra.rsm_request, extra.extra, profile_key)
1452
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
875
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
876 def getFromMany(self, node_data, max_item=None, rsm_request=None, extra=None, profile_key=C.PROF_KEY_NONE):
1452
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
877 """Get items from many nodes at once
2203
427391c706eb plugin XEP-0060: added affiliation handling:
Goffi <goffi@goffi.org>
parents: 2201
diff changeset
878
1452
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
879 @param node_data (iterable[tuple]): iterable of tuple (service, node) where:
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
880 - service (jid.JID) is the pubsub service
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
881 - node (unicode) is the node to get items from
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
882 @param max_items (int): optional limit on the number of retrieved items.
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
883 @param rsm_request (RSMRequest): RSM request data
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
884 @param profile_key (unicode): %(doc_profile_key)s
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
885 @return (str): RT Deferred session id
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
886 """
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
887 client = self.host.getClient(profile_key)
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
888 deferreds = {}
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
889 for service, node in node_data:
2360
72cbb6478f97 plugin XEP-0060: use client instead of profile_key in getItems
Goffi <goffi@goffi.org>
parents: 2352
diff changeset
890 deferreds[(service, node)] = self.getItems(client, service, node, max_item, rsm_request=rsm_request, extra=extra)
1452
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
891 return self.rt_sessions.newSession(deferreds, client.profile)
5116d70ddd1c plugin xep-0060,xep-0277: added getFromMany using new RTDeferredSession mechanism
Goffi <goffi@goffi.org>
parents: 1451
diff changeset
892
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
893
1267
ea692d51a0ee plugins XEP-0059, XEP-0060: leave internal wokkel extensions to sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents: 1261
diff changeset
894 class SatPubSubClient(rsm.PubSubClient):
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
895 implements(disco.IDisco)
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
896
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
897 def __init__(self, host, parent_plugin):
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
898 self.host = host
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
899 self.parent_plugin = parent_plugin
1267
ea692d51a0ee plugins XEP-0059, XEP-0060: leave internal wokkel extensions to sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents: 1261
diff changeset
900 rsm.PubSubClient.__init__(self)
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
901
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
902 def connectionInitialized(self):
1267
ea692d51a0ee plugins XEP-0059, XEP-0060: leave internal wokkel extensions to sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents: 1261
diff changeset
903 rsm.PubSubClient.connectionInitialized(self)
745
812dc38c0094 plugins groupblog (xep-0060, xep-0277): added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 704
diff changeset
904
1760
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
905 def _getNodeCallbacks(self, node, event):
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
906 """Generate callbacks from given node and event
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
907
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
908 @param node(unicode): node used for the item
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
909 any registered node which prefix the node will match
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
910 @param event(unicode): one of C.PS_ITEMS, C.PS_RETRACT, C.PS_DELETE
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
911 @return (iterator[callable]): callbacks for this node/event
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
912 """
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
913 for registered_node, callbacks_dict in self.parent_plugin._node_cb.iteritems():
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
914 if not node.startswith(registered_node):
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
915 continue
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
916 try:
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
917 for callback in callbacks_dict[event]:
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
918 yield callback
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
919 except KeyError:
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
920 continue
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
921
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
922 def itemsReceived(self, event):
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
923 log.debug(u"Pubsub items received")
1760
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
924 for callback in self._getNodeCallbacks(event.nodeIdentifier, C.PS_ITEMS):
2305
972e33507609 plugin XEP-0060: addManagedNode callbacks now use client syntax instead of profile
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
925 callback(self.parent, event)
2444
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
926 client = self.parent
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
927 if (event.sender, event.nodeIdentifier) in client.pubsub_watching:
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
928 raw_items = [i.toXml() for i in event.items]
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
929 self.host.bridge.psEventRaw(event.sender.full(), event.nodeIdentifier, C.PS_ITEMS, raw_items, client.profile)
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
930
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
931 def deleteReceived(self, event):
1459
4c4f88d7b156 plugins xep-0060, xep-0163, xep-0277, groupblog: bloging improvments (huge patch, sorry):
Goffi <goffi@goffi.org>
parents: 1452
diff changeset
932 log.debug((u"Publish node deleted"))
1760
30efe084471c plugin XEP-0060: None is no more used in addManagedNode, but all nodes prefixed with a registered one are now triggered
Goffi <goffi@goffi.org>
parents: 1678
diff changeset
933 for callback in self._getNodeCallbacks(event.nodeIdentifier, C.PS_DELETE):
2305
972e33507609 plugin XEP-0060: addManagedNode callbacks now use client syntax instead of profile
Goffi <goffi@goffi.org>
parents: 2272
diff changeset
934 callback(self.parent, event)
2444
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
935 client = self.parent
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
936 if (event.sender, event.nodeIdentifier) in client.pubsub_watching:
30278ea1ca7c plugin XEP-0060: added node watching methods to bridge:
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
937 self.host.bridge.psEventRaw(event.sender.full(), event.nodeIdentifier, C.PS_DELETE, [], client.profile)
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
938
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
939 def subscriptions(self, service, nodeIdentifier, sender=None):
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
940 """Return the list of subscriptions to the given service and node.
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
941
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
942 @param service: The publish subscribe service to retrieve the subscriptions from.
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
943 @type service: L{JID<twisted.words.protocols.jabber.jid.JID>}
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
944 @param nodeIdentifier: The identifier of the node (leave empty to retrieve all subscriptions).
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
945 @type nodeIdentifier: C{unicode}
2352
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
946 @return (list[pubsub.Subscription]): list of subscriptions
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
947 """
1267
ea692d51a0ee plugins XEP-0059, XEP-0060: leave internal wokkel extensions to sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents: 1261
diff changeset
948 request = pubsub.PubSubRequest('subscriptions')
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
949 request.recipient = service
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
950 request.nodeIdentifier = nodeIdentifier
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
951 request.sender = sender
1267
ea692d51a0ee plugins XEP-0059, XEP-0060: leave internal wokkel extensions to sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents: 1261
diff changeset
952 d = request.send(self.xmlstream)
ea692d51a0ee plugins XEP-0059, XEP-0060: leave internal wokkel extensions to sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents: 1261
diff changeset
953
ea692d51a0ee plugins XEP-0059, XEP-0060: leave internal wokkel extensions to sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents: 1261
diff changeset
954 def cb(iq):
2352
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
955 subs = []
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
956 for subscription_elt in iq.pubsub.subscriptions.elements(pubsub.NS_PUBSUB, 'subscription'):
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
957 subscription = pubsub.Subscription(subscription_elt['node'],
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
958 jid.JID(subscription_elt['jid']),
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
959 subscription_elt['subscription'],
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
960 subscriptionIdentifier=subscription_elt.getAttribute('subid'))
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
961 subs.append(subscription)
6c26f435a02d plugin XEP-0060: added/fixed subscribe/unsubscribe and subscriptions methods/bridge methods:
Goffi <goffi@goffi.org>
parents: 2338
diff changeset
962 return subs
1267
ea692d51a0ee plugins XEP-0059, XEP-0060: leave internal wokkel extensions to sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents: 1261
diff changeset
963
ea692d51a0ee plugins XEP-0059, XEP-0060: leave internal wokkel extensions to sat.tmp.wokkel
souliane <souliane@mailoo.org>
parents: 1261
diff changeset
964 return d.addCallback(cb)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
965
1217
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
966 def getDiscoInfo(self, requestor, service, nodeIdentifier=''):
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
967 disco_info = []
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
968 self.host.trigger.point("PubSub Disco Info", disco_info, self.parent.profile)
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
969 return disco_info
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
970
318eab3f93f8 plugin XEP-0060, groupblog: avoid unecessary pubsub errors while doing massive requests:
souliane <souliane@mailoo.org>
parents: 993
diff changeset
971 def getDiscoItems(self, requestor, service, nodeIdentifier=''):
1259
633fcd13a7dc plugin pubsub: fixed a bug introducted in revision 318eab3f93f8: getDiscoItems handler method which is called on disco items request, was calling getDiscoItems from host, which do a request itself, resulting in an infinite items request loop.
Goffi <goffi@goffi.org>
parents: 1246
diff changeset
972 return []