mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-26 00:02:06 +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:
parent
09425609af
commit
afd1f6bc36
3 changed files with 4 additions and 45 deletions
|
@ -159,10 +159,7 @@ public class FileTransferManager extends Manager {
|
||||||
protected void rejectIncomingFileTransfer(FileTransferRequest request) throws NotConnectedException {
|
protected void rejectIncomingFileTransfer(FileTransferRequest request) throws NotConnectedException {
|
||||||
StreamInitiation initiation = request.getStreamInitiation();
|
StreamInitiation initiation = request.getStreamInitiation();
|
||||||
|
|
||||||
IQ rejection = FileTransferNegotiator.createIQ(
|
IQ rejection = IQ.createErrorResponse(initiation, new XMPPError(XMPPError.Condition.no_acceptable));
|
||||||
initiation.getPacketID(), initiation.getFrom(), initiation
|
|
||||||
.getTo(), IQ.Type.error);
|
|
||||||
rejection.setError(new XMPPError(XMPPError.Condition.no_acceptable));
|
|
||||||
connection().sendPacket(rejection);
|
connection().sendPacket(rejection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,30 +143,6 @@ public class FileTransferNegotiator extends Manager {
|
||||||
return true;
|
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.
|
* Returns a collection of the supported transfer protocols.
|
||||||
*
|
*
|
||||||
|
@ -213,9 +189,7 @@ public class FileTransferNegotiator extends Manager {
|
||||||
if (streamMethodField == null) {
|
if (streamMethodField == null) {
|
||||||
String errorMessage = "No stream methods contained in packet.";
|
String errorMessage = "No stream methods contained in packet.";
|
||||||
XMPPError error = new XMPPError(XMPPError.Condition.bad_request, errorMessage);
|
XMPPError error = new XMPPError(XMPPError.Condition.bad_request, errorMessage);
|
||||||
IQ iqPacket = createIQ(si.getPacketID(), si.getFrom(), si.getTo(),
|
IQ iqPacket = IQ.createErrorResponse(si, error);
|
||||||
IQ.Type.error);
|
|
||||||
iqPacket.setError(error);
|
|
||||||
connection().sendPacket(iqPacket);
|
connection().sendPacket(iqPacket);
|
||||||
throw new XMPPErrorException(errorMessage, error);
|
throw new XMPPErrorException(errorMessage, error);
|
||||||
}
|
}
|
||||||
|
@ -227,9 +201,7 @@ public class FileTransferNegotiator extends Manager {
|
||||||
selectedStreamNegotiator = getNegotiator(streamMethodField);
|
selectedStreamNegotiator = getNegotiator(streamMethodField);
|
||||||
}
|
}
|
||||||
catch (XMPPErrorException e) {
|
catch (XMPPErrorException e) {
|
||||||
IQ iqPacket = createIQ(si.getPacketID(), si.getFrom(), si.getTo(),
|
IQ iqPacket = IQ.createErrorResponse(si, e.getXMPPError());
|
||||||
IQ.Type.error);
|
|
||||||
iqPacket.setError(e.getXMPPError());
|
|
||||||
connection().sendPacket(iqPacket);
|
connection().sendPacket(iqPacket);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
@ -290,9 +262,7 @@ public class FileTransferNegotiator extends Manager {
|
||||||
*/
|
*/
|
||||||
public void rejectStream(final StreamInitiation si) throws NotConnectedException {
|
public void rejectStream(final StreamInitiation si) throws NotConnectedException {
|
||||||
XMPPError error = new XMPPError(XMPPError.Condition.forbidden, "Offer Declined");
|
XMPPError error = new XMPPError(XMPPError.Condition.forbidden, "Offer Declined");
|
||||||
IQ iqPacket = createIQ(si.getPacketID(), si.getFrom(), si.getTo(),
|
IQ iqPacket = IQ.createErrorResponse(si, error);
|
||||||
IQ.Type.error);
|
|
||||||
iqPacket.setError(error);
|
|
||||||
connection().sendPacket(iqPacket);
|
connection().sendPacket(iqPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,6 @@ import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
||||||
import org.jivesoftware.smack.filter.PacketFilter;
|
import org.jivesoftware.smack.filter.PacketFilter;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.packet.Packet;
|
import org.jivesoftware.smack.packet.Packet;
|
||||||
import org.jivesoftware.smack.packet.XMPPError;
|
|
||||||
import org.jivesoftware.smackx.si.packet.StreamInitiation;
|
import org.jivesoftware.smackx.si.packet.StreamInitiation;
|
||||||
import org.jivesoftware.smackx.xdata.Form;
|
import org.jivesoftware.smackx.xdata.Form;
|
||||||
import org.jivesoftware.smackx.xdata.FormField;
|
import org.jivesoftware.smackx.xdata.FormField;
|
||||||
|
@ -74,13 +73,6 @@ public abstract class StreamNegotiator {
|
||||||
return response;
|
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 {
|
Packet initiateIncomingStream(XMPPConnection connection, StreamInitiation initiation) throws NoResponseException, XMPPErrorException, NotConnectedException {
|
||||||
StreamInitiation response = createInitiationAccept(initiation,
|
StreamInitiation response = createInitiationAccept(initiation,
|
||||||
getNamespaces());
|
getNamespaces());
|
||||||
|
|
Loading…
Reference in a new issue