aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/xmpp
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel.gultsch@rwth-aachen.de>2014-04-10 14:12:08 +0200
committerDaniel Gultsch <daniel.gultsch@rwth-aachen.de>2014-04-10 14:12:08 +0200
commit644473205ab261157f500470d496999db665d75f (patch)
treeca059f9b294bfaa79c6ed8dfb3d6fedddcaecf06 /src/eu/siacs/conversations/xmpp
parentba0bedc5facabc573023925660d7d49b27d5c68c (diff)
incomming jingle packets are routed to their connection. added presence chooser in gui
Diffstat (limited to 'src/eu/siacs/conversations/xmpp')
-rw-r--r--src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java27
-rw-r--r--src/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java112
-rw-r--r--src/eu/siacs/conversations/xmpp/jingle/stanzas/JinglePacket.java8
3 files changed, 106 insertions, 41 deletions
diff --git a/src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java b/src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java
index 60ba0291..e8f5aa22 100644
--- a/src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java
+++ b/src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java
@@ -19,6 +19,11 @@ public class JingleConnection {
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_FAILED = 99;
+
+ private int status = -1;
private Message message;
private String sessionId;
private Account account;
@@ -30,7 +35,9 @@ public class JingleConnection {
@Override
public void onIqPacketReceived(Account account, IqPacket packet) {
- Log.d("xmppService",packet.toString());
+ if (packet.getType() == IqPacket.TYPE_ERROR) {
+ status = STATUS_FAILED;
+ }
}
};
@@ -44,6 +51,21 @@ public class JingleConnection {
return this.sessionId;
}
+ public String getAccountJid() {
+ return this.account.getJid();
+ }
+
+ public String getCounterPart() {
+ return this.message.getCounterpart();
+ }
+
+ public void deliverPacket(JinglePacket packet) {
+ Log.d("xmppService","packet arrived in connection");
+ if (packet.isAction("")) {
+
+ }
+ }
+
public void init(Message message) {
this.message = message;
this.account = message.getConversation().getAccount();
@@ -78,13 +100,14 @@ public class JingleConnection {
packet.setContent(content);
Log.d("xmppService",packet.toString());
account.getXmppConnection().sendIqPacket(packet, this.responseListener);
+ this.status = STATUS_INITIATED;
}
}
private JinglePacket bootstrapPacket() {
JinglePacket packet = new JinglePacket();
packet.setFrom(account.getFullJid());
- packet.setTo(this.message.getCounterpart()+"/Gajim"); //fixme, not right in all cases;
+ packet.setTo(this.message.getCounterpart()); //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
index 784d90d4..b28f692a 100644
--- a/src/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java
+++ b/src/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java
@@ -17,76 +17,110 @@ 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 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());
+ for (JingleConnection connection : connections) {
+ if (connection.getAccountJid().equals(account.getJid()) && connection
+ .getSessionId().equals(packet.getSessionId()) && connection
+ .getCounterPart().equals(packet.getFrom())) {
+ connection.deliverPacket(packet);
+ return;
+ }
+ }
+ Log.d("xmppService","delivering packet failed "+packet.toString());
}
-
+
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);
+ connections.add(connection);
return connection;
}
-
- private String generateInternalId(String account, String counterpart, String sid) {
- return account+"#"+counterpart+"#"+sid;
-
+
+ public JingleConnection createNewConnection(JinglePacket packet) {
+ JingleConnection connection = new JingleConnection(this);
+ connections.add(connection);
+ 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) {
+ 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) {
+ final 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);
- }
- }
- });
+ 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");
+ canditate.setAttribute("jid", proxy);
+ canditate
+ .setAttribute("priority", "655360");
+ 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()));
+ 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/jingle/stanzas/JinglePacket.java b/src/eu/siacs/conversations/xmpp/jingle/stanzas/JinglePacket.java
index 9cb2b448..bd912ea3 100644
--- a/src/eu/siacs/conversations/xmpp/jingle/stanzas/JinglePacket.java
+++ b/src/eu/siacs/conversations/xmpp/jingle/stanzas/JinglePacket.java
@@ -70,7 +70,15 @@ public class JinglePacket extends IqPacket {
this.jingle.setAttribute("action", action);
}
+ public String getAction() {
+ return this.jingle.getAttribute("action");
+ }
+
public void setInitiator(String initiator) {
this.jingle.setAttribute("initiator", initiator);
}
+
+ public boolean isAction(String action) {
+ return action.equalsIgnoreCase(this.getAction());
+ }
}