Example usage for org.dom4j Element getNamespaceURI

List of usage examples for org.dom4j Element getNamespaceURI

Introduction

In this page you can find the example usage for org.dom4j Element getNamespaceURI.

Prototype

String getNamespaceURI();

Source Link

Document

Returns the URI mapped to the namespace of this element if one exists otherwise an empty String is returned.

Usage

From source file:org.jivesoftware.openfire.IQRouter.java

License:Open Source License

/**
 * <p>Performs the actual packet routing.</p>
 * <p>You routing is considered 'quick' and implementations may not take
 * excessive amounts of time to complete the routing. If routing will take
 * a long amount of time, the actual routing should be done in another thread
 * so this method returns quickly.</p>
 * <h2>Warning</h2>/*from   w  w w  . j a v a  2 s . c  o  m*/
 * <p>Be careful to enforce concurrency DbC of concurrent by synchronizing
 * any accesses to class resources.</p>
 *
 * @param packet The packet to route
 * @throws NullPointerException If the packet is null
 */
public void route(IQ packet) {
    if (packet == null) {
        throw new NullPointerException();
    }
    JID sender = packet.getFrom();
    ClientSession session = sessionManager.getSession(sender);
    Element childElement = packet.getChildElement(); // may be null
    try {
        // Invoke the interceptors before we process the read packet
        InterceptorManager.getInstance().invokeInterceptors(packet, session, true, false);
        JID to = packet.getTo();
        if (session != null && to != null && session.getStatus() == Session.STATUS_CONNECTED
                && !serverName.equals(to.toString())) {
            // User is requesting this server to authenticate for another server. Return
            // a bad-request error
            IQ reply = IQ.createResultIQ(packet);
            if (childElement != null) {
                reply.setChildElement(childElement.createCopy());
            }
            reply.setError(PacketError.Condition.bad_request);
            session.process(reply);
            Log.warn("User tried to authenticate with this server using an unknown receipient: "
                    + packet.toXML());
        } else if (session == null || session.getStatus() == Session.STATUS_AUTHENTICATED
                || (childElement != null && isLocalServer(to)
                        && ("jabber:iq:auth".equals(childElement.getNamespaceURI())
                                || "jabber:iq:register".equals(childElement.getNamespaceURI())
                                || "urn:ietf:params:xml:ns:xmpp-bind"
                                        .equals(childElement.getNamespaceURI())))) {
            handle(packet);
        } else if (packet.getType() == IQ.Type.get || packet.getType() == IQ.Type.set) {
            IQ reply = IQ.createResultIQ(packet);
            if (childElement != null) {
                reply.setChildElement(childElement.createCopy());
            }
            reply.setError(PacketError.Condition.not_authorized);
            session.process(reply);
        }
        // Invoke the interceptors after we have processed the read packet
        InterceptorManager.getInstance().invokeInterceptors(packet, session, true, true);
    } catch (PacketRejectedException e) {
        if (session != null) {
            // An interceptor rejected this packet so answer a not_allowed error
            IQ reply = new IQ();
            if (childElement != null) {
                reply.setChildElement(childElement.createCopy());
            }
            reply.setID(packet.getID());
            reply.setTo(session.getAddress());
            reply.setFrom(packet.getTo());
            reply.setError(PacketError.Condition.not_allowed);
            session.process(reply);
            // Check if a message notifying the rejection should be sent
            if (e.getRejectionMessage() != null && e.getRejectionMessage().trim().length() > 0) {
                // A message for the rejection will be sent to the sender of the rejected packet
                Message notification = new Message();
                notification.setTo(session.getAddress());
                notification.setFrom(packet.getTo());
                notification.setBody(e.getRejectionMessage());
                session.process(notification);
            }
        }
    }
}

From source file:org.jivesoftware.openfire.IQRouter.java

License:Open Source License

