aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/xmpp
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel.gultsch@rwth-aachen.de>2014-04-07 20:05:45 +0200
committerDaniel Gultsch <daniel.gultsch@rwth-aachen.de>2014-04-07 20:05:45 +0200
commit3f403fb8a976f6cc7d135cf1eb6dd6f0789c312a (patch)
tree69fb1e80e9380b337b775910798870b04c5e4037 /src/eu/siacs/conversations/xmpp
parentc30bf75a5d77fab21480e04ce18b46d6b2826295 (diff)
jingle connection and manager. able to trigger dialog in gajim
Diffstat (limited to 'src/eu/siacs/conversations/xmpp')
-rw-r--r--src/eu/siacs/conversations/xmpp/JingleConnection.java67
-rw-r--r--src/eu/siacs/conversations/xmpp/stanzas/jingle/Content.java22
-rw-r--r--src/eu/siacs/conversations/xmpp/stanzas/jingle/JinglePacket.java32
3 files changed, 116 insertions, 5 deletions
diff --git a/src/eu/siacs/conversations/xmpp/JingleConnection.java b/src/eu/siacs/conversations/xmpp/JingleConnection.java
new file mode 100644
index 00000000..34587a93
--- /dev/null
+++ b/src/eu/siacs/conversations/xmpp/JingleConnection.java
@@ -0,0 +1,67 @@
+package eu.siacs.conversations.xmpp;
+
+import java.math.BigInteger;
+import java.security.SecureRandom;
+import java.util.ArrayList;
+import java.util.List;
+
+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;
+
+public class JingleConnection {
+
+ private JingleConnectionManager mJingleConnectionManager;
+ private XmppConnectionService mXmppConnectionService;
+
+ private String sessionId;
+ private Account account;
+ private String counterpart;
+ private List<Element> canditates = new ArrayList<Element>();
+
+ public JingleConnection(JingleConnectionManager mJingleConnectionManager, Account account, String counterpart) {
+ 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()));
+ }
+
+ public String getSessionId() {
+ return this.sessionId;
+ }
+
+ public void init(Message message) {
+ 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);
+ }
+ }
+
+ private JinglePacket bootstrapPacket() {
+ JinglePacket packet = new JinglePacket();
+ packet.setFrom(account.getFullJid());
+ packet.setTo(this.counterpart+"/Gajim");
+ packet.setSessionId(this.sessionId);
+ return packet;
+ }
+
+}
diff --git a/src/eu/siacs/conversations/xmpp/stanzas/jingle/Content.java b/src/eu/siacs/conversations/xmpp/stanzas/jingle/Content.java
index ebd212b8..ed51a2a5 100644
--- a/src/eu/siacs/conversations/xmpp/stanzas/jingle/Content.java
+++ b/src/eu/siacs/conversations/xmpp/stanzas/jingle/Content.java
@@ -1,5 +1,8 @@
package eu.siacs.conversations.xmpp.stanzas.jingle;
+import java.io.File;
+import java.util.List;
+
import eu.siacs.conversations.xml.Element;
public class Content extends Element {
@@ -10,4 +13,23 @@ public class Content extends Element {
public Content() {
super("content");
}
+
+ public void offerFile(File actualFile) {
+ Element description = this.addChild("description", "urn:xmpp:jingle:apps:file-transfer:3");
+ Element offer = description.addChild("offer");
+ Element file = offer.addChild("file");
+ file.addChild("size").setContent(""+actualFile.length());
+ file.addChild("name").setContent(actualFile.getName());
+ }
+
+ public void setCanditates(List<Element> canditates) {
+ Element transport = this.findChild("transport", "urn:xmpp:jingle:transports:s5b:1");
+ if (transport==null) {
+ transport = this.addChild("transport", "urn:xmpp:jingle:transports:s5b:1");
+ }
+ transport.clearChildren();
+ for(Element canditate : canditates) {
+ transport.addChild(canditate);
+ }
+ }
}
diff --git a/src/eu/siacs/conversations/xmpp/stanzas/jingle/JinglePacket.java b/src/eu/siacs/conversations/xmpp/stanzas/jingle/JinglePacket.java
index 51c60d1f..4c444a74 100644
--- a/src/eu/siacs/conversations/xmpp/stanzas/jingle/JinglePacket.java
+++ b/src/eu/siacs/conversations/xmpp/stanzas/jingle/JinglePacket.java
@@ -6,6 +6,7 @@ import eu.siacs.conversations.xmpp.stanzas.IqPacket;
public class JinglePacket extends IqPacket {
Content content = null;
Reason reason = null;
+ Element jingle = new Element("jingle");
@Override
public Element addChild(Element child) {
@@ -22,27 +23,25 @@ public class JinglePacket extends IqPacket {
this.reason.setChildren(reasonElement.getChildren());
this.reason.setAttributes(reasonElement.getAttributes());
}
- this.build();
- this.findChild("jingle").setAttributes(child.getAttributes());
+ this.jingle.setAttributes(child.getAttributes());
}
return child;
}
public JinglePacket setContent(Content content) {
this.content = content;
- this.build();
return this;
}
public JinglePacket setReason(Reason reason) {
this.reason = reason;
- this.build();
return this;
}
private void build() {
this.children.clear();
- Element jingle = addChild("jingle", "urn:xmpp:jingle:1");
+ this.jingle.clearChildren();
+ this.jingle.setAttribute("xmlns", "urn:xmpp:jingle:1");
if (this.content!=null) {
jingle.addChild(this.content);
}
@@ -50,5 +49,28 @@ public class JinglePacket extends IqPacket {
jingle.addChild(this.reason);
}
this.children.add(jingle);
+ this.setAttribute("type", "set");
+ }
+
+ public String getSessionId() {
+ return this.jingle.getAttribute("sid");
+ }
+
+ public void setSessionId(String sid) {
+ this.jingle.setAttribute("sid", sid);
+ }
+
+ @Override
+ public String toString() {
+ this.build();
+ return super.toString();
+ }
+
+ public void setAction(String action) {
+ this.jingle.setAttribute("action", action);
+ }
+
+ public void setInitiator(String initiator) {
+ this.jingle.setAttribute("initiator", initiator);
}
}