Package org.xmpp.packet

Examples of org.xmpp.packet.IQ


        // Notify the new listener about existing components
        for (String domain : routingTable.getComponentsDomains()) {
            JID componentJID = new JID(domain);
            listener.componentRegistered(componentJID);
            // Check if there is disco#info stored for the component
            IQ disco = componentInfo.get(domain);
            if (disco != null) {
                listener.componentInfoReceived(disco);
            }
        }
    }
View Full Code Here


     * @param component the new component that was added to this manager.
     * @param componentJID the XMPP address of the new component.
     */
    private void checkDiscoSupport(Component component, JID componentJID) {
        // Build a disco#info request that will be sent to the component
        IQ iq = new IQ(IQ.Type.get);
        iq.setFrom(getAddress());
        iq.setTo(componentJID);
        iq.setChildElement("query", "http://jabber.org/protocol/disco#info");
        // Send the disco#info request to the component. The reply (if any) will be processed in
        // #process(Packet)
//        sendPacket(component, iq);
        component.processPacket(iq);
    }
View Full Code Here

    public void process(Packet packet) throws PacketException {
        List<Component> components = getComponents(packet.getFrom());
        // Only process packets that were sent by registered components
        if (!components.isEmpty()) {
            if (packet instanceof IQ && IQ.Type.result == ((IQ) packet).getType()) {
                IQ iq = (IQ) packet;
                Element childElement = iq.getChildElement();
                if (childElement != null) {
                    String namespace = childElement.getNamespaceURI();
                    if ("http://jabber.org/protocol/disco#info".equals(namespace)) {
                        // Add a disco item to the server for the component that supports disco
                        Element identity = childElement.element("identity");
View Full Code Here

   */
    @Override
    public IQ handleIQ(IQ packet) throws UnauthorizedException {
        // 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;
        }

        final JID senderJID = packet.getFrom();
        if (packet.getTo() == null) {
          // packet addressed to service itself (not to a node/user)
         
            if (packet.getType() == IQ.Type.set) {
                final String jidFrom = senderJID.toBareJID();
                PEPService pepService = pepServiceManager.getPEPService(jidFrom);

                // If no service exists yet for jidFrom, create one.
                if (pepService == null) {
                  try {
                    pepService = pepServiceManager.create(senderJID);                   
                  } catch (IllegalArgumentException ex) {
                  final IQ reply = IQ.createResultIQ(packet);
                  reply.setChildElement(packet.getChildElement().createCopy());
                  reply.setError(PacketError.Condition.not_allowed);
                  return reply;
                  }

                // Probe presences
                pepServiceManager.start(pepService);

                // Those who already have presence subscriptions to jidFrom
          // will now automatically be subscribed to this new
          // PEPService.
          try {
            final RosterManager rm = XMPPServer.getInstance()
                .getRosterManager();
            final Roster roster = rm.getRoster(senderJID.getNode());
            for (final RosterItem item : roster.getRosterItems()) {
              if (item.getSubStatus() == RosterItem.SUB_BOTH
                  || item.getSubStatus() == RosterItem.SUB_FROM) {
                createSubscriptionToPEPService(pepService, item
                    .getJid(), senderJID);
              }
            }
          } catch (UserNotFoundException e) {
            // Do nothing
          }
                }

                // If publishing a node, and the node doesn't exist, create it.
                final Element childElement = packet.getChildElement();
                final Element publishElement = childElement.element("publish");
                if (publishElement != null) {
                    final String nodeID = publishElement.attributeValue("node");

                    // Do not allow User Avatar nodes to be created.
                    // TODO: Implement XEP-0084
                    if (nodeID.startsWith("http://www.xmpp.org/extensions/xep-0084.html")) {
                        IQ reply = IQ.createResultIQ(packet);
                        reply.setChildElement(packet.getChildElement().createCopy());
                        reply.setError(PacketError.Condition.feature_not_implemented);
                        return reply;
                    }

                    if (pepService.getNode(nodeID) == null) {
                        // Create the node
View Full Code Here

        //              </x>
        //           </options>
        //         </pubsub>
        //        </iq>

        IQ subscriptionPacket = new IQ(IQ.Type.set);
        subscriptionPacket.setFrom(subscriber);
        subscriptionPacket.setTo(owner.toBareJID());

        Element pubsubElement = subscriptionPacket.setChildElement("pubsub", "http://jabber.org/protocol/pubsub");

        Element subscribeElement = pubsubElement.addElement("subscribe");
        subscribeElement.addAttribute("jid", subscriber.toBareJID());

        Element optionsElement = pubsubElement.addElement("options");
View Full Code Here

                                    boolean processed)
                throws PacketRejectedException
        {
            // We only want packets recieved by the server
            if (!processed && incoming && packet instanceof IQ) {
                IQ iq = (IQ) packet;
                Element childElement = iq.getChildElement();
                if(childElement == null) {
                    return;
                }

                String namespace = childElement.getNamespaceURI();
                String profile = childElement.attributeValue("profile");
                // Check that the SI is about file transfer and try creating a file transfer
                if (NAMESPACE_SI.equals(namespace) && NAMESPACE_SI_FILETRANSFER.equals(profile)) {
                    // If this is a set, check the feature offer
                    if (iq.getType().equals(IQ.Type.set)) {
                        JID from = iq.getFrom();
                        JID to = iq.getTo();

                        FileTransfer transfer = createFileTransfer(from, to, childElement);

                        try {
                            if (transfer == null || !acceptIncomingFileTransferRequest(transfer)) {
View Full Code Here

    public boolean handleSet(IQ packet) {
        return false;
    }

    public void executeGet(IQ packet, Workgroup workgroup) {
        IQ reply = IQ.createResultIQ(packet);
        try {
            if (workgroup.getAgentManager().getAgentSession(packet.getFrom()) == null) {
                reply = IQ.createResultIQ(packet);
                reply.setChildElement(packet.getChildElement().createCopy());
                reply.setError(new PacketError(PacketError.Condition.not_authorized));
                workgroup.send(reply);
                return;
            }
        }
        catch (AgentNotFoundException e) {
            reply = IQ.createResultIQ(packet);
            reply.setChildElement(packet.getChildElement().createCopy());
            reply.setError(new PacketError(PacketError.Condition.not_authorized));
            workgroup.send(reply);
            return;
        }

        // Create session list
        List<AgentHistoryModel> sessionList = new ArrayList<AgentHistoryModel>();

        Element chatSessions = reply.setChildElement("chat-sessions", "http://jivesoftware.com/protocol/workgroup");


        Element iq = packet.getChildElement();
        String agentJID = iq.attributeValue("agentJID");
        String ms = iq.attributeValue("maxSessions");
View Full Code Here

        return "monitor".equals(name);
    }

    public void executeGet(IQ packet, Workgroup workgroup) {
        IQ reply = IQ.createResultIQ(packet);

        JID from = packet.getFrom();
        String bareJID = from.toBareJID();

        boolean isMonitor = false;

        // Retrieve the sound settings.
        String monitors = workgroup.getProperties().getProperty("monitors");
        if (monitors != null) {
            StringTokenizer tkn = new StringTokenizer(monitors, ",");
            while (tkn.hasMoreTokens()) {
                String agent = tkn.nextToken();
                if (agent.equalsIgnoreCase(bareJID)) {
                    isMonitor = true;
                }
            }
        }

        Element monitorElement = reply.setChildElement("monitor", "http://jivesoftware.com/protocol/workgroup");

        if (!isMonitor) {
            monitorElement.addElement("isMonitor").setText("false");
        }
        else {
View Full Code Here

        workgroup.send(reply);
    }

    public void executeSet(IQ packet, Workgroup workgroup) {
        IQ reply = null;
        Element iq = packet.getChildElement();

        try {
            JID from = packet.getFrom();
            String bareJID = from.toBareJID();
            if (!isOwner(bareJID, workgroup)) {
                reply = IQ.createResultIQ(packet);
                reply.setChildElement(packet.getChildElement().createCopy());
                reply.setError(new PacketError(PacketError.Condition.forbidden));
                workgroup.send(reply);
                return;
            }

            // Verify that an agent is requesting this information.
            WorkgroupManager workgroupManager = WorkgroupManager.getInstance();
            if (iq.element("makeOwner") != null) {
                String sessionID = iq.element("makeOwner").attributeValue("sessionID");
                final String serviceName = workgroupManager.getMUCServiceName();
                final String roomName = sessionID + "@" + serviceName;
                // final String roomJID = roomName + "/" + workgroup.getJID().getNode();

                IQ iqPacket = new IQ(IQ.Type.set);
                iqPacket.setTo(roomName);
                iqPacket.setFrom(workgroup.getFullJID());

                Element query = iqPacket.setChildElement("query", "http://jabber.org/protocol/muc#owner");
                Element item = query.addElement("item");
                item.addAttribute("affiliation", "owner");
                item.addAttribute("jid", packet.getFrom().toBareJID());
                workgroup.send(iqPacket);
            }
View Full Code Here

            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);
                reply.setChildElement(packet.getChildElement().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 || (
                    isLocalServer(to) && (
                            "jabber:iq:auth".equals(packet.getChildElement().getNamespaceURI()) ||
                                    "jabber:iq:register"
                                            .equals(packet.getChildElement().getNamespaceURI()) ||
                                    "urn:ietf:params:xml:ns:xmpp-bind"
                                            .equals(packet.getChildElement().getNamespaceURI())))) {
                handle(packet);
            }
            else {
                IQ reply = IQ.createResultIQ(packet);
                reply.setChildElement(packet.getChildElement().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();
                reply.setChildElement(packet.getChildElement().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();
View Full Code Here

TOP

Related Classes of org.xmpp.packet.IQ

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.