Search in sources :

Example 1 with Data

use of eu.siacs.conversations.xmpp.forms.Data in project Conversations by siacs.

the class IqGenerator method queryMessageArchiveManagement.

public IqPacket queryMessageArchiveManagement(final MessageArchiveService.Query mam) {
    final IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
    final Element query = packet.query(mam.isLegacy() ? Namespace.MAM_LEGACY : Namespace.MAM);
    query.setAttribute("queryid", mam.getQueryId());
    final Data data = new Data();
    data.setFormType(mam.isLegacy() ? Namespace.MAM_LEGACY : Namespace.MAM);
    if (mam.muc()) {
        packet.setTo(mam.getWith());
    } else if (mam.getWith() != null) {
        data.put("with", mam.getWith().toString());
    }
    data.put("start", getTimestamp(mam.getStart()));
    data.put("end", getTimestamp(mam.getEnd()));
    data.submit();
    query.addChild(data);
    if (mam.getPagingOrder() == MessageArchiveService.PagingOrder.REVERSE) {
        query.addChild("set", "http://jabber.org/protocol/rsm").addChild("before").setContent(mam.getReference());
    } else if (mam.getReference() != null) {
        query.addChild("set", "http://jabber.org/protocol/rsm").addChild("after").setContent(mam.getReference());
    }
    return packet;
}
Also used : Element(eu.siacs.conversations.xml.Element) Data(eu.siacs.conversations.xmpp.forms.Data) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 2 with Data

use of eu.siacs.conversations.xmpp.forms.Data in project Conversations by siacs.

the class XmppConnection method sendRegistryRequest.

private void sendRegistryRequest() {
    final IqPacket register = new IqPacket(IqPacket.TYPE.GET);
    register.query("jabber:iq:register");
    register.setTo(account.getServer());
    sendUnmodifiedIqPacket(register, new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(final Account account, final IqPacket packet) {
            boolean failed = false;
            if (packet.getType() == IqPacket.TYPE.RESULT && packet.query().hasChild("username") && (packet.query().hasChild("password"))) {
                final IqPacket register = new IqPacket(IqPacket.TYPE.SET);
                final Element username = new Element("username").setContent(account.getUsername());
                final Element password = new Element("password").setContent(account.getPassword());
                register.query("jabber:iq:register").addChild(username);
                register.query().addChild(password);
                register.setFrom(account.getJid().toBareJid());
                sendUnmodifiedIqPacket(register, registrationResponseListener);
            } else if (packet.getType() == IqPacket.TYPE.RESULT && (packet.query().hasChild("x", "jabber:x:data"))) {
                final Data data = Data.parse(packet.query().findChild("x", "jabber:x:data"));
                final Element blob = packet.query().findChild("data", "urn:xmpp:bob");
                final String id = packet.getId();
                Bitmap captcha = null;
                if (blob != null) {
                    try {
                        final String base64Blob = blob.getContent();
                        final byte[] strBlob = Base64.decode(base64Blob, Base64.DEFAULT);
                        InputStream stream = new ByteArrayInputStream(strBlob);
                        captcha = BitmapFactory.decodeStream(stream);
                    } catch (Exception e) {
                    //ignored
                    }
                } else {
                    try {
                        Field url = data.getFieldByName("url");
                        String urlString = url.findChildContent("value");
                        URL uri = new URL(urlString);
                        captcha = BitmapFactory.decodeStream(uri.openConnection().getInputStream());
                    } catch (IOException e) {
                        Log.e(Config.LOGTAG, e.toString());
                    }
                }
                if (captcha != null) {
                    failed = !mXmppConnectionService.displayCaptchaRequest(account, id, data, captcha);
                }
            } else {
                failed = true;
            }
            if (failed) {
                final Element instructions = packet.query().findChild("instructions");
                setAccountCreationFailed((instructions != null) ? instructions.getContent() : "");
            }
        }
    });
}
Also used : Account(eu.siacs.conversations.entities.Account) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Element(eu.siacs.conversations.xml.Element) Data(eu.siacs.conversations.xmpp.forms.Data) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) URL(java.net.URL) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket) Field(eu.siacs.conversations.xmpp.forms.Field) Bitmap(android.graphics.Bitmap) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 3 with Data

use of eu.siacs.conversations.xmpp.forms.Data in project Conversations by siacs.

the class PushManagementService method registerPushTokenOnServer.

