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