1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-12-24 19:47:58 +01:00

Remove some duplicate code from smackx.filetransfer

packet.IQ provides all the utility functions we need. An extension should
never (re-)implemented it's own core functionality.
This commit is contained in:
Florian Schmaus 2014-07-04 23:15:59 +02:00
parent 09425609af
commit afd1f6bc36
3 changed files with 4 additions and 45 deletions

View file

@ -159,10 +159,7 @@ public class FileTransferManager extends Manager {
protected void rejectIncomingFileTransfer(FileTransferRequest request) throws NotConnectedException {
StreamInitiation initiation = request.getStreamInitiation();
IQ rejection = FileTransferNegotiator.createIQ(
initiation.getPacketID(), initiation.getFrom(), initiation
.getTo(), IQ.Type.error);
rejection.setError(new XMPPError(XMPPError.Condition.no_acceptable));
IQ rejection = IQ.createErrorResponse(initiation, new XMPPError(XMPPError.Condition.no_acceptable));
connection().sendPacket(rejection);
}
}

View file

@ -143,30 +143,6 @@ public class FileTransferNegotiator extends Manager {
return true;
}
/**
* A convenience method to create an IQ packet.
*
* @param ID The packet ID of the
* @param to To whom the packet is addressed.
* @param from From whom the packet is sent.
* @param type The IQ type of the packet.
* @return The created IQ packet.
*/
public static IQ createIQ(final String ID, final String to,
final String from, final IQ.Type type) {
IQ iqPacket = new IQ() {
public String getChildElementXML() {
return null;
}
};
iqPacket.setPacketID(ID);
iqPacket.setTo(to);
iqPacket.setFrom(from);
iqPacket.setType(type);
return iqPacket;
}
/**
* Returns a collection of the supported transfer protocols.
*
@ -213,9 +189,7 @@ public class FileTransferNegotiator extends Manager {
if (streamMethodField == null) {
String errorMessage = "No stream methods contained in packet.";
XMPPError error = new XMPPError(XMPPError.Condition.bad_request, errorMessage);
IQ iqPacket = createIQ(si.getPacketID(), si.getFrom(), si.getTo(),
IQ.Type.error);
iqPacket.setError(error);
IQ iqPacket = IQ.createErrorResponse(si, error);
connection().sendPacket(iqPacket);
throw new XMPPErrorException(errorMessage, error);
}
@ -227,9 +201,7 @@ public class FileTransferNegotiator extends Manager {
selectedStreamNegotiator = getNegotiator(streamMethodField);
}
catch (XMPPErrorException e) {
IQ iqPacket = createIQ(si.getPacketID(), si.getFrom(), si.getTo(),
IQ.Type.error);
iqPacket.setError(e.getXMPPError());
IQ iqPacket = IQ.createErrorResponse(si, e.getXMPPError());
connection().sendPacket(iqPacket);
throw e;
}
@ -290,9 +262,7 @@ public class FileTransferNegotiator extends Manager {
*/
public void rejectStream(final StreamInitiation si) throws NotConnectedException {
XMPPError error = new XMPPError(XMPPError.Condition.forbidden, "Offer Declined");
IQ iqPacket = createIQ(si.getPacketID(), si.getFrom(), si.getTo(),
IQ.Type.error);
iqPacket.setError(error);
IQ iqPacket = IQ.createErrorResponse(si, error);
connection().sendPacket(iqPacket);
}

View file

@ -26,7 +26,6 @@ import org.jivesoftware.smack.XMPPException.XMPPErrorException;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smackx.si.packet.StreamInitiation;
import org.jivesoftware.smackx.xdata.Form;
import org.jivesoftware.smackx.xdata.FormField;
@ -74,13 +73,6 @@ public abstract class StreamNegotiator {
return response;
}
public IQ createError(String from, String to, String packetID, XMPPError xmppError) {
IQ iq = FileTransferNegotiator.createIQ(packetID, to, from, IQ.Type.error);
iq.setError(xmppError);
return iq;
}
Packet initiateIncomingStream(XMPPConnection connection, StreamInitiation initiation) throws NoResponseException, XMPPErrorException, NotConnectedException {
StreamInitiation response = createInitiationAccept(initiation,
getNamespaces());