Fix a few things in common.connection_handlers_events.

This commit is contained in:
Emmanuel Gil Peyrot 2017-02-08 04:37:21 +00:00
parent ad9370afa8
commit eb51184a95
1 changed files with 44 additions and 46 deletions

View File

@ -18,34 +18,33 @@
## along with Gajim. If not, see <http://www.gnu.org/licenses/>. ## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
## ##
from calendar import timegm
import datetime import datetime
import hashlib
import hmac
import logging
import sys import sys
import os import os
from time import time as time_time from time import time as time_time
from calendar import timegm
import hmac
import hashlib
import nbxmpp
from nbxmpp.protocol import NS_CHATSTATES
from common import atom from common import atom
from common import nec from common import nec
from common import helpers from common import helpers
from common import gajim from common import gajim
from common import i18n from common import i18n
import nbxmpp
from common import dataforms from common import dataforms
from common import exceptions from common import exceptions
from common.zeroconf import zeroconf
from common.zeroconf.zeroconf import Constant from common.zeroconf.zeroconf import Constant
from common.logger import LOG_DB_PATH from common.logger import LOG_DB_PATH
from common.pep import SUPPORTED_PERSONAL_USER_EVENTS from common.pep import SUPPORTED_PERSONAL_USER_EVENTS
from nbxmpp.protocol import NS_CHATSTATES
from common.jingle_transport import JingleTransportSocks5 from common.jingle_transport import JingleTransportSocks5
from common.file_props import FilesProp from common.file_props import FilesProp
if gajim.HAVE_PYOPENSSL: if gajim.HAVE_PYOPENSSL:
import OpenSSL.crypto import OpenSSL.crypto
import logging
log = logging.getLogger('gajim.c.connection_handlers_events') log = logging.getLogger('gajim.c.connection_handlers_events')
CONDITION_TO_CODE = { CONDITION_TO_CODE = {
@ -281,8 +280,7 @@ class GMailQueryReceivedEvent(nec.NetworkIncomingEvent):
gmail_messages = mb.getTags('mail-thread-info') gmail_messages = mb.getTags('mail-thread-info')
for gmessage in gmail_messages: for gmessage in gmail_messages:
unread_senders = [] unread_senders = []
for sender in gmessage.getTag('senders').getTags( for sender in gmessage.getTag('senders').getTags('sender'):
'sender'):
if sender.getAttr('unread') != '1': if sender.getAttr('unread') != '1':
continue continue
if sender.getAttr('name'): if sender.getAttr('name'):
@ -310,8 +308,7 @@ class GMailQueryReceivedEvent(nec.NetworkIncomingEvent):
self.conn.gmail_last_time = int(mb.getAttr('result-time')) self.conn.gmail_last_time = int(mb.getAttr('result-time'))
self.jid = gajim.get_jid_from_account(self.name) self.jid = gajim.get_jid_from_account(self.name)
log.debug(('You have %s new gmail e-mails on %s.') % (self.newmsgs, log.debug('You have %s new gmail e-mails on %s.', self.newmsgs, self.jid)
self.jid))
return True return True
class RosterItemExchangeEvent(nec.NetworkIncomingEvent, HelperEvent): class RosterItemExchangeEvent(nec.NetworkIncomingEvent, HelperEvent):
@ -778,7 +775,8 @@ PresenceHelperEvent):
sig_msg = sig_tag.getData() sig_msg = sig_tag.getData()
self.keyID = self.conn.gpg.verify(self.status, sig_msg) self.keyID = self.conn.gpg.verify(self.status, sig_msg)
self.keyID = helpers.prepare_and_validate_gpg_keyID(self.conn.name, self.keyID = helpers.prepare_and_validate_gpg_keyID(self.conn.name,
self.jid, self.keyID) self.jid,
self.keyID)
def _generate_prio(self): def _generate_prio(self):
self.prio = self.stanza.getPriority() self.prio = self.stanza.getPriority()
@ -857,8 +855,10 @@ PresenceHelperEvent):
self.errmsg = self.stanza.getErrorMsg() self.errmsg = self.stanza.getErrorMsg()
if self.is_gc: if self.is_gc:
gajim.nec.push_incoming_event(GcPresenceReceivedEvent(None, gajim.nec.push_incoming_event(
conn=self.conn, stanza=self.stanza, presence_obj=self)) GcPresenceReceivedEvent(
None, conn=self.conn, stanza=self.stanza,
presence_obj=self))
return return
if self.ptype == 'subscribe': if self.ptype == 'subscribe':
@ -878,8 +878,7 @@ PresenceHelperEvent):
if not self.ptype or self.ptype == 'unavailable': if not self.ptype or self.ptype == 'unavailable':
our_jid = gajim.get_jid_from_account(self.conn.name) our_jid = gajim.get_jid_from_account(self.conn.name)
if self.jid == our_jid and self.resource == \ if self.jid == our_jid and self.resource == self.conn.server_resource:
self.conn.server_resource:
# We got our own presence # We got our own presence
gajim.nec.push_incoming_event(OurShowEvent(None, conn=self.conn, gajim.nec.push_incoming_event(OurShowEvent(None, conn=self.conn,
show=self.show)) show=self.show))
@ -948,11 +947,9 @@ class GcPresenceReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
# we know real jid, save it in db # we know real jid, save it in db
st += ' (%s)' % jid st += ' (%s)' % jid
try: try:
gajim.logger.write('gcstatus', self.fjid, st, gajim.logger.write('gcstatus', self.fjid, st, self.show)
self.show)
except exceptions.PysqliteOperationalError as e: except exceptions.PysqliteOperationalError as e:
self.conn.dispatch('DB_ERROR', (_('Disk Write Error'), self.conn.dispatch('DB_ERROR', (_('Disk Write Error'), str(e)))
str(e)))
except exceptions.DatabaseMalformed: except exceptions.DatabaseMalformed:
pritext = _('Database Error') pritext = _('Database Error')
sectext = _('The database file (%s) cannot be read. ' sectext = _('The database file (%s) cannot be read. '
@ -1261,7 +1258,8 @@ class MessageReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
self.session = self.conn.get_latest_session(self.fjid) self.session = self.conn.get_latest_session(self.fjid)
if not self.session: if not self.session:
self.session = self.conn.make_new_session(self.fjid, self.session = self.conn.make_new_session(self.fjid,
self.thread_id, type_='pm') self.thread_id,
type_='pm')
else: else:
self.session = self.conn.get_or_create_session(self.fjid, self.session = self.conn.get_or_create_session(self.fjid,
self.thread_id) self.thread_id)
@ -1351,7 +1349,7 @@ class GcInvitationReceivedEvent(nec.NetworkIncomingEvent):
try: try:
self.room_jid = helpers.parse_jid(invite_tag.getAttr('jid')) self.room_jid = helpers.parse_jid(invite_tag.getAttr('jid'))
except helpers.InvalidFormat: except helpers.InvalidFormat:
log.warning('Invalid JID: %s, ignoring it' % invite_tag.getAttr( log.warning('Invalid JID: %s, ignoring it', invite_tag.getAttr(
'jid')) 'jid'))
return return
self.jid_from = self.msg_obj.fjid self.jid_from = self.msg_obj.fjid