private void handle(IQ packet) {
    JID recipientJID = packet.getTo();//from  w  ww  .  ja v  a 2 s. c  om
    // Check if the packet was sent to the server hostname
    if (recipientJID != null && recipientJID.getNode() == null && recipientJID.getResource() == null
            && serverName.equals(recipientJID.getDomain())) {
        Element childElement = packet.getChildElement();
        if (childElement != null && childElement.element("addresses") != null) {
            // Packet includes multicast processing instructions. Ask the multicastRouter
            // to route this packet
            multicastRouter.route(packet);
            return;
        }
    }
    if (packet.getID() != null && (IQ.Type.result == packet.getType() || IQ.Type.error == packet.getType())) {
        // The server got an answer to an IQ packet that was sent from the server
        IQResultListener iqResultListener = resultListeners.remove(packet.getID());
        if (iqResultListener != null) {
            resultTimeout.remove(packet.getID());
            if (iqResultListener != null) {
                try {
                    iqResultListener.receivedAnswer(packet);
                } catch (Exception e) {
                    Log.error("Error processing answer of remote entity. Answer: " + packet.toXML(), e);
                }
                return;
            }
        }
    }
    try {
        // Check for registered components, services or remote servers
        if (recipientJID != null && (routingTable.hasComponentRoute(recipientJID)
                || routingTable.hasServerRoute(recipientJID))) {
            // A component/service/remote server was found that can handle the Packet
            routingTable.routePacket(recipientJID, packet, false);
            return;
        }

        if (isLocalServer(recipientJID)) {
            // Let the server handle the Packet
            Element childElement = packet.getChildElement();
            String namespace = null;
            if (childElement != null) {
                namespace = childElement.getNamespaceURI();
            }
            if (namespace == null) {
                if (packet.getType() != IQ.Type.result && packet.getType() != IQ.Type.error) {
                    // Do nothing. We can't handle queries outside of a valid namespace
                    Log.warn("Unknown packet " + packet.toXML());
                }
            } else {
                // Check if communication to local users is allowed
                if (recipientJID != null && userManager.isRegisteredUser(recipientJID.getNode())) {
                    PrivacyList list = PrivacyListManager.getInstance()
                            .getDefaultPrivacyList(recipientJID.getNode());
                    if (list != null && list.shouldBlockPacket(packet)) {
                        // Communication is blocked
                        if (IQ.Type.set == packet.getType() || IQ.Type.get == packet.getType()) {
                            // Answer that the service is unavailable
                            sendErrorPacket(packet, PacketError.Condition.service_unavailable);
                        }
                        return;
                    }
                }
                IQHandler handler = getHandler(namespace);
                if (handler == null) {
                    if (recipientJID == null) {
                        // Answer an error since the server can't handle the requested namespace
                        sendErrorPacket(packet, PacketError.Condition.service_unavailable);
                    } else if (recipientJID.getNode() == null || "".equals(recipientJID.getNode())) {
                        // Answer an error if JID is of the form <domain>
                        sendErrorPacket(packet, PacketError.Condition.feature_not_implemented);
                    } else {
                        // JID is of the form <node@domain>
                        // Answer an error since the server can't handle packets sent to a node
                        sendErrorPacket(packet, PacketError.Condition.service_unavailable);
                    }
                } else {
                    handler.process(packet);
                }
            }
        } else {

            // RFC 6121 8.5.1.  No Such User http://xmpp.org/rfcs/rfc6121.html#rules-localpart-nosuchuser
            // If the 'to' address specifies a bare JID <localpart@domainpart> or full JID <localpart@domainpart/resourcepart> where the domainpart of the JID matches a configured domain that is serviced by the server itself, the server MUST proceed as follows.
            // If the user account identified by the 'to' attribute does not exist, how the stanza is processed depends on the stanza type.
            if (recipientJID != null && recipientJID.getNode() != null
                    && serverName.equals(recipientJID.getDomain())
                    && !userManager.isRegisteredUser(recipientJID.getNode())
                    && sessionManager.getSession(recipientJID) == null
                    && (IQ.Type.set == packet.getType() || IQ.Type.get == packet.getType())) {
                // For an IQ stanza, the server MUST return a <service-unavailable/> stanza error to the sender.
                sendErrorPacket(packet, PacketError.Condition.service_unavailable);
                return;
            }

            ClientSession session = sessionManager.getSession(packet.getFrom());
            boolean isAcceptable = true;
            if (session instanceof LocalClientSession) {
                // Check if we could process IQ stanzas from the recipient.
                // If not, return a not-acceptable error as per XEP-0016:
                // If the user attempts to send an outbound stanza to a contact and that stanza type is blocked, the user's server MUST NOT route the stanza to the contact but instead MUST return a <not-acceptable/> error
                IQ dummyIQ = packet.createCopy();
                dummyIQ.setFrom(packet.getTo());
                dummyIQ.setTo(packet.getFrom());
                if (!((LocalClientSession) session).canProcess(dummyIQ)) {
                    packet.setTo(session.getAddress());
                    packet.setFrom((JID) null);
                    packet.setError(PacketError.Condition.not_acceptable);
                    session.process(packet);
                    isAcceptable = false;
                }
            }

            if (isAcceptable) {
                // JID is of the form <node@domain/resource> or belongs to a remote server
                // or to an uninstalled component
                routingTable.routePacket(recipientJID, packet, false);
            }
        }
    } catch (Exception e) {
        Log.error(LocaleUtils.getLocalizedString("admin.error.routing"), e);
        Session session = sessionManager.getSession(packet.getFrom());
        if (session != null) {
            IQ reply = IQ.createResultIQ(packet);
            reply.setError(PacketError.Condition.internal_server_error);
            session.process(reply);
        }
    }
}

