Package tigase.server

Examples of tigase.server.Packet


    Packet packet, String errorMsg) throws IOException {
    String code = "<body type='terminate'"
      + " condition='item-not-found'"
      + " xmlns='http://jabber.org/protocol/httpbind'/>";
    try {
      Packet error = errorCode.getResponseMessage(packet, errorMsg, false);
      code = error.getElement().toString();
    } catch (PacketErrorTypeException e) {
      // ignore
    }
    StringBuilder sb = new StringBuilder();
    sb.append("HTTP/1.1 " + errorCode.getErrorCode() + " " + errorMsg + EOL);
View Full Code Here


  public synchronized boolean handleDialbackSuccess() {
    if (outgoing != null && conn_state == OutgoingState.HANDSHAKING) {
      setValid();
      LinkedList<Packet> all = new LinkedList<Packet>();
      Packet packet = null;
      while ((packet = waitingControlPackets.poll()) != null) {
        all.offer(packet);
      }
      sentPackets += waitingPackets.size();
      while ((packet = waitingPackets.poll()) != null) {
View Full Code Here

      // It doesn't look good, there should reaaly be a connection for
      // this packet....
      // returning error back...
      log.info("Broken packet: " + p.toString());
      try {
        Packet error =
            Authorization.SERVICE_UNAVAILABLE.getResponseMessage(p,
              "Service not available.", true);
        error.setTo(p.getFrom());
        fastAddOutPacket(error);
      } catch (PacketErrorTypeException e) {
        log.warning("Packet processing exception: " + e);
      }
      return true;
View Full Code Here

    if (!packet.wasProcessed()) {
      if (log.isLoggable(Level.FINEST)) {
        log.finest("Packet not processed: " + packet.toString());
      }
      Packet error = null;
      if (stop
        || (conn == null
          && packet.getElemFrom() != null && packet.getElemTo() != null
          && packet.getElemTo() != getComponentId()
          && (packet.getElemName().equals("iq")
            || packet.getElemName().equals("message")))) {
        try {
          error =  Authorization.SERVICE_UNAVAILABLE.getResponseMessage(packet,
            "Service not available.", true);
        } catch (PacketErrorTypeException e) {
          log.warning("Packet processing exception: " + e
            + ", packet: " + packet.toString());
        }
      } else {
        if (packet.getElemFrom() != null || conn != null) {
          try {
            error = Authorization.FEATURE_NOT_IMPLEMENTED.getResponseMessage(packet,
              "Feature not supported yet.", true);
          } catch (PacketErrorTypeException e) {
            log.warning("Packet processing exception: " + e
              + ", packet: " + packet.toString());
          }
        }
      }
      if (error != null) {
        if (error.getElemTo() != null) {
          conn = getResourceConnection(error.getElemTo());
        } // end of if (error.getElemTo() != null)
        if (conn != null) {
          error.setTo(conn.getConnectionId());
        } // end of if (conn != null)
        addOutPacket(error);
      }
    } else {
      log.finest("Packet processed by: " + packet.getProcessorsIds().toString());
View Full Code Here

        // Yes this packet is for admin....
        log.finer("Packet for admin: " + packet.getStringData());
        sendToAdmins(packet);
      } else {
        log.finer("Packet for hostname: " + packet.getStringData());
        Packet host_pac =
          new Packet(packet.getElement().clone());
        host_pac.getElement().setAttribute("to", getComponentId());
        host_pac.getElement().setAttribute(Packet.OLDTO, packet.getElemTo());
        processPacket(host_pac);
      }
      return true;
    } // end of if (isInRoutings(to))
    return false;
View Full Code Here

  }

  protected void sendToAdmins(Packet packet) {
    for (String admin: admins) {
      log.finer("Sending packet to admin: " + admin);
      Packet admin_pac =
        new Packet(packet.getElement().clone());
      admin_pac.getElement().setAttribute("to", admin);
      processPacket(admin_pac);
    }
  }
View Full Code Here

      break;
    case GETFEATURES:
      if (pc.getType() == StanzaType.get) {
        List<Element> features =
          getFeatures(connectionsByFrom.get(pc.getFrom()));
        Packet result = pc.commandResult(null);
        Command.setData(result, features);
        addOutPacket(result);
      } // end of if (pc.getType() == StanzaType.get)
      processing_result = true;
      break;
    case STREAM_CLOSED:
      closeConnection(pc.getFrom(), false);
      processing_result = true;
      break;
    case BROADCAST_TO_ONLINE:
      String from = pc.getFrom();
      boolean trusted = false;
      try {
        trusted = (from != null && isTrusted(from))
          || (connection != null && isTrusted(connection.getUserId()));
      } catch (NotAuthorizedException e) {
        trusted = false;
      }
      try {
        if (trusted) {
          List<Element> packets = Command.getData(pc);
          if (packets != null) {
            for (XMPPResourceConnection conn: connectionsByFrom.values()) {
              if (conn.isAuthorized()) {
                try {
                  for (Element el_pack: packets) {
                    Element el_copy = el_pack.clone();
                    el_copy.setAttribute("to", conn.getJID());
                    Packet out_packet = new Packet(el_copy);
                    out_packet.setTo(conn.getConnectionId());
                    addOutPacket(out_packet);
                  }
                } catch (NotAuthorizedException e) {
                  log.warning("Something wrong, connection is authenticated but "
                    + "NoAuthorizedException is thrown.");
                }
              }
            }
          } else {
            addOutPacket(Authorization.BAD_REQUEST.getResponseMessage(pc,
                "Missing packets for broadcast.", true));
          }
        } else {
          addOutPacket(Authorization.FORBIDDEN.getResponseMessage(pc,
              "You don't have enough permission to brodcast packet.", true));
        }
      } catch (PacketErrorTypeException e) {
        log.warning("Packet processing exception: " + e
          + ", packet: " + pc.toString());
      }
      processing_result = true;
      break;
    case USER_STATUS:
      try {
        if (isTrusted(pc.getElemFrom())
          || isTrusted(JIDUtils.getNodeHost(pc.getElemFrom()))) {
          String av = Command.getFieldValue(pc, "available");
          boolean available = !(av != null && av.equalsIgnoreCase("false"));
          if (available) {
            Packet presence = null;
            Element p = pc.getElement().getChild("command").getChild("presence");
            if (p != null) {
// +              // use this hack to break XMLNS
// +              Element el = new Element("presence");
// +              el.setChildren(p.getChildren());
              Element elem = p.clone();
              elem.setXMLNS("jabber:client");
              presence = new Packet(elem);
            }
            connection = connectionsByFrom.get(pc.getElemFrom());
            if (connection == null) {
              String user_jid = Command.getFieldValue(pc, "jid");
              String hostname = JIDUtils.getNodeHost(user_jid);
              connection = createUserSession(pc.getElemFrom(), hostname, user_jid);
              connection.setSessionId("USER_STATUS");
              user_repository.setData(JIDUtils.getNodeID(user_jid), "tokens",
                "USER_STATUS", "USER_STATUS");
              connection.loginToken("USER_STATUS", "USER_STATUS");
              handleLogin(user_jid, connection);
              connection.putSessionData("jingle", "active");
              addOutPacket(pc.okResult((String)null, 0));
              if (presence == null) {
                presence =
                  new Packet(new Element("presence",
                      new Element[] {
                        new Element("priority", "-1"),
                        new Element("c",
                          new String[] {"node", "ver", "ext", "xmlns"},
                          new String[] {"http://www.google.com/xmpp/client/caps",
                                        XMPPServer.getImplementationVersion(),
                                        "voice-v1",
                                        "http://jabber.org/protocol/caps"})},
                      null, null));
              }
            } else {
//               addOutPacket(Authorization.CONFLICT.getResponseMessage(pc,
//                   "The user resource already exists.", true));
              log.finest("USER_STATUS set to true for user who is already available: "
                + pc.toString());
            }
            if (presence != null) {
              presence.setFrom(pc.getElemFrom());
              presence.setTo(getComponentId());
              addOutPacket(presence);
            }
          } else {
            connection = connectionsByFrom.remove(pc.getElemFrom());
            if (connection != null) {
View Full Code Here

    LinkedList<Packet> packets =
      (LinkedList<Packet>)conn.getSessionData(SESSION_PACKETS);
    if (remote_smId == null) {
      log.finest("No address for remote SM to redirect packets, processing locally.");
      if (packets != null) {
        Packet sess_pack = null;
        while ((sess_pack = packets.poll()) != null) {
          processPacket(sess_pack);
        }
      }
      return;
    }
    conn.setConnectionStatus(ConnectionStatus.REDIRECT);
    if (packets != null) {
      Packet sess_pack = null;
      while ((sess_pack = packets.poll()) != null) {
        sess_pack.setTo(remote_smId);
        fastAddOutPacket(sess_pack);
      }
    }
  }
View Full Code Here

    return super.addOutPacket(packet);
  }

  @Override
  protected boolean addOutPackets(Queue<Packet> packets) {
    Packet packet = null;
    while ((packet = packets.poll()) != null) {
      addOutPacket(packet);
    }
    return true;
  }
View Full Code Here

      id = JIDUtils.getNodeID(packet.getElemTo());
      if (id.equals(session.getUserId())) {
        // Yes this is message to 'this' client
        log.finest("Yes, this is packet to 'this' client: " + id);
        Element elem = packet.getElement().clone();
        Packet result = new Packet(elem);
        result.setTo(session.getConnectionId(packet.getElemTo()));
        log.finest("Setting to: " + result.getTo());
        result.setFrom(packet.getTo());
        results.offer(result);
        return true;
      } // end of else

      id = JIDUtils.getNodeID(packet.getElemFrom());
      if (id.equals(session.getUserId())) {
        Element result = packet.getElement().clone();
        results.offer(new Packet(result));
        return true;
      }
    } catch (NotAuthorizedException e) {
      try {
        results.offer(Authorization.NOT_AUTHORIZED.getResponseMessage(packet,
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.