Java Code Examples for org.xmpp.packet.Presence#getFrom()
The following examples show how to use
org.xmpp.packet.Presence#getFrom() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PresenceUpdateHandler.java From Openfire with Apache License 2.0 | 6 votes |
/** * Handle presence updates that affect roster subscriptions. * * @param presence The presence presence to handle * @throws PacketException if the packet is null or the packet could not be routed. */ public void process(Presence presence) throws PacketException { try { process((Packet)presence); } catch (UnauthorizedException e) { try { LocalSession session = (LocalSession) sessionManager.getSession(presence.getFrom()); presence = presence.createCopy(); if (session != null) { presence.setFrom(new JID(null, session.getServerName(), null, true)); presence.setTo(session.getAddress()); } else { JID sender = presence.getFrom(); presence.setFrom(presence.getTo()); presence.setTo(sender); } presence.setError(PacketError.Condition.not_authorized); deliverer.deliver(presence); } catch (Exception err) { Log.error(LocaleUtils.getLocalizedString("admin.error"), err); } } }
Example 2
Source File: PresenceUpdateHandler.java From Openfire with Apache License 2.0 | 5 votes |
/** * Sends an unavailable presence to the entities that sent a directed (available) presence * to other entities. * * @param update the unavailable presence sent by the user. */ private void broadcastUnavailableForDirectedPresences(Presence update) { JID from = update.getFrom(); if (from == null) { return; } if (localServer.isLocal(from)) { // Remove the registry of directed presences of this user Collection<DirectedPresence> directedPresences = null; Lock lock = CacheFactory.getLock(from.toString(), directedPresencesCache); try { lock.lock(); directedPresences = directedPresencesCache.remove(from.toString()); } finally { lock.unlock(); } if (directedPresences != null) { // Iterate over all the entities that the user sent a directed presence for (DirectedPresence directedPresence : directedPresences) { for (String receiver : directedPresence.getReceivers()) { Presence presence = update.createCopy(); presence.setTo(receiver); localServer.getPresenceRouter().route(presence); } } localDirectedPresences.remove(from.toString()); } } }
Example 3
Source File: IQPEPHandler.java From Openfire with Apache License 2.0 | 5 votes |
@Override public void availableSession(ClientSession session, Presence presence) { // Do nothing if server is not enabled if (!isEnabled()) { return; } JID newlyAvailableJID = presence.getFrom(); if (newlyAvailableJID == null) { return; } final GetNotificationsOnInitialPresence task = new GetNotificationsOnInitialPresence(newlyAvailableJID); executor.submit(task); }
Example 4
Source File: EntityCapabilitiesManager.java From Openfire with Apache License 2.0 | 4 votes |
public void process(Presence packet) { if (Presence.Type.unavailable == packet.getType()) { if (packet.getFrom() != null ) { this.capabilitiesBeingUpdated.remove( packet.getFrom() ); final String oldVer = this.entityCapabilitiesUserMap.remove( packet.getFrom() ); if ( oldVer != null ) { checkObsolete( oldVer ); } } return; } // Examine the packet and check if it has caps info, // if not -- do nothing by returning. Element capsElement = packet.getChildElement("c", "http://jabber.org/protocol/caps"); if (capsElement == null) { return; } // Examine the packet and check if it's in legacy format (pre version 1.4 // of XEP-0115). If so, do nothing by returning. // TODO: if this packet is in legacy format, we SHOULD check the 'node', // 'ver', and 'ext' combinations as specified in the archived version // 1.3 of the specification, and cache the results. See JM-1447 final String hashAttribute = capsElement.attributeValue("hash"); if (hashAttribute == null || hashAttribute.trim().length() == 0) { return; } // Examine the packet and check if it has and a 'ver' hash // if not -- do nothing by returning. final String newVerAttribute = capsElement.attributeValue("ver"); if (newVerAttribute == null || newVerAttribute.trim().length() == 0) { return; } // Check to see if the 'ver' hash is already in our cache. EntityCapabilities caps; if ((caps = entityCapabilitiesMap.get(newVerAttribute)) != null) { // The 'ver' hash is in the cache already, so let's update the // entityCapabilitiesUserMap for the user that sent the caps // packet. Log.trace( "Registering 'ver' (for recognized caps) for {}", packet.getFrom() ); registerCapabilities( packet.getFrom(), caps ); } else { // If this entity previously had another registration, that now no longer is valid. final String ver = entityCapabilitiesUserMap.remove(packet.getFrom()); if ( ver != null ) { capabilitiesBeingUpdated.put( packet.getFrom(), ver ); } // The 'ver' hash is not in the cache so send out a disco#info query // so that we may begin recognizing this 'ver' hash. IQ iq = new IQ(IQ.Type.get); iq.setTo(packet.getFrom()); String serverName = XMPPServer.getInstance().getServerInfo().getXMPPDomain(); iq.setFrom(serverName); iq.setChildElement("query", "http://jabber.org/protocol/disco#info"); String packetId = iq.getID(); caps = new EntityCapabilities(); caps.setHashAttribute(hashAttribute); caps.setVerAttribute(newVerAttribute); Log.trace( "Querying 'ver' for unrecognized caps. Querying: {}", packet.getFrom() ); verAttributes.put(packetId, caps); final IQRouter iqRouter = XMPPServer.getInstance().getIQRouter(); iqRouter.addIQResultListener(packetId, this); iqRouter.route(iq); } }
Example 5
Source File: PresenceUpdateHandler.java From Openfire with Apache License 2.0 | 4 votes |
private void process(Presence presence, ClientSession session) throws UnauthorizedException, PacketException { try { Presence.Type type = presence.getType(); // Available if (type == null) { if (session != null && session.getStatus() == Session.STATUS_CLOSED) { Log.warn("Rejected available presence: " + presence + " - " + session); return; } if (session != null) { session.setPresence(presence); } broadcastUpdate(presence.createCopy()); if (session != null && !session.isInitialized()) { initSession(session); session.setInitialized(true); } // Notify the presence manager that the user is now available. The manager may // remove the last presence status sent by the user when he went offline. presenceManager.userAvailable(presence); } else if (Presence.Type.unavailable == type) { if (session != null) { session.setPresence(presence); } broadcastUpdate(presence.createCopy()); broadcastUnavailableForDirectedPresences(presence); // Notify the presence manager that the user is now unavailable. The manager may // save the last presence status sent by the user and keep track when the user // went offline. presenceManager.userUnavailable(presence); } else { presence = presence.createCopy(); if (session != null) { presence.setFrom(new JID(null, session.getServerName(), null, true)); presence.setTo(session.getAddress()); } else { JID sender = presence.getFrom(); presence.setFrom(presence.getTo()); presence.setTo(sender); } presence.setError(PacketError.Condition.bad_request); deliverer.deliver(presence); } } catch (Exception e) { Log.error(LocaleUtils.getLocalizedString("admin.error") + ". Triggered by packet: " + presence, e); } }