Changeset 9829
- Timestamp:
- 06/21/08 21:12:47 (2 months ago)
- Location:
- trunk/src
- Files:
-
- 3 modified
-
common/connection_handlers.py (modified) (2 diffs)
-
gajim.py (modified) (3 diffs)
-
session.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/common/connection_handlers.py
r9817 r9829 1219 1219 self.sessions = {} 1220 1220 1221 def _FeatureNegCB(self, con, stanza, session):1222 gajim.log.debug('FeatureNegCB')1223 feature = stanza.getTag(name='feature', namespace=common.xmpp.NS_FEATURE)1224 form = common.xmpp.DataForm(node=feature.getTag('x'))1225 1226 if form['FORM_TYPE'] == 'urn:xmpp:ssn':1227 self.dispatch('SESSION_NEG', (stanza.getFrom(), session, form))1228 else:1229 reply = stanza.buildReply()1230 reply.setType('error')1231 1232 reply.addChild(feature)1233 reply.addChild(node=common.xmpp.ErrorNode('service-unavailable', typ='cancel'))1234 1235 con.send(reply)1236 1237 raise common.xmpp.NodeProcessed1238 1239 def _InitE2ECB(self, con, stanza, session):1240 gajim.log.debug('InitE2ECB')1241 init = stanza.getTag(name='init', namespace=common.xmpp.NS_ESESSION_INIT)1242 form = common.xmpp.DataForm(node=init.getTag('x'))1243 1244 self.dispatch('SESSION_NEG', (stanza.getFrom(), session, form))1245 1246 raise common.xmpp.NodeProcessed1247 1248 1221 def get_or_create_session(self, jid, thread_id): 1249 1222 '''returns an existing session between this connection and 'jid', returns a new one if none exist.''' … … 1718 1691 if msg.getTag('feature', namespace=common.xmpp.NS_FEATURE): 1719 1692 if gajim.HAVE_PYCRYPTO: 1720 self._FeatureNegCB(con, msg, session) 1721 return 1693 feature = msg.getTag(name='feature', namespace=common.xmpp.NS_FEATURE) 1694 form = common.xmpp.DataForm(node=feature.getTag('x')) 1695 1696 if form['FORM_TYPE'] == 'urn:xmpp:ssn': 1697 session.handle_negotiation(form) 1698 else: 1699 reply = msg.buildReply() 1700 reply.setType('error') 1701 1702 reply.addChild(feature) 1703 err = common.xmpp.ErrorNode('service-unavailable', typ='cancel') 1704 reply.addChild(node=err) 1705 1706 con.send(reply) 1707 1708 raise common.xmpp.NodeProcessed 1709 1710 return 1711 1722 1712 if msg.getTag('init', namespace=common.xmpp.NS_ESESSION_INIT): 1723 self._InitE2ECB(con, msg, session) 1713 init = msg.getTag(name='init', namespace=common.xmpp.NS_ESESSION_INIT) 1714 form = common.xmpp.DataForm(node=init.getTag('x')) 1715 1716 session.handle_negotiation(form) 1717 1718 raise common.xmpp.NodeProcessed 1724 1719 1725 1720 tim = msg.getTimestamp() -
trunk/src/gajim.py
r9820 r9829 247 247 import notify 248 248 import message_control 249 import negotiation250 249 251 250 from chat_control import ChatControlBase … … 1752 1751 else: 1753 1752 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 = data1757 1758 if form.getField('accept') and not form['accept'] in ('1', 'true'):1759 session.cancelled_negotiation()1760 return1761 1762 # encrypted session states. these are described in stanza_session.py1763 1764 try:1765 # bob responds1766 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 responder1772 if 'dhkeys' in form.asDict():1773 session.fail_bad_negotiation('3 message negotiation not supported when responding', ('dhkeys',))1774 return1775 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 %s1794 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 return1804 1805 continue_with_negotiation()1806 1807 return1808 1809 # alice accepts1810 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 = _cb1818 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 return1845 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 = _cb1851 1852 try:1853 session.accept_e2e_bob(form)1854 except exceptions.NegotiationError, details:1855 session.fail_bad_negotiation(details)1856 1857 return1858 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 = _cb1863 1864 try:1865 session.final_steps_alice(form)1866 except exceptions.NegotiationError, details:1867 session.fail_bad_negotiation(details)1868 1869 return1870 except exceptions.Cancelled:1871 # user cancelled the negotiation1872 1873 session.reject_negotiation()1874 1875 return1876 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 return1887 1888 # non-esession negotiation. this isn't very useful, but i'm keeping it around1889 # 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)1901 1753 1902 1754 def handle_event_privacy_lists_received(self, account, data): … … 2196 2048 self.handle_event_unique_room_id_unsupported, 2197 2049 'UNIQUE_ROOM_ID_SUPPORTED': self.handle_event_unique_room_id_supported, 2198 'SESSION_NEG': self.handle_session_negotiation,2199 2050 'GPG_PASSWORD_REQUIRED': self.handle_event_gpg_password_required, 2200 2051 'SSL_ERROR': self.handle_event_ssl_error, -
trunk/src/session.py
r9826 r9829 8 8 import common.xmpp 9 9 10 import message_control 11 12 import notify 13 10 14 import dialogs 11 12 import message_control 13 14 import notify 15 import negotiation 15 16 16 17 class ChatControlSession(stanza_session.EncryptedStanzaSession): … … 331 332 # Select contact row in roster. 332 333 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)
