def _connect_error(self, sid, error, error_type, msg=None): """ Called when there is an error establishing BS connection, or when connection is rejected """ if not self.connection or self.connected < 2: return file_props = FilesProp.getFileProp(self.name, sid) if file_props is None: log.error('can not send iq error on failed transfer') return if file_props.type_ == 's': to = file_props.receiver else: to = file_props.sender iq = nbxmpp.Iq(to=to, typ='error') iq.setAttr('id', file_props.request_id) err = iq.setTag('error') err.setAttr('type', error_type) err.setTag(error, namespace=nbxmpp.NS_STANZAS) self.connection.send(iq) if msg: self.disconnect_transfer(file_props) file_props.error = -3 from common.connection_handlers_events import \ FileRequestErrorEvent gajim.nec.push_incoming_event( FileRequestErrorEvent(None, conn=self, jid=to, file_props=file_props, error_msg=msg))
def _connect_error(self,sid, code=404): """ Called when there is an error establishing BS connection, or when connection is rejected """ if not self.connection or self.connected < 2: return file_props = FilesProp.getFileProp(self.name, sid) if file_props is None: log.error('can not send iq error on failed transfer') return msg_dict = { 404: 'Could not connect to given hosts', 405: 'Cancel', 406: 'Not acceptable', } msg = msg_dict[code] if file_props.type_ == 's': to = file_props.receiver else: to = file_props.sender iq = nbxmpp.Iq(to=to, typ='error') iq.setAttr('id', file_props.sid) err = iq.setTag('error') err.setAttr('code', unicode(code)) err.setData(msg) self.connection.send(iq) if code == 404: self.disconnect_transfer(file_props) file_props.error = -3 from common.connection_handlers_events import \ FileRequestErrorEvent gajim.nec.push_incoming_event(FileRequestErrorEvent(None, conn=self, jid=to, file_props=file_props, error_msg=msg))
def _siResultCB(self, con, iq_obj): file_props = FilesProp.getFileProp(self.name, iq_obj.getAttr('id')) if not file_props: return if file_props.request_id: # we have already sent streamhosts info return file_props.receiver = self._ft_get_from(iq_obj) si = iq_obj.getTag('si') file_tag = si.getTag('file') range_tag = None if file_tag: range_tag = file_tag.getTag('range') if range_tag: offset = range_tag.getAttr('offset') if offset: file_props.offset = int(offset) length = range_tag.getAttr('length') if length: file_props.length = int(length) feature = si.setTag('feature') if feature.getNamespace() != nbxmpp.NS_FEATURE: return form_tag = feature.getTag('x') form = nbxmpp.DataForm(node=form_tag) field = form.getField('stream-method') if field.getValue() == nbxmpp.NS_BYTESTREAM: self._send_socks5_info(file_props) raise nbxmpp.NodeProcessed if field.getValue() == nbxmpp.NS_IBB: sid = file_props.sid file_props.transport_sid = sid fp = open(file_props.file_name, 'r') self.OpenStream(sid, file_props.receiver, fp) raise nbxmpp.NodeProcessed
def _siResultCB(self, con, iq_obj): file_props = FilesProp.getFileProp(self.name, iq_obj.getAttr('id')) if not file_props: return if file_props.request_id: # we have already sent streamhosts info return file_props.receiver = self._ft_get_from(iq_obj) si = iq_obj.getTag('si') file_tag = si.getTag('file') range_tag = None if file_tag: range_tag = file_tag.getTag('range') if range_tag: offset = range_tag.getAttr('offset') if offset: file_props.offset = int(offset) length = range_tag.getAttr('length') if length: file_props.length = int(length) feature = si.setTag('feature') if feature.getNamespace() != nbxmpp.NS_FEATURE: return form_tag = feature.getTag('x') form = nbxmpp.DataForm(node=form_tag) field = form.getField('stream-method') if field.getValue() == nbxmpp.NS_BYTESTREAM: self._send_socks5_info(file_props) raise nbxmpp.NodeProcessed if field.getValue() == nbxmpp.NS_IBB: sid = file_props.sid file_props.transport_sid = sid fp = open(file_props.file_name, 'r') self.OpenStream(sid, file_props.receiver, fp) raise nbxmpp.NodeProcessed
def _connect_error(self, sid, error, error_type, msg=None): """ Called when there is an error establishing BS connection, or when connection is rejected """ if not self.connection or self.connected < 2: return file_props = FilesProp.getFileProp(self.name, sid) if file_props is None: log.error('can not send iq error on failed transfer') return if file_props.type_ == 's': to = file_props.receiver else: to = file_props.sender iq = nbxmpp.Iq(to=to, typ='error') iq.setAttr('id', file_props.request_id) err = iq.setTag('error') err.setAttr('type', error_type) err.setTag(error, namespace=nbxmpp.NS_STANZAS) self.connection.send(iq) if msg: self.disconnect_transfer(file_props) file_props.error = -3 from common.connection_handlers_events import \ FileRequestErrorEvent gajim.nec.push_incoming_event(FileRequestErrorEvent(None, conn=self, jid=to, file_props=file_props, error_msg=msg))
def _bytestreamSetCB(self, con, iq_obj): target = iq_obj.getAttr('to') id_ = iq_obj.getAttr('id') query = iq_obj.getTag('query') sid = query.getAttr('sid') file_props = FilesProp.getFileProp(self.name, sid) streamhosts = [] for item in query.getChildren(): if item.getName() == 'streamhost': host_dict = { 'state': 0, 'target': target, 'id': id_, 'sid': sid, 'initiator': self._ft_get_from(iq_obj) } for attr in item.getAttrs(): host_dict[attr] = item.getAttr(attr) if 'host' not in host_dict: continue if 'jid' not in host_dict: continue if 'port' not in host_dict: continue streamhosts.append(host_dict) file_props = FilesProp.getFilePropBySid(sid) if file_props is not None: if file_props.type_ == 's': # FIXME: remove fast xmlns # only psi do this if file_props.streamhosts: file_props.streamhosts.extend(streamhosts) else: file_props.streamhosts = streamhosts gajim.socks5queue.connect_to_hosts( self.name, sid, self.send_success_connect_reply, None) raise nbxmpp.NodeProcessed else: log.warning( 'Gajim got streamhosts for unknown transfer. Ignoring it.') raise nbxmpp.NodeProcessed file_props.streamhosts = streamhosts def _connection_error(sid): self._connect_error(sid, 'item-not-found', 'cancel', msg='Could not connect to given hosts') if file_props.type_ == 'r': gajim.socks5queue.connect_to_hosts(self.name, sid, self.send_success_connect_reply, _connection_error) raise nbxmpp.NodeProcessed
def _siErrorCB(self, con, iq_obj): si = iq_obj.getTag('si') profile = si.getAttr('profile') if profile != nbxmpp.NS_FILE: return file_props = FilesProp.getFileProp(self.name, iq_obj.getAttr('id')) if not file_props: return jid = self._ft_get_from(iq_obj) file_props.error = -3 from common.connection_handlers_events import FileRequestErrorEvent gajim.nec.push_incoming_event(FileRequestErrorEvent(None, conn=self, jid=jid, file_props=file_props, error_msg='')) raise nbxmpp.NodeProcessed
def _siErrorCB(self, con, iq_obj): si = iq_obj.getTag('si') profile = si.getAttr('profile') if profile != nbxmpp.NS_FILE: return file_props = FilesProp.getFileProp(self.name, iq_obj.getAttr('id')) if not file_props: return jid = self._ft_get_from(iq_obj) file_props.error = -3 from common.connection_handlers_events import FileRequestErrorEvent gajim.nec.push_incoming_event(FileRequestErrorEvent(None, conn=self, jid=jid, file_props=file_props, error_msg='')) raise nbxmpp.NodeProcessed
def _bytestreamSetCB(self, con, iq_obj): target = iq_obj.getAttr('to') id_ = iq_obj.getAttr('id') query = iq_obj.getTag('query') sid = query.getAttr('sid') file_props = FilesProp.getFileProp(self.name, sid) streamhosts = [] for item in query.getChildren(): if item.getName() == 'streamhost': host_dict = { 'state': 0, 'target': target, 'id': id_, 'sid': sid, 'initiator': self._ft_get_from(iq_obj) } for attr in item.getAttrs(): host_dict[attr] = item.getAttr(attr) if 'host' not in host_dict: continue if 'jid' not in host_dict: continue if 'port' not in host_dict: continue streamhosts.append(host_dict) file_props = FilesProp.getFilePropBySid(sid) if file_props is not None: if file_props.type_ == 's': # FIXME: remove fast xmlns # only psi do this if file_props.streamhosts: file_props.streamhosts.extend(streamhosts) else: file_props.streamhosts = streamhosts gajim.socks5queue.connect_to_hosts(self.name, sid, self.send_success_connect_reply, None) raise nbxmpp.NodeProcessed else: log.warning('Gajim got streamhosts for unknown transfer. Ignoring it.') raise nbxmpp.NodeProcessed file_props.streamhosts = streamhosts def _connection_error(sid): self._connect_error(sid, 'item-not-found', 'cancel', msg='Could not connect to given hosts') if file_props.type_ == 'r': gajim.socks5queue.connect_to_hosts(self.name, sid, self.send_success_connect_reply, _connection_error) raise nbxmpp.NodeProcessed
def _proxy_auth_ok(self, proxy): """ Called after authentication to proxy server """ if not self.connection or self.connected < 2: return file_props = FilesProp.getFileProp(self.name, proxy['sid']) iq = nbxmpp.Iq(to=proxy['initiator'], typ='set') auth_id = "au_" + proxy['sid'] iq.setID(auth_id) query = iq.setTag('query', namespace=nbxmpp.NS_BYTESTREAM) query.setAttr('sid', proxy['sid']) activate = query.setTag('activate') activate.setData(file_props.proxy_receiver) iq.setID(auth_id) self.connection.send(iq)
def _proxy_auth_ok(self, proxy): """ Called after authentication to proxy server """ if not self.connection or self.connected < 2: return file_props = FilesProp.getFileProp(self.name, proxy['sid']) iq = nbxmpp.Iq(to=proxy['initiator'], typ='set') auth_id = "au_" + proxy['sid'] iq.setID(auth_id) query = iq.setTag('query', namespace=nbxmpp.NS_BYTESTREAM) query.setAttr('sid', proxy['sid']) activate = query.setTag('activate') activate.setData(file_props.proxy_receiver) iq.setID(auth_id) self.connection.send(iq)
def _bytestreamResultCB(self, con, iq_obj): frm = self._ft_get_from(iq_obj) real_id = unicode(iq_obj.getAttr('id')) query = iq_obj.getTag('query') gajim.proxy65_manager.resolve_result(frm, query) try: streamhost = query.getTag('streamhost-used') except Exception: # this bytestream result is not what we need pass id_ = real_id[3:] file_props = FilesProp.getFileProp(self.name, id_) if file_props is None: raise nbxmpp.NodeProcessed if streamhost is None: # proxy approves the activate query if real_id.startswith('au_'): if file_props.streamhost_used is False: raise nbxmpp.NodeProcessed if not file_props.proxyhosts: raise nbxmpp.NodeProcessed for host in file_props.proxyhosts: if host['initiator'] == frm and \ unicode(query.getAttr('sid')) == file_props.sid: gajim.socks5queue.activate_proxy(host['idx']) break raise nbxmpp.NodeProcessed jid = self._ft_get_streamhost_jid_attr(streamhost) if file_props.streamhost_used is True: raise nbxmpp.NodeProcessed if real_id.startswith('au_'): if file_props.stopped: self.remove_transfer(file_props) else: gajim.socks5queue.send_file(file_props, self.name) raise nbxmpp.NodeProcessed proxy = None if file_props.proxyhosts: for proxyhost in file_props.proxyhosts: if proxyhost['jid'] == jid: proxy = proxyhost if file_props.stopped: self.remove_transfer(file_props) raise nbxmpp.NodeProcessed if proxy is not None: file_props.streamhost_used = True file_props.streamhosts.append(proxy) file_props.is_a_proxy = True idx = gajim.socks5queue.idx sender = Socks5SenderClient(gajim.idlequeue, idx, gajim.socks5queue, _sock=None, host=str(proxy['host']), port=int(proxy['port']), fingerprint=None, connected=False, file_props=file_props) sender.streamhost = proxy gajim.socks5queue.add_sockobj(self.name, sender) proxy['idx'] = sender.queue_idx gajim.socks5queue.on_success[file_props.sid] = self._proxy_auth_ok raise nbxmpp.NodeProcessed else: if file_props.stopped: self.remove_transfer(file_props) else: gajim.socks5queue.send_file(file_props, self.name, 'server') raise nbxmpp.NodeProcessed
def _bytestreamResultCB(self, con, iq_obj): frm = self._ft_get_from(iq_obj) real_id = iq_obj.getAttr('id') query = iq_obj.getTag('query') gajim.proxy65_manager.resolve_result(frm, query) try: streamhost = query.getTag('streamhost-used') except Exception: # this bytestream result is not what we need pass id_ = real_id[3:] file_props = FilesProp.getFileProp(self.name, id_) if file_props is None: raise nbxmpp.NodeProcessed if streamhost is None: # proxy approves the activate query if real_id.startswith('au_'): if file_props.streamhost_used is False: raise nbxmpp.NodeProcessed if not file_props.proxyhosts: raise nbxmpp.NodeProcessed for host in file_props.proxyhosts: if host['initiator'] == frm and \ query.getAttr('sid') == file_props.sid: gajim.socks5queue.activate_proxy(host['idx']) break raise nbxmpp.NodeProcessed jid = self._ft_get_streamhost_jid_attr(streamhost) if file_props.streamhost_used is True: raise nbxmpp.NodeProcessed if real_id.startswith('au_'): if file_props.stopped: self.remove_transfer(file_props) else: gajim.socks5queue.send_file(file_props, self.name) raise nbxmpp.NodeProcessed proxy = None if file_props.proxyhosts: for proxyhost in file_props.proxyhosts: if proxyhost['jid'] == jid: proxy = proxyhost if file_props.stopped: self.remove_transfer(file_props) raise nbxmpp.NodeProcessed if proxy is not None: file_props.streamhost_used = True file_props.streamhosts.append(proxy) file_props.is_a_proxy = True idx = gajim.socks5queue.idx sender = Socks5SenderClient(gajim.idlequeue, idx, gajim.socks5queue, _sock=None, host=str(proxy['host']), port=int(proxy['port']), fingerprint=None, connected=False, file_props=file_props) sender.streamhost = proxy gajim.socks5queue.add_sockobj(self.name, sender) proxy['idx'] = sender.queue_idx gajim.socks5queue.on_success[file_props.sid] = self._proxy_auth_ok raise nbxmpp.NodeProcessed else: if file_props.stopped: self.remove_transfer(file_props) else: gajim.socks5queue.send_file(file_props, self.name, 'server') raise nbxmpp.NodeProcessed