use of org.jivesoftware.openfire.session.ClientSession in project Openfire by igniterealtime.
the class IQPrivacyHandler method declineActiveList.
/**
* User has requested that no active list should be used for the current session. Return
* acknowledge of success.
*
* @param packet IQ packet declining active list for the current session.
* @param from sender of the IQ packet.
* @return acknowledge of success.
*/
private IQ declineActiveList(IQ packet, JID from) {
// Get the user session
ClientSession session = sessionManager.getSession(from);
// Set that there is no active list for this session
session.setActiveList(null);
// Return acknowledge of success
return IQ.createResultIQ(packet);
}
use of org.jivesoftware.openfire.session.ClientSession in project Openfire by igniterealtime.
the class IQPrivacyHandler method deleteList.
private IQ deleteList(IQ packet, JID from, String listName) {
ClientSession currentSession;
IQ result = IQ.createResultIQ(packet);
Element childElement = packet.getChildElement().createCopy();
result.setChildElement(childElement);
// Get the list to delete
PrivacyList list = manager.getPrivacyList(from.getNode(), listName);
if (list == null) {
// List to delete was not found
result.setError(PacketError.Condition.item_not_found);
return result;
} else {
currentSession = sessionManager.getSession(from);
// Check if the list is being used by another session
for (ClientSession session : sessionManager.getSessions(from.getNode())) {
if (currentSession == session) {
// Ignore the active session for this checking
continue;
}
if (list.equals(session.getDefaultList()) || list.equals(session.getActiveList())) {
// List to delete is being used by another session so return a conflict error
result.setError(PacketError.Condition.conflict);
return result;
}
}
}
// Remove the list from the active session (if it was being used)
if (list.equals(currentSession.getDefaultList())) {
currentSession.setDefaultList(null);
}
if (list.equals(currentSession.getActiveList())) {
currentSession.setActiveList(null);
}
manager.deletePrivacyList(from.getNode(), listName);
return result;
}
use of org.jivesoftware.openfire.session.ClientSession in project Openfire by igniterealtime.
the class TransportSessionRouter method leftCluster.
/**
* @see org.jivesoftware.openfire.cluster.ClusterEventListener#leftCluster(byte[])
*/
public void leftCluster(byte[] leavingNodeID) {
KrakenPlugin plugin = getPlugin();
// TODO: Is this correct? Lets say another node updates an entry before I get to it, will I see the update?
for (Map.Entry<String, byte[]> entry : sessionLocations.entrySet()) {
if (Arrays.equals(entry.getValue(), leavingNodeID)) {
Lock l = CacheFactory.getLock(entry.getKey() + "lc", sessionLocations);
try {
l.lock();
String jid = entry.getKey().substring(0, entry.getKey().lastIndexOf("@"));
String trType = entry.getKey().substring(entry.getKey().lastIndexOf("@") + 1);
Log.debug("Kraken: Node handling session " + jid + " on " + trType + " lost, taking over session...");
sessionLocations.remove(jid + "@" + trType);
TransportInstance trInstance = plugin.getTransportInstance(trType);
if (trInstance != null) {
BaseTransport<? extends TransportBuddy> transport = trInstance.getTransport();
if (transport != null) {
Collection<ClientSession> sessions = XMPPServer.getInstance().getSessionManager().getSessions(new JID(jid).getNode());
for (ClientSession session : sessions) {
transport.processPacket(session.getPresence());
}
}
}
} finally {
l.unlock();
}
}
}
}
use of org.jivesoftware.openfire.session.ClientSession in project Openfire by igniterealtime.
the class PresenceRouter method route.
/**
* Routes presence packets.
*
* @param packet the packet to route.
* @throws NullPointerException if the packet is null.
*/
public void route(Presence packet) {
if (packet == null) {
throw new NullPointerException();
}
ClientSession session = sessionManager.getSession(packet.getFrom());
try {
// Invoke the interceptors before we process the read packet
InterceptorManager.getInstance().invokeInterceptors(packet, session, true, false);
if (session == null || session.getStatus() != Session.STATUS_CONNECTED) {
handle(packet);
} else {
packet.setTo(session.getAddress());
packet.setFrom((JID) null);
packet.setError(PacketError.Condition.not_authorized);
session.process(packet);
}
// Invoke the interceptors after we have processed the read packet
InterceptorManager.getInstance().invokeInterceptors(packet, session, true, true);
} catch (PacketRejectedException e) {
if (session != null) {
// An interceptor rejected this packet so answer a not_allowed error
Presence reply = new Presence();
reply.setID(packet.getID());
reply.setTo(session.getAddress());
reply.setFrom(packet.getTo());
reply.setError(PacketError.Condition.not_allowed);
session.process(reply);
// Check if a message notifying the rejection should be sent
if (e.getRejectionMessage() != null && e.getRejectionMessage().trim().length() > 0) {
// A message for the rejection will be sent to the sender of the rejected packet
Message notification = new Message();
notification.setTo(session.getAddress());
notification.setFrom(packet.getTo());
notification.setBody(e.getRejectionMessage());
session.process(notification);
}
}
}
}
use of org.jivesoftware.openfire.session.ClientSession in project Openfire by igniterealtime.
the class SessionManager method broadcastPresenceOfOtherResource.
/**
* Sends the presences of other connected resources to the resource that just connected.
*
* @param session the newly created session.
*/
private void broadcastPresenceOfOtherResource(LocalClientSession session) {
if (!SessionManager.isOtherResourcePresenceEnabled()) {
return;
}
Presence presence;
// Get list of sessions of the same user
JID searchJID = new JID(session.getAddress().getNode(), session.getAddress().getDomain(), null);
List<JID> addresses = routingTable.getRoutes(searchJID, null);
for (JID address : addresses) {
if (address.equals(session.getAddress())) {
continue;
}
// Send the presence of an existing session to the session that has just changed
// the presence
ClientSession userSession = routingTable.getClientRoute(address);
presence = userSession.getPresence().createCopy();
presence.setTo(session.getAddress());
session.process(presence);
}
}
Aggregations