Search in sources :

Example 6 with Data

use of de.pixart.messenger.xmpp.forms.Data in project Pix-Art-Messenger by kriztan.

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", Namespace.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(de.pixart.messenger.entities.Account) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) Jid(de.pixart.messenger.xmpp.jid.Jid) Element(de.pixart.messenger.xml.Element) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) Data(de.pixart.messenger.xmpp.forms.Data) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 7 with Data

use of de.pixart.messenger.xmpp.forms.Data in project Pix-Art-Messenger by kriztan.

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(de.pixart.messenger.xmpp.forms.Data) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Field(de.pixart.messenger.xmpp.forms.Field) MessageDigest(java.security.MessageDigest)

Example 8 with Data

use of de.pixart.messenger.xmpp.forms.Data in project Pix-Art-Messenger by kriztan.

the class IqGenerator method pushTokenToAppServer.

public IqPacket pushTokenToAppServer(Jid appServer, String token, String deviceId) {
    IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
    packet.setTo(appServer);
    Element command = packet.addChild("command", "http://jabber.org/protocol/commands");
    command.setAttribute("node", "register-push-gcm");
    command.setAttribute("action", "execute");
    Data data = new Data();
    data.put("token", token);
    data.put("device-id", deviceId);
    data.submit();
    command.addChild(data);
    return packet;
}
Also used : Element(de.pixart.messenger.xml.Element) Data(de.pixart.messenger.xmpp.forms.Data) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 9 with Data

use of de.pixart.messenger.xmpp.forms.Data in project Pix-Art-Messenger by kriztan.

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", Namespace.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(de.pixart.messenger.entities.Account) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) Data(de.pixart.messenger.xmpp.forms.Data) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Aggregations

Data (de.pixart.messenger.xmpp.forms.Data)9 IqPacket (de.pixart.messenger.xmpp.stanzas.IqPacket)6 Element (de.pixart.messenger.xml.Element)5 Account (de.pixart.messenger.entities.Account)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 OnIqPacketReceived (de.pixart.messenger.xmpp.OnIqPacketReceived)2 Field (de.pixart.messenger.xmpp.forms.Field)2 InvalidJidException (de.pixart.messenger.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 (de.pixart.messenger.xmpp.jid.Jid)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ConnectException (java.net.ConnectException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 UnknownHostException (java.net.UnknownHostException)1