use of org.xmpp.packet.IQ in project Openfire by igniterealtime.
the class ChatSettingsManager method getChatSettingsByType.
/**
* Send all WebChat settings for a particular Workgroup and type.
*
* @param packet the original packet that made the request.
* @param workgroup the workgroup the packet was sent to.
* @param type the type.
*/
public void getChatSettingsByType(IQ packet, Workgroup workgroup, int type) {
IQ reply = IQ.createResultIQ(packet);
// Retrieve the web chat setting.
ChatSettings chatSettings = getChatSettings(workgroup);
if (chatSettings == null) {
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(new PacketError(PacketError.Condition.item_not_found));
workgroup.send(reply);
return;
}
Element webSettings = reply.setChildElement("chat-settings", "http://jivesoftware.com/protocol/workgroup");
for (ChatSetting setting : chatSettings.getChatSettings()) {
if (setting.getType().getType() == type) {
Element root = webSettings.addElement("chat-setting");
root.addElement("key").setText(setting.getKey().toString());
root.addElement("value").setText(setting.getValue());
root.addElement("type").setText(Integer.toString(setting.getType().getType()));
}
}
workgroup.send(reply);
}
use of org.xmpp.packet.IQ in project Openfire by igniterealtime.
the class PacketCounter method start.
/**
* Resets all counters, and starts counting.
*/
public void start() {
// Register a packet listener so that we can track packet traffic.
interceptor = new PacketInterceptor() {
public void interceptPacket(final Packet packet, final Session session, final boolean incoming, final boolean processed) {
if (!processed) {
// don't count packets twice!
return;
}
stanza.incrementAndGet();
if (packet instanceof Message) {
message.incrementAndGet();
}
if (packet instanceof Presence) {
presence.incrementAndGet();
}
if (packet instanceof IQ) {
iq.incrementAndGet();
switch(((IQ) packet).getType()) {
case get:
iqGet.incrementAndGet();
break;
case set:
iqSet.incrementAndGet();
break;
case result:
iqResult.incrementAndGet();
break;
case error:
iqError.incrementAndGet();
break;
}
}
}
};
// reset counters
stanza.set(0);
message.set(0);
presence.set(0);
iq.set(0);
iqGet.set(0);
iqSet.set(0);
iqResult.set(0);
iqError.set(0);
// register listener
InterceptorManager.getInstance().addInterceptor(interceptor);
}
use of org.xmpp.packet.IQ in project Openfire by igniterealtime.
the class JingleNodesComponent method handleIQGet.
@Override
protected IQ handleIQGet(IQ iq) throws Exception {
final IQ reply = IQ.createResultIQ(iq);
final Element element = iq.getChildElement();
final String namespace = element.getNamespaceURI();
if (JingleChannelIQ.NAME.equals(element.getName()) && JingleChannelIQ.NAMESPACE.equals(namespace) && UDP.equals(element.attributeValue(PROTOCOL))) {
final Element childElement = iq.getChildElement().createCopy();
final RelayChannel channel = plugin.createRelayChannel();
if (channel != null) {
childElement.addAttribute(HOST, plugin.getPublicIP());
childElement.addAttribute(LOCAL_PORT, Integer.toString(channel.getPortA()));
childElement.addAttribute(REMOTE_PORT, Integer.toString(channel.getPortB()));
reply.setChildElement(childElement);
Log.debug("Created relay channel {}:{}, {}:{}, {}:{}", new Object[] { HOST, plugin.getPublicIP(), LOCAL_PORT, Integer.toString(channel.getPortA()), REMOTE_PORT, Integer.toString(channel.getPortB()) });
} else {
reply.setError(PacketError.Condition.internal_server_error);
}
return reply;
} else if (JingleTrackerIQ.NAME.equals(element.getName()) && JingleTrackerIQ.NAMESPACE.equals(namespace)) {
final List<TrackerEntry> entries = new ArrayList<TrackerEntry>();
entries.add(new TrackerEntry(TrackerEntry.Type.relay, TrackerEntry.Policy._roster, plugin.getServiceName() + "." + getDomain(), UDP));
final String elements = getChildElementXML(entries);
final Element e = DocumentHelper.parseText(elements).getRootElement();
reply.setChildElement(e);
return reply;
}
// feature not implemented.
return null;
}
use of org.xmpp.packet.IQ in project Openfire by igniterealtime.
the class BaseMUCTransport method processPacket.
/**
* Handles all incoming iq stanzas.
*
* @param packet The iq packet to be processed.
* @return list of packets that will be sent back to the IQ requester.
*/
private List<Packet> processPacket(IQ packet) {
Log.debug("Received iq packet: " + packet.toXML());
List<Packet> reply = new ArrayList<Packet>();
if (packet.getType() == IQ.Type.error) {
// Lets not start a loop. Ignore.
return reply;
}
String xmlns = null;
Element child = (packet).getChildElement();
if (child != null) {
xmlns = child.getNamespaceURI();
}
if (xmlns == null) {
// No namespace defined.
Log.debug("No XMLNS:" + packet.toString());
IQ error = IQ.createResultIQ(packet);
error.setError(PacketError.Condition.bad_request);
reply.add(error);
return reply;
}
if (xmlns.equals(NameSpace.DISCO_INFO)) {
reply.addAll(handleDiscoInfo(packet));
} else if (xmlns.equals(NameSpace.DISCO_ITEMS)) {
reply.addAll(handleDiscoItems(packet));
} else if (xmlns.equals(NameSpace.MUC_ADMIN)) {
reply.addAll(handleMUCAdmin(packet));
} else if (xmlns.equals(NameSpace.MUC_USER)) {
reply.addAll(handleMUCUser(packet));
} else {
Log.debug("Unable to handle iq request: " + xmlns);
IQ error = IQ.createResultIQ(packet);
error.setError(PacketError.Condition.service_unavailable);
reply.add(error);
}
return reply;
}
use of org.xmpp.packet.IQ in project Openfire by igniterealtime.
the class BaseMUCTransport method handleDiscoItems.
/**
* Handle service discovery items request.
*
* @param packet An IQ packet in the disco items namespace.
* @return A list of IQ packets to be returned to the user.
*/
private List<Packet> handleDiscoItems(IQ packet) {
List<Packet> reply = new ArrayList<Packet>();
JID from = packet.getFrom();
JID to = packet.getTo();
if (packet.getTo().getNode() == null) {
// A request for a list of rooms
IQ result = IQ.createResultIQ(packet);
if (JiveGlobals.getBooleanProperty("plugin.gateway." + getTransport().getType() + ".roomlist", false)) {
try {
TransportSession<B> session = getTransport().getSessionManager().getSession(from);
if (session.isLoggedIn()) {
storePendingRequest(packet);
session.getRooms();
}
} catch (NotFoundException e) {
// Not found? No active session then.
result.setError(PacketError.Condition.forbidden);
reply.add(result);
}
} else {
// Time to lie and tell them we have no rooms
sendRooms(from, new ArrayList<MUCTransportRoom>());
}
} else {
// Ah, a request for members of a room.
IQ result = IQ.createResultIQ(packet);
try {
TransportSession<B> session = getTransport().getSessionManager().getSession(from);
if (session.isLoggedIn()) {
storePendingRequest(packet);
session.getRoomMembers(getTransport().convertJIDToID(to));
} else {
// Not logged in? Not logged in then.
result.setError(PacketError.Condition.forbidden);
reply.add(result);
}
} catch (NotFoundException e) {
// Not found? No active session then.
result.setError(PacketError.Condition.forbidden);
reply.add(result);
}
}
return reply;
}
Aggregations