if ( password.indexOf(' ' ) != -1
|| password.indexOf('\t') != -1
|| password.indexOf('\r') != -1
|| password.indexOf('\n') != -1)
{
throw new MessagingNetworkException("MSN password cannot contain whitespace", MessagingNetworkException.CATEGORY_NOT_CATEGORIZED, MessagingNetworkException.ENDUSER_CANNOT_LOGIN_WRONG_PASSWORD);
}
long plannedAbortTime = System.currentTimeMillis() + 1000 * MSNMessagingNetwork.REQPARAM_SOCKET_TIMEOUT_SECONDS;
if (Defines.DEBUG && CAT.isDebugEnabled()) CAT.debug("connecting to DS "+host+":"+port);
for (;;)
{
if (Thread.currentThread().isInterrupted()) throw new InterruptedException();
ds = new DS(host, port, ctx);
ses.add(ds);
ses.setDS(ds);
ses.setRunning(true);
//7.1 Protocol Versioning
//C: VER TrID dialect-name{ dialect-name...}
//S: VER TrID dialect-name{ dialect-name...}
//S: VER TrID{ dialect-name ... } 0{ dialect-name ... } //failure
ds.start(new Transaction()
{
final String CMD1 = "VER";
public void clientRequest(TransactionContext ctx)
throws IOException, InterruptedException, MessagingNetworkException
{
post(CMD1, PROTOCOL_VERSIONS_STRING, ctx);
}
public void serverResponse(String cmd, String args, TransactionContext ctx, final Session ses, final PluginContext pctx)
throws IOException, InterruptedException, MessagingNetworkException
{
StringTokenizer r = new StringTokenizer(args);
if (!cmd.equals(CMD1)) throwProtocolViolated("cmd must be "+CMD1);
while (r.hasMoreTokens())
{
String dialect = r.nextToken();
if ("0".equals(dialect)) throwProtocolViolated("DS server reported version negotiation failure");
//ignoring all dialect ids != "0"
}
finish();
}
}).waitFor(true, ses, pctx);
ds.start(new Transaction()
{
//7.2 Server Policy Information
//C: INF TrID
//S: INF TrID SP{,SP...}
final String CMD1 = "INF";
public void clientRequest(TransactionContext ctx)
throws IOException, InterruptedException, MessagingNetworkException
{
post(CMD1, "", ctx);
}
public void serverResponse(String cmd, String args, TransactionContext ctx, final Session ses, final PluginContext pctx)
throws IOException, InterruptedException, MessagingNetworkException
{
StringTokenizer r = new StringTokenizer(args);
if (!cmd.equals(CMD1)) throwProtocolViolated("cmd must be "+CMD1);
r = new StringTokenizer(tok(r), ", \t");
if (!r.hasMoreElements()) throwProtocolViolated("DS server did not report server security policy id; cannot proceed");
boolean md5found = false;
while (r.hasMoreElements())
{
String sp = r.nextToken(); //security package
//"MD5" is used by the NS,
//"CKI" by the SS.
if ("MD5".equals(sp))
{
md5found = true;
break;
}
}
if (!md5found) throwProtocolViolated("DS server reported no known security packages; cannot proceed");
finish();
}
}).waitFor(true, ses, pctx);
if (Defines.DEBUG && CAT.isDebugEnabled()) CAT.debug("sending login id");
USRLoginTransaction usrt = new USRLoginTransaction(loginId);
ds.start(usrt).waitFor(true, ses, pctx);
r = usrt.stringTokenizer;
if (usrt.isUSR) break;
ds.close("changing NS server", MessagingNetworkException.CATEGORY_NOT_CATEGORIZED, MessagingNetworkException.ENDUSER_NO_ERROR);
ds = null;
if (System.currentTimeMillis() > plannedAbortTime)
throw new MessagingNetworkException("login timed out", MessagingNetworkException.CATEGORY_NOT_CATEGORIZED, MessagingNetworkException.ENDUSER_LOGGED_OFF_DUE_TO_MESSAGING_OPERATION_TIMEOUT);
HostPort hp = parseReferral(r, "NS");
host = hp.host;
port = hp.port;