Search in sources :

Example 6 with PresencePacket

use of eu.siacs.conversations.xmpp.stanzas.PresencePacket in project Conversations by siacs.

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://conversations.im");
        cap.setAttribute("ver", capHash);
    }
    return packet;
}
Also used : Element(eu.siacs.conversations.xml.Element) PresencePacket(eu.siacs.conversations.xmpp.stanzas.PresencePacket)

Example 7 with PresencePacket

use of eu.siacs.conversations.xmpp.stanzas.PresencePacket in project Conversations by siacs.

the class PresenceGenerator method subscription.

private PresencePacket subscription(String type, Contact contact) {
    PresencePacket packet = new PresencePacket();
    packet.setAttribute("type", type);
    packet.setTo(contact.getJid());
    packet.setFrom(contact.getAccount().getJid().toBareJid());
    return packet;
}
Also used : PresencePacket(eu.siacs.conversations.xmpp.stanzas.PresencePacket)

Example 8 with PresencePacket

use of eu.siacs.conversations.xmpp.stanzas.PresencePacket in project Conversations by siacs.

the class XmppConnection method processPresence.

private void processPresence(final Tag currentTag) throws XmlPullParserException, IOException {
    PresencePacket packet = (PresencePacket) processPacket(currentTag, PACKET_PRESENCE);
    this.presenceListener.onPresencePacketReceived(account, packet);
}
Also used : PresencePacket(eu.siacs.conversations.xmpp.stanzas.PresencePacket)

Example 9 with PresencePacket

use of eu.siacs.conversations.xmpp.stanzas.PresencePacket in project Conversations by siacs.

the class XmppConnection method processPacket.

private Element processPacket(final Tag currentTag, final int packetType) throws XmlPullParserException, IOException {
    Element element;
    switch(packetType) {
        case PACKET_IQ:
            element = new IqPacket();
            break;
        case PACKET_MESSAGE:
            element = new MessagePacket();
            break;
        case PACKET_PRESENCE:
            element = new PresencePacket();
            break;
        default:
            return null;
    }
    element.setAttributes(currentTag.getAttributes());
    Tag nextTag = tagReader.readTag();
    if (nextTag == null) {
        throw new IOException("interrupted mid tag");
    }
    while (!nextTag.isEnd(element.getName())) {
        if (!nextTag.isNo()) {
            final Element child = tagReader.readElement(nextTag);
            final String type = currentTag.getAttribute("type");
            if (packetType == PACKET_IQ && "jingle".equals(child.getName()) && ("set".equalsIgnoreCase(type) || "get".equalsIgnoreCase(type))) {
                element = new JinglePacket();
                element.setAttributes(currentTag.getAttributes());
            }
            element.addChild(child);
        }
        nextTag = tagReader.readTag();
        if (nextTag == null) {
            throw new IOException("interrupted mid tag");
        }
    }
    if (stanzasReceived == Integer.MAX_VALUE) {
        resetStreamId();
        throw new IOException("time to restart the session. cant handle >2 billion pcks");
    }
    ++stanzasReceived;
    lastPacketReceived = SystemClock.elapsedRealtime();
    if (Config.BACKGROUND_STANZA_LOGGING && mXmppConnectionService.checkListeners()) {
        Log.d(Config.LOGTAG, "[background stanza] " + element);
    }
    return element;
}
Also used : MessagePacket(eu.siacs.conversations.xmpp.stanzas.MessagePacket) JinglePacket(eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket) Element(eu.siacs.conversations.xml.Element) Tag(eu.siacs.conversations.xml.Tag) IOException(java.io.IOException) PresencePacket(eu.siacs.conversations.xmpp.stanzas.PresencePacket) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Aggregations

PresencePacket (eu.siacs.conversations.xmpp.stanzas.PresencePacket)9 Element (eu.siacs.conversations.xml.Element)4 Account (eu.siacs.conversations.entities.Account)3 MucOptions (eu.siacs.conversations.entities.MucOptions)2 Jid (eu.siacs.conversations.xmpp.jid.Jid)2 Bookmark (eu.siacs.conversations.entities.Bookmark)1 Conversation (eu.siacs.conversations.entities.Conversation)1 OnRenameListener (eu.siacs.conversations.entities.MucOptions.OnRenameListener)1 Tag (eu.siacs.conversations.xml.Tag)1 JinglePacket (eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket)1 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)1 MessagePacket (eu.siacs.conversations.xmpp.stanzas.MessagePacket)1 IOException (java.io.IOException)1