// <db:result> with CDATA containing KEY
Element elem = new Element(DB_VERIFY_EL_NAME, db_key,
new String[] {"id", "to", "from", XMLNS_DB_ATT},
new String[] {session_id, remote_hostname, local_hostname,
XMLNS_DB_VAL});
Packet result = new Packet(elem);
if (serv_conns == null) {
serv_conns = createNewServerConnections(cid, null);
}
//serv_conns.putDBKey(session_id, db_key);
serv.getSessionData().put("remote-hostname", remote_hostname);
serv.getSessionData().put("local-hostname", local_hostname);
log.finest("cid: " + cid + ", sessionId: " + session_id
+ ", Counters: ioservices: " + countIOServices()
+ ", s2s connections: " + countOpenConnections());
if (!serv_conns.sendControlPacket(result)
&& serv_conns.needsConnection()) {
createServerConnection(cid, result, serv_conns);
}
} 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, cid);
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: " + cid
+ " is valid, adding to available services.");
serv_conns.handleDialbackSuccess();
break;
default:
log.finer("Connection: " + cid + " is invalid!! Stopping...");
serv_conns.handleDialbackFailure();
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() == VERIFY_EL_NAME)
|| (packet.getElemName() == DB_VERIFY_EL_NAME)) {
if (packet.getElemId() != null) {
String forkey_session_id = packet.getElemId();
if (packet.getType() == null) {
// When type is NULL then it means this packet contains
// data for verification
if (packet.getElemId() != null && packet.getElemCData() != null) {
String db_key = packet.getElemCData();
// This might be the first dialback packet from remote server
// serv.getSessionData().put("remote-hostname", remote_hostname);
// serv.getSessionData().put("local-hostname", local_hostname);
// serv_conns.addIncoming(session_id, serv);
// log.finest("cid: " + cid + ", sessionId: " + session_id
// + ", Counters: ioservices: " + countIOServices()
// + ", s2s connections: " + countOpenConnections());
//initServiceMapping(local_hostname, remote_hostname, accept_jid, serv);
String local_key = getLocalDBKey(cid, db_key, forkey_session_id,
session_id);
if (local_key == null) {
log.fine("db key is not availablefor session ID: " + forkey_session_id
+ ", key for validation: " + db_key);
} else {
log.fine("Local key for cid=" + cid + " is " + local_key);
sendVerifyResult(local_hostname, remote_hostname, forkey_session_id,
db_key.equals(local_key), serv_conns, session_id);
}
} // 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_EL_NAME,
new String[] {"type", "to", "from", XMLNS_DB_ATT},
new String[] {packet.getType().toString(),
remote_hostname, local_hostname,
XMLNS_DB_VAL});
sendToIncoming(forkey_session_id, new Packet(elem));
validateIncoming(forkey_session_id,
(packet.getType() == StanzaType.valid));
} // end of if (packet.getType() == null) else
} else {