public void notifyQueueStatus(JID sender, JID receiver, UserRequest request, boolean isPolling) {
    Packet statusPacket;
    if (isPolling) {
      statusPacket = new IQ();
    } else {
      statusPacket = new Message();
    }
    statusPacket.setFrom(sender);
    statusPacket.setTo(receiver);

    // Add Queue Status Packet to IQ
    Element status =
        statusPacket
            .getElement()
            .addElement("queue-status", "http://jabber.org/protocol/workgroup");

    // Add Time Element
    Element time = status.addElement("time");
    time.setText(Integer.toString(request.getTimeStatus()));

    // Add Position Element
    Element position = status.addElement("position");
    position.setText(Integer.toString(request.getPosition() + 1));
    status.add(request.getSessionElement());

    // Send the queue status
    request.getWorkgroup().send(statusPacket);
  }
 private void sendFederatedRequests(String originatingServer) throws ComponentException {
   String remoteServer = discoveredServers.get(originatingServer);
   List<Packet> packetsToSend = waitingStanzas.get(originatingServer);
   if (packetsToSend == null) {
     return;
   }
   for (Packet packet : packetsToSend) {
     packet.setTo(remoteServer);
     sendPacket(packet.createCopy());
   }
   waitingStanzas.remove(originatingServer);
 }
  public void send(Packet packet) {
    if (packet == null) {
      return;
    }
    packet.setTo(user.getAddress());

    if (session != null && session.getStatus() == Session.STATUS_AUTHENTICATED) {
      // Send the packet directly to the local user session
      session.process(packet);
    } else {
      router.route(packet);
    }
  }
示例#4
0
  public Packet doAction(Packet packet) throws PacketRejectedException {
    SessionManager sessionManager = SessionManager.getInstance();
    ClientSession clientSession = sessionManager.getSession(packet.getFrom());
    Packet rejectPacket;
    String pfFrom = JiveGlobals.getProperty("pf.From", "packetfilter");

    if (packet instanceof Message) {
      Message in = (Message) packet.createCopy();
      if (clientSession != null && in.getBody() != null) {

        in.setFrom(new JID(pfFrom));
        String rejectMessage =
            JiveGlobals.getProperty(
                "pf.rejectMessage", "Your message was rejected by the packet filter");
        in.setBody(rejectMessage);
        in.setType(Message.Type.error);
        in.setTo(packet.getFrom());
        String rejectSubject = JiveGlobals.getProperty("pf.rejectSubject", "Rejected");
        in.setSubject(rejectSubject);
        clientSession.process(in);
      }

    } else if (packet instanceof Presence) {
      rejectPacket = new Presence();
      rejectPacket.setTo(packet.getFrom());
      rejectPacket.setError(PacketError.Condition.forbidden);

    } else if (packet instanceof IQ) {
      rejectPacket = new IQ();
      rejectPacket.setTo(packet.getFrom());
      rejectPacket.setError(PacketError.Condition.forbidden);
    }
    if (doLog()) {
      Log.info("Rejecting packet from " + packet.getFrom() + " to " + packet.getTo());
    }
    throw new PacketRejectedException();
  }
  public void process(Packet packet) throws ComponentException {

    logger.debug("Packet payload " + packet.toXML() + " going to federation.");

    String to = packet.getTo().toString();

    String uniqueId = generateUniqueId(packet);
    idMap.put(uniqueId, packet.getID());
    packet.setID(uniqueId);

    sentRemotePackets.put(uniqueId, packet.getFrom());
    try {
      extractNodeDetails(packet);
      // Do we have a map already?
      if (discoveredServers.containsKey(to)) {
        packet.setTo(new JID(discoveredServers.get(to)));
        sendPacket(packet.createCopy());
        return;
      }
      // Are we already discovering a remote server?
      if (!remoteChannelDiscoveryStatus.containsKey(to)) {
        discoverRemoteChannelServer(to, packet.getID());
      } else if (remoteChannelDiscoveryStatus.get(to).equals(NO_CHANNEL_SERVER)) {
        logger.error("No remote channel server for " + to);
        IQ reply = IQ.createResultIQ((IQ) packet);
        reply.setError(
            new PacketError(
                PacketError.Condition.remote_server_not_found, PacketError.Type.cancel));
        component.sendPacket(reply);
        return;
      }
      // Add packet to list
      if (!waitingStanzas.containsKey(to)) {
        waitingStanzas.put(to, new ArrayList<Packet>());
      }
      waitingStanzas.get(to).add(packet);
      logger.debug(
          "Adding packet to waiting stanza list for "
              + to
              + " (size "
              + waitingStanzas.get(to).size()
              + ")");
    } catch (Exception e) {
      logger.error(e);
    }
  }