Search in sources :

Example 1 with Jid

use of eu.siacs.conversations.xmpp.jid.Jid in project Conversations by siacs.

the class ExportLogsService method writeToFile.

private void writeToFile(Conversation conversation) {
    Jid accountJid = resolveAccountUuid(conversation.getAccountUuid());
    Jid contactJid = conversation.getJid();
    File dir = new File(String.format(DIRECTORY_STRING_FORMAT, accountJid.toBareJid().toString()));
    dir.mkdirs();
    BufferedWriter bw = null;
    try {
        for (Message message : mDatabaseBackend.getMessagesIterable(conversation)) {
            if (message == null)
                continue;
            if (message.getType() == Message.TYPE_TEXT || message.hasFileOnRemoteHost()) {
                String date = simpleDateFormat.format(new Date(message.getTimeSent()));
                if (bw == null) {
                    bw = new BufferedWriter(new FileWriter(new File(dir, contactJid.toBareJid().toString() + ".txt")));
                }
                String jid = null;
                switch(message.getStatus()) {
                    case Message.STATUS_RECEIVED:
                        jid = getMessageCounterpart(message);
                        break;
                    case Message.STATUS_SEND:
                    case Message.STATUS_SEND_RECEIVED:
                    case Message.STATUS_SEND_DISPLAYED:
                        jid = accountJid.toBareJid().toString();
                        break;
                }
                if (jid != null) {
                    String body = message.hasFileOnRemoteHost() ? message.getFileParams().url.toString() : message.getBody();
                    bw.write(String.format(MESSAGE_STRING_FORMAT, date, jid, body.replace("\\\n", "\\ \n").replace("\n", "\\ \n")));
                }
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            if (bw != null) {
                bw.close();
            }
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }
}
Also used : Jid(eu.siacs.conversations.xmpp.jid.Jid) Message(eu.siacs.conversations.entities.Message) FileWriter(java.io.FileWriter) IOException(java.io.IOException) File(java.io.File) Date(java.util.Date) BufferedWriter(java.io.BufferedWriter)

Example 2 with Jid

use of eu.siacs.conversations.xmpp.jid.Jid in project Conversations by siacs.

the class XmppConnectionService method sendReadMarker.

public void sendReadMarker(final Conversation conversation) {
    final Message markable = conversation.getLatestMarkableMessage();
    if (this.markRead(conversation)) {
        updateConversationUi();
    }
    if (confirmMessages() && markable != null && markable.trusted() && markable.getRemoteMsgId() != null) {
        Log.d(Config.LOGTAG, conversation.getAccount().getJid().toBareJid() + ": sending read marker to " + markable.getCounterpart().toString());
        Account account = conversation.getAccount();
        final Jid to = markable.getCounterpart();
        MessagePacket packet = mMessageGenerator.confirm(account, to, markable.getRemoteMsgId());
        this.sendMessagePacket(conversation.getAccount(), packet);
    }
}
Also used : MessagePacket(eu.siacs.conversations.xmpp.stanzas.MessagePacket) Account(eu.siacs.conversations.entities.Account) XmppAxolotlMessage(eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage) Message(eu.siacs.conversations.entities.Message) Jid(eu.siacs.conversations.xmpp.jid.Jid)

Example 3 with Jid

use of eu.siacs.conversations.xmpp.jid.Jid in project Conversations by siacs.

the class HttpUploadConnection method init.

public void init(Message message, boolean delay) {
    this.message = message;
    this.account = message.getConversation().getAccount();
    this.file = mXmppConnectionService.getFileBackend().getFile(message, false);
    this.mime = this.file.getMimeType();
    this.delayed = delay;
    if (Config.ENCRYPT_ON_HTTP_UPLOADED || message.getEncryption() == Message.ENCRYPTION_AXOLOTL || message.getEncryption() == Message.ENCRYPTION_OTR) {
        this.key = new byte[48];
        mXmppConnectionService.getRNG().nextBytes(this.key);
        this.file.setKeyAndIv(this.key);
    }
    Pair<InputStream, Integer> pair;
    try {
        pair = AbstractConnectionManager.createInputStream(file, true);
    } catch (FileNotFoundException e) {
        Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not find file to upload - " + e.getMessage());
        fail(e.getMessage());
        return;
    }
    this.file.setExpectedSize(pair.second);
    this.mFileInputStream = pair.first;
    Jid host = account.getXmppConnection().findDiscoItemByFeature(Namespace.HTTP_UPLOAD);
    IqPacket request = mXmppConnectionService.getIqGenerator().requestHttpUploadSlot(host, file, mime);
    mXmppConnectionService.sendIqPacket(account, request, new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(Account account, IqPacket packet) {
            if (packet.getType() == IqPacket.TYPE.RESULT) {
                Element slot = packet.findChild("slot", Namespace.HTTP_UPLOAD);
                if (slot != null) {
                    try {
                        mGetUrl = new URL(slot.findChildContent("get"));
                        mPutUrl = new URL(slot.findChildContent("put"));
                        if (!canceled) {
                            new Thread(new FileUploader()).start();
                        }
                        return;
                    } catch (MalformedURLException e) {
                    //fall through
                    }
                }
            }
            Log.d(Config.LOGTAG, account.getJid().toString() + ": invalid response to slot request " + packet);
            fail(IqParser.extractErrorMessage(packet));
        }
    });
    message.setTransferable(this);
    mXmppConnectionService.markMessage(message, Message.STATUS_UNSEND);
}
Also used : Account(eu.siacs.conversations.entities.Account) MalformedURLException(java.net.MalformedURLException) Jid(eu.siacs.conversations.xmpp.jid.Jid) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) InputStream(java.io.InputStream) Element(eu.siacs.conversations.xml.Element) FileNotFoundException(java.io.FileNotFoundException) URL(java.net.URL) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 4 with Jid

