2010-08-28 00:25:07 +02:00
|
|
|
# -*- coding:utf-8 -*-
|
|
|
|
## src/common/connection_handlers_events.py
|
|
|
|
##
|
|
|
|
## Copyright (C) 2010 Yann Leboulanger <asterix AT lagaule.org>
|
|
|
|
##
|
|
|
|
## This file is part of Gajim.
|
|
|
|
##
|
|
|
|
## Gajim is free software; you can redistribute it and/or modify
|
|
|
|
## it under the terms of the GNU General Public License as published
|
|
|
|
## by the Free Software Foundation; version 3 only.
|
|
|
|
##
|
|
|
|
## Gajim is distributed in the hope that it will be useful,
|
|
|
|
## 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/>.
|
|
|
|
##
|
|
|
|
|
|
|
|
import datetime
|
2010-09-07 10:23:37 +02:00
|
|
|
import sys
|
2010-09-17 12:41:30 +02:00
|
|
|
from time import (localtime, time as time_time)
|
|
|
|
from calendar import timegm
|
2010-09-28 21:05:18 +02:00
|
|
|
import hmac
|
2010-08-28 00:25:07 +02:00
|
|
|
|
|
|
|
from common import nec
|
|
|
|
from common import helpers
|
|
|
|
from common import gajim
|
|
|
|
from common import xmpp
|
|
|
|
from common import dataforms
|
2010-09-17 12:41:30 +02:00
|
|
|
from common import exceptions
|
|
|
|
from common.logger import LOG_DB_PATH
|
2010-08-28 00:25:07 +02:00
|
|
|
|
|
|
|
import logging
|
|
|
|
log = logging.getLogger('gajim.c.connection_handlers_events')
|
|
|
|
|
|
|
|
class HelperEvent:
|
2010-10-24 15:33:19 +02:00
|
|
|
def get_jid_resource(self, check_fake_jid=False):
|
|
|
|
if check_fake_jid and hasattr(self, 'id_') and \
|
|
|
|
self.id_ in self.conn.groupchat_jids:
|
2010-08-28 00:25:07 +02:00
|
|
|
self.fjid = self.conn.groupchat_jids[self.id_]
|
|
|
|
del self.conn.groupchat_jids[self.id_]
|
|
|
|
else:
|
2010-10-18 22:05:41 +02:00
|
|
|
self.fjid = helpers.get_full_jid_from_iq(self.stanza)
|
2010-08-28 00:25:07 +02:00
|
|
|
self.jid, self.resource = gajim.get_room_and_nick_from_fjid(self.fjid)
|
|
|
|
|
|
|
|
def get_id(self):
|
2010-10-18 22:05:41 +02:00
|
|
|
self.id_ = self.stanza.getID()
|
|
|
|
|
|
|
|
def get_gc_control(self):
|
|
|
|
self.gc_control = gajim.interface.msg_win_mgr.get_gc_control(self.jid,
|
|
|
|
self.conn.name)
|
|
|
|
|
|
|
|
# If gc_control is missing - it may be minimized. Try to get it
|
|
|
|
# from there. If it's not there - then it's missing anyway and
|
|
|
|
# will remain set to None.
|
|
|
|
if not self.gc_control:
|
|
|
|
minimized = gajim.interface.minimized_controls[self.conn.name]
|
|
|
|
self.gc_control = minimized.get(self.jid)
|
|
|
|
|
|
|
|
def _generate_timestamp(self, tag):
|
|
|
|
tim = helpers.datetime_tuple(tag)
|
|
|
|
self.timestamp = localtime(timegm(tim))
|
2010-08-28 00:25:07 +02:00
|
|
|
|
|
|
|
class HttpAuthReceivedEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'http-auth-received'
|
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
def generate(self):
|
|
|
|
self.opt = gajim.config.get_per('accounts', self.conn.name, 'http_auth')
|
2010-10-18 22:05:41 +02:00
|
|
|
self.iq_id = self.stanza.getTagAttr('confirm', 'id')
|
|
|
|
self.method = self.stanza.getTagAttr('confirm', 'method')
|
|
|
|
self.url = self.stanza.getTagAttr('confirm', 'url')
|
2010-08-28 00:25:07 +02:00
|
|
|
# In case it's a message with a body
|
2010-10-18 22:05:41 +02:00
|
|
|
self.msg = self.stanza.getTagData('body')
|
2010-08-28 00:25:07 +02:00
|
|
|
return True
|
|
|
|
|
|
|
|
class LastResultReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
|
|
|
|
name = 'last-result-received'
|
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
def generate(self):
|
|
|
|
self.get_id()
|
2010-10-24 15:33:19 +02:00
|
|
|
self.get_jid_resource(check_fake_jid=True)
|
2010-08-28 00:25:07 +02:00
|
|
|
if self.id_ in self.conn.last_ids:
|
|
|
|
self.conn.last_ids.remove(self.id_)
|
|
|
|
|
|
|
|
self.status = ''
|
|
|
|
self.seconds = -1
|
|
|
|
|
2010-10-18 22:05:41 +02:00
|
|
|
if self.stanza.getType() == 'error':
|
2010-08-28 00:25:07 +02:00
|
|
|
return True
|
|
|
|
|
2010-10-18 22:05:41 +02:00
|
|
|
qp = self.stanza.getTag('query')
|
2010-09-10 21:27:10 +02:00
|
|
|
if not qp:
|
|
|
|
return
|
2010-08-28 00:25:07 +02:00
|
|
|
sec = qp.getAttr('seconds')
|
|
|
|
self.status = qp.getData()
|
|
|
|
try:
|
|
|
|
self.seconds = int(sec)
|
|
|
|
except Exception:
|
|
|
|
return
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
class VersionResultReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
|
|
|
|
name = 'version-result-received'
|
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
def generate(self):
|
|
|
|
self.get_id()
|
2010-10-24 15:33:19 +02:00
|
|
|
self.get_jid_resource(check_fake_jid=True)
|
2010-08-28 00:25:07 +02:00
|
|
|
if self.id_ in self.conn.version_ids:
|
|
|
|
self.conn.version_ids.remove(self.id_)
|
|
|
|
|
|
|
|
self.client_info = ''
|
|
|
|
self.os_info = ''
|
|
|
|
|
2010-10-18 22:05:41 +02:00
|
|
|
if self.stanza.getType() == 'error':
|
2010-08-28 00:25:07 +02:00
|
|
|
return True
|
|
|
|
|
2010-10-18 22:05:41 +02:00
|
|
|
qp = self.stanza.getTag('query')
|
2010-08-28 00:25:07 +02:00
|
|
|
if qp.getTag('name'):
|
|
|
|
self.client_info += qp.getTag('name').getData()
|
|
|
|
if qp.getTag('version'):
|
|
|
|
self.client_info += ' ' + qp.getTag('version').getData()
|
|
|
|
if qp.getTag('os'):
|
|
|
|
self.os_info += qp.getTag('os').getData()
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
class TimeResultReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
|
|
|
|
name = 'time-result-received'
|
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
def generate(self):
|
|
|
|
self.get_id()
|
2010-10-24 15:33:19 +02:00
|
|
|
self.get_jid_resource(check_fake_jid=True)
|
2010-08-28 00:25:07 +02:00
|
|
|
if self.id_ in self.conn.entity_time_ids:
|
|
|
|
self.conn.entity_time_ids.remove(self.id_)
|
|
|
|
|
|
|
|
self.time_info = ''
|
|
|
|
|
2010-10-18 22:05:41 +02:00
|
|
|
if self.stanza.getType() == 'error':
|
2010-08-28 00:25:07 +02:00
|
|
|
return True
|
|
|
|
|
2010-10-18 22:05:41 +02:00
|
|
|
qp = self.stanza.getTag('time')
|
2010-08-28 00:25:07 +02:00
|
|
|
if not qp:
|
|
|
|
# wrong answer
|
|
|
|
return
|
|
|
|
tzo = qp.getTag('tzo').getData()
|
|
|
|
if tzo.lower() == 'z':
|
|
|
|
tzo = '0:0'
|
|
|
|
tzoh, tzom = tzo.split(':')
|
|
|
|
utc_time = qp.getTag('utc').getData()
|
|
|
|
ZERO = datetime.timedelta(0)
|
|
|
|
class UTC(datetime.tzinfo):
|
|
|
|
def utcoffset(self, dt):
|
|
|
|
return ZERO
|
|
|
|
def tzname(self, dt):
|
|
|
|
return "UTC"
|
|
|
|
def dst(self, dt):
|
|
|
|
return ZERO
|
|
|
|
|
|
|
|
class contact_tz(datetime.tzinfo):
|
|
|
|
def utcoffset(self, dt):
|
|
|
|
return datetime.timedelta(hours=int(tzoh), minutes=int(tzom))
|
|
|
|
def tzname(self, dt):
|
|
|
|
return "remote timezone"
|
|
|
|
def dst(self, dt):
|
|
|
|
return ZERO
|
|
|
|
|
|
|
|
try:
|
|
|
|
t = datetime.datetime.strptime(utc_time, '%Y-%m-%dT%H:%M:%SZ')
|
|
|
|
except ValueError, e:
|
2010-09-13 12:23:49 +02:00
|
|
|
try:
|
|
|
|
t = datetime.datetime.strptime(utc_time,
|
|
|
|
'%Y-%m-%dT%H:%M:%S.%fZ')
|
|
|
|
except ValueError, e:
|
|
|
|
log.info('Wrong time format: %s' % str(e))
|
|
|
|
return
|
|
|
|
|
|
|
|
t = t.replace(tzinfo=UTC())
|
|
|
|
self.time_info = t.astimezone(contact_tz()).strftime('%c')
|
2010-08-28 00:25:07 +02:00
|
|
|
return True
|
|
|
|
|
|
|
|
class GMailQueryReceivedEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'gmail-notify'
|
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
def generate(self):
|
2010-10-18 22:05:41 +02:00
|
|
|
if not self.stanza.getTag('mailbox'):
|
2010-08-28 00:25:07 +02:00
|
|
|
return
|
2010-10-18 22:05:41 +02:00
|
|
|
mb = self.stanza.getTag('mailbox')
|
2010-08-28 00:25:07 +02:00
|
|
|
if not mb.getAttr('url'):
|
|
|
|
return
|
|
|
|
self.conn.gmail_url = mb.getAttr('url')
|
|
|
|
if mb.getNamespace() != xmpp.NS_GMAILNOTIFY:
|
|
|
|
return
|
|
|
|
self.newmsgs = mb.getAttr('total-matched')
|
|
|
|
if not self.newmsgs:
|
|
|
|
return
|
|
|
|
if self.newmsgs == '0':
|
|
|
|
return
|
|
|
|
# there are new messages
|
|
|
|
self.gmail_messages_list = []
|
|
|
|
if mb.getTag('mail-thread-info'):
|
|
|
|
gmail_messages = mb.getTags('mail-thread-info')
|
|
|
|
for gmessage in gmail_messages:
|
|
|
|
unread_senders = []
|
|
|
|
for sender in gmessage.getTag('senders').getTags(
|
|
|
|
'sender'):
|
|
|
|
if sender.getAttr('unread') != '1':
|
|
|
|
continue
|
|
|
|
if sender.getAttr('name'):
|
|
|
|
unread_senders.append(sender.getAttr('name') + \
|
|
|
|
'< ' + sender.getAttr('address') + '>')
|
|
|
|
else:
|
|
|
|
unread_senders.append(sender.getAttr('address'))
|
|
|
|
|
|
|
|
if not unread_senders:
|
|
|
|
continue
|
|
|
|
gmail_subject = gmessage.getTag('subject').getData()
|
|
|
|
gmail_snippet = gmessage.getTag('snippet').getData()
|
|
|
|
tid = int(gmessage.getAttr('tid'))
|
|
|
|
if not self.conn.gmail_last_tid or \
|
|
|
|
tid > self.conn.gmail_last_tid:
|
|
|
|
self.conn.gmail_last_tid = tid
|
|
|
|
self.gmail_messages_list.append({
|
|
|
|
'From': unread_senders,
|
|
|
|
'Subject': gmail_subject,
|
|
|
|
'Snippet': gmail_snippet,
|
|
|
|
'url': gmessage.getAttr('url'),
|
|
|
|
'participation': gmessage.getAttr('participation'),
|
|
|
|
'messages': gmessage.getAttr('messages'),
|
|
|
|
'date': gmessage.getAttr('date')})
|
|
|
|
self.conn.gmail_last_time = int(mb.getAttr('result-time'))
|
|
|
|
|
|
|
|
self.jid = gajim.get_jid_from_account(self.name)
|
|
|
|
log.debug(('You have %s new gmail e-mails on %s.') % (self.newmsgs,
|
|
|
|
self.jid))
|
|
|
|
return True
|
|
|
|
|
|
|
|
class RosterItemExchangeEvent(nec.NetworkIncomingEvent, HelperEvent):
|
|
|
|
name = 'roster-item-exchange-received'
|
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
def generate(self):
|
|
|
|
self.get_id()
|
|
|
|
self.get_jid_resource()
|
|
|
|
self.exchange_items_list = {}
|
2010-10-18 22:05:41 +02:00
|
|
|
items_list = self.stanza.getTag('x').getChildren()
|
2010-08-28 00:25:07 +02:00
|
|
|
if not items_list:
|
|
|
|
return
|
|
|
|
self.action = items_list[0].getAttr('action')
|
|
|
|
if self.action is None:
|
|
|
|
self.action = 'add'
|
2010-10-18 22:05:41 +02:00
|
|
|
for item in self.stanza.getTag('x', namespace=xmpp.NS_ROSTERX).\
|
2010-08-28 00:25:07 +02:00
|
|
|
getChildren():
|
|
|
|
try:
|
|
|
|
jid = helpers.parse_jid(item.getAttr('jid'))
|
|
|
|
except helpers.InvalidFormat:
|
|
|
|
log.warn('Invalid JID: %s, ignoring it' % item.getAttr('jid'))
|
|
|
|
continue
|
|
|
|
name = item.getAttr('name')
|
|
|
|
contact = gajim.contacts.get_contact(self.conn.name, jid)
|
|
|
|
groups = []
|
|
|
|
same_groups = True
|
|
|
|
for group in item.getTags('group'):
|
|
|
|
groups.append(group.getData())
|
|
|
|
# check that all suggested groups are in the groups we have for
|
|
|
|
# this contact
|
|
|
|
if not contact or group not in contact.groups:
|
|
|
|
same_groups = False
|
|
|
|
if contact:
|
|
|
|
# check that all groups we have for this contact are in the
|
|
|
|
# suggested groups
|
|
|
|
for group in contact.groups:
|
|
|
|
if group not in groups:
|
|
|
|
same_groups = False
|
|
|
|
if contact.sub in ('both', 'to') and same_groups:
|
|
|
|
continue
|
|
|
|
self.exchange_items_list[jid] = []
|
|
|
|
self.exchange_items_list[jid].append(name)
|
|
|
|
self.exchange_items_list[jid].append(groups)
|
|
|
|
if self.exchange_items_list:
|
|
|
|
return True
|
|
|
|
|
|
|
|
class VersionRequestEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'version-request-received'
|
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
class LastRequestEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'last-request-received'
|
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
class TimeRequestEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'time-request-received'
|
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
class TimeRevisedRequestEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'time-revised-request-received'
|
|
|
|
base_network_events = []
|
|
|
|
|
2010-08-29 20:22:20 +02:00
|
|
|
class RosterReceivedEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'roster-received'
|
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
def generate(self):
|
2010-10-19 18:14:30 +02:00
|
|
|
if hasattr(self, 'xmpp_roster'):
|
|
|
|
self.version = self.xmpp_roster.version
|
|
|
|
self.received_from_server = self.xmpp_roster.received_from_server
|
|
|
|
self.roster = {}
|
|
|
|
raw_roster = self.xmpp_roster.getRaw()
|
|
|
|
our_jid = gajim.get_jid_from_account(self.conn.name)
|
|
|
|
|
|
|
|
for jid in raw_roster:
|
|
|
|
try:
|
|
|
|
j = helpers.parse_jid(jid)
|
|
|
|
except Exception:
|
|
|
|
print >> sys.stderr, _('JID %s is not RFC compliant. It '
|
|
|
|
'will not be added to your roster. Use roster '
|
|
|
|
'management tools such as '
|
|
|
|
'http://jru.jabberstudio.org/ to remove it') % jid
|
|
|
|
else:
|
|
|
|
infos = raw_roster[jid]
|
|
|
|
if jid != our_jid and (not infos['subscription'] or \
|
|
|
|
infos['subscription'] == 'none') and (not infos['ask'] or \
|
|
|
|
infos['ask'] == 'none') and not infos['name'] and \
|
|
|
|
not infos['groups']:
|
|
|
|
# remove this useless item, it won't be shown in roster
|
|
|
|
# anyway
|
|
|
|
self.conn.connection.getRoster().delItem(jid)
|
|
|
|
elif jid != our_jid: # don't add our jid
|
|
|
|
self.roster[j] = raw_roster[jid]
|
|
|
|
else:
|
|
|
|
# Roster comes from DB
|
|
|
|
self.received_from_server = False
|
|
|
|
self.version = gajim.config.get_per('accounts', self.conn.name,
|
|
|
|
'roster_version')
|
|
|
|
self.roster = gajim.logger.get_roster(gajim.get_jid_from_account(
|
|
|
|
self.conn.name))
|
2010-08-29 20:22:20 +02:00
|
|
|
return True
|
|
|
|
|
2010-08-28 00:25:07 +02:00
|
|
|
class RosterSetReceivedEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'roster-set-received'
|
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
def generate(self):
|
2010-10-18 22:05:41 +02:00
|
|
|
self.version = self.stanza.getTagAttr('query', 'ver')
|
2010-08-28 00:25:07 +02:00
|
|
|
self.items = {}
|
2010-10-18 22:05:41 +02:00
|
|
|
for item in self.stanza.getTag('query').getChildren():
|
2010-08-28 00:25:07 +02:00
|
|
|
try:
|
|
|
|
jid = helpers.parse_jid(item.getAttr('jid'))
|
|
|
|
except helpers.InvalidFormat:
|
|
|
|
log.warn('Invalid JID: %s, ignoring it' % item.getAttr('jid'))
|
|
|
|
continue
|
|
|
|
name = item.getAttr('name')
|
|
|
|
sub = item.getAttr('subscription')
|
|
|
|
ask = item.getAttr('ask')
|
|
|
|
groups = []
|
|
|
|
for group in item.getTags('group'):
|
|
|
|
groups.append(group.getData())
|
|
|
|
self.items[jid] = {'name': name, 'sub': sub, 'ask': ask,
|
|
|
|
'groups': groups}
|
|
|
|
if self.conn.connection and self.conn.connected > 1:
|
2010-10-18 22:05:41 +02:00
|
|
|
reply = xmpp.Iq(typ='result', attrs={'id': self.stanza.getID()},
|
|
|
|
to=self.stanza.getFrom(), frm=self.stanza.getTo(), xmlns=None)
|
2010-08-28 00:25:07 +02:00
|
|
|
self.conn.connection.send(reply)
|
|
|
|
return True
|
|
|
|
|
|
|
|
class RosterInfoEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'roster-info'
|
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
class MucOwnerReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
|
|
|
|
name = 'muc-owner-received'
|
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
def generate(self):
|
|
|
|
self.get_jid_resource()
|
2010-10-18 22:05:41 +02:00
|
|
|
qp = self.stanza.getQueryPayload()
|
2010-08-28 00:25:07 +02:00
|
|
|
self.form_node = None
|
|
|
|
for q in qp:
|
|
|
|
if q.getNamespace() == xmpp.NS_DATA:
|
|
|
|
self.form_node = q
|
|
|
|
self.dataform = dataforms.ExtendForm(node=self.form_node)
|
|
|
|
return True
|
|
|
|
|
|
|
|
class MucAdminReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
|
|
|
|
name = 'muc-admin-received'
|
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
def generate(self):
|
|
|
|
self.get_jid_resource()
|
2010-10-18 22:05:41 +02:00
|
|
|
items = self.stanza.getTag('query',
|
2010-08-28 00:25:07 +02:00
|
|
|
namespace=xmpp.NS_MUC_ADMIN).getTags('item')
|
|
|
|
self.users_dict = {}
|
|
|
|
for item in items:
|
|
|
|
if item.has_attr('jid') and item.has_attr('affiliation'):
|
|
|
|
try:
|
|
|
|
jid = helpers.parse_jid(item.getAttr('jid'))
|
|
|
|
except helpers.InvalidFormat:
|
|
|
|
log.warn('Invalid JID: %s, ignoring it' % \
|
|
|
|
item.getAttr('jid'))
|
|
|
|
continue
|
|
|
|
affiliation = item.getAttr('affiliation')
|
|
|
|
self.users_dict[jid] = {'affiliation': affiliation}
|
|
|
|
if item.has_attr('nick'):
|
|
|
|
self.users_dict[jid]['nick'] = item.getAttr('nick')
|
|
|
|
if item.has_attr('role'):
|
|
|
|
self.users_dict[jid]['role'] = item.getAttr('role')
|
|
|
|
reason = item.getTagData('reason')
|
|
|
|
if reason:
|
|
|
|
self.users_dict[jid]['reason'] = reason
|
|
|
|
return True
|
|
|
|
|
|
|
|
class PrivateStorageReceivedEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'private-storage-received'
|
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
def generate(self):
|
2010-10-18 22:05:41 +02:00
|
|
|
query = self.stanza.getTag('query')
|
2010-08-28 00:25:07 +02:00
|
|
|
self.storage_node = query.getTag('storage')
|
|
|
|
if self.storage_node:
|
|
|
|
self.namespace = self.storage_node.getNamespace()
|
|
|
|
return True
|
|
|
|
|
|
|
|
class BookmarksHelper:
|
|
|
|
def parse_bookmarks(self):
|
|
|
|
self.bookmarks = []
|
|
|
|
confs = self.base_event.storage_node.getTags('conference')
|
|
|
|
for conf in confs:
|
|
|
|
autojoin_val = conf.getAttr('autojoin')
|
|
|
|
if autojoin_val is None: # not there (it's optional)
|
|
|
|
autojoin_val = False
|
|
|
|
minimize_val = conf.getAttr('minimize')
|
|
|
|
if minimize_val is None: # not there (it's optional)
|
|
|
|
minimize_val = False
|
|
|
|
print_status = conf.getTagData('print_status')
|
|
|
|
if not print_status:
|
|
|
|
print_status = conf.getTagData('show_status')
|
|
|
|
try:
|
|
|
|
jid = helpers.parse_jid(conf.getAttr('jid'))
|
|
|
|
except helpers.InvalidFormat:
|
|
|
|
log.warn('Invalid JID: %s, ignoring it' % conf.getAttr('jid'))
|
|
|
|
continue
|
|
|
|
bm = {'name': conf.getAttr('name'),
|
|
|
|
'jid': jid,
|
|
|
|
'autojoin': autojoin_val,
|
|
|
|
'minimize': minimize_val,
|
|
|
|
'password': conf.getTagData('password'),
|
|
|
|
'nick': conf.getTagData('nick'),
|
|
|
|
'print_status': print_status}
|
|
|
|
|
|
|
|
|
|
|
|
bm_jids = [b['jid'] for b in self.bookmarks]
|
|
|
|
if bm['jid'] not in bm_jids:
|
|
|
|
self.bookmarks.append(bm)
|
|
|
|
|
|
|
|
class PrivateStorageBookmarksReceivedEvent(nec.NetworkIncomingEvent,
|
|
|
|
BookmarksHelper):
|
|
|
|
name = 'private-storage-bookmarks-received'
|
|
|
|
base_network_events = ['private-storage-received']
|
|
|
|
|
|
|
|
def generate(self):
|
|
|
|
self.conn = self.base_event.conn
|
|
|
|
if self.base_event.namespace != 'storage:bookmarks':
|
|
|
|
return
|
|
|
|
self.parse_bookmarks()
|
|
|
|
return True
|
|
|
|
|
|
|
|
class BookmarksReceivedEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'bookmarks-received'
|
|
|
|
base_network_events = ['private-storage-bookmarks-received',
|
|
|
|
'pubsub-bookmarks-received']
|
|
|
|
|
|
|
|
def generate(self):
|
|
|
|
self.conn = self.base_event.conn
|
|
|
|
self.bookmarks = self.base_event.bookmarks
|
|
|
|
return True
|
|
|
|
|
|
|
|
class PrivateStorageRosternotesReceivedEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'private-storage-rosternotes-received'
|
|
|
|
base_network_events = ['private-storage-received']
|
|
|
|
|
|
|
|
def generate(self):
|
|
|
|
self.conn = self.base_event.conn
|
|
|
|
if self.base_event.namespace != 'storage:rosternotes':
|
|
|
|
return
|
|
|
|
notes = self.base_event.storage_node.getTags('note')
|
|
|
|
self.annotations = {}
|
|
|
|
for note in notes:
|
|
|
|
try:
|
|
|
|
jid = helpers.parse_jid(note.getAttr('jid'))
|
|
|
|
except helpers.InvalidFormat:
|
|
|
|
log.warn('Invalid JID: %s, ignoring it' % note.getAttr('jid'))
|
|
|
|
continue
|
|
|
|
annotation = note.getData()
|
|
|
|
self.annotations[jid] = annotation
|
|
|
|
if self.annotations:
|
|
|
|
return True
|
|
|
|
|
|
|
|
class RosternotesReceivedEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'rosternotes-received'
|
|
|
|
base_network_events = ['private-storage-rosternotes-received']
|
|
|
|
|
|
|
|
def generate(self):
|
|
|
|
self.conn = self.base_event.conn
|
|
|
|
self.annotations = self.base_event.annotations
|
|
|
|
return True
|
|
|
|
|
|
|
|
class PubsubReceivedEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'pubsub-received'
|
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
def generate(self):
|
2010-10-18 22:05:41 +02:00
|
|
|
self.pubsub_node = self.stanza.getTag('pubsub')
|
2010-08-28 00:25:07 +02:00
|
|
|
if not self.pubsub_node:
|
|
|
|
return
|
|
|
|
self.items_node = self.pubsub_node.getTag('items')
|
|
|
|
if not self.items_node:
|
|
|
|
return
|
|
|
|
self.item_node = self.items_node.getTag('item')
|
|
|
|
if not self.item_node:
|
|
|
|
return
|
|
|
|
return True
|
|
|
|
|
|
|
|
class PubsubBookmarksReceivedEvent(nec.NetworkIncomingEvent, BookmarksHelper):
|
|
|
|
name = 'pubsub-bookmarks-received'
|
|
|
|
base_network_events = ['pubsub-received']
|
|
|
|
|
|
|
|
def generate(self):
|
|
|
|
self.conn = self.base_event.conn
|
|
|
|
storage = self.base_event.item_node.getTag('storage')
|
|
|
|
if not storage:
|
|
|
|
return
|
|
|
|
ns = storage.getNamespace()
|
|
|
|
if ns != 'storage:bookmarks':
|
|
|
|
return
|
|
|
|
self.parse_bookmarks()
|
2010-08-30 21:42:36 +02:00
|
|
|
return True
|
|
|
|
|
|
|
|
class SearchFormReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
|
|
|
|
name = 'search-form-received'
|
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
def generate(self):
|
|
|
|
self.get_jid_resource()
|
|
|
|
self.data = None
|
|
|
|
self.is_dataform = False
|
2010-10-18 22:05:41 +02:00
|
|
|
tag = self.stanza.getTag('query', namespace=xmpp.NS_SEARCH)
|
2010-08-30 21:42:36 +02:00
|
|
|
if not tag:
|
|
|
|
return True
|
|
|
|
self.data = tag.getTag('x', namespace=xmpp.NS_DATA)
|
|
|
|
if self.data:
|
|
|
|
self.is_dataform = True
|
|
|
|
return True
|
|
|
|
self.data = {}
|
2010-10-18 22:05:41 +02:00
|
|
|
for i in self.stanza.getQueryPayload():
|
2010-08-30 21:42:36 +02:00
|
|
|
self.data[i.getName()] = i.getData()
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
class SearchResultReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
|
|
|
|
name = 'search-result-received'
|
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
def generate(self):
|
|
|
|
self.get_jid_resource()
|
|
|
|
self.data = None
|
|
|
|
self.is_dataform = False
|
2010-10-18 22:05:41 +02:00
|
|
|
tag = self.stanza.getTag('query', namespace=xmpp.NS_SEARCH)
|
2010-08-30 21:42:36 +02:00
|
|
|
if not tag:
|
|
|
|
return True
|
|
|
|
self.data = tag.getTag('x', namespace=xmpp.NS_DATA)
|
|
|
|
if self.data:
|
|
|
|
self.is_dataform = True
|
|
|
|
return True
|
|
|
|
self.data = []
|
|
|
|
for item in tag.getTags('item'):
|
|
|
|
# We also show attributes. jid is there
|
|
|
|
f = item.attrs
|
|
|
|
for i in item.getPayload():
|
|
|
|
f[i.getName()] = i.getData()
|
|
|
|
self.data.append(f)
|
2010-09-07 10:23:37 +02:00
|
|
|
return True
|
2010-09-08 19:55:19 +02:00
|
|
|
|
2010-10-04 13:51:42 +02:00
|
|
|
class IqErrorReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
|
|
|
|
name = 'iq-error-received'
|
2010-09-08 19:55:19 +02:00
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
def generate(self):
|
|
|
|
self.get_id()
|
2010-10-24 15:33:19 +02:00
|
|
|
self.get_jid_resource(check_fake_jid=True)
|
2010-10-18 22:05:41 +02:00
|
|
|
self.errmsg = self.stanza.getErrorMsg()
|
|
|
|
self.errcode = self.stanza.getErrorCode()
|
2010-09-09 15:21:43 +02:00
|
|
|
return True
|
|
|
|
|
|
|
|
class GmailNewMailReceivedEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'gmail-new-mail-received'
|
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
def generate(self):
|
2010-10-18 22:05:41 +02:00
|
|
|
if not self.stanza.getTag('new-mail'):
|
2010-09-09 15:21:43 +02:00
|
|
|
return
|
2010-10-18 22:05:41 +02:00
|
|
|
if self.stanza.getTag('new-mail').getNamespace() != xmpp.NS_GMAILNOTIFY:
|
2010-09-09 15:21:43 +02:00
|
|
|
return
|
|
|
|
return True
|
2010-09-09 15:48:08 +02:00
|
|
|
|
|
|
|
class PingReceivedEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'ping-received'
|
|
|
|
base_network_events = []
|
2010-09-09 16:40:58 +02:00
|
|
|
|
|
|
|
class StreamReceivedEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'stream-received'
|
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
class StreamConflictReceivedEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'stream-conflict-received'
|
|
|
|
base_network_events = ['stream-received']
|
|
|
|
|
|
|
|
def generate(self):
|
2010-10-18 22:05:41 +02:00
|
|
|
if self.base_event.stanza.getTag('conflict'):
|
2010-09-09 16:40:58 +02:00
|
|
|
self.conn = self.base_event.conn
|
|
|
|
return True
|
2010-09-17 12:41:30 +02:00
|
|
|
|
|
|
|
class PresenceReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
|
|
|
|
name = 'presence-received'
|
|
|
|
base_network_events = ['raw-pres-received']
|
|
|
|
|
2010-10-05 12:25:56 +02:00
|
|
|
def _generate_keyID(self, sig_tag):
|
|
|
|
self.keyID = ''
|
|
|
|
if sig_tag and self.conn.USE_GPG and self.ptype != 'error':
|
|
|
|
# error presences contain our own signature
|
|
|
|
# verify
|
|
|
|
sig_msg = sig_tag.getData()
|
|
|
|
self.keyID = self.conn.gpg.verify(self.status, sig_msg)
|
|
|
|
self.keyID = helpers.prepare_and_validate_gpg_keyID(self.conn.name,
|
|
|
|
self.jid, self.keyID)
|
2010-09-23 20:46:47 +02:00
|
|
|
|
2010-10-05 12:25:56 +02:00
|
|
|
def _generate_show(self):
|
2010-10-18 22:05:41 +02:00
|
|
|
self.show = self.stanza.getShow()
|
2010-10-05 12:25:56 +02:00
|
|
|
if self.show not in ('chat', 'away', 'xa', 'dnd'):
|
|
|
|
self.show = '' # We ignore unknown show
|
|
|
|
if not self.ptype and not self.show:
|
|
|
|
self.show = 'online'
|
|
|
|
elif self.ptype == 'unavailable':
|
|
|
|
self.show = 'offline'
|
2010-09-23 20:46:47 +02:00
|
|
|
|
2010-10-05 12:25:56 +02:00
|
|
|
def _generate_prio(self):
|
2010-10-18 22:05:41 +02:00
|
|
|
self.prio = self.stanza.getPriority()
|
2010-10-05 12:25:56 +02:00
|
|
|
try:
|
|
|
|
self.prio = int(self.prio)
|
|
|
|
except Exception:
|
|
|
|
self.prio = 0
|
|
|
|
|
|
|
|
def _generate_ptype(self):
|
2010-10-18 22:05:41 +02:00
|
|
|
self.ptype = self.stanza.getType()
|
2010-09-17 12:41:30 +02:00
|
|
|
if self.ptype == 'available':
|
|
|
|
self.ptype = None
|
|
|
|
rfc_types = ('unavailable', 'error', 'subscribe', 'subscribed',
|
|
|
|
'unsubscribe', 'unsubscribed')
|
|
|
|
if self.ptype and not self.ptype in rfc_types:
|
|
|
|
self.ptype = None
|
2010-10-05 12:25:56 +02:00
|
|
|
|
|
|
|
def generate(self):
|
|
|
|
self.conn = self.base_event.conn
|
2010-10-18 22:05:41 +02:00
|
|
|
self.stanza = self.base_event.stanza
|
2010-10-05 12:25:56 +02:00
|
|
|
|
|
|
|
self.need_add_in_roster = False
|
|
|
|
self.need_redraw = False
|
|
|
|
|
2010-09-17 12:41:30 +02:00
|
|
|
if not self.conn or self.conn.connected < 2:
|
|
|
|
log.debug('account is no more connected')
|
|
|
|
return
|
2010-10-05 12:25:56 +02:00
|
|
|
|
|
|
|
self._generate_ptype()
|
2010-09-17 12:41:30 +02:00
|
|
|
try:
|
|
|
|
self.get_jid_resource()
|
|
|
|
except Exception:
|
|
|
|
return
|
2010-09-23 20:46:47 +02:00
|
|
|
jid_list = gajim.contacts.get_jid_list(self.conn.name)
|
2010-09-17 12:41:30 +02:00
|
|
|
self.timestamp = None
|
|
|
|
self.get_id()
|
|
|
|
self.is_gc = False # is it a GC presence ?
|
2010-10-05 12:25:56 +02:00
|
|
|
sig_tag = None
|
2010-09-28 15:13:51 +02:00
|
|
|
self.avatar_sha = None
|
2010-09-17 12:41:30 +02:00
|
|
|
# XEP-0172 User Nickname
|
2010-10-18 22:05:41 +02:00
|
|
|
self.user_nick = self.stanza.getTagData('nick') or ''
|
2010-09-17 12:41:30 +02:00
|
|
|
self.contact_nickname = None
|
2010-10-04 10:56:34 +02:00
|
|
|
self.transport_auto_auth = False
|
2010-09-17 12:41:30 +02:00
|
|
|
# XEP-0203
|
2010-10-18 22:05:41 +02:00
|
|
|
delay_tag = self.stanza.getTag('delay', namespace=xmpp.NS_DELAY2)
|
2010-09-17 12:41:30 +02:00
|
|
|
if delay_tag:
|
2010-10-18 22:05:41 +02:00
|
|
|
self._generate_timestamp(self.stanza.getTimestamp2())
|
|
|
|
xtags = self.stanza.getTags('x')
|
2010-09-17 12:41:30 +02:00
|
|
|
for x in xtags:
|
|
|
|
namespace = x.getNamespace()
|
|
|
|
if namespace.startswith(xmpp.NS_MUC):
|
|
|
|
self.is_gc = True
|
|
|
|
elif namespace == xmpp.NS_SIGNED:
|
2010-10-05 12:25:56 +02:00
|
|
|
sig_tag = x
|
2010-09-17 12:41:30 +02:00
|
|
|
elif namespace == xmpp.NS_VCARD_UPDATE:
|
2010-09-28 15:13:51 +02:00
|
|
|
self.avatar_sha = x.getTagData('photo')
|
2010-09-17 12:41:30 +02:00
|
|
|
self.contact_nickname = x.getTagData('nickname')
|
|
|
|
elif namespace == xmpp.NS_DELAY and not self.timestamp:
|
|
|
|
# XEP-0091
|
2010-10-18 22:05:41 +02:00
|
|
|
self._generate_timestamp(self.stanza.getTimestamp())
|
2010-09-17 12:41:30 +02:00
|
|
|
elif namespace == 'http://delx.cjb.net/protocol/roster-subsync':
|
|
|
|
# see http://trac.gajim.org/ticket/326
|
|
|
|
agent = gajim.get_server_from_jid(self.jid)
|
|
|
|
if self.conn.connection.getRoster().getItem(agent):
|
|
|
|
# to be sure it's a transport contact
|
2010-10-04 10:56:34 +02:00
|
|
|
self.transport_auto_auth = True
|
2010-09-17 12:41:30 +02:00
|
|
|
|
|
|
|
if not self.is_gc and self.id_ and self.id_.startswith('gajim_muc_') \
|
|
|
|
and self.ptype == 'error':
|
2010-10-04 10:56:34 +02:00
|
|
|
# Error presences may not include sent stanza, so we don't detect
|
|
|
|
# it's a muc presence. So detect it by ID
|
2010-09-17 12:41:30 +02:00
|
|
|
h = hmac.new(self.conn.secret_hmac, self.jid).hexdigest()[:6]
|
|
|
|
if self.id_.split('_')[-1] == h:
|
|
|
|
self.is_gc = True
|
2010-10-18 22:05:41 +02:00
|
|
|
self.status = self.stanza.getStatus() or ''
|
2010-10-05 12:25:56 +02:00
|
|
|
self._generate_show()
|
|
|
|
self._generate_prio()
|
|
|
|
self._generate_keyID(sig_tag)
|
2010-09-17 12:41:30 +02:00
|
|
|
|
2010-10-18 22:05:41 +02:00
|
|
|
self.errcode = self.stanza.getErrorCode()
|
|
|
|
self.errmsg = self.stanza.getErrorMsg()
|
2010-10-04 13:51:42 +02:00
|
|
|
|
2010-09-17 12:41:30 +02:00
|
|
|
if self.is_gc:
|
2010-09-28 15:13:51 +02:00
|
|
|
gajim.nec.push_incoming_event(GcPresenceReceivedEvent(None,
|
2010-10-18 22:05:41 +02:00
|
|
|
conn=self.conn, stanza=self.stanza, presence_obj=self))
|
2010-09-17 12:41:30 +02:00
|
|
|
return
|
|
|
|
|
|
|
|
if self.ptype == 'subscribe':
|
2010-10-04 10:56:34 +02:00
|
|
|
gajim.nec.push_incoming_event(SubscribePresenceReceivedEvent(None,
|
2010-10-18 22:05:41 +02:00
|
|
|
conn=self.conn, stanza=self.stanza, presence_obj=self))
|
2010-09-17 12:41:30 +02:00
|
|
|
elif self.ptype == 'subscribed':
|
|
|
|
# BE CAREFUL: no con.updateRosterItem() in a callback
|
2010-10-04 10:56:34 +02:00
|
|
|
gajim.nec.push_incoming_event(SubscribedPresenceReceivedEvent(None,
|
2010-10-18 22:05:41 +02:00
|
|
|
conn=self.conn, stanza=self.stanza, presence_obj=self))
|
2010-09-17 12:41:30 +02:00
|
|
|
elif self.ptype == 'unsubscribe':
|
|
|
|
log.debug(_('unsubscribe request from %s') % self.jid)
|
|
|
|
elif self.ptype == 'unsubscribed':
|
2010-10-04 10:56:34 +02:00
|
|
|
gajim.nec.push_incoming_event(UnsubscribedPresenceReceivedEvent(
|
2010-10-18 22:05:41 +02:00
|
|
|
None, conn=self.conn, stanza=self.stanza, presence_obj=self))
|
2010-09-17 12:41:30 +02:00
|
|
|
elif self.ptype == 'error':
|
2010-10-04 13:51:42 +02:00
|
|
|
if self.errcode != '409': # conflict # See #5120
|
2010-09-17 12:41:30 +02:00
|
|
|
self.show = 'error'
|
2010-10-04 13:51:42 +02:00
|
|
|
self.status = self.errmsg
|
2010-09-17 12:41:30 +02:00
|
|
|
return True
|
|
|
|
|
|
|
|
if not self.ptype or self.ptype == 'unavailable':
|
|
|
|
our_jid = gajim.get_jid_from_account(self.conn.name)
|
|
|
|
if self.jid == our_jid and self.resource == \
|
|
|
|
self.conn.server_resource:
|
|
|
|
# We got our own presence
|
2010-11-06 10:04:41 +01:00
|
|
|
gajim.nec.push_incoming_event(OurShowEvent(None, conn=self.conn,
|
|
|
|
show=self.show))
|
2010-10-04 21:24:34 +02:00
|
|
|
elif self.jid in jid_list or self.jid == our_jid:
|
2010-09-17 12:41:30 +02:00
|
|
|
return True
|
2010-09-28 15:13:51 +02:00
|
|
|
|
2010-10-18 22:05:41 +02:00
|
|
|
class GcPresenceReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
|
2010-09-28 15:13:51 +02:00
|
|
|
name = 'gc-presence-received'
|
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
def generate(self):
|
|
|
|
self.ptype = self.presence_obj.ptype
|
|
|
|
self.fjid = self.presence_obj.fjid
|
2010-10-18 22:05:41 +02:00
|
|
|
self.jid = self.presence_obj.jid
|
2010-09-28 15:13:51 +02:00
|
|
|
self.room_jid = self.presence_obj.jid
|
|
|
|
self.nick = self.presence_obj.resource
|
|
|
|
self.show = self.presence_obj.show
|
|
|
|
self.status = self.presence_obj.status
|
|
|
|
self.avatar_sha = self.presence_obj.avatar_sha
|
2010-10-04 13:51:42 +02:00
|
|
|
self.errcode = self.presence_obj.errcode
|
|
|
|
self.errmsg = self.presence_obj.errmsg
|
2010-10-18 22:05:41 +02:00
|
|
|
self.errcon = self.stanza.getError()
|
2010-09-28 15:13:51 +02:00
|
|
|
self.get_gc_control()
|
|
|
|
self.gc_contact = gajim.contacts.get_gc_contact(self.conn.name,
|
|
|
|
self.room_jid, self.nick)
|
|
|
|
|
|
|
|
if self.ptype == 'error':
|
|
|
|
return True
|
|
|
|
|
|
|
|
if self.ptype and self.ptype != 'unavailable':
|
|
|
|
return
|
|
|
|
if gajim.config.get('log_contact_status_changes') and \
|
|
|
|
gajim.config.should_log(self.conn.name, self.room_jid):
|
|
|
|
if self.gc_contact:
|
|
|
|
jid = self.gc_contact.jid
|
|
|
|
else:
|
2010-10-18 22:05:41 +02:00
|
|
|
jid = self.stanza.getJid()
|
2010-09-29 17:51:52 +02:00
|
|
|
st = self.status
|
2010-09-28 15:13:51 +02:00
|
|
|
if jid:
|
|
|
|
# we know real jid, save it in db
|
2010-09-29 17:51:52 +02:00
|
|
|
st += ' (%s)' % jid
|
2010-09-28 15:13:51 +02:00
|
|
|
try:
|
2010-09-29 17:51:52 +02:00
|
|
|
gajim.logger.write('gcstatus', self.fjid, st,
|
2010-09-28 15:13:51 +02:00
|
|
|
self.show)
|
|
|
|
except exceptions.PysqliteOperationalError, e:
|
|
|
|
self.conn.dispatch('DB_ERROR', (_('Disk Write Error'),
|
|
|
|
str(e)))
|
|
|
|
except exceptions.DatabaseMalformed:
|
|
|
|
pritext = _('Database Error')
|
|
|
|
sectext = _('The database file (%s) cannot be read. '
|
|
|
|
'Try to repair it (see '
|
|
|
|
'http://trac.gajim.org/wiki/DatabaseBackup) or '
|
|
|
|
'remove it (all history will be lost).') % \
|
|
|
|
LOG_DB_PATH
|
|
|
|
self.conn.dispatch('DB_ERROR', (pritext, sectext))
|
|
|
|
if self.avatar_sha == '':
|
|
|
|
# contact has no avatar
|
|
|
|
puny_nick = helpers.sanitize_filename(self.nick)
|
|
|
|
gajim.interface.remove_avatar_files(self.room_jid, puny_nick)
|
|
|
|
# NOTE: if it's a gc presence, don't ask vcard here.
|
|
|
|
# We may ask it to real jid in gui part.
|
|
|
|
self.status_code = []
|
2010-10-18 22:05:41 +02:00
|
|
|
ns_muc_user_x = self.stanza.getTag('x', namespace=xmpp.NS_MUC_USER)
|
2010-09-29 17:51:52 +02:00
|
|
|
destroy = ns_muc_user_x.getTag('destroy')
|
|
|
|
if ns_muc_user_x and destroy:
|
2010-09-28 15:13:51 +02:00
|
|
|
# Room has been destroyed. see
|
|
|
|
# http://www.xmpp.org/extensions/xep-0045.html#destroyroom
|
|
|
|
self.reason = _('Room has been destroyed')
|
2010-09-29 17:51:52 +02:00
|
|
|
r = destroy.getTagData('reason')
|
|
|
|
if r:
|
|
|
|
self.reason += ' (%s)' % r
|
|
|
|
if destroy.getAttr('jid'):
|
|
|
|
try:
|
|
|
|
jid = helpers.parse_jid(destroy.getAttr('jid'))
|
|
|
|
self.reason += '\n' + \
|
|
|
|
_('You can join this room instead: %s') % jid
|
|
|
|
except common.helpers.InvalidFormat:
|
|
|
|
pass
|
|
|
|
self.status_code = ['destroyed']
|
2010-09-28 15:13:51 +02:00
|
|
|
else:
|
2010-10-18 22:05:41 +02:00
|
|
|
self.reason = self.stanza.getReason()
|
|
|
|
self.status_code = self.stanza.getStatusCode()
|
|
|
|
self.role = self.stanza.getRole()
|
|
|
|
self.affiliation = self.stanza.getAffiliation()
|
|
|
|
self.real_jid = self.stanza.getJid()
|
|
|
|
self.actor = self.stanza.getActor()
|
|
|
|
self.new_nick = self.stanza.getNewNick()
|
2010-09-28 15:13:51 +02:00
|
|
|
return True
|
2010-10-04 10:56:34 +02:00
|
|
|
|
|
|
|
class SubscribePresenceReceivedEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'subscribe-presence-received'
|
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
def generate(self):
|
|
|
|
self.jid = self.presence_obj.jid
|
|
|
|
self.fjid = self.presence_obj.fjid
|
|
|
|
self.status = self.presence_obj.status
|
|
|
|
self.transport_auto_auth = self.presence_obj.transport_auto_auth
|
|
|
|
self.user_nick = self.presence_obj.user_nick
|
|
|
|
return True
|
|
|
|
|
|
|
|
class SubscribedPresenceReceivedEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'subscribed-presence-received'
|
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
def generate(self):
|
|
|
|
self.jid = self.presence_obj.jid
|
|
|
|
self.resource = self.presence_obj.resource
|
|
|
|
return True
|
|
|
|
|
|
|
|
class UnsubscribedPresenceReceivedEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'unsubscribed-presence-received'
|
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
def generate(self):
|
|
|
|
self.jid = self.presence_obj.jid
|
|
|
|
return True
|
2010-10-18 22:05:41 +02:00
|
|
|
|
2010-11-06 10:04:41 +01:00
|
|
|
class OurShowEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'our-show'
|
|
|
|
base_network_events = []
|
|
|
|
|
2010-10-18 22:05:41 +02:00
|
|
|
class MessageReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
|
|
|
|
name = 'message-received'
|
|
|
|
base_network_events = ['raw-message-received']
|
|
|
|
|
|
|
|
def generate(self):
|
|
|
|
self.conn = self.base_event.conn
|
|
|
|
self.stanza = self.base_event.stanza
|
|
|
|
self.get_id()
|
|
|
|
|
|
|
|
account = self.conn.name
|
|
|
|
|
|
|
|
# check if the message is a roster item exchange (XEP-0144)
|
|
|
|
if self.stanza.getTag('x', namespace=xmpp.NS_ROSTERX):
|
|
|
|
gajim.nec.push_incoming_event(RosterItemExchangeEvent(None,
|
|
|
|
conn=self.conn, stanza=self.stanza))
|
|
|
|
return
|
|
|
|
|
|
|
|
# check if the message is a XEP-0070 confirmation request
|
|
|
|
if self.stanza.getTag('confirm', namespace=xmpp.NS_HTTP_AUTH):
|
|
|
|
gajim.nec.push_incoming_event(HttpAuthReceivedEvent(None,
|
|
|
|
conn=self.conn, stanza=self.stanza))
|
|
|
|
return
|
|
|
|
|
|
|
|
try:
|
|
|
|
self.get_jid_resource()
|
|
|
|
except helpers.InvalidFormat:
|
|
|
|
self.conn.dispatch('ERROR', (_('Invalid Jabber ID'),
|
|
|
|
_('A message from a non-valid JID arrived, it has been '
|
|
|
|
'ignored.')))
|
|
|
|
return
|
|
|
|
|
|
|
|
address_tag = self.stanza.getTag('addresses', namespace=xmpp.NS_ADDRESS)
|
|
|
|
# Be sure it comes from one of our resource, else ignore address element
|
|
|
|
if address_tag and self.jid == gajim.get_jid_from_account(account):
|
|
|
|
address = address_tag.getTag('address', attrs={'type': 'ofrom'})
|
|
|
|
if address:
|
|
|
|
try:
|
|
|
|
self.fjid = helpers.parse_jid(address.getAttr('jid'))
|
|
|
|
except helpers.InvalidFormat:
|
|
|
|
log.warn('Invalid JID: %s, ignoring it' % address.getAttr(
|
|
|
|
'jid'))
|
|
|
|
return
|
|
|
|
self.jid = gajim.get_jid_without_resource(self.fjid)
|
|
|
|
|
|
|
|
self.enc_tag = self.stanza.getTag('x', namespace=xmpp.NS_ENCRYPTED)
|
|
|
|
|
|
|
|
self.invite_tag = None
|
|
|
|
if not self.enc_tag:
|
|
|
|
self.invite_tag = self.stanza.getTag('x',
|
|
|
|
namespace=xmpp.NS_MUC_USER)
|
|
|
|
if self.invite_tag and not self.invite_tag.getTag('invite'):
|
|
|
|
self.invite_tag = None
|
|
|
|
|
|
|
|
self.thread_id = self.stanza.getThread()
|
|
|
|
self.mtype = self.stanza.getType()
|
|
|
|
if not self.mtype or self.mtype not in ('chat', 'groupchat', 'error'):
|
|
|
|
self.mtype = 'normal'
|
|
|
|
|
|
|
|
self.msgtxt = self.stanza.getBody()
|
|
|
|
|
|
|
|
self.get_gc_control()
|
|
|
|
|
|
|
|
if self.gc_control and self.jid == self.fjid:
|
|
|
|
# message from a gc without a resource
|
|
|
|
self.mtype = 'groupchat'
|
|
|
|
|
|
|
|
self.session = None
|
|
|
|
if self.mtype != 'groupchat':
|
|
|
|
self.session = self.conn.get_or_create_session(self.fjid,
|
|
|
|
self.thread_id)
|
|
|
|
|
|
|
|
if self.thread_id and not self.session.received_thread_id:
|
|
|
|
self.session.received_thread_id = True
|
|
|
|
|
|
|
|
self.session.last_receive = time_time()
|
|
|
|
|
|
|
|
# check if the message is a XEP-0020 feature negotiation request
|
|
|
|
if self.stanza.getTag('feature', namespace=xmpp.NS_FEATURE):
|
|
|
|
if gajim.HAVE_PYCRYPTO:
|
|
|
|
feature = self.stanza.getTag(name='feature',
|
|
|
|
namespace=xmpp.NS_FEATURE)
|
|
|
|
form = xmpp.DataForm(node=feature.getTag('x'))
|
|
|
|
|
|
|
|
if form['FORM_TYPE'] == 'urn:xmpp:ssn':
|
|
|
|
self.session.handle_negotiation(form)
|
|
|
|
else:
|
|
|
|
reply = self.stanza.buildReply()
|
|
|
|
reply.setType('error')
|
|
|
|
reply.addChild(feature)
|
|
|
|
err = xmpp.ErrorNode('service-unavailable', typ='cancel')
|
|
|
|
reply.addChild(node=err)
|
|
|
|
self.conn.connection.send(reply)
|
|
|
|
return
|
|
|
|
|
|
|
|
if self.stanza.getTag('init', namespace=xmpp.NS_ESESSION_INIT):
|
|
|
|
init = self.stanza.getTag(name='init',
|
|
|
|
namespace=xmpp.NS_ESESSION_INIT)
|
|
|
|
form = xmpp.DataForm(node=init.getTag('x'))
|
|
|
|
|
|
|
|
self.session.handle_negotiation(form)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
self._generate_timestamp(self.stanza.getTimestamp())
|
|
|
|
|
|
|
|
self.encrypted = False
|
|
|
|
xep_200_encrypted = self.stanza.getTag('c',
|
|
|
|
namespace=xmpp.NS_STANZA_CRYPTO)
|
|
|
|
if xep_200_encrypted:
|
|
|
|
self.encrypted = 'xep200'
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
class GcInvitationReceivedEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'gc-invitation-received'
|
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
def generate(self):
|
|
|
|
self.room_jid = self.msg_obj.fjid
|
|
|
|
|
|
|
|
item = self.msg_obj.invite_tag.getTag('invite')
|
|
|
|
try:
|
|
|
|
self.jid_from = helpers.parse_jid(item.getAttr('from'))
|
|
|
|
except helpers.InvalidFormat:
|
|
|
|
log.warn('Invalid JID: %s, ignoring it' % item.getAttr('from'))
|
|
|
|
return
|
|
|
|
self.reason = item.getTagData('reason')
|
|
|
|
self.password = self.msg_obj.invite_tag.getTagData('password')
|
|
|
|
|
|
|
|
self.is_continued = False
|
|
|
|
if item.getTag('continue'):
|
|
|
|
self.is_continued = True
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
class DecryptedMessageReceivedEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'decrypted-message-received'
|
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
def generate(self):
|
|
|
|
self.stanza = self.msg_obj.stanza
|
2010-10-19 11:43:17 +02:00
|
|
|
self.id_ = self.msg_obj.id_
|
2010-10-18 22:05:41 +02:00
|
|
|
self.jid = self.msg_obj.jid
|
|
|
|
self.fjid = self.msg_obj.fjid
|
|
|
|
self.resource = self.msg_obj.resource
|
|
|
|
self.mtype = self.msg_obj.mtype
|
|
|
|
self.invite_tag = self.msg_obj.invite_tag
|
|
|
|
self.thread_id = self.msg_obj.thread_id
|
|
|
|
self.msgtxt = self.msg_obj.msgtxt
|
|
|
|
self.gc_control = self.msg_obj.gc_control
|
|
|
|
self.session = self.msg_obj.session
|
|
|
|
self.timestamp = self.msg_obj.timestamp
|
2010-10-19 07:03:45 +02:00
|
|
|
self.encrypted = self.msg_obj.encrypted
|
2010-10-19 11:43:17 +02:00
|
|
|
|
|
|
|
self.receipt_request_tag = self.stanza.getTag('request',
|
|
|
|
namespace=xmpp.NS_RECEIPTS)
|
|
|
|
self.receipt_received_tag = self.stanza.getTag('received',
|
|
|
|
namespace=xmpp.NS_RECEIPTS)
|
2010-10-18 22:05:41 +02:00
|
|
|
return True
|
|
|
|
|
|
|
|
class GcMessageReceivedEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'gc-message-received'
|
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
def generate(self):
|
|
|
|
self.stanza = self.msg_obj.stanza
|
|
|
|
self.fjid = self.msg_obj.fjid
|
|
|
|
self.msgtxt = self.msg_obj.msgtxt
|
|
|
|
self.jid = self.msg_obj.jid
|
2010-10-19 21:43:44 +02:00
|
|
|
self.room_jid = self.msg_obj.jid
|
2010-10-18 22:05:41 +02:00
|
|
|
self.timestamp = self.msg_obj.timestamp
|
|
|
|
self.xhtml_msgtxt = self.stanza.getXHTML()
|
|
|
|
|
|
|
|
if gajim.config.get('ignore_incoming_xhtml'):
|
|
|
|
self.xhtml_msgtxt = None
|
|
|
|
|
|
|
|
if self.msg_obj.resource:
|
|
|
|
# message from someone
|
|
|
|
self.nick = self.msg_obj.resource
|
|
|
|
else:
|
|
|
|
# message from server
|
|
|
|
self.nick = ''
|
|
|
|
|
|
|
|
self.has_timestamp = bool(self.stanza.timestamp)
|
|
|
|
|
|
|
|
self.subject = self.stanza.getSubject()
|
|
|
|
|
|
|
|
if self.subject is not None:
|
|
|
|
self.conn.dispatch('GC_SUBJECT', (self.fjid, self.subject,
|
|
|
|
self.msgtxt, self.has_timestamp))
|
|
|
|
return
|
|
|
|
|
|
|
|
self.status_code = self.stanza.getStatusCode()
|
|
|
|
|
|
|
|
if not self.stanza.getTag('body'): # no <body>
|
|
|
|
# It could be a config change. See
|
|
|
|
# http://www.xmpp.org/extensions/xep-0045.html#roomconfig-notify
|
|
|
|
if self.stanza.getTag('x'):
|
|
|
|
if self.status_code != []:
|
|
|
|
self.conn.dispatch('GC_CONFIG_CHANGE', (self.jid,
|
|
|
|
self.status_code))
|
|
|
|
return
|
|
|
|
|
|
|
|
self.displaymarking = None
|
|
|
|
seclabel = self.stanza.getTag('securitylabel')
|
|
|
|
if seclabel and seclabel.getNamespace() == xmpp.NS_SECLABEL:
|
|
|
|
# Ignore message from room in which we are not
|
|
|
|
self.displaymarking = seclabel.getTag('displaymarking')
|
|
|
|
|
|
|
|
if self.jid not in self.conn.last_history_time:
|
|
|
|
return
|
|
|
|
|
|
|
|
self.captcha_form = None
|
|
|
|
captcha_tag = self.stanza.getTag('captcha', namespace=xmpp.NS_CAPTCHA)
|
|
|
|
if captcha_tag:
|
|
|
|
self.captcha_form = captcha_tag.getTag('x', namespace=xmpp.NS_DATA)
|
|
|
|
for field in self.captcha_form.getTags('field'):
|
|
|
|
for media in field.getTags('media'):
|
|
|
|
for uri in media.getTags('uri'):
|
|
|
|
uri_data = uri.getData()
|
|
|
|
if uri_data.startswith('cid:'):
|
|
|
|
uri_data = uri_data[4:]
|
|
|
|
found = False
|
2010-10-20 14:54:43 +02:00
|
|
|
for data in self.stanza.getTags('data',
|
2010-10-18 22:05:41 +02:00
|
|
|
namespace=xmpp.NS_BOB):
|
|
|
|
if data.getAttr('cid') == uri_data:
|
|
|
|
uri.setData(data.getData())
|
|
|
|
found = True
|
|
|
|
if not found:
|
|
|
|
self.conn.get_bob_data(uri_data, frm,
|
|
|
|
self.conn._dispatch_gc_msg_with_captcha,
|
|
|
|
[self.stanza, self.msg_obj], 0)
|
|
|
|
return
|
|
|
|
|
|
|
|
return True
|
2010-10-26 21:25:41 +02:00
|
|
|
|
2010-11-08 21:23:08 +01:00
|
|
|
class MessageSentEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'message-sent'
|
|
|
|
base_network_events = []
|
|
|
|
|
2010-10-26 21:25:41 +02:00
|
|
|
class AnonymousAuthEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'anonymous-auth'
|
2010-10-27 09:36:29 +02:00
|
|
|
base_network_events = []
|
|
|
|
|
2010-10-27 19:37:14 +02:00
|
|
|
class JingleRequestReceivedEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'jingle-request-received'
|
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
def generate(self):
|
|
|
|
self.fjid = self.jingle_session.peerjid
|
|
|
|
self.jid, self.resource = gajim.get_room_and_nick_from_fjid(self.fjid)
|
|
|
|
self.sid = self.jingle_session.sid
|
|
|
|
return True
|
|
|
|
|
|
|
|
class JingleConnectedReceivedEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'jingle-connected-received'
|
2010-10-27 09:36:29 +02:00
|
|
|
base_network_events = []
|
|
|
|
|
2010-10-29 16:49:53 +02:00
|
|
|
def generate(self):
|
|
|
|
self.fjid = self.jingle_session.peerjid
|
|
|
|
self.jid, self.resource = gajim.get_room_and_nick_from_fjid(self.fjid)
|
|
|
|
self.sid = self.jingle_session.sid
|
|
|
|
return True
|
|
|
|
|
|
|
|
class JingleDisconnectedReceivedEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'jingle-disconnected-received'
|
|
|
|
base_network_events = []
|
|
|
|
|
2010-11-05 11:08:06 +01:00
|
|
|
def generate(self):
|
|
|
|
self.fjid = self.jingle_session.peerjid
|
|
|
|
self.jid, self.resource = gajim.get_room_and_nick_from_fjid(self.fjid)
|
|
|
|
self.sid = self.jingle_session.sid
|
|
|
|
return True
|
|
|
|
|
|
|
|
class JingleErrorReceivedEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'jingle-error-received'
|
|
|
|
base_network_events = []
|
|
|
|
|
2010-10-27 09:36:29 +02:00
|
|
|
def generate(self):
|
2010-10-27 10:28:59 +02:00
|
|
|
self.fjid = self.jingle_session.peerjid
|
|
|
|
self.jid, self.resource = gajim.get_room_and_nick_from_fjid(self.fjid)
|
2010-10-27 09:36:29 +02:00
|
|
|
self.sid = self.jingle_session.sid
|
2010-11-05 20:36:45 +01:00
|
|
|
return True
|
|
|
|
|
|
|
|
class ArchivingReceivedEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'archiving-received'
|
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
def generate(self):
|
|
|
|
self.type_ = self.stanza.getType()
|
|
|
|
if self.type_ not in ('result', 'set', 'error'):
|
|
|
|
return
|
|
|
|
return True
|
|
|
|
|
|
|
|
class ArchivingErrorReceivedEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'archiving-error-received'
|
|
|
|
base_network_events = ['archiving-received']
|
|
|
|
|
|
|
|
def generate(self):
|
|
|
|
self.conn = self.base_event.conn
|
|
|
|
self.stanza = self.base_event.stanza
|
2010-11-06 09:19:20 +01:00
|
|
|
self.type_ = self.base_event.type_
|
2010-11-05 20:36:45 +01:00
|
|
|
|
|
|
|
if self.type_ == 'error':
|
|
|
|
self.error_msg = self.stanza.getErrorMsg()
|
|
|
|
return True
|
|
|
|
|
|
|
|
class ArchivingPreferencesChangedReceivedEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'archiving-preferences-changed-received'
|
|
|
|
base_network_events = ['archiving-received']
|
|
|
|
|
|
|
|
def generate(self):
|
|
|
|
self.conn = self.base_event.conn
|
|
|
|
self.stanza = self.base_event.stanza
|
|
|
|
self.type_ = self.base_event.type_
|
|
|
|
|
|
|
|
if self.type_ not in ('result', 'set'):
|
|
|
|
return
|
|
|
|
|
|
|
|
self.conf = {}
|
|
|
|
self.new_items = {}
|
|
|
|
self.removed_items = []
|
|
|
|
if self.stanza.getTag('pref'):
|
|
|
|
pref = self.stanza.getTag('pref')
|
|
|
|
|
|
|
|
if pref.getTag('auto'):
|
|
|
|
self.conf['auto'] = pref.getTagAttr('auto', 'save')
|
|
|
|
|
|
|
|
method_auto = pref.getTag('method', attrs={'type': 'auto'})
|
|
|
|
if method_auto:
|
|
|
|
self.conf['method_auto'] = method_auto.getAttr('use')
|
|
|
|
|
|
|
|
method_local = pref.getTag('method', attrs={'type': 'local'})
|
|
|
|
if method_local:
|
|
|
|
self.conf['method_local'] = method_local.getAttr('use')
|
|
|
|
|
|
|
|
method_manual = pref.getTag('method', attrs={'type': 'manual'})
|
|
|
|
if method_manual:
|
|
|
|
self.conf['method_manual'] = method_manual.getAttr('use')
|
|
|
|
|
|
|
|
default = pref.getTag('default')
|
|
|
|
if default:
|
|
|
|
self.conf['default'] = {
|
|
|
|
'expire': default.getAttr('expire'),
|
|
|
|
'otr': default.getAttr('otr'),
|
|
|
|
'save': default.getAttr('save'),
|
|
|
|
'unset': default.getAttr('unset')}
|
|
|
|
|
|
|
|
for item in pref.getTags('item'):
|
|
|
|
self.new_items[item.getAttr('jid')] = {
|
|
|
|
'expire': item.getAttr('expire'),
|
|
|
|
'otr': item.getAttr('otr'),
|
|
|
|
'save': item.getAttr('save')}
|
|
|
|
|
|
|
|
elif self.stanza.getTag('itemremove'):
|
|
|
|
for item in pref.getTags('item'):
|
|
|
|
self.removed_items.append(item.getAttr('jid'))
|
2010-11-07 18:26:31 +01:00
|
|
|
return True
|
|
|
|
|
|
|
|
class AccountCreatedEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'account-created'
|
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
class AccountNotCreatedEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'account-not-created'
|
2010-11-07 18:50:24 +01:00
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
class NewAccountConnectedEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'new-account-connected'
|
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
def generate(self):
|
|
|
|
try:
|
|
|
|
self.errnum = self.conn.connection.Connection.ssl_errnum
|
|
|
|
except AttributeError:
|
|
|
|
self.errnum = -1 # we don't have an errnum
|
|
|
|
self.ssl_msg = ''
|
|
|
|
if self.errnum > 0:
|
|
|
|
from common.connection import ssl_error
|
|
|
|
self.ssl_msg = ssl_error.get(errnum, _('Unknown SSL error: %d') % \
|
|
|
|
errnum)
|
|
|
|
self.ssl_cert = ''
|
|
|
|
if hasattr(self.conn.connection.Connection, 'ssl_cert_pem'):
|
|
|
|
self.ssl_cert = self.conn.connection.Connection.ssl_cert_pem
|
|
|
|
self.ssl_fingerprint = ''
|
|
|
|
if hasattr(self.conn.connection.Connection, 'ssl_fingerprint_sha1'):
|
|
|
|
self.ssl_fingerprint = \
|
|
|
|
self.conn.connection.Connection.ssl_fingerprint_sha1
|
|
|
|
return True
|
|
|
|
|
|
|
|
class NewAccountNotConnectedEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'new-account-not-connected'
|
2010-11-07 22:45:01 +01:00
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
class ConnectionTypeEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'connection-type'
|
2010-11-08 22:34:04 +01:00
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
class VcardPublishedEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'vcard-published'
|
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
class VcardNotPublishedEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'vcard-not-published'
|
2010-11-09 20:58:11 +01:00
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
class StanzaReceivedEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'stanza-received'
|
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
class StanzaSentEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'stanza-sent'
|
2010-11-09 21:52:22 +01:00
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
class AgentRemovedEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'agent-removed'
|
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
def generate(self):
|
|
|
|
self.jid_list = []
|
|
|
|
for jid in gajim.contacts.get_jid_list(self.conn.name):
|
|
|
|
if jid.endswith('@' + self.agent):
|
|
|
|
self.jid_list.append(jid)
|
2010-11-15 16:50:54 +01:00
|
|
|
return True
|
|
|
|
|
|
|
|
class BadGPGPassphraseEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'bad-gpg-passphrase'
|
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
def generate(self):
|
|
|
|
self.account = self.conn.name
|
|
|
|
self.use_gpg_agent = gajim.config.get('use_gpg_agent')
|
2010-11-18 17:02:34 +01:00
|
|
|
self.keyID = gajim.config.get_per('accounts', self.conn.name, 'keyid')
|
2010-11-15 16:50:54 +01:00
|
|
|
return True
|
2010-11-15 17:03:38 +01:00
|
|
|
|
|
|
|
class ConnectionLostEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'connection-lost'
|
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
def generate(self):
|
|
|
|
gajim.nec.push_incoming_event(OurShowEvent(None, conn=self.conn,
|
|
|
|
show='offline'))
|
|
|
|
return True
|
2010-11-15 17:35:19 +01:00
|
|
|
|
|
|
|
class PingSentEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'ping-sent'
|
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
class PingReplyEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'ping-reply'
|
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
class PingErrorEvent(nec.NetworkIncomingEvent):
|
|
|
|
name = 'ping-error'
|
|
|
|
base_network_events = []
|
2010-11-17 17:27:36 +01:00
|
|
|
|
|
|
|
class CapsPresenceReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
|
|
|
|
name = 'caps-presence-received'
|
|
|
|
base_network_events = ['raw-pres-received']
|
|
|
|
|
|
|
|
def _extract_caps_from_presence(self):
|
|
|
|
caps_tag = self.stanza.getTag('c', namespace=xmpp.NS_CAPS)
|
|
|
|
if caps_tag:
|
|
|
|
self.hash_method = caps_tag['hash']
|
|
|
|
self.node = caps_tag['node']
|
|
|
|
self.caps_hash = caps_tag['ver']
|
|
|
|
else:
|
|
|
|
self.hash_method = self.node = self.caps_hash = None
|
|
|
|
|
|
|
|
def generate(self):
|
|
|
|
self.conn = self.base_event.conn
|
|
|
|
self.stanza = self.base_event.stanza
|
|
|
|
try:
|
|
|
|
self.get_jid_resource()
|
|
|
|
except Exception:
|
|
|
|
return
|
|
|
|
self._extract_caps_from_presence()
|
|
|
|
return True
|
|
|
|
|
|
|
|
class CapsDiscoReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
|
|
|
|
name = 'caps-disco-received'
|
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
class CapsReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
|
|
|
|
name = 'caps-received'
|
|
|
|
base_network_events = ['caps-presence-received', 'caps-disco-received']
|
|
|
|
|
|
|
|
def generate(self):
|
|
|
|
self.conn = self.base_event.conn
|
|
|
|
self.fjid = self.base_event.fjid
|
|
|
|
self.jid = self.base_event.jid
|
|
|
|
self.resource = self.base_event.resource
|
|
|
|
self.client_caps = self.base_event.client_caps
|
|
|
|
return True
|
2010-11-17 23:52:14 +01:00
|
|
|
|
|
|
|
class GPGTrustKey(nec.NetworkIncomingEvent):
|
|
|
|
name = 'gpg-trust-key'
|
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
class GPGPasswordRequired(nec.NetworkIncomingEvent):
|
|
|
|
name = 'gpg-password-required'
|
|
|
|
base_network_events = []
|
|
|
|
|
|
|
|
def generate(self):
|
|
|
|
self.keyid = gajim.config.get_per('accounts', self.conn.name, 'keyid')
|
2010-11-18 17:02:34 +01:00
|
|
|
return True
|