diff options
author | Daniel Gultsch <daniel.gultsch@rwth-aachen.de> | 2014-04-07 20:05:45 +0200 |
---|---|---|
committer | Daniel Gultsch <daniel.gultsch@rwth-aachen.de> | 2014-04-07 20:05:45 +0200 |
commit | 3f403fb8a976f6cc7d135cf1eb6dd6f0789c312a (patch) | |
tree | 69fb1e80e9380b337b775910798870b04c5e4037 /src/eu/siacs/conversations/services | |
parent | c30bf75a5d77fab21480e04ce18b46d6b2826295 (diff) |
jingle connection and manager. able to trigger dialog in gajim
Diffstat (limited to 'src/eu/siacs/conversations/services')
-rw-r--r-- | src/eu/siacs/conversations/services/JingleConnectionManager.java | 50 | ||||
-rw-r--r-- | src/eu/siacs/conversations/services/XmppConnectionService.java | 85 |
2 files changed, 96 insertions, 39 deletions
diff --git a/src/eu/siacs/conversations/services/JingleConnectionManager.java b/src/eu/siacs/conversations/services/JingleConnectionManager.java new file mode 100644 index 000000000..f2ca927a5 --- /dev/null +++ b/src/eu/siacs/conversations/services/JingleConnectionManager.java @@ -0,0 +1,50 @@ +package eu.siacs.conversations.services; + +import java.util.concurrent.ConcurrentHashMap; + +import eu.siacs.conversations.entities.Account; +import eu.siacs.conversations.entities.Message; +import eu.siacs.conversations.xml.Element; +import eu.siacs.conversations.xmpp.JingleConnection; +import eu.siacs.conversations.xmpp.stanzas.jingle.JinglePacket; + +public class JingleConnectionManager { + + private XmppConnectionService xmppConnectionService; + + private ConcurrentHashMap<String, JingleConnection> connections = new ConcurrentHashMap<String, JingleConnection>(); + + 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,account, message.getCounterpart()); + 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 Element getPrimaryCanditate(String jid) { + Element canditate = new Element("canditate"); + canditate.setAttribute("cid","122"); + canditate.setAttribute("port","1234"); + canditate.setAttribute("jid", jid); + canditate.setAttribute("type", "assisted"); + return canditate; + } +} diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index e8ec6f7f1..62e487733 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -87,7 +87,8 @@ public class XmppConnectionService extends Service { private List<Account> accounts; private List<Conversation> conversations = null; - + private JingleConnectionManager mJingleConnectionManager = new JingleConnectionManager(this); + public OnConversationListChangedListener convChangedListener = null; private int convChangedListenerCount = 0; private OnAccountListChangedListener accountChangedListener = null; @@ -389,13 +390,15 @@ public class XmppConnectionService extends Service { return this.fileBackend; } - public void attachImageToConversation(Conversation conversation, Uri uri) { + public Message attachImageToConversation(Conversation conversation, Uri uri) { Message message = new Message(conversation, "", Message.ENCRYPTION_NONE); message.setType(Message.TYPE_IMAGE); File file = this.fileBackend.copyImageToPrivateStorage(message, uri); Log.d(LOGTAG,"new file"+file.getAbsolutePath()); conversation.getMessages().add(message); databaseBackend.createMessage(message); + sendMessage(message, null); + return message; } @@ -655,48 +658,52 @@ public class XmppConnectionService extends Service { boolean saveInDb = false; boolean addToConversation = false; if (account.getStatus() == Account.STATUS_ONLINE) { - MessagePacket packet; - if (message.getEncryption() == Message.ENCRYPTION_OTR) { - if (!conv.hasValidOtrSession()) { - // starting otr session. messages will be send later - conv.startOtrSession(getApplicationContext(), presence,true); - } else if (conv.getOtrSession().getSessionStatus() == SessionStatus.ENCRYPTED) { - // otr session aleary exists, creating message packet - // accordingly - packet = prepareMessagePacket(account, message, - conv.getOtrSession()); - account.getXmppConnection().sendMessagePacket(packet); - message.setStatus(Message.STATUS_SEND); - } - saveInDb = true; - addToConversation = true; - } else if (message.getEncryption() == Message.ENCRYPTION_PGP) { - message.getConversation().endOtrIfNeeded(); - long keyId = message.getConversation().getContact() - .getPgpKeyId(); - packet = new MessagePacket(); - packet.setType(MessagePacket.TYPE_CHAT); - packet.setFrom(message.getConversation().getAccount() - .getFullJid()); - packet.setTo(message.getCounterpart()); - packet.setBody("This is an XEP-0027 encryted message"); - packet.addChild("x", "jabber:x:encrypted").setContent(message.getEncryptedBody()); - account.getXmppConnection().sendMessagePacket(packet); - message.setStatus(Message.STATUS_SEND); - message.setEncryption(Message.ENCRYPTION_DECRYPTED); - saveInDb = true; - addToConversation = true; + if (message.getType() == Message.TYPE_IMAGE) { + mJingleConnectionManager.createNewConnection(message); } else { - message.getConversation().endOtrIfNeeded(); - // don't encrypt - if (message.getConversation().getMode() == Conversation.MODE_SINGLE) { + MessagePacket packet; + if (message.getEncryption() == Message.ENCRYPTION_OTR) { + if (!conv.hasValidOtrSession()) { + // starting otr session. messages will be send later + conv.startOtrSession(getApplicationContext(), presence,true); + } else if (conv.getOtrSession().getSessionStatus() == SessionStatus.ENCRYPTED) { + // otr session aleary exists, creating message packet + // accordingly + packet = prepareMessagePacket(account, message, + conv.getOtrSession()); + account.getXmppConnection().sendMessagePacket(packet); + message.setStatus(Message.STATUS_SEND); + } + saveInDb = true; + addToConversation = true; + } else if (message.getEncryption() == Message.ENCRYPTION_PGP) { + message.getConversation().endOtrIfNeeded(); + long keyId = message.getConversation().getContact() + .getPgpKeyId(); + packet = new MessagePacket(); + packet.setType(MessagePacket.TYPE_CHAT); + packet.setFrom(message.getConversation().getAccount() + .getFullJid()); + packet.setTo(message.getCounterpart()); + packet.setBody("This is an XEP-0027 encryted message"); + packet.addChild("x", "jabber:x:encrypted").setContent(message.getEncryptedBody()); + account.getXmppConnection().sendMessagePacket(packet); message.setStatus(Message.STATUS_SEND); + message.setEncryption(Message.ENCRYPTION_DECRYPTED); saveInDb = true; addToConversation = true; + } else { + message.getConversation().endOtrIfNeeded(); + // don't encrypt + if (message.getConversation().getMode() == Conversation.MODE_SINGLE) { + message.setStatus(Message.STATUS_SEND); + saveInDb = true; + addToConversation = true; + } + + packet = prepareMessagePacket(account, message, null); + account.getXmppConnection().sendMessagePacket(packet); } - - packet = prepareMessagePacket(account, message, null); - account.getXmppConnection().sendMessagePacket(packet); } } else { // account is offline |