2010-02-08 15:08:40 +01:00
|
|
|
## common/zeroconf/connection_zeroconf.py
|
2006-05-26 16:27:42 +02:00
|
|
|
##
|
|
|
|
## Contributors for this file:
|
2010-02-08 15:08:40 +01:00
|
|
|
## - Yann Leboulanger <asterix@lagaule.org>
|
|
|
|
## - Nikos Kouremenos <nkour@jabber.org>
|
|
|
|
## - Dimitur Kirov <dkirov@gmail.com>
|
|
|
|
## - Travis Shirk <travis@pobox.com>
|
2009-11-18 11:06:09 +01:00
|
|
|
## - Stefan Bethge <stefan@lanpartei.de>
|
2006-05-26 16:27:42 +02:00
|
|
|
##
|
2014-01-02 09:33:54 +01:00
|
|
|
## Copyright (C) 2003-2014 Yann Leboulanger <asterix@lagaule.org>
|
2010-03-11 16:52:36 +01:00
|
|
|
## Copyright (C) 2003-2004 Vincent Hanquez <tab@snarc.org>
|
|
|
|
## Copyright (C) 2006 Nikos Kouremenos <nkour@jabber.org>
|
2006-05-26 16:27:42 +02:00
|
|
|
## Dimitur Kirov <dkirov@gmail.com>
|
|
|
|
## Travis Shirk <travis@pobox.com>
|
|
|
|
## Norman Rasmussen <norman@rasmussen.co.za>
|
2006-07-27 22:36:21 +02: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 os
|
2015-05-10 20:54:26 +02:00
|
|
|
import socket
|
2006-05-26 16:27:42 +02:00
|
|
|
import random
|
|
|
|
random.seed()
|
|
|
|
|
|
|
|
import signal
|
|
|
|
if os.name != 'nt':
|
2010-02-08 15:08:40 +01:00
|
|
|
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
|
2006-07-11 17:22:59 +02:00
|
|
|
import getpass
|
2013-07-29 18:35:49 +02:00
|
|
|
from gi.repository import GLib
|
2006-06-13 23:19:39 +02:00
|
|
|
|
2009-11-18 11:06:09 +01:00
|
|
|
from common.connection import CommonConnection
|
2006-05-26 16:27:42 +02:00
|
|
|
from common import gajim
|
2011-07-19 23:05:32 +02:00
|
|
|
from common import ged
|
2006-06-28 01:09:21 +02:00
|
|
|
from common.zeroconf import client_zeroconf
|
2007-08-06 23:46:51 +02:00
|
|
|
from common.zeroconf import zeroconf
|
2013-01-02 13:54:02 +01:00
|
|
|
from common.zeroconf.connection_handlers_zeroconf import *
|
2010-10-26 11:25:30 +02:00
|
|
|
from common.connection_handlers_events import *
|
2006-05-29 17:36:18 +02:00
|
|
|
|
2009-11-18 11:06:09 +01:00
|
|
|
class ConnectionZeroconf(CommonConnection, ConnectionHandlersZeroconf):
|
2010-02-08 15:08:40 +01:00
|
|
|
def __init__(self, name):
|
|
|
|
ConnectionHandlersZeroconf.__init__(self)
|
|
|
|
# system username
|
|
|
|
self.username = None
|
|
|
|
self.server_resource = '' # zeroconf has no resource, fake an empty one
|
|
|
|
self.call_resolve_timeout = False
|
|
|
|
# we don't need a password, but must be non-empty
|
|
|
|
self.password = 'zeroconf'
|
|
|
|
self.autoconnect = False
|
|
|
|
|
|
|
|
CommonConnection.__init__(self, name)
|
|
|
|
self.is_zeroconf = True
|
|
|
|
|
2017-04-06 23:21:19 +02:00
|
|
|
gajim.ged.register_event_handler('stanza-message-outgoing', ged.OUT_CORE,
|
|
|
|
self._nec_stanza_message_outgoing)
|
2011-07-19 23:05:32 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def get_config_values_or_default(self):
|
|
|
|
"""
|
|
|
|
Get name, host, port from config, or create zeroconf account with default
|
|
|
|
values
|
|
|
|
"""
|
|
|
|
if not gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME, 'name'):
|
|
|
|
gajim.log.debug('Creating zeroconf account')
|
|
|
|
gajim.config.add_per('accounts', gajim.ZEROCONF_ACC_NAME)
|
|
|
|
gajim.config.set_per('accounts', gajim.ZEROCONF_ACC_NAME,
|
|
|
|
'autoconnect', True)
|
|
|
|
gajim.config.set_per('accounts', gajim.ZEROCONF_ACC_NAME, 'no_log_for',
|
|
|
|
'')
|
|
|
|
gajim.config.set_per('accounts', gajim.ZEROCONF_ACC_NAME, 'password',
|
|
|
|
'zeroconf')
|
|
|
|
gajim.config.set_per('accounts', gajim.ZEROCONF_ACC_NAME,
|
|
|
|
'sync_with_global_status', True)
|
|
|
|
|
|
|
|
gajim.config.set_per('accounts', gajim.ZEROCONF_ACC_NAME,
|
|
|
|
'custom_port', 5298)
|
|
|
|
gajim.config.set_per('accounts', gajim.ZEROCONF_ACC_NAME,
|
|
|
|
'is_zeroconf', True)
|
|
|
|
gajim.config.set_per('accounts', gajim.ZEROCONF_ACC_NAME,
|
|
|
|
'use_ft_proxies', False)
|
2013-01-01 21:06:16 +01:00
|
|
|
self.host = socket.gethostname()
|
2010-02-08 15:08:40 +01:00
|
|
|
gajim.config.set_per('accounts', gajim.ZEROCONF_ACC_NAME, 'hostname',
|
|
|
|
self.host)
|
|
|
|
self.port = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME,
|
|
|
|
'custom_port')
|
|
|
|
self.autoconnect = gajim.config.get_per('accounts',
|
|
|
|
gajim.ZEROCONF_ACC_NAME, 'autoconnect')
|
|
|
|
self.sync_with_global_status = gajim.config.get_per('accounts',
|
|
|
|
gajim.ZEROCONF_ACC_NAME, 'sync_with_global_status')
|
|
|
|
self.first = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME,
|
|
|
|
'zeroconf_first_name')
|
|
|
|
self.last = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME,
|
|
|
|
'zeroconf_last_name')
|
|
|
|
self.jabber_id = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME,
|
|
|
|
'zeroconf_jabber_id')
|
|
|
|
self.email = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME,
|
|
|
|
'zeroconf_email')
|
|
|
|
|
|
|
|
if not self.username:
|
2013-01-01 21:06:16 +01:00
|
|
|
self.username = getpass.getuser()
|
2010-02-08 15:08:40 +01:00
|
|
|
gajim.config.set_per('accounts', gajim.ZEROCONF_ACC_NAME, 'name',
|
2010-12-19 10:39:15 +01:00
|
|
|
self.username)
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
|
|
|
self.username = gajim.config.get_per('accounts',
|
2010-12-19 10:39:15 +01:00
|
|
|
gajim.ZEROCONF_ACC_NAME, 'name')
|
2010-02-08 15:08:40 +01:00
|
|
|
# END __init__
|
|
|
|
|
|
|
|
def check_jid(self, jid):
|
|
|
|
return jid
|
|
|
|
|
2017-04-25 14:43:54 +02:00
|
|
|
def reconnect(self):
|
2010-02-08 15:08:40 +01:00
|
|
|
# Do not try to reco while we are already trying
|
|
|
|
self.time_to_reconnect = None
|
|
|
|
gajim.log.debug('reconnect')
|
|
|
|
|
|
|
|
self.disconnect()
|
|
|
|
self.change_status(self.old_show, self.status)
|
|
|
|
|
|
|
|
def disable_account(self):
|
|
|
|
self.disconnect()
|
|
|
|
|
|
|
|
def _on_resolve_timeout(self):
|
|
|
|
if self.connected:
|
|
|
|
self.connection.resolve_all()
|
|
|
|
diffs = self.roster.getDiffs()
|
|
|
|
for key in diffs:
|
|
|
|
self.roster.setItem(key)
|
2010-12-18 14:21:09 +01:00
|
|
|
gajim.nec.push_incoming_event(RosterInfoEvent(None, conn=self,
|
|
|
|
jid=key, nickname=self.roster.getName(key), sub='both',
|
|
|
|
ask='no', groups=self.roster.getGroups(key)))
|
2010-12-19 10:39:15 +01:00
|
|
|
gajim.nec.push_incoming_event(ZeroconfPresenceReceivedEvent(
|
2010-12-19 21:22:29 +01:00
|
|
|
None, conn=self, fjid=key, show=self.roster.getStatus(key),
|
2010-12-19 10:39:15 +01:00
|
|
|
status=self.roster.getMessage(key)))
|
2010-02-08 15:08:40 +01:00
|
|
|
#XXX open chat windows don't get refreshed (full name), add that
|
|
|
|
return self.call_resolve_timeout
|
|
|
|
|
|
|
|
# callbacks called from zeroconf
|
|
|
|
def _on_new_service(self, jid):
|
|
|
|
self.roster.setItem(jid)
|
2010-12-18 14:21:09 +01:00
|
|
|
gajim.nec.push_incoming_event(RosterInfoEvent(None, conn=self,
|
|
|
|
jid=jid, nickname=self.roster.getName(jid), sub='both',
|
|
|
|
ask='no', groups=self.roster.getGroups(jid)))
|
2010-12-19 10:39:15 +01:00
|
|
|
gajim.nec.push_incoming_event(ZeroconfPresenceReceivedEvent(
|
2010-12-19 21:22:29 +01:00
|
|
|
None, conn=self, fjid=jid, show=self.roster.getStatus(jid),
|
2010-12-19 10:39:15 +01:00
|
|
|
status=self.roster.getMessage(jid)))
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def _on_remove_service(self, jid):
|
|
|
|
self.roster.delItem(jid)
|
|
|
|
# 'NOTIFY' (account, (jid, status, status message, resource, priority,
|
|
|
|
# keyID, timestamp, contact_nickname))
|
2010-12-19 10:39:15 +01:00
|
|
|
gajim.nec.push_incoming_event(ZeroconfPresenceReceivedEvent(
|
2010-12-19 21:22:29 +01:00
|
|
|
None, conn=self, fjid=jid, show='offline', status=''))
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2017-04-25 14:43:54 +02:00
|
|
|
def disconnectedReconnCB(self):
|
2010-02-08 15:08:40 +01:00
|
|
|
"""
|
|
|
|
Called when we are disconnected. Comes from network manager for example
|
|
|
|
we don't try to reconnect, network manager will tell us when we can
|
|
|
|
"""
|
|
|
|
if gajim.account_is_connected(self.name):
|
|
|
|
# we cannot change our status to offline or connecting
|
|
|
|
# after we auth to server
|
|
|
|
self.old_show = STATUS_LIST[self.connected]
|
|
|
|
self.connected = 0
|
2010-11-06 10:04:41 +01:00
|
|
|
gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
|
|
|
|
show='offline'))
|
2010-02-08 15:08:40 +01:00
|
|
|
# random number to show we wait network manager to send us a reconenct
|
|
|
|
self.time_to_reconnect = 5
|
|
|
|
self.on_purpose = False
|
|
|
|
|
|
|
|
def _on_name_conflictCB(self, alt_name):
|
|
|
|
self.disconnect()
|
2010-11-06 10:04:41 +01:00
|
|
|
gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
|
|
|
|
show='offline'))
|
2010-11-28 11:00:53 +01:00
|
|
|
gajim.nec.push_incoming_event(ZeroconfNameConflictEvent(None, conn=self,
|
|
|
|
alt_name=alt_name))
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def _on_error(self, message):
|
2011-11-22 19:25:15 +01:00
|
|
|
gajim.nec.push_incoming_event(InformationEvent(None, conn=self,
|
|
|
|
level='error', pri_txt=_('Avahi error'), sec_txt=_('%s\nLink-local '
|
|
|
|
'messaging might not work properly.') % message))
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def connect(self, show='online', msg=''):
|
|
|
|
self.get_config_values_or_default()
|
|
|
|
if not self.connection:
|
|
|
|
self.connection = client_zeroconf.ClientZeroconf(self)
|
|
|
|
if not zeroconf.test_zeroconf():
|
2010-11-06 10:04:41 +01:00
|
|
|
gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
|
|
|
|
show='offline'))
|
2010-02-08 15:08:40 +01:00
|
|
|
self.status = 'offline'
|
2010-12-01 17:57:54 +01:00
|
|
|
gajim.nec.push_incoming_event(ConnectionLostEvent(None,
|
|
|
|
conn=self, title=_('Could not connect to "%s"') % self.name,
|
|
|
|
msg=_('Please check if Avahi or Bonjour is installed.')))
|
2010-02-08 15:08:40 +01:00
|
|
|
self.disconnect()
|
|
|
|
return
|
|
|
|
result = self.connection.connect(show, msg)
|
|
|
|
if not result:
|
2010-11-06 10:04:41 +01:00
|
|
|
gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
|
|
|
|
show='offline'))
|
2010-02-08 15:08:40 +01:00
|
|
|
self.status = 'offline'
|
|
|
|
if result is False:
|
2010-12-01 17:57:54 +01:00
|
|
|
gajim.nec.push_incoming_event(ConnectionLostEvent(None,
|
|
|
|
conn=self, title=_('Could not start local service'),
|
|
|
|
msg=_('Unable to bind to port %d.' % self.port)))
|
2010-02-08 15:08:40 +01:00
|
|
|
else: # result is None
|
2010-12-01 17:57:54 +01:00
|
|
|
gajim.nec.push_incoming_event(ConnectionLostEvent(None,
|
|
|
|
conn=self, title=_('Could not start local service'),
|
|
|
|
msg=_('Please check if avahi-daemon is running.')))
|
2010-02-08 15:08:40 +01:00
|
|
|
self.disconnect()
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
self.connection.announce()
|
|
|
|
self.roster = self.connection.getRoster()
|
2010-10-26 11:25:30 +02:00
|
|
|
gajim.nec.push_incoming_event(RosterReceivedEvent(None, conn=self,
|
|
|
|
xmpp_roster=self.roster))
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
# display contacts already detected and resolved
|
|
|
|
for jid in self.roster.keys():
|
2010-12-18 14:21:09 +01:00
|
|
|
gajim.nec.push_incoming_event(RosterInfoEvent(None, conn=self,
|
|
|
|
jid=jid, nickname=self.roster.getName(jid), sub='both',
|
|
|
|
ask='no', groups=self.roster.getGroups(jid)))
|
2010-12-19 10:39:15 +01:00
|
|
|
gajim.nec.push_incoming_event(ZeroconfPresenceReceivedEvent(
|
2010-12-19 21:22:29 +01:00
|
|
|
None, conn=self, fjid=jid, show=self.roster.getStatus(jid),
|
2010-12-19 10:39:15 +01:00
|
|
|
status=self.roster.getMessage(jid)))
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
self.connected = STATUS_LIST.index(show)
|
|
|
|
|
|
|
|
# refresh all contacts data every five seconds
|
|
|
|
self.call_resolve_timeout = True
|
2013-07-29 18:35:49 +02:00
|
|
|
GLib.timeout_add_seconds(5, self._on_resolve_timeout)
|
2010-02-08 15:08:40 +01:00
|
|
|
return True
|
|
|
|
|
|
|
|
def disconnect(self, on_purpose=False):
|
|
|
|
self.connected = 0
|
|
|
|
self.time_to_reconnect = None
|
|
|
|
if self.connection:
|
|
|
|
self.connection.disconnect()
|
|
|
|
self.connection = None
|
|
|
|
# stop calling the timeout
|
|
|
|
self.call_resolve_timeout = False
|
|
|
|
|
|
|
|
def reannounce(self):
|
|
|
|
if self.connected:
|
|
|
|
txt = {}
|
|
|
|
txt['1st'] = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME,
|
|
|
|
'zeroconf_first_name')
|
|
|
|
txt['last'] = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME,
|
|
|
|
'zeroconf_last_name')
|
|
|
|
txt['jid'] = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME,
|
|
|
|
'zeroconf_jabber_id')
|
|
|
|
txt['email'] = gajim.config.get_per('accounts',
|
|
|
|
gajim.ZEROCONF_ACC_NAME, 'zeroconf_email')
|
|
|
|
self.connection.reannounce(txt)
|
|
|
|
|
|
|
|
def update_details(self):
|
|
|
|
if self.connection:
|
|
|
|
port = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME,
|
|
|
|
'custom_port')
|
|
|
|
if port != self.port:
|
|
|
|
self.port = port
|
|
|
|
last_msg = self.connection.last_msg
|
|
|
|
self.disconnect()
|
|
|
|
if not self.connect(self.status, last_msg):
|
|
|
|
return
|
|
|
|
if self.status != 'invisible':
|
|
|
|
self.connection.announce()
|
|
|
|
else:
|
|
|
|
self.reannounce()
|
|
|
|
|
|
|
|
def connect_and_init(self, show, msg, sign_msg):
|
|
|
|
# to check for errors from zeroconf
|
|
|
|
check = True
|
|
|
|
if not self.connect(show, msg):
|
|
|
|
return
|
|
|
|
if show != 'invisible':
|
|
|
|
check = self.connection.announce()
|
|
|
|
else:
|
|
|
|
self.connected = STATUS_LIST.index(show)
|
2010-11-29 11:11:24 +01:00
|
|
|
gajim.nec.push_incoming_event(SignedInEvent(None, conn=self))
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
# stay offline when zeroconf does something wrong
|
|
|
|
if check:
|
2010-11-06 10:04:41 +01:00
|
|
|
gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
|
|
|
|
show=show))
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
|
|
|
# show notification that avahi or system bus is down
|
2013-12-31 14:28:24 +01:00
|
|
|
self.connected = 0
|
2010-11-06 10:04:41 +01:00
|
|
|
gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
|
|
|
|
show='offline'))
|
2010-02-08 15:08:40 +01:00
|
|
|
self.status = 'offline'
|
2010-12-01 17:57:54 +01:00
|
|
|
gajim.nec.push_incoming_event(ConnectionLostEvent(None, conn=self,
|
|
|
|
title=_('Could not change status of account "%s"') % self.name,
|
|
|
|
msg=_('Please check if avahi-daemon is running.')))
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def _change_to_invisible(self, msg):
|
|
|
|
if self.connection.remove_announce():
|
2010-11-06 10:04:41 +01:00
|
|
|
gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
|
|
|
|
show='invisible'))
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
|
|
|
# show notification that avahi or system bus is down
|
2010-11-06 10:04:41 +01:00
|
|
|
gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
|
|
|
|
show='offline'))
|
2010-02-08 15:08:40 +01:00
|
|
|
self.status = 'offline'
|
2010-12-01 17:57:54 +01:00
|
|
|
gajim.nec.push_incoming_event(ConnectionLostEvent(None, conn=self,
|
|
|
|
title=_('Could not change status of account "%s"') % self.name,
|
|
|
|
msg=_('Please check if avahi-daemon is running.')))
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def _change_from_invisible(self):
|
|
|
|
self.connection.announce()
|
|
|
|
|
|
|
|
def _update_status(self, show, msg):
|
|
|
|
if self.connection.set_show_msg(show, msg):
|
2010-11-06 10:04:41 +01:00
|
|
|
gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
|
|
|
|
show=show))
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
|
|
|
# show notification that avahi or system bus is down
|
2010-11-06 10:04:41 +01:00
|
|
|
gajim.nec.push_incoming_event(OurShowEvent(None, conn=self,
|
|
|
|
show='offline'))
|
2010-02-08 15:08:40 +01:00
|
|
|
self.status = 'offline'
|
2010-12-01 17:57:54 +01:00
|
|
|
gajim.nec.push_incoming_event(ConnectionLostEvent(None, conn=self,
|
|
|
|
title=_('Could not change status of account "%s"') % self.name,
|
|
|
|
msg=_('Please check if avahi-daemon is running.')))
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2017-04-06 23:21:19 +02:00
|
|
|
def _nec_stanza_message_outgoing(self, obj):
|
2017-08-02 21:03:12 +02:00
|
|
|
if obj.conn.name != self.name:
|
|
|
|
return
|
2011-07-19 23:05:32 +02:00
|
|
|
|
2017-07-28 01:37:06 +02:00
|
|
|
def on_send_ok(stanza_id):
|
2017-04-06 23:21:19 +02:00
|
|
|
gajim.nec.push_incoming_event(MessageSentEvent(None, conn=self,
|
|
|
|
jid=obj.jid, message=obj.message, keyID=obj.keyID,
|
|
|
|
automatic_message=obj.automatic_message, chatstate=None,
|
2017-07-28 01:37:06 +02:00
|
|
|
stanza_id=stanza_id))
|
2017-04-06 23:21:19 +02:00
|
|
|
if obj.callback:
|
|
|
|
obj.callback(obj.msg_iq, *obj.callback_args)
|
|
|
|
|
2017-06-14 15:29:19 +02:00
|
|
|
self.log_message(obj, obj.jid)
|
2017-04-06 23:21:19 +02:00
|
|
|
|
|
|
|
def on_send_not_ok(reason):
|
|
|
|
reason += ' ' + _('Your message could not be sent.')
|
|
|
|
gajim.nec.push_incoming_event(MessageErrorEvent(None, conn=self,
|
|
|
|
fjid=obj.jid, error_code=-1, error_msg=reason, msg=None,
|
|
|
|
time_=None, session=obj.session))
|
|
|
|
|
|
|
|
ret = self.connection.send(
|
|
|
|
obj.msg_iq, obj.message is not None,
|
|
|
|
on_ok=on_send_ok, on_not_ok=on_send_not_ok)
|
|
|
|
|
|
|
|
if ret == -1:
|
|
|
|
# Contact Offline
|
|
|
|
gajim.nec.push_incoming_event(MessageErrorEvent(None, conn=self,
|
|
|
|
fjid=obj.jid, error_code=-1, error_msg=_(
|
|
|
|
'Contact is offline. Your message could not be sent.'),
|
|
|
|
msg=None, time_=None, session=obj.session))
|
2011-07-19 23:05:32 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def send_stanza(self, stanza):
|
|
|
|
# send a stanza untouched
|
|
|
|
if not self.connection:
|
|
|
|
return
|
2012-12-09 21:37:51 +01:00
|
|
|
if not isinstance(stanza, nbxmpp.Node):
|
|
|
|
stanza = nbxmpp.Protocol(node=stanza)
|
2010-02-08 15:08:40 +01:00
|
|
|
self.connection.send(stanza)
|
|
|
|
|
|
|
|
def _event_dispatcher(self, realm, event, data):
|
|
|
|
CommonConnection._event_dispatcher(self, realm, event, data)
|
|
|
|
if realm == '':
|
2012-12-09 21:37:51 +01:00
|
|
|
if event == nbxmpp.transports_nb.DATA_ERROR:
|
2010-02-08 15:08:40 +01:00
|
|
|
thread_id = data[1]
|
2013-01-01 21:06:16 +01:00
|
|
|
frm = data[0]
|
2010-02-08 15:08:40 +01:00
|
|
|
session = self.get_or_create_session(frm, thread_id)
|
2010-12-01 21:38:39 +01:00
|
|
|
gajim.nec.push_incoming_event(MessageErrorEvent(
|
|
|
|
None, conn=self, fjid=frm, error_code=-1, error_msg=_(
|
|
|
|
'Connection to host could not be established: Timeout while '
|
|
|
|
'sending data.'), msg=None, time_=None, session=session))
|
2006-09-18 00:57:41 +02:00
|
|
|
|
2006-05-29 21:57:39 +02:00
|
|
|
# END ConnectionZeroconf
|