if (toValue != null) {
EntityImpl toEntity = null;
try {
toEntity = EntityImpl.parse(toValue);
} catch (EntityFormatException e) {
return new ResponseStanzaContainerImpl(ServerErrorResponses.getInstance().getStreamError(
StreamErrorCondition.IMPROPER_ADDRESSING, sessionContext.getXMLLang(),
"could not parse incoming stanza's TO attribute", null));
}
// TODO check if toEntity is served by this server
// if (!server.doesServe(toEntity)) throw WhateverException();
// TODO RFC3920: 'from' attribute SHOULD be silently ignored by the receiving entity
// TODO RFC3920bis: 'from' attribute SHOULD be not ignored by the receiving entity and used as 'to' in responses
}
responseStanza = new ServerResponses().getStreamOpener(clientCall, sessionContext.getServerJID(),
responseVersion, sessionContext);
} else if (serverCall) {
// RFC3920: 'from' attribute SHOULD be used by the receiving entity
String fromValue = stanza.getAttributeValue("from");
if (fromValue != null) {
EntityImpl entity = null;
try {
entity = EntityImpl.parse(fromValue);
} catch (EntityFormatException e) {
return new ResponseStanzaContainerImpl(ServerErrorResponses.getInstance().getStreamError(
StreamErrorCondition.INVALID_FROM, sessionContext.getXMLLang(),
"could not parse incoming stanza's FROM attribute", null));
}
}
throw new RuntimeException("server connection not yet supported");
} else {
String descriptiveText = "one of the two namespaces must be present: " + NamespaceURIs.JABBER_CLIENT
+ " or " + NamespaceURIs.JABBER_SERVER;
return respondIllegalNamespaceError(descriptiveText);
}
// if all is correct, go to next phase
switch (sessionStateHolder.getState()) {
case AUTHENTICATED:
case ENCRYPTED:
// do not change state!
break;
default:
sessionStateHolder.setState(SessionState.STARTED);
}
if (responseStanza != null)
return new ResponseStanzaContainerImpl(responseStanza);
return null;
}