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) {
}
}
});
}
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;
}
}
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;
}
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();
}
}
}
});
}
Aggregations