diff options
author | steckbrief <steckbrief@chefmail.de> | 2015-02-20 22:19:31 +0100 |
---|---|---|
committer | steckbrief <steckbrief@chefmail.de> | 2015-02-20 22:19:31 +0100 |
commit | 20eae3955700341188bc1907a506970f5817a153 (patch) | |
tree | 6e50d9083a4392875b5f9dbe92b38973cf95c332 /src/main/java/eu/siacs/conversations/xmpp/jingle | |
parent | 980a84a6ce4358e8662addf203695e01d9f931dc (diff) | |
parent | ecbceae88b7a7aa871e5396efec1e2ff8d056d46 (diff) |
Merge master-origin
Conflicts:
src/main/java/eu/siacs/conversations/ui/SettingsActivity.java
src/main/java/eu/siacs/conversations/ui/XmppActivity.java
src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java
src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java
src/main/java/eu/siacs/conversations/utils/UIHelper.java
src/main/res/values-de/strings.xml
Diffstat (limited to '')
4 files changed, 112 insertions, 130 deletions
diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleCandidate.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleCandidate.java index 281ea3ca..dcadb92f 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleCandidate.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleCandidate.java @@ -85,8 +85,7 @@ public class JingleCandidate { } public boolean equalValues(JingleCandidate other) { - return other.getHost().equals(this.getHost()) - && (other.getPort() == this.getPort()); + return other != null && other.getHost().equals(this.getHost()) && (other.getPort() == this.getPort()); } public boolean isOurs() { diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java index d578ca38..2d949e21 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java @@ -36,8 +36,6 @@ public class JingleConnection implements Downloadable { protected static final int JINGLE_STATUS_INITIATED = 0; protected static final int JINGLE_STATUS_ACCEPTED = 1; - protected static final int JINGLE_STATUS_TERMINATED = 2; - protected static final int JINGLE_STATUS_CANCELED = 3; protected static final int JINGLE_STATUS_FINISHED = 4; protected static final int JINGLE_STATUS_TRANSMITTING = 5; protected static final int JINGLE_STATUS_FAILED = 99; @@ -75,7 +73,7 @@ public class JingleConnection implements Downloadable { @Override public void onIqPacketReceived(Account account, IqPacket packet) { - if (packet.getType() == IqPacket.TYPE_ERROR) { + if (packet.getType() == IqPacket.TYPE.ERROR) { fail(); } } @@ -101,11 +99,9 @@ public class JingleConnection implements Downloadable { file.delete(); } } - Log.d(Config.LOGTAG, - "sucessfully transmitted file:" + file.getAbsolutePath()); + Log.d(Config.LOGTAG,"sucessfully transmitted file:" + file.getAbsolutePath()); if (message.getEncryption() != Message.ENCRYPTION_PGP) { - Intent intent = new Intent( - Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); + Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); intent.setData(Uri.fromFile(file)); mXmppConnectionService.sendBroadcast(intent); } @@ -191,10 +187,10 @@ public class JingleConnection implements Downloadable { } IqPacket response; if (returnResult) { - response = packet.generateResponse(IqPacket.TYPE_RESULT); + response = packet.generateResponse(IqPacket.TYPE.RESULT); } else { - response = packet.generateResponse(IqPacket.TYPE_ERROR); + response = packet.generateResponse(IqPacket.TYPE.ERROR); } account.getXmppConnection().sendIqPacket(response, null); } @@ -280,16 +276,18 @@ public class JingleConnection implements Downloadable { Element fileNameElement = fileOffer.findChild("name"); if (fileNameElement != null) { String[] filename = fileNameElement.getContent() - .toLowerCase(Locale.US).split("\\."); - if (Arrays.asList(VALID_IMAGE_EXTENSIONS).contains( - filename[filename.length - 1])) { + .toLowerCase(Locale.US).toLowerCase().split("\\."); + String extension = filename[filename.length - 1]; + if (Arrays.asList(VALID_IMAGE_EXTENSIONS).contains(extension)) { message.setType(Message.TYPE_IMAGE); + message.setRelativeFilePath(message.getUuid()+"."+extension); } else if (Arrays.asList(VALID_CRYPTO_EXTENSIONS).contains( filename[filename.length - 1])) { if (filename.length == 3) { - if (Arrays.asList(VALID_IMAGE_EXTENSIONS).contains( - filename[filename.length - 2])) { + extension = filename[filename.length - 2]; + if (Arrays.asList(VALID_IMAGE_EXTENSIONS).contains(extension)) { message.setType(Message.TYPE_IMAGE); + message.setRelativeFilePath(message.getUuid()+"."+extension); } else { message.setType(Message.TYPE_FILE); } @@ -360,7 +358,6 @@ public class JingleConnection implements Downloadable { } private void sendInitRequest() { - this.mXmppConnectionService.markMessage(this.message, Message.STATUS_OFFERED); JinglePacket packet = this.bootstrapPacket("session-initiate"); Content content = new Content(this.contentCreator, this.contentName); if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE) { @@ -379,8 +376,19 @@ public class JingleConnection implements Downloadable { content.setTransportId(this.transportId); content.socks5transport().setChildren(getCandidatesAsElements()); packet.setContent(content); - this.sendJinglePacket(packet); - this.mJingleStatus = JINGLE_STATUS_INITIATED; + this.sendJinglePacket(packet,new OnIqPacketReceived() { + + @Override + public void onIqPacketReceived(Account account, IqPacket packet) { + if (packet.getType() != IqPacket.TYPE.ERROR) { + mJingleStatus = JINGLE_STATUS_INITIATED; + mXmppConnectionService.markMessage(message, Message.STATUS_OFFERED); + } else { + fail(); + } + } + }); + } } @@ -396,58 +404,48 @@ public class JingleConnection implements Downloadable { mJingleStatus = JINGLE_STATUS_ACCEPTED; this.mStatus = Downloadable.STATUS_DOWNLOADING; mXmppConnectionService.updateConversationUi(); - this.mJingleConnectionManager.getPrimaryCandidate(this.account, - new OnPrimaryCandidateFound() { - - @Override - public void onPrimaryCandidateFound(boolean success, - final JingleCandidate candidate) { - final JinglePacket packet = bootstrapPacket("session-accept"); - final Content content = new Content(contentCreator, - contentName); - content.setFileOffer(fileOffer); - content.setTransportId(transportId); - if ((success) && (!equalCandidateExists(candidate))) { - final JingleSocks5Transport socksConnection = new JingleSocks5Transport( - JingleConnection.this, candidate); - connections.put(candidate.getCid(), socksConnection); - socksConnection.connect(new OnTransportConnected() { - - @Override - public void failed() { - Log.d(Config.LOGTAG, - "connection to our own primary candidate failed"); - content.socks5transport().setChildren( - getCandidatesAsElements()); - packet.setContent(content); - sendJinglePacket(packet); - connectNextCandidate(); - } + this.mJingleConnectionManager.getPrimaryCandidate(this.account, new OnPrimaryCandidateFound() { + @Override + public void onPrimaryCandidateFound(boolean success, final JingleCandidate candidate) { + final JinglePacket packet = bootstrapPacket("session-accept"); + final Content content = new Content(contentCreator,contentName); + content.setFileOffer(fileOffer); + content.setTransportId(transportId); + if (success && candidate != null && !equalCandidateExists(candidate)) { + final JingleSocks5Transport socksConnection = new JingleSocks5Transport( + JingleConnection.this, + candidate); + connections.put(candidate.getCid(), socksConnection); + socksConnection.connect(new OnTransportConnected() { - @Override - public void established() { - Log.d(Config.LOGTAG, - "connected to primary candidate"); - mergeCandidate(candidate); - content.socks5transport().setChildren( - getCandidatesAsElements()); - packet.setContent(content); - sendJinglePacket(packet); - connectNextCandidate(); - } - }); - } else { - Log.d(Config.LOGTAG, - "did not find a primary candidate for ourself"); - content.socks5transport().setChildren( - getCandidatesAsElements()); + @Override + public void failed() { + Log.d(Config.LOGTAG,"connection to our own primary candidate failed"); + content.socks5transport().setChildren(getCandidatesAsElements()); packet.setContent(content); sendJinglePacket(packet); connectNextCandidate(); } - } - }); + @Override + public void established() { + Log.d(Config.LOGTAG, "connected to primary candidate"); + mergeCandidate(candidate); + content.socks5transport().setChildren(getCandidatesAsElements()); + packet.setContent(content); + sendJinglePacket(packet); + connectNextCandidate(); + } + }); + } else { + Log.d(Config.LOGTAG,"did not find a primary candidate for ourself"); + content.socks5transport().setChildren(getCandidatesAsElements()); + packet.setContent(content); + sendJinglePacket(packet); + connectNextCandidate(); + } + } + }); } private JinglePacket bootstrapPacket(String action) { @@ -461,10 +459,13 @@ public class JingleConnection implements Downloadable { } private void sendJinglePacket(JinglePacket packet) { - // Log.d(Config.LOGTAG,packet.toString()); account.getXmppConnection().sendIqPacket(packet, responseListener); } + private void sendJinglePacket(JinglePacket packet, OnIqPacketReceived callback) { + account.getXmppConnection().sendIqPacket(packet,callback); + } + private boolean receiveAccept(JinglePacket packet) { Content content = packet.getJingleContent(); mergeCandidates(JingleCandidate.parse(content.socks5transport() @@ -479,16 +480,13 @@ public class JingleConnection implements Downloadable { Content content = packet.getJingleContent(); if (content.hasSocks5Transport()) { if (content.socks5transport().hasChild("activated")) { - if ((this.transport != null) - && (this.transport instanceof JingleSocks5Transport)) { + if ((this.transport != null) && (this.transport instanceof JingleSocks5Transport)) { onProxyActivated.success(); } else { - String cid = content.socks5transport() - .findChild("activated").getAttribute("cid"); + String cid = content.socks5transport().findChild("activated").getAttribute("cid"); Log.d(Config.LOGTAG, "received proxy activated (" + cid + ")prior to choosing our own transport"); - JingleSocks5Transport connection = this.connections - .get(cid); + JingleSocks5Transport connection = this.connections.get(cid); if (connection != null) { connection.setActivated(true); } else { @@ -552,7 +550,7 @@ public class JingleConnection implements Downloadable { Log.d(Config.LOGTAG, "candidate " + connection.getCandidate().getCid() + " was our proxy. going to activate"); - IqPacket activation = new IqPacket(IqPacket.TYPE_SET); + IqPacket activation = new IqPacket(IqPacket.TYPE.SET); activation.setTo(connection.getCandidate().getJid()); activation.query("http://jabber.org/protocol/bytestreams") .setAttribute("sid", this.getSessionId()); @@ -564,7 +562,7 @@ public class JingleConnection implements Downloadable { @Override public void onIqPacketReceived(Account account, IqPacket packet) { - if (packet.getType() == IqPacket.TYPE_ERROR) { + if (packet.getType() == IqPacket.TYPE.ERROR) { onProxyActivated.failed(); } else { onProxyActivated.success(); @@ -707,8 +705,7 @@ public class JingleConnection implements Downloadable { private void receiveSuccess() { this.mJingleStatus = JINGLE_STATUS_FINISHED; - this.mXmppConnectionService.markMessage(this.message, - Message.STATUS_SEND); + this.mXmppConnectionService.markMessage(this.message,Message.STATUS_SEND_RECEIVED); this.disconnectSocks5Connections(); if (this.transport != null && this.transport instanceof JingleInbandTransport) { this.transport.disconnect(); diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java index b0a730b1..5dfa3ff4 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java @@ -12,6 +12,7 @@ import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.services.AbstractConnectionManager; import eu.siacs.conversations.services.XmppConnectionService; +import eu.siacs.conversations.utils.Xmlns; import eu.siacs.conversations.xml.Element; import eu.siacs.conversations.xmpp.OnIqPacketReceived; import eu.siacs.conversations.xmpp.jid.InvalidJidException; @@ -46,7 +47,7 @@ public class JingleConnectionManager extends AbstractConnectionManager { return; } } - IqPacket response = packet.generateResponse(IqPacket.TYPE_ERROR); + IqPacket response = packet.generateResponse(IqPacket.TYPE.ERROR); Element error = response.addChild("error"); error.setAttribute("type", "cancel"); error.addChild("item-not-found", @@ -80,49 +81,37 @@ public class JingleConnectionManager extends AbstractConnectionManager { return; } if (!this.primaryCandidates.containsKey(account.getJid().toBareJid())) { - String xmlns = "http://jabber.org/protocol/bytestreams"; - final String proxy = account.getXmppConnection() - .findDiscoItemByFeature(xmlns); + final String proxy = account.getXmppConnection().findDiscoItemByFeature(Xmlns.BYTE_STREAMS); if (proxy != null) { - IqPacket iq = new IqPacket(IqPacket.TYPE_GET); + IqPacket iq = new IqPacket(IqPacket.TYPE.GET); iq.setAttribute("to", proxy); - iq.query(xmlns); - account.getXmppConnection().sendIqPacket(iq, - new OnIqPacketReceived() { + iq.query(Xmlns.BYTE_STREAMS); + account.getXmppConnection().sendIqPacket(iq,new OnIqPacketReceived() { - @Override - public void onIqPacketReceived(Account account, - IqPacket packet) { - Element streamhost = packet - .query() - .findChild("streamhost", - "http://jabber.org/protocol/bytestreams"); - if (streamhost != null) { - JingleCandidate candidate = new JingleCandidate( - nextRandomId(), true); - candidate.setHost(streamhost - .getAttribute("host")); - candidate.setPort(Integer - .parseInt(streamhost - .getAttribute("port"))); - candidate - .setType(JingleCandidate.TYPE_PROXY); - try { - candidate.setJid(Jid.fromString(proxy)); - } catch (final InvalidJidException e) { - candidate.setJid(null); - } - candidate.setPriority(655360 + 65535); - primaryCandidates.put(account.getJid().toBareJid(), - candidate); - listener.onPrimaryCandidateFound(true, - candidate); - } else { - listener.onPrimaryCandidateFound(false, - null); - } + @Override + public void onIqPacketReceived(Account account, IqPacket packet) { + Element streamhost = packet.query().findChild("streamhost",Xmlns.BYTE_STREAMS); + final String host = streamhost == null ? null : streamhost.getAttribute("host"); + final String port = streamhost == null ? null : streamhost.getAttribute("port"); + if (host != null && port != null) { + try { + JingleCandidate candidate = new JingleCandidate(nextRandomId(), true); + candidate.setHost(host); + candidate.setPort(Integer.parseInt(port)); + candidate.setType(JingleCandidate.TYPE_PROXY); + candidate.setJid(Jid.fromString(proxy)); + candidate.setPriority(655360 + 65535); + primaryCandidates.put(account.getJid().toBareJid(),candidate); + listener.onPrimaryCandidateFound(true,candidate); + } catch (final NumberFormatException | InvalidJidException e) { + listener.onPrimaryCandidateFound(false,null); + return; } - }); + } else { + listener.onPrimaryCandidateFound(false,null); + } + } + }); } else { listener.onPrimaryCandidateFound(false, null); } @@ -141,12 +130,10 @@ public class JingleConnectionManager extends AbstractConnectionManager { String sid = null; Element payload = null; if (packet.hasChild("open", "http://jabber.org/protocol/ibb")) { - payload = packet - .findChild("open", "http://jabber.org/protocol/ibb"); + payload = packet.findChild("open", "http://jabber.org/protocol/ibb"); sid = payload.getAttribute("sid"); } else if (packet.hasChild("data", "http://jabber.org/protocol/ibb")) { - payload = packet - .findChild("data", "http://jabber.org/protocol/ibb"); + payload = packet.findChild("data", "http://jabber.org/protocol/ibb"); sid = payload.getAttribute("sid"); } if (sid != null) { @@ -161,10 +148,9 @@ public class JingleConnectionManager extends AbstractConnectionManager { } } } - Log.d(Config.LOGTAG, - "couldnt deliver payload: " + payload.toString()); + Log.d(Config.LOGTAG,"couldn't deliver payload: " + payload.toString()); } else { - Log.d(Config.LOGTAG, "no sid found in incomming ibb packet"); + Log.d(Config.LOGTAG, "no sid found in incoming ibb packet"); } } diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleInbandTransport.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleInbandTransport.java index e25f7e65..174f70fa 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleInbandTransport.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleInbandTransport.java @@ -44,7 +44,7 @@ public class JingleInbandTransport extends JingleTransport { private OnIqPacketReceived onAckReceived = new OnIqPacketReceived() { @Override public void onIqPacketReceived(Account account, IqPacket packet) { - if (connected && packet.getType() == IqPacket.TYPE_RESULT) { + if (connected && packet.getType() == IqPacket.TYPE.RESULT) { sendNextBlock(); } } @@ -60,7 +60,7 @@ public class JingleInbandTransport extends JingleTransport { } public void connect(final OnTransportConnected callback) { - IqPacket iq = new IqPacket(IqPacket.TYPE_SET); + IqPacket iq = new IqPacket(IqPacket.TYPE.SET); iq.setTo(this.counterpart); Element open = iq.addChild("open", "http://jabber.org/protocol/ibb"); open.setAttribute("sid", this.sessionId); @@ -73,7 +73,7 @@ public class JingleInbandTransport extends JingleTransport { @Override public void onIqPacketReceived(Account account, IqPacket packet) { - if (packet.getType() == IqPacket.TYPE_ERROR) { + if (packet.getType() == IqPacket.TYPE.ERROR) { callback.failed(); } else { callback.established(); @@ -157,7 +157,7 @@ public class JingleInbandTransport extends JingleTransport { this.remainingSize -= count; this.digest.update(buffer); String base64 = Base64.encodeToString(buffer, Base64.NO_WRAP); - IqPacket iq = new IqPacket(IqPacket.TYPE_SET); + IqPacket iq = new IqPacket(IqPacket.TYPE.SET); iq.setTo(this.counterpart); Element data = iq.addChild("data", "http://jabber.org/protocol/ibb"); @@ -208,15 +208,15 @@ public class JingleInbandTransport extends JingleTransport { established = true; connected = true; this.account.getXmppConnection().sendIqPacket( - packet.generateResponse(IqPacket.TYPE_RESULT), null); + packet.generateResponse(IqPacket.TYPE.RESULT), null); } else { this.account.getXmppConnection().sendIqPacket( - packet.generateResponse(IqPacket.TYPE_ERROR), null); + packet.generateResponse(IqPacket.TYPE.ERROR), null); } } else if (connected && payload.getName().equals("data")) { this.receiveNextBlock(payload.getContent()); this.account.getXmppConnection().sendIqPacket( - packet.generateResponse(IqPacket.TYPE_RESULT), null); + packet.generateResponse(IqPacket.TYPE.RESULT), null); } else { // TODO some sort of exception } |