report not-acceptable on jingle errors

This commit is contained in:
Daniel Gultsch 2019-10-01 11:31:15 +02:00
parent d2d9bbe3da
commit f8bd4284a5
2 changed files with 210 additions and 209 deletions

View file

@ -270,9 +270,10 @@ public class JingleConnection implements Transferable {
IqPacket response; IqPacket response;
if (returnResult) { if (returnResult) {
response = packet.generateResponse(IqPacket.TYPE.RESULT); response = packet.generateResponse(IqPacket.TYPE.RESULT);
} else { } else {
response = packet.generateResponse(IqPacket.TYPE.ERROR); response = packet.generateResponse(IqPacket.TYPE.ERROR);
final Element error = response.addChild("error").setAttribute("type", "cancel");
error.addChild("not-acceptable", "urn:ietf:params:xml:ns:xmpp-stanzas");
} }
mXmppConnectionService.sendIqPacket(account, response, null); mXmppConnectionService.sendIqPacket(account, response, null);
} }
@ -933,8 +934,9 @@ public class JingleConnection implements Transferable {
private boolean receiveTransportAccept(JinglePacket packet) { private boolean receiveTransportAccept(JinglePacket packet) {
if (packet.getJingleContent().hasIbbTransport()) { if (packet.getJingleContent().hasIbbTransport()) {
String receivedBlockSize = packet.getJingleContent().ibbTransport() final Element ibbTransport = packet.getJingleContent().ibbTransport();
.getAttribute("block-size"); final String receivedBlockSize = ibbTransport.getAttribute("block-size");
final String sid = ibbTransport.getAttribute("sid");
if (receivedBlockSize != null) { if (receivedBlockSize != null) {
try { try {
int bs = Integer.parseInt(receivedBlockSize); int bs = Integer.parseInt(receivedBlockSize);
@ -947,6 +949,10 @@ public class JingleConnection implements Transferable {
} }
this.transport = new JingleInbandTransport(this, this.transportId, this.ibbBlockSize); this.transport = new JingleInbandTransport(this, this.transportId, this.ibbBlockSize);
if (sid == null || !sid.equals(this.transportId)) {
Log.w(Config.LOGTAG,String.format("%s: sid in transport-accept (%s) did not match our sid (%s) ", account.getJid().asBareJid(), sid, transportId));
}
//might be receive instead if we are not initiating //might be receive instead if we are not initiating
if (initiating()) { if (initiating()) {
this.transport.connect(onIbbTransportConnected); this.transport.connect(onIbbTransportConnected);
@ -955,6 +961,7 @@ public class JingleConnection implements Transferable {
} }
return true; return true;
} else { } else {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": received invalid transport-accept");
return false; return false;
} }
} }

View file

@ -80,18 +80,12 @@ public class JingleInbandTransport extends JingleTransport {
open.setAttribute("stanza", "iq"); open.setAttribute("stanza", "iq");
open.setAttribute("block-size", Integer.toString(this.blockSize)); open.setAttribute("block-size", Integer.toString(this.blockSize));
this.connected = true; this.connected = true;
this.account.getXmppConnection().sendIqPacket(iq, this.account.getXmppConnection().sendIqPacket(iq, (account, packet) -> {
new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(Account account,
IqPacket packet) {
if (packet.getType() != IqPacket.TYPE.RESULT) { if (packet.getType() != IqPacket.TYPE.RESULT) {
callback.failed(); callback.failed();
} else { } else {
callback.established(); callback.established();
} }
}
}); });
} }
@ -104,13 +98,13 @@ public class JingleInbandTransport extends JingleTransport {
digest.reset(); digest.reset();
this.fileOutputStream = connection.getFileOutputStream(); this.fileOutputStream = connection.getFileOutputStream();
if (this.fileOutputStream == null) { if (this.fileOutputStream == null) {
Log.d(Config.LOGTAG,account.getJid().asBareJid()+": could not create output stream"); Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": could not create output stream");
callback.onFileTransferAborted(); callback.onFileTransferAborted();
return; return;
} }
this.remainingSize = this.fileSize = file.getExpectedSize(); this.remainingSize = this.fileSize = file.getExpectedSize();
} catch (final NoSuchAlgorithmException | IOException e) { } catch (final NoSuchAlgorithmException | IOException e) {
Log.d(Config.LOGTAG,account.getJid().asBareJid()+" "+e.getMessage()); Log.d(Config.LOGTAG, account.getJid().asBareJid() + " " + e.getMessage());
callback.onFileTransferAborted(); callback.onFileTransferAborted();
} }
} }
@ -126,7 +120,7 @@ public class JingleInbandTransport extends JingleTransport {
this.digest.reset(); this.digest.reset();
fileInputStream = connection.getFileInputStream(); fileInputStream = connection.getFileInputStream();
if (fileInputStream == null) { if (fileInputStream == null) {
Log.d(Config.LOGTAG,account.getJid().asBareJid()+": could no create input stream"); Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": could no create input stream");
callback.onFileTransferAborted(); callback.onFileTransferAborted();
return; return;
} }
@ -136,7 +130,7 @@ public class JingleInbandTransport extends JingleTransport {
} }
} catch (Exception e) { } catch (Exception e) {
callback.onFileTransferAborted(); callback.onFileTransferAborted();
Log.d(Config.LOGTAG,account.getJid().asBareJid()+": "+e.getMessage()); Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": " + e.getMessage());
} }
} }
@ -154,19 +148,19 @@ public class JingleInbandTransport extends JingleTransport {
if (count == -1) { if (count == -1) {
sendClose(); sendClose();
file.setSha1Sum(digest.digest()); file.setSha1Sum(digest.digest());
Log.d(Config.LOGTAG,account.getJid().asBareJid()+": sendNextBlock() count was -1"); Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": sendNextBlock() count was -1");
this.onFileTransmissionStatusChanged.onFileTransmitted(file); this.onFileTransmissionStatusChanged.onFileTransmitted(file);
fileInputStream.close(); fileInputStream.close();
return; return;
} else if (count != buffer.length) { } else if (count != buffer.length) {
int rem = innerInputStream.read(buffer,count,buffer.length-count); int rem = innerInputStream.read(buffer, count, buffer.length - count);
if (rem > 0) { if (rem > 0) {
count += rem; count += rem;
} }
} }
this.remainingSize -= count; this.remainingSize -= count;
this.digest.update(buffer,0,count); this.digest.update(buffer, 0, count);
String base64 = Base64.encodeToString(buffer,0,count, Base64.NO_WRAP); String base64 = Base64.encodeToString(buffer, 0, count, Base64.NO_WRAP);
IqPacket iq = new IqPacket(IqPacket.TYPE.SET); IqPacket iq = new IqPacket(IqPacket.TYPE.SET);
iq.setTo(this.counterpart); iq.setTo(this.counterpart);
Element data = iq.addChild("data", "http://jabber.org/protocol/ibb"); Element data = iq.addChild("data", "http://jabber.org/protocol/ibb");
@ -185,7 +179,7 @@ public class JingleInbandTransport extends JingleTransport {
fileInputStream.close(); fileInputStream.close();
} }
} catch (IOException e) { } catch (IOException e) {
Log.d(Config.LOGTAG,account.getJid().asBareJid()+": io exception during sendNextBlock() "+e.getMessage()); Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": io exception during sendNextBlock() " + e.getMessage());
FileBackend.close(fileInputStream); FileBackend.close(fileInputStream);
this.onFileTransmissionStatusChanged.onFileTransferAborted(); this.onFileTransmissionStatusChanged.onFileTransferAborted();
} }
@ -204,13 +198,13 @@ public class JingleInbandTransport extends JingleTransport {
file.setSha1Sum(digest.digest()); file.setSha1Sum(digest.digest());
fileOutputStream.flush(); fileOutputStream.flush();
fileOutputStream.close(); fileOutputStream.close();
Log.d(Config.LOGTAG,account.getJid().asBareJid()+": receive next block nothing remaining"); Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": receive next block nothing remaining");
this.onFileTransmissionStatusChanged.onFileTransmitted(file); this.onFileTransmissionStatusChanged.onFileTransmitted(file);
} else { } else {
connection.updateProgress((int) ((((double) (this.fileSize - this.remainingSize)) / this.fileSize) * 100)); connection.updateProgress((int) ((((double) (this.fileSize - this.remainingSize)) / this.fileSize) * 100));
} }
} catch (Exception e) { } catch (Exception e) {
Log.d(Config.LOGTAG,account.getJid().asBareJid()+": "+e.getMessage()); Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": " + e.getMessage());
FileBackend.close(fileOutputStream); FileBackend.close(fileOutputStream);
this.onFileTransmissionStatusChanged.onFileTransferAborted(); this.onFileTransmissionStatusChanged.onFileTransferAborted();
} }
@ -236,9 +230,9 @@ public class JingleInbandTransport extends JingleTransport {
this.connected = false; this.connected = false;
this.account.getXmppConnection().sendIqPacket( this.account.getXmppConnection().sendIqPacket(
packet.generateResponse(IqPacket.TYPE.RESULT), null); packet.generateResponse(IqPacket.TYPE.RESULT), null);
Log.d(Config.LOGTAG,account.getJid().asBareJid()+": received ibb close"); Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": received ibb close");
} else { } else {
Log.d(Config.LOGTAG,payload.toString()); Log.d(Config.LOGTAG, payload.toString());
// TODO some sort of exception // TODO some sort of exception
} }
} }