From source file:org.jivesoftware.openfire.mediaproxy.MediaProxyService.java

License:Open Source License

private void processIQ(IQ iq) {
    IQ reply = IQ.createResultIQ(iq);/* ww w  .j  av  a  2s  . c o m*/
    Element childElement = iq.getChildElement();
    String namespace = childElement.getNamespaceURI();
    Element childElementCopy = iq.getChildElement().createCopy();
    reply.setChildElement(childElementCopy);

    if ("http://jabber.org/protocol/disco#info".equals(namespace)) {
        reply = XMPPServer.getInstance().getIQDiscoInfoHandler().handleIQ(iq);
        router.route(reply);
        return;
    } else if ("http://jabber.org/protocol/disco#items".equals(namespace)) {
        // a component
        reply = XMPPServer.getInstance().getIQDiscoItemsHandler().handleIQ(iq);
        router.route(reply);
        return;
    } else if (NAMESPACE.equals(namespace) && enabled) {

        Element candidateElement = childElementCopy.element("candidate");
        String sid = childElementCopy.attribute("sid").getValue() + "-" + iq.getFrom();

        if (candidateElement != null) {
            childElementCopy.remove(candidateElement);
            Element candidate = childElementCopy.addElement("candidate ");
            ProxyCandidate proxyCandidate = mediaProxy.addRelayAgent(sid, iq.getFrom().toString());
            Log.debug("MediaProxyService: " + sid);
            proxyCandidate.start();
            candidate.addAttribute("name", "voicechannel");
            candidate.addAttribute("ip", mediaProxy.getPublicIP());
            candidate.addAttribute("porta", String.valueOf(proxyCandidate.getLocalPortA()));
            candidate.addAttribute("portb", String.valueOf(proxyCandidate.getLocalPortB()));
            candidate.addAttribute("pass", proxyCandidate.getPass());

        } else {
            candidateElement = childElementCopy.element("relay");
            if (candidateElement != null) {
                MediaProxySession session = mediaProxy.getSession(sid);
                Log.debug("MediaProxyService: " + sid);
                if (session != null) {
                    Attribute pass = candidateElement.attribute("pass");

                    if (pass != null && pass.getValue().trim().equals(session.getPass().trim())) {
                        Attribute portA = candidateElement.attribute("porta");
                        Attribute portB = candidateElement.attribute("portb");
                        Attribute hostA = candidateElement.attribute("hosta");
                        Attribute hostB = candidateElement.attribute("hostb");

                        try {
                            if (hostA != null && portA != null) {
                                for (int i = 0; i < 2; i++) {
                                    session.sendFromPortA(hostB.getValue(), Integer.parseInt(portB.getValue()));
                                }
                            }
                        } catch (Exception e) {
                            Log.error(e.getMessage(), e);
                        }

                    } else {
                        reply.setError(PacketError.Condition.forbidden);
                    }
                }
                childElementCopy.remove(candidateElement);
            } else {
                candidateElement = childElementCopy.element("publicip");
                if (candidateElement != null) {
                    childElementCopy.remove(candidateElement);
                    Element publicIp = childElementCopy.addElement("publicip");
                    try {
                        String ip = sessionManager.getSession(iq.getFrom()).getHostAddress();
                        if (ip != null) {
                            publicIp.addAttribute("ip", ip);
                        }
                    } catch (UnknownHostException e) {
                        Log.error(e.getMessage(), e);
                    }

                } else {
                    childElementCopy.remove(candidateElement);
                    reply.setError(PacketError.Condition.forbidden);
                }

            }
        }
    } else {
        // Answer an error since the server can't handle the requested namespace
        reply.setError(PacketError.Condition.service_unavailable);
    }

    try {
        if (Log.isDebugEnabled()) {
            Log.debug("MediaProxyService: RETURNED:" + reply.toXML());
        }
        router.route(reply);
    } catch (Exception e) {
        Log.error(e.getMessage(), e);
    }
}

