Package tigase.xml

Examples of tigase.xml.Element


      results.offer(packet.okResult(query, 0));
  }


  public Element getDiscoInfo(String node, String jid) {
    Element query = serviceEntity.getDiscoInfo(null);
    log.finest("Returing disco-info: " + query.toString());
    return query;
  }
View Full Code Here


    String lang = packet.getAttribute(LANG_ATTR);
    if (lang == null) {
      lang = "en";
    }
    service.setContentType(content_type);
    Element body = new Element(BODY_EL_NAME,
      new String[] {WAIT_ATTR,
                    INACTIVITY_ATTR,
                    POLLING_ATTR,
                    REQUESTS_ATTR,
                    HOLD_ATTR,
                    MAXPAUSE_ATTR,
                    SID_ATTR,
                    VER_ATTR,
                    FROM_ATTR,
                    SECURE_ATTR,
                    "xmpp:version",
                    "xmlns:xmpp",
                    "xmlns:stream"},
      new String[] {Long.valueOf(this.max_wait).toString(),
                    Long.valueOf(this.max_inactivity).toString(),
                    Long.valueOf(this.min_polling).toString(),
                    Integer.valueOf(this.concurrent_requests).toString(),
                    Integer.valueOf(this.hold_requests).toString(),
                    Long.valueOf(this.max_pause).toString(),
                    this.sid.toString(),
                    BOSH_VERSION,
                    this.domain,
                    "true",
                    "1.0",
                    "urn:xmpp:xbosh",
                    "http://etherx.jabber.org/streams"});
    sessionId = UUID.randomUUID().toString();
    body.setAttribute(AUTHID_ATTR, sessionId);
    if (getCurrentRidTail() > 0) {
      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);
View Full Code Here

    "$1<a href=\"http://$2\" target=\"_blank\">$2</a>",
    "$1<a href=\"$2\" target=\"_blank\">$2</a>",
  };

  private Element applyFilters(Element packet) {
    Element result = packet.clone();
    if (result.getName() == MESSAGE_ELEMENT_NAME) {
      String body =  result.getCData("/message/body");
      if (body != null) {
        int count = 0;
//         for (Pattern reg: links_regexs) {
//           body = reg.matcher(body).replaceAll(replace_with[count++]);
//         }
        result.getChild("body").setCData(body);
      }
    }
    return result;
  }
