Package tigase.xmpp.impl

Source Code of tigase.xmpp.impl.JabberIqCommand

/*
* Tigase Jabber/XMPP Server
* Copyright (C) 2004-2007 "Artur Hefczyc" <artur.hefczyc@tigase.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. Look for COPYING file in the top folder.
* If not, see http://www.gnu.org/licenses/.
*
* $Rev: 1250 $
* Last modified by $Author: kobit $
* $Date: 2008-12-01 13:32:35 +0000 (Mon, 01 Dec 2008) $
*/
package tigase.xmpp.impl;

import java.util.Arrays;
import java.util.Queue;
import java.util.Map;
import java.util.logging.Logger;
import tigase.db.NonAuthUserRepository;
import tigase.server.Command;
import tigase.server.Packet;
import tigase.xml.Element;
import tigase.xmpp.Authorization;
import tigase.xmpp.NotAuthorizedException;
import tigase.xmpp.XMPPProcessor;
import tigase.xmpp.XMPPProcessorIfc;
import tigase.xmpp.XMPPResourceConnection;
import tigase.xmpp.XMPPException;
import tigase.util.JIDUtils;

/**
* Describe class JabberIqCommand here.
*
*
* Created: Mon Jan 22 22:41:17 2007
*
* @author <a href="mailto:artur.hefczyc@tigase.org">Artur Hefczyc</a>
* @version $Rev: 1250 $
*/
public class JabberIqCommand extends XMPPProcessor implements XMPPProcessorIfc {

  private static final Logger log =
    Logger.getLogger("tigase.xmpp.impl.JabberIqCommand");

  private static final String XMLNS = Command.XMLNS;
  private static final String ID = XMLNS;
  private static final String[] ELEMENTS =
  {"command"};
  private static final String[] XMLNSS =
  {Command.XMLNS};
  private static final Element[] DISCO_FEATURES =
  {new Element("feature"new String[] {"var"}new String[] {XMLNS})};

  public String id() { return ID; }

  public String[] supElements()
  { return ELEMENTS; }

  public String[] supNamespaces()
  { return XMLNSS; }

  public Element[] supDiscoFeatures(final XMPPResourceConnection session)
  { return DISCO_FEATURES; }

  public void process(final Packet packet, final XMPPResourceConnection session,
    final NonAuthUserRepository repo, final Queue<Packet> results,
    final Map<String, Object> settings)
    throws XMPPException {

    if (session == null) { return; }

    // Processing only commands (that should be quaranteed by name space)
    // and only unknown commands. All known commands are processed elsewhere
//    if (!packet.isCommand() || packet.getCommand() != Command.OTHER) {
//      return;
//    }

    try {
      log.finest("Received packet: " + packet.getStringData());

      // Not needed anymore. Packet filter does it for all stanzas.
//       // For all messages coming from the owner of this account set
//       // proper 'from' attribute. This is actually needed for the case
//       // when the user sends a message to himself.
//       if (packet.getFrom().equals(session.getConnectionId())) {
//         packet.getElement().setAttribute("from", session.getJID());
//       } // end of if (packet.getFrom().equals(session.getConnectionId()))

      String id = JIDUtils.getNodeID(packet.getElemTo());

      if (id.equals(session.getUserId())) {
        // Yes this is message to 'this' client
        Element elem = packet.getElement().clone();
        Packet result = new Packet(elem);
        result.setTo(session.getConnectionId(packet.getElemTo()));
        result.setFrom(packet.getTo());
        results.offer(result);
      } else {
        // This is message to some other client
        Element result = packet.getElement().clone();
        results.offer(new Packet(result));
      } // end of else
    } catch (NotAuthorizedException e) {
      log.warning("NotAuthorizedException for packet: "  + packet.getStringData());
      results.offer(Authorization.NOT_AUTHORIZED.getResponseMessage(packet,
          "You must authorize session first.", true));
    } // end of try-catch
  }

}
TOP

Related Classes of tigase.xmpp.impl.JabberIqCommand

TOP
Copyright © 2018 www.massapi.com. 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.