From source file:org.jivesoftware.openfire.muc.spi.LocalMUCUser.java

License:Open Source License

public void process(IQ packet) {
    lastPacketTime = System.currentTimeMillis();
    JID recipient = packet.getTo();//from ww  w  .  j a  v  a 2s  .c  om
    String group = recipient.getNode();
    if (group == null) {
        // Ignore packets to the groupchat server
        // In the future, we'll need to support TYPE_IQ queries to the server for MUC
        Log.info(LocaleUtils.getLocalizedString("muc.error.not-supported") + " " + packet.toString());
    } else {
        MUCRole role = roles.get(group);
        if (role == null) {
            // If a non-occupant sends a disco to an address of the form <room@service/nick>,
            // a MUC service MUST return a <bad-request/> error.
            // http://xmpp.org/extensions/xep-0045.html#disco-occupant
            sendErrorPacket(packet, PacketError.Condition.bad_request);
        } else if (IQ.Type.result == packet.getType() || IQ.Type.error == packet.getType()) {
            // Only process IQ result packet if it's a private packet sent to another
            // room occupant
            if (packet.getTo().getResource() != null) {
                try {
                    // User is sending an IQ result packet to another room occupant
                    role.getChatRoom().sendPrivatePacket(packet, role);
                } catch (NotFoundException e) {
                    // Do nothing. No error will be sent to the sender of the IQ result packet
                }
            }
        } else {
            // Check and reject conflicting packets with conflicting roles
            // In other words, another user already has this nickname
            if (!role.getUserAddress().equals(packet.getFrom())) {
                sendErrorPacket(packet, PacketError.Condition.conflict);
            } else {
                try {
                    Element query = packet.getElement().element("query");
                    if (query != null
                            && "http://jabber.org/protocol/muc#owner".equals(query.getNamespaceURI())) {
                        role.getChatRoom().getIQOwnerHandler().handleIQ(packet, role);
                    } else if (query != null
                            && "http://jabber.org/protocol/muc#admin".equals(query.getNamespaceURI())) {
                        role.getChatRoom().getIQAdminHandler().handleIQ(packet, role);
                    } else {
                        if (packet.getTo().getResource() != null) {
                            // User is sending an IQ packet to another room occupant
                            role.getChatRoom().sendPrivatePacket(packet, role);
                        } else {
                            sendErrorPacket(packet, PacketError.Condition.bad_request);
                        }
                    }
                } catch (ForbiddenException e) {
                    sendErrorPacket(packet, PacketError.Condition.forbidden);
                } catch (NotFoundException e) {
                    sendErrorPacket(packet, PacketError.Condition.recipient_unavailable);
                } catch (ConflictException e) {
                    sendErrorPacket(packet, PacketError.Condition.conflict);
                } catch (NotAllowedException e) {
                    sendErrorPacket(packet, PacketError.Condition.not_allowed);
                } catch (CannotBeInvitedException e) {
                    sendErrorPacket(packet, PacketError.Condition.not_acceptable);
                } catch (Exception e) {
                    sendErrorPacket(packet, PacketError.Condition.internal_server_error);
                    Log.error(e.getMessage(), e);
                }
            }
        }
    }
}

