// }
if ((id.equals(session.getDomain())
|| id.equals(session.getUserId()))
&& packet.getFrom().equals(session.getConnectionId())) {
Authorization result = Authorization.NOT_AUTHORIZED;
Element request = packet.getElement();
StanzaType type = packet.getType();
switch (type) {
case set:
// Is it registration cancel request?
Element elem = request.findChild("/iq/query/remove");
if (elem != null) {
// Yes this is registration cancel request
// According to JEP-0077 there must not be any
// more subelemets apart from <remove/>
elem = request.findChild("/iq/query");
if (elem.getChildren().size() > 1) {
result = Authorization.BAD_REQUEST;
} else {
try {
result = session.unregister(packet.getElemFrom());
results.offer(packet.okResult((String)null, 0));
results.offer(Command.CLOSE.getPacket(session.getDomain(),
session.getConnectionId(), StanzaType.set,
session.nextStanzaId()));
} catch (NotAuthorizedException e) {
results.offer(Authorization.NOT_AUTHORIZED.getResponseMessage(packet,
"You must authorize session first.", true));
} // end of try-catch
}
} else {
// No, so assuming this is registration of new
// user or change registration details for existing user
String user_name = request.getChildCData("/iq/query/username");
String password = request.getChildCData("/iq/query/password");
String email = request.getChildCData("/iq/query/email");
result = session.register(user_name, password, email);
if (result == Authorization.AUTHORIZED) {
results.offer(result.getResponseMessage(packet, null, false));
} else {
results.offer(result.getResponseMessage(packet,
"Unsuccessful registration attempt", true));
}
}
break;
case get: