コード例 #1
0
ファイル: session.py プロジェクト: irl/gajim
    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:
            if form.getType() == 'form' and 'security' in form.asDict():
                security_options = [x[1] for x in form.getField('security').\
                    getOptions()]
                if security_options == ['none']:
                    self.respond_archiving(form)
                else:
                    # bob responds

                    # we don't support 3-message negotiation as the responder
                    if 'dhkeys' in form.asDict():
                        self.fail_bad_negotiation('3 message negotiation not '
                            'supported when responding', ('dhkeys',))
                        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)
                            self.respond_e2e_bob(form, negotiated,
                                not_acceptable)

                        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)

                        self.dialog = dialogs.YesNoDialog(_('Confirm these '
                            'session options'),
                            _('The remote client wants to negotiate a session '
                            'with these features:\n\n%s\n\nAre these options '
                            'acceptable?''') % (
                            negotiation.describe_features(ask_user)),
                            on_response_yes=accept_nondefault_options,
                            on_response_no=reject_nondefault_options,
                            transient_for=self.control.parent_win.window)
                    else:
                        self.respond_e2e_bob(form, negotiated, not_acceptable)

                return

            elif self.status == 'requested-archiving' and form.getType() == \
            'submit':
                try:
                    self.archiving_accepted(form)
                except exceptions.NegotiationError as details:
                    self.fail_bad_negotiation(details)

                return

            # alice accepts
            elif self.status == 'requested-e2e' and form.getType() == 'submit':
                negotiated, not_acceptable, ask_user = self.verify_options_alice(
                        form)

                if ask_user:
                    def accept_nondefault_options(is_checked):
                        if dialog:
                            dialog.destroy()

                        if is_checked:
                            allow_no_log_for = gajim.config.get_per(
                                'accounts', self.conn.name,
                                'allow_no_log_for').split()
                            jid = str(self.jid)
                            if jid not in allow_no_log_for:
                                allow_no_log_for.append(jid)
                                gajim.config.set_per('accounts', self.conn.name,
                                'allow_no_log_for', ' '.join(allow_no_log_for))

                        negotiated.update(ask_user)

                        try:
                            self.accept_e2e_alice(form, negotiated)
                        except exceptions.NegotiationError as details:
                            self.fail_bad_negotiation(details)

                    def reject_nondefault_options():
                        self.reject_negotiation()
                        dialog.destroy()

                    allow_no_log_for = gajim.config.get_per('accounts',
                        self.conn.name, 'allow_no_log_for').split()
                    if str(self.jid) in allow_no_log_for:
                        dialog = None
                        accept_nondefault_options(False)
                    else:
                        dialog = dialogs.YesNoDialog(_('Confirm these session '
                            'options'),
                            _('The remote client selected these options:\n\n%s'
                            '\n\nContinue with the session?') % (
                            negotiation.describe_features(ask_user)),
                            _('Always accept for this contact'),
                            on_response_yes = accept_nondefault_options,
                            on_response_no = reject_nondefault_options,
                            transient_for=self.control.parent_win.window)
                else:
                    try:
                        self.accept_e2e_alice(form, negotiated)
                    except exceptions.NegotiationError as details:
                        self.fail_bad_negotiation(details)

                return
            elif self.status == 'responded-archiving' and form.getType() == \
            'result':
                try:
                    self.we_accept_archiving(form)
                except exceptions.NegotiationError as 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 as 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 as 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()

            self.conn.delete_session(str(self.jid), self.thread_id)

            return

        # non-esession negotiation. this isn't very useful, but i'm keeping it
        # around to test my test suite.
        if form.getType() == 'form':
            if not self.control:
                jid, resource = gajim.get_room_and_nick_from_fjid(str(self.jid))

                account = self.conn.name
                contact = gajim.contacts.get_contact(account, str(self.jid),
                    resource)

                if not contact:
                    contact = gajim.contacts.create_contact(jid=jid, account=account,
                            resource=resource, show=self.conn.get_status())

                gajim.interface.new_chat(contact, account, resource=resource,
                        session=self)

            negotiation.FeatureNegotiationWindow(account, str(self.jid), self,
                form)
