Java Code Examples for org.xmpp.packet.Packet#getTo()

The following examples show how to use org.xmpp.packet.Packet#getTo() . 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: TransportHandler.java    From Openfire with Apache License 2.0 6 votes vote down vote up
@Override
public void process(Packet packet) throws UnauthorizedException, PacketException {
    boolean handled = false;
    String host = packet.getTo().getDomain();
    for (Channel<Packet> channel : transports.values()) {
        if (channel.getName().equalsIgnoreCase(host)) {
            channel.add(packet);
            handled = true;
        }
    }
    if (!handled) {
        JID recipient = packet.getTo();
        JID sender = packet.getFrom();
        packet.setError(PacketError.Condition.remote_server_timeout);
        packet.setFrom(recipient);
        packet.setTo(sender);
        try {
            deliverer.deliver(packet);
        }
        catch (PacketException e) {
            Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
        }
    }
}
 
Example 2
Source File: AuditManagerImpl.java    From Openfire with Apache License 2.0 5 votes vote down vote up
@Override
public void interceptPacket(Packet packet, Session session, boolean read, boolean processed) {
    if (!processed) {
        // Ignore packets sent or received by users that are present in the ignore list
        JID from = packet.getFrom();
        JID to = packet.getTo();
        if ((from == null || !ignoreList.contains(from.getNode())) &&
                (to == null || !ignoreList.contains(to.getNode()))) {
            auditor.audit(packet, session);
        }
    }
}
 
Example 3
Source File: SocketPacketWriteHandler.java    From Openfire with Apache License 2.0 5 votes vote down vote up
@Override
 public void process(Packet packet) throws UnauthorizedException, PacketException {
    try {
        JID recipient = packet.getTo();
        // Check if the target domain belongs to a remote server or a component
        if (server.matchesComponent(recipient) || server.isRemote(recipient)) {
            routingTable.routePacket(recipient, packet, false);
        }
        // The target domain belongs to the local server
        else if (recipient == null || (recipient.getNode() == null && recipient.getResource() == null)) {
            // no TO was found so send back the packet to the sender
            routingTable.routePacket(packet.getFrom(), packet, false);
        }
        else if (recipient.getResource() != null || !(packet instanceof Presence)) {
            // JID is of the form <user@domain/resource>
            routingTable.routePacket(recipient, packet, false);
        }
        else {
            // JID is of the form <user@domain>
            for (JID route : routingTable.getRoutes(recipient, null)) {
                routingTable.routePacket(route, packet, false);
            }
        }
    }
    catch (Exception e) {
        Log.error(LocaleUtils.getLocalizedString("admin.error.deliver") + "\n" + packet.toString(), e);
    }
}
 
Example 4
Source File: S2STestService.java    From Openfire with Apache License 2.0 5 votes vote down vote up
/**
 * Keeps a log of the XMPP traffic, releasing the wait lock on response received.
 */
@Override
public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed)
        throws PacketRejectedException {

    if (ping.getTo() == null || packet.getFrom() == null || packet.getTo() == null) {
        return;
    }

    if (!processed
            && (ping.getTo().getDomain().equals(packet.getFrom().getDomain()) || ping.getTo().getDomain().equals(packet.getTo().getDomain()))) {

        // Log all traffic to and from the domain.
        xml.append(packet.toXML());
        xml.append('\n');

        // If we've received our IQ response, stop the test.
        if ( packet instanceof IQ )
        {
            final IQ iq = (IQ) packet;
            if ( iq.isResponse() && ping.getID().equals( iq.getID() ) && ping.getTo().equals( iq.getFrom() ) ) {
                Log.info("Successful server to server response received.");
                waitUntil.release();
            }
        }
    }
}
 
Example 5
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);
    }
}
 
Example 6
Source File: PresenceUpdateHandler.java    From Openfire with Apache License 2.0 2 votes vote down vote up
/**
 * Checks if the packet is a presence stanza that intends to reflect an update back to the client from which the update originated.
 *
 * @param packet The stanza (cannot be null.
 * @return true if the packet is presence reflection, otherwise false.
 */
public static boolean isPresenceUpdateReflection( final Packet packet ) {
    return packet instanceof Presence && packet.getTo() != null && packet.getTo().equals( packet.getFrom() );
}