Java Code Examples for org.xmpp.packet.IQ#createResultIQ()

The following examples show how to use org.xmpp.packet.IQ#createResultIQ() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PubSubModule.java    From Openfire with Apache License 2.0 6 votes vote down vote up
@Override
public void process(Packet packet) {
    try {
        // Check if the packet is a disco request or a packet with namespace iq:register
        if (packet instanceof IQ) {
            if (engine.process(this, (IQ) packet) == null) {
                process((IQ) packet);
            }
        }
        else if (packet instanceof Presence) {
            engine.process(this, (Presence) packet);
        }
        else {
            engine.process(this, (Message) packet);
        }
    }
    catch (Exception e) {
        Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
        if (packet instanceof IQ) {
            // Send internal server error
            IQ reply = IQ.createResultIQ((IQ) packet);
            reply.setError(PacketError.Condition.internal_server_error);
            send(reply);
        }
    }
}
 
Example 2
Source File: IQPrivacyHandler.java    From Openfire with Apache License 2.0 6 votes vote down vote up
/**
 * User has specified a new active list that should be used for the current session.
 *
 * @param packet IQ packet setting new active list for the current session.
 * @param from sender of the IQ packet.
 * @param listName name of the new active list for the current session.
 * @return acknowledge of success.
 */
private IQ setActiveList(IQ packet, JID from, String listName) {
    IQ result = IQ.createResultIQ(packet);
    Element childElement = packet.getChildElement().createCopy();
    result.setChildElement(childElement);

    // Get the list
    PrivacyList list = manager.getPrivacyList(from.getNode(), listName);
    if (list != null) {
        // Get the user session
        ClientSession session = sessionManager.getSession(from);
        if (session != null) {
            // Set the new active list for this session
            session.setActiveList(list);
        }
    }
    else {
        // List not found
        result.setError(PacketError.Condition.item_not_found);
    }
    return result;
}
 
Example 3
Source File: LeafNode.java    From Openfire with Apache License 2.0 6 votes vote down vote up
/**
 * Sends an IQ result with the list of items published to the node. Item ID and payload
 * may be included in the result based on the node configuration.
 *
 * @param originalRequest the IQ packet sent by a subscriber (or anyone) to get the node items.
 * @param publishedItems the list of published items to send to the subscriber.
 * @param forceToIncludePayload true if the item payload should be include if one exists. When
 *        false the decision is up to the node.
 */
void sendPublishedItems(IQ originalRequest, List<PublishedItem> publishedItems,
        boolean forceToIncludePayload) {
    IQ result = IQ.createResultIQ(originalRequest);
    Element pubsubElem = result.setChildElement("pubsub", "http://jabber.org/protocol/pubsub");
    Element items = pubsubElem.addElement("items");
    items.addAttribute("node", nodeID);
    
    for (PublishedItem publishedItem : publishedItems) {
        Element item = items.addElement("item");
        if (isItemRequired()) {
            item.addAttribute("id", publishedItem.getID());
        }
        if ((forceToIncludePayload || isPayloadDelivered()) &&
                publishedItem.getPayload() != null) {
            item.add(publishedItem.getPayload().createCopy());
        }
    }
    // Send the result
    getService().send(result);
}
 
Example 4
Source File: Node.java    From Openfire with Apache License 2.0 6 votes vote down vote up
/**
 * Sends the list of affiliations with the node to the owner that sent the IQ
 * request.
 *
 * @param iqRequest IQ request sent by an owner of the node.
 */
void sendAffiliations(IQ iqRequest) {
    IQ reply = IQ.createResultIQ(iqRequest);
    Element childElement = iqRequest.getChildElement().createCopy();
    reply.setChildElement(childElement);
    Element affiliations = childElement.element("affiliations");

    for (NodeAffiliate affiliate : affiliates) {
        if (affiliate.getAffiliation() == NodeAffiliate.Affiliation.none) {
            continue;
        }
        Element entity = affiliations.addElement("affiliation");
        entity.addAttribute("jid", affiliate.getJID().toString());
        entity.addAttribute("affiliation", affiliate.getAffiliation().name());
    }
    // Send reply
    getService().send(reply);
}
 
