annotate src/plugins/plugin_exp_pipe.py @ 1723:5632c5350296

core: avoid initialisation blocking when a long callback is added to backend.initialised (could prevent sessions starting)
author Goffi <goffi@goffi.org>
date Mon, 07 Dec 2015 13:10:44 +0100
parents dbd7c79aab2b
children d17772b0fe22
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
401
b2caa2615c4c jp roster name manegement + Pipe transfer
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
b2caa2615c4c jp roster name manegement + Pipe transfer
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
b2caa2615c4c jp roster name manegement + Pipe transfer
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 managing pipes (experimental)
1396
069ad98b360d 2015 copyright dates update
Goffi <goffi@goffi.org>
parents: 993
diff changeset
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Jérôme Poisson (goffi@goffi.org)
401
b2caa2615c4c jp roster name manegement + Pipe transfer
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.
401
b2caa2615c4c jp roster name manegement + Pipe transfer
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.
401
b2caa2615c4c jp roster name manegement + Pipe transfer
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/>.
401
b2caa2615c4c jp roster name manegement + Pipe transfer
Goffi <goffi@goffi.org>
parents:
diff changeset
19
1669
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
20 from sat.core.i18n import _, D_
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 811
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: 941
diff changeset
22 from sat.core.log import getLogger
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 941
diff changeset
23 log = getLogger(__name__)
1669
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
24 from sat.tools import xml_tools
401
b2caa2615c4c jp roster name manegement + Pipe transfer
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from twisted.words.xish import domish
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 480
diff changeset
26 from twisted.words.protocols.jabber import jid
1669
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
27 from twisted.internet import defer
401
b2caa2615c4c jp roster name manegement + Pipe transfer
Goffi <goffi@goffi.org>
parents:
diff changeset
28
1672
dbd7c79aab2b plugin group blog: big cleaning
Goffi <goffi@goffi.org>
parents: 1669
diff changeset
29 NS_PIPE = 'http://salut-a-toi.org/protocol/pipe'
1669
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
30 SECURITY_LIMIT=30
401
b2caa2615c4c jp roster name manegement + Pipe transfer
Goffi <goffi@goffi.org>
parents:
diff changeset
31
b2caa2615c4c jp roster name manegement + Pipe transfer
Goffi <goffi@goffi.org>
parents:
diff changeset
32 PLUGIN_INFO = {
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
33 "name": "Pipe Plugin",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
34 "import_name": "EXP-PIPE",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
35 "type": "EXP",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
36 "protocols": ["EXP-PIPE"],
1669
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
37 "dependencies": ["XEP-0166"],
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
38 "main": "Exp_Pipe",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
39 "handler": "no",
1669
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
40 "description": _("""Jingle Pipe Transfer experimental plugin""")
401
b2caa2615c4c jp roster name manegement + Pipe transfer
Goffi <goffi@goffi.org>
parents:
diff changeset
41 }
b2caa2615c4c jp roster name manegement + Pipe transfer
Goffi <goffi@goffi.org>
parents:
diff changeset
42
1669
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
43 CONFIRM = D_(u"{peer} wants to send you a pipe stream, do you accept ?")
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
44 CONFIRM_TITLE = D_(u"Pipe stream")
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
45
588
beaf6bec2fcd Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
46 class Exp_Pipe(object):
1669
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
47 """This non standard jingle application works with named pipes"""
401
b2caa2615c4c jp roster name manegement + Pipe transfer
Goffi <goffi@goffi.org>
parents:
diff changeset
48
b2caa2615c4c jp roster name manegement + Pipe transfer
Goffi <goffi@goffi.org>
parents:
diff changeset
49 def __init__(self, host):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 941
diff changeset
50 log.info(_("Plugin Pipe initialization"))
401
b2caa2615c4c jp roster name manegement + Pipe transfer
Goffi <goffi@goffi.org>
parents:
diff changeset
51 self.host = host
1669
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
52 self._j = host.plugins["XEP-0166"] # shortcut to access jingle
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
53 self._j.registerApplication(NS_PIPE, self)
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
54 host.bridge.addMethod("pipeOut", ".plugin", in_sign='sss', out_sign='', method=self._pipeOut)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
55
1669
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
56 # jingle callbacks
401
b2caa2615c4c jp roster name manegement + Pipe transfer
Goffi <goffi@goffi.org>
parents:
diff changeset
57
1669
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
58 def _pipeOut(self, peer_jid_s, filepath, profile_key=C.PROF_KEY_NONE):
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
59 profile = self.host.memory.getProfileName(profile_key)
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
60 self.pipeOut(jid.JID(peer_jid_s), filepath, profile)
401
b2caa2615c4c jp roster name manegement + Pipe transfer
Goffi <goffi@goffi.org>
parents:
diff changeset
61
1669
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
62 def pipeOut(self, peer_jid, filepath, profile):
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
63 """send a file using EXP-PIPE
401
b2caa2615c4c jp roster name manegement + Pipe transfer
Goffi <goffi@goffi.org>
parents:
diff changeset
64
1669
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
65 @param peer_jid(jid.JID): recipient
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
66 @param filepath(unicode): absolute path to the named pipe to send
401
b2caa2615c4c jp roster name manegement + Pipe transfer
Goffi <goffi@goffi.org>
parents:
diff changeset
67 @param profile_key: %(doc_profile_key)s
b2caa2615c4c jp roster name manegement + Pipe transfer
Goffi <goffi@goffi.org>
parents:
diff changeset
68 @return: an unique id to identify the transfer
b2caa2615c4c jp roster name manegement + Pipe transfer
Goffi <goffi@goffi.org>
parents:
diff changeset
69 """
1669
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
70 self._j.initiate(peer_jid,
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
71 [{'app_ns': NS_PIPE,
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
72 'senders': self._j.ROLE_INITIATOR,
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
73 'app_kwargs': {'filepath': filepath,
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
74 },
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
75 }],
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
76 profile=profile)
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
77
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
78 def jingleSessionInit(self, session, content_name, filepath, profile=C.PROF_KEY_NONE):
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
79 content_data = session['contents'][content_name]
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
80 application_data = content_data['application_data']
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
81 assert 'file_path' not in application_data
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
82 application_data['file_path'] = filepath
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
83 desc_elt = domish.Element((NS_PIPE, 'description'))
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
84 return desc_elt
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
85
1669
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
86 def jingleRequestConfirmation(self, action, session, content_name, desc_elt, profile):
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
87 """This method request confirmation for a jingle session"""
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
88 content_data = session['contents'][content_name]
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
89 if content_data['senders'] not in (self._j.ROLE_INITIATOR, self._j.ROLE_RESPONDER):
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
90 log.warning(u"Bad sender, assuming initiator")
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
91 content_data['senders'] = self._j.ROLE_INITIATOR
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
92
1669
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
93 def gotConfirmation(data):
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
94 if data.get('cancelled', False):
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
95 return False
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
96 application_data = content_data['application_data']
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
97 dest_path = application_data['file_path'] = data['path']
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
98 content_data['file_obj'] = open(dest_path, 'w+')
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
99 finished_d = content_data['finished_d'] = defer.Deferred()
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
100 args = [session, content_name, content_data, profile]
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
101 finished_d.addCallbacks(self._finishedCb, self._finishedEb, args, None, args)
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
102 return True
401
b2caa2615c4c jp roster name manegement + Pipe transfer
Goffi <goffi@goffi.org>
parents:
diff changeset
103
1669
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
104 d = xml_tools.deferDialog(self.host,
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
105 _(CONFIRM).format(peer=session['peer_jid'].full()),
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
106 _(CONFIRM_TITLE),
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
107 type_=C.XMLUI_DIALOG_FILE,
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
108 options={C.XMLUI_DATA_FILETYPE: C.XMLUI_DATA_FILETYPE_DIR},
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
109 action_extra={'meta_from_jid': session['peer_jid'].full(),
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
110 'meta_type': "PIPE",
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
111 },
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
112 security_limit=SECURITY_LIMIT,
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
113 profile=profile)
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
114
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
115 d.addCallback(gotConfirmation)
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
116 return d
401
b2caa2615c4c jp roster name manegement + Pipe transfer
Goffi <goffi@goffi.org>
parents:
diff changeset
117
1669
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
118 def jingleHandler(self, action, session, content_name, desc_elt, profile):
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
119 content_data = session['contents'][content_name]
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
120 application_data = content_data['application_data']
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
121 if action in (self._j.A_ACCEPTED_ACK, self._j.A_SESSION_INITIATE):
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
122 pass
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
123 elif action == self._j.A_SESSION_ACCEPT:
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
124 assert not 'file_obj' in content_data
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
125 filepath = application_data['file_path']
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
126 content_data['file_obj'] = open(filepath, 'r') # XXX: we have to be sure that filepath is well opened, as reading can block it
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
127 finished_d = content_data['finished_d'] = defer.Deferred()
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
128 args = [session, content_name, content_data, profile]
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
129 finished_d.addCallbacks(self._finishedCb, self._finishedEb, args, None, args)
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
130 else:
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
131 log.warning(u"FIXME: unmanaged action {}".format(action))
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
132 return desc_elt
401
b2caa2615c4c jp roster name manegement + Pipe transfer
Goffi <goffi@goffi.org>
parents:
diff changeset
133
1669
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
134 def _finishedCb(self, dummy, session, content_name, content_data, profile):
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
135 log.info(u"Pipe transfer completed")
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
136 self._j.contentTerminate(session, content_name, profile=profile)
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
137 content_data['file_obj'].close()
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
138
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
139 def _finishedEb(self, failure, session, content_name, content_data, profile):
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
140 log.warning(u"Error while streaming pipe: {}".format(failure))
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
141 content_data['file_obj'].close()
697effba0310 plugin pipe: rewritten plugin as a jingle application. The current implentation can, in some cases, block the backend, and is experimental only. Improvments are needed in the future.
Goffi <goffi@goffi.org>
parents: 1409
diff changeset
142 self._j.contentTerminate(session, content_name, reason=self._j.REASON_FAILED_TRANSPORT, profile=profile)