break;
case GETFEATURES:
if (pc.getType() == StanzaType.get) {
List<Element> features =
getFeatures(connectionsByFrom.get(pc.getFrom()));
Packet result = pc.commandResult(null);
Command.setData(result, features);
addOutPacket(result);
} // end of if (pc.getType() == StanzaType.get)
processing_result = true;
break;
case STREAM_CLOSED:
closeConnection(pc.getFrom(), false);
processing_result = true;
break;
case BROADCAST_TO_ONLINE:
String from = pc.getFrom();
boolean trusted = false;
try {
trusted = (from != null && isTrusted(from))
|| (connection != null && isTrusted(connection.getUserId()));
} catch (NotAuthorizedException e) {
trusted = false;
}
try {
if (trusted) {
List<Element> packets = Command.getData(pc);
if (packets != null) {
for (XMPPResourceConnection conn: connectionsByFrom.values()) {
if (conn.isAuthorized()) {
try {
for (Element el_pack: packets) {
Element el_copy = el_pack.clone();
el_copy.setAttribute("to", conn.getJID());
Packet out_packet = new Packet(el_copy);
out_packet.setTo(conn.getConnectionId());
addOutPacket(out_packet);
}
} catch (NotAuthorizedException e) {
log.warning("Something wrong, connection is authenticated but "
+ "NoAuthorizedException is thrown.");
}
}
}
} else {
addOutPacket(Authorization.BAD_REQUEST.getResponseMessage(pc,
"Missing packets for broadcast.", true));
}
} else {
addOutPacket(Authorization.FORBIDDEN.getResponseMessage(pc,
"You don't have enough permission to brodcast packet.", true));
}
} catch (PacketErrorTypeException e) {
log.warning("Packet processing exception: " + e
+ ", packet: " + pc.toString());
}
processing_result = true;
break;
case USER_STATUS:
try {
if (isTrusted(pc.getElemFrom())
|| isTrusted(JIDUtils.getNodeHost(pc.getElemFrom()))) {
String av = Command.getFieldValue(pc, "available");
boolean available = !(av != null && av.equalsIgnoreCase("false"));
if (available) {
Packet presence = null;
Element p = pc.getElement().getChild("command").getChild("presence");
if (p != null) {
// + // use this hack to break XMLNS
// + Element el = new Element("presence");
// + el.setChildren(p.getChildren());
Element elem = p.clone();
elem.setXMLNS("jabber:client");
presence = new Packet(elem);
}
connection = connectionsByFrom.get(pc.getElemFrom());
if (connection == null) {
String user_jid = Command.getFieldValue(pc, "jid");
String hostname = JIDUtils.getNodeHost(user_jid);
connection = createUserSession(pc.getElemFrom(), hostname, user_jid);
connection.setSessionId("USER_STATUS");
user_repository.setData(JIDUtils.getNodeID(user_jid), "tokens",
"USER_STATUS", "USER_STATUS");
connection.loginToken("USER_STATUS", "USER_STATUS");
handleLogin(user_jid, connection);
connection.putSessionData("jingle", "active");
addOutPacket(pc.okResult((String)null, 0));
if (presence == null) {
presence =
new Packet(new Element("presence",
new Element[] {
new Element("priority", "-1"),
new Element("c",
new String[] {"node", "ver", "ext", "xmlns"},
new String[] {"http://www.google.com/xmpp/client/caps",
XMPPServer.getImplementationVersion(),
"voice-v1",
"http://jabber.org/protocol/caps"})},
null, null));
}
} else {
// addOutPacket(Authorization.CONFLICT.getResponseMessage(pc,
// "The user resource already exists.", true));
log.finest("USER_STATUS set to true for user who is already available: "
+ pc.toString());
}
if (presence != null) {
presence.setFrom(pc.getElemFrom());
presence.setTo(getComponentId());
addOutPacket(presence);
}
} else {
connection = connectionsByFrom.remove(pc.getElemFrom());
if (connection != null) {