Example 5
Source File: IQSharedGroupHandler.java    From Openfire with Apache License 2.0 6 votes vote down vote up
@Override
public IQ handleIQ(IQ packet) throws UnauthorizedException {
    IQ result = IQ.createResultIQ(packet);
    String username = packet.getFrom().getNode();
    if (!serverName.equals(packet.getFrom().getDomain()) || username == null) {
        // Users of remote servers are not allowed to get their "shared groups". Users of
        // remote servers cannot have shared groups in this server.
        // Besides, anonymous users do not belong to shared groups so answer an error
        result.setChildElement(packet.getChildElement().createCopy());
        result.setError(PacketError.Condition.not_allowed);
        return result;
    }

    Collection<Group> groups = rosterManager.getSharedGroups(username);
    Element sharedGroups = result.setChildElement("sharedgroup",
            "http://www.jivesoftware.org/protocol/sharedgroup");
    for (Group sharedGroup : groups) {
        String displayName = sharedGroup.getProperties().get("sharedRoster.displayName");
        if (displayName != null) {
            sharedGroups.addElement("group").setText(displayName);
        }
    }
    return result;
}
 
Example 6
Source File: IQAdminHandler.java    From Openfire with Apache License 2.0 6 votes vote down vote up
/**
 * Handles the IQ packet sent by an owner or admin of the room. Possible actions are:
 * <ul>
 * <li>Return the list of participants</li>
 * <li>Return the list of moderators</li>
 * <li>Return the list of members</li>
 * <li>Return the list of outcasts</li>
 * <li>Change user's affiliation to member</li>
 * <li>Change user's affiliation to outcast</li>
 * <li>Change user's affiliation to none</li>
 * <li>Change occupant's affiliation to moderator</li>
 * <li>Change occupant's affiliation to participant</li>
 * <li>Change occupant's affiliation to visitor</li>
 * <li>Kick occupants from the room</li>
 * </ul>
 *
 * @param packet the IQ packet sent by an owner or admin of the room.
 * @param role the role of the user that sent the request packet.
 * @throws ForbiddenException If the user is not allowed to perform his request.
 * @throws ConflictException If the desired room nickname is already reserved for the room or
 *                           if the room was going to lose all of its owners.
 * @throws NotAllowedException Thrown if trying to ban an owner or an administrator.
 * @throws CannotBeInvitedException If the user being invited as a result of being added to a members-only room still does not have permission
 */
public void handleIQ(IQ packet, MUCRole role) throws ForbiddenException, ConflictException,
        NotAllowedException, CannotBeInvitedException {
    IQ reply = IQ.createResultIQ(packet);
    Element element = packet.getChildElement();

    // Analyze the action to perform based on the included element
    @SuppressWarnings("unchecked")
    List<Element> itemsList = element.elements("item");
    
    if (!itemsList.isEmpty()) {
        handleItemsElement(role, itemsList, reply);
    }
    else {
        // An unknown and possibly incorrect element was included in the query
        // element so answer a BAD_REQUEST error
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(PacketError.Condition.bad_request);
    }
    if (reply.getTo() != null) {
        // Send a reply only if the sender of the original packet was from a real JID. (i.e. not
        // a packet generated locally)
        router.route(reply);
    }
}
 
Example 7
Source File: IQPrivacyHandler.java    From Openfire with Apache License 2.0 6 votes vote down vote up
/**
 * User has specified that there is no default list that should be used for this user.
 *
 * @param packet IQ packet declining default list for all sessions.
 * @param from sender of the IQ packet.
 * @return acknowledge of success.
 */
private IQ declineDefaultList(IQ packet, JID from) {
    IQ result = IQ.createResultIQ(packet);
    Element childElement = packet.getChildElement().createCopy();
    result.setChildElement(childElement);

    if (sessionManager.getSessionCount(from.getNode()) > 1) {
        // Current default list is being used by more than one session
        result.setError(PacketError.Condition.conflict);
    }
    else {
        // Get the user session
        ClientSession session = sessionManager.getSession(from);
        // Check if a default list was already defined
        if (session.getDefaultList() != null) {
            // Set the existing default list as non-default
            session.getDefaultList().setDefaultList(false);
            // Update the database with the new list state
            provider.updatePrivacyList(from.getNode(), session.getDefaultList());
            session.setDefaultList(null);
        }
    }
    return result;
}
 
