2008-08-15 19:31:51 +02:00
|
|
|
# -*- coding:utf-8 -*-
|
2008-08-15 05:20:23 +02:00
|
|
|
## src/session.py
|
|
|
|
##
|
|
|
|
## Copyright (C) 2008 Yann Leboulanger <asterix AT lagaule.org>
|
|
|
|
## Brendan Taylor <whateley AT gmail.com>
|
|
|
|
## Jonathan Schleifer <js-gajim AT webkeks.org>
|
|
|
|
## Stephan Erb <steve-e AT h3c.de>
|
|
|
|
##
|
|
|
|
## 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/>.
|
|
|
|
##
|
|
|
|
|
2008-02-06 02:40:51 +01:00
|
|
|
from common import helpers
|
|
|
|
|
2008-04-15 07:32:45 +02:00
|
|
|
from common import exceptions
|
2008-02-06 02:40:51 +01:00
|
|
|
from common import gajim
|
|
|
|
from common import stanza_session
|
|
|
|
from common import contacts
|
|
|
|
|
2008-04-15 07:32:45 +02:00
|
|
|
import common.xmpp
|
|
|
|
|
2008-02-06 02:40:51 +01:00
|
|
|
import message_control
|
|
|
|
|
|
|
|
import notify
|
|
|
|
|
2008-06-21 21:12:47 +02:00
|
|
|
import dialogs
|
|
|
|
import negotiation
|
|
|
|
|
2008-02-06 02:40:51 +01:00
|
|
|
class ChatControlSession(stanza_session.EncryptedStanzaSession):
|
2008-10-11 12:22:04 +02:00
|
|
|
def __init__(self, conn, jid, thread_id, type_='chat'):
|
2008-09-30 17:21:44 +02:00
|
|
|
stanza_session.EncryptedStanzaSession.__init__(self, conn, jid, thread_id,
|
2008-10-11 12:22:04 +02:00
|
|
|
type_='chat')
|
2008-02-06 02:40:51 +01:00
|
|
|
|
|
|
|
self.control = None
|
|
|
|
|
2008-10-12 00:02:20 +02:00
|
|
|
def detach_from_control(self):
|
2008-05-04 01:19:02 +02:00
|
|
|
if self.control:
|
2008-05-24 01:27:08 +02:00
|
|
|
self.control.set_session(None)
|
|
|
|
|
2008-10-12 00:02:20 +02:00
|
|
|
def acknowledge_termination(self):
|
|
|
|
self.detach_from_control()
|
2008-06-29 17:57:07 +02:00
|
|
|
stanza_session.EncryptedStanzaSession.acknowledge_termination(self)
|
|
|
|
|
2008-12-13 19:10:37 +01:00
|
|
|
def terminate(self, send_termination = True):
|
|
|
|
stanza_session.EncryptedStanzaSession.terminate(self, send_termination)
|
2008-10-12 00:02:20 +02:00
|
|
|
self.detach_from_control()
|
2008-05-03 18:52:27 +02:00
|
|
|
|
2008-04-15 07:32:45 +02:00
|
|
|
def get_chatstate(self, msg, msgtxt):
|
2008-11-08 12:14:31 +01:00
|
|
|
'''extracts chatstate from a <message/> stanza'''
|
2008-04-15 07:32:45 +02:00
|
|
|
composing_xep = None
|
|
|
|
chatstate = None
|
|
|
|
|
|
|
|
# chatstates - look for chatstate tags in a message if not delayed
|
2008-10-11 11:44:12 +02:00
|
|
|
delayed = msg.getTag('x', namespace=common.xmpp.NS_DELAY) is not None
|
2008-04-15 07:32:45 +02:00
|
|
|
if not delayed:
|
|
|
|
composing_xep = False
|
|
|
|
children = msg.getChildren()
|
|
|
|
for child in children:
|
|
|
|
if child.getNamespace() == 'http://jabber.org/protocol/chatstates':
|
|
|
|
chatstate = child.getName()
|
|
|
|
composing_xep = 'XEP-0085'
|
|
|
|
break
|
|
|
|
# No XEP-0085 support, fallback to XEP-0022
|
|
|
|
if not chatstate:
|
2008-09-30 17:21:44 +02:00
|
|
|
chatstate_child = msg.getTag('x', namespace=common.xmpp.NS_EVENT)
|
2008-04-15 07:32:45 +02:00
|
|
|
if chatstate_child:
|
|
|
|
chatstate = 'active'
|
|
|
|
composing_xep = 'XEP-0022'
|
|
|
|
if not msgtxt and chatstate_child.getTag('composing'):
|
|
|
|
chatstate = 'composing'
|
|
|
|
|
|
|
|
return (composing_xep, chatstate)
|
|
|
|
|
2008-05-24 01:27:08 +02:00
|
|
|
def received(self, full_jid_with_resource, msgtxt, tim, encrypted, msg):
|
2008-11-08 12:14:31 +01:00
|
|
|
'''dispatch a received <message> stanza'''
|
2008-04-15 07:32:45 +02:00
|
|
|
msg_type = msg.getType()
|
2008-05-24 01:27:08 +02:00
|
|
|
subject = msg.getSubject()
|
2009-10-08 14:21:18 +02:00
|
|
|
resource = gajim.get_resource_from_jid(full_jid_with_resource)
|
2009-10-06 17:35:25 +02:00
|
|
|
if self.resource != resource:
|
|
|
|
self.resource = resource
|
2009-09-15 17:41:47 +02:00
|
|
|
if self.control and self.control.resource:
|
|
|
|
self.control.change_resource(self.resource)
|
2008-05-14 02:37:06 +02:00
|
|
|
|
2008-06-20 09:17:27 +02:00
|
|
|
if not msg_type or msg_type not in ('chat', 'groupchat', 'error'):
|
2008-05-14 02:37:06 +02:00
|
|
|
msg_type = 'normal'
|
|
|
|
|
2008-04-15 07:32:45 +02:00
|
|
|
msg_id = None
|
|
|
|
|
|
|
|
# XEP-0172 User Nickname
|
|
|
|
user_nick = msg.getTagData('nick')
|
|
|
|
if not user_nick:
|
2008-09-30 17:21:44 +02:00
|
|
|
user_nick = ''
|
2008-04-15 07:32:45 +02:00
|
|
|
|
|
|
|
form_node = None
|
|
|
|
for xtag in msg.getTags('x'):
|
|
|
|
if xtag.getNamespace() == common.xmpp.NS_DATA:
|
|
|
|
form_node = xtag
|
|
|
|
break
|
|
|
|
|
|
|
|
composing_xep, chatstate = self.get_chatstate(msg, msgtxt)
|
|
|
|
|
|
|
|
xhtml = msg.getXHTML()
|
|
|
|
|
|
|
|
if msg_type == 'chat':
|
|
|
|
if not msg.getTag('body') and chatstate is None:
|
|
|
|
return
|
|
|
|
|
|
|
|
log_type = 'chat_msg_recv'
|
|
|
|
else:
|
|
|
|
log_type = 'single_msg_recv'
|
|
|
|
|
|
|
|
if self.is_loggable() and msgtxt:
|
|
|
|
try:
|
2008-09-30 17:21:44 +02:00
|
|
|
msg_id = gajim.logger.write(log_type, full_jid_with_resource,
|
|
|
|
msgtxt, tim=tim, subject=subject)
|
2008-04-15 07:32:45 +02:00
|
|
|
except exceptions.PysqliteOperationalError, e:
|
2008-07-04 01:19:44 +02:00
|
|
|
self.conn.dispatch('ERROR', (_('Disk WriteError'), str(e)))
|
2009-07-30 18:06:52 +02:00
|
|
|
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).') % common.logger.LOG_DB_PATH
|
|
|
|
self.conn.dispatch('ERROR', (pritext, sectext))
|
2008-04-15 07:32:45 +02:00
|
|
|
|
|
|
|
treat_as = gajim.config.get('treat_incoming_messages')
|
|
|
|
if treat_as:
|
|
|
|
msg_type = treat_as
|
2008-02-06 02:40:51 +01:00
|
|
|
|
|
|
|
jid = gajim.get_jid_without_resource(full_jid_with_resource)
|
|
|
|
resource = gajim.get_resource_from_jid(full_jid_with_resource)
|
|
|
|
|
|
|
|
if gajim.config.get('ignore_incoming_xhtml'):
|
|
|
|
xhtml = None
|
|
|
|
if gajim.jid_is_transport(jid):
|
|
|
|
jid = jid.replace('@', '')
|
|
|
|
|
2008-09-30 17:21:44 +02:00
|
|
|
groupchat_control = gajim.interface.msg_win_mgr.get_gc_control(jid,
|
|
|
|
self.conn.name)
|
2008-04-30 04:55:13 +02:00
|
|
|
|
2008-05-03 02:10:17 +02:00
|
|
|
if not groupchat_control and \
|
|
|
|
jid in gajim.interface.minimized_controls[self.conn.name]:
|
2008-09-30 17:21:44 +02:00
|
|
|
groupchat_control = gajim.interface.minimized_controls[self.conn.name]\
|
|
|
|
[jid]
|
2008-02-06 02:40:51 +01:00
|
|
|
|
|
|
|
pm = False
|
2008-05-03 02:10:17 +02:00
|
|
|
if groupchat_control and groupchat_control.type_id == \
|
2008-11-23 18:17:44 +01:00
|
|
|
message_control.TYPE_GC and resource:
|
2008-02-06 02:40:51 +01:00
|
|
|
# It's a Private message
|
2008-05-03 02:10:17 +02:00
|
|
|
pm = True
|
|
|
|
msg_type = 'pm'
|
2008-02-06 02:40:51 +01:00
|
|
|
|
2008-05-14 02:37:06 +02:00
|
|
|
highest_contact = gajim.contacts.get_contact_with_highest_priority(
|
|
|
|
self.conn.name, jid)
|
|
|
|
|
2008-06-10 04:58:17 +02:00
|
|
|
# does this resource have the highest priority of any available?
|
|
|
|
is_highest = not highest_contact or not highest_contact.resource or \
|
2008-09-30 17:21:44 +02:00
|
|
|
resource == highest_contact.resource or highest_contact.show == \
|
|
|
|
'offline'
|
2008-05-14 02:37:06 +02:00
|
|
|
|
2008-02-06 02:40:51 +01:00
|
|
|
# Handle chat states
|
|
|
|
contact = gajim.contacts.get_contact(self.conn.name, jid, resource)
|
|
|
|
if contact:
|
|
|
|
if contact.composing_xep != 'XEP-0085': # We cache xep85 support
|
|
|
|
contact.composing_xep = composing_xep
|
|
|
|
if self.control and self.control.type_id == message_control.TYPE_CHAT:
|
|
|
|
if chatstate is not None:
|
|
|
|
# other peer sent us reply, so he supports jep85 or jep22
|
|
|
|
contact.chatstate = chatstate
|
|
|
|
if contact.our_chatstate == 'ask': # we were jep85 disco?
|
|
|
|
contact.our_chatstate = 'active' # no more
|
2008-05-03 02:10:17 +02:00
|
|
|
self.control.handle_incoming_chatstate()
|
2008-02-06 02:40:51 +01:00
|
|
|
elif contact.chatstate != 'active':
|
|
|
|
# got no valid jep85 answer, peer does not support it
|
|
|
|
contact.chatstate = False
|
|
|
|
elif chatstate == 'active':
|
|
|
|
# Brand new message, incoming.
|
|
|
|
contact.our_chatstate = chatstate
|
|
|
|
contact.chatstate = chatstate
|
|
|
|
if msg_id: # Do not overwrite an existing msg_id with None
|
|
|
|
contact.msg_id = msg_id
|
|
|
|
|
|
|
|
# THIS MUST BE AFTER chatstates handling
|
|
|
|
# AND BEFORE playsound (else we ear sounding on chatstates!)
|
2008-04-15 07:32:45 +02:00
|
|
|
if not msgtxt: # empty message text
|
2008-02-06 02:40:51 +01:00
|
|
|
return
|
|
|
|
|
2009-01-29 21:16:34 +01:00
|
|
|
if gajim.config.get_per('accounts', self.conn.name,
|
|
|
|
'ignore_unknown_contacts') and not gajim.contacts.get_contacts(
|
|
|
|
self.conn.name, jid) and not pm:
|
2008-02-06 02:40:51 +01:00
|
|
|
return
|
|
|
|
|
|
|
|
if not contact:
|
|
|
|
# contact is not in the roster, create a fake one to display
|
|
|
|
# notification
|
2008-09-30 17:21:44 +02:00
|
|
|
contact = contacts.Contact(jid=jid, resource=resource)
|
2008-05-20 02:44:30 +02:00
|
|
|
|
2008-02-06 02:40:51 +01:00
|
|
|
advanced_notif_num = notify.get_advanced_notification('message_received',
|
|
|
|
self.conn.name, contact)
|
|
|
|
|
2008-06-10 04:58:17 +02:00
|
|
|
if not pm and is_highest:
|
|
|
|
jid_of_control = jid
|
|
|
|
else:
|
|
|
|
jid_of_control = full_jid_with_resource
|
2008-02-06 02:40:51 +01:00
|
|
|
|
2008-05-25 23:28:40 +02:00
|
|
|
if not self.control:
|
2008-09-30 17:21:44 +02:00
|
|
|
ctrl = gajim.interface.msg_win_mgr.get_control(jid_of_control,
|
|
|
|
self.conn.name)
|
2008-05-29 04:48:55 +02:00
|
|
|
if ctrl:
|
|
|
|
self.control = ctrl
|
|
|
|
self.control.set_session(self)
|
2008-05-25 23:28:40 +02:00
|
|
|
|
2008-06-12 05:56:41 +02:00
|
|
|
# Is it a first or next message received ?
|
|
|
|
first = False
|
|
|
|
if not self.control and not gajim.events.get_events(self.conn.name, \
|
|
|
|
jid_of_control, [msg_type]):
|
|
|
|
first = True
|
|
|
|
|
2008-02-06 02:40:51 +01:00
|
|
|
if pm:
|
|
|
|
nickname = resource
|
2008-07-15 01:46:22 +02:00
|
|
|
if self.control:
|
|
|
|
# print if a control is open
|
2008-09-30 17:21:44 +02:00
|
|
|
self.control.print_conversation(msgtxt, tim=tim, xhtml=xhtml,
|
|
|
|
encrypted=encrypted)
|
2008-07-15 01:46:22 +02:00
|
|
|
else:
|
|
|
|
# otherwise pass it off to the control to be queued
|
|
|
|
groupchat_control.on_private_message(nickname, msgtxt, tim,
|
|
|
|
xhtml, self, msg_id=msg_id, encrypted=encrypted)
|
2008-02-06 02:40:51 +01:00
|
|
|
else:
|
2008-04-15 07:32:45 +02:00
|
|
|
self.roster_message(jid, msgtxt, tim, encrypted, msg_type,
|
2008-02-06 02:40:51 +01:00
|
|
|
subject, resource, msg_id, user_nick, advanced_notif_num,
|
|
|
|
xhtml=xhtml, form_node=form_node)
|
|
|
|
|
|
|
|
nickname = gajim.get_name_from_jid(self.conn.name, jid)
|
2008-06-10 04:58:17 +02:00
|
|
|
|
2008-02-06 02:40:51 +01:00
|
|
|
# Check and do wanted notifications
|
2008-04-15 07:32:45 +02:00
|
|
|
msg = msgtxt
|
2008-02-06 02:40:51 +01:00
|
|
|
if subject:
|
|
|
|
msg = _('Subject: %s') % subject + '\n' + msg
|
|
|
|
focused = False
|
|
|
|
|
|
|
|
if self.control:
|
|
|
|
parent_win = self.control.parent_win
|
2009-09-21 21:22:57 +02:00
|
|
|
if parent_win and self.control == parent_win.get_active_control() and \
|
2008-02-06 02:40:51 +01:00
|
|
|
parent_win.window.has_focus:
|
|
|
|
focused = True
|
|
|
|
|
|
|
|
notify.notify('new_message', jid_of_control, self.conn.name, [msg_type,
|
|
|
|
first, nickname, msg, focused], advanced_notif_num)
|
|
|
|
|
|
|
|
if gajim.interface.remote_ctrl:
|
2008-09-30 17:21:44 +02:00
|
|
|
gajim.interface.remote_ctrl.raise_signal('NewMessage', (self.conn.name,
|
|
|
|
[full_jid_with_resource, msgtxt, tim, encrypted, msg_type, subject,
|
|
|
|
chatstate, msg_id, composing_xep, user_nick, xhtml, form_node]))
|
2008-02-06 02:40:51 +01:00
|
|
|
|
|
|
|
def roster_message(self, jid, msg, tim, encrypted=False, msg_type='',
|
|
|
|
subject=None, resource='', msg_id=None, user_nick='',
|
|
|
|
advanced_notif_num=None, xhtml=None, form_node=None):
|
2008-11-08 12:14:31 +01:00
|
|
|
'''display the message or show notification in the roster'''
|
2008-02-06 02:40:51 +01:00
|
|
|
contact = None
|
|
|
|
# if chat window will be for specific resource
|
|
|
|
resource_for_chat = resource
|
|
|
|
|
|
|
|
fjid = jid
|
|
|
|
|
|
|
|
# Try to catch the contact with correct resource
|
|
|
|
if resource:
|
|
|
|
fjid = jid + '/' + resource
|
|
|
|
contact = gajim.contacts.get_contact(self.conn.name, jid, resource)
|
|
|
|
|
|
|
|
highest_contact = gajim.contacts.get_contact_with_highest_priority(
|
|
|
|
self.conn.name, jid)
|
|
|
|
if not contact:
|
|
|
|
# If there is another resource, it may be a message from an invisible
|
|
|
|
# resource
|
|
|
|
lcontact = gajim.contacts.get_contacts(self.conn.name, jid)
|
|
|
|
if (len(lcontact) > 1 or (lcontact and lcontact[0].resource and \
|
|
|
|
lcontact[0].show != 'offline')) and jid.find('@') > 0:
|
|
|
|
contact = gajim.contacts.copy_contact(highest_contact)
|
|
|
|
contact.resource = resource
|
|
|
|
if resource:
|
|
|
|
fjid = jid + '/' + resource
|
|
|
|
contact.priority = 0
|
|
|
|
contact.show = 'offline'
|
|
|
|
contact.status = ''
|
|
|
|
gajim.contacts.add_contact(self.conn.name, contact)
|
|
|
|
|
|
|
|
else:
|
|
|
|
# Default to highest prio
|
|
|
|
fjid = jid
|
|
|
|
resource_for_chat = None
|
|
|
|
contact = highest_contact
|
|
|
|
|
|
|
|
if not contact:
|
|
|
|
# contact is not in roster
|
2008-05-13 03:59:10 +02:00
|
|
|
contact = gajim.interface.roster.add_to_not_in_the_roster(
|
|
|
|
self.conn.name, jid, user_nick)
|
|
|
|
|
|
|
|
if not self.control:
|
2009-02-09 20:38:05 +01:00
|
|
|
ctrl = gajim.interface.msg_win_mgr.get_control(fjid, self.conn.name)
|
|
|
|
if ctrl:
|
|
|
|
self.control = ctrl
|
|
|
|
self.control.set_session(self)
|
|
|
|
else:
|
|
|
|
# if no control exists and message comes from highest prio, the new
|
|
|
|
# control shouldn't have a resource
|
|
|
|
if highest_contact and contact.resource == highest_contact.resource\
|
|
|
|
and not jid == gajim.get_jid_from_account(self.conn.name):
|
|
|
|
fjid = jid
|
|
|
|
resource_for_chat = None
|
2008-02-06 02:40:51 +01:00
|
|
|
|
|
|
|
# Do we have a queue?
|
|
|
|
no_queue = len(gajim.events.get_events(self.conn.name, fjid)) == 0
|
|
|
|
|
|
|
|
popup = helpers.allow_popup_window(self.conn.name, advanced_notif_num)
|
|
|
|
|
|
|
|
if msg_type == 'normal' and popup: # it's single message to be autopopuped
|
2008-05-13 03:59:10 +02:00
|
|
|
dialogs.SingleMessageWindow(self.conn.name, contact.jid,
|
|
|
|
action='receive', from_whom=jid, subject=subject, message=msg,
|
|
|
|
resource=resource, session=self, form_node=form_node)
|
2008-02-06 02:40:51 +01:00
|
|
|
return
|
|
|
|
|
|
|
|
# We print if window is opened and it's not a single message
|
|
|
|
if self.control and msg_type != 'normal':
|
|
|
|
typ = ''
|
|
|
|
|
|
|
|
if msg_type == 'error':
|
2009-02-09 20:38:05 +01:00
|
|
|
typ = 'error'
|
2008-02-06 02:40:51 +01:00
|
|
|
|
2008-05-13 03:59:10 +02:00
|
|
|
self.control.print_conversation(msg, typ, tim=tim, encrypted=encrypted,
|
|
|
|
subject=subject, xhtml=xhtml)
|
2008-02-06 02:40:51 +01:00
|
|
|
|
|
|
|
if msg_id:
|
|
|
|
gajim.logger.set_read_messages([msg_id])
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
# We save it in a queue
|
|
|
|
type_ = 'chat'
|
|
|
|
event_type = 'message_received'
|
|
|
|
|
|
|
|
if msg_type == 'normal':
|
|
|
|
type_ = 'normal'
|
|
|
|
event_type = 'single_message_received'
|
|
|
|
|
2008-09-30 17:21:44 +02:00
|
|
|
show_in_roster = notify.get_show_in_roster(event_type, self.conn.name,
|
|
|
|
contact, self)
|
|
|
|
show_in_systray = notify.get_show_in_systray(event_type, self.conn.name,
|
|
|
|
contact)
|
2008-02-06 02:40:51 +01:00
|
|
|
|
|
|
|
event = gajim.events.create_event(type_, (msg, subject, msg_type, tim,
|
|
|
|
encrypted, resource, msg_id, xhtml, self, form_node),
|
|
|
|
show_in_roster=show_in_roster, show_in_systray=show_in_systray)
|
|
|
|
|
|
|
|
gajim.events.add_event(self.conn.name, fjid, event)
|
|
|
|
|
|
|
|
if popup:
|
|
|
|
if not self.control:
|
2008-06-03 08:06:42 +02:00
|
|
|
self.control = gajim.interface.new_chat(contact,
|
|
|
|
self.conn.name, resource=resource_for_chat, session=self)
|
2008-02-06 02:40:51 +01:00
|
|
|
|
|
|
|
if len(gajim.events.get_events(self.conn.name, fjid)):
|
|
|
|
self.control.read_queue()
|
|
|
|
else:
|
|
|
|
if no_queue: # We didn't have a queue: we change icons
|
|
|
|
gajim.interface.roster.draw_contact(jid, self.conn.name)
|
|
|
|
|
|
|
|
gajim.interface.roster.show_title() # we show the * or [n]
|
2009-04-08 09:55:52 +02:00
|
|
|
# Select the big brother contact in roster, it's visible because it has
|
|
|
|
# events.
|
|
|
|
family = gajim.contacts.get_metacontacts_family(self.conn.name, jid)
|
|
|
|
if family:
|
|
|
|
nearby_family, bb_jid, bb_account = \
|
|
|
|
gajim.interface.roster._get_nearby_family_and_big_brother(family,
|
|
|
|
self.conn.name)
|
|
|
|
else:
|
|
|
|
bb_jid, bb_account = jid, self.conn.name
|
|
|
|
gajim.interface.roster.select_contact(bb_jid, bb_account)
|
2008-06-21 21:12:47 +02:00
|
|
|
|
|
|
|
# ---- ESessions stuff ---
|
|
|
|
|
|
|
|
def handle_negotiation(self, form):
|
|
|
|
if form.getField('accept') and not form['accept'] in ('1', 'true'):
|
|
|
|
self.cancelled_negotiation()
|
|
|
|
return
|
|
|
|
|
|
|
|
# encrypted session states. these are described in stanza_session.py
|
|
|
|
|
|
|
|
try:
|
|
|
|
# bob responds
|
|
|
|
if form.getType() == 'form' and 'security' in form.asDict():
|
2008-08-30 03:31:11 +02:00
|
|
|
# we don't support 3-message negotiation as the responder
|
|
|
|
if 'dhkeys' in form.asDict():
|
2008-09-30 17:21:44 +02:00
|
|
|
self.fail_bad_negotiation('3 message negotiation not supported '
|
|
|
|
'when responding', ('dhkeys',))
|
2008-08-30 03:31:11 +02:00
|
|
|
return
|
|
|
|
|
|
|
|
negotiated, not_acceptable, ask_user = self.verify_options_bob(form)
|
|
|
|
|
|
|
|
if ask_user:
|
|
|
|
def accept_nondefault_options(is_checked):
|
|
|
|
self.dialog.destroy()
|
|
|
|
negotiated.update(ask_user)
|
2008-06-21 21:12:47 +02:00
|
|
|
self.respond_e2e_bob(form, negotiated, not_acceptable)
|
|
|
|
|
2008-08-30 03:31:11 +02:00
|
|
|
def reject_nondefault_options():
|
|
|
|
self.dialog.destroy()
|
|
|
|
for key in ask_user.keys():
|
|
|
|
not_acceptable.append(key)
|
|
|
|
self.respond_e2e_bob(form, negotiated, not_acceptable)
|
|
|
|
|
2008-09-30 17:21:44 +02:00
|
|
|
self.dialog = dialogs.YesNoDialog(_('Confirm these session '
|
|
|
|
'options'),
|
2008-08-30 03:31:11 +02:00
|
|
|
_('''The remote client wants to negotiate an session with these features:
|
|
|
|
|
|
|
|
%s
|
2008-06-21 21:12:47 +02:00
|
|
|
|
2008-09-30 17:21:44 +02:00
|
|
|
Are these options acceptable?''') % (negotiation.describe_features(
|
|
|
|
ask_user)),
|
|
|
|
on_response_yes=accept_nondefault_options,
|
|
|
|
on_response_no=reject_nondefault_options)
|
2008-08-30 03:31:11 +02:00
|
|
|
else:
|
|
|
|
self.respond_e2e_bob(form, negotiated, not_acceptable)
|
2008-06-21 21:12:47 +02:00
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
# alice accepts
|
|
|
|
elif self.status == 'requested-e2e' and form.getType() == 'submit':
|
2008-09-30 17:21:44 +02:00
|
|
|
negotiated, not_acceptable, ask_user = self.verify_options_alice(
|
|
|
|
form)
|
2008-06-21 21:12:47 +02:00
|
|
|
|
|
|
|
if ask_user:
|
|
|
|
def accept_nondefault_options(is_checked):
|
|
|
|
dialog.destroy()
|
|
|
|
|
|
|
|
negotiated.update(ask_user)
|
|
|
|
|
|
|
|
try:
|
|
|
|
self.accept_e2e_alice(form, negotiated)
|
|
|
|
except exceptions.NegotiationError, details:
|
|
|
|
self.fail_bad_negotiation(details)
|
|
|
|
|
|
|
|
def reject_nondefault_options():
|
|
|
|
self.reject_negotiation()
|
|
|
|
dialog.destroy()
|
|
|
|
|
|
|
|
dialog = dialogs.YesNoDialog(_('Confirm these session options'),
|
2008-09-30 17:21:44 +02:00
|
|
|
_('The remote client selected these options:\n\n%s\n\n'
|
|
|
|
'Continue with the session?') % (
|
|
|
|
negotiation.describe_features(ask_user)),
|
|
|
|
on_response_yes = accept_nondefault_options,
|
|
|
|
on_response_no = reject_nondefault_options)
|
2008-06-21 21:12:47 +02:00
|
|
|
else:
|
|
|
|
try:
|
|
|
|
self.accept_e2e_alice(form, negotiated)
|
|
|
|
except exceptions.NegotiationError, details:
|
|
|
|
self.fail_bad_negotiation(details)
|
|
|
|
|
|
|
|
return
|
|
|
|
elif self.status == 'responded-e2e' and form.getType() == 'result':
|
|
|
|
try:
|
|
|
|
self.accept_e2e_bob(form)
|
|
|
|
except exceptions.NegotiationError, details:
|
|
|
|
self.fail_bad_negotiation(details)
|
|
|
|
|
|
|
|
return
|
|
|
|
elif self.status == 'identified-alice' and form.getType() == 'result':
|
|
|
|
try:
|
|
|
|
self.final_steps_alice(form)
|
|
|
|
except exceptions.NegotiationError, details:
|
|
|
|
self.fail_bad_negotiation(details)
|
|
|
|
|
|
|
|
return
|
|
|
|
except exceptions.Cancelled:
|
|
|
|
# user cancelled the negotiation
|
|
|
|
|
|
|
|
self.reject_negotiation()
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
if form.getField('terminate') and\
|
|
|
|
form.getField('terminate').getValue() in ('1', 'true'):
|
|
|
|
self.acknowledge_termination()
|
|
|
|
|
2008-07-26 07:28:15 +02:00
|
|
|
self.conn.delete_session(str(self.jid), self.thread_id)
|
2008-06-21 21:12:47 +02:00
|
|
|
|
|
|
|
return
|
|
|
|
|
2008-09-30 17:21:44 +02:00
|
|
|
# non-esession negotiation. this isn't very useful, but i'm keeping it
|
|
|
|
# around to test my test suite.
|
2008-06-21 21:12:47 +02:00
|
|
|
if form.getType() == 'form':
|
|
|
|
if not self.control:
|
|
|
|
jid, resource = gajim.get_room_and_nick_from_fjid(self.jid)
|
|
|
|
|
|
|
|
account = self.conn.name
|
|
|
|
contact = gajim.contacts.get_contact(account, self.jid, resource)
|
|
|
|
|
|
|
|
if not contact:
|
2008-07-05 21:04:27 +02:00
|
|
|
contact = gajim.contacts.create_contact(jid=jid,
|
2008-09-30 17:21:44 +02:00
|
|
|
resource=resource, show=self.conn.get_status())
|
2008-06-21 21:12:47 +02:00
|
|
|
|
2008-09-30 17:21:44 +02:00
|
|
|
gajim.interface.new_chat(contact, account, resource=resource,
|
|
|
|
session=self)
|
2008-06-21 21:12:47 +02:00
|
|
|
|
|
|
|
negotiation.FeatureNegotiationWindow(account, self.jid, self, form)
|
2008-07-29 21:49:31 +02:00
|
|
|
|
2008-08-15 05:20:23 +02:00
|
|
|
# vim: se ts=3:
|