Search in sources :

Example 91 with Element

use of eu.siacs.conversations.xml.Element in project Conversations by siacs.

the class Avatar method parseMetadata.

public static Avatar parseMetadata(Element items) {
    Element item = items.findChild("item");
    if (item == null) {
        return null;
    }
    Element metadata = item.findChild("metadata");
    if (metadata == null) {
        return null;
    }
    String primaryId = item.getAttribute("id");
    if (primaryId == null) {
        return null;
    }
    for (Element child : metadata.getChildren()) {
        if (child.getName().equals("info") && primaryId.equals(child.getAttribute("id"))) {
            Avatar avatar = new Avatar();
            String height = child.getAttribute("height");
            String width = child.getAttribute("width");
            String size = child.getAttribute("bytes");
            try {
                if (height != null) {
                    avatar.height = Integer.parseInt(height);
                }
                if (width != null) {
                    avatar.width = Integer.parseInt(width);
                }
                if (size != null) {
                    avatar.size = Long.parseLong(size);
                }
            } catch (NumberFormatException e) {
                return null;
            }
            avatar.type = child.getAttribute("type");
            String hash = child.getAttribute("id");
            if (!isValidSHA1(hash)) {
                return null;
            }
            avatar.sha1sum = hash;
            avatar.origin = Origin.PEP;
            return avatar;
        }
    }
    return null;
}
Also used : Element(eu.siacs.conversations.xml.Element)

Example 92 with Element

use of eu.siacs.conversations.xml.Element in project Conversations by siacs.

the class MessagePacket method setBody.

public void setBody(String text) {
    this.children.remove(findChild("body"));
    Element body = new Element("body");
    body.setContent(text);
    this.children.add(0, body);
}
Also used : Element(eu.siacs.conversations.xml.Element)

Example 93 with Element

use of eu.siacs.conversations.xml.Element in project Conversations by siacs.

the class JingleConnectionManager method deliverIbbPacket.

public void deliverIbbPacket(Account account, IqPacket packet) {
    String sid = null;
    Element payload = null;
    if (packet.hasChild("open", "http://jabber.org/protocol/ibb")) {
        payload = packet.findChild("open", "http://jabber.org/protocol/ibb");
        sid = payload.getAttribute("sid");
    } else if (packet.hasChild("data", "http://jabber.org/protocol/ibb")) {
        payload = packet.findChild("data", "http://jabber.org/protocol/ibb");
        sid = payload.getAttribute("sid");
    } else if (packet.hasChild("close", "http://jabber.org/protocol/ibb")) {
        payload = packet.findChild("close", "http://jabber.org/protocol/ibb");
        sid = payload.getAttribute("sid");
    }
    if (sid != null) {
        for (JingleConnection connection : connections) {
            if (connection.getAccount() == account && connection.hasTransportId(sid)) {
                JingleTransport transport = connection.getTransport();
                if (transport instanceof JingleInbandTransport) {
                    JingleInbandTransport inbandTransport = (JingleInbandTransport) transport;
                    inbandTransport.deliverPayload(packet, payload);
                    return;
                }
            }
        }
        Log.d(Config.LOGTAG, "couldn't deliver payload: " + payload.toString());
    } else {
        Log.d(Config.LOGTAG, "no sid found in incoming ibb packet");
    }
}
Also used : Element(eu.siacs.conversations.xml.Element)

Aggregations

Element (eu.siacs.conversations.xml.Element)93 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)43 Account (eu.siacs.conversations.entities.Account)21 Jid (eu.siacs.conversations.xmpp.jid.Jid)17 OnIqPacketReceived (eu.siacs.conversations.xmpp.OnIqPacketReceived)16 MessagePacket (eu.siacs.conversations.xmpp.stanzas.MessagePacket)8 Contact (eu.siacs.conversations.entities.Contact)7 Conversation (eu.siacs.conversations.entities.Conversation)6 ArrayList (java.util.ArrayList)6 Data (eu.siacs.conversations.xmpp.forms.Data)5 Avatar (eu.siacs.conversations.xmpp.pep.Avatar)5 IOException (java.io.IOException)5 MucOptions (eu.siacs.conversations.entities.MucOptions)4 PresencePacket (eu.siacs.conversations.xmpp.stanzas.PresencePacket)4 Pair (android.util.Pair)3 Bookmark (eu.siacs.conversations.entities.Bookmark)3 Message (eu.siacs.conversations.entities.Message)3 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3