use NEC to handle plain connection events

This commit is contained in:
Yann Leboulanger 2010-11-24 15:38:16 +01:00
parent 11efeb8f3d
commit a45cc993e8
3 changed files with 22 additions and 13 deletions

View File

@ -1201,7 +1201,8 @@ class Connection(CommonConnection, ConnectionHandlers):
con.RegisterDisconnectHandler(self._on_disconnected) con.RegisterDisconnectHandler(self._on_disconnected)
if _con_type == 'plain' and gajim.config.get_per('accounts', self.name, if _con_type == 'plain' and gajim.config.get_per('accounts', self.name,
'warn_when_plaintext_connection'): 'warn_when_plaintext_connection'):
self.dispatch('PLAIN_CONNECTION', (con,)) gajim.nec.push_incoming_event(PlainConnectionEvent(None, conn=self,
xmpp_client=con))
return True return True
if _con_type in ('tls', 'ssl') and con.Connection.ssl_lib != 'PYOPENSSL' \ if _con_type in ('tls', 'ssl') and con.Connection.ssl_lib != 'PYOPENSSL' \
and gajim.config.get_per('accounts', self.name, and gajim.config.get_per('accounts', self.name,

View File

@ -1431,3 +1431,7 @@ class AtomEntryReceived(nec.NetworkIncomingEvent):
def generate(self): def generate(self):
self.atom_entry = atom.OldEntry(node=entry) self.atom_entry = atom.OldEntry(node=entry)
return True return True
class PlainConnectionEvent(nec.NetworkIncomingEvent):
name = 'plain-connection'
base_network_events = []

View File

@ -1493,7 +1493,7 @@ class Interface:
dialogs.YesNoDialog(pritext, sectext, on_response_yes=on_yes, dialogs.YesNoDialog(pritext, sectext, on_response_yes=on_yes,
on_response_no=on_no) on_response_no=on_no)
def handle_event_plain_connection(self, account, data): def handle_event_plain_connection(self, obj):
# ('PLAIN_CONNECTION', account, (connection)) # ('PLAIN_CONNECTION', account, (connection))
def on_ok(is_checked): def on_ok(is_checked):
if not is_checked[0]: if not is_checked[0]:
@ -1501,25 +1501,29 @@ class Interface:
return return
# On cancel call del self.instances, so don't call it another time # On cancel call del self.instances, so don't call it another time
# before # before
del self.instances[account]['online_dialog']['plain_connection'] del self.instances[obj.conn.name]['online_dialog']\
['plain_connection']
if is_checked[1]: if is_checked[1]:
gajim.config.set_per('accounts', account, gajim.config.set_per('accounts', obj.conn.name,
'warn_when_plaintext_connection', False) 'warn_when_plaintext_connection', False)
gajim.connections[account].connection_accepted(data[0], 'plain') obj.conn.connection_accepted(obj.xmpp_client, 'plain')
def on_cancel(): def on_cancel():
del self.instances[account]['online_dialog']['plain_connection'] del self.instances[obj.conn.name]['online_dialog']\
gajim.connections[account].disconnect(on_purpose=True) ['plain_connection']
self.handle_event_status(account, 'offline') obj.conn.disconnect(on_purpose=True)
self.handle_event_status(obj.conn.name, 'offline')
pritext = _('Insecure connection') pritext = _('Insecure connection')
sectext = _('You are about to connect to the server with an insecure ' sectext = _('You are about to connect to the server with an insecure '
'connection. This means all your conversations will be ' 'connection. This means all your conversations will be '
'exchanged unencrypted. Are you sure you want to do that?') 'exchanged unencrypted. Are you sure you want to do that?')
checktext1 = _('Yes, I really want to connect insecurely') checktext1 = _('Yes, I really want to connect insecurely')
checktext2 = _('_Do not ask me again') checktext2 = _('_Do not ask me again')
if 'plain_connection' in self.instances[account]['online_dialog']: if 'plain_connection' in self.instances[obj.conn.name]['online_dialog']:
self.instances[account]['online_dialog']['plain_connection'].\ self.instances[obj.conn.name]['online_dialog']['plain_connection'].\
destroy() destroy()
self.instances[account]['online_dialog']['plain_connection'] = \ self.instances[obj.conn.name]['online_dialog']['plain_connection'] = \
dialogs.ConfirmationDialogDoubleCheck(pritext, sectext, checktext1, dialogs.ConfirmationDialogDoubleCheck(pritext, sectext, checktext1,
checktext2, on_response_ok=on_ok, on_response_cancel=on_cancel, checktext2, on_response_ok=on_ok, on_response_cancel=on_cancel,
is_modal=False) is_modal=False)
@ -1630,7 +1634,6 @@ class Interface:
'PASSWORD_REQUIRED': [self.handle_event_password_required], 'PASSWORD_REQUIRED': [self.handle_event_password_required],
'SSL_ERROR': [self.handle_event_ssl_error], 'SSL_ERROR': [self.handle_event_ssl_error],
'FINGERPRINT_ERROR': [self.handle_event_fingerprint_error], 'FINGERPRINT_ERROR': [self.handle_event_fingerprint_error],
'PLAIN_CONNECTION': [self.handle_event_plain_connection],
'INSECURE_SSL_CONNECTION': \ 'INSECURE_SSL_CONNECTION': \
[self.handle_event_insecure_ssl_connection], [self.handle_event_insecure_ssl_connection],
'INSECURE_PASSWORD': [self.handle_event_insecure_password], 'INSECURE_PASSWORD': [self.handle_event_insecure_password],
@ -1656,6 +1659,7 @@ class Interface:
'muc-admin-received': [self.handle_event_gc_affiliation], 'muc-admin-received': [self.handle_event_gc_affiliation],
'muc-owner-received': [self.handle_event_gc_config], 'muc-owner-received': [self.handle_event_gc_config],
'our-show': [self.handle_event_status], 'our-show': [self.handle_event_status],
'plain-connection': [self.handle_event_plain_connection],
'presence-received': [self.handle_event_presence], 'presence-received': [self.handle_event_presence],
'roster-info': [self.handle_event_roster_info], 'roster-info': [self.handle_event_roster_info],
'roster-item-exchange-received': \ 'roster-item-exchange-received': \