View Full Code Here

    }
    return false;
  }

  private void sendBody(BoshIOService serv, Element body_par) {
    Element body = body_par;
    if (body == null) {
      body = new Element(BODY_EL_NAME,
        new String[] {FROM_ATTR, SECURE_ATTR,
                    "xmpp:version",
                    "xmlns:xmpp",
                    "xmlns:stream"},
        new String[] {this.domain, "true",
                    "1.0",
                    "urn:xmpp:xbosh",
                    "http://etherx.jabber.org/streams"});
      body.setXMLNS(BOSH_XMLNS);
      long rid = takeCurrentRidTail();
      if (rid > 0) {
        body.setAttribute(ACK_ATTR, ""+rid);
      }
      if (waiting_packets.size() > 0) {
        body.addChild(applyFilters(waiting_packets.poll()));
        while (waiting_packets.size() > 0
          && body.getChildren().size() < MAX_PACKETS) {
          body.addChild(applyFilters(waiting_packets.poll()));
        }
      }
    }
    try {
      if (terminate) {
        body.setAttribute("type", StanzaType.terminate.toString());
      }
      handler.writeRawData(serv, body.toString());
      //serv.writeRawData(body.toString());
      //waiting_packets.clear();
      serv.stop();
//     } catch (IOException e) {
//       // I call it anyway at the end of method call
View Full Code Here

   * @param packet a <code>Packet</code> value
   * @return a <code>boolean</code> value
   */
  private boolean processIQPacket(Packet packet) {
    boolean processed = false;
    Element iq = packet.getElement();
    Element query = iq.getChild("query", INFO_XMLNS);
    Element query_rep = null;
    if (query != null && packet.getType() == StanzaType.get) {
      query_rep =
        serviceEntity.getDiscoInfo(JIDUtils.getNodeNick(packet.getElemTo()));
      processed = true;
    } // end of if (query != null && packet.getType() == StanzaType.get)
    query = iq.getChild("query", ITEMS_XMLNS);
    if (query != null && packet.getType() == StanzaType.get) {
      query_rep = query.clone();
      List<Element> items =
        serviceEntity.getDiscoItems(JIDUtils.getNodeNick(packet.getElemTo()),
          packet.getElemTo());
      if (items != null && items.size() > 0) {
        query_rep.addChildren(items);
      } // end of if (items != null && items.size() > 0)
      processed = true;
    } // end of if (query != null && packet.getType() == StanzaType.get)
    if (query_rep != null) {
      addOutPacket(packet.okResult(query_rep, 0));
View Full Code Here

        key = Algorithms.hexDigest(remote_id, uuid, "SHA");
      } catch (NoSuchAlgorithmException e) {
        key = uuid;
      } // end of try-catch
      sharedSessionData.put(cid+"-dialback-key", key);
      Element elem = new Element("db:result", key);
      elem.addAttribute("to", remote_hostname);
      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());
      return sb.toString();
    }
    case accept: {
View Full Code Here

    return false;
  }

  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

      } // end of while (p = waitingPackets.remove(ipAddress) != null)
    } // end of if (waiting != null)
  }

  private void generateStreamError(String error_el, XMPPIOService serv) {
    Element error = new Element("stream:error",
      new Element[] {
        new Element(error_el,
          new String[] {"xmlns"},
          new String[] {"urn:ietf:params:xml:ns:xmpp-streams"})
      }, null, null);
    try {
      writeRawData(serv, error.toString());
//       serv.writeRawData(error.toString());
//       serv.writeRawData("</stream:stream>");
      serv.stop();
    } catch (Exception e) {
      serv.stop();
View Full Code Here

        String new_password = packet.getElemCData("/iq/query/password");
        try {
          repository.setData(getComponentId(), id, username_key, new_username);
          repository.setData(getComponentId(), id, password_key, new_password);
          addOutPacket(packet.okResult((String)null, 0));
          addOutPacket(new Packet(new Element(PRESENCE_ELNAME,
                new String[] {"to", "from", "type"},
                new String[] {id, packet.getElemTo(), "subscribe"})));
          if (is_moderated && !isAdmin(id)) {
            repository.setData(getComponentId(), id, moderated_key, moderated_true);
            addOutPacket(new Packet(new Element("message",
                  new Element[] {
                    new Element("body",
                      "Your subscription to the gateway needs administrator approval."
                      + " You will be notified when your request has been processed"
                      + " and you will be able to use the gateway since then." )
                  },
                  new String[] {"to", "from", "type", "id"},
                  new String[] {id, packet.getElemTo(), "chat", "gw-ap-1"})));
            sendToAdmins(new Element("message",
                new Element[] {
                  new Element("body",
                    "Gateway subscription request is awaiting for: " + id)
                },
                new String[] {"from", "type", "id"},
                new String[] {packet.getElemTo(), "chat", "gw-ap-1"}));
          } else {
View Full Code Here

          sharedSessionData.put(accept_jid + "-dialback-key",
            packet.getElemCData());
          initServiceMapping(local_hostname, remote_hostname, accept_jid, serv);

          // <db:result> with CDATA containing KEY
          Element elem = new Element("db:verify", packet.getElemCData(),
            new String[] {"id", "to", "from", "xmlns:db"},
            new String[] {(String)serv.getSessionData().get(serv.SESSION_ID_KEY),
                          packet.getElemFrom(),
                          packet.getElemTo(),
                          DIALBACK_XMLNS});
          Packet result = new Packet(elem);
          result.setTo(connect_jid);
          results.offer(result);
        } else {
          // Incorrect dialback packet, it happens for some servers....
          // I don't know yet what software they use.
          // Let's just disconnect and signal unrecoverable conection error
          log.finer("Incorrect diablack packet: " + packet.getStringData());
          bouncePacketsBack(Authorization.SERVICE_UNAVAILABLE, connect_jid);
          generateStreamError("bad-format", serv);
        }
      } else {
        // <db:result> with type 'valid' or 'invalid'
        // It means that session has been validated now....
        XMPPIOService connect_serv = handshakingByHost_Type.get(connect_jid);
        switch (packet.getType()) {
        case valid:
          log.finer("Connection: " + connect_jid
            + " is valid, adding to available services.");
          servicesByHost_Type.put(connect_jid, connect_serv);
          handshakingByHost_Type.remove(connect_jid);
          connectingByHost_Type.remove(connect_jid);
          waitingControlPackets.remove(connect_jid);
          handleDialbackSuccess(connect_jid);
          break;
        default:
          log.finer("Connection: " + connect_jid + " is invalid!! Stopping...");
          connect_serv.stop();
          break;
        } // end of switch (packet.getType())
      } // end of if (packet.getType() != null) else
    } // end of if (packet != null && packet.getElemName().equals("db:result"))

    // <db:verify> with type 'valid' or 'invalid'
    if (packet.getElemName().equals("verify")) {
      if (packet.getType() == null) {
        // When type is NULL then it means this packet contains
        // data for verification
        if (packet.getElemId() != null && packet.getElemCData() != null) {
          // This might be the first dialback packet from remote server
          initServiceMapping(local_hostname, remote_hostname, accept_jid, serv);

          // Yes data for verification are available in packet
          final String id = packet.getElemId();
          final String key = packet.getElemCData();

          final String local_key =
            (String)sharedSessionData.get(connect_jid+"-dialback-key");

          log.fine("Local key for cid=" + connect_jid + " is " + local_key);

          Element result_el = new Element("db:verify",
            new String[] {"to", "from", "id", "xmlns:db"},
            new String[] {packet.getElemFrom(), packet.getElemTo(),
                          packet.getElemId(), DIALBACK_XMLNS});
          Packet result = new Packet(result_el);

          if (key.equals(local_key)) {
            log.finer("Verification for " + accept_jid
              + " succeeded, sending valid.");
            result_el.setAttribute("type", "valid");
            //result = packet.swapElemFromTo(StanzaType.valid);
          } else {
            log.finer("Verification for " + accept_jid
              + " failed, sending invalid.");
            result_el.setAttribute("type", "invalid");
            //result = packet.swapElemFromTo(StanzaType.invalid);
          } // end of if (key.equals(local_key)) else
          result.setTo(accept_jid);
          log.finest("Adding result packet: " + result.getStringData()
            + " to " + result.getTo());
          results.offer(result);
        } // end of if (packet.getElemName().equals("db:verify"))
      else {
        // Type is not null so this is packet with verification result.
        // If the type is valid it means accept connection has been
        // validated and we can now receive data from this channel.

        Element elem = new Element("db:result",
          new String[] {"type", "to", "from", "xmlns:db"},
          new String[] {packet.getType().toString(),
                        packet.getElemFrom(), packet.getElemTo(),
                        DIALBACK_XMLNS});

        XMPPIOService accept_serv = handshakingByHost_Type.remove(accept_jid);
        if (accept_serv == null) {
          accept_serv = servicesByHost_Type.get(accept_jid);
        } else {
          connectingByHost_Type.remove(accept_jid);
          waitingControlPackets.remove(accept_jid);
        }

        if (accept_serv == null) {
          // UPS, no such connection do send a packet, I give up
          log.fine("Connection closed before handshaking completed: "
            + accept_jid
            + ", can't send packet: " + elem.toString());
          return;
        }
        try {
          writeRawData(accept_serv, elem.toString());
          //accept_serv.writeRawData(elem.toString());
          switch (packet.getType()) {
          case valid:
            log.finer("Received " + packet.getType().toString()
              + " validation result, adding connection to active services.");
View Full Code Here

TOP

Related Classes of tigase.xml.Element

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.