Esempio n. 1
0
  private void processIQ(Element doc) {
    log.debug("processIQ()...");
    IQ packet;
    try {
      packet = getIQ(doc);
    } catch (IllegalArgumentException e) {
      log.debug("Rejecting packet. JID malformed", e);
      IQ reply = new IQ();
      if (!doc.elements().isEmpty()) {
        reply.setChildElement(((Element) doc.elements().get(0)).createCopy());
      }
      reply.setID(doc.attributeValue("id"));
      reply.setTo(session.getAddress());
      String to = doc.attributeValue("to");
      if (to != null) {
        reply.getElement().addAttribute("from", to);
      }
      reply.setError(PacketError.Condition.jid_malformed);
      session.process(reply);
      return;
    }

    //        if (packet.getID() == null) {
    //            // IQ packets MUST have an 'id' attribute
    //            StreamError error = new StreamError(
    //                    StreamError.Condition.invalid_xml);
    //            session.deliverRawText(error.toXML());
    //            session.close();
    //            return;
    //        }

    packet.setFrom(session.getAddress());
    router.route(packet);
    session.incrementClientPacketCount();
  }
Esempio n. 2
0
  /**
   * Process the received stanza using the given XMPP packet reader.
   *
   * @param stanza the received statza
   * @param reader the XMPP packet reader
   * @throws Exception if the XML stream is not valid.
   */
  public void process(String stanza, XMPPPacketReader reader) throws Exception {
    boolean initialStream = stanza.startsWith("<stream:stream");
    if (!sessionCreated || initialStream) {
      if (!initialStream) {
        return; // Ignore <?xml version="1.0"?>
      }
      if (!sessionCreated) {
        sessionCreated = true;
        MXParser parser = reader.getXPPParser();
        parser.setInput(new StringReader(stanza));
        createSession(parser);
      } else if (startedTLS) {
        startedTLS = false;
        tlsNegotiated();
      }
      return;
    }

    // If end of stream was requested
    if (stanza.equals("</stream:stream>")) {
      session.close();
      return;
    }
    // Ignore <?xml version="1.0"?>
    if (stanza.startsWith("<?xml")) {
      return;
    }
    // Create DOM object
    Element doc = reader.read(new StringReader(stanza)).getRootElement();
    if (doc == null) {
      return;
    }

    String tag = doc.getName();
    if ("starttls".equals(tag)) {
      if (negotiateTLS()) { // Negotiate TLS
        startedTLS = true;
      } else {
        connection.close();
        session = null;
      }
    } else if ("message".equals(tag)) {
      processMessage(doc);
    } else if ("presence".equals(tag)) {
      log.debug("presence...");
      processPresence(doc);
    } else if ("iq".equals(tag)) {
      log.debug("iq...");
      processIQ(doc);
    } else {
      log.warn("Unexpected packet tag (not message, iq, presence)" + doc.asXML());
      session.close();
    }
  }
Esempio n. 3
0
  private void processMessage(Element doc) {
    log.debug("processMessage()...");
    Message packet;
    try {
      packet = new Message(doc, false);
    } catch (IllegalArgumentException e) {
      log.debug("Rejecting packet. JID malformed", e);
      Message reply = new Message();
      reply.setID(doc.attributeValue("id"));
      reply.setTo(session.getAddress());
      reply.getElement().addAttribute("from", doc.attributeValue("to"));
      reply.setError(PacketError.Condition.jid_malformed);
      session.process(reply);
      return;
    }

    packet.setFrom(session.getAddress());
    router.route(packet);
    session.incrementClientPacketCount();
  }
Esempio n. 4
0
 private void tlsNegotiated() {
   // Offer stream features including SASL Mechanisms
   StringBuilder sb = new StringBuilder(620);
   sb.append("<?xml version='1.0' encoding='UTF-8'?>");
   sb.append("<stream:stream ");
   sb.append("xmlns:stream=\"http://etherx.jabber.org/streams\" ");
   sb.append("xmlns=\"jabber:client\" from=\"");
   sb.append(serverName);
   sb.append("\" id=\"");
   sb.append(session.getStreamID());
   sb.append("\" xml:lang=\"");
   sb.append(connection.getLanguage());
   sb.append("\" version=\"");
   sb.append(Session.MAJOR_VERSION).append(".").append(Session.MINOR_VERSION);
   sb.append("\">");
   sb.append("<stream:features>");
   // Include specific features such as auth and register for client sessions
   String specificFeatures = session.getAvailableStreamFeatures();
   if (specificFeatures != null) {
     sb.append(specificFeatures);
   }
   sb.append("</stream:features>");
   connection.deliverRawText(sb.toString());
 }
Esempio n. 5
0
  private void processPresence(Element doc) {
    log.debug("processPresence()...");
    Presence packet;
    try {
      packet = new Presence(doc, false);
    } catch (IllegalArgumentException e) {
      log.debug("Rejecting packet. JID malformed", e);
      Presence reply = new Presence();
      reply.setID(doc.attributeValue("id"));
      reply.setTo(session.getAddress());
      reply.getElement().addAttribute("from", doc.attributeValue("to"));
      reply.setError(PacketError.Condition.jid_malformed);
      session.process(reply);
      return;
    }
    if (session.getStatus() == Session.STATUS_CLOSED && packet.isAvailable()) {
      log.warn("Ignoring available presence packet of closed session: " + packet);
      return;
    }
    packet.setFrom(session.getAddress());
    router.route(packet);
    session.incrementClientPacketCount();

    if (session.getStatus() == Session.STATUS_AUTHENTICATED && packet.isAvailable()) {
      String userName = session.getAddress().getNode();
      System.out.println("Query username : -> " + userName);
      if (null != userName && !"".equals(userName)) {
        NotificationMO mo = new NotificationMO();
        mo.setUsername(userName);
        mo.setStatus(NotificationMO.STATUS_NOT_SEND);
        List<NotificationMO> list = notificationService.queryNotification(mo);
        if (!list.isEmpty()) {
          for (NotificationMO notificationMO : list) {
            notificationManager.sendOfflineNotification(notificationMO);
          }
        } else {
          log.info(" no offline notification, username = "******"userName is null !!!!!!");
      }
    }
  }