Package tigase.server

Examples of tigase.server.Packet


  private Packet parseXMLData(String data, Packet packet) {
    DomBuilderHandler domHandler = new DomBuilderHandler();
    parser.parse(domHandler, data.toCharArray(), 0, data.length());
    Queue<Element> elems = domHandler.getParsedElements();
    Packet result = packet.okResult((Element)null, 1);
    Element query = result.getElement().findChild("/iq/query");
    for (Element el: elems) {
      query.addChild(el);
    } // end of for (Element el: elems)
    return result;
  }
View Full Code Here


      char[] data = sb.toString().toCharArray();
      parser.parse(domHandler, data, 0, data.length);
      Queue<Element> elems = domHandler.getParsedElements();
      Element elem = null;
      while ((elem = elems.poll()) != null) {
        pacs.offer(new Packet(elem));
      } // end of while (elem = elems.poll() != null)
      try {
        Collections.sort(pacs, new StampComparator());
      } catch (NullPointerException e) {
        try {
View Full Code Here

          } // end of else
          break;
        case result:
        case error:
          Element elem = packet.getElement().clone();
          Packet result = new Packet(elem);
          result.setTo(session.getConnectionId());
          result.setFrom(packet.getTo());
          results.offer(result);
          break;
        default:
          results.offer(Authorization.BAD_REQUEST.getResponseMessage(packet,
              "Request type is incorrect", false));
          break;
        } // end of switch (type)
      } else {
        Element result = packet.getElement().clone();
        // According to spec we must set proper FROM attribute
        //        result.setAttribute("from", session.getJID());
        results.offer(new Packet(result));
      } // end of else
    } catch (NotAuthorizedException e) {
      e.printStackTrace();
      log.warning(
        "Received vCard request but user session is not authorized yet: " +
View Full Code Here

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

    Packet result = packet.commandResult("result");
    switch (packet.getCommand()) {
      case VHOSTS_RELOAD:
        repo.reload();
        addCompletedVHostsField(result);
        results.offer(result);
View Full Code Here

  private Packet parseXMLData(String data, Packet packet) {
    DomBuilderHandler domHandler = new DomBuilderHandler();
    parser.parse(domHandler, data.toCharArray(), 0, data.length());
    Queue<Element> elems = domHandler.getParsedElements();
    Packet result = packet.okResult((Element)null, 0);
    for (Element el: elems) {
      result.getElement().addChild(el);
    } // end of for (Element el: elems)
    return result;
  }
View Full Code Here

            }
          }
        }

        Element elem = packet.getElement().clone();
        Packet result = new Packet(elem);
        result.setTo(session.getConnectionId());
        result.setFrom(packet.getTo());
        results.offer(result);
      } else {
        // This is message to some other client
        Element result = packet.getElement().clone();
        results.offer(new Packet(result));
      } // end of else
    } catch (NotAuthorizedException e) {
      log.warning("NotAuthorizedException for packet: "  + packet.getStringData());
      results.offer(Authorization.NOT_AUTHORIZED.getResponseMessage(packet,
          "You must authorize session first.", true));
View Full Code Here

  protected void processPacket(ClusterElement packet) {
    List<Element> elems = packet.getDataPackets();
    //String packet_from = packet.getDataPacketFrom();
    if (elems != null && elems.size() > 0) {
      for (Element elem: elems) {
        Packet el_packet = new Packet(elem);
        //processPacket(el_packet);
        //el_packet.setFrom(packet_from);
        XMPPResourceConnection conn = getXMPPResourceConnection(el_packet);
        if (conn != null || !sentToNextNode(packet)) {
          if (conn != null) {
            switch (conn.getConnectionStatus()) {
            case ON_HOLD:
              LinkedList<Packet> packets =
              (LinkedList<Packet>)conn.getSessionData(SESSION_PACKETS);
              if (packets == null) {
                packets = new LinkedList<Packet>();
                conn.putSessionData(SESSION_PACKETS, packets);
              }
              packets.offer(el_packet);
              log.finest("Packet put on hold: " + el_packet.toString());
              return;
            case REDIRECT:
              el_packet.setTo((String)conn.getSessionData("redirect-to"));
              fastAddOutPacket(el_packet);
              log.finest("Packet redirected: " + el_packet.toString());
              return;
            }
          }
          processPacket(el_packet, conn);
        }
View Full Code Here

              if (conn != null) {
                Map<String, String> res_vals = new LinkedHashMap<String, String>();
                res_vals.put(TRANSFER, "accept");
                ClusterElement result = clel.createMethodResponse(getComponentId(),
                  node_found, "result", res_vals);
                fastAddOutPacket(new Packet(result.getClusterElement()));
                conn.putSessionData("redirect-to", node_found);
                sendAllOnHold(conn);

                String xmpp_sessionId = clel.getMethodParam(XMPP_SESSION_ID);
                Packet redirect = Command.REDIRECT.getPacket(node_found,
                  connectionId, StanzaType.set, "1", "submit");
                Command.addFieldValue(redirect, "session-id", xmpp_sessionId);
                fastAddOutPacket(redirect);
              } else {
                // Ups, the user has disconnected, send session transfer to all
                log.finest("Addeding node to cancel_nodes: " + node_found);
                cancel_nodes.add(node_found);
                log.fine("The user connection doesn't exist: " + userId
                  + ", connectionId: " + connectionId);
              }
            } else {
              // Ups, the user has disconnected, send session transfer to all
              log.finest("Addeding node to cancel_nodes: " + node_found);
              cancel_nodes.add(node_found);
              log.fine("The user session doesn't exist: " + userId);
            }
          } else {
            // Set status to NORMALL, user is not logged in on any other node.
            if (conn != null) {
              log.finest("Set status to NORMAL and send all ON_HOLD");
              conn.setConnectionStatus(ConnectionStatus.NORMAL);
              sendAllOnHold(conn);
            } else {
              log.fine("The user connection doesn't exist: " + userId
                + ", connectionId: " + connectionId);
            }
          }
          if (cancel_nodes.size() > 0) {
            // Send session transfer to all.
            Map<String, String> res_vals = new LinkedHashMap<String, String>();
            res_vals.put(TRANSFER, "cancel");
            for (String node: cancel_nodes) {
              ClusterElement result = clel.createMethodResponse(getComponentId(),
                node, "result", res_vals);
              log.finest("Sending sesstion transfer CANCEL to node: " + node);
              fastAddOutPacket(new Packet(result.getClusterElement()));
            }
          }
        } else {
          // A request from some other node, maybe the user session should be
          // transfered here...
          ClusterElement result = ClusterElement.createForNextNode(clel,
            cluster_nodes,  getComponentId());
          if (session != null) {
            conn = session.getOldestConnection();
            boolean transfer_in = false;
            switch (conn.getConnectionStatus()) {
            case ON_HOLD:
              long local_auth_time = conn.getAuthTime();
              long remote_auth_time = clel.getMethodParam(AUTH_TIME, 0L);
              if (local_auth_time == remote_auth_time) {
                transfer_in = (conn.getSessionId().hashCode() >
                  clel.getMethodParam(XMPP_SESSION_ID).hashCode());
              } else {
                transfer_in = (local_auth_time > remote_auth_time);
              }
              break;
            case REDIRECT:
              transfer_in = false;
              break;
            case NORMAL:
              transfer_in = true;
              break;
            default:
              break;
            }
            if (transfer_in) {
              addTempSession(clel);
              result.addMethodResult(getComponentId() + "-" + AUTH_TIME,
                "" + conn.getAuthTime());
              result.addMethodResult(getComponentId() + "-HASH-" + XMPP_SESSION_ID,
                "" + conn.getSessionId().hashCode());
              result.addMethodResult(getComponentId() + "-STATUS",
                "" + conn.getConnectionStatus());
              result.addMethodResult(getComponentId() + "-CREATED",
                "" + true);
            }
          } else {
            // Do nothing really, just forward the request to a next node
          }
          fastAddOutPacket(new Packet(result.getClusterElement()));
        }
      }
      break;
    case result:
      if (ClusterMethods.SESSION_TRANSFER.toString().equals(clel.getMethodName())) {
        String transfer = clel.getMethodResultVal(TRANSFER);
        if (transfer == null) {
          log.warning("Incorrect response for the session transfer: "
            + packet.toString());
          return;
        }
        if (transfer.equals("accept")) {
          String userId = clel.getMethodParam(USER_ID);
          XMPPSession session = getSession(userId);
          if (session == null) {
            // Ups, something wrong happened, let's record this in the log
            // file for now...
            log.warning("User session does not exist for the request to complete the user transfer: " + packet.toString());
            return;
          }
          String connectionId = clel.getMethodParam(CONNECTION_ID);
          XMPPResourceConnection conn =
            session.getResourceForConnectionId(connectionId);
          if (conn == null) {
            // Ups, something wrong happened, let's record this in the log
            // file for now...
            log.warning("User connection does not exist for the request to complete the user transfer: " + packet.toString());
            return;
          }
          String token = (String)conn.getSessionData(TOKEN);
          String xmpp_sessionId = conn.getSessionId();
          Authorization auth_res = null;
          try {
            auth_res = conn.loginToken(xmpp_sessionId, token);
          } catch (Exception e) {
            log.log(Level.WARNING, "Token authentication unsuccessful.", e);
            auth_res = Authorization.NOT_AUTHORIZED;
          }
          if (auth_res == Authorization.AUTHORIZED) {
            log.finest("SESSION_TRANSFER received SET request, userId: " + userId
              + ", xmpp_sessionId: " + xmpp_sessionId
              + ", connectionId: " + connectionId + ", auth_res: " + auth_res);
          } else {
            log.finest("SESSION_TRANSFER authorization failed: " + auth_res
              + ", userId: " + userId);
            closeConnection(conn.getConnectionId(), true);
            Packet close = Command.CLOSE.getPacket(getComponentId(),
              connectionId, StanzaType.set, "1");
            fastAddOutPacket(close);
          }
          conn.setConnectionStatus(ConnectionStatus.NORMAL);
//           Packet redirect = Command.REDIRECT.getPacket(getComponentId(),
View Full Code Here

  protected boolean sentToNextNode(ClusterElement clel) {
    ClusterElement next_clel = ClusterElement.createForNextNode(clel,
      cluster_nodes, getComponentId());
    if (next_clel != null) {
      fastAddOutPacket(new Packet(next_clel.getClusterElement()));
      return true;
    } else {
      return false;
    }
  }
View Full Code Here

      String cluster_node = getFirstClusterNode();
      if (cluster_node != null) {
        ClusterElement clel = new ClusterElement(sess_man_id, cluster_node,
          StanzaType.set, packet);
        clel.addVisitedNode(sess_man_id);
        fastAddOutPacket(new Packet(clel.getClusterElement()));
        return true;
      }
    }
    return false;
  }
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.