use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class SessionManager method removeSession.
/**
* Removes a session.
*
* @param session the session or null when session is derived from fullJID.
* @param fullJID the address of the session.
* @param anonymous true if the authenticated user is anonymous.
* @param forceUnavailable true if an unavailable presence must be created and routed.
* @return true if the requested session was successfully removed.
*/
public boolean removeSession(ClientSession session, JID fullJID, boolean anonymous, boolean forceUnavailable) {
// is shutting down the serverName will be null.
if (serverName == null) {
return false;
}
if (session == null) {
session = getSession(fullJID);
}
// Remove route to the removed session (anonymous or not)
boolean removed = routingTable.removeClientRoute(fullJID);
if (removed) {
// Fire session event.
if (anonymous) {
SessionEventDispatcher.dispatchEvent(session, SessionEventDispatcher.EventType.anonymous_session_destroyed);
} else {
SessionEventDispatcher.dispatchEvent(session, SessionEventDispatcher.EventType.session_destroyed);
}
}
// Remove the session from the pre-Authenticated sessions list (if present)
boolean preauth_removed = localSessionManager.getPreAuthenticatedSessions().remove(fullJID.getResource()) != null;
// If the user is still available then send an unavailable presence
if (forceUnavailable || session.getPresence().isAvailable()) {
Presence offline = new Presence();
offline.setFrom(fullJID);
offline.setTo(new JID(null, serverName, null, true));
offline.setType(Presence.Type.unavailable);
router.route(offline);
}
// Stop tracking information about the session and share it with other cluster nodes
sessionInfoCache.remove(fullJID.toString());
if (removed || preauth_removed) {
// Decrement the counter of user sessions
connectionsCounter.decrementAndGet();
return true;
}
return false;
}
use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class BroadcastPlugin method processPresence.
private void processPresence(boolean canProceed, Presence presence) {
try {
if (Presence.Type.subscribe == presence.getType()) {
// Accept all presence requests if user has permissions
// Reply that the subscription request was approved or rejected
Presence reply = new Presence();
reply.setTo(presence.getFrom());
reply.setFrom(presence.getTo());
reply.setType(canProceed ? Presence.Type.subscribed : Presence.Type.unsubscribed);
componentManager.sendPacket(this, reply);
} else if (Presence.Type.unsubscribe == presence.getType()) {
// Send confirmation of unsubscription
Presence reply = new Presence();
reply.setTo(presence.getFrom());
reply.setFrom(presence.getTo());
reply.setType(Presence.Type.unsubscribed);
componentManager.sendPacket(this, reply);
if (!canProceed) {
// Send unavailable presence of the service
reply = new Presence();
reply.setTo(presence.getFrom());
reply.setFrom(presence.getTo());
reply.setType(Presence.Type.unavailable);
componentManager.sendPacket(this, reply);
}
} else if (Presence.Type.probe == presence.getType()) {
// Send that the service is available
Presence reply = new Presence();
reply.setTo(presence.getFrom());
reply.setFrom(presence.getTo());
if (!canProceed) {
// Send forbidden error since user is not allowed
reply.setError(PacketError.Condition.forbidden);
}
componentManager.sendPacket(this, reply);
}
} catch (ComponentException e) {
Log.error(e.getMessage(), e);
}
}
use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class ContentFilterTest method testFilterPresenceXML.
@Test
public void testFilterPresenceXML() throws Exception {
String presenceXML = "<presence from=\"bob@127.0.0.1/frodo\">" + "<show>away</show>" + "<status>fox</status>" + "<priority>0</priority>" + "<x xmlns=\"vcard-temp:x:update\">" + "<photo>f9a514f112c0bcb988d5aa12bc1a9a6f22de5262</photo>" + "</x>" + "<c xmlns=\"http://jabber.org/protocol/caps\" node=\"apple:ichat:caps\" ver=\"392\" ext=\"avavail maudio mvideo avcap audio\"/>" + "<x xmlns=\"http://jabber.org/protocol/tune\"/>" + "</presence>";
XPPReader packetReader = new XPPReader();
Document doc = packetReader.read(new StringReader(presenceXML));
Presence p = new Presence(doc.getRootElement());
// filter on the word "fox" and "dog"
filter.setPatterns("fox,dog,message");
filter.setMask("**");
String expectedXML = presenceXML.replaceAll("fox", filter.getMask());
// do filter
boolean matched = filter.filter(p);
assertTrue(matched);
assertEquals(expectedXML, expectedXML, p.toXML());
}
use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class AgentSession method sendStatusOfAllAgents.
/**
* Sends the presence of each available agent in the workgroup to this agent.
*
* @param workgroup the workgroup whose agents' presences will be sent to this agent.
*/
private void sendStatusOfAllAgents(Workgroup workgroup) {
for (AgentSession agentSession : workgroup.getAgentSessions()) {
if (!agentSession.getJID().equals(address)) {
Presence statusPacket = agentSession.getPresence().createCopy();
statusPacket.setFrom(agentSession.getJID());
statusPacket.setTo(address);
// Add the agent-status element
agentSession.getAgentStatus(statusPacket, workgroup);
workgroup.send(statusPacket);
}
}
}
use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class AgentSession method sendStatusToAllAgents.
/**
* Sends this agent's status to all other agents in the Workgroup.
*
* @param workgroup the workgroup whose agent will be notified
*/
private void sendStatusToAllAgents(Workgroup workgroup) {
for (AgentSession agentSession : workgroup.getAgentSessions()) {
// receive other agents' information
if (agentSession.hasRequestedAgentInfo() && !agentSession.getJID().equals(address)) {
Presence statusPacket = presence.createCopy();
statusPacket.setFrom(address);
statusPacket.setTo(agentSession.getJID());
// Add the agent-status element
getAgentStatus(statusPacket, workgroup);
workgroup.send(statusPacket);
}
}
}
Aggregations