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

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


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@1125 b35dd754-fafc-0310-a699-88a17e54d16e
parent 8fcd236a
......@@ -116,11 +116,13 @@ public class IQDiscoInfoHandler extends IQHandler {
else {
// If the DiscoInfoProvider has no information for the requested name and node
// then answer a not found error
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(PacketError.Condition.item_not_found);
}
}
else {
// If we didn't find a DiscoInfoProvider then answer a not found error
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(PacketError.Condition.item_not_found);
}
......
......@@ -74,6 +74,7 @@ public class IQDiscoItemsHandler extends IQHandler implements ServerFeaturesProv
// TODO Implement publishing client items
if (IQ.Type.set == packet.getType()) {
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(PacketError.Condition.feature_not_implemented);
return reply;
}
......@@ -112,11 +113,13 @@ public class IQDiscoItemsHandler extends IQHandler implements ServerFeaturesProv
else {
// If the DiscoItemsProvider has no items for the requested name and node
// then answer a not found error
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(PacketError.Condition.item_not_found);
}
}
else {
// If we didn't find a DiscoItemsProvider then answer a not found error
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(PacketError.Condition.item_not_found);
}
......
......@@ -131,10 +131,12 @@ public class IQAuthHandler extends IQHandler implements IQAuthInfo {
}
catch (UserNotFoundException e) {
response = IQ.createResultIQ(packet);
response.setChildElement(packet.getChildElement().createCopy());
response.setError(PacketError.Condition.not_authorized);
}
catch (UnauthorizedException e) {
response = IQ.createResultIQ(packet);
response.setChildElement(packet.getChildElement().createCopy());
response.setError(PacketError.Condition.not_authorized);
}
// Send the response directly since we want to be sure that we are sending it back
......@@ -179,6 +181,7 @@ public class IQAuthHandler extends IQHandler implements IQAuthInfo {
}
else {
response = IQ.createResultIQ(packet);
response.setChildElement(packet.getChildElement().createCopy());
response.setError(PacketError.Condition.forbidden);
}
}
......@@ -239,6 +242,7 @@ public class IQAuthHandler extends IQHandler implements IQAuthInfo {
auth.addElement("resource").setText(session.getAddress().getResource());
}
else {
response.setChildElement(packet.getChildElement().createCopy());
response.setError(PacketError.Condition.forbidden);
}
return response;
......
......@@ -54,6 +54,7 @@ public abstract class IQHandler extends BasicModule implements ChannelHandler {
if (iq != null) {
try {
IQ response = IQ.createResultIQ(iq);
response.setChildElement(iq.getChildElement().createCopy());
response.setError(PacketError.Condition.not_authorized);
Session session = sessionManager.getSession(iq.getFrom());
if (!session.getConnection().isClosed()) {
......
......@@ -141,6 +141,7 @@ public class IQRegisterHandler extends IQHandler implements ServerFeaturesProvid
// If inband registration is not allowed, return an error.
if (!enabled) {
reply = IQ.createResultIQ(packet);
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(PacketError.Condition.forbidden);
}
else if (IQ.Type.get.equals(packet.getType())) {
......@@ -261,6 +262,7 @@ public class IQRegisterHandler extends IQHandler implements ServerFeaturesProvid
// not provided
if (password == null || password.trim().length() == 0) {
reply = IQ.createResultIQ(packet);
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(PacketError.Condition.not_acceptable);
return reply;
}
......@@ -295,10 +297,12 @@ public class IQRegisterHandler extends IQHandler implements ServerFeaturesProvid
}
catch (UserAlreadyExistsException e) {
reply = IQ.createResultIQ(packet);
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(PacketError.Condition.conflict);
}
catch (UserNotFoundException e) {
reply = IQ.createResultIQ(packet);
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(PacketError.Condition.bad_request);
}
catch (Exception e) {
......
......@@ -110,6 +110,7 @@ public class IQRosterHandler extends IQHandler implements ServerFeaturesProvider
}
catch (SharedGroupException e) {
IQ result = IQ.createResultIQ(packet);
result.setChildElement(packet.getChildElement().createCopy());
result.setError(PacketError.Condition.not_acceptable);
return result;
}
......
......@@ -80,6 +80,7 @@ public class IQAdminHandler {
else {
// An unknown and possibly incorrect element was included in the query
// element so answer a BAD_REQUEST error
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(PacketError.Condition.bad_request);
}
if (reply.getTo() != null) {
......
......@@ -110,6 +110,7 @@ class IQMUCRegisterHandler {
if (room == null) {
// The room doesn't exist so answer a NOT_FOUND error
reply = IQ.createResultIQ(packet);
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(PacketError.Condition.item_not_found);
return reply;
}
......@@ -172,6 +173,7 @@ class IQMUCRegisterHandler {
room.getRole()));
}
else {
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(PacketError.Condition.bad_request);
}
}
......@@ -183,10 +185,12 @@ class IQMUCRegisterHandler {
}
catch (ForbiddenException e) {
reply = IQ.createResultIQ(packet);
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(PacketError.Condition.forbidden);
}
catch (ConflictException e) {
reply = IQ.createResultIQ(packet);
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(PacketError.Condition.conflict);
}
catch (Exception e) {
......
......@@ -107,6 +107,7 @@ public class IQOwnerHandler {
// An unknown and possibly incorrect element was included in the query
// element so answer a BAD_REQUEST error
else {
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(PacketError.Condition.bad_request);
}
}
......
......@@ -744,11 +744,10 @@ public class MUCRoomImpl implements MUCRoom {
broadcastPresence((Presence)packet);
}
else if (packet instanceof IQ) {
packet = packet.createCopy();
packet.setError(PacketError.Condition.bad_request);
packet.setTo(packet.getFrom());
packet.setFrom(role.getRoleAddress());
router.route(packet);
IQ reply = IQ.createResultIQ((IQ) packet);
reply.setChildElement(((IQ) packet).getChildElement());
reply.setError(PacketError.Condition.bad_request);
router.route(reply);
}
}
......
......@@ -93,12 +93,20 @@ public class MUCUserImpl implements MUCUser {
* @param packet the packet to be bounced.
*/
private void sendErrorPacket(Packet packet, PacketError.Condition error) {
if (packet instanceof IQ) {
IQ reply = IQ.createResultIQ((IQ) packet);
reply.setChildElement(((IQ) packet).getChildElement().createCopy());
reply.setError(error);
router.route(reply);
}
else {
Packet reply = packet.createCopy();
reply.setError(error);
reply.setFrom(packet.getTo());
reply.setTo(packet.getFrom());
router.route(reply);
}
}
public JID getAddress() {
return realjid;
......
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