Package tigase.server

Examples of tigase.server.Packet


    }
  }

  public void handleDialbackSuccess(final String connect_jid) {
    log.finest("handleDialbackSuccess: connect_jid="+connect_jid);
    Packet p = null;
    XMPPIOService serv = servicesByHost_Type.get(connect_jid);
    ServerPacketQueue waiting = waitingPackets.remove(connect_jid);
    if (waiting != null) {
      while ((p = waiting.poll()) != null) {
        log.finest("Sending packet: " + p.getStringData());
        writePacketToSocket(serv, p);
      } // end of while (p = waitingPackets.remove(ipAddress) != null)
    } // end of if (waiting != null)
  }
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." )
View Full Code Here

        }
        if (!pres_show.equals("null")) {
          Element show = new Element("show", pres_show);
          pres_el.addChild(show);
        }
        Packet presence = new Packet(pres_el);
        log.finest("Sending out presence: " + presence.toString());
        addOutPacket(presence);
      }
      if (packet.getType() == StanzaType.subscribe) {
        addOutPacket(packet.swapElemFromTo(StanzaType.subscribe));
        String buddy = decodeLegacyName(packet.getElemTo());
        log.fine("Received subscribe presence for: " + buddy);
        String nick = JIDUtils.getNodeNick(buddy);
        if (nick == null || nick.isEmpty()) {
          nick = buddy;
        }
        GatewayConnection conn = findConnection(packet, true);
        if (conn != null) {
          try {
            conn.addBuddy(buddy, nick);
            log.fine("Added to roster buddy: " + buddy);
          } catch (GatewayException e) {
            log.log(Level.WARNING, "Problem with gateway when adding buddy: "
              + buddy, e);
          }
        }
      }
      if (packet.getType() == StanzaType.unsubscribe) {
        Packet presence = packet.swapElemFromTo(StanzaType.unsubscribe);
        log.finest("Sending out presence: " + presence.toString());
        addOutPacket(presence);
      }
      if (packet.getType() == StanzaType.unsubscribed) {
        addOutPacket(packet.swapElemFromTo(StanzaType.unsubscribe));
        addOutPacket(packet.swapElemFromTo(StanzaType.unsubscribed));
View Full Code Here

            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
View Full Code Here

    String id = JIDUtils.getNodeID(packet.getElemFrom());
    GatewayConnection conn = gw_connections.get(id);
    if (conn != null || !create) {
      if (conn != null) {
        conn.addJid(packet.getElemFrom());
        addOutPacket(new Packet(new Element(PRESENCE_ELNAME,
              new String[] {"from", "to"},
              new String[] {getComponentId(), packet.getElemFrom()})));
        updateRosterPresence(conn.getRoster(), packet.getElemFrom());
      }
      return conn;
View Full Code Here

  }

  public void logout(GatewayConnection gc) {
    String[] jids = gc.getAllJids();
    for (String username: jids) {
      addOutPacket(new Packet(new Element(PRESENCE_ELNAME,
            new String[] {"from", "to", "type"},
            new String[] {getComponentId(), username, "unavailable"})));
      List<RosterItem> roster = gc.getRoster();
      for (RosterItem item: roster) {
        String from = formatJID(item.getBuddyId());
        Element pres_el = new Element(PRESENCE_ELNAME,
          new String[] {"to", "from", "type"},
          new String[] {username, from, "unavailable"});
        Packet presence = new Packet(pres_el);
        log.finest("Sending out presence: " + presence.toString());
        addOutPacket(presence);
      }
    }
    gw_connections.remove(JIDUtils.getNodeID(jids[0]));
  }
View Full Code Here

  }

  public void loginCompleted(GatewayConnection gc) {
    String[] jids = gc.getAllJids();
    for (String username: jids) {
      addOutPacket(new Packet(new Element(PRESENCE_ELNAME,
            new String[] {"from", "to"},
            new String[] {getComponentId(), username})));
    }
  }
View Full Code Here

        }
        if (item.getStatus().getShow() != null) {
          Element show = new Element("show", item.getStatus().getShow());
          pres_el.addChild(show);
        }
        Packet presence = new Packet(pres_el);
        log.finest("Sending out presence: " + presence.toString());
        addOutPacket(presence);
      }
    }
  }
View Full Code Here

      } catch (TigaseDBException e) {
        log.log(Level.WARNING, "Problem updating repository data", e);
      }

      for (String username: jids) {
        Packet presence = new Packet(new Element(PRESENCE_ELNAME,
            new String[] {"to", "from", "type"},
            new String[] {username, from, "subscribe"}));
        log.finest("Sending out presence: " + presence.toString());
        addOutPacket(presence);
      }
    }
    updateRosterPresence(roster, jids);
  }
View Full Code Here

      }
      if (item.getStatus().getShow() != null) {
        Element show = new Element("show", item.getStatus().getShow());
        pres_el.addChild(show);
      }
      Packet presence = new Packet(pres_el);
      log.finest("Sending out presence: " + presence.toString());
      addOutPacket(presence);
    }
  }
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.