Example 8
Source File: FileTransferProxy.java    From Openfire with Apache License 2.0 5 votes vote down vote up
@Override
public void process(Packet packet) throws UnauthorizedException, PacketException {
    // Check if the packet is a disco request or a packet with namespace iq:register
    if (packet instanceof IQ) {
        if (handleIQ((IQ) packet)) {
            // Do nothing
        }
        else {
            IQ reply = IQ.createResultIQ((IQ) packet);
            reply.setChildElement(((IQ) packet).getChildElement().createCopy());
            reply.setError(PacketError.Condition.feature_not_implemented);
            router.route(reply);
        }
    }
}
 
Example 9
Source File: IQPrivacyHandler.java    From Openfire with Apache License 2.0 5 votes vote down vote up
/**
 * User has specified a new default list that should be used for all session.
 *
 * @param packet IQ packet setting new default list for all sessions.
 * @param from sender of the IQ packet.
 * @param listName name of the new default list for all sessions.
 * @return acknowledge of success.
 */
private IQ setDefaultList(IQ packet, JID from, String listName) {
    IQ result = IQ.createResultIQ(packet);
    Element childElement = packet.getChildElement().createCopy();
    result.setChildElement(childElement);

    if (sessionManager.getSessionCount(from.getNode()) > 1) {
        // Current default list is being used by more than one session
        result.setError(PacketError.Condition.conflict);
    }
    else {
        // Get the list
        PrivacyList list = manager.getPrivacyList(from.getNode(), listName);
        if (list != null) {
            // Get the user session
            ClientSession session = sessionManager.getSession(from);
            PrivacyList oldDefaultList = session.getDefaultList();
            manager.changeDefaultList(from.getNode(), list, oldDefaultList);
            // Set the new default list for this session (the only existing session)
            session.setDefaultList(list);
        }
        else {
            // List not found
            result.setError(PacketError.Condition.item_not_found);
        }
    }
    return result;
}
 
Example 10
Source File: IQPEPHandler.java    From Openfire with Apache License 2.0 5 votes vote down vote up
@Override
public IQ handleIQ(IQ packet) {
    // Do nothing if server is not enabled
    if (!isEnabled()) {
        IQ reply = IQ.createResultIQ(packet);
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(PacketError.Condition.service_unavailable);
        return reply;
    }

    if (packet.getTo() == null || packet.getTo().equals( new JID(XMPPServer.getInstance().getServerInfo().getXMPPDomain())) )
    {
        // packet addressed to service itself (not to a node/user)
        switch ( packet.getType() )
        {
            case set:
                return handleIQSetToService(packet );
            case get:
                return handleIQGetToService(packet );
            default:
                return null; // Ignore 'error' and 'result' stanzas.
        }
    }
    else
    {
        // packet was addressed to a node.
        if ( packet.isRequest() ) {
            return handleIQRequestToUser( packet );
        } else {
            return null; // Ignore IQ packets of type 'error' or 'result'.
        }
    }
}
 
Example 11
Source File: IQPrivacyHandler.java    From Openfire with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the IQ packet containing the details of the specified list. If no list
 * was found or the IQ request contains more than one specified list then an error will
 * be returned.
 *
 * @param packet IQ packet requesting a given list.
 * @param from sender of the IQ packet.
 * @return the IQ packet containing the details of the specified list.
 */
private IQ getPrivacyList(IQ packet, JID from) {
    IQ result = IQ.createResultIQ(packet);
    Element childElement = packet.getChildElement().createCopy();
    result.setChildElement(childElement);

    // Check that only one list was requested
    List<Element> lists = childElement.elements("list");
    if (lists.size() > 1) {
        result.setError(PacketError.Condition.bad_request);
    }
    else {
        String listName = lists.get(0).attributeValue("name");
        PrivacyList list = null;
        if (listName != null) {
            // A list name was specified so get it
            list = manager.getPrivacyList(from.getNode(), listName);
        }
        if (list != null) {
            // Add the privacy list to the result
            childElement = result.setChildElement("query", "jabber:iq:privacy");
            childElement.add(list.asElement());
        }
        else {
            // List not found
            result.setError(PacketError.Condition.item_not_found);
        }
    }
    return result;
}
 
Example 12
Source File: IQPingHandler.java    From Openfire with Apache License 2.0 5 votes vote down vote up
@Override
public IQ handleIQ(IQ packet) {
    if (Type.get.equals(packet.getType())) {
        return IQ.createResultIQ(packet);
    }
    return null;
}
 
