Package tigase.server

Examples of tigase.server.Packet


          // Send it back to user.
          Element query = Command.getData(packet, "query", null);
          Element iq =
            ElementUtils.createIqQuery(session.getDomain(), session.getJID(),
              StanzaType.result, packet.getElemId(), query);
          Packet result = new Packet(iq);
          result.setTo(session.getConnectionId());
          result.getElement().setAttribute("from",
            Command.getFieldValue(packet,  "jid"));
          results.offer(result);
          return;
        } else {
          return;
        }
      }

      // If ID part of user account contains only host name
      // and this is local domain it is message to admin
      if (nodeId == null || nodeId.equals("")
        || (nodeNick == null && nodeId.endsWith(session.getDomain()))) {
        Element query = packet.getElement().getChild("query");
        Packet discoCommand = Command.GETDISCO.getPacket(session.getJID(),
          session.getDomain(), StanzaType.get, packet.getElemId(), "submit");
        Command.addFieldValue(discoCommand, "xmlns", query.getXMLNS());
        Command.addFieldValue(discoCommand, "jid", packet.getElemTo());
        if (query.getAttribute("node") != null) {
          Command.addFieldValue(discoCommand, "node", query.getAttribute("node"));
        } // end of if (query.getAttribute("node") != null)
        results.offer(discoCommand);
        return;
      }

      if (nodeId.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 so I need to
        // set proper 'from' attribute whatever it is set to now.
        // Actually processor should not modify request but in this
        // case it is absolutely safe and recommended to set 'from'
        // attribute
        Element result = packet.getElement().clone();
        // Not needed anymore. Packet filter does it for all stanzas.
//         // According to spec we must set proper FROM attribute
//         result.setAttribute("from", session.getJID());
        results.offer(new Packet(result));
      } // end of else
    } catch (NotAuthorizedException e) {
      log.warning(
        "Received stats request but user session is not authorized yet: " +
        packet.getStringData());
View Full Code Here


                "You are not authorized to set vcard data.", true));
          } // end of else
          break;
        case result:
          Element elem = packet.getElement().clone();
          Packet result = new Packet(elem);
          result.setTo(session.getConnectionId());
          result.setFrom(packet.getTo());
          results.offer(result);
          break;
        default:
          results.offer(Authorization.BAD_REQUEST.getResponseMessage(packet,
              "Request type is incorrect", false));
          break;
        } // end of switch (type)
      } else {
        Element result = packet.getElement().clone();
        results.offer(new Packet(result));
      } // end of else
    } catch (NotAuthorizedException e) {
      log.warning(
        "Received privacy request but user session is not authorized yet: " +
        packet.getStringData());
View Full Code Here

      writePacketToSocket(packet);
    }
  }

  public Queue<Packet> processSocketData(XMPPIOService serv) {
    Packet p = null;
    while ((p = serv.getReceivedPackets().poll()) != null) {
      log.finer("Processing packet: " + p.getElemName()
        + ", type: " + p.getType());
      log.finest("Processing socket data: " + p.getStringData());
      if (p.getElemName().equals("handshake")) {
        processHandshake(p, serv);
      } else {
        if (p.isRouted()) {
          p = p.unpackRouted();
        } // end of if (p.isRouted())
        addOutPacket(p);
      }
    } // end of while ()
    return null;
View Full Code Here

      try {
        String loc_digest = Algorithms.hexDigest(id, secret, "SHA");
        log.finest("Calculating digest: id="+id+", secret="+secret
          +", digest="+loc_digest);
        if (digest != null && digest.equals(loc_digest)) {
          Packet resp = new Packet(new Element("handshake"));
          writePacketToSocket(serv, resp);
          String[] routings =
            (String[])serv.getSessionData().get(PORT_ROUTING_TABLE_PROP_KEY);
          updateRoutings(routings, true);
          String addr =
View Full Code Here

      if (packet.getType() == StanzaType.result) {
        List<Element> features = getFeatures(getXMPPSession(packet));
        Element elem_features = new Element("stream:features");
        elem_features.addChildren(features);
        elem_features.addChildren(Command.getData(packet));
        Packet result = new Packet(elem_features);
        result.setTo(packet.getTo());
        writePacketToSocket(result);
      } // end of if (packet.getType() == StanzaType.get)
      break;
    case STARTTLS:
      if (serv != null) {
        log.finer("Starting TLS for connection: " + serv.getUniqueId());
        try {
          // Note:
          // If you send <proceed> packet to client you must expect
          // instant response from the client with TLS handshaking data
          // before you will call startTLS() on server side.
          // So the initial handshaking data might be lost as they will
          // be processed in another thread reading data from the socket.
          // That's why below code first removes service from reading
          // threads pool and then sends <proceed> packet and starts TLS.
          Element proceed = Command.getData(packet, "proceed", null);
          Packet p_proceed = new Packet(proceed);
           SocketReadThread readThread = SocketReadThread.getInstance();
           readThread.removeSocketService(serv);
          //          writePacketToSocket(serv, p_proceed);
           serv.addPacketToSend(p_proceed);
           serv.processWaitingPackets();
          serv.startTLS(false);
          //          serv.call();
           readThread.addSocketService(serv);
        } catch (IOException e) {
          log.warning("Error starting TLS: " + e);
        } // end of try-catch
      } else {
        log.warning("Can't find sevice for STARTTLS command: " +
          packet.getStringData());
      } // end of else
      break;
    case REDIRECT:
      String command_sessionId = Command.getFieldValue(packet, "session-id");
      String newAddress = packet.getFrom();
      String old_receiver = changeDataReceiver(packet, newAddress,
        command_sessionId, serv);
      if (old_receiver != null) {
        log.fine("Redirecting data for sessionId: " + command_sessionId
          + ", to: " + newAddress);
        Packet response = null;
//         response = packet.commandResult(null);
//         Command.addFieldValue(response, "session-id", command_sessionId);
//         Command.addFieldValue(response, "action", "close");
//         response.getElement().setAttribute("to", old_receiver);
//         addOutPacket(response);
        response = packet.commandResult(null);
        Command.addFieldValue(response, "session-id", command_sessionId);
        Command.addFieldValue(response, "action", "activate");
        response.getElement().setAttribute("to", newAddress);
        addOutPacket(response);
      } else {
        log.finest("Connection for REDIRECT command does not exist, ignoring "
          + "packet: " + packet.toString());
      }
View Full Code Here

  public Queue<Packet> processSocketData(XMPPIOService serv) {

    String id = getUniqueId(serv);
    //String hostname = (String)serv.getSessionData().get(serv.HOSTNAME_KEY);

    Packet p = null;
    while ((p = serv.getReceivedPackets().poll()) != null) {
      log.finer("Processing packet: " + p.getElemName()
        + ", type: " + p.getType());
      log.finest("Processing socket data: " + p.getStringData());
      p.setFrom(getFromAddress(id));
      p.setTo(serv.getDataReceiver());
//       p.setTo(serv.getDataReceiver() != null ? serv.getDataReceiver()
//         : routings.computeRouting(hostname));
      addOutPacket(p);
      //       results.offer(new Packet(new Element("OK")));
    } // end of while ()
View Full Code Here

        + " from='" + hostname + "'"
        + " id='" + id + "'"
        + " version='1.0' xml:lang='en'>");
      serv.getSessionData().put(XMPPIOService.HOSTNAME_KEY, hostname);
      serv.setDataReceiver(routings.computeRouting(hostname));
      Packet streamOpen = Command.STREAM_OPENED.getPacket(
        getFromAddress(getUniqueId(serv)),
        serv.getDataReceiver(), StanzaType.set, "sess1", "submit");
      Command.addFieldValue(streamOpen, "session-id", id);
      Command.addFieldValue(streamOpen, "hostname", hostname);
      Command.addFieldValue(streamOpen, "xml:lang", lang);
View Full Code Here

  public void serviceStopped(XMPPIOService service) {
    super.serviceStopped(service);
    if (service.getXMLNS() == XMLNS) {
      //    XMPPIOService serv = (XMPPIOService)service;
      if (service.getDataReceiver() != null) {
        Packet command = Command.STREAM_CLOSED.getPacket(
          getFromAddress(getUniqueId(service)),
          service.getDataReceiver(), StanzaType.set, "sess1");
        addOutPacket(command);
        log.fine("Service stopped, sending packet: " + command.getStringData());
      } else {
        log.fine("Service stopped, before stream:stream received");
      }
    }
  }
View Full Code Here

  private void parseXMLData(String data) {
    DomBuilderHandler domHandler = new DomBuilderHandler();
    parser.parse(domHandler, data.toCharArray(), 0, data.length());
    Queue<Element> elems = domHandler.getParsedElements();
    while (elems != null && elems.size() > 0) {
      Packet result = new Packet(elems.poll());
      addOutPacket(result);
    }
  }
View Full Code Here

      while (rs.next()) {
        String name = rs.getString("name");
        String thread = rs.getString("thread");
        String subject = rs.getString("subject");
        String comment = rs.getString("comment");
        Packet msg = Packet.getMessage(jid, getName(), StanzaType.normal,
          "New comment by " + name + ":\n\n" + XMLUtils.escape(comment),
          XMLUtils.escape(subject), thread);
        log.fine("Sending new comment: " + msg.toString());
        results.offer(msg);
      }
    } catch (SQLException e) {
      // Let's ignore it for now.
      log.log(Level.WARNING, "Error retrieving stanzas from database: ", e);
View Full Code Here

TOP

Related Classes of tigase.server.Packet

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.