2006-05-26 16:27:42 +02:00
|
|
|
##
|
|
|
|
## Copyright (C) 2006 Gajim Team
|
|
|
|
##
|
|
|
|
## 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>
|
2008-12-03 22:56:12 +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
|
|
|
|
2012-12-09 21:37:51 +01:00
|
|
|
import nbxmpp
|
2006-05-26 16:27:42 +02:00
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
from gajim.common import app
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim.common.commands import ConnectionCommands
|
|
|
|
from gajim.common.protocol.bytestream import ConnectionSocks5BytestreamZeroconf
|
|
|
|
from gajim.common.connection_handlers_events import ZeroconfMessageReceivedEvent
|
2009-08-30 00:57:49 +02:00
|
|
|
|
|
|
|
import logging
|
|
|
|
log = logging.getLogger('gajim.c.z.connection_handlers_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',
|
2010-02-08 15:08:40 +01:00
|
|
|
'invisible']
|
2006-05-26 16:27:42 +02:00
|
|
|
# kind of events we can wait for an answer
|
|
|
|
AGENT_REMOVED = 'agent_removed'
|
|
|
|
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim.common import connection_handlers
|
2007-10-09 05:46:51 +02:00
|
|
|
|
2008-05-17 04:23:46 +02:00
|
|
|
class ConnectionVcard(connection_handlers.ConnectionVcard):
|
2017-09-16 11:49:31 +02:00
|
|
|
def add_sha(self, p, *args):
|
2010-02-08 15:08:40 +01:00
|
|
|
return p
|
2006-11-23 16:17:24 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def add_caps(self, p):
|
|
|
|
return p
|
2006-11-23 16:17:24 +01:00
|
|
|
|
2017-09-16 11:49:31 +02:00
|
|
|
def request_vcard(self, *args):
|
2010-02-08 15:08:40 +01:00
|
|
|
pass
|
2008-05-17 04:23:46 +02:00
|
|
|
|
2017-09-16 11:49:31 +02:00
|
|
|
def send_vcard(self, *args):
|
2010-02-08 15:08:40 +01:00
|
|
|
pass
|
2006-09-21 01:24:07 +02:00
|
|
|
|
|
|
|
|
2010-02-22 16:29:01 +01:00
|
|
|
class ConnectionHandlersZeroconf(ConnectionVcard,
|
2013-04-06 10:14:28 +02:00
|
|
|
ConnectionSocks5BytestreamZeroconf, ConnectionCommands,
|
|
|
|
connection_handlers.ConnectionPEP, connection_handlers.ConnectionHandlersBase,
|
|
|
|
connection_handlers.ConnectionJingle):
|
2010-02-08 15:08:40 +01:00
|
|
|
def __init__(self):
|
|
|
|
ConnectionVcard.__init__(self)
|
2010-02-23 19:10:51 +01:00
|
|
|
ConnectionSocks5BytestreamZeroconf.__init__(self)
|
2010-02-08 15:08:40 +01:00
|
|
|
ConnectionCommands.__init__(self)
|
2010-03-14 22:12:10 +01:00
|
|
|
connection_handlers.ConnectionJingle.__init__(self)
|
2010-02-08 15:08:40 +01:00
|
|
|
connection_handlers.ConnectionHandlersBase.__init__(self)
|
|
|
|
|
|
|
|
def _messageCB(self, ip, con, msg):
|
|
|
|
"""
|
|
|
|
Called when we receive a message
|
|
|
|
"""
|
|
|
|
log.debug('Zeroconf MessageCB')
|
2017-08-13 13:18:56 +02:00
|
|
|
app.nec.push_incoming_event(ZeroconfMessageReceivedEvent(None,
|
2010-12-19 21:22:29 +01:00
|
|
|
conn=self, stanza=msg, ip=ip))
|
|
|
|
return
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def store_metacontacts(self, tags):
|
|
|
|
"""
|
|
|
|
Fake empty method
|
|
|
|
"""
|
|
|
|
# serverside metacontacts are not supported with zeroconf
|
|
|
|
# (there is no server)
|
|
|
|
pass
|
|
|
|
|
|
|
|
def _DiscoverItemsGetCB(self, con, iq_obj):
|
|
|
|
log.debug('DiscoverItemsGetCB')
|
|
|
|
|
|
|
|
if not self.connection or self.connected < 2:
|
|
|
|
return
|
|
|
|
|
|
|
|
if self.commandItemsQuery(con, iq_obj):
|
2012-12-09 21:37:51 +01:00
|
|
|
raise nbxmpp.NodeProcessed
|
2010-02-08 15:08:40 +01:00
|
|
|
node = iq_obj.getTagAttr('query', 'node')
|
|
|
|
if node is None:
|
|
|
|
result = iq_obj.buildReply('result')
|
|
|
|
self.connection.send(result)
|
2012-12-09 21:37:51 +01:00
|
|
|
raise nbxmpp.NodeProcessed
|
|
|
|
if node==nbxmpp.NS_COMMANDS:
|
2010-02-08 15:08:40 +01:00
|
|
|
self.commandListQuery(con, iq_obj)
|
2012-12-09 21:37:51 +01:00
|
|
|
raise nbxmpp.NodeProcessed
|