Example 13
Source File: IQPrivacyHandler.java    From Openfire with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 14
Source File: LocationHandler.java    From openfireLBS with Apache License 2.0 5 votes vote down vote up
@Override
public IQ handleIQ(IQ packet) throws UnauthorizedException {
	
	System.out.println(">>>>>>>>>>>>> RECV IQ: " + packet.toXML()); // XXX
	
	// get users near me(from JID)
	if (IQ.Type.get.equals(packet.getType())) {
		return getUsersNearme(packet);
	// set from JID's location to ...
	} else if (IQ.Type.set.equals(packet.getType())) {
		JID to = packet.getTo();
		
		// send from JID's location to to JID
		if (to.getNode() != null && !to.getNode().equals("")){  
			XMPPServer.getInstance().getIQRouter().route(packet); // route to another user 
			
			return IQ.createResultIQ(packet);
		// send from JID's location to server , and update ofLocation  
		}else{ 
			return updateLocation(packet);
		}
	} else {
		IQ reply = IQ.createResultIQ(packet);
		reply.setType(IQ.Type.error);
		reply.setError(PacketError.Condition.bad_request);
		return reply;
	}
}
 
Example 15
Source File: IQPrivacyHandler.java    From Openfire with Apache License 2.0 5 votes vote down vote up
/**
 * Updates an existing privacy list or creates a new one with the specified items list. The
 * new list will not become the active or default list by default. The user will have to
 * send another packet to set the new list as active or default.<p>
 *
 * Once the list was updated or created a "privacy list push" will be sent to all
 * connected resources of the user.
 *
 * @param packet IQ packet updating or creating a new privacy list.
 * @param from sender of the IQ packet.
 * @param listElement the element containing the list and its items.
 * @return acknowledge of success.
 */
private IQ updateOrCreateList(IQ packet, JID from, Element listElement) {
    IQ result = IQ.createResultIQ(packet);
    Element childElement = packet.getChildElement().createCopy();
    result.setChildElement(childElement);

    String listName = listElement.attributeValue("name");
    PrivacyList list = manager.getPrivacyList(from.getNode(), listName);
    if (list == null) {
        list = manager.createPrivacyList(from.getNode(), listName, listElement);
    }
    else {
        // Update existing list
        list.updateList(listElement);
        provider.updatePrivacyList(from.getNode(), list);
        // Make sure that existing user sessions that are using the updated list are poining
        // to the updated instance. This may happen since PrivacyListManager uses a Cache that
        // may expire so it's possible to have many instances representing the same privacy
        // list. Therefore, if a list is modified then we need to make sure that all
        // instances are replaced with the updated instance. An OR Mapping Tool would have
        // avoided this issue since identity is ensured.
        for (ClientSession session : sessionManager.getSessions(from.getNode())) {
            if (list.equals(session.getDefaultList())) {
                session.setDefaultList(list);
            }
            if (list.equals(session.getActiveList())) {
                session.setActiveList(list);
            }
        }
    }
    // Send a "privacy list push" to all connected resources
    IQ pushPacket = new IQ(IQ.Type.set);
    Element child = pushPacket.setChildElement("query", "jabber:iq:privacy");
    child.addElement("list").addAttribute("name", list.getName());
    sessionManager.userBroadcast(from.getNode(), pushPacket);

    return result;
}
 
Example 16
Source File: MultiplexerPacketHandler.java    From Openfire with Apache License 2.0 4 votes vote down vote up
/**
 * Sends an IQ result packet confirming that the operation was successful.
 *
 * @param packet the original IQ packet.
 */
private void sendResultPacket(IQ packet) {
    IQ reply = IQ.createResultIQ(packet);
    reply.setChildElement(packet.getChildElement().createCopy());
    deliver(reply);
}
 
Example 17
Source File: IQSessionEstablishmentHandler.java    From Openfire with Apache License 2.0 4 votes vote down vote up
@Override
public IQ handleIQ(IQ packet) throws UnauthorizedException {
    // Just answer that the session has been activated
    IQ reply = IQ.createResultIQ(packet);
    return reply;
}
 