From source file:org.jivesoftware.openfire.OfflineMessageStore.java

License:Open Source License

/**
 * Decide whether a message should be stored offline according to XEP-0160 and XEP-0334.
 *
 * @param message//from   w w  w.jav a 2s . c om
 * @return <code>true</code> if the message should be stored offline, <code>false</code> otherwise.
 */
static boolean shouldStoreMessage(final Message message) {
    // XEP-0334: Implement the <no-store/> hint to override offline storage
    if (message.getChildElement("no-store", "urn:xmpp:hints") != null) {
        return false;
    }

    switch (message.getType()) {
    case chat:
        // XEP-0160: Messages with a 'type' attribute whose value is "chat" SHOULD be stored offline, with the exception of messages that contain only Chat State Notifications (XEP-0085) [7] content

        // Iterate through the child elements to see if we can find anything that's not a chat state notification or
        // real time text notification
        Iterator<?> it = message.getElement().elementIterator();

        while (it.hasNext()) {
            Object item = it.next();

            if (item instanceof Element) {
                Element el = (Element) item;

                if (!el.getNamespaceURI().equals("http://jabber.org/protocol/chatstates")
                        && !(el.getQName().equals(QName.get("rtt", "urn:xmpp:rtt:0")))) {
                    return true;
                }
            }
        }

        return false;

    case groupchat:
    case headline:
        // XEP-0160: "groupchat" message types SHOULD NOT be stored offline
        // XEP-0160: "headline" message types SHOULD NOT be stored offline
        return false;

    case error:
        // XEP-0160: "error" message types SHOULD NOT be stored offline,
        // although a server MAY store advanced message processing errors offline
        if (message.getChildElement("amp", "http://jabber.org/protocol/amp") == null) {
            return false;
        }
        break;

    default:
        // XEP-0160: Messages with a 'type' attribute whose value is "normal" (or messages with no 'type' attribute) SHOULD be stored offline.
        break;
    }
    return true;
}

From source file:org.jivesoftware.openfire.plugin.BroadcastPlugin.java

License:Open Source License

private void processIQ(IQ iq, boolean targetAll, Group group, boolean canProceed) {
    IQ reply = IQ.createResultIQ(iq);//  w  ww .j a  v  a  2s .c  o m
    Element childElement = iq.getChildElement();
    String namespace = childElement.getNamespaceURI();
    Element childElementCopy = iq.getChildElement().createCopy();
    reply.setChildElement(childElementCopy);
    if ("http://jabber.org/protocol/disco#info".equals(namespace)) {
        if (iq.getTo().getNode() == null) {
            // Return service identity and features
            Element identity = childElementCopy.addElement("identity");
            identity.addAttribute("category", "component");
            identity.addAttribute("type", "generic");
            identity.addAttribute("name", "Broadcast service");
            childElementCopy.addElement("feature").addAttribute("var", "http://jabber.org/protocol/disco#info");
            childElementCopy.addElement("feature").addAttribute("var",
                    "http://jabber.org/protocol/disco#items");
        } else {
            if (targetAll) {
                // Return identity and features of the "all" group
                Element identity = childElementCopy.addElement("identity");
                identity.addAttribute("category", "component");
                identity.addAttribute("type", "generic");
                identity.addAttribute("name", "Broadcast all connected users");
                childElementCopy.addElement("feature").addAttribute("var",
                        "http://jabber.org/protocol/disco#info");
            } else if (group != null && canProceed) {
                // Return identity and features of the "all" group
                Element identity = childElementCopy.addElement("identity");
                identity.addAttribute("category", "component");
                identity.addAttribute("type", "generic");
                identity.addAttribute("name", "Broadcast " + group.getName());
                childElementCopy.addElement("feature").addAttribute("var",
                        "http://jabber.org/protocol/disco#info");
            } else {
                // Group not found or not allowed to use that group so
                // answer item_not_found error
                reply.setError(PacketError.Condition.item_not_found);
            }
        }
    } else if ("http://jabber.org/protocol/disco#items".equals(namespace)) {
        if (iq.getTo().getNode() == null) {
            // Return the list of groups hosted by the service that can be used by the user
            Collection<Group> groups;
            JID address = new JID(iq.getFrom().toBareJID());
            if (allowedUsers.contains(address)) {
                groups = groupManager.getGroups();
            } else {
                groups = groupManager.getGroups(iq.getFrom());
            }
            for (Group userGroup : groups) {
                try {
                    JID groupJID = new JID(
                            userGroup.getName() + "@" + serviceName + "." + componentManager.getServerName());
                    childElementCopy.addElement("item").addAttribute("jid", groupJID.toString());
                } catch (Exception e) {
                    // Group name is not valid to be used as a JID
                }
            }
            if (allowedUsers.isEmpty() || allowedUsers.contains(address)) {
                // Add the "all" group to the list
                childElementCopy.addElement("item").addAttribute("jid",
                        "all@" + serviceName + "." + componentManager.getServerName());
            }
        }
    } else {
        // Answer an error since the server can't handle the requested namespace
        reply.setError(PacketError.Condition.service_unavailable);
    }
    try {
        componentManager.sendPacket(this, reply);
    } catch (Exception e) {
        Log.error(e.getMessage(), e);
    }
}

