Examples of XMPPIOService


Examples of tigase.xmpp.XMPPIOService

          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.");
            servicesByHost_Type.put(accept_jid, accept_serv);
            break;
          default:
            // Ups, verification failed, let's stop the service now.
            log.finer("Received " + packet.getType().toString()
              + " validation result, stopping service, closing connection.");
            writeRawData(accept_serv, "</stream:stream>");
            //accept_serv.writeRawData("</stream:stream>");
            accept_serv.stop();
            break;
          }
        } catch (Exception e) {
          accept_serv.stop();
        }

      } // end of if (packet.getType() == null) else
    } // end of if (packet != null && packet.getType() != null)
View Full Code Here

Examples of tigase.xmpp.XMPPIOService

  protected long getMaxInactiveTime() {
    return 15*MINUTE;
  }

  protected XMPPIOService getXMPPIOServiceInstance() {
    return new XMPPIOService();
  }
View Full Code Here

Examples of tigase.xmpp.XMPPIOService

  public String getDBKey(String sessionId) {
    return db_keys.get(sessionId);
  }

  public synchronized void addOutgoing(XMPPIOService serv) {
    XMPPIOService old = outgoing;
    if (outgoing != serv) {
      outgoing = serv;
      conn_state = OutgoingState.HANDSHAKING;
    }
    if (old != null) {
      log.warning("Old outgoing connection replaced with new one!");
      old.forceStop();
    }
  }
View Full Code Here

Examples of tigase.xmpp.XMPPIOService

  public boolean isIncomingValid(String session_id) {
    if (session_id == null) {
      return false;
    }
    XMPPIOService serv = incoming.get(session_id);
    if (serv == null || serv.getSessionData().get("valid") == null) {
      return false;
    } else {
      return (Boolean)serv.getSessionData().get("valid");
    }
  }
View Full Code Here

Examples of tigase.xmpp.XMPPIOService

      }
      break;
    case accept:
      String session_id = (String)serv.getSessionData().get(serv.SESSION_ID_KEY);
      if (session_id != null) {
        XMPPIOService rem = incoming.remove(session_id);
        if (rem == null) {
          log.fine("No service with given SESSION_ID: " + session_id);
        } else {
          log.finer("Connection removed: " + session_id);
        }
View Full Code Here

Examples of tigase.xmpp.XMPPIOService

    } // end of if (packet != null && packet.getType() != null)

  }

  public boolean sendToIncoming(String session_id, Packet packet) {
    XMPPIOService serv = incoming.get(session_id);
    if (serv != null) {
      log.finest("Sending to incoming connectin: " + session_id
        + " packet: " + packet.toString());
      return writePacketToSocket(serv, packet);
    } else {
View Full Code Here

Examples of tigase.xmpp.XMPPIOService

      return false;
    }
  }

  public void validateIncoming(String session_id, boolean valid) {
    XMPPIOService serv = incoming.get(session_id);
    if (serv != null) {
      serv.getSessionData().put("valid", valid);
      if (!valid) {
        serv.stop();
      }
    }
  }
View Full Code Here

Examples of tigase.xmpp.XMPPIOService

  protected long getMaxInactiveTime() {
    return 15*MINUTE;
  }

  protected XMPPIOService getXMPPIOServiceInstance() {
    return new XMPPIOService();
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.