Search in sources :

Example 1 with PacketExtension

use of org.jivesoftware.smack.packet.PacketExtension in project ecf by eclipse.

the class PubSubProvider method parseIQ.

public IQ parseIQ(XmlPullParser parser) throws Exception {
    PubSub pubsub = new PubSub();
    String namespace = parser.getNamespace();
    pubsub.setPubSubNamespace(PubSubNamespace.valueOfFromXmlns(namespace));
    boolean done = false;
    while (!done) {
        int eventType = parser.next();
        if (eventType == XmlPullParser.START_TAG) {
            PacketExtension ext = PacketParserUtils.parsePacketExtension(parser.getName(), namespace, parser);
            if (ext != null) {
                pubsub.addExtension(ext);
            }
        } else if (eventType == XmlPullParser.END_TAG) {
            if (parser.getName().equals("pubsub")) {
                done = true;
            }
        }
    }
    return pubsub;
}
Also used : PacketExtension(org.jivesoftware.smack.packet.PacketExtension) PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub)

Example 2 with PacketExtension

use of org.jivesoftware.smack.packet.PacketExtension in project ecf by eclipse.

the class EntityCapsManager method updateLocalEntityCaps.

/**
 * Updates the local user Entity Caps information with the data provided
 *
 * If we are connected and there was already a presence send, another
 * presence is send to inform others about your new Entity Caps node string.
 *
 * @param discoverInfo
 *            the local users discover info (mostly the service discovery
 *            features)
 * @param identityType
 *            the local users identity type
 * @param identityName
 *            the local users identity name
 * @param extendedInfo
 *            the local users extended info
 */
public void updateLocalEntityCaps() {
    Connection connection = weakRefConnection.get();
    DiscoverInfo discoverInfo = new DiscoverInfo();
    discoverInfo.setType(IQ.Type.RESULT);
    discoverInfo.setNode(getLocalNodeVer());
    if (connection != null)
        discoverInfo.setFrom(connection.getUser());
    sdm.addDiscoverInfoTo(discoverInfo);
    currentCapsVersion = generateVerificationString(discoverInfo, "sha-1");
    addDiscoverInfoByNode(ENTITY_NODE + '#' + currentCapsVersion, discoverInfo);
    if (lastLocalCapsVersions.size() > 10) {
        String oldCapsVersion = lastLocalCapsVersions.poll();
        sdm.removeNodeInformationProvider(ENTITY_NODE + '#' + oldCapsVersion);
    }
    lastLocalCapsVersions.add(currentCapsVersion);
    caps.put(currentCapsVersion, discoverInfo);
    if (connection != null)
        jidCaps.put(connection.getUser(), new NodeVerHash(ENTITY_NODE, currentCapsVersion, "sha-1"));
    sdm.setNodeInformationProvider(ENTITY_NODE + '#' + currentCapsVersion, new NodeInformationProvider() {

        List<String> features = sdm.getFeaturesList();

        List<Identity> identities = new LinkedList<Identity>(ServiceDiscoveryManager.getIdentities());

        List<PacketExtension> packetExtensions = sdm.getExtendedInfoAsList();

        public List<Item> getNodeItems() {
            return null;
        }

        public List<String> getNodeFeatures() {
            return features;
        }

        public List<Identity> getNodeIdentities() {
            return identities;
        }

        public List<PacketExtension> getNodePacketExtensions() {
            return packetExtensions;
        }
    });
    // to respect ConnectionConfiguration.isSendPresence()
    if (connection != null && connection.isAuthenticated() && presenceSend) {
        Presence presence = new Presence(Presence.Type.available);
        connection.sendPacket(presence);
    }
}
Also used : PacketExtension(org.jivesoftware.smack.packet.PacketExtension) DiscoverInfo(org.jivesoftware.smackx.packet.DiscoverInfo) NodeInformationProvider(org.jivesoftware.smackx.NodeInformationProvider) Connection(org.jivesoftware.smack.Connection) XMPPConnection(org.jivesoftware.smack.XMPPConnection) LinkedList(java.util.LinkedList) Presence(org.jivesoftware.smack.packet.Presence) LinkedList(java.util.LinkedList) List(java.util.List) Identity(org.jivesoftware.smackx.packet.DiscoverInfo.Identity)

Example 3 with PacketExtension

use of org.jivesoftware.smack.packet.PacketExtension in project camel by apache.

the class XmppBinding method extractHeadersFromXmpp.

