Package tigase.server

Examples of tigase.server.Packet


//     return JIDUtils.getJID(packet.getFrom(), packet.getTo(), null);
//   }

  public Queue<Packet> processSocketData(XMPPIOService serv) {
    Queue<Packet> packets = serv.getReceivedPackets();
    Packet p = null;
    while ((p = packets.poll()) != null) {
//       log.finer("Processing packet: " + p.getElemName()
//         + ", type: " + p.getType());
      log.finest("Processing socket data: " + p.getStringData());

      if (p.getElement().getXMLNS() != null &&
        p.getElement().getXMLNS().equals(DIALBACK_XMLNS)) {
        Queue<Packet> results = new LinkedList<Packet>();
        processDialback(p, serv, results);
        for (Packet res: results) {
          String cid = res.getTo();
          log.finest("Sending dialback result: " + res.getStringData()
            + " to " + cid);
          XMPPIOService sender = handshakingByHost_Type.get(cid);
          if (sender == null) {
            sender = servicesByHost_Type.get(cid);
          }
          log.finest("cid: " + cid
            + ", writing packet to socket: " + res.getStringData());
          if (sender == null || !writePacketToSocket(sender, res)) {
            // I am assuming here that it can't happen that the packet is
            // to accept channel and it doesn't exist
            addWaitingPacket(cid, res, waitingControlPackets);
          } // end of else
        } // end of for (Packet p: results)
      } else {
        if (p.getElemName().equals("error")) {
          processStreamError(p, serv);
          return null;
        } else {
          if (checkPacket(p, serv)) {
            log.finest("Adding packet out: " + p.getStringData());
            addOutPacket(p);
          } else {
            return null;
          }
        }
View Full Code Here


  public void processPacket(final Packet packet) {

    if (packet.isCommand()) {
      Command.Action action = Command.getAction(packet);
      if (action == Command.Action.cancel) {
        Packet result = packet.commandResult(null);
        addOutPacket(result);
        return;
      }

//       Packet result = packet.commandResult("result");
//       TaskCommandIfc command = commands.get("*");
//       if (command != null) {
//         command.processCommand(packet, result, this);
//       } // end of if (command != null)
//       addOutPacket(result);
//       return;

      Packet result = packet.commandResult("result");
      String str_command = packet.getStrCommand();
      if (str_command != null) {
        String[] arr_command = str_command.split("/");
        if (arr_command.length > 1) {
          TaskCommandIfc command = commands.get(arr_command[1]);
View Full Code Here

      rs = get_new_topics.executeQuery();
      while (rs.next()) {
        String name = rs.getString("name");
        String title = rs.getString("title");
        String body = rs.getString("body");
        Packet msg = Packet.getMessage(jid, getName(), StanzaType.normal,
          "New post by " + name + ":\n\n" + XMLUtils.escape(body),
          XMLUtils.escape(title), null);
        log.fine("Sending new topic: " + 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

      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

      body.setAttribute(ACK_ATTR, ""+takeCurrentRidTail());
    }
    body.setXMLNS(BOSH_XMLNS);
    sendBody(service, body);
    //service.writeRawData(body.toString());
    Packet streamOpen = Command.STREAM_OPENED.getPacket(null, null,
      StanzaType.set, "sess1", "submit");
    Command.addFieldValue(streamOpen, "session-id", sessionId);
    Command.addFieldValue(streamOpen, "hostname", domain);
    Command.addFieldValue(streamOpen, LANG_ATTR, lang);
    out_results.offer(streamOpen);
View Full Code Here

  }

  private void bouncePacketsBack(Authorization author, String cid) {
    Queue<Packet> waiting =  waitingPackets.remove(cid);
    if (waiting != null) {
      Packet p = null;
      while ((p = waiting.poll()) != null) {
        log.finest("Sending packet back: " + p.getStringData());
        try {
          addOutPacket(author.getResponseMessage(p, "S2S - not delivered", true));
        } catch (PacketErrorTypeException e) {
          log.warning("Packet processing exception: " + e);
        }
View Full Code Here

          // Some client send IQ stanzas with private data to store some
          // settings so some confirmation stanzas might be sent back
          // let's give the client a few secs for session termination
          max_inactivity = 2;   // Max pause changed to 2 secs
          terminate = true;
          Packet command = Command.STREAM_CLOSED.getPacket(null, null,
            StanzaType.set, "bosh1");
          out_results.offer(command);
        }
        if (packet.getAttribute(RESTART_ATTR) != null
          && packet.getAttribute(RESTART_ATTR).equals("true")) {
          log.fine("Found stream restart instruction: " + packet.toString());
          out_results.offer(Command.GETFEATURES.getPacket(null, null,
              StanzaType.get, "restart1", null));
        }
        if (packet.getAttribute(CACHE_ATTR) != null) {
          try {
            CacheAction action =
              CacheAction.valueOf(packet.getAttribute(CACHE_ATTR));
            if (cache_on || (action == CacheAction.on)) {
              processCache(action, packet);
            }
          } catch (IllegalArgumentException e) {
            log.warning("Incorrect cache action: "
              + packet.getAttribute(CACHE_ATTR));
          }
        } else {
          List<Element> children = packet.getElemChildren(BODY_EL_NAME);
          if (children != null) {
            for (Element el: children) {
              if (el.getXMLNS().equals(BOSH_XMLNS)) {
                el.setXMLNS("jabber:client");
              }
              Packet result = new Packet(el);
              if (filterOutPacket(result)) {
                log.finest("Sending out packet: " + result.toString());
                out_results.offer(result);
              } else {
                log.finest("Out packet filtered: " + result.toString());
              }
            }
          }
        }
      } else {
        log.info("Duplicated packet: " + packet.toString());
      }
    } else {
      log.warning("[" + connections.size() +
        "] Unexpected packet from the network: " + packet.toString());
      String er_msg = "Invalid body element";
      if (packet.getElemName() != BODY_EL_NAME) {
        er_msg += ", incorrect root element name, use " + BODY_EL_NAME;
      }
      if (packet.getXMLNS() != BOSH_XMLNS) {
        er_msg += ", incorrect xmlns, use " + BOSH_XMLNS;
      }
      try {
        Packet error = Authorization.BAD_REQUEST.getResponseMessage(
          packet, er_msg, true);
        waiting_packets.add(error.getElement());
        terminate = true;
        Packet command = Command.STREAM_CLOSED.getPacket(null, null,
          StanzaType.set, "sess1");
        out_results.offer(command);
      } catch (PacketErrorTypeException e) {
        log.info("Error type and incorrect from bosh client? Ignoring...");
      }
View Full Code Here

      elem.addAttribute("from", local_hostname);
      elem.addAttribute("xmlns:db", DIALBACK_XMLNS);

      StringBuilder sb = new StringBuilder();
      // Attach also all controll packets which are wating to send
      Packet p = null;
      Queue<Packet> waiting =  waitingControlPackets.get(cid);
      if (waiting != null) {
        while ((p = waiting.poll()) != null) {
          log.finest("Sending packet: " + p.getStringData());
          sb.append(p.getStringData());
        } // end of while (p = waitingPackets.remove(ipAddress) != null)
      } // end of if (waiting != null)
      sb.append(elem.toString());
      log.finest("cid: " + (String)serv.getSessionData().get("cid")
        + ", sending: " + sb.toString());
View Full Code Here

          }
          for (Element packet: waiting_packets) {
            try {
              out_results.offer(
                Authorization.RECIPIENT_UNAVAILABLE.getResponseMessage(
                  new Packet(packet),
                  "Bosh = disconnected", true));
            } catch (PacketErrorTypeException e) {
              log.warning("Packet processing exception: " + e);
            }
          }
          Packet command = Command.STREAM_CLOSED.getPacket(null, null,
            StanzaType.set, "sess1");
          out_results.offer(command);
          return true;
        case EMPTY_RESP:
          BoshIOService serv = connections.poll();
View Full Code Here

  private void sendToAdmins(Element elem) {
    for (String adm: admins) {
      Element msg = elem.clone();
      msg.setAttribute("to", adm);
      addOutPacket(new Packet(msg));
    }
  }
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.