From source file:org.jivesoftware.openfire.plugin.SearchPlugin.java

License:Open Source License

/**
 * Handles IQ requests. This method throws an IllegalArgumentException if an IQ stanza is supplied that is not a request (if the stanza
 * is not of type 'get' or 'set'). This method will either throw an Exception, or return a non-null IQ stanza of type 'error' or
 * 'result', as XMPP Core specifies that <strong>all</strong> IQ request stanza's (type 'get' or 'set') MUST be replied to.
 * //from w  w w.  j av a 2  s  .  c om
 * @param iq
 *            The IQ stanza that forms the request.
 * @return The response to the request.
 */
private IQ handleIQRequest(IQ iq) {
    final IQ replyPacket; // 'final' to ensure that it is set.

    if (iq == null) {
        throw new IllegalArgumentException("Argument 'iq' cannot be null.");
    }

    final IQ.Type type = iq.getType();
    if (type != IQ.Type.get && type != IQ.Type.set) {
        throw new IllegalArgumentException("Argument 'iq' must be of type 'get' or 'set'");
    }

    final Element childElement = iq.getChildElement();
    if (childElement == null) {
        replyPacket = IQ.createResultIQ(iq);
        replyPacket.setError(new PacketError(Condition.bad_request, org.xmpp.packet.PacketError.Type.modify,
                "IQ stanzas of type 'get' and 'set' MUST contain one and only one child element (RFC 3920 section 9.2.3)."));
        return replyPacket;
    }

    final String namespace = childElement.getNamespaceURI();
    if (namespace == null) {
        replyPacket = IQ.createResultIQ(iq);
        replyPacket.setError(Condition.feature_not_implemented);
        return replyPacket;
    }

    if (namespace.equals(NAMESPACE_JABBER_IQ_SEARCH)) {
        replyPacket = handleSearchRequest(iq);
    } else if (namespace.equals(IQDiscoInfoHandler.NAMESPACE_DISCO_INFO)) {
        replyPacket = handleDiscoInfo(iq);
    } else if (namespace.equals(IQDiscoItemsHandler.NAMESPACE_DISCO_ITEMS)) {
        replyPacket = IQ.createResultIQ(iq);
        replyPacket.setChildElement("query", IQDiscoItemsHandler.NAMESPACE_DISCO_ITEMS);
    } else {
        // don't known what to do with this.
        replyPacket = IQ.createResultIQ(iq);
        replyPacket.setError(Condition.feature_not_implemented);
    }

    return replyPacket;
}

From source file:org.jivesoftware.openfire.plugin.SearchPlugin.java

License:Open Source License