public Map<String, Object> extractHeadersFromXmpp(Packet xmppPacket, Exchange exchange) {
    Map<String, Object> answer = new HashMap<String, Object>();
    PacketExtension jpe = xmppPacket.getExtension(JivePropertiesExtension.NAMESPACE);
    if (jpe != null && jpe instanceof JivePropertiesExtension) {
        extractHeadersFrom((JivePropertiesExtension) jpe, exchange, answer);
    }
    if (jpe != null && jpe instanceof DefaultPacketExtension) {
        extractHeadersFrom((DefaultPacketExtension) jpe, exchange, answer);
    }
    if (xmppPacket instanceof Message) {
        Message xmppMessage = (Message) xmppPacket;
        answer.put(XmppConstants.MESSAGE_TYPE, xmppMessage.getType());
        answer.put(XmppConstants.SUBJECT, xmppMessage.getSubject());
        answer.put(XmppConstants.THREAD_ID, xmppMessage.getThread());
    } else if (xmppPacket instanceof PubSub) {
        PubSub pubsubPacket = (PubSub) xmppPacket;
        answer.put(XmppConstants.MESSAGE_TYPE, pubsubPacket.getType());
    }
    answer.put(XmppConstants.FROM, xmppPacket.getFrom());
    answer.put(XmppConstants.PACKET_ID, xmppPacket.getPacketID());
    answer.put(XmppConstants.TO, xmppPacket.getTo());
    return answer;
}
Also used : PacketExtension(org.jivesoftware.smack.packet.PacketExtension) DefaultPacketExtension(org.jivesoftware.smack.packet.DefaultPacketExtension) PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub) Message(org.jivesoftware.smack.packet.Message) HashMap(java.util.HashMap) DefaultPacketExtension(org.jivesoftware.smack.packet.DefaultPacketExtension) JivePropertiesExtension(org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension)

Example 4 with PacketExtension

use of org.jivesoftware.smack.packet.PacketExtension in project Openfire by igniterealtime.

the class XMPPListener method processMessage.

/**
     * Handles incoming messages.
     *
     * @param chat Chat instance this message is associated with.
     * @param message Message received.
     */
public void processMessage(Chat chat, org.jivesoftware.smack.packet.Message message) {
    Log.debug("Received " + getSession().getTransport().getType().name() + " message: " + message.toXML());
    try {
        final BaseTransport<XMPPBuddy> transport = getSession().getTransport();
        final JID legacyJID = transport.convertIDToJID(message.getFrom());
        final JID localJID = getSession().getJID();
        final PacketExtension pe = message.getExtension("x", NameSpace.X_DELAY);
        final PacketExtension attExt = message.getExtension(AttentionExtension.ELEMENT_NAME, AttentionExtension.NAMESPACE);
        if (pe != null && pe instanceof DelayInformation) {
            DelayInformation di = (DelayInformation) pe;
            transport.sendOfflineMessage(localJID, legacyJID, message.getBody(), di.getStamp(), di.getReason());
        } else if (attExt != null && (attExt instanceof AttentionExtension)) {
            transport.sendAttentionNotification(localJID, legacyJID, message.getBody());
        } else {
            // see if we got sent chat state notifications
            final PacketExtension cse = message.getExtension("http://jabber.org/protocol/chatstates");
            if (cse != null && cse instanceof ChatStateExtension) {
                final String chatState = cse.getElementName();
                try {
                    final ChatStateType cst = ChatStateType.valueOf(ChatStateType.class, chatState);
                    switch(cst) {
                        case active:
                            // included with that chat message below.
                            if (message.getBody() == null || message.getBody().trim().length() == 0) {
                                transport.sendChatActiveNotification(localJID, legacyJID);
                            }
                            break;
                        case composing:
                            transport.sendComposingNotification(localJID, legacyJID);
                            break;
                        case gone:
                            transport.sendChatGoneNotification(localJID, legacyJID);
                            break;
                        case inactive:
                            transport.sendChatInactiveNotification(localJID, legacyJID);
                            break;
                        case paused:
                            transport.sendComposingPausedNotification(localJID, legacyJID);
                            break;
                        default:
                            Log.debug("Unexpected chat state recieved: " + cst);
                            break;
                    }
                } catch (IllegalArgumentException ex) {
                    Log.warn("Illegal chat state notification " + "received from legacy domain: " + chatState);
                }
            }
            if (message.getType() == Type.error) {
                Log.debug("Received an error message! Message: " + message.toXML());
                transport.sendMessage(localJID, legacyJID, message.getBody(), Message.Type.error);
            } else {
                transport.sendMessage(localJID, legacyJID, message.getBody());
            }
        }
    //            if (message.getProperty("time") == null || message.getProperty("time").equals("")) {
    //            }
    //            else {
    //                getSession().getTransport().sendOfflineMessage(
    //                        getSession().getJID(),
    //                        getSession().getTransport().convertIDToJID(message.getFrom()),
    //                        message.getBody(),
    //                        Message.Type.chat,
    //                        message.getProperty("time").toString()
    //                );
    //            }
    } catch (Exception ex) {
        Log.debug("E001:" + ex.getMessage(), ex);
    }
}
Also used : PacketExtension(org.jivesoftware.smack.packet.PacketExtension) IQWithPacketExtension(net.sf.kraken.protocols.xmpp.packet.IQWithPacketExtension) ChatStateType(net.sf.kraken.type.ChatStateType) JID(org.xmpp.packet.JID) DelayInformation(org.jivesoftware.smackx.packet.DelayInformation) ChatStateExtension(org.jivesoftware.smackx.packet.ChatStateExtension) AttentionExtension(net.sf.kraken.protocols.xmpp.packet.AttentionExtension)

