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;
}
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);
}
}
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;
}
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);
}
}
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.
}
}
}
Aggregations