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 { ...@@ -74,9 +74,10 @@ public class IQRouter extends BasicModule {
handle(packet); handle(packet);
} }
else { else {
packet.setTo(sessionManager.getSession(packet.getFrom()).getAddress()); IQ reply = IQ.createResultIQ(packet);
reply.setChildElement(packet.getChildElement().createCopy());
packet.setError(PacketError.Condition.not_authorized); 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 { ...@@ -164,25 +165,30 @@ public class IQRouter extends BasicModule {
namespace = childElement.getNamespaceURI(); namespace = childElement.getNamespaceURI();
} }
if (namespace == null) { if (namespace == null) {
if (packet.getType() != IQ.Type.result) {
// Do nothing. We can't handle queries outside of a valid namespace // Do nothing. We can't handle queries outside of a valid namespace
Log.warn("Unknown packet " + packet); Log.warn("Unknown packet " + packet);
} }
}
else { else {
IQHandler handler = getHandler(namespace); IQHandler handler = getHandler(namespace);
if (handler == null) { if (handler == null) {
IQ reply = IQ.createResultIQ(packet); IQ reply = IQ.createResultIQ(packet);
if (recipientJID == null) { if (recipientJID == null) {
// Answer an error since the server can't handle the requested namespace // Answer an error since the server can't handle the requested namespace
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(PacketError.Condition.service_unavailable); reply.setError(PacketError.Condition.service_unavailable);
} }
else if (recipientJID.getNode() == null || else if (recipientJID.getNode() == null ||
"".equals(recipientJID.getNode())) { "".equals(recipientJID.getNode())) {
// Answer an error if JID is of the form <domain> // Answer an error if JID is of the form <domain>
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(PacketError.Condition.feature_not_implemented); reply.setError(PacketError.Condition.feature_not_implemented);
} }
else { else {
// JID is of the form <node@domain> // JID is of the form <node@domain>
// Answer an error since the server can't handle packets sent to a node // 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); reply.setError(PacketError.Condition.service_unavailable);
} }
Session session = sessionManager.getSession(packet.getFrom()); Session session = sessionManager.getSession(packet.getFrom());
...@@ -200,24 +206,28 @@ public class IQRouter extends BasicModule { ...@@ -200,24 +206,28 @@ public class IQRouter extends BasicModule {
} }
else { else {
try {
// JID is of the form <node@domain/resource> // JID is of the form <node@domain/resource>
ChannelHandler route = routingTable.getRoute(recipientJID); ChannelHandler route = routingTable.getRoute(recipientJID);
route.process(packet); route.process(packet);
} }
}
catch (NoSuchRouteException e) { catch (NoSuchRouteException e) {
Log.info("Packet sent to unreachable address " + packet); Log.info("Packet sent to unreachable address " + packet);
Session session = sessionManager.getSession(packet.getFrom()); Session session = sessionManager.getSession(packet.getFrom());
if (session != null) { if (session != null) {
try { try {
packet.setError(PacketError.Condition.service_unavailable); IQ reply = IQ.createResultIQ(packet);
session.getConnection().deliver(packet); reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(PacketError.Condition.service_unavailable);
session.getConnection().deliver(reply);
} }
catch (UnauthorizedException ex) { catch (UnauthorizedException ex) {
Log.error(LocaleUtils.getLocalizedString("admin.error.routing"), e); Log.error(LocaleUtils.getLocalizedString("admin.error.routing"), e);
} }
} }
} }
}
}
catch (Exception e) { catch (Exception e) {
Log.error(LocaleUtils.getLocalizedString("admin.error.routing"), e); Log.error(LocaleUtils.getLocalizedString("admin.error.routing"), e);
try { 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