コード例 #2
0
ファイル: session.py プロジェクト: kevin-teddy/gajim
	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():
				# we don't support 3-message negotiation as the responder
				if 'dhkeys' in form.asDict():
					self.fail_bad_negotiation('3 message negotiation not supported '
						'when responding', ('dhkeys',))
					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)
						self.respond_e2e_bob(form, negotiated, not_acceptable)

					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)

					self.dialog = dialogs.YesNoDialog(_('Confirm these session '
						'options'),
						_('''The remote client wants to negotiate an session with these features:

	%s

	Are these options acceptable?''') % (negotiation.describe_features(
						ask_user)),
						on_response_yes=accept_nondefault_options,
						on_response_no=reject_nondefault_options)
				else:
					self.respond_e2e_bob(form, negotiated, not_acceptable)

				return

			# alice accepts
			elif self.status == 'requested-e2e' and form.getType() == 'submit':
				negotiated, not_acceptable, ask_user = self.verify_options_alice(
					form)

				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'),
						_('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)
				else:
					try:
						self.accept_e2e_alice(form, negotiated)
					except exceptions.NegotiationError, details:
						self.fail_bad_negotiation(details)

				return
コード例 #3
0
ファイル: session.py プロジェクト: jabber-at/gajim
    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:
            if form.getType() == 'form' and 'security' in form.asDict():
                security_options = [x[1] for x in form.getField('security').\
                    getOptions()]
                if security_options == ['none']:
                    self.respond_archiving(form)
                else:
                    # bob responds

                    # we don't support 3-message negotiation as the responder
                    if 'dhkeys' in form.asDict():
                        self.fail_bad_negotiation('3 message negotiation not '
                            'supported when responding', ('dhkeys',))
                        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)
                            self.respond_e2e_bob(form, negotiated,
                                not_acceptable)

                        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)

                        self.dialog = dialogs.YesNoDialog(_('Confirm these '
                            'session options'),
                            _('The remote client wants to negotiate a session '
                            'with these features:\n\n%s\n\nAre these options '
                            'acceptable?''') % (
                            negotiation.describe_features(ask_user)),
                            on_response_yes=accept_nondefault_options,
                            on_response_no=reject_nondefault_options,
                            transient_for=self.control.parent_win.window)
                    else:
                        self.respond_e2e_bob(form, negotiated, not_acceptable)

                return

            elif self.status == 'requested-archiving' and form.getType() == \
            'submit':
                try:
                    self.archiving_accepted(form)
                except exceptions.NegotiationError, details:
                    self.fail_bad_negotiation(details)

                return

            # alice accepts
            elif self.status == 'requested-e2e' and form.getType() == 'submit':
                negotiated, not_acceptable, ask_user = self.verify_options_alice(
                        form)

                if ask_user:
                    def accept_nondefault_options(is_checked):
                        if dialog:
                            dialog.destroy()

                        if is_checked:
                            allow_no_log_for = gajim.config.get_per(
                                'accounts', self.conn.name,
                                'allow_no_log_for').split()
                            jid = str(self.jid)
                            if jid not in allow_no_log_for:
                                allow_no_log_for.append(jid)
                                gajim.config.set_per('accounts', self.conn.name,
                                'allow_no_log_for', ' '.join(allow_no_log_for))

                        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()

                    allow_no_log_for = gajim.config.get_per('accounts',
                        self.conn.name, 'allow_no_log_for').split()
                    if str(self.jid) in allow_no_log_for:
                        dialog = None
                        accept_nondefault_options(False)
                    else:
                        dialog = dialogs.YesNoDialog(_('Confirm these session '
                            'options'),
                            _('The remote client selected these options:\n\n%s'
                            '\n\nContinue with the session?') % (
                            negotiation.describe_features(ask_user)),
                            _('Always accept for this contact'),
                            on_response_yes = accept_nondefault_options,
                            on_response_no = reject_nondefault_options,
                            transient_for=self.control.parent_win.window)