Example 18
Source File: Node.java    From Openfire with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new subscription and possibly a new affiliate if the owner of the subscription
 * does not have any existing affiliation with the node. The new subscription might require
 * to be authorized by a node owner to be active. If new subscriptions are required to be
 * configured before being active then the subscription state would be "unconfigured".<p>
 *
 * The originalIQ parameter may be {@code null} when using this API internally. When no
 * IQ packet was sent then no IQ result will be sent to the sender. The rest of the
 * functionality is the same.
 *
 * @param originalIQ the IQ packet sent by the entity to subscribe to the node or
 *        null when using this API internally.
 * @param owner the JID of the affiliate.
 * @param subscriber the JID where event notifications are going to be sent.
 * @param authorizationRequired true if the new subscriptions needs to be authorized by
 *        a node owner.
 * @param options the data form with the subscription configuration or null if subscriber
 *        didn't provide a configuration.
 */
public void createSubscription(IQ originalIQ, JID owner, JID subscriber,
        boolean authorizationRequired, DataForm options) {
    // Create a new affiliation if required
    if (getAffiliate(owner) == null) {
        addNoneAffiliation(owner);
    }
    // Figure out subscription status
    NodeSubscription.State subState = NodeSubscription.State.subscribed;
    if (isSubscriptionConfigurationRequired()) {
        // User has to configure the subscription to make it active
        subState = NodeSubscription.State.unconfigured;
    }
    else if (authorizationRequired && !isAdmin(owner)) {
        // Node owner needs to authorize subscription request so status is pending
        subState = NodeSubscription.State.pending;
    }
    // Generate a subscription ID (override even if one was sent by the client)
    String id = StringUtils.randomString(40);
    // Create new subscription
    NodeSubscription subscription = new NodeSubscription(this, owner, subscriber, subState, id);
    // Configure the subscription with the specified configuration (if any)
    if (options != null) {
        subscription.configure(options);
    }

    if ( subscription.isAuthorizationPending() ) {
        final Set<NodeSubscription> existing = new HashSet<>();
        existing.add( subscriptionsByJID.get( subscription.getJID().toString() ) ); // potentially null
        existing.addAll( subscriptionsByID.values().stream().filter( s -> s.getJID().equals( subscription.getJID() ) ).collect( Collectors.toSet()) );
        if (existing.stream().anyMatch( s -> s != null && s.isAuthorizationPending() ) ) {
            // This node already has a pending subscription for this JID. The XEP forbids this.
            if (originalIQ != null ) {
                final IQ response = IQ.createResultIQ( originalIQ );
                response.setError( PacketError.Condition.not_authorized );
                response.getError().getElement().addElement( "pending-subscription", "http://jabber.org/protocol/pubsub#errors" );
                getService().send( response );
            }
            // Silently ignore if this was an internal API call.
            return;
        }
    }

    addSubscription(subscription);

    if (savedToDB) {
        // Add the new subscription to the database
        PubSubPersistenceProviderManager.getInstance().getProvider().createSubscription(this, subscription);
    }

    if (originalIQ != null) {
        // Reply with subscription and affiliation status indicating if subscription
        // must be configured (only when subscription was made through an IQ packet)
        subscription.sendSubscriptionState(originalIQ);
    }

    // If subscription is pending then send notification to node owners asking to approve
    // new subscription
    if (subscription.isAuthorizationPending()) {
        subscription.sendAuthorizationRequest();
    }

    // Update the other members with the new subscription
    CacheFactory.doClusterTask(new NewSubscriptionTask(subscription));

    // Send last published item (if node is leaf node and subscription status is ok)
    if (isSendItemSubscribe() && subscription.isActive()) {
        PublishedItem lastItem = getLastPublishedItem();
        if (lastItem != null) {
            subscription.sendLastPublishedItem(lastItem);
        }
    }

    // Check if we need to subscribe to the presence of the owner
    if (isPresenceBasedDelivery() && getSubscriptions(subscription.getOwner()).size() == 1) {
        if (subscription.getPresenceStates().isEmpty()) {
            // Subscribe to the owner's presence since the node is only sending events to
            // online subscribers and this is the first subscription of the user and the
            // subscription is not filtering notifications based on presence show values.
            getService().presenceSubscriptionRequired(this, owner);
        }
    }
}
 
Example 19
Source File: LocationHandler.java    From openfireLBS with Apache License 2.0 4 votes vote down vote up
/**
 * 
 * 
 * @param packet
 * @return
 */