/**
 * This method checks if the search request that was received is a valid JABBER:IQ:SEARCH request. In other words, it checks if the
 * search request is spec compliant (XEP-0055). It does this by checking:
 * <ul>/*from   w w  w .j  a  v a2 s . c  om*/
 * <li>if the IQ stanza is of type 'set';</li>
 * <li>if a child element identified by the jabber:iq:search namespace is supplied;</li>
 * <li>if the stanza child element is has valid children itself.</li>
 * </ul>
 * 
 * @param iq
 *            The IQ object that should include a jabber:iq:search request.
 * @return ''true'' if the supplied IQ stanza is a spec compliant search request, ''false'' otherwise.
 */
@SuppressWarnings("unchecked")
public static boolean isValidSearchRequest(IQ iq) {

    if (iq == null) {
        throw new IllegalArgumentException("Argument 'iq' cannot be null.");
    }

    if (iq.getType() != IQ.Type.set) {
        return false;
    }

    final Element childElement = iq.getChildElement();
    if (childElement == null) {
        return false;
    }

    if (!childElement.getNamespaceURI().equals(NAMESPACE_JABBER_IQ_SEARCH)) {
        return false;
    }

    if (!childElement.getName().equals("query")) {
        return false;
    }

    final List<Element> fields = childElement.elements();
    if (fields.size() == 0) {
        return false;
    }

    for (Element element : fields) {
        final String name = element.getName();
        if (!validSearchRequestFields.contains(name)) {
            return false;
        }

        // TODO: check dataform validity.
        // if (name.equals("x") && !isValidDataForm(element))
        // {
        // return false;
        // }

        if (name.equals("set") && !ResultSet.isValidRSMRequest(element)) {
            return false;
        }
    }

    return true;
}

From source file:org.jivesoftware.openfire.plugin.spark.BookmarkInterceptor.java

License:Open Source License

public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed)
        throws PacketRejectedException {
    if (!processed && packet instanceof IQ && !incoming) {

        // Check for the Bookmark Storage element and hand off to the Bookmark engine.
        IQ iq = (IQ) packet;/*ww  w  . ja v a2s . c  om*/
        Element childElement = iq.getChildElement();
        if (childElement == null || iq.getType() != IQ.Type.result) {
            return;
        }

        String namespace = childElement.getNamespaceURI();
        if ("jabber:iq:private".equals(namespace)) {
            // In private data, when a user is attempting to retrieve bookmark
            // information, there will be a storage:bookmarks namespace.
            Element storageElement = childElement.element("storage");
            if (storageElement == null) {
                return;
            }

            namespace = storageElement.getNamespaceURI();
            if ("storage:bookmarks".equals(namespace)) {
                // Append Server defined bookmarks for user.
                JID toJID = iq.getTo();
                addBookmarks(toJID, storageElement);
            }
        }
    }
}

From source file:org.jivesoftware.openfire.plugin.spark.manager.SparkVersionManager.java

License:Open Source License

public void processPacket(Packet packet) {
    if (packet instanceof IQ) {
        IQ iqPacket = (IQ) packet;//from  w  w  w .j  a va2  s .c om

        if (IQ.Type.get == iqPacket.getType()) {
            Element childElement = (iqPacket).getChildElement();
            String namespace = null;
            if (childElement != null) {
                namespace = childElement.getNamespaceURI();
            }

            // Handle any disco info requests.
            if ("http://jabber.org/protocol/disco#info".equals(namespace)) {
                handleDiscoInfo(iqPacket);
            }

            // Handle any disco item requests.
            else if ("http://jabber.org/protocol/disco#items".equals(namespace)) {
                handleDiscoItems(iqPacket);
            }
            // Handle a jabber spark request.
            else if ("jabber:iq:spark".equals(namespace)) {
                handleSparkIQ(iqPacket);
            }
        } else if (IQ.Type.error == iqPacket.getType() || IQ.Type.result == iqPacket.getType()) {
            // Ignore these packets
        } else {
            // Return error since this is an unknown service request
            IQ reply = IQ.createResultIQ(iqPacket);
            reply.setError(PacketError.Condition.service_unavailable);
            sendPacket(reply);
        }
    }
}