Example 5 with PacketExtension

use of org.jivesoftware.smack.packet.PacketExtension in project Openfire by igniterealtime.

the class XMPPPresenceHandler method handlePresenceMode.

/**
	 * Handles incoming presence stanzas that relate to presence status / mode
	 * changes. Ignores others.
	 * 
	 * @param presence
	 *            the stanza
	 */
private void handlePresenceMode(final org.jivesoftware.smack.packet.Presence presence) {
    if (!session.getBuddyManager().isActivated()) {
        session.getBuddyManager().storePendingStatus(session.getTransport().convertIDToJID(presence.getFrom()), ((XMPPTransport) session.getTransport()).convertXMPPStatusToGateway(presence.getType(), presence.getMode()), presence.getStatus());
    } else {
        // TODO: Need to handle resources and priorities!
        try {
            final XMPPBuddy xmppBuddy = session.getBuddyManager().getBuddy(session.getTransport().convertIDToJID(presence.getFrom()));
            Log.debug("XMPP: Presence changed detected type " + presence.getType() + " and mode " + presence.getMode() + " for " + presence.getFrom());
            xmppBuddy.setPresenceAndStatus(((XMPPTransport) session.getTransport()).convertXMPPStatusToGateway(presence.getType(), presence.getMode()), presence.getStatus());
            if (JiveGlobals.getBooleanProperty("plugin.gateway." + session.getTransport().getType() + ".avatars", true)) {
                PacketExtension pe = presence.getExtension("x", NameSpace.VCARD_TEMP_X_UPDATE);
                if (pe != null) {
                    DefaultPacketExtension dpe = (DefaultPacketExtension) pe;
                    String hash = dpe.getValue("photo");
                    final String from = presence.getFrom();
                    if (hash != null) {
                        Avatar curAvatar = xmppBuddy.getAvatar();
                        if (curAvatar == null || !curAvatar.getLegacyIdentifier().equals(hash)) {
                            new Thread() {

                                @Override
                                public void run() {
                                    VCard vcard = new VCard();
                                    try {
                                        vcard.load(session.conn, from);
                                        xmppBuddy.setAvatar(new Avatar(xmppBuddy.getJID(), from, vcard.getAvatar()));
                                    } catch (XMPPException e) {
                                        Log.debug("XMPP: Failed to load XMPP avatar: ", e);
                                    } catch (IllegalArgumentException e) {
                                        Log.debug("XMPP: Got null avatar, ignoring.");
                                    }
                                }
                            }.start();
                        }
                    }
                }
            }
        } catch (NotFoundException e) {
            Log.debug("XMPP: Received presence notification for contact that's not in the buddy manager of user " + session.getJID() + ". GTalk is known to do this occasionally: " + presence.getFrom());
        // We cannot add this buddy to the buddy manager, as that would result into an auto-accept of the contact sending the data.
        }
    }
}
Also used : PacketExtension(org.jivesoftware.smack.packet.PacketExtension) DefaultPacketExtension(org.jivesoftware.smack.packet.DefaultPacketExtension) DefaultPacketExtension(org.jivesoftware.smack.packet.DefaultPacketExtension) NotFoundException(org.jivesoftware.util.NotFoundException) XMPPException(org.jivesoftware.smack.XMPPException) VCard(org.jivesoftware.smackx.packet.VCard) Avatar(net.sf.kraken.avatars.Avatar)

Aggregations

PacketExtension (org.jivesoftware.smack.packet.PacketExtension)7 DefaultPacketExtension (org.jivesoftware.smack.packet.DefaultPacketExtension)2 Message (org.jivesoftware.smack.packet.Message)2 PubSub (org.jivesoftware.smackx.pubsub.packet.PubSub)2 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Avatar (net.sf.kraken.avatars.Avatar)1 AttentionExtension (net.sf.kraken.protocols.xmpp.packet.AttentionExtension)1 IQWithPacketExtension (net.sf.kraken.protocols.xmpp.packet.IQWithPacketExtension)1 ChatStateType (net.sf.kraken.type.ChatStateType)1 Connection (org.jivesoftware.smack.Connection)1 XMPPConnection (org.jivesoftware.smack.XMPPConnection)1 XMPPException (org.jivesoftware.smack.XMPPException)1 Presence (org.jivesoftware.smack.packet.Presence)1 NodeInformationProvider (org.jivesoftware.smackx.NodeInformationProvider)1 JivePropertiesExtension (org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension)1 ChatStateExtension (org.jivesoftware.smackx.packet.ChatStateExtension)1 DelayInformation (org.jivesoftware.smackx.packet.DelayInformation)1 DiscoverInfo (org.jivesoftware.smackx.packet.DiscoverInfo)1