gajim-plural/src/common/zeroconf/connection_handlers_zerocon...

123 lines
3.7 KiB
Python
Raw Normal View History

2006-05-26 16:27:42 +02:00
##
## Copyright (C) 2006 Gajim Team
##
## Contributors for this file:
## - 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
##
## 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
## by the Free Software Foundation; version 3 only.
2006-05-26 16:27:42 +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.
##
## 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
import common.xmpp
from common import helpers
from common import gajim
from common.zeroconf import zeroconf
from common.commands import ConnectionCommands
from common.pep import ConnectionPEP
from common.protocol.bytestream import ConnectionSocks5BytestreamZeroconf
2010-12-19 21:22:29 +01:00
from common.connection_handlers_events import ZeroconfMessageReceivedEvent
import logging
log = logging.getLogger('gajim.c.z.connection_handlers_zeroconf')
2006-05-26 16:27:42 +02:00
STATUS_LIST = ['offline', 'connecting', 'online', 'chat', 'away', 'xa', 'dnd',
'invisible']
2006-05-26 16:27:42 +02:00
# 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:
import idle
except Exception:
log.debug(_('Unable to load idle module'))
HAS_IDLE = False
2006-05-26 16:27:42 +02:00
from common import connection_handlers
from session import ChatControlSession
2007-10-09 05:46:51 +02:00
class ConnectionVcard(connection_handlers.ConnectionVcard):
def add_sha(self, p, send_caps = True):
return p
2006-11-23 16:17:24 +01:00
def add_caps(self, p):
return p
2006-11-23 16:17:24 +01:00
def request_vcard(self, jid = None, is_fake_jid = False):
pass
def send_vcard(self, vcard):
pass
2006-09-21 01:24:07 +02:00
class ConnectionHandlersZeroconf(ConnectionVcard,
ConnectionSocks5BytestreamZeroconf, ConnectionCommands, ConnectionPEP,
2010-03-14 22:12:10 +01:00
connection_handlers.ConnectionHandlersBase, connection_handlers.ConnectionJingle):
def __init__(self):
ConnectionVcard.__init__(self)
2010-02-23 19:10:51 +01:00
ConnectionSocks5BytestreamZeroconf.__init__(self)
ConnectionCommands.__init__(self)
2010-03-14 22:12:10 +01:00
connection_handlers.ConnectionJingle.__init__(self)
connection_handlers.ConnectionHandlersBase.__init__(self)
try:
idle.init()
except Exception:
global HAS_IDLE
HAS_IDLE = False
def _messageCB(self, ip, con, msg):
"""
Called when we receive a message
"""
log.debug('Zeroconf MessageCB')
2010-12-19 21:22:29 +01:00
gajim.nec.push_incoming_event(ZeroconfMessageReceivedEvent(None,
conn=self, stanza=msg, ip=ip))
return
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):
raise common.xmpp.NodeProcessed
node = iq_obj.getTagAttr('query', 'node')
if node is None:
result = iq_obj.buildReply('result')
self.connection.send(result)
raise common.xmpp.NodeProcessed
if node==common.xmpp.NS_COMMANDS:
self.commandListQuery(con, iq_obj)
raise common.xmpp.NodeProcessed