aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java')
-rw-r--r--src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java85
1 files changed, 53 insertions, 32 deletions
diff --git a/src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java b/src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java
index 4853d75c7..8e4714f4e 100644
--- a/src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java
+++ b/src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java
@@ -34,17 +34,18 @@ public class JingleConnection implements Downloadable {
private JingleConnectionManager mJingleConnectionManager;
private XmppConnectionService mXmppConnectionService;
- public static final int STATUS_INITIATED = 0;
- public static final int STATUS_ACCEPTED = 1;
- public static final int STATUS_TERMINATED = 2;
- public static final int STATUS_CANCELED = 3;
- public static final int STATUS_FINISHED = 4;
- public static final int STATUS_TRANSMITTING = 5;
- public static final int STATUS_FAILED = 99;
+ 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;
private int ibbBlockSize = 4096;
- private int status = -1;
+ private int mJingleStatus = -1;
+ private int mStatus = -1;
private Message message;
private String sessionId;
private Account account;
@@ -76,7 +77,7 @@ public class JingleConnection implements Downloadable {
mXmppConnectionService.markMessage(message,
Message.STATUS_SEND_FAILED);
}
- status = STATUS_FAILED;
+ mJingleStatus = JINGLE_STATUS_FAILED;
}
}
};
@@ -254,13 +255,14 @@ public class JingleConnection implements Downloadable {
}
public void init(Account account, JinglePacket packet) {
- this.status = STATUS_INITIATED;
+ this.mJingleStatus = JINGLE_STATUS_INITIATED;
Conversation conversation = this.mXmppConnectionService
.findOrCreateConversation(account,
packet.getFrom().split("/", 2)[0], false);
this.message = new Message(conversation, "", Message.ENCRYPTION_NONE);
+ this.message.setStatus(Message.STATUS_RECEIVED);
this.message.setType(Message.TYPE_IMAGE);
- this.message.setStatus(Message.STATUS_RECEIVED_OFFER);
+ this.mStatus = Downloadable.STATUS_OFFER;
this.message.setDownloadable(this);
String[] fromParts = packet.getFrom().split("/", 2);
this.message.setPresence(fromParts[1]);
@@ -306,6 +308,7 @@ public class JingleConnection implements Downloadable {
long size = Long.parseLong(fileSize.getContent());
message.setBody(Long.toString(size));
conversation.getMessages().add(message);
+ mXmppConnectionService.updateConversationUi();
if (size <= this.mJingleConnectionManager
.getAutoAcceptFileSize()) {
Log.d(Config.LOGTAG, "auto accepting file from "
@@ -370,7 +373,7 @@ public class JingleConnection implements Downloadable {
content.socks5transport().setChildren(getCandidatesAsElements());
packet.setContent(content);
this.sendJinglePacket(packet);
- this.status = STATUS_INITIATED;
+ this.mJingleStatus = JINGLE_STATUS_INITIATED;
}
}
@@ -383,8 +386,9 @@ public class JingleConnection implements Downloadable {
}
private void sendAccept() {
- status = STATUS_ACCEPTED;
- mXmppConnectionService.markMessage(message, Message.STATUS_RECEIVING);
+ mJingleStatus = JINGLE_STATUS_ACCEPTED;
+ this.mStatus = Downloadable.STATUS_DOWNLOADING;
+ mXmppConnectionService.updateConversationUi();
this.mJingleConnectionManager.getPrimaryCandidate(this.account,
new OnPrimaryCandidateFound() {
@@ -458,7 +462,7 @@ public class JingleConnection implements Downloadable {
Content content = packet.getJingleContent();
mergeCandidates(JingleCandidate.parse(content.socks5transport()
.getChildren()));
- this.status = STATUS_ACCEPTED;
+ this.mJingleStatus = JINGLE_STATUS_ACCEPTED;
mXmppConnectionService.markMessage(message, Message.STATUS_UNSEND);
this.connectNextCandidate();
return true;
@@ -493,7 +497,8 @@ public class JingleConnection implements Downloadable {
} else if (content.socks5transport().hasChild("candidate-error")) {
Log.d(Config.LOGTAG, "received candidate error");
this.receivedCandidate = true;
- if ((status == STATUS_ACCEPTED) && (this.sentCandidate)) {
+ if ((mJingleStatus == JINGLE_STATUS_ACCEPTED)
+ && (this.sentCandidate)) {
this.connect();
}
return true;
@@ -505,7 +510,8 @@ public class JingleConnection implements Downloadable {
JingleCandidate candidate = getCandidate(cid);
candidate.flagAsUsedByCounterpart();
this.receivedCandidate = true;
- if ((status == STATUS_ACCEPTED) && (this.sentCandidate)) {
+ if ((mJingleStatus == JINGLE_STATUS_ACCEPTED)
+ && (this.sentCandidate)) {
this.connect();
} else {
Log.d(Config.LOGTAG,
@@ -533,7 +539,7 @@ public class JingleConnection implements Downloadable {
this.sendFallbackToIbb();
}
} else {
- this.status = STATUS_TRANSMITTING;
+ this.mJingleStatus = JINGLE_STATUS_TRANSMITTING;
if (connection.needsActivation()) {
if (connection.getCandidate().isOurs()) {
Log.d(Config.LOGTAG, "candidate "
@@ -620,9 +626,10 @@ public class JingleConnection implements Downloadable {
packet.setReason(reason);
this.sendJinglePacket(packet);
this.disconnect();
- this.status = STATUS_FINISHED;
- this.mXmppConnectionService.markMessage(this.message,
- Message.STATUS_RECEIVED);
+ this.mJingleStatus = JINGLE_STATUS_FINISHED;
+ this.message.setStatus(Message.STATUS_RECEIVED);
+ this.message.setDownloadable(null);
+ this.mXmppConnectionService.updateMessage(message);
this.mJingleConnectionManager.finishConnection(this);
}
@@ -692,7 +699,7 @@ public class JingleConnection implements Downloadable {
}
private void receiveSuccess() {
- this.status = STATUS_FINISHED;
+ this.mJingleStatus = JINGLE_STATUS_FINISHED;
this.mXmppConnectionService.markMessage(this.message,
Message.STATUS_SEND);
this.disconnect();
@@ -700,14 +707,14 @@ public class JingleConnection implements Downloadable {
}
public void cancel() {
- this.status = STATUS_CANCELED;
+ this.mJingleStatus = JINGLE_STATUS_CANCELED;
this.disconnect();
if (this.message != null) {
if (this.responder.equals(account.getFullJid())) {
- this.mXmppConnectionService.markMessage(this.message,
- Message.STATUS_RECEPTION_FAILED);
+ this.mStatus = Downloadable.STATUS_FAILED;
+ this.mXmppConnectionService.updateConversationUi();
} else {
- if (this.status == STATUS_INITIATED) {
+ if (this.mJingleStatus == JINGLE_STATUS_INITIATED) {
this.mXmppConnectionService.markMessage(this.message,
Message.STATUS_SEND_REJECTED);
} else {
@@ -790,7 +797,7 @@ public class JingleConnection implements Downloadable {
.setAttribute("cid", cid);
packet.setContent(content);
this.sentCandidate = true;
- if ((receivedCandidate) && (status == STATUS_ACCEPTED)) {
+ if ((receivedCandidate) && (mJingleStatus == JINGLE_STATUS_ACCEPTED)) {
connect();
}
this.sendJinglePacket(packet);
@@ -803,7 +810,7 @@ public class JingleConnection implements Downloadable {
content.socks5transport().addChild("candidate-error");
packet.setContent(content);
this.sentCandidate = true;
- if ((receivedCandidate) && (status == STATUS_ACCEPTED)) {
+ if ((receivedCandidate) && (mJingleStatus == JINGLE_STATUS_ACCEPTED)) {
connect();
}
this.sendJinglePacket(packet);
@@ -817,8 +824,8 @@ public class JingleConnection implements Downloadable {
return this.responder;
}
- public int getStatus() {
- return this.status;
+ public int getJingleStatus() {
+ return this.mJingleStatus;
}
private boolean equalCandidateExists(JingleCandidate candidate) {
@@ -869,7 +876,7 @@ public class JingleConnection implements Downloadable {
}
public void start() {
- if (status == STATUS_INITIATED) {
+ if (mJingleStatus == JINGLE_STATUS_INITIATED) {
new Thread(new Runnable() {
@Override
@@ -878,7 +885,21 @@ public class JingleConnection implements Downloadable {
}
}).start();
} else {
- Log.d(Config.LOGTAG, "status (" + status + ") was not ok");
+ Log.d(Config.LOGTAG, "status (" + mJingleStatus + ") was not ok");
+ }
+ }
+
+ @Override
+ public int getStatus() {
+ return this.mStatus;
+ }
+
+ @Override
+ public long getFileSize() {
+ if (this.file != null) {
+ return this.file.getExpectedSize();
+ } else {
+ return 0;
}
}
}