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