use of de.pixart.messenger.xml.Element in project Pix-Art-Messenger by kriztan.
the class MessageGenerator method directInvite.
public MessagePacket directInvite(final Conversation conversation, final Jid contact) {
MessagePacket packet = new MessagePacket();
packet.setType(MessagePacket.TYPE_NORMAL);
packet.setTo(contact);
packet.setFrom(conversation.getAccount().getJid());
Element x = packet.addChild("x", "jabber:x:conference");
x.setAttribute("jid", conversation.getJid().toBareJid().toString());
String password = conversation.getMucOptions().getPassword();
if (password != null) {
x.setAttribute("password", password);
}
return packet;
}
use of de.pixart.messenger.xml.Element in project Pix-Art-Messenger by kriztan.
the class MessageGenerator method invite.
public MessagePacket invite(Conversation conversation, Jid contact) {
MessagePacket packet = new MessagePacket();
packet.setTo(conversation.getJid().toBareJid());
packet.setFrom(conversation.getAccount().getJid());
Element x = new Element("x");
x.setAttribute("xmlns", "http://jabber.org/protocol/muc#user");
Element invite = new Element("invite");
invite.setAttribute("to", contact.toBareJid().toString());
x.addChild(invite);
packet.addChild(x);
return packet;
}
use of de.pixart.messenger.xml.Element in project Pix-Art-Messenger by kriztan.
the class MessageGenerator method generateOtrError.
public MessagePacket generateOtrError(Jid to, String id, String errorText) {
MessagePacket packet = new MessagePacket();
packet.setType(MessagePacket.TYPE_ERROR);
packet.setAttribute("id", id);
packet.setTo(to);
Element error = packet.addChild("error");
error.setAttribute("code", "406");
error.setAttribute("type", "modify");
error.addChild("not-acceptable", "urn:ietf:params:xml:ns:xmpp-stanzas");
error.addChild("text").setContent("?OTR Error:" + errorText);
return packet;
}
use of de.pixart.messenger.xml.Element in project Pix-Art-Messenger by kriztan.
the class PresenceGenerator method selfPresence.
public PresencePacket selfPresence(Account account, Presence.Status status, boolean includePgpAnnouncement) {
PresencePacket packet = new PresencePacket();
if (status.toShowString() != null) {
packet.addChild("show").setContent(status.toShowString());
}
packet.setFrom(account.getJid());
String sig = account.getPgpSignature();
if (includePgpAnnouncement && sig != null && mXmppConnectionService.getPgpEngine() != null) {
packet.addChild("x", "jabber:x:signed").setContent(sig);
}
String capHash = getCapHash();
if (capHash != null) {
Element cap = packet.addChild("c", "http://jabber.org/protocol/caps");
cap.setAttribute("hash", "sha-1");
cap.setAttribute("node", "http://jabber.pix-art.de");
cap.setAttribute("ver", capHash);
}
return packet;
}
use of de.pixart.messenger.xml.Element in project Pix-Art-Messenger by kriztan.
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) {
if (packet.getType() == IqPacket.TYPE.TIMEOUT) {
return;
}
if (packet.getType() == IqPacket.TYPE.ERROR) {
throw new StateChangingError(Account.State.REGISTRATION_FAILED);
}
final Element query = packet.query("jabber:iq:register");
if (query.hasChild("username") && (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, true);
} else if (query.hasChild("x", Namespace.DATA)) {
final Data data = Data.parse(query.findChild("x", Namespace.DATA));
final Element blob = query.findChild("data", "urn:xmpp:bob");
final String id = packet.getId();
InputStream is;
if (blob != null) {
try {
final String base64Blob = blob.getContent();
final byte[] strBlob = Base64.decode(base64Blob, Base64.DEFAULT);
is = new ByteArrayInputStream(strBlob);
} catch (Exception e) {
is = null;
}
} else {
try {
Field field = data.getFieldByName("url");
URL url = field != null && field.getValue() != null ? new URL(field.getValue()) : null;
is = url != null ? url.openStream() : null;
} catch (IOException e) {
is = null;
}
}
if (is != null) {
Bitmap captcha = BitmapFactory.decodeStream(is);
try {
if (mXmppConnectionService.displayCaptchaRequest(account, id, data, captcha)) {
return;
}
} catch (Exception e) {
throw new StateChangingError(Account.State.REGISTRATION_FAILED);
}
}
throw new StateChangingError(Account.State.REGISTRATION_FAILED);
} else if (query.hasChild("instructions") || query.hasChild("x", Namespace.OOB)) {
final String instructions = query.findChildContent("instructions");
final Element oob = query.findChild("x", Namespace.OOB);
final String url = oob == null ? null : oob.findChildContent("url");
if (url != null) {
setAccountCreationFailed(url);
} else if (instructions != null) {
Matcher matcher = Patterns.AUTOLINK_WEB_URL.matcher(instructions);
if (matcher.find()) {
setAccountCreationFailed(instructions.substring(matcher.start(), matcher.end()));
}
}
throw new StateChangingError(Account.State.REGISTRATION_FAILED);
}
}
}, true);
}
Aggregations