automatically start an esession when the remote client supports it

This commit is contained in:
Brendan Taylor 2008-07-14 00:26:14 +00:00
parent 814c9c118a
commit a407414dd9
1 changed files with 20 additions and 13 deletions

View File

@ -45,7 +45,7 @@ from common.contacts import GC_Contact
from common.logger import Constants from common.logger import Constants
constants = Constants() constants = Constants()
from common.rst_xhtml_generator import create_xhtml from common.rst_xhtml_generator import create_xhtml
from common.xmpp.protocol import NS_XHTML, NS_FILE, NS_MUC from common.xmpp.protocol import NS_XHTML, NS_FILE, NS_MUC, NS_ESESSION
try: try:
import gtkspell import gtkspell
@ -1128,10 +1128,11 @@ class ChatControl(ChatControlBase):
self.print_esession_details() self.print_esession_details()
# Enable encryption if needed # Enable encryption if needed
e2e_is_active = hasattr(self, 'session') and self.session and self.session.enable_encryption e2e_is_active = self.session and self.session.enable_encryption
self.gpg_is_active = False self.gpg_is_active = False
gpg_pref = gajim.config.get_per('contacts', contact.jid, 'gpg_enabled') gpg_pref = gajim.config.get_per('contacts', contact.jid, 'gpg_enabled')
# try GPG first
if not e2e_is_active and gpg_pref and gajim.config.get_per('accounts', self.account, 'keyid') and\ if not e2e_is_active and gpg_pref and gajim.config.get_per('accounts', self.account, 'keyid') and\
gajim.connections[self.account].USE_GPG: gajim.connections[self.account].USE_GPG:
self.gpg_is_active = True self.gpg_is_active = True
@ -1143,6 +1144,9 @@ class ChatControl(ChatControlBase):
self.session.loggable = gajim.config.get('log_encrypted_sessions') self.session.loggable = gajim.config.get('log_encrypted_sessions')
self._show_lock_image(self.gpg_is_active, 'GPG', self.gpg_is_active, self.session and \ self._show_lock_image(self.gpg_is_active, 'GPG', self.gpg_is_active, self.session and \
self.session.is_loggable(), self.session and self.session.verified_identity) self.session.is_loggable(), self.session and self.session.verified_identity)
# then try E2E
elif not e2e_is_active and gajim.capscache.is_supported(contact, NS_ESESSION):
self.begin_e2e_negotiation()
self.status_tooltip = gtk.Tooltips() self.status_tooltip = gtk.Tooltips()
@ -1793,23 +1797,23 @@ class ChatControl(ChatControlBase):
contact = self.parent_win.get_active_contact() contact = self.parent_win.get_active_contact()
jid = contact.jid jid = contact.jid
e2e_is_active = self.session is not None and self.session.enable_encryption
# check if we support and use gpg # check if we support and use gpg
if not gajim.config.get_per('accounts', self.account, 'keyid') or\ if not gajim.config.get_per('accounts', self.account, 'keyid') or\
not gajim.connections[self.account].USE_GPG or\ not gajim.connections[self.account].USE_GPG or\
gajim.jid_is_transport(jid): gajim.jid_is_transport(jid):
toggle_gpg_menuitem.set_sensitive(False) toggle_gpg_menuitem.set_sensitive(False)
else: else:
e2e_is_active = int(self.session is not None and self.session.enable_encryption)
toggle_gpg_menuitem.set_sensitive(not e2e_is_active) toggle_gpg_menuitem.set_sensitive(not e2e_is_active)
toggle_gpg_menuitem.set_active(self.gpg_is_active) toggle_gpg_menuitem.set_active(self.gpg_is_active)
# TODO: check that the remote client supports e2e # disable esessions if we or the other client don't support them
if not gajim.HAVE_PYCRYPTO: if not gajim.HAVE_PYCRYPTO or \
not gajim.capscache.is_supported(contact, NS_ESESSION):
toggle_e2e_menuitem.set_sensitive(False) toggle_e2e_menuitem.set_sensitive(False)
else: else:
isactive = int(self.session is not None and \ toggle_e2e_menuitem.set_active(e2e_is_active)
self.session.enable_encryption)
toggle_e2e_menuitem.set_active(isactive)
toggle_e2e_menuitem.set_sensitive(not self.gpg_is_active) toggle_e2e_menuitem.set_sensitive(not self.gpg_is_active)
# add_to_roster_menuitem # add_to_roster_menuitem
@ -2326,6 +2330,9 @@ class ChatControl(ChatControlBase):
gajim.connections[self.account].delete_session(jid, thread_id) gajim.connections[self.account].delete_session(jid, thread_id)
else: else:
self.begin_e2e_negotiation()
def begin_e2e_negotiation(self):
if not self.session: if not self.session:
fjid = self.contact.get_full_jid() fjid = self.contact.get_full_jid()
new_sess = gajim.connections[self.account].make_new_session(fjid) new_sess = gajim.connections[self.account].make_new_session(fjid)