use of org.xmpp.packet.IQ in project Openfire by igniterealtime.
the class SipComponent method processPacket.
// Component Interface
public void processPacket(Packet packet) {
Log.debug(packet.toXML());
if (packet instanceof IQ) {
// Handle disco packets
IQ iq = (IQ) packet;
// Ignore IQs of type ERROR or RESULT
if (IQ.Type.error == iq.getType() || IQ.Type.result == iq.getType()) {
return;
}
processIQ(iq);
}
}
use of org.xmpp.packet.IQ in project Openfire by igniterealtime.
the class PubSubEngine method sendErrorPacket.
/**
* Generate a conflict packet to indicate that the nickname being requested/used is already in
* use by another user.
*
* @param packet the packet to be bounced.
*/
void sendErrorPacket(IQ packet, PacketError.Condition error, Element pubsubError) {
IQ reply = IQ.createResultIQ(packet);
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(error);
if (pubsubError != null) {
// Add specific pubsub error if available
reply.getError().getElement().add(pubsubError);
}
router.route(reply);
}
use of org.xmpp.packet.IQ in project Openfire by igniterealtime.
the class PubSubEngine method createNode.
private void createNode(PubSubService service, IQ iq, Element childElement, Element createElement) {
// Call createNodeHelper and get the node creation status.
CreateNodeResponse response = createNodeHelper(service, iq, childElement, createElement);
if (response.newNode == null) {
// New node creation failed
sendErrorPacket(iq, response.creationStatus, response.pubsubError);
} else {
IQ reply = IQ.createResultIQ(iq);
Node newNode = response.newNode;
String nodeID = createElement.attributeValue("node");
// Include new nodeID if it has changed from the original nodeID
if (!newNode.getNodeID().equals(nodeID)) {
Element elem = reply.setChildElement("pubsub", "http://jabber.org/protocol/pubsub");
elem.addElement("create").addAttribute("node", newNode.getNodeID());
}
router.route(reply);
}
}
use of org.xmpp.packet.IQ in project Openfire by igniterealtime.
the class UserManager method isRegisteredUser.
/**
* Returns true if the specified JID belongs to a local or remote registered user. For
* remote users (i.e. domain does not match local domain) a disco#info request is going
* to be sent to the bare JID of the user.
*
* @param user to JID of the user to check it it's a registered user.
* @return true if the specified JID belongs to a local or remote registered user.
*/
public boolean isRegisteredUser(JID user) {
XMPPServer server = XMPPServer.getInstance();
if (server.isLocal(user)) {
try {
getUser(user.getNode());
return true;
} catch (UserNotFoundException e) {
return false;
}
} else {
// Look up in the cache using the full JID
Boolean isRegistered = remoteUsersCache.get(user.toString());
if (isRegistered == null) {
// Check if the bare JID of the user is cached
isRegistered = remoteUsersCache.get(user.toBareJID());
if (isRegistered == null) {
// No information is cached so check user identity and cache it
// A disco#info is going to be sent to the bare JID of the user. This packet
// is going to be handled by the remote server.
IQ iq = new IQ(IQ.Type.get);
iq.setFrom(server.getServerInfo().getXMPPDomain());
iq.setTo(user.toBareJID());
iq.setChildElement("query", "http://jabber.org/protocol/disco#info");
// Send the disco#info request to the remote server. The reply will be
// processed by the IQResultListener (interface that this class implements)
server.getIQRouter().addIQResultListener(iq.getID(), this);
synchronized (user.toBareJID().intern()) {
server.getIQRouter().route(iq);
// Wait for the reply to be processed. Time out in 1 minute.
try {
user.toBareJID().intern().wait(60000);
} catch (InterruptedException e) {
// Do nothing
}
}
// Get the discovered result
isRegistered = remoteUsersCache.get(user.toBareJID());
if (isRegistered == null) {
// Disco failed for some reason (i.e. we timed out before getting a result)
// so assume that user is not anonymous and cache result
isRegistered = Boolean.FALSE;
remoteUsersCache.put(user.toString(), isRegistered);
}
}
}
return isRegistered;
}
}
use of org.xmpp.packet.IQ in project Openfire by igniterealtime.
the class SparkManager method handleDiscoItems.
/**
* Sends a reply for a ServiceDiscovery.
*
* @param packet the packet.
*/
private void handleDiscoItems(IQ packet) {
IQ replyPacket = IQ.createResultIQ(packet);
replyPacket.setChildElement("query", "http://jabber.org/protocol/disco#items");
sendPacket(replyPacket);
}
Aggregations