コード例 #4
0
ファイル: session.py プロジェクト: tdruiva/gajim
    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():
                # we don't support 3-message negotiation as the responder
                if 'dhkeys' in form.asDict():
                    self.fail_bad_negotiation(
                        '3 message negotiation not supported '
                        'when responding', ('dhkeys', ))
                    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)
                        self.respond_e2e_bob(form, negotiated, not_acceptable)

                    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)

                    self.dialog = dialogs.YesNoDialog(
                        _('Confirm these session '
                          'options'),
                        _('''The remote client wants to negotiate an session with these features:

	%s

	Are these options acceptable?''') % (negotiation.describe_features(ask_user)),
                        on_response_yes=accept_nondefault_options,
                        on_response_no=reject_nondefault_options)
                else:
                    self.respond_e2e_bob(form, negotiated, not_acceptable)

                return

            # alice accepts
            elif self.status == 'requested-e2e' and form.getType() == 'submit':
                negotiated, not_acceptable, ask_user = self.verify_options_alice(
                    form)

                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'),
                        _('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)
                else:
                    try:
                        self.accept_e2e_alice(form, negotiated)
                    except exceptions.NegotiationError, details:
                        self.fail_bad_negotiation(details)

                return
コード例 #5
0
ファイル: session.py プロジェクト: lheckemann/gajim
    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:
            if form.getType() == 'form' and 'security' in form.asDict():
                security_options = [x[1] for x in form.getField('security').\
                    getOptions()]
                if security_options == ['none']:
                    self.respond_archiving(form)
                else:
                    # bob responds

                    # we don't support 3-message negotiation as the responder
                    if 'dhkeys' in form.asDict():
                        self.fail_bad_negotiation('3 message negotiation not '
                            'supported when responding', ('dhkeys',))
                        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)
                            self.respond_e2e_bob(form, negotiated,
                                not_acceptable)

                        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)

                        self.dialog = dialogs.YesNoDialog(_('Confirm these '
                            'session options'),
                            _('The remote client wants to negotiate a session '
                            'with these features:\n\n%s\n\nAre these options '
                            'acceptable?''') % (
                            negotiation.describe_features(ask_user)),
                            on_response_yes=accept_nondefault_options,
                            on_response_no=reject_nondefault_options,
                            transient_for=self.control.parent_win.window)
                    else:
                        self.respond_e2e_bob(form, negotiated, not_acceptable)

                return

            elif self.status == 'requested-archiving' and form.getType() == \
            'submit':
                try:
                    self.archiving_accepted(form)
                except exceptions.NegotiationError as details:
                    self.fail_bad_negotiation(details)

                return

            # alice accepts
            elif self.status == 'requested-e2e' and form.getType() == 'submit':
                negotiated, not_acceptable, ask_user = self.verify_options_alice(
                        form)

                if ask_user:
                    def accept_nondefault_options(is_checked):
                        if dialog:
                            dialog.destroy()

                        if is_checked:
                            allow_no_log_for = gajim.config.get_per(
                                'accounts', self.conn.name,
                                'allow_no_log_for').split()
                            jid = str(self.jid)
                            if jid not in allow_no_log_for:
                                allow_no_log_for.append(jid)
                                gajim.config.set_per('accounts', self.conn.name,
                                'allow_no_log_for', ' '.join(allow_no_log_for))

                        negotiated.update(ask_user)

                        try:
                            self.accept_e2e_alice(form, negotiated)
                        except exceptions.NegotiationError as details:
                            self.fail_bad_negotiation(details)

                    def reject_nondefault_options():
                        self.reject_negotiation()
                        dialog.destroy()

                    allow_no_log_for = gajim.config.get_per('accounts',
                        self.conn.name, 'allow_no_log_for').split()
                    if str(self.jid) in allow_no_log_for:
                        dialog = None
                        accept_nondefault_options(False)
                    else:
                        dialog = dialogs.YesNoDialog(_('Confirm these session '
                            'options'),
                            _('The remote client selected these options:\n\n%s'
                            '\n\nContinue with the session?') % (
                            negotiation.describe_features(ask_user)),
                            _('Always accept for this contact'),
                            on_response_yes = accept_nondefault_options,
                            on_response_no = reject_nondefault_options,
                            transient_for=self.control.parent_win.window)
                else:
                    try:
                        self.accept_e2e_alice(form, negotiated)
                    except exceptions.NegotiationError as details:
                        self.fail_bad_negotiation(details)

                return
            elif self.status == 'responded-archiving' and form.getType() == \
            'result':
                try:
                    self.we_accept_archiving(form)
                except exceptions.NegotiationError as 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 as 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 as 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()

            self.conn.delete_session(str(self.jid), self.thread_id)

            return

        # non-esession negotiation. this isn't very useful, but i'm keeping it
        # around to test my test suite.
        if form.getType() == 'form':
            if not self.control:
                jid, resource = gajim.get_room_and_nick_from_fjid(str(self.jid))

                account = self.conn.name
                contact = gajim.contacts.get_contact(account, str(self.jid),
                    resource)

                if not contact:
                    contact = gajim.contacts.create_contact(jid=jid, account=account,
                            resource=resource, show=self.conn.get_status())

                gajim.interface.new_chat(contact, account, resource=resource,
                        session=self)

            negotiation.FeatureNegotiationWindow(account, str(self.jid), self,
                form)
