Package org.xmpp.packet

Examples of org.xmpp.packet.IQ


   *
   * @param packet   the response packet
   * @param listener the interface to the wave server
   */
  private void processGetSignerResponse(Packet packet, DeltaSignerInfoResponseListener listener) {
    IQ response = (IQ) packet;
    Element items = response.getChildElement().element("items");
    Element signature = items.element("signature");
    if (signature == null) {
      LOG.severe("Empty getDeltaSignerRequest response: " + response);
      listener.onFailure(FederationErrors.badRequest("Bad getDeltaSignatureRequest response"));
      return;
View Full Code Here


   * @param listener the listener to invoke
   */
  private void processPostSignerResponse(
      Packet packet,
      WaveletFederationProvider.PostSignerInfoResponseListener listener) {
    IQ response = (IQ) packet;
    Element pubsub = response.getChildElement();
    Element item = pubsub.element("publish").element("item");
    if (item.element("signature-response") != null) {
      listener.onSuccess();
    } else {
      listener.onFailure(FederationErrors.badRequest("No valid response"));
View Full Code Here

  }

  public void processPacket(Packet packet) {
    Kernel.debug(this,"Received packet: " + packet.toString(),6);
    if(packet instanceof IQ) {
      IQ iq = (IQ)packet;
      if(iq.getType() == IQ.Type.get || iq.getType() == IQ.Type.set) {
        Element element = iq.getChildElement();
        if(element.getName().equals("query")) {
          IQ result = new IQ(IQ.Type.result,iq.getID());
          result.setTo(iq.getFrom());
          result.setFrom(iq.getTo());
         
          Element childResult = result.setChildElement(element.getName(),element.getNamespaceURI());
          if(element.getNamespaceURI().equals("http://jabber.org/protocol/disco#info")) {
            //Element discoResult = result.setChildElement("query","http://jabber.org/protocol/disco#info");
            Element identity = childResult.addElement("identity");
            identity.addAttribute("category","gateway");
            identity.addAttribute("type","GOIMstats");
View Full Code Here

    return "Allows you to get information about buddies racing in LFS if they don't use Jabber";
  }
 
  public void processPacket(Packet packet) {
    if(packet instanceof IQ) {
      IQ iq = (IQ)packet;
      if(iq.getType() == IQ.Type.get || iq.getType() == IQ.Type.set) {
        Element element = iq.getChildElement();
        if(element.getName().equals("query")) {
          IQ result = new IQ(IQ.Type.result,iq.getID());
          result.setTo(iq.getFrom());
          result.setFrom(iq.getTo());
         
          Element childResult = result.setChildElement(element.getName(),element.getNamespaceURI());
          if(element.getNamespaceURI().equals("http://jabber.org/protocol/disco#info")) {
            // Element discoResult =
            // result.setChildElement("query","http://jabber.org/protocol/disco#info");
            Element identity = childResult.addElement("identity");
            identity.addAttribute("category","gateway");
            identity.addAttribute("type","lfs");
            identity.addAttribute("name",getName());
           
            Element feature = childResult.addElement("feature");
            feature.addAttribute("var","http://jabber.org/protocol/disco");
           
            feature = childResult.addElement("feature");
            feature.addAttribute("var","jabber:iq:register");
           
            feature = childResult.addElement("feature");
            feature.addAttribute("var","jabber:iq:gateway");

            manager.sendPacket(this,result);
          } else if(element.getNamespaceURI().equals("http://jabber.org/protocol/disco#items")) {
            // Element discoResult =
            // result.setChildElement("query","http://jabber.org/protocol/disco#items");
          } else if(element.getNamespaceURI().equals("jabber:iq:gateway")) {
            if(iq.getType() == IQ.Type.get) {
              Element desc = childResult.addElement("desc");
              desc.setText("Enter the users LFS username");
              childResult.addElement("prompt");
            } else if(iq.getType() == IQ.Type.set) {
              Element promptInput = element.element("prompt");
              String jid = promptInput.getText() + "@" + componentJID.toString();
              childResult.addElement("prompt").setText(jid);
              childResult.addElement("jid").setText(jid); // JEP-0100
                                    // says
                                    // it
                                    // should
                                    // be
                                    // <jid>xxx</jid>
                                    // but
                                    // the
                                    // PyICQ
                                    // returns
                                    // <prompt>xxx</prompt>
            }
          } else if(element.getNamespaceURI().equals("jabber:iq:register")) {
            Map<String, Object> registration = getRegistration(iq.getFrom());
            if(iq.getType() == IQ.Type.get) {
              DataForm form = new DataForm(DataForm.Type.form);
              form.setTitle("Enter Your LFS Username");
              form.addInstruction("Enter Your LFS Username");
              FormField username = form.addField();
              username.setVariable("username");
              username.setLabel("LFS Username");
              username.setType(FormField.Type.text_single);
              username.setRequired(true);
              username.setDescription("Your LFS Username");
              childResult.add(form.getElement());
              childResult.addElement("instructions").addText("Enter Your LFS Username");
              Element username_element = childResult.addElement("username");
              if(registration != null) {
                username_element.setText((String) registration.get("username"));
                username.addValue(registration.get("username"));
              }
            } else if(iq.getType() == IQ.Type.set) {
              String username = null;
              DataForm form = (DataForm)iq.getExtension(DataForm.ELEMENT_NAME,DataForm.NAMESPACE);
              if(form != null) {
                List<FormField> fields = form.getFields();
                for(FormField field : fields) {
                  if(!field.getVariable().equals("username")) continue;
                  List<String> vals = field.getValues();
                  if(vals != null && vals.size() > 0)
                    username = vals.get(0);
                }
              }
              if(username == null)
                username = iq.getChildElement().element("username").getText();
              if(username == null)
                result.setType(IQ.Type.error);
              else {
                if(registration == null)
                  db.sendInsert(null,"goim_component_registrations","subdomain,jid,username,password",getSubdomain(),iq.getFrom().toBareJID(),username,"");
                else
                  db.sendUpdate(null,"goim_component_registrations","username=?,password=?",new Object[]{username,""},"id=?",registration.get("id"));
View Full Code Here

    public IQHandler(String moduleName) {
        super(moduleName);
    }

    public void process(Packet packet) throws PacketException {
        IQ iq = (IQ) packet;
        try {
            IQ reply = handleIQ(iq);
            if (reply != null) {
                deliverer.deliver(reply);
            }
        }
        catch (org.jivesoftware.openfire.auth.UnauthorizedException e) {
            if (iq != null) {
                try {
                    IQ response = IQ.createResultIQ(iq);
                    response.setChildElement(iq.getChildElement().createCopy());
                    response.setError(PacketError.Condition.not_authorized);
                    sessionManager.getSession(iq.getFrom()).process(response);
                }
                catch (Exception de) {
                    Log.error(LocaleUtils.getLocalizedString("admin.error"), de);
                    sessionManager.getSession(iq.getFrom()).close();
                }
            }
        }
        catch (Exception e) {
            Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
            try {
                IQ response = IQ.createResultIQ(iq);
                response.setChildElement(iq.getChildElement().createCopy());
                response.setError(PacketError.Condition.internal_server_error);
                sessionManager.getSession(iq.getFrom()).process(response);
            }
            catch (Exception e1) {
                // Do nothing
            }
View Full Code Here

            ConnectionMultiplexerSession multiplexerSession =
                    multiplexerManager.getMultiplexerSession(connectionManagerName,streamID);
            if (multiplexerSession != null) {
                // Server requested to close the client session so let the connection manager
                // know that he has to finish the client session
                IQ closeRequest = new IQ(IQ.Type.set);
                closeRequest.setFrom(serverName);
                closeRequest.setTo(connectionManagerName);
                Element child = closeRequest.setChildElement("session",
                        "http://jabber.org/protocol/connectionmanager");
                child.addAttribute("id", streamID);
                child.addElement("close");
                multiplexerSession.process(closeRequest);
            }
View Full Code Here

        responseElement.addElement("display");
    }

    @Override
  public IQ handleIQ(IQ packet) {
        IQ response = null;
        response = IQ.createResultIQ(packet);
        response.setChildElement(buildResponse());
        return response;
    }
View Full Code Here

    @Override
  public IQ handleIQ(IQ packet) {
        // Create a copy of the sent pack that will be used as the reply
        // we only need to add the requested items to the reply if any otherwise add
        // a not found error
        IQ reply = IQ.createResultIQ(packet);
       
        // TODO Implement publishing client items
        if (IQ.Type.set == packet.getType()) {
            reply.setChildElement(packet.getChildElement().createCopy());
            reply.setError(PacketError.Condition.feature_not_implemented);
            return reply;
        }

        // Look for a DiscoItemsProvider associated with the requested entity.
        // We consider the host of the recipient JID of the packet as the entity. It's the
        // DiscoItemsProvider responsibility to provide the items associated with the JID's name 
        // together with any possible requested node.
        DiscoItemsProvider itemsProvider = getProvider(packet.getTo() == null ?
                XMPPServer.getInstance().getServerInfo().getXMPPDomain() : packet.getTo().getDomain());
        if (itemsProvider != null) {
            // Get the JID's name
            String name = packet.getTo() == null ? null : packet.getTo().getNode();
            if (name == null || name.trim().length() == 0) {
                name = null;
            }
            // Get the requested node
            Element iq = packet.getChildElement();
            String node = iq.attributeValue("node");

            // Check if we have items associated with the requested name and node
            Iterator<DiscoItem> itemsItr = itemsProvider.getItems(name, node, packet.getFrom());
            if (itemsItr != null) {
                reply.setChildElement(iq.createCopy());
                Element queryElement = reply.getChildElement();

        // See if the requesting entity would like to apply 'result set
        // management'
        final Element rsmElement = packet.getChildElement().element(
            QName.get("set",
                ResultSet.NAMESPACE_RESULT_SET_MANAGEMENT));

        // apply RSM only if the element exists, and the (total) results
        // set is not empty.
        final boolean applyRSM = rsmElement != null
            && itemsItr.hasNext();

        if (applyRSM) {
          if (!ResultSet.isValidRSMRequest(rsmElement))
          {
            reply.setError(PacketError.Condition.bad_request);
            return reply;
          }
         
          // Calculate which results to include.
          final List<DiscoItem> rsmResults;
          final List<DiscoItem> allItems = new ArrayList<DiscoItem>();
          while (itemsItr.hasNext()) {
            allItems.add(itemsItr.next());
          }
          final ResultSet<DiscoItem> rs = new ResultSetImpl<DiscoItem>(
              allItems);
          try {
            rsmResults = rs.applyRSMDirectives(rsmElement);
          } catch (NullPointerException e) {
            final IQ itemNotFound = IQ.createResultIQ(packet);
            itemNotFound.setError(PacketError.Condition.item_not_found);
            return itemNotFound;
          }

          // add the applicable results to the IQ-result
          for (DiscoItem item : rsmResults) {
View Full Code Here

        info = new IQHandlerInfo("query", "jabber:iq:private");
    }

    @Override
  public IQ handleIQ(IQ packet) throws UnauthorizedException, PacketException {
        IQ replyPacket;
        Element child = packet.getChildElement();
        Element dataElement = (Element) child.elementIterator().next();

        if (dataElement != null) {
            if (IQ.Type.get.equals(packet.getType())) {
                replyPacket = IQ.createResultIQ(packet);
                Element dataStored = privateStorage.get(packet.getFrom().getNode(), dataElement);
                dataStored.setParent(null);

                child.remove(dataElement);
                child.setParent(null);
                replyPacket.setChildElement(child);
                child.add(dataStored);
            }
            else {
                privateStorage.add(packet.getFrom().getNode(), dataElement);
                replyPacket = IQ.createResultIQ(packet);
            }
        }
        else {
            replyPacket = IQ.createResultIQ(packet);
            replyPacket.setChildElement("query", "jabber:iq:private");
        }
        return replyPacket;
    }
View Full Code Here

     *
     * @param packet the IQ packet.
     */
    public void handle(Packet packet) {
        if (packet instanceof IQ) {
            IQ iq = (IQ) packet;
            if (iq.getType() == IQ.Type.result) {
                // Do nothing with result packets
            }
            else if (iq.getType() == IQ.Type.error) {
                // Log the IQ error packet that the connection manager failed to process
                Log.warn("Connection Manager failed to process IQ packet: " + packet.toXML());
            }
            else if (iq.getType() == IQ.Type.set) {
                Element child = iq.getChildElement();
                String streamID = child.attributeValue("id");
                if (streamID == null) {
                    // No stream ID was included so return a bad_request error
                    Element extraError = DocumentHelper.createElement(QName.get(
                            "id-required", "http://jabber.org/protocol/connectionmanager#errors"));
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.