Search in sources :

Example 11 with Jid

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

the class MagicCreateActivity method onCreate.

@Override
protected void onCreate(final Bundle savedInstanceState) {
    if (getResources().getBoolean(R.bool.portrait_only)) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }
    super.onCreate(savedInstanceState);
    setContentView(R.layout.magic_create);
    mFullJidDisplay = (TextView) findViewById(R.id.full_jid);
    mUsername = (EditText) findViewById(R.id.username);
    mRandom = new SecureRandom();
    Button next = (Button) findViewById(R.id.create_account);
    next.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            String username = mUsername.getText().toString();
            if (username.contains("@") || username.length() < 3) {
                mUsername.setError(getString(R.string.invalid_username));
                mUsername.requestFocus();
            } else {
                mUsername.setError(null);
                try {
                    Jid jid = Jid.fromParts(username.toLowerCase(), Config.MAGIC_CREATE_DOMAIN, null);
                    Account account = xmppConnectionService.findAccountByJid(jid);
                    if (account == null) {
                        account = new Account(jid, createPassword());
                        account.setOption(Account.OPTION_REGISTER, true);
                        account.setOption(Account.OPTION_DISABLED, true);
                        account.setOption(Account.OPTION_MAGIC_CREATE, true);
                        xmppConnectionService.createAccount(account);
                    }
                    Intent intent = new Intent(MagicCreateActivity.this, EditAccountActivity.class);
                    intent.putExtra("jid", account.getJid().toBareJid().toString());
                    intent.putExtra("init", true);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                    Toast.makeText(MagicCreateActivity.this, R.string.secure_password_generated, Toast.LENGTH_SHORT).show();
                    startActivity(intent);
                } catch (InvalidJidException e) {
                    mUsername.setError(getString(R.string.invalid_username));
                    mUsername.requestFocus();
                }
            }
        }
    });
    mUsername.addTextChangedListener(this);
}
Also used : Account(eu.siacs.conversations.entities.Account) Jid(eu.siacs.conversations.xmpp.jid.Jid) Button(android.widget.Button) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) SecureRandom(java.security.SecureRandom) Intent(android.content.Intent) TextView(android.widget.TextView) View(android.view.View)

Example 12 with Jid

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

the class IqParser method rosterItems.

private void rosterItems(final Account account, final Element query) {
    final String version = query.getAttribute("ver");
    if (version != null) {
        account.getRoster().setVersion(version);
    }
    for (final Element item : query.getChildren()) {
        if (item.getName().equals("item")) {
            final Jid jid = item.getAttributeAsJid("jid");
            if (jid == null) {
                continue;
            }
            final String name = item.getAttribute("name");
            final String subscription = item.getAttribute("subscription");
            final Contact contact = account.getRoster().getContact(jid);
            boolean bothPre = contact.getOption(Contact.Options.TO) && contact.getOption(Contact.Options.FROM);
            if (!contact.getOption(Contact.Options.DIRTY_PUSH)) {
                contact.setServerName(name);
                contact.parseGroupsFromElement(item);
            }
            if (subscription != null) {
                if (subscription.equals("remove")) {
                    contact.resetOption(Contact.Options.IN_ROSTER);
                    contact.resetOption(Contact.Options.DIRTY_DELETE);
                    contact.resetOption(Contact.Options.PREEMPTIVE_GRANT);
                } else {
                    contact.setOption(Contact.Options.IN_ROSTER);
                    contact.resetOption(Contact.Options.DIRTY_PUSH);
                    contact.parseSubscriptionFromElement(item);
                }
            }
            boolean both = contact.getOption(Contact.Options.TO) && contact.getOption(Contact.Options.FROM);
            if ((both != bothPre) && both) {
                Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": gained mutual presence subscription with " + contact.getJid());
                AxolotlService axolotlService = account.getAxolotlService();
                if (axolotlService != null) {
                    axolotlService.clearErrorsInFetchStatusMap(contact.getJid());
                }
            }
            mXmppConnectionService.getAvatarService().clear(contact);
        }
    }
    mXmppConnectionService.updateConversationUi();
    mXmppConnectionService.updateRosterUi();
}
Also used : AxolotlService(eu.siacs.conversations.crypto.axolotl.AxolotlService) Jid(eu.siacs.conversations.xmpp.jid.Jid) Element(eu.siacs.conversations.xml.Element) Contact(eu.siacs.conversations.entities.Contact)

Example 13 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 14 with Jid

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

the class MessageParser method extractStanzaId.

private static String extractStanzaId(Element packet, boolean isTypeGroupChat, Conversation conversation) {
    final Jid by;
    final boolean safeToExtract;
    if (isTypeGroupChat) {
        by = conversation.getJid().toBareJid();
        safeToExtract = conversation.getMucOptions().hasFeature(Namespace.STANZA_IDS);
    } else {
        Account account = conversation.getAccount();
        by = account.getJid().toBareJid();
        safeToExtract = account.getXmppConnection().getFeatures().stanzaIds();
    }
    return safeToExtract ? extractStanzaId(packet, by) : null;
}
Also used : Account(eu.siacs.conversations.entities.Account) Jid(eu.siacs.conversations.xmpp.jid.Jid)

Example 15 with Jid

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

the class TrustKeysActivity method commitTrusts.

private void commitTrusts() {
    for (final String fingerprint : ownKeysToTrust.keySet()) {
        mAccount.getAxolotlService().setFingerprintTrust(fingerprint, FingerprintStatus.createActive(ownKeysToTrust.get(fingerprint)));
    }
    List<Jid> acceptedTargets = mConversation == null ? new ArrayList<Jid>() : mConversation.getAcceptedCryptoTargets();
    synchronized (this.foreignKeysToTrust) {
        for (Map.Entry<Jid, Map<String, Boolean>> entry : foreignKeysToTrust.entrySet()) {
            Jid jid = entry.getKey();
            Map<String, Boolean> value = entry.getValue();
            if (!acceptedTargets.contains(jid)) {
                acceptedTargets.add(jid);
            }
            for (final String fingerprint : value.keySet()) {
                mAccount.getAxolotlService().setFingerprintTrust(fingerprint, FingerprintStatus.createActive(value.get(fingerprint)));
            }
        }
    }
    if (mConversation != null && mConversation.getMode() == Conversation.MODE_MULTI) {
        mConversation.setAcceptedCryptoTargets(acceptedTargets);
        xmppConnectionService.updateConversation(mConversation);
    }
}
Also used : Jid(eu.siacs.conversations.xmpp.jid.Jid) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Jid (eu.siacs.conversations.xmpp.jid.Jid)59 Account (eu.siacs.conversations.entities.Account)22 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)19 Element (eu.siacs.conversations.xml.Element)17 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)14 Conversation (eu.siacs.conversations.entities.Conversation)13 Contact (eu.siacs.conversations.entities.Contact)9 MucOptions (eu.siacs.conversations.entities.MucOptions)9 OnIqPacketReceived (eu.siacs.conversations.xmpp.OnIqPacketReceived)9 Message (eu.siacs.conversations.entities.Message)7 ArrayList (java.util.ArrayList)6 Intent (android.content.Intent)5 SuppressLint (android.annotation.SuppressLint)4 AlertDialog (android.app.AlertDialog)4 TextView (android.widget.TextView)4 AxolotlService (eu.siacs.conversations.crypto.axolotl.AxolotlService)4 Bookmark (eu.siacs.conversations.entities.Bookmark)4 MessagePacket (eu.siacs.conversations.xmpp.stanzas.MessagePacket)4 HashMap (java.util.HashMap)4 PendingIntent (android.app.PendingIntent)3