use of eu.siacs.conversations.xmpp.jid.Jid in project Conversations by siacs.

the class JingleConnection method upgradeNamespace.

private void upgradeNamespace() {
    Jid jid = this.message.getCounterpart();
    String resource = jid != null ? jid.getResourcepart() : null;
    if (resource != null) {
        Presence presence = this.account.getRoster().getContact(jid).getPresences().getPresences().get(resource);
        ServiceDiscoveryResult result = presence != null ? presence.getServiceDiscoveryResult() : null;
        if (result != null) {
            List<String> features = result.getFeatures();
            if (features.contains(Content.Version.FT_4.getNamespace())) {
                this.ftVersion = Content.Version.FT_4;
            }
        }
    }
}
Also used : Jid(eu.siacs.conversations.xmpp.jid.Jid) ServiceDiscoveryResult(eu.siacs.conversations.entities.ServiceDiscoveryResult) Presence(eu.siacs.conversations.entities.Presence)

Example 5 with Jid

use of eu.siacs.conversations.xmpp.jid.Jid in project Conversations by siacs.

the class JingleConnectionManager method getPrimaryCandidate.

public void getPrimaryCandidate(Account account, final OnPrimaryCandidateFound listener) {
    if (Config.DISABLE_PROXY_LOOKUP) {
        listener.onPrimaryCandidateFound(false, null);
        return;
    }
    if (!this.primaryCandidates.containsKey(account.getJid().toBareJid())) {
        final Jid proxy = account.getXmppConnection().findDiscoItemByFeature(Namespace.BYTE_STREAMS);
        if (proxy != null) {
            IqPacket iq = new IqPacket(IqPacket.TYPE.GET);
            iq.setTo(proxy);
            iq.query(Namespace.BYTE_STREAMS);
            account.getXmppConnection().sendIqPacket(iq, new OnIqPacketReceived() {

                @Override
                public void onIqPacketReceived(Account account, IqPacket packet) {
                    Element streamhost = packet.query().findChild("streamhost", Namespace.BYTE_STREAMS);
                    final String host = streamhost == null ? null : streamhost.getAttribute("host");
                    final String port = streamhost == null ? null : streamhost.getAttribute("port");
                    if (host != null && port != null) {
                        try {
                            JingleCandidate candidate = new JingleCandidate(nextRandomId(), true);
                            candidate.setHost(host);
                            candidate.setPort(Integer.parseInt(port));
                            candidate.setType(JingleCandidate.TYPE_PROXY);
                            candidate.setJid(proxy);
                            candidate.setPriority(655360 + 65535);
                            primaryCandidates.put(account.getJid().toBareJid(), candidate);
                            listener.onPrimaryCandidateFound(true, candidate);
                        } catch (final NumberFormatException e) {
                            listener.onPrimaryCandidateFound(false, null);
                            return;
                        }
                    } else {
                        listener.onPrimaryCandidateFound(false, null);
                    }
                }
            });
        } else {
            listener.onPrimaryCandidateFound(false, null);
        }
    } else {
        listener.onPrimaryCandidateFound(true, this.primaryCandidates.get(account.getJid().toBareJid()));
    }
}
Also used : Account(eu.siacs.conversations.entities.Account) Jid(eu.siacs.conversations.xmpp.jid.Jid) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) Element(eu.siacs.conversations.xml.Element) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Aggregations

Jid (eu.siacs.conversations.xmpp.jid.Jid)23 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)11 Conversation (eu.siacs.conversations.entities.Conversation)6 Account (eu.siacs.conversations.entities.Account)4 Message (eu.siacs.conversations.entities.Message)4 Element (eu.siacs.conversations.xml.Element)4 Intent (android.content.Intent)3 Contact (eu.siacs.conversations.entities.Contact)3 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)3 MessagePacket (eu.siacs.conversations.xmpp.stanzas.MessagePacket)3 SuppressLint (android.annotation.SuppressLint)2 PendingIntent (android.app.PendingIntent)2 AxolotlService (eu.siacs.conversations.crypto.axolotl.AxolotlService)2 XmppAxolotlMessage (eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage)2 MucOptions (eu.siacs.conversations.entities.MucOptions)2 OnIqPacketReceived (eu.siacs.conversations.xmpp.OnIqPacketReceived)2 FileNotFoundException (java.io.FileNotFoundException)2 ArrayList (java.util.ArrayList)2 AlertDialog (android.app.AlertDialog)1 Builder (android.app.AlertDialog.Builder)1