Changeset 9447

Show
Ignore:
Timestamp:
04/07/08 00:21:46 (5 months ago)
Author:
bct
Message:

rearranged _messageCB and split it into multiple methods

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/session_centric/src/common/connection_handlers.py

    r9326 r9447  
    15491549                        self._pubsubEventCB(con, msg) 
    15501550                        return 
     1551 
    15511552                # check if the message is a xep70-confirmation-request 
    15521553                if msg.getTag('confirm') and msg.getTag('confirm').namespace == \ 
     
    15541555                        self._HttpAuthCB(con, msg) 
    15551556                        return 
     1557 
     1558                # check if the message is a XEP 0020 feature negotiation request 
    15561559                if msg.getTag('feature') and msg.getTag('feature').namespace == \ 
    15571560                common.xmpp.NS_FEATURE: 
     
    15591562                                self._FeatureNegCB(con, msg, session) 
    15601563                        return 
     1564 
     1565                # check if the message is initiating an ESession negotiation 
    15611566                if msg.getTag('init') and msg.getTag('init').namespace == \ 
    15621567                common.xmpp.NS_ESESSION_INIT: 
    15631568                        self._InitE2ECB(con, msg, session) 
    1564                  
     1569 
    15651570                encrypted = False 
    1566                 tim = msg.getTimestamp() 
    1567                 tim = helpers.datetime_tuple(tim) 
    1568                 tim = localtime(timegm(tim)) 
    15691571 
    15701572                e2e_tag = msg.getTag('c', namespace = common.xmpp.NS_STANZA_CRYPTO) 
     
    15801582                msghtml = msg.getXHTML() 
    15811583                subject = msg.getSubject() # if not there, it's None 
     1584 
    15821585                tim = msg.getTimestamp() 
    15831586                tim = helpers.datetime_tuple(tim) 
    15841587                tim = localtime(timegm(tim)) 
     1588 
    15851589                frm = helpers.get_full_jid_from_iq(msg) 
    15861590                jid = helpers.get_jid_from_iq(msg) 
     1591 
    15871592                addressTag = msg.getTag('addresses', namespace = common.xmpp.NS_ADDRESS) 
     1593 
    15881594                # Be sure it comes from one of our resource, else ignore address element 
    15891595                if addressTag and jid == gajim.get_jid_from_account(self.name): 
     
    15921598                                frm = address.getAttr('jid') 
    15931599                                jid = gajim.get_jid_without_resource(frm) 
    1594                 no_log_for = gajim.config.get_per('accounts', self.name, 
    1595                         'no_log_for') 
    1596                 if not no_log_for: 
    1597                         no_log_for = '' 
    1598                 no_log_for = no_log_for.split() 
    1599                 chatstate = None 
     1600 
    16001601                encTag = msg.getTag('x', namespace = common.xmpp.NS_ENCRYPTED) 
    1601                 decmsg = '' 
    16021602                # invitations 
    16031603                invite = None 
     1604 
    16041605                if not encTag: 
    16051606                        invite = msg.getTag('x', namespace = common.xmpp.NS_MUC_USER) 
    16061607                        if invite and not invite.getTag('invite'): 
    16071608                                invite = None 
     1609 
    16081610                delayed = msg.getTag('x', namespace = common.xmpp.NS_DELAY) != None 
    16091611                msg_id = None 
    16101612                composing_xep = None 
     1613 
    16111614                # FIXME: Msn transport (CMSN1.2.1 and PyMSN0.10) do NOT RECOMMENDED 
    16121615                # invitation 
     
    16221625                                        is_continued)) 
    16231626                                return 
     1627 
    16241628                form_node = None 
    16251629                for xtag in xtags: 
     
    16271631                                form_node = xtag 
    16281632                                break 
     1633 
     1634                chatstate = None 
     1635 
    16291636                # chatstates - look for chatstate tags in a message if not delayed 
    16301637                if not delayed: 
     
    16441651                                        if not msgtxt and chatstate_child.getTag('composing'): 
    16451652                                                chatstate = 'composing' 
     1653 
    16461654                # XEP-0172 User Nickname 
    16471655                user_nick = msg.getTagData('nick') 
     
    16501658 
    16511659                if encTag and self.USE_GPG: 
    1652                         #decrypt 
    16531660                        encmsg = encTag.getData() 
    16541661 
     
    16571664                                decmsg = self.gpg.decrypt(encmsg, keyID) 
    16581665                                # \x00 chars are not allowed in C (so in GTK) 
    1659                                 decmsg = decmsg.replace('\x00', '') 
    1660                 if decmsg: 
    1661                         msgtxt = decmsg 
    1662                         encrypted = True 
     1666                                msgtxt = decmsg.replace('\x00', '') 
     1667 
     1668                                encrypted = True 
     1669 
    16631670                if mtype == 'error': 
    1664                         error_msg = msg.getError() 
    1665                         if not error_msg: 
    1666                                 error_msg = msgtxt 
    1667                                 msgtxt = None 
    1668                         if session.is_loggable(): 
    1669                                 try: 
    1670                                         gajim.logger.write('error', frm, error_msg, tim = tim, 
    1671                                                 subject = subject) 
    1672                                 except exceptions.PysqliteOperationalError, e: 
    1673                                         self.dispatch('ERROR', (_('Disk Write Error'), str(e))) 
    1674                         self.dispatch('MSGERROR', (frm, msg.getErrorCode(), error_msg, msgtxt, 
    1675                                 tim)) 
     1671                        self.dispatch_error_message(msg, msgtxt, session, frm, tim, subject) 
     1672 
    16761673                        return 
    16771674                elif mtype == 'groupchat': 
    1678                         has_timestamp = False 
    1679                         if msg.timestamp: 
    1680                                 has_timestamp = True 
    1681                         if subject != None: 
    1682                                 self.dispatch('GC_SUBJECT', (frm, subject, msgtxt, has_timestamp)) 
    1683                         else: 
    1684                                 statusCode = msg.getStatusCode() 
    1685                                 if not msg.getTag('body'): #no <body> 
    1686                                         # It could be a config change. See 
    1687                                         # http://www.xmpp.org/extensions/xep-0045.html#roomconfig-notify 
    1688                                         if msg.getTag('x'): 
    1689                                                 if statusCode != []: 
    1690                                                         self.dispatch('GC_CONFIG_CHANGE', (jid, statusCode)) 
    1691                                         return 
    1692                                 # Ignore message from room in which we are not 
    1693                                 if not self.last_history_line.has_key(jid): 
    1694                                         return 
    1695                                 self.dispatch('GC_MSG', (frm, msgtxt, tim, has_timestamp, msghtml, 
    1696                                         statusCode)) 
    1697                                 if self.name not in no_log_for and jid not in no_log_for and not \ 
    1698                                 int(float(mktime(tim))) <= self.last_history_line[jid] and msgtxt: 
    1699                                         try: 
    1700                                                 gajim.logger.write('gc_msg', frm, msgtxt, tim = tim) 
    1701                                         except exceptions.PysqliteOperationalError, e: 
    1702                                                 self.dispatch('ERROR', (_('Disk Write Error'), str(e))) 
    1703                         return 
    1704                 elif mtype == 'chat': # it's type 'chat' 
    1705                         if not msg.getTag('body') and chatstate is None: #no <body> 
     1675                        self.dispatch_gc_message(msg, subject, frm, msgtxt, jid, tim, msghtml) 
     1676 
     1677                        return 
     1678                elif invite is not None: 
     1679                        self.dispatch_invite_message(invite, frm) 
     1680 
     1681                        return 
     1682                elif mtype == 'chat': 
     1683                        if not msg.getTag('body') and chatstate is None: # no <body> 
    17061684                                return 
    1707                         if msg.getTag('body') and session.is_loggable() and msgtxt: 
    1708                                 try: 
    1709                                         msg_id = gajim.logger.write('chat_msg_recv', frm, msgtxt, 
    1710                                                 tim = tim, subject = subject) 
    1711                                 except exceptions.PysqliteOperationalError, e: 
    1712                                         self.dispatch('ERROR', (_('Disk Write Error'), str(e))) 
    1713                 else: # it's single message 
    1714                         if invite is not None: 
    1715                                 item = invite.getTag('invite') 
    1716                                 jid_from = item.getAttr('from') 
    1717                                 reason = item.getTagData('reason') 
    1718                                 item = invite.getTag('password') 
    1719                                 password = invite.getTagData('password') 
    1720                                 is_continued = False 
    1721                                 if invite.getTag('invite').getTag('continue'): 
    1722                                         is_continued = True 
    1723                                 self.dispatch('GC_INVITATION',(frm, jid_from, reason, password, 
    1724                                         is_continued)) 
    1725                                 return 
    1726                         if session.is_loggable()and msgtxt: 
    1727                                 try: 
    1728                                         gajim.logger.write('single_msg_recv', frm, msgtxt, tim = tim, 
    1729                                                 subject = subject) 
    1730                                 except exceptions.PysqliteOperationalError, e: 
    1731                                         self.dispatch('ERROR', (_('Disk Write Error'), str(e))) 
     1685 
     1686                        log_type = 'chat_msg_recv' 
     1687                else: # it's a single message 
     1688                        log_type = 'single_msg_recv' 
     1689 
    17321690                        mtype = 'normal' 
     1691 
     1692                if session.is_loggable() and msgtxt: 
     1693                        try: 
     1694                                msg_id = gajim.logger.write(log_type, frm, msgtxt, 
     1695                                        tim = tim, subject = subject) 
     1696                        except exceptions.PysqliteOperationalError, e: 
     1697                                self.dispatch('ERROR', (_('Disk Write Error'), str(e))) 
     1698 
    17331699                treat_as = gajim.config.get('treat_incoming_messages') 
     1700 
    17341701                if treat_as: 
    17351702                        mtype = treat_as 
     
    17381705      msg_id, composing_xep, user_nick, msghtml, form_node) 
    17391706        # END messageCB 
     1707 
     1708        # process and dispatch an error message 
     1709        def dispatch_error_message(self, msg, msgtxt, session, frm, tim, subject) 
     1710                error_msg = msg.getError() 
     1711 
     1712                if not error_msg: 
     1713                        error_msg = msgtxt 
     1714                        msgtxt = None 
     1715 
     1716                if session.is_loggable(): 
     1717                        try: 
     1718                                gajim.logger.write('error', frm, error_msg, tim = tim, 
     1719                                        subject = subject) 
     1720                        except exceptions.PysqliteOperationalError, e: 
     1721                                self.dispatch('ERROR', (_('Disk Write Error'), str(e))) 
     1722 
     1723                self.dispatch('MSGERROR', (frm, msg.getErrorCode(), error_msg, msgtxt, tim)) 
     1724 
     1725        # process and dispatch a groupchat message 
     1726        def dispatch_gc_message(self, msg, subject, frm, msgtxt, jid, tim, msghtml): 
     1727                has_timestamp = bool(msg.timestamp) 
     1728 
     1729                if subject != None: 
     1730                        self.dispatch('GC_SUBJECT', (frm, subject, msgtxt, has_timestamp)) 
     1731                else: 
     1732                        statusCode = msg.getStatusCode() 
     1733 
     1734                        if not msg.getTag('body'): #no <body> 
     1735                                # It could be a config change. See 
     1736                                # http://www.xmpp.org/extensions/xep-0045.html#roomconfig-notify 
     1737                                if msg.getTag('x'): 
     1738                                        if statusCode != []: 
     1739                                                self.dispatch('GC_CONFIG_CHANGE', (jid, statusCode)) 
     1740                                return 
     1741 
     1742                        # Ignore messages from rooms that we're not in 
     1743                        if not self.last_history_line.has_key(jid): 
     1744                                return 
     1745 
     1746                        self.dispatch('GC_MSG', (frm, msgtxt, tim, has_timestamp, msghtml, 
     1747                                statusCode)) 
     1748 
     1749                        no_log_for = gajim.config.get_per('accounts', self.name, 
     1750                                'no_log_for') 
     1751 
     1752                        if not no_log_for: 
     1753                                no_log_for = '' 
     1754 
     1755                        no_log_for = no_log_for.split() 
     1756 
     1757                        if self.name not in no_log_for and jid not in no_log_for and not \ 
     1758                        int(float(mktime(tim))) <= self.last_history_line[jid] and msgtxt: 
     1759                                try: 
     1760                                        gajim.logger.write('gc_msg', frm, msgtxt, tim = tim) 
     1761                                except exceptions.PysqliteOperationalError, e: 
     1762                                        self.dispatch('ERROR', (_('Disk Write Error'), str(e))) 
     1763 
     1764        def dispatch_invite_message(self, invite, frm) 
     1765                item = invite.getTag('invite') 
     1766 
     1767                jid_from = item.getAttr('from') 
     1768                reason = item.getTagData('reason') 
     1769                item = invite.getTag('password') 
     1770                password = invite.getTagData('password') 
     1771 
     1772                is_continued = False 
     1773                if invite.getTag('invite').getTag('continue'): 
     1774                        is_continued = True 
     1775 
     1776                self.dispatch('GC_INVITATION',(frm, jid_from, reason, password, 
     1777                        is_continued)) 
    17401778 
    17411779        def get_session(self, jid, thread_id, type):