Ticket #644: jep70.patch

File jep70.patch, 9.3 KB (added by travis@…, 5 years ago)

Patch

  • launch.sh

     
    11cd src 
    2 ./gajim.py $@ 
     2./gajim.py --verbose $@ 
  • src/common/xmpp/protocol.py

     
    7070NS_FILE         ='http://jabber.org/protocol/si/profile/file-transfer' # JEP-0096 
    7171NS_FEATURE      ='http://jabber.org/protocol/feature-neg' 
    7272NS_BYTESTREAM   ='http://jabber.org/protocol/bytestreams' # JEP-0065 
    73 NS_DISCO                ='http://jabber.org/protocol/disco#info' # JEP-0095 
    74 NS_STREAM               ='http://affinix.com/jabber/stream' 
     73NS_DISCO        ='http://jabber.org/protocol/disco#info' # JEP-0095 
     74NS_STREAM       ='http://affinix.com/jabber/stream' 
     75NS_HTTP_AUTH    ='http://jabber.org/protocol/http-auth'         # JEP-0070 
    7576 
    7677xmpp_stream_error_conditions=""" 
    7778bad-format --  --  -- The entity has sent XML that cannot be processed. 
     
    324325                if tag.getName()<>'text': return tag.getName() 
    325326            return errtag.getData() 
    326327    def getErrorCode(self): 
    327         """ Return the error code. Obsolette. """ 
     328        """ Return the error code. Obsolete. """ 
    328329        return self.getTagAttr('error','code') 
    329330    def setError(self,error,code=None): 
    330         """ Set the error code. Obsolette. Use error-conditions instead. """ 
     331        """ Set the error code. Obsolete. Use error-conditions instead. """ 
    331332        if code: 
    332333            if str(code) in _errorcodes.keys(): error=ErrorNode(_errorcodes[str(code)],text=error) 
    333334            else: error=ErrorNode(ERR_UNDEFINED_CONDITION,code=code,typ='cancel',text=error) 
     
    449450 
    450451class Iq(Protocol):  
    451452    """ XMPP Iq object - get/set dialog mechanism. """ 
    452     def __init__(self, typ=None, queryNS=None, attrs={}, to=None, frm=None, payload=[], xmlns=NS_CLIENT, node=None): 
     453    def __init__(self, typ=None, queryNS=None, attrs={}, to=None, frm=None, 
     454                 payload=[], xmlns=NS_CLIENT, node=None, iq_child='query'): 
    453455        """ Create Iq object. You can specify type, query namespace 
    454             any additional attributes, recipient of the iq, sender of the iq, any additional payload (f.e. jabber:x:data node) and namespace in one go. 
    455             Alternatively you can pass in the other XML object as the 'node' parameted to replicate it as an iq. """ 
    456         Protocol.__init__(self, 'iq', to=to, typ=typ, attrs=attrs, frm=frm, xmlns=xmlns, node=node) 
     456            any additional attributes, recipient of the iq, sender of the iq, 
     457            any additional payload (f.e. jabber:x:data node) and namespace in 
     458            one go.  Alternatively you can pass in the other XML object as the 
     459            'node' parameted to replicate it as an iq.  Many protocols 
     460            have an inner child named 'query' for the Iq payload, but this is 
     461            not required. To allow for newer protocols the name of this child 
     462            can be specified to override the default value 'query'.""" 
     463        Protocol.__init__(self, 'iq', to=to, typ=typ, attrs=attrs, frm=frm, 
     464                          xmlns=xmlns, node=node) 
     465        self.iq_child = iq_child or 'query' 
    457466        if payload: self.setQueryPayload(payload) 
    458467        if queryNS: self.setQueryNS(queryNS) 
     468    def setIqChildName(self, iq_child): 
     469        self.iq_child = iq_child or 'query'; 
    459470    def getQueryNS(self): 
    460         """ Return the namespace of the 'query' child element.""" 
    461         tag=self.getTag('query') 
     471        """ Return the namespace of the iq child element.""" 
     472        tag=self.getTag(self.iq_child) 
    462473        if tag: return tag.getNamespace() 
    463474    def getQuerynode(self): 
    464         """ Return the 'node' attribute value of the 'query' child element.""" 
    465         return self.getTagAttr('query','node') 
     475        """ Return the 'node' attribute value of the iq child element.""" 
     476        return self.getTagAttr(self.iq_child,'node') 
    466477    def getQueryPayload(self): 
    467         """ Return the 'query' child element payload.""" 
    468         tag=self.getTag('query') 
     478        """ Return the iq child element payload.""" 
     479        tag=self.getTag(self.iq_child) 
    469480        if tag: return tag.getPayload() 
    470481    def getQueryChildren(self): 
    471         """ Return the 'query' child element child nodes.""" 
    472         tag=self.getTag('query') 
     482        """ Return the iq child element child nodes.""" 
     483        tag=self.getTag(self.iq_child) 
    473484        if tag: return tag.getChildren() 
    474485    def setQueryNS(self,namespace): 
    475         """ Set the namespace of the 'query' child element.""" 
    476         self.setTag('query').setNamespace(namespace) 
     486        """ Set the namespace of the iq child element.""" 
     487        self.setTag(self.iq_child).setNamespace(namespace) 
    477488    def setQueryPayload(self,payload): 
    478         """ Set the 'query' child element payload.""" 
    479         self.setTag('query').setPayload(payload) 
     489        """ Set the iq child element payload.""" 
     490        self.setTag(self.iq_child).setPayload(payload) 
    480491    def setQuerynode(self,node): 
    481         """ Set the 'node' attribute value of the 'query' child element.""" 
    482         self.setTagAttr('query','node',node) 
     492        """ Set the 'node' attribute value of the iq child element.""" 
     493        self.setTagAttr(self.iq_child,'node',node) 
    483494    def buildReply(self,typ): 
    484495        """ Builds and returns another Iq object of specified type. 
    485             The to, from and query child node of new Iq are pre-set as reply to this Iq. """ 
     496            The to, from and child node of new Iq are pre-set as reply 
     497            to this Iq. """ 
    486498        iq=Iq(typ,to=self.getFrom(),frm=self.getTo(),attrs={'id':self.getID()}) 
    487         if self.getTag('query'): iq.setQueryNS(self.getQueryNS()) 
     499        if self.getTag(self.iq_child): iq.setQueryNS(self.getQueryNS()) 
    488500        return iq 
    489501 
    490502class ErrorNode(Node): 
  • src/common/connection.py

     
    127127                        'GC_SUBJECT': [], 'GC_CONFIG': [], 'BAD_PASSPHRASE': [], 
    128128                        'ROSTER_INFO': [], 'ERROR_ANSWER': [], 'BOOKMARKS': [], 'CON_TYPE': [], 
    129129                        'FILE_REQUEST': [], 'FILE_RCV_COMPLETED': [], 'FILE_PROGRESS': [], 
    130                         'STANZA_ARRIVED': [] 
     130                        'STANZA_ARRIVED': [], 'HTTP_AUTH': [] 
    131131                        } 
    132132                self.name = name 
    133133                self.connected = 0 # offline 
     
    861861                        #TODO: implement this 
    862862                        pass  
    863863 
     864        def _HttpAuthCB(self, con, iq_obj): 
     865                self.dispatch('HTTP_AUTH', (con, iq_obj)); 
     866                raise common.xmpp.NodeProcessed 
     867 
    864868        def _ErrorCB(self, con, iq_obj): 
    865869                errmsg = iq_obj.getError() 
    866870                errcode = iq_obj.getErrorCode() 
     
    988992                        common.xmpp.NS_ROSTER) 
    989993                con.RegisterHandler('iq', self._PrivateCB, 'result', 
    990994                        common.xmpp.NS_PRIVATE) 
     995                con.RegisterHandler('iq', self._HttpAuthCB, 'get', 
     996                        common.xmpp.NS_HTTP_AUTH) 
    991997                con.RegisterHandler('iq', self._ErrorCB, 'error') 
    992998                con.RegisterHandler('iq', self._StanzaArrivedCB) 
    993999                con.RegisterHandler('presence', self._StanzaArrivedCB) 
  • src/common/config.py

     
    122122                'confirm_close_muc': [opt_bool, True], # confirm closing MUC window 
    123123                'notify_on_file_complete': [opt_bool, True], # notif. on file complete 
    124124                'file_transfers_port': [opt_int, 28011],  # port, used for file transfers 
     125                'http_auth': [opt_str, 'ask'], # yes, no, ask 
    125126        } 
    126127 
    127128        __options_per_key = { 
  • src/gajim.py

     
    197197                #('INFORMATION', account, (title_text, section_text)) 
    198198                dialogs.InformationDialog(data[0], data[1]).get_response() 
    199199 
     200        def handle_http_auth(self, unused, data): 
     201                #('HTTP_AUTH', account, (connection, iq)) 
     202                con = data[0] 
     203                iq = data[1] 
     204                opt = gajim.config.get('http_auth') 
     205                if opt == 'yes': 
     206                        iq = iq.buildReply('result') 
     207                elif opt == 'no': 
     208                        iq = iq.buildReply('error') 
     209                        iq.setError('not-authorized', 401); 
     210                else: 
     211                        method = iq.getTagAttr('confirm', 'method') 
     212                        url = iq.getTagAttr('confirm', 'url') 
     213                        dialog = dialogs.ConfirmationDialog(\ 
     214                            _('HTTP (%s) Authorization for %s') % (method, url), 
     215                            _('Accept this request?')) 
     216                        if dialog.get_response() == gtk.RESPONSE_OK: 
     217                                iq = iq.buildReply('result'); 
     218                        else: 
     219                                iq = iq.buildReply('error'); 
     220                                iq.setError('not-authorized', 401); 
     221                con.send(iq); 
     222 
    200223        def handle_event_error_answer(self, account, array): 
    201224                id, jid_from, errmsg, errcode = array 
    202225                if str(errcode) in ['403', '406'] and id: 
     
    932955                con.register_handler('CON_TYPE', self.handle_event_con_type) 
    933956                con.register_handler('FILE_REQUEST', self.handle_event_file_request) 
    934957                con.register_handler('STANZA_ARRIVED', self.handle_event_stanza_arrived) 
     958                con.register_handler('HTTP_AUTH', self.handle_http_auth) 
    935959 
    936960        def process_connections(self): 
    937961                try: