Changeset 9829 for trunk/src/gajim.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/gajim.py

    r9820 r9829  
    247247import notify 
    248248import message_control 
    249 import negotiation 
    250249 
    251250from chat_control import ChatControlBase 
     
    17521751                else: 
    17531752                        print 'failed decrypt, unable to find a control to notify you in.' 
    1754  
    1755         def handle_session_negotiation(self, account, data): 
    1756                 jid, session, form = data 
    1757  
    1758                 if form.getField('accept') and not form['accept'] in ('1', 'true'): 
    1759                         session.cancelled_negotiation() 
    1760                         return 
    1761  
    1762                 # encrypted session states. these are described in stanza_session.py 
    1763  
    1764                 try: 
    1765                         # bob responds 
    1766                         if form.getType() == 'form' and 'security' in form.asDict(): 
    1767                                 def continue_with_negotiation(*args): 
    1768                                         if len(args): 
    1769                                                 self.dialog.destroy() 
    1770  
    1771                                         # we don't support 3-message negotiation as the responder 
    1772                                         if 'dhkeys' in form.asDict(): 
    1773                                                 session.fail_bad_negotiation('3 message negotiation not supported when responding', ('dhkeys',)) 
    1774                                                 return 
    1775  
    1776                                         negotiated, not_acceptable, ask_user = session.verify_options_bob(form) 
    1777  
    1778                                         if ask_user: 
    1779                                                 def accept_nondefault_options(is_checked): 
    1780                                                         self.dialog.destroy() 
    1781                                                         negotiated.update(ask_user) 
    1782                                                         session.respond_e2e_bob(form, negotiated, not_acceptable) 
    1783  
    1784                                                 def reject_nondefault_options(): 
    1785                                                         self.dialog.destroy() 
    1786                                                         for key in ask_user.keys(): 
    1787                                                                 not_acceptable.append(key) 
    1788                                                         session.respond_e2e_bob(form, negotiated, not_acceptable) 
    1789  
    1790                                                 self.dialog = dialogs.YesNoDialog(_('Confirm these session options'), 
    1791                                                         _('''The remote client wants to negotiate an session with these features: 
    1792  
    1793                 %s 
    1794  
    1795                 Are these options acceptable?''') % (negotiation.describe_features(ask_user)), 
    1796                                                                 on_response_yes=accept_nondefault_options, 
    1797                                                                 on_response_no=reject_nondefault_options) 
    1798                                         else: 
    1799                                                 session.respond_e2e_bob(form, negotiated, not_acceptable) 
    1800  
    1801                                 def ignore_negotiation(widget): 
    1802                                         self.dialog.destroy() 
    1803                                         return 
    1804  
    1805                                 continue_with_negotiation() 
    1806  
    1807                                 return 
    1808  
    1809                         # alice accepts 
    1810                         elif session.status == 'requested-e2e' and form.getType() == 'submit': 
    1811                                 negotiated, not_acceptable, ask_user = session.verify_options_alice(form) 
    1812  
    1813                                 if session.sigmai: 
    1814                                         def _cb(on_success): 
    1815                                                 negotiation.show_sas_dialog(session, jid, session.sas, on_success) 
    1816  
    1817                                         session.check_identity = _cb 
    1818  
    1819                                 if ask_user: 
    1820                                         def accept_nondefault_options(is_checked): 
    1821                                                 dialog.destroy() 
    1822  
    1823                                                 negotiated.update(ask_user) 
    1824  
    1825                                                 try: 
    1826                                                         session.accept_e2e_alice(form, negotiated) 
    1827                                                 except exceptions.NegotiationError, details: 
    1828                                                         session.fail_bad_negotiation(details) 
    1829  
    1830                                         def reject_nondefault_options(): 
    1831                                                 session.reject_negotiation() 
    1832                                                 dialog.destroy() 
    1833  
    1834                                         dialog = dialogs.YesNoDialog(_('Confirm these session options'), 
    1835                                                         _('The remote client selected these options:\n\n%s\n\nContinue with the session?') % (negotiation.describe_features(ask_user)), 
    1836                                                         on_response_yes = accept_nondefault_options, 
    1837                                                         on_response_no = reject_nondefault_options) 
    1838                                 else: 
    1839                                         try: 
    1840                                                 session.accept_e2e_alice(form, negotiated) 
    1841                                         except exceptions.NegotiationError, details: 
    1842                                                 session.fail_bad_negotiation(details) 
    1843  
    1844                                 return 
    1845                         elif session.status == 'responded-e2e' and form.getType() == 'result': 
    1846  
    1847                                 def _cb(on_success): 
    1848                                         negotiation.show_sas_dialog(session, jid, session.sas, on_success) 
    1849  
    1850                                 session.check_identity = _cb 
    1851  
    1852                                 try: 
    1853                                         session.accept_e2e_bob(form) 
    1854                                 except exceptions.NegotiationError, details: 
    1855                                         session.fail_bad_negotiation(details) 
    1856  
    1857                                 return 
    1858                         elif session.status == 'identified-alice' and form.getType() == 'result': 
    1859                                 def _cb(on_success): 
    1860                                         negotiation.show_sas_dialog(session, jid, session.sas, on_success) 
    1861  
    1862                                 session.check_identity = _cb 
    1863  
    1864                                 try: 
    1865                                         session.final_steps_alice(form) 
    1866                                 except exceptions.NegotiationError, details: 
    1867                                         session.fail_bad_negotiation(details) 
    1868  
    1869                                 return 
    1870                 except exceptions.Cancelled: 
    1871                         # user cancelled the negotiation 
    1872  
    1873                         session.reject_negotiation() 
    1874  
    1875                         return 
    1876  
    1877                 if form.getField('terminate') and\ 
    1878                 form.getField('terminate').getValue() in ('1', 'true'): 
    1879                         jid = str(jid) 
    1880  
    1881                         session.acknowledge_termination() 
    1882  
    1883                         conn = gajim.connections[account] 
    1884                         conn.delete_session(jid, session.thread_id) 
    1885  
    1886                         return 
    1887  
    1888                 # non-esession negotiation. this isn't very useful, but i'm keeping it around 
    1889                 # to test my test suite. 
    1890                 if form.getType() == 'form': 
    1891                         if not session.control: 
    1892                                 resource = jid.getResource() 
    1893                                 contact = gajim.contacts.get_contact(account, str(jid), resource) 
    1894                                 if not contact: 
    1895                                         connection = gajim.connections[account] 
    1896                                         contact = gajim.contacts.create_contact(jid = jid.getStripped(),  
    1897                                                         resource = resource, show = connection.get_status()) 
    1898                                 self.new_chat(contact, account, resource = resource, session = session) 
    1899  
    1900                         negotiation.FeatureNegotiationWindow(account, jid, session, form) 
    19011753 
    19021754        def handle_event_privacy_lists_received(self, account, data): 
     
    21962048                                self.handle_event_unique_room_id_unsupported, 
    21972049                        'UNIQUE_ROOM_ID_SUPPORTED': self.handle_event_unique_room_id_supported, 
    2198                         'SESSION_NEG': self.handle_session_negotiation, 
    21992050                        'GPG_PASSWORD_REQUIRED': self.handle_event_gpg_password_required, 
    22002051                        'SSL_ERROR': self.handle_event_ssl_error,