コード例 #6
0
    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:
            if form.getType() == 'form' and 'security' in form.asDict():
                security_options = [x[1] for x in form.getField('security').\
                    getOptions()]
                if security_options == ['none']:
                    self.respond_archiving(form)
                else:
                    # bob responds

                    # we don't support 3-message negotiation as the responder
                    if 'dhkeys' in form.asDict():
                        self.fail_bad_negotiation(
                            '3 message negotiation not '
                            'supported when responding', ('dhkeys', ))
                        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)
                            self.respond_e2e_bob(form, negotiated,
                                                 not_acceptable)

                        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)

                        self.dialog = dialogs.YesNoDialog(
                            _('Confirm these '
                              'session options'),
                            _('The remote client wants to negotiate a session '
                              'with these features:\n\n%s\n\nAre these options '
                              'acceptable?'
                              '') % (negotiation.describe_features(ask_user)),
                            on_response_yes=accept_nondefault_options,
                            on_response_no=reject_nondefault_options,
                            transient_for=self.control.parent_win.window)
                    else:
                        self.respond_e2e_bob(form, negotiated, not_acceptable)

                return

            elif self.status == 'requested-archiving' and form.getType() == \
            'submit':
                try:
                    self.archiving_accepted(form)
                except exceptions.NegotiationError, details:
                    self.fail_bad_negotiation(details)

                return

            # alice accepts
            elif self.status == 'requested-e2e' and form.getType() == 'submit':
                negotiated, not_acceptable, ask_user = self.verify_options_alice(
                    form)

                if ask_user:

                    def accept_nondefault_options(is_checked):
                        if dialog:
                            dialog.destroy()

                        if is_checked:
                            allow_no_log_for = gajim.config.get_per(
                                'accounts', self.conn.name,
                                'allow_no_log_for').split()
                            jid = str(self.jid)
                            if jid not in allow_no_log_for:
                                allow_no_log_for.append(jid)
                                gajim.config.set_per(
                                    'accounts', self.conn.name,
                                    'allow_no_log_for',
                                    ' '.join(allow_no_log_for))

                        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()

                    allow_no_log_for = gajim.config.get_per(
                        'accounts', self.conn.name,
                        'allow_no_log_for').split()
                    if str(self.jid) in allow_no_log_for:
                        dialog = None
                        accept_nondefault_options(False)
                    else:
                        dialog = dialogs.YesNoDialog(
                            _('Confirm these session '
                              'options'),
                            _('The remote client selected these options:\n\n%s'
                              '\n\nContinue with the session?') %
                            (negotiation.describe_features(ask_user)),
                            _('Always accept for this contact'),
                            on_response_yes=accept_nondefault_options,
                            on_response_no=reject_nondefault_options,
                            transient_for=self.control.parent_win.window)