use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class Workgroup method process.
public void process(Packet packet) {
InterceptorManager interceptorManager = WorkgroupInterceptorManager.getInstance();
try {
interceptorManager.invokeInterceptors(getJID().toBareJID(), packet, true, false);
String mucDomain = WorkgroupManager.getInstance().getMUCServiceName();
if (mucDomain.equals(packet.getFrom().getDomain())) {
roomActivity(packet);
} else if (packet instanceof Message) {
process((Message) packet);
} else if (packet instanceof Presence) {
process((Presence) packet);
} else if (packet instanceof IQ) {
process((IQ) packet);
}
interceptorManager.invokeInterceptors(getJID().toBareJID(), packet, true, true);
} catch (PacketRejectedException e) {
rejectPacket(packet, e);
}
}
use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class WorkgroupPresence method agentToWorkgroup.
private void agentToWorkgroup(Presence packet) throws AgentNotFoundException {
String workgroupNode = workgroup.getJID().getNode();
String resource = packet.getFrom().getResource();
boolean usesAgentResource = workgroupNode.equalsIgnoreCase(resource);
final JID sender = packet.getFrom();
Agent agent = null;
// Check if the sender of the Presence is an Agent otherwise return an error
try {
agent = workgroup.getAgentManager().getAgent(sender);
} catch (AgentNotFoundException notFound) {
if (usesAgentResource) {
throw notFound;
}
}
// Check if the presence includes the Workgroup extension
boolean includesExtension = packet.getChildElement("agent-status", "http://jabber.org/protocol/workgroup") != null;
AgentManager agentManager = workgroup.getAgentManager();
if (agent != null && !agentManager.isInWorkgroup(agent, workgroup) && includesExtension) {
throw new AgentNotFoundException();
}
if (agent == null || !agentManager.isInWorkgroup(agent, workgroup)) {
if (packet.isAvailable()) {
if (!sender.equals(workgroup.getJID())) {
// Add the user to the list of temporary subscribers. Since the
// user sent this presence using a directed presence the server
// will send an unavailable presence if the user gets disconnected.
// When an unavailable presence is received the subscription is
// going to be removed.
listeners.add(packet.getFrom());
sendPresence(packet.getFrom());
}
} else {
listeners.remove(packet.getFrom());
}
return;
}
InterceptorManager interceptorManager = AgentInterceptorManager.getInstance();
try {
interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(), packet, true, false);
// Try to update the presence of the AgentSession with the new presence
AgentSession agentSession = agent.getAgentSession();
if (agentSession == null) {
if (!includesExtension) {
// and does not contain the proper extension
return;
}
// Add new agent session.
agentSession = agent.createSession(packet.getFrom());
if (agentSession == null) {
// User is not able to join since an existing session from another resource already exists
Presence reply = new Presence();
reply.setID(packet.getID());
reply.setTo(packet.getFrom());
reply.setFrom(packet.getTo());
reply.setError(PacketError.Condition.not_allowed);
workgroup.send(reply);
return;
}
}
// Update session's presence with latest presence
agentSession.updatePresence(packet);
if (agentSession.getPresence().getType() == null) {
agentSession.join(workgroup);
} else {
agentSession.depart(workgroup);
}
interceptorManager.invokeInterceptors(workgroup.getJID().toBareJID(), packet, true, true);
} catch (PacketRejectedException e) {
workgroup.rejectPacket(packet, e);
}
}
use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class MainInterceptor method presencePush.
/**
* Just pushes a available presence, we need this for GAJIM Client as it does not push available presence after
* registering We also wait a little so after register transport is on users roster. Really didnt wanted this here
* but doesnt really belong anywhere else
*
* @param to
* @param from
* @param delay MS until the job should be done
*/
private void presencePush(final JID to, final JID from, int delay) {
TimerTask pushPresenceTask = new TimerTask() {
@Override
public void run() {
PacketRouter router = server.getPacketRouter();
Packet presence = new Presence();
presence.setTo(to);
presence.setFrom(from);
router.route(presence);
}
};
Timer timer = new Timer();
timer.schedule(pushPresenceTask, delay);
}
use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class MainInterceptor method interceptPacket.
/**
* This Interceptor tests if GoJara needs to process this package. We decided to do one global Interceptor so we
* would'nt redundantly test for cases we already checked in previous Interceptors, also we have only one big ugly
* If Structure to maintain instead of several.
*
* @see org.jivesoftware.openfire.interceptor.PacketInterceptor#interceptPacket (org.xmpp.packet.Packet,
* org.jivesoftware.openfire.session.Session, boolean, boolean)
*/
public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed) throws PacketRejectedException {
if (frozen)
return;
String from = "";
String to = "";
if (!processed || (incoming && processed)) {
try {
if (packet.getFrom() != null)
from = packet.getFrom().toString();
if (packet.getTo() != null)
to = packet.getTo().toString();
} catch (IllegalArgumentException e) {
Log.debug("There was an illegal JID while intercepting Message for GoJara. Not Intercepting it! " + e.getMessage());
return;
}
}
if (incoming && !processed) {
if (packet instanceof IQ) {
IQ iqPacket = (IQ) packet;
Element query = iqPacket.getChildElement();
if (query == null)
return;
else // Jabber:IQ:roster Indicates Client to Component update or Rosterpush
if (query.getNamespaceURI().equals("jabber:iq:roster")) {
if (!activeTransports.contains(from) && to.length() == 0 && iqPacket.getType().equals(IQ.Type.set))
packetProcessors.get("clientToComponentUpdate").process(packet, "", to, from);
else if (from.length() > 0 && activeTransports.contains(from))
packetProcessors.get("iqRosterPayload").process(packet, from, to, from);
} else // SPARK IQ REGISTERED Feature
if (query.getNamespaceURI().equals("http://jabber.org/protocol/disco#info") && to.length() > 0 && activeTransports.contains(to) && iqPacket.getType().equals(IQ.Type.get)) {
packetProcessors.get("sparkIQRegistered").process(packet, to, to, from);
} else // JABBER:IQ:LAST - Autoresponse Feature
if (JiveGlobals.getBooleanProperty("plugin.remoteroster.iqLastFilter", false) && query.getNamespaceURI().equals("jabber:iq:last")) {
String to_s = searchJIDforSubdomain(to);
if (to_s.length() > 0 && iqPacket.getType().equals(IQ.Type.get))
throw new PacketRejectedException();
}
} else // Gojara Admin Manager Feature - Intercept responses to ADHOC commands sent via AdminManager
if (packet instanceof Message && activeTransports.contains(from) && to.contains("gojaraadmin")) {
packetProcessors.get("gojaraAdminProcessor").process(packet, from, to, from);
} else // NONPERSISTANT Feature
{
if (!JiveGlobals.getBooleanProperty("plugin.remoteroster.persistent", false)) {
if (packet instanceof Presence && activeTransports.contains(from))
packetProcessors.get("handleNonPersistant").process(packet, from, to, from);
}
}
} else if (incoming && processed) {
// We ignore Pings from S2 to S2 itself.
// STATISTICS - Feature
String from_searched = searchJIDforSubdomain(from);
String to_searched = searchJIDforSubdomain(to);
String subdomain = from_searched.length() == 0 ? to_searched : from_searched;
if (!from.equals(to) && subdomain.length() > 0)
packetProcessors.get("statisticsProcessor").process(packet, subdomain, to, from);
// TransportSession Feature
if (packet instanceof Presence && activeTransports.contains(from)) {
Presence presence_packet = (Presence) packet;
if (presence_packet.getType() == null) {
tSessionManager.connectUserTo(from, packet.getTo().getNode().toString());
} else if (presence_packet.getType() != null && presence_packet.getType().equals(Presence.Type.unavailable)) {
tSessionManager.disconnectUserFrom(from, packet.getTo().getNode().toString());
}
} else // TransportSession Feature - track Registrations and unregistrations so we can reset unsuccesfull ones
if (packet instanceof IQ && activeTransports.contains(to)) {
IQ iqPacket = (IQ) packet;
Element query = iqPacket.getChildElement();
if (query == null)
return;
/*
* Okay, so now we have a IQ Packet with a query xmlns: jabber:iq:register Spark sends registrations and
* unregistrations in such a query, register has a x xmls jabber:iq:gateway:register, unregister is just
* a <remove/> element Gajim sends the whole form with x xmlns jabber:x:data type="submit", where a
* field var=unregister value of 0 is a registration, and unregister = 1 is unregistration
*/
if (query.getNamespaceURI().equals("jabber:iq:register") && iqPacket.getType().equals(IQ.Type.set)) {
// spark + gajim unregister
if (query.element("remove") != null)
tSessionManager.removeRegistrationOfUserFromDB(to, iqPacket.getFrom().getNode().toString());
else if (query.element("x") != null) {
Element xElem = query.element("x");
String xNamespace = xElem.getNamespaceURI();
// spark register
if (xNamespace.equals("jabber:iq:gateway:register"))
tSessionManager.registerUserTo(to, iqPacket.getFrom().getNode().toString());
else // Gajim register + presence push
if (xNamespace.equals("jabber:x:data") && xElem.attribute("type").getText().equals("submit")) {
tSessionManager.registerUserTo(to, iqPacket.getFrom().getNode().toString());
presencePush(packet.getTo(), packet.getFrom(), 150);
}
}
}
}
} else if (!incoming && !processed) {
if (packet instanceof IQ) {
IQ iqPacket = (IQ) packet;
Element query = iqPacket.getChildElement();
if (query == null)
return;
// DISCO#ITEMS - Whitelisting Feature
if (query.getNamespaceURI().equals("http://jabber.org/protocol/disco#items"))
packetProcessors.get("whitelistProcessor").process(packet, "", to, from);
else // DISCO#INFO - MUC-Filter-Feature
if (JiveGlobals.getBooleanProperty("plugin.remoteroster.mucFilter", false) && query.getNamespaceURI().equals("http://jabber.org/protocol/disco#info") && from.length() > 0 && activeTransports.contains(from))
packetProcessors.get("mucfilterProcessor").process(packet, from, to, from);
else // pushed by OF anyways
if (JiveGlobals.getBooleanProperty("plugin.remoteroster.gajimBroadcast", false)) {
if (to.contains("Gajim") && query.getNamespaceURI().equals("jabber:iq:roster") && iqPacket.getType().equals(IQ.Type.result)) {
List<Node> nodes = XpathHelper.findNodesInDocument(iqPacket.getElement().getDocument(), "//roster:item");
for (Node n : nodes) {
String jid = n.valueOf("@jid");
if (activeTransports.contains(jid)) {
JID pushTo = new JID(jid);
presencePush(pushTo, iqPacket.getTo(), 3000);
}
}
}
}
} else if (JiveGlobals.getBooleanProperty("plugin.remoteroster.blockPresences", true) && packet instanceof Presence) {
/*
* We block Presences to users of a subdomain (except transport itself) so OF/S2 wont log you in
* automatically if you have a subdomain user in your roster. This prevents some clients from logging
* automatically, as the clients dont send a specific presence to the transport. We could do a presence
* push if we see them come online, but that would do the same as just not intercepting these presences,
* as the problem is really the client
*/
String to_s = searchJIDforSubdomain(to);
if (to_s.length() > 0 && !activeTransports.contains(to))
throw new PacketRejectedException();
}
}
}
use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class WorkgroupPresence method process.
public void process(Presence packet) {
try {
JID sender = packet.getFrom();
// Handling Subscription
if (Presence.Type.subscribe == packet.getType()) {
// Only create item if user was not already subscribed to workgroup's presence
if (!presenceSubscribers.contains(sender.toBareJID())) {
createRosterItem(sender);
}
// Reply that the subscription request was approved
Presence reply = new Presence();
reply.setTo(sender);
reply.setFrom(workgroup.getJID());
reply.setType(Presence.Type.subscribed);
workgroup.send(reply);
// Send the presence of the workgroup to the user that requested it
sendPresence(packet.getFrom());
} else if (Presence.Type.unsubscribe == packet.getType()) {
// Remove sender from the workgroup roster
deleteRosterItem(sender);
// Send confirmation of unsubscription
Presence reply = new Presence();
reply.setTo(sender);
reply.setFrom(workgroup.getJID());
reply.setType(Presence.Type.unsubscribed);
workgroup.send(reply);
// Send unavailable presence of the workgroup
reply = new Presence();
reply.setTo(sender);
reply.setFrom(workgroup.getJID());
reply.setType(Presence.Type.unavailable);
workgroup.send(reply);
} else if (Presence.Type.subscribed == packet.getType()) {
// ignore
} else if (Presence.Type.unsubscribed == packet.getType()) {
// ignore
} else if (Presence.Type.probe == packet.getType()) {
// Send the presence of the workgroup to the user that requested it
sendPresence(packet.getFrom());
} else {
try {
agentToWorkgroup(packet);
} catch (AgentNotFoundException e) {
Presence reply = new Presence();
reply.setError(new PacketError(PacketError.Condition.not_authorized));
reply.setTo(packet.getFrom());
reply.setFrom(workgroup.getJID());
workgroup.send(reply);
StringBuilder errorMessage = new StringBuilder();
errorMessage.append("Sender: ");
errorMessage.append(packet.getFrom().toString());
errorMessage.append(" Workgroup: ");
errorMessage.append(workgroup.getJID().toString());
Log.debug(errorMessage.toString(), e);
}
}
} catch (Exception e) {
Log.error(e.getMessage(), e);
Presence reply = new Presence();
reply.setError(new PacketError(PacketError.Condition.internal_server_error));
reply.setTo(packet.getFrom());
reply.setFrom(workgroup.getJID());
workgroup.send(reply);
}
}
Aggregations