2006-05-26 16:27:42 +02:00
|
|
|
##
|
|
|
|
## Copyright (C) 2006 Gajim Team
|
|
|
|
##
|
|
|
|
## Contributors for this file:
|
2007-10-22 13:33:50 +02:00
|
|
|
## - Yann Leboulanger <asterix@lagaule.org>
|
2006-05-26 16:27:42 +02:00
|
|
|
## - Nikos Kouremenos <nkour@jabber.org>
|
|
|
|
## - Dimitur Kirov <dkirov@gmail.com>
|
|
|
|
## - Travis Shirk <travis@pobox.com>
|
2007-01-28 20:11:39 +01:00
|
|
|
## - Stefan Bethge <stefan@lanpartei.de>
|
2006-05-26 16:27:42 +02:00
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## This file is part of Gajim.
|
|
|
|
##
|
|
|
|
## Gajim is free software; you can redistribute it and/or modify
|
2006-05-26 16:27:42 +02:00
|
|
|
## it under the terms of the GNU General Public License as published
|
2007-10-22 13:13:13 +02:00
|
|
|
## by the Free Software Foundation; version 3 only.
|
2006-05-26 16:27:42 +02:00
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## Gajim is distributed in the hope that it will be useful,
|
2006-05-26 16:27:42 +02:00
|
|
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
## GNU General Public License for more details.
|
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## You should have received a copy of the GNU General Public License
|
|
|
|
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
##
|
2006-05-26 16:27:42 +02:00
|
|
|
|
|
|
|
import time
|
|
|
|
import socket
|
|
|
|
|
|
|
|
from calendar import timegm
|
|
|
|
|
2006-11-20 22:02:15 +01:00
|
|
|
from common import socks5
|
2006-05-26 16:27:42 +02:00
|
|
|
import common.xmpp
|
|
|
|
|
|
|
|
from common import helpers
|
|
|
|
from common import gajim
|
2006-09-18 00:57:41 +02:00
|
|
|
from common.zeroconf import zeroconf
|
2008-05-17 04:23:46 +02:00
|
|
|
|
2006-05-26 16:27:42 +02:00
|
|
|
STATUS_LIST = ['offline', 'connecting', 'online', 'chat', 'away', 'xa', 'dnd',
|
|
|
|
'invisible']
|
|
|
|
# kind of events we can wait for an answer
|
|
|
|
VCARD_PUBLISHED = 'vcard_published'
|
|
|
|
VCARD_ARRIVED = 'vcard_arrived'
|
|
|
|
AGENT_REMOVED = 'agent_removed'
|
|
|
|
HAS_IDLE = True
|
|
|
|
try:
|
2006-11-08 14:23:38 +01:00
|
|
|
import idle
|
2008-10-11 11:37:13 +02:00
|
|
|
except Exception:
|
2006-11-08 14:23:38 +01:00
|
|
|
gajim.log.debug(_('Unable to load idle module'))
|
|
|
|
HAS_IDLE = False
|
2006-05-26 16:27:42 +02:00
|
|
|
|
2008-05-17 04:23:46 +02:00
|
|
|
from common import connection_handlers
|
|
|
|
from session import ChatControlSession
|
2007-10-09 05:46:51 +02:00
|
|
|
|
2008-05-17 04:23:46 +02:00
|
|
|
class ConnectionVcard(connection_handlers.ConnectionVcard):
|
|
|
|
def add_sha(self, p, send_caps = True):
|
|
|
|
pass
|
2006-11-23 16:17:24 +01:00
|
|
|
|
|
|
|
def add_caps(self, p):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def request_vcard(self, jid = None, is_fake_jid = False):
|
|
|
|
pass
|
2008-05-17 04:23:46 +02:00
|
|
|
|
2006-11-23 16:17:24 +01:00
|
|
|
def send_vcard(self, vcard):
|
|
|
|
pass
|
2006-09-21 01:24:07 +02:00
|
|
|
|
2008-05-17 04:23:46 +02:00
|
|
|
class ConnectionBytestream(connection_handlers.ConnectionBytestream):
|
2006-09-21 01:24:07 +02:00
|
|
|
def send_socks5_info(self, file_props, fast = True, receiver = None,
|
|
|
|
sender = None):
|
|
|
|
''' send iq for the present streamhosts and proxies '''
|
2008-10-11 11:59:52 +02:00
|
|
|
if not isinstance(self.peerhost, tuple):
|
2006-09-21 01:24:07 +02:00
|
|
|
return
|
|
|
|
port = gajim.config.get('file_transfers_port')
|
2007-01-28 20:11:39 +01:00
|
|
|
ft_add_hosts_to_send = gajim.config.get('ft_add_hosts_to_send')
|
2006-09-21 01:24:07 +02:00
|
|
|
if receiver is None:
|
|
|
|
receiver = file_props['receiver']
|
|
|
|
if sender is None:
|
|
|
|
sender = file_props['sender']
|
|
|
|
sha_str = helpers.get_auth_sha(file_props['sid'], sender,
|
|
|
|
receiver)
|
|
|
|
file_props['sha_str'] = sha_str
|
2007-01-28 20:11:39 +01:00
|
|
|
ft_add_hosts = []
|
|
|
|
if ft_add_hosts_to_send:
|
|
|
|
ft_add_hosts_to_send = map(lambda e:e.strip(),
|
|
|
|
ft_add_hosts_to_send.split(','))
|
|
|
|
for ft_host in ft_add_hosts_to_send:
|
|
|
|
try:
|
|
|
|
ft_host = socket.gethostbyname(ft_host)
|
|
|
|
ft_add_hosts.append(ft_host)
|
|
|
|
except socket.gaierror:
|
|
|
|
self.dispatch('ERROR', (_('Wrong host'), _('The host %s you configured as the ft_add_hosts_to_send advanced option is not valid, so ignored.') % ft_host))
|
2006-09-29 01:38:55 +02:00
|
|
|
listener = gajim.socks5queue.start_listener(port,
|
2006-09-21 01:24:07 +02:00
|
|
|
sha_str, self._result_socks5_sid, file_props['sid'])
|
2008-10-11 11:44:12 +02:00
|
|
|
if listener is None:
|
2006-09-21 01:24:07 +02:00
|
|
|
file_props['error'] = -5
|
|
|
|
self.dispatch('FILE_REQUEST_ERROR', (unicode(receiver), file_props,
|
|
|
|
''))
|
|
|
|
self._connect_error(unicode(receiver), file_props['sid'],
|
|
|
|
file_props['sid'], code = 406)
|
|
|
|
return
|
|
|
|
|
|
|
|
iq = common.xmpp.Protocol(name = 'iq', to = unicode(receiver),
|
|
|
|
typ = 'set')
|
|
|
|
file_props['request-id'] = 'id_' + file_props['sid']
|
|
|
|
iq.setID(file_props['request-id'])
|
|
|
|
query = iq.setTag('query')
|
|
|
|
query.setNamespace(common.xmpp.NS_BYTESTREAM)
|
|
|
|
query.setAttr('mode', 'tcp')
|
|
|
|
query.setAttr('sid', file_props['sid'])
|
2007-01-28 20:11:39 +01:00
|
|
|
for ft_host in ft_add_hosts:
|
|
|
|
# The streamhost, if set
|
|
|
|
ostreamhost = common.xmpp.Node(tag = 'streamhost')
|
|
|
|
query.addChild(node = ostreamhost)
|
|
|
|
ostreamhost.setAttr('port', unicode(port))
|
|
|
|
ostreamhost.setAttr('host', ft_host)
|
|
|
|
ostreamhost.setAttr('jid', sender)
|
|
|
|
for thehost in self.peerhost:
|
|
|
|
thehost = self.peerhost[0]
|
|
|
|
streamhost = common.xmpp.Node(tag = 'streamhost') # My IP
|
|
|
|
query.addChild(node = streamhost)
|
|
|
|
streamhost.setAttr('port', unicode(port))
|
|
|
|
streamhost.setAttr('host', thehost)
|
|
|
|
streamhost.setAttr('jid', sender)
|
2006-09-21 01:24:07 +02:00
|
|
|
self.connection.send(iq)
|
|
|
|
|
|
|
|
def send_file_request(self, file_props):
|
|
|
|
''' send iq for new FT request '''
|
|
|
|
if not self.connection or self.connected < 2:
|
|
|
|
return
|
|
|
|
our_jid = gajim.get_jid_from_account(self.name)
|
|
|
|
frm = our_jid
|
|
|
|
file_props['sender'] = frm
|
2008-05-17 04:23:46 +02:00
|
|
|
fjid = file_props['receiver'].jid
|
2006-09-21 01:24:07 +02:00
|
|
|
iq = common.xmpp.Protocol(name = 'iq', to = fjid,
|
|
|
|
typ = 'set')
|
|
|
|
iq.setID(file_props['sid'])
|
|
|
|
self.files_props[file_props['sid']] = file_props
|
|
|
|
si = iq.setTag('si')
|
|
|
|
si.setNamespace(common.xmpp.NS_SI)
|
|
|
|
si.setAttr('profile', common.xmpp.NS_FILE)
|
|
|
|
si.setAttr('id', file_props['sid'])
|
|
|
|
file_tag = si.setTag('file')
|
|
|
|
file_tag.setNamespace(common.xmpp.NS_FILE)
|
|
|
|
file_tag.setAttr('name', file_props['name'])
|
|
|
|
file_tag.setAttr('size', file_props['size'])
|
|
|
|
desc = file_tag.setTag('desc')
|
2008-10-07 22:41:59 +02:00
|
|
|
if 'desc' in file_props:
|
2006-09-21 01:24:07 +02:00
|
|
|
desc.setData(file_props['desc'])
|
|
|
|
file_tag.setTag('range')
|
|
|
|
feature = si.setTag('feature')
|
|
|
|
feature.setNamespace(common.xmpp.NS_FEATURE)
|
|
|
|
_feature = common.xmpp.DataForm(typ='form')
|
|
|
|
feature.addChild(node=_feature)
|
|
|
|
field = _feature.setField('stream-method')
|
|
|
|
field.setAttr('type', 'list-single')
|
|
|
|
field.addOption(common.xmpp.NS_BYTESTREAM)
|
|
|
|
self.connection.send(iq)
|
2008-05-17 04:23:46 +02:00
|
|
|
|
2006-09-21 01:24:07 +02:00
|
|
|
def _bytestreamSetCB(self, con, iq_obj):
|
|
|
|
gajim.log.debug('_bytestreamSetCB')
|
|
|
|
target = unicode(iq_obj.getAttr('to'))
|
2008-12-03 18:16:04 +01:00
|
|
|
id_ = unicode(iq_obj.getAttr('id'))
|
2006-09-21 01:24:07 +02:00
|
|
|
query = iq_obj.getTag('query')
|
|
|
|
sid = unicode(query.getAttr('sid'))
|
|
|
|
file_props = gajim.socks5queue.get_file_props(
|
|
|
|
self.name, sid)
|
|
|
|
streamhosts=[]
|
|
|
|
for item in query.getChildren():
|
|
|
|
if item.getName() == 'streamhost':
|
|
|
|
host_dict={
|
|
|
|
'state': 0,
|
|
|
|
'target': target,
|
2008-12-03 18:16:04 +01:00
|
|
|
'id': id_,
|
2006-09-21 01:24:07 +02:00
|
|
|
'sid': sid,
|
|
|
|
'initiator': unicode(iq_obj.getFrom())
|
|
|
|
}
|
|
|
|
for attr in item.getAttrs():
|
|
|
|
host_dict[attr] = item.getAttr(attr)
|
|
|
|
streamhosts.append(host_dict)
|
|
|
|
if file_props is None:
|
2008-10-07 22:41:59 +02:00
|
|
|
if sid in self.files_props:
|
2006-09-21 01:24:07 +02:00
|
|
|
file_props = self.files_props[sid]
|
|
|
|
file_props['fast'] = streamhosts
|
2008-05-17 04:23:46 +02:00
|
|
|
if file_props['type'] == 's':
|
2008-10-07 22:41:59 +02:00
|
|
|
if 'streamhosts' in file_props:
|
2006-09-21 01:24:07 +02:00
|
|
|
file_props['streamhosts'].extend(streamhosts)
|
|
|
|
else:
|
|
|
|
file_props['streamhosts'] = streamhosts
|
|
|
|
if not gajim.socks5queue.get_file_props(self.name, sid):
|
|
|
|
gajim.socks5queue.add_file_props(self.name, file_props)
|
|
|
|
gajim.socks5queue.connect_to_hosts(self.name, sid,
|
|
|
|
self.send_success_connect_reply, None)
|
|
|
|
raise common.xmpp.NodeProcessed
|
|
|
|
|
|
|
|
file_props['streamhosts'] = streamhosts
|
|
|
|
if file_props['type'] == 'r':
|
|
|
|
gajim.socks5queue.connect_to_hosts(self.name, sid,
|
|
|
|
self.send_success_connect_reply, self._connect_error)
|
|
|
|
raise common.xmpp.NodeProcessed
|
|
|
|
|
|
|
|
def _ResultCB(self, con, iq_obj):
|
|
|
|
gajim.log.debug('_ResultCB')
|
|
|
|
# if we want to respect jep-0065 we have to check for proxy
|
|
|
|
# activation result in any result iq
|
|
|
|
real_id = unicode(iq_obj.getAttr('id'))
|
2008-04-21 22:39:55 +02:00
|
|
|
if not real_id.startswith('au_'):
|
2006-09-21 01:24:07 +02:00
|
|
|
return
|
|
|
|
frm = unicode(iq_obj.getFrom())
|
2008-12-03 18:16:04 +01:00
|
|
|
id_ = real_id[3:]
|
|
|
|
if id_ in self.files_props:
|
|
|
|
file_props = self.files_props[id_]
|
2006-09-21 01:24:07 +02:00
|
|
|
if file_props['streamhost-used']:
|
|
|
|
for host in file_props['proxyhosts']:
|
2008-10-07 22:41:59 +02:00
|
|
|
if host['initiator'] == frm and 'idx' in host:
|
2006-09-21 01:24:07 +02:00
|
|
|
gajim.socks5queue.activate_proxy(host['idx'])
|
|
|
|
raise common.xmpp.NodeProcessed
|
2008-05-17 04:23:46 +02:00
|
|
|
|
2006-09-21 01:24:07 +02:00
|
|
|
def _bytestreamResultCB(self, con, iq_obj):
|
|
|
|
gajim.log.debug('_bytestreamResultCB')
|
|
|
|
frm = unicode(iq_obj.getFrom())
|
|
|
|
real_id = unicode(iq_obj.getAttr('id'))
|
|
|
|
query = iq_obj.getTag('query')
|
|
|
|
gajim.proxy65_manager.resolve_result(frm, query)
|
2008-05-17 04:23:46 +02:00
|
|
|
|
2006-09-21 01:24:07 +02:00
|
|
|
try:
|
|
|
|
streamhost = query.getTag('streamhost-used')
|
2008-10-11 11:37:13 +02:00
|
|
|
except Exception: # this bytestream result is not what we need
|
2006-09-21 01:24:07 +02:00
|
|
|
pass
|
2008-12-03 18:16:04 +01:00
|
|
|
id_ = real_id[3:]
|
|
|
|
if id_ in self.files_props:
|
|
|
|
file_props = self.files_props[id_]
|
2006-09-21 01:24:07 +02:00
|
|
|
else:
|
|
|
|
raise common.xmpp.NodeProcessed
|
|
|
|
if streamhost is None:
|
|
|
|
# proxy approves the activate query
|
2008-10-11 11:32:59 +02:00
|
|
|
if real_id.startswith('au_'):
|
2008-12-03 18:16:04 +01:00
|
|
|
id_ = real_id[3:]
|
2008-10-07 22:41:59 +02:00
|
|
|
if 'streamhost-used' not in file_props or \
|
2006-09-21 01:24:07 +02:00
|
|
|
file_props['streamhost-used'] is False:
|
|
|
|
raise common.xmpp.NodeProcessed
|
2008-10-07 22:41:59 +02:00
|
|
|
if 'proxyhosts' not in file_props:
|
2006-09-21 01:24:07 +02:00
|
|
|
raise common.xmpp.NodeProcessed
|
|
|
|
for host in file_props['proxyhosts']:
|
|
|
|
if host['initiator'] == frm and \
|
|
|
|
unicode(query.getAttr('sid')) == file_props['sid']:
|
|
|
|
gajim.socks5queue.activate_proxy(host['idx'])
|
|
|
|
break
|
|
|
|
raise common.xmpp.NodeProcessed
|
|
|
|
jid = streamhost.getAttr('jid')
|
2008-10-07 22:41:59 +02:00
|
|
|
if 'streamhost-used' in file_props and \
|
2006-09-21 01:24:07 +02:00
|
|
|
file_props['streamhost-used'] is True:
|
|
|
|
raise common.xmpp.NodeProcessed
|
|
|
|
|
2008-10-11 11:32:59 +02:00
|
|
|
if real_id.startswith('au_'):
|
2006-09-21 01:24:07 +02:00
|
|
|
gajim.socks5queue.send_file(file_props, self.name)
|
|
|
|
raise common.xmpp.NodeProcessed
|
|
|
|
|
|
|
|
proxy = None
|
2008-10-07 22:41:59 +02:00
|
|
|
if 'proxyhosts' in file_props:
|
2006-09-21 01:24:07 +02:00
|
|
|
for proxyhost in file_props['proxyhosts']:
|
|
|
|
if proxyhost['jid'] == jid:
|
|
|
|
proxy = proxyhost
|
|
|
|
|
2008-10-11 11:44:12 +02:00
|
|
|
if proxy is not None:
|
2006-09-21 01:24:07 +02:00
|
|
|
file_props['streamhost-used'] = True
|
2008-10-07 22:41:59 +02:00
|
|
|
if 'streamhosts' not in file_props:
|
2006-09-21 01:24:07 +02:00
|
|
|
file_props['streamhosts'] = []
|
|
|
|
file_props['streamhosts'].append(proxy)
|
|
|
|
file_props['is_a_proxy'] = True
|
|
|
|
receiver = socks5.Socks5Receiver(gajim.idlequeue, proxy, file_props['sid'], file_props)
|
|
|
|
gajim.socks5queue.add_receiver(self.name, receiver)
|
|
|
|
proxy['idx'] = receiver.queue_idx
|
|
|
|
gajim.socks5queue.on_success = self._proxy_auth_ok
|
|
|
|
raise common.xmpp.NodeProcessed
|
|
|
|
|
|
|
|
else:
|
|
|
|
gajim.socks5queue.send_file(file_props, self.name)
|
2008-10-07 22:41:59 +02:00
|
|
|
if 'fast' in file_props:
|
2006-09-21 01:24:07 +02:00
|
|
|
fasts = file_props['fast']
|
|
|
|
if len(fasts) > 0:
|
|
|
|
self._connect_error(frm, fasts[0]['id'], file_props['sid'],
|
|
|
|
code = 406)
|
2008-05-17 04:23:46 +02:00
|
|
|
|
2006-09-21 01:24:07 +02:00
|
|
|
raise common.xmpp.NodeProcessed
|
2008-05-17 04:23:46 +02:00
|
|
|
|
2006-09-21 01:24:07 +02:00
|
|
|
def _siResultCB(self, con, iq_obj):
|
|
|
|
gajim.log.debug('_siResultCB')
|
|
|
|
self.peerhost = con._owner.Connection._sock.getsockname()
|
2008-12-03 18:16:04 +01:00
|
|
|
id_ = iq_obj.getAttr('id')
|
|
|
|
if id_ not in self.files_props:
|
2006-09-21 01:24:07 +02:00
|
|
|
# no such jid
|
|
|
|
return
|
2008-12-03 18:16:04 +01:00
|
|
|
file_props = self.files_props[id_]
|
2006-09-21 01:24:07 +02:00
|
|
|
if file_props is None:
|
|
|
|
# file properties for jid is none
|
|
|
|
return
|
2008-10-07 22:41:59 +02:00
|
|
|
if 'request-id' in file_props:
|
2006-09-21 01:24:07 +02:00
|
|
|
# we have already sent streamhosts info
|
|
|
|
return
|
|
|
|
file_props['receiver'] = unicode(iq_obj.getFrom())
|
|
|
|
si = iq_obj.getTag('si')
|
|
|
|
file_tag = si.getTag('file')
|
|
|
|
range_tag = None
|
|
|
|
if file_tag:
|
|
|
|
range_tag = file_tag.getTag('range')
|
|
|
|
if range_tag:
|
|
|
|
offset = range_tag.getAttr('offset')
|
|
|
|
if offset:
|
|
|
|
file_props['offset'] = int(offset)
|
|
|
|
length = range_tag.getAttr('length')
|
|
|
|
if length:
|
|
|
|
file_props['length'] = int(length)
|
|
|
|
feature = si.setTag('feature')
|
|
|
|
if feature.getNamespace() != common.xmpp.NS_FEATURE:
|
|
|
|
return
|
|
|
|
form_tag = feature.getTag('x')
|
|
|
|
form = common.xmpp.DataForm(node=form_tag)
|
|
|
|
field = form.getField('stream-method')
|
|
|
|
if field.getValue() != common.xmpp.NS_BYTESTREAM:
|
|
|
|
return
|
|
|
|
self.send_socks5_info(file_props, fast = True)
|
|
|
|
raise common.xmpp.NodeProcessed
|
2008-05-17 04:23:46 +02:00
|
|
|
|
2006-09-21 01:24:07 +02:00
|
|
|
def _siSetCB(self, con, iq_obj):
|
|
|
|
gajim.log.debug('_siSetCB')
|
|
|
|
jid = unicode(iq_obj.getFrom())
|
|
|
|
si = iq_obj.getTag('si')
|
|
|
|
profile = si.getAttr('profile')
|
|
|
|
mime_type = si.getAttr('mime-type')
|
|
|
|
if profile != common.xmpp.NS_FILE:
|
|
|
|
return
|
|
|
|
file_tag = si.getTag('file')
|
|
|
|
file_props = {'type': 'r'}
|
|
|
|
for attribute in file_tag.getAttrs():
|
|
|
|
if attribute in ('name', 'size', 'hash', 'date'):
|
|
|
|
val = file_tag.getAttr(attribute)
|
|
|
|
if val is None:
|
|
|
|
continue
|
|
|
|
file_props[attribute] = val
|
|
|
|
file_desc_tag = file_tag.getTag('desc')
|
|
|
|
if file_desc_tag is not None:
|
|
|
|
file_props['desc'] = file_desc_tag.getData()
|
|
|
|
|
|
|
|
if mime_type is not None:
|
|
|
|
file_props['mime-type'] = mime_type
|
|
|
|
our_jid = gajim.get_jid_from_account(self.name)
|
2008-05-17 04:23:46 +02:00
|
|
|
file_props['receiver'] = our_jid
|
2006-09-21 01:24:07 +02:00
|
|
|
file_props['sender'] = unicode(iq_obj.getFrom())
|
|
|
|
file_props['request-id'] = unicode(iq_obj.getAttr('id'))
|
|
|
|
file_props['sid'] = unicode(si.getAttr('id'))
|
2007-10-08 19:25:53 +02:00
|
|
|
file_props['transfered_size'] = []
|
2006-09-21 01:24:07 +02:00
|
|
|
gajim.socks5queue.add_file_props(self.name, file_props)
|
|
|
|
self.dispatch('FILE_REQUEST', (jid, file_props))
|
|
|
|
raise common.xmpp.NodeProcessed
|
|
|
|
|
|
|
|
def _siErrorCB(self, con, iq_obj):
|
|
|
|
gajim.log.debug('_siErrorCB')
|
|
|
|
si = iq_obj.getTag('si')
|
|
|
|
profile = si.getAttr('profile')
|
|
|
|
if profile != common.xmpp.NS_FILE:
|
|
|
|
return
|
2008-12-03 18:16:04 +01:00
|
|
|
id_ = iq_obj.getAttr('id')
|
|
|
|
if id_ not in self.files_props:
|
2006-09-21 01:24:07 +02:00
|
|
|
# no such jid
|
|
|
|
return
|
2008-12-03 18:16:04 +01:00
|
|
|
file_props = self.files_props[id_]
|
2006-09-21 01:24:07 +02:00
|
|
|
if file_props is None:
|
|
|
|
# file properties for jid is none
|
|
|
|
return
|
|
|
|
jid = unicode(iq_obj.getFrom())
|
|
|
|
file_props['error'] = -3
|
|
|
|
self.dispatch('FILE_REQUEST_ERROR', (jid, file_props, ''))
|
|
|
|
raise common.xmpp.NodeProcessed
|
|
|
|
|
2008-05-17 04:23:46 +02:00
|
|
|
class ConnectionHandlersZeroconf(ConnectionVcard, ConnectionBytestream, connection_handlers.ConnectionHandlersBase):
|
2006-05-26 16:27:42 +02:00
|
|
|
def __init__(self):
|
2006-11-29 23:57:37 +01:00
|
|
|
ConnectionVcard.__init__(self)
|
2006-09-21 01:24:07 +02:00
|
|
|
ConnectionBytestream.__init__(self)
|
2008-05-17 04:23:46 +02:00
|
|
|
connection_handlers.ConnectionHandlersBase.__init__(self)
|
|
|
|
|
2006-05-26 16:27:42 +02:00
|
|
|
try:
|
|
|
|
idle.init()
|
2008-10-11 11:37:13 +02:00
|
|
|
except Exception:
|
2008-12-02 16:53:23 +01:00
|
|
|
global HAS_IDLE
|
2006-05-26 16:27:42 +02:00
|
|
|
HAS_IDLE = False
|
2008-05-17 04:23:46 +02:00
|
|
|
|
2006-09-18 00:57:41 +02:00
|
|
|
def _messageCB(self, ip, con, msg):
|
|
|
|
'''Called when we receive a message'''
|
2008-05-17 04:23:46 +02:00
|
|
|
|
|
|
|
gajim.log.debug('Zeroconf MessageCB')
|
|
|
|
|
|
|
|
frm = msg.getFrom()
|
2006-09-18 00:57:41 +02:00
|
|
|
mtype = msg.getType()
|
2007-10-09 05:46:51 +02:00
|
|
|
thread_id = msg.getThread()
|
2008-05-17 04:23:46 +02:00
|
|
|
|
|
|
|
if not mtype:
|
|
|
|
mtype = 'normal'
|
2007-10-09 05:46:51 +02:00
|
|
|
|
2008-10-11 11:44:12 +02:00
|
|
|
if frm is None:
|
2006-10-03 00:41:48 +02:00
|
|
|
for key in self.connection.zeroconf.contacts:
|
|
|
|
if ip == self.connection.zeroconf.contacts[key][zeroconf.C_ADDRESS]:
|
2006-09-18 00:57:41 +02:00
|
|
|
frm = key
|
2008-05-17 04:23:46 +02:00
|
|
|
|
2006-10-17 21:13:36 +02:00
|
|
|
frm = unicode(frm)
|
2007-10-09 05:46:51 +02:00
|
|
|
|
2008-05-17 04:23:46 +02:00
|
|
|
session = self.get_or_create_session(frm, thread_id)
|
2007-10-09 05:46:51 +02:00
|
|
|
|
|
|
|
if thread_id and not session.received_thread_id:
|
|
|
|
session.received_thread_id = True
|
2008-05-17 04:23:46 +02:00
|
|
|
|
2007-10-09 05:46:51 +02:00
|
|
|
if msg.getTag('feature') and msg.getTag('feature').namespace == \
|
|
|
|
common.xmpp.NS_FEATURE:
|
|
|
|
if gajim.HAVE_PYCRYPTO:
|
|
|
|
self._FeatureNegCB(con, msg, session)
|
|
|
|
return
|
2008-05-17 04:23:46 +02:00
|
|
|
|
2007-10-09 05:46:51 +02:00
|
|
|
if msg.getTag('init') and msg.getTag('init').namespace == \
|
|
|
|
common.xmpp.NS_ESESSION_INIT:
|
|
|
|
self._InitE2ECB(con, msg, session)
|
|
|
|
|
2006-09-18 00:57:41 +02:00
|
|
|
encrypted = False
|
2008-05-17 04:23:46 +02:00
|
|
|
tim = msg.getTimestamp()
|
|
|
|
tim = helpers.datetime_tuple(tim)
|
|
|
|
tim = time.localtime(timegm(tim))
|
2007-10-09 05:46:51 +02:00
|
|
|
|
2008-05-17 04:23:46 +02:00
|
|
|
if msg.getTag('c', namespace = common.xmpp.NS_STANZA_CRYPTO):
|
2007-10-09 05:46:51 +02:00
|
|
|
encrypted = True
|
|
|
|
|
|
|
|
try:
|
|
|
|
msg = session.decrypt_stanza(msg)
|
2008-10-11 11:37:13 +02:00
|
|
|
except Exception:
|
2007-10-09 05:46:51 +02:00
|
|
|
self.dispatch('FAILED_DECRYPT', (frm, tim))
|
2008-05-17 04:23:46 +02:00
|
|
|
|
2007-10-09 05:46:51 +02:00
|
|
|
msgtxt = msg.getBody()
|
|
|
|
subject = msg.getSubject() # if not there, it's None
|
|
|
|
|
2006-09-18 00:57:41 +02:00
|
|
|
# invitations
|
|
|
|
invite = None
|
2008-05-17 04:23:46 +02:00
|
|
|
encTag = msg.getTag('x', namespace = common.xmpp.NS_ENCRYPTED)
|
|
|
|
|
2006-09-18 00:57:41 +02:00
|
|
|
if not encTag:
|
|
|
|
invite = msg.getTag('x', namespace = common.xmpp.NS_MUC_USER)
|
|
|
|
if invite and not invite.getTag('invite'):
|
|
|
|
invite = None
|
|
|
|
|
2007-12-28 19:49:28 +01:00
|
|
|
if encTag and self.USE_GPG:
|
2006-09-18 00:57:41 +02:00
|
|
|
#decrypt
|
|
|
|
encmsg = encTag.getData()
|
2008-05-17 04:23:46 +02:00
|
|
|
|
2006-09-18 00:57:41 +02:00
|
|
|
keyID = gajim.config.get_per('accounts', self.name, 'keyid')
|
|
|
|
if keyID:
|
|
|
|
decmsg = self.gpg.decrypt(encmsg, keyID)
|
2007-12-31 02:19:08 +01:00
|
|
|
# \x00 chars are not allowed in C (so in GTK)
|
2008-05-17 04:23:46 +02:00
|
|
|
msgtxt = decmsg.replace('\x00', '')
|
|
|
|
encrypted = True
|
2007-10-09 05:46:51 +02:00
|
|
|
|
2008-05-17 04:23:46 +02:00
|
|
|
if mtype == 'error':
|
|
|
|
self.dispatch_error_msg(msg, msgtxt, session, frm, tim, subject)
|
2007-10-09 05:46:51 +02:00
|
|
|
else:
|
2008-05-17 04:23:46 +02:00
|
|
|
# XXX this shouldn't be hardcoded
|
|
|
|
if isinstance(session, ChatControlSession):
|
2008-06-13 17:59:04 +02:00
|
|
|
session.received(frm, msgtxt, tim, encrypted, msg)
|
2007-10-09 05:46:51 +02:00
|
|
|
else:
|
2008-05-17 04:23:46 +02:00
|
|
|
session.received(msg)
|
|
|
|
# END messageCB
|
2007-10-09 05:46:51 +02:00
|
|
|
|
2006-09-17 16:45:58 +02:00
|
|
|
def store_metacontacts(self, tags):
|
|
|
|
''' fake empty method '''
|
2008-05-17 04:23:46 +02:00
|
|
|
# serverside metacontacts are not supported with zeroconf
|
2006-09-17 16:45:58 +02:00
|
|
|
# (there is no server)
|
|
|
|
pass
|
2006-11-20 22:02:15 +01:00
|
|
|
|
2006-06-13 23:19:39 +02:00
|
|
|
def remove_transfers_for_contact(self, contact):
|
|
|
|
''' stop all active transfer for contact '''
|
|
|
|
pass
|
2006-11-20 22:02:15 +01:00
|
|
|
|
2006-06-13 23:19:39 +02:00
|
|
|
def remove_all_transfers(self):
|
|
|
|
''' stops and removes all active connections from the socks5 pool '''
|
|
|
|
pass
|
|
|
|
|
2006-11-20 22:02:15 +01:00
|
|
|
def remove_transfer(self, file_props, remove_from_list = True):
|
2006-06-13 23:19:39 +02:00
|
|
|
pass
|
2008-07-29 21:49:31 +02:00
|
|
|
|
2008-12-02 15:44:26 +01:00
|
|
|
# vim: se ts=3:
|