private IQ getUsersNearme(IQ packet) {

	IQ reply = IQ.createResultIQ(packet);
	
	JID from = packet.getFrom();
	
	Element iq = packet.getChildElement();
	Element item = iq.element("item");
	Double myLon = Double.parseDouble(item.attributeValue("lon"));
	Double myLat = Double.parseDouble(item.attributeValue("lat"));
	
	// XXX: update user location firstly 
	insertLocation(myLon,myLat,from.getNode());
	
	// find users near me 
	PreparedStatement pstmt = null;
	ResultSet rs = null;
	try {
		pstmt = openfireConn.prepareStatement(SQL_USERS_NEARME);
		pstmt.setDouble(1, myLon);
		pstmt.setDouble(2, myLon);
		pstmt.setDouble(3, myLat);
		pstmt.setDouble(4, myLat);
		rs = pstmt.executeQuery();
		String username = null;
		double nearLon = 0;
		double nearLat = 0;
		while (rs.next()) {  
			username = rs.getString("username");
			nearLon = rs.getDouble("lon");
			nearLat = rs.getDouble("lat");
			Element e = iq.addElement("item");
			e.addAttribute("user", username);
			e.addAttribute("lon", Double.toString(nearLon));
			e.addAttribute("lat", Double.toString(nearLat));
		}
		reply.setChildElement(iq);
	} catch (SQLException e1) {
		reply.setType(IQ.Type.error);
		reply.setError(PacketError.Condition.internal_server_error);
		e1.printStackTrace();
	}
	return reply;
}
 
Example 20
Source File: MultiUserChatServiceImpl.java    From Openfire with Apache License 2.0 4 votes vote down vote up
@Override
public void processPacket(final Packet packet) {

    Log.trace( "Routing stanza: {}", packet.toXML() );
    if (!isServiceEnabled()) {
        Log.trace( "Service is disabled. Ignoring stanza." );
        return;
    }
    // The MUC service will receive all the packets whose domain matches the domain of the MUC
    // service. This means that, for instance, a disco request should be responded by the
    // service itself instead of relying on the server to handle the request.
    try {
        // Check if the packet is a disco request or a packet with namespace iq:register
        if (packet instanceof IQ) {
            if (process((IQ)packet)) {
                Log.trace( "Done processing IQ stanza." );
                return;
            }
        } else if (packet instanceof Message) {
            final Message msg = (Message) packet;
            if (msg.getType() == Message.Type.error) {
                // Bounced message, drop user.
                removeUser(packet.getFrom());
                Log.trace( "Done processing Message stanza." );
                return;
            }
        } else if (packet instanceof Presence) {
            final Presence pres = (Presence) packet;
            if (pres.getType() == Presence.Type.error) {
                // Bounced presence, drop user.
                removeUser(packet.getFrom());
                Log.trace( "Done processing Presence stanza." );
                return;
            }
        }

        if ( packet.getTo().getNode() == null )
        {
            Log.trace( "Stanza was addressed at the service itself, which by now should have been handled." );
            if ( packet instanceof IQ && ((IQ) packet).isRequest() )
            {
                final IQ reply = IQ.createResultIQ( (IQ) packet );
                reply.setChildElement( ((IQ) packet).getChildElement().createCopy() );
                reply.setError( PacketError.Condition.feature_not_implemented );
                router.route( reply );
            }
            Log.debug( "Ignoring stanza addressed at conference service: {}", packet.toXML() );
        }
        else
        {
            Log.trace( "The stanza is a normal packet that should possibly be sent to the room." );
            final JID recipient = packet.getTo();
            final String roomName = recipient != null ? recipient.getNode() : null;
            final JID userJid = packet.getFrom();
            Log.trace( "Stanza recipient: {}, room name: {}, sender: {}", recipient, roomName, userJid );
            try (final AutoCloseableReentrantLock.AutoCloseableLock ignored = new AutoCloseableReentrantLock(MultiUserChatServiceImpl.class, userJid.toString()).lock()) {
                if ( !packet.getElement().elements(FMUCHandler.FMUC).isEmpty() ) {
                    Log.trace( "Stanza is a FMUC stanza." );
                    final MUCRoom chatRoom = getChatRoom(roomName);
                    if ( chatRoom != null ) {
                        chatRoom.getFmucHandler().process(packet);
                    } else {
                        Log.warn( "Unable to process FMUC stanza, as room it's addressed to does not exist: {}", roomName );
                        // FIXME need to send error back in case of IQ request, and FMUC join. Might want to send error back in other cases too.
                    }
                } else {
                    Log.trace( "Stanza is a regular MUC stanza." );
                    getChatUser(userJid, roomName).process(packet);
                }
            }
        }
    }
    catch (final Exception e) {
        Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
    }
}