public void registerPushTokenOnServer(final Account account) {
    Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": has push support");
    retrieveGcmInstanceToken(new OnGcmInstanceTokenRetrieved() {

        @Override
        public void onGcmInstanceTokenRetrieved(String token) {
            try {
                final String deviceId = Settings.Secure.getString(mXmppConnectionService.getContentResolver(), Settings.Secure.ANDROID_ID);
                IqPacket packet = mXmppConnectionService.getIqGenerator().pushTokenToAppServer(Jid.fromString(APP_SERVER), token, deviceId);
                mXmppConnectionService.sendIqPacket(account, packet, new OnIqPacketReceived() {

                    @Override
                    public void onIqPacketReceived(Account account, IqPacket packet) {
                        Element command = packet.findChild("command", "http://jabber.org/protocol/commands");
                        if (packet.getType() == IqPacket.TYPE.RESULT && command != null) {
                            Element x = command.findChild("x", "jabber:x:data");
                            if (x != null) {
                                Data data = Data.parse(x);
                                try {
                                    String node = data.getValue("node");
                                    String secret = data.getValue("secret");
                                    Jid jid = Jid.fromString(data.getValue("jid"));
                                    if (node != null && secret != null) {
                                        enablePushOnServer(account, jid, node, secret);
                                    }
                                } catch (InvalidJidException e) {
                                    e.printStackTrace();
                                }
                            }
                        } else {
                            Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": invalid response from app server");
                        }
                    }
                });
            } catch (InvalidJidException ignored) {
            }
        }
    });
}
Also used : Account(eu.siacs.conversations.entities.Account) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) Jid(eu.siacs.conversations.xmpp.jid.Jid) Element(eu.siacs.conversations.xml.Element) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) Data(eu.siacs.conversations.xmpp.forms.Data) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 4 with Data

use of eu.siacs.conversations.xmpp.forms.Data in project Conversations by siacs.

the class XmppConnectionService method pushConferenceConfiguration.

public void pushConferenceConfiguration(final Conversation conversation, final Bundle options, final OnConfigurationPushed callback) {
    IqPacket request = new IqPacket(IqPacket.TYPE.GET);
    request.setTo(conversation.getJid().toBareJid());
    request.query("http://jabber.org/protocol/muc#owner");
    sendIqPacket(conversation.getAccount(), request, new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(Account account, IqPacket packet) {
            if (packet.getType() == IqPacket.TYPE.RESULT) {
                Data data = Data.parse(packet.query().findChild("x", "jabber:x:data"));
                data.submit(options);
                IqPacket set = new IqPacket(IqPacket.TYPE.SET);
                set.setTo(conversation.getJid().toBareJid());
                set.query("http://jabber.org/protocol/muc#owner").addChild(data);
                sendIqPacket(account, set, new OnIqPacketReceived() {

                    @Override
                    public void onIqPacketReceived(Account account, IqPacket packet) {
                        if (callback != null) {
                            if (packet.getType() == IqPacket.TYPE.RESULT) {
                                callback.onPushSucceeded();
                            } else {
                                callback.onPushFailed();
                            }
                        }
                    }
                });
            } else {
                if (callback != null) {
                    callback.onPushFailed();
                }
            }
        }
    });
}
Also used : Account(eu.siacs.conversations.entities.Account) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) Data(eu.siacs.conversations.xmpp.forms.Data) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 5 with Data

use of eu.siacs.conversations.xmpp.forms.Data in project Conversations by siacs.

the class ServiceDiscoveryResult method mkCapHash.

protected byte[] mkCapHash() {
    StringBuilder s = new StringBuilder();
    List<Identity> identities = this.getIdentities();
    Collections.sort(identities);
    for (Identity id : identities) {
        s.append(blankNull(id.getCategory()) + "/" + blankNull(id.getType()) + "/" + blankNull(id.getLang()) + "/" + blankNull(id.getName()) + "<");
    }
    List<String> features = this.getFeatures();
    Collections.sort(features);
    for (String feature : features) {
        s.append(feature + "<");
    }
    Collections.sort(forms, new Comparator<Data>() {

        @Override
        public int compare(Data lhs, Data rhs) {
            return lhs.getFormType().compareTo(rhs.getFormType());
        }
    });
    for (Data form : forms) {
        s.append(form.getFormType() + "<");
        List<Field> fields = form.getFields();
        Collections.sort(fields, new Comparator<Field>() {

            @Override
            public int compare(Field lhs, Field rhs) {
                return lhs.getFieldName().compareTo(rhs.getFieldName());
            }
        });
        for (Field field : fields) {
            s.append(field.getFieldName() + "<");
            List<String> values = field.getValues();
            Collections.sort(values);
            for (String value : values) {
                s.append(value + "<");
            }
        }
    }
    MessageDigest md;
    try {
        md = MessageDigest.getInstance("SHA-1");
    } catch (NoSuchAlgorithmException e) {
        return null;
    }
    try {
        return md.digest(s.toString().getBytes("UTF-8"));
    } catch (UnsupportedEncodingException e) {
        return null;
    }
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) Data(eu.siacs.conversations.xmpp.forms.Data) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Field(eu.siacs.conversations.xmpp.forms.Field) MessageDigest(java.security.MessageDigest)

Aggregations

Data (eu.siacs.conversations.xmpp.forms.Data)9 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)6 Element (eu.siacs.conversations.xml.Element)5 Account (eu.siacs.conversations.entities.Account)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 OnIqPacketReceived (eu.siacs.conversations.xmpp.OnIqPacketReceived)2 Field (eu.siacs.conversations.xmpp.forms.Field)2 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 JSONArray (org.json.JSONArray)2 JSONException (org.json.JSONException)2 Bitmap (android.graphics.Bitmap)1 Jid (eu.siacs.conversations.xmpp.jid.Jid)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ConnectException (java.net.ConnectException)1 URL (java.net.URL)1 UnknownHostException (java.net.UnknownHostException)1 KeyManagementException (java.security.KeyManagementException)1