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