aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/xmpp/jingle
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java (renamed from src/eu/siacs/conversations/xmpp/JingleConnection.java)57
-rw-r--r--src/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java93
-rw-r--r--src/eu/siacs/conversations/xmpp/jingle/OnJinglePacketReceived.java (renamed from src/eu/siacs/conversations/xmpp/OnJinglePacketReceived.java)5
-rw-r--r--src/eu/siacs/conversations/xmpp/jingle/OnPrimaryCanditateFound.java7
-rw-r--r--src/eu/siacs/conversations/xmpp/jingle/stanzas/Content.java (renamed from src/eu/siacs/conversations/xmpp/stanzas/jingle/Content.java)2
-rw-r--r--src/eu/siacs/conversations/xmpp/jingle/stanzas/JinglePacket.java (renamed from src/eu/siacs/conversations/xmpp/stanzas/jingle/JinglePacket.java)2
-rw-r--r--src/eu/siacs/conversations/xmpp/jingle/stanzas/Reason.java (renamed from src/eu/siacs/conversations/xmpp/stanzas/jingle/Reason.java)2
7 files changed, 147 insertions, 21 deletions
diff --git a/src/eu/siacs/conversations/xmpp/JingleConnection.java b/src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java
index 34587a93..60ba0291 100644
--- a/src/eu/siacs/conversations/xmpp/JingleConnection.java
+++ b/src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java
@@ -1,7 +1,5 @@
-package eu.siacs.conversations.xmpp;
+package eu.siacs.conversations.xmpp.jingle;
-import java.math.BigInteger;
-import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.List;
@@ -9,30 +7,37 @@ import android.util.Log;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Message;
-import eu.siacs.conversations.services.JingleConnectionManager;
import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.xml.Element;
-import eu.siacs.conversations.xmpp.stanzas.jingle.Content;
-import eu.siacs.conversations.xmpp.stanzas.jingle.JinglePacket;
+import eu.siacs.conversations.xmpp.OnIqPacketReceived;
+import eu.siacs.conversations.xmpp.jingle.stanzas.Content;
+import eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket;
+import eu.siacs.conversations.xmpp.stanzas.IqPacket;
public class JingleConnection {
private JingleConnectionManager mJingleConnectionManager;
private XmppConnectionService mXmppConnectionService;
+ private Message message;
private String sessionId;
private Account account;
- private String counterpart;
+ private String initiator;
+ private String responder;
private List<Element> canditates = new ArrayList<Element>();
- public JingleConnection(JingleConnectionManager mJingleConnectionManager, Account account, String counterpart) {
+ private OnIqPacketReceived responseListener = new OnIqPacketReceived() {
+
+ @Override
+ public void onIqPacketReceived(Account account, IqPacket packet) {
+ Log.d("xmppService",packet.toString());
+ }
+ };
+
+ public JingleConnection(JingleConnectionManager mJingleConnectionManager) {
this.mJingleConnectionManager = mJingleConnectionManager;
this.mXmppConnectionService = mJingleConnectionManager.getXmppConnectionService();
- this.account = account;
- this.counterpart = counterpart;
- SecureRandom random = new SecureRandom();
- sessionId = new BigInteger(100, random).toString(32);
- this.canditates.add(this.mJingleConnectionManager.getPrimaryCanditate(account.getJid()));
+ this.sessionId = this.mJingleConnectionManager.nextRandomId();
}
public String getSessionId() {
@@ -40,26 +45,46 @@ public class JingleConnection {
}
public void init(Message message) {
+ this.message = message;
+ this.account = message.getConversation().getAccount();
+ this.initiator = this.account.getFullJid();
+ if (this.canditates.size() > 0) {
+ this.sendInitRequest();
+ } else {
+ this.mJingleConnectionManager.getPrimaryCanditate(account, new OnPrimaryCanditateFound() {
+
+ @Override
+ public void onPrimaryCanditateFound(boolean success, Element canditate) {
+ if (success) {
+ canditates.add(canditate);
+ }
+ sendInitRequest();
+ }
+ });
+ }
+
+ }
+
+ private void sendInitRequest() {
JinglePacket packet = this.bootstrapPacket();
packet.setAction("session-initiate");
packet.setInitiator(this.account.getFullJid());
Content content = new Content();
if (message.getType() == Message.TYPE_IMAGE) {
- //creator='initiator' name='a-file-offer'
content.setAttribute("creator", "initiator");
content.setAttribute("name", "a-file-offer");
content.offerFile(this.mXmppConnectionService.getFileBackend().getImageFile(message));
content.setCanditates(this.canditates);
packet.setContent(content);
Log.d("xmppService",packet.toString());
- account.getXmppConnection().sendIqPacket(packet, null);
+ account.getXmppConnection().sendIqPacket(packet, this.responseListener);
}
}
private JinglePacket bootstrapPacket() {
JinglePacket packet = new JinglePacket();
packet.setFrom(account.getFullJid());
- packet.setTo(this.counterpart+"/Gajim");
+ packet.setTo(this.message.getCounterpart()+"/Gajim"); //fixme, not right in all cases;
packet.setSessionId(this.sessionId);
return packet;
}
diff --git a/src/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java b/src/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java
new file mode 100644
index 00000000..784d90d4
--- /dev/null
+++ b/src/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java
@@ -0,0 +1,93 @@
+package eu.siacs.conversations.xmpp.jingle;
+
+import java.math.BigInteger;
+import java.security.SecureRandom;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+
+import android.util.Log;
+
+import eu.siacs.conversations.entities.Account;
+import eu.siacs.conversations.entities.Message;
+import eu.siacs.conversations.services.XmppConnectionService;
+import eu.siacs.conversations.xml.Element;
+import eu.siacs.conversations.xmpp.OnIqPacketReceived;
+import eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket;
+import eu.siacs.conversations.xmpp.stanzas.IqPacket;
+
+public class JingleConnectionManager {
+
+ private XmppConnectionService xmppConnectionService;
+
+ private List<JingleConnection> connections = new ArrayList<JingleConnection>(); //make concurrent
+
+ private ConcurrentHashMap<String, Element> primaryCanditates = new ConcurrentHashMap<String, Element>();
+
+ private SecureRandom random = new SecureRandom();
+
+ public JingleConnectionManager(XmppConnectionService service) {
+ this.xmppConnectionService = service;
+ }
+
+ public void deliverPacket(Account account, JinglePacket packet) {
+ String id = generateInternalId(account.getJid(), packet.getFrom(), packet.getSessionId());
+ }
+
+ public JingleConnection createNewConnection(Message message) {
+ Account account = message.getConversation().getAccount();
+ JingleConnection connection = new JingleConnection(this);
+ String id = generateInternalId(account.getJid(), message.getCounterpart(), connection.getSessionId());
+ connection.init(message);
+ return connection;
+ }
+
+ private String generateInternalId(String account, String counterpart, String sid) {
+ return account+"#"+counterpart+"#"+sid;
+
+ }
+
+ public XmppConnectionService getXmppConnectionService() {
+ return this.xmppConnectionService;
+ }
+
+ public void getPrimaryCanditate(Account account, final OnPrimaryCanditateFound listener) {
+ if (!this.primaryCanditates.containsKey(account.getJid())) {
+ String xmlns = "http://jabber.org/protocol/bytestreams";
+ String proxy = account.getXmppConnection().findDiscoItemByFeature(xmlns);
+ if (proxy!=null) {
+ IqPacket iq = new IqPacket(IqPacket.TYPE_GET);
+ iq.setTo(proxy);
+ iq.query(xmlns);
+ 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) {
+ Log.d("xmppService","streamhost found "+streamhost.toString());
+ Element canditate = new Element("canditate");
+ canditate.setAttribute("cid",nextRandomId());
+ canditate.setAttribute("host", streamhost.getAttribute("host"));
+ canditate.setAttribute("port",streamhost.getAttribute("port"));
+ canditate.setAttribute("type", "proxy");
+ primaryCanditates.put(account.getJid(), canditate);
+ listener.onPrimaryCanditateFound(true, canditate);
+ } else {
+ listener.onPrimaryCanditateFound(false, null);
+ }
+ }
+ });
+ } else {
+ listener.onPrimaryCanditateFound(false, null);
+ }
+
+ } else {
+ listener.onPrimaryCanditateFound(true, this.primaryCanditates.get(account.getJid()));
+ }
+ }
+
+ public String nextRandomId() {
+ return new BigInteger(50, random).toString(32);
+ }
+}
diff --git a/src/eu/siacs/conversations/xmpp/OnJinglePacketReceived.java b/src/eu/siacs/conversations/xmpp/jingle/OnJinglePacketReceived.java
index 6705e309..2aaf62a1 100644
--- a/src/eu/siacs/conversations/xmpp/OnJinglePacketReceived.java
+++ b/src/eu/siacs/conversations/xmpp/jingle/OnJinglePacketReceived.java
@@ -1,7 +1,8 @@
-package eu.siacs.conversations.xmpp;
+package eu.siacs.conversations.xmpp.jingle;
import eu.siacs.conversations.entities.Account;
-import eu.siacs.conversations.xmpp.stanzas.jingle.JinglePacket;
+import eu.siacs.conversations.xmpp.PacketReceived;
+import eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket;
public interface OnJinglePacketReceived extends PacketReceived {
public void onJinglePacketReceived(Account account, JinglePacket packet);
diff --git a/src/eu/siacs/conversations/xmpp/jingle/OnPrimaryCanditateFound.java b/src/eu/siacs/conversations/xmpp/jingle/OnPrimaryCanditateFound.java
new file mode 100644
index 00000000..25aab118
--- /dev/null
+++ b/src/eu/siacs/conversations/xmpp/jingle/OnPrimaryCanditateFound.java
@@ -0,0 +1,7 @@
+package eu.siacs.conversations.xmpp.jingle;
+
+import eu.siacs.conversations.xml.Element;
+
+public interface OnPrimaryCanditateFound {
+ public void onPrimaryCanditateFound(boolean success, Element canditate);
+}
diff --git a/src/eu/siacs/conversations/xmpp/stanzas/jingle/Content.java b/src/eu/siacs/conversations/xmpp/jingle/stanzas/Content.java
index ed51a2a5..941e6559 100644
--- a/src/eu/siacs/conversations/xmpp/stanzas/jingle/Content.java
+++ b/src/eu/siacs/conversations/xmpp/jingle/stanzas/Content.java
@@ -1,4 +1,4 @@
-package eu.siacs.conversations.xmpp.stanzas.jingle;
+package eu.siacs.conversations.xmpp.jingle.stanzas;
import java.io.File;
import java.util.List;
diff --git a/src/eu/siacs/conversations/xmpp/stanzas/jingle/JinglePacket.java b/src/eu/siacs/conversations/xmpp/jingle/stanzas/JinglePacket.java
index 4c444a74..9cb2b448 100644
--- a/src/eu/siacs/conversations/xmpp/stanzas/jingle/JinglePacket.java
+++ b/src/eu/siacs/conversations/xmpp/jingle/stanzas/JinglePacket.java
@@ -1,4 +1,4 @@
-package eu.siacs.conversations.xmpp.stanzas.jingle;
+package eu.siacs.conversations.xmpp.jingle.stanzas;
import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xmpp.stanzas.IqPacket;
diff --git a/src/eu/siacs/conversations/xmpp/stanzas/jingle/Reason.java b/src/eu/siacs/conversations/xmpp/jingle/stanzas/Reason.java
index 35b81655..195e0db7 100644
--- a/src/eu/siacs/conversations/xmpp/stanzas/jingle/Reason.java
+++ b/src/eu/siacs/conversations/xmpp/jingle/stanzas/Reason.java
@@ -1,4 +1,4 @@
-package eu.siacs.conversations.xmpp.stanzas.jingle;
+package eu.siacs.conversations.xmpp.jingle.stanzas;
import eu.siacs.conversations.xml.Element;