Changeset 9829 for trunk/src/session.py

Show
Ignore:
Timestamp:
06/21/08 21:12:47 (5 months ago)
Author:
bct
Message:

moved session negotiation handling from gajim.py to session.py

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/session.py

    r9826 r9829  
    88import common.xmpp 
    99 
     10import message_control 
     11 
     12import notify 
     13 
    1014import dialogs 
    11  
    12 import message_control 
    13  
    14 import notify 
     15import negotiation 
    1516 
    1617class ChatControlSession(stanza_session.EncryptedStanzaSession): 
     
    331332                # Select contact row in roster. 
    332333                gajim.interface.roster.select_contact(jid, self.conn.name) 
     334 
     335        # ---- ESessions stuff --- 
     336 
     337        def check_identity(self, on_success): 
     338                negotiation.show_sas_dialog(self, self.jid, self.sas, on_success) 
     339 
     340        def handle_negotiation(self, form): 
     341                if form.getField('accept') and not form['accept'] in ('1', 'true'): 
     342                        self.cancelled_negotiation() 
     343                        return 
     344 
     345                # encrypted session states. these are described in stanza_session.py 
     346 
     347                try: 
     348                        # bob responds 
     349                        if form.getType() == 'form' and 'security' in form.asDict(): 
     350                                def continue_with_negotiation(*args): 
     351                                        if len(args): 
     352                                                self.dialog.destroy() 
     353 
     354                                        # we don't support 3-message negotiation as the responder 
     355                                        if 'dhkeys' in form.asDict(): 
     356                                                self.fail_bad_negotiation('3 message negotiation not supported when responding', ('dhkeys',)) 
     357                                                return 
     358 
     359                                        negotiated, not_acceptable, ask_user = self.verify_options_bob(form) 
     360 
     361                                        if ask_user: 
     362                                                def accept_nondefault_options(is_checked): 
     363                                                        self.dialog.destroy() 
     364                                                        negotiated.update(ask_user) 
     365                                                        self.respond_e2e_bob(form, negotiated, not_acceptable) 
     366 
     367                                                def reject_nondefault_options(): 
     368                                                        self.dialog.destroy() 
     369                                                        for key in ask_user.keys(): 
     370                                                                not_acceptable.append(key) 
     371                                                        self.respond_e2e_bob(form, negotiated, not_acceptable) 
     372 
     373                                                self.dialog = dialogs.YesNoDialog(_('Confirm these session options'), 
     374                                                        _('''The remote client wants to negotiate an session with these features: 
     375 
     376                %s 
     377 
     378                Are these options acceptable?''') % (negotiation.describe_features(ask_user)), 
     379                                                                on_response_yes=accept_nondefault_options, 
     380                                                                on_response_no=reject_nondefault_options) 
     381                                        else: 
     382                                                self.respond_e2e_bob(form, negotiated, not_acceptable) 
     383 
     384                                def ignore_negotiation(widget): 
     385                                        self.dialog.destroy() 
     386                                        return 
     387 
     388                                continue_with_negotiation() 
     389 
     390                                return 
     391 
     392                        # alice accepts 
     393                        elif self.status == 'requested-e2e' and form.getType() == 'submit': 
     394                                negotiated, not_acceptable, ask_user = self.verify_options_alice(form) 
     395 
     396                                if ask_user: 
     397                                        def accept_nondefault_options(is_checked): 
     398                                                dialog.destroy() 
     399 
     400                                                negotiated.update(ask_user) 
     401 
     402                                                try: 
     403                                                        self.accept_e2e_alice(form, negotiated) 
     404                                                except exceptions.NegotiationError, details: 
     405                                                        self.fail_bad_negotiation(details) 
     406 
     407                                        def reject_nondefault_options(): 
     408                                                self.reject_negotiation() 
     409                                                dialog.destroy() 
     410 
     411                                        dialog = dialogs.YesNoDialog(_('Confirm these session options'), 
     412                                                        _('The remote client selected these options:\n\n%s\n\nContinue with the session?') % (negotiation.describe_features(ask_user)), 
     413                                                        on_response_yes = accept_nondefault_options, 
     414                                                        on_response_no = reject_nondefault_options) 
     415                                else: 
     416                                        try: 
     417                                                self.accept_e2e_alice(form, negotiated) 
     418                                        except exceptions.NegotiationError, details: 
     419                                                self.fail_bad_negotiation(details) 
     420 
     421                                return 
     422                        elif self.status == 'responded-e2e' and form.getType() == 'result': 
     423                                try: 
     424                                        self.accept_e2e_bob(form) 
     425                                except exceptions.NegotiationError, details: 
     426                                        self.fail_bad_negotiation(details) 
     427 
     428                                return 
     429                        elif self.status == 'identified-alice' and form.getType() == 'result': 
     430                                try: 
     431                                        self.final_steps_alice(form) 
     432                                except exceptions.NegotiationError, details: 
     433                                        self.fail_bad_negotiation(details) 
     434 
     435                                return 
     436                except exceptions.Cancelled: 
     437                        # user cancelled the negotiation 
     438 
     439                        self.reject_negotiation() 
     440 
     441                        return 
     442 
     443                if form.getField('terminate') and\ 
     444                form.getField('terminate').getValue() in ('1', 'true'): 
     445                        self.acknowledge_termination() 
     446 
     447                        self.conn.delete_session(self.jid, self.thread_id) 
     448 
     449                        return 
     450 
     451                # non-esession negotiation. this isn't very useful, but i'm keeping it around 
     452                # to test my test suite. 
     453                if form.getType() == 'form': 
     454                        if not self.control: 
     455                                jid, resource = gajim.get_room_and_nick_from_fjid(self.jid) 
     456 
     457                                account = self.conn.name 
     458                                contact = gajim.contacts.get_contact(account, self.jid, resource) 
     459 
     460                                if not contact: 
     461                                        contact = gajim.contacts.create_contact(jid = jidk, 
     462                                                        resource = resource, show = self.conn.get_status()) 
     463 
     464                                gajim.interface.new_chat(contact, account, 
     465                                        resource = resource, session = self) 
     466 
     467                        negotiation.FeatureNegotiationWindow(account, self.jid, self, form)