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

The following examples show how to use org.xmpp.packet.IQ#getType() . 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: LocalComponentSession.java    From Openfire with Apache License 2.0 6 votes vote down vote up
@Override
public void processPacket(Packet packet) {
    if (packet instanceof IQ) {
        IQ iq = (IQ) packet;
        if (iq.getType() == IQ.Type.result || iq.getType() == IQ.Type.error) {
            // Check if this IQ reply belongs to a specific component and route
            // reply to that specific component (if it exists)
            LocalExternalComponent targetComponent;
            synchronized (iqs) {
                targetComponent = iqs.remove(packet.getID());
            }
            if (targetComponent != null) {
                targetComponent.processPacket(packet);
                return;
            }
        }
    }
    // Ask the session to process the outgoing packet. This will
    // give us the chance to apply PacketInterceptors
    session.process(packet);
}
 
Example 2
Source File: ComponentStanzaHandler.java    From Openfire with Apache License 2.0 6 votes vote down vote up
@Override
protected void processIQ(IQ packet) throws UnauthorizedException {
    if (session.getStatus() != Session.STATUS_AUTHENTICATED) {
        // Session is not authenticated so return error
        IQ reply = new IQ();
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setID(packet.getID());
        reply.setTo(packet.getFrom());
        reply.setFrom(packet.getTo());
        reply.setError(PacketError.Condition.not_authorized);
        session.process(reply);
        return;
    }
    // Keep track of the component that sent an IQ get/set
    if (packet.getType() == IQ.Type.get || packet.getType() == IQ.Type.set) {
        // Handle subsequent bind packets
        LocalComponentSession componentSession = (LocalComponentSession) session;
        // Get the external component of this session
        LocalComponentSession.LocalExternalComponent component =
                (LocalComponentSession.LocalExternalComponent) componentSession.getExternalComponent();
        component.track(packet);
    }
    super.processIQ(packet);
}
 
Example 3
Source File: BookmarkInterceptor.java    From openfire-ofmeet-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * XEP-0048 'Bookmarks' describes a storage element that contains the list of bookmarks that we intend to
 * add to in this method. Such a storage element can be transmitted in a number of different ways, including
 * XEP-0049 "Private XML Storage" and XEP-0223 "Persistent Storage of Private Data via PubSub".
 *
 * @param packet The packet in which to search for a 'storage' element (cannot be null).
 * @return The storage element, or null when no such element was found.
 */
static Element findStorageElement( final Packet packet )
{
    if ( packet instanceof IQ )
    {
        final IQ iq = (IQ) packet;
        final Element childElement = iq.getChildElement();
        if ( childElement == null || iq.getType() != IQ.Type.result )
        {
            return null;
        }

        switch ( childElement.getNamespaceURI() )
        {
            // A "Private XML Storage (XEP-0049) Bookmarks" result stanza.
            case "jabber:iq:private":
                return findStorageElementInPrivateXmlStorage( childElement );

            // a "Persistent Storage of Private Data via PubSub (XEP-0048 / XEP-0223)" Bookmarks result.
            case "http://jabber.org/protocol/pubsub":
                return findStorageElementInPubsub( childElement );

            default:
                return null;
        }
    }

    if ( packet instanceof Message )
    {
        final Message message = (Message) packet;

        // Check for a "Persistent Storage of Private Data via PubSub (XEP-0048 / XEP-0223)" Bookmarks event notification.
        return findStorageElementInPubsub( message.getChildElement( "event", "http://jabber.org/protocol/pubsub#event" ) );
    }

    return null;
}
 
Example 4
Source File: SipComponent.java    From openfire-ofmeet-plugin with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example 5
Source File: EntityCapabilitiesManager.java    From Openfire with Apache License 2.0 5 votes vote down vote up
/**
 * Determines whether or not the packet received from a disco#info result
 * was valid by comparing its 'ver' hash (identites+features encapsulated
 * hash) with the 'ver' hash of the original caps packet that the
 * disco#info query was sent on behalf of.
 * 
 * @param packet the disco#info result packet.
 * @return true if the packet's generated 'ver' hash matches the 'ver'
 *         hash of the original caps packet.
 */
private boolean isValid(IQ packet) {
    if (packet.getType() != IQ.Type.result)
        return false;

    final EntityCapabilities original = verAttributes.get(packet.getID());
    if (original == null) {
        return false;
    }
    final String newVerHash = generateVerHash(packet, original.getHashAttribute());

    return newVerHash.equals(original.getVerAttribute());
}
 
Example 6
Source File: EntityCapabilitiesManager.java    From Openfire with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the 'ver' hash for this server.
 *
 * @return A 'ver' hash, or null if none could be generated.
 */
public static String getLocalDomainVerHash()
{
    // TODO Cache results to increase performance.
    final IQ discoInfoRequest = new IQ( IQ.Type.get );
    discoInfoRequest.setChildElement( "query", "http://jabber.org/protocol/disco#info" );
    final IQ discoInfoResponse = XMPPServer.getInstance().getIQDiscoInfoHandler().handleIQ( discoInfoRequest );
    if ( discoInfoResponse.getType() == IQ.Type.result )
    {
        return EntityCapabilitiesManager.generateVerHash( discoInfoResponse, "SHA-1" );
    }
    return null;
}
 
Example 7
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 8
Source File: MediaProxyService.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 user is allowed to send packet to this service
    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);
    }
}