Commit 33726493 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

1) IQ packets of type ERROR should include the original child element. JM-213

2) Improved logging of warnings. JM-214


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@1126 b35dd754-fafc-0310-a699-88a17e54d16e
parent cdff6698
......@@ -74,9 +74,10 @@ public class IQRouter extends BasicModule {
handle(packet);
}
else {
packet.setTo(sessionManager.getSession(packet.getFrom()).getAddress());
IQ reply = IQ.createResultIQ(packet);
reply.setChildElement(packet.getChildElement().createCopy());
packet.setError(PacketError.Condition.not_authorized);
sessionManager.getSession(packet.getFrom()).process(packet);
sessionManager.getSession(packet.getFrom()).process(reply);
}
}
......@@ -164,25 +165,30 @@ public class IQRouter extends BasicModule {
namespace = childElement.getNamespaceURI();
}
if (namespace == null) {
if (packet.getType() != IQ.Type.result) {
// Do nothing. We can't handle queries outside of a valid namespace
Log.warn("Unknown packet " + packet);
}
}
else {
IQHandler handler = getHandler(namespace);
if (handler == null) {
IQ reply = IQ.createResultIQ(packet);
if (recipientJID == null) {
// Answer an error since the server can't handle the requested namespace
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(PacketError.Condition.service_unavailable);
}
else if (recipientJID.getNode() == null ||
"".equals(recipientJID.getNode())) {
// Answer an error if JID is of the form <domain>
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(PacketError.Condition.feature_not_implemented);
}
else {
// JID is of the form <node@domain>
// Answer an error since the server can't handle packets sent to a node
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(PacketError.Condition.service_unavailable);
}
Session session = sessionManager.getSession(packet.getFrom());
......@@ -200,24 +206,28 @@ public class IQRouter extends BasicModule {
}
else {
try {
// JID is of the form <node@domain/resource>
ChannelHandler route = routingTable.getRoute(recipientJID);
route.process(packet);
}
}
catch (NoSuchRouteException e) {
Log.info("Packet sent to unreachable address " + packet);
Session session = sessionManager.getSession(packet.getFrom());
if (session != null) {
try {
packet.setError(PacketError.Condition.service_unavailable);
session.getConnection().deliver(packet);
IQ reply = IQ.createResultIQ(packet);
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(PacketError.Condition.service_unavailable);
session.getConnection().deliver(reply);
}
catch (UnauthorizedException ex) {
Log.error(LocaleUtils.getLocalizedString("admin.error.routing"), e);
}
}
}
}
}
catch (Exception e) {
Log.error(LocaleUtils.getLocalizedString("admin.error.routing"), e);
try {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment