use of org.xmpp.packet.Message 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.Message 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.Message in project Openfire by igniterealtime.
the class Chatbot method sendReply.
private void sendReply(Message message, String reply) {
Message packet = new Message();
packet.setTo(message.getFrom());
packet.setFrom(message.getTo());
packet.setThread(message.getThread());
packet.setType(message.getType());
packet.setBody(reply);
send(packet);
}
use of org.xmpp.packet.Message in project Openfire by igniterealtime.
the class Chatbot method notifyQueueDepartued.
public void notifyQueueDepartued(JID sender, JID receiver, UserRequest request, Request.CancelType type) {
// Get the chatbot session of the user
ChatbotSession session = getSession(receiver, false);
if (session != null) {
Message packet = new Message();
packet.setTo(receiver);
packet.setFrom(sender);
packet.setThread(session.getMessageThread());
if (session.getMessageThread() != null) {
packet.setType(Message.Type.chat);
}
packet.setBody(getDepartureConfirmedMessage());
send(packet);
// Remove the session of this user
removeSession(receiver);
}
}
use of org.xmpp.packet.Message in project Openfire by igniterealtime.
the class Chatbot method sendMessage.
private void sendMessage(JID receiver, String thread, String body) {
Message packet = new Message();
packet.setTo(receiver);
packet.setFrom(workgroup.getJID());
packet.setThread(thread);
if (thread != null) {
packet.setType(Message.Type.chat);
}
packet.setBody(body);
send(packet);
}
Aggregations