Commit 637fb08f authored by Alex Wenckus's avatar Alex Wenckus Committed by alex

Work on FileTransferInterceptor

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@4896 b35dd754-fafc-0310-a699-88a17e54d16e
parent bb76f606
......@@ -27,6 +27,7 @@ import org.xmpp.packet.JID;
import java.util.Map;
import java.util.List;
import java.util.ArrayList;
/**
* Provides several utility methods for file transfer manager implementaions to utilize.
......@@ -39,6 +40,9 @@ public class DefaultFileTransferManager extends BasicModule implements FileTrans
private final Map<String, FileTransfer> fileTransferMap;
private final List<FileTransferInterceptor> fileTransferInterceptorList
= new ArrayList<FileTransferInterceptor>();
/**
* Default constructor creates the cache.
*/
......@@ -93,13 +97,9 @@ public class DefaultFileTransferManager extends BasicModule implements FileTrans
}
public boolean acceptIncomingFileTransferRequest(FileTransfer transfer)
throws FileTransferRejectedException
{
try {
fireFileTransferMetaIntercept(transfer);
}
catch (FileTransferRejectedException e) {
return false;
}
fireFileTransferIntercept(transfer, false);
if(transfer != null) {
String streamID = transfer.getSessionID();
JID from = new JID(transfer.getInitiator());
......@@ -125,8 +125,8 @@ public class DefaultFileTransferManager extends BasicModule implements FileTrans
cacheFileTransfer(transferDigest, transfer);
}
private FileTransfer createFileTransfer(String packetID, JID from,
JID to, Element siElement) {
private FileTransfer createFileTransfer(JID from,
JID to, Element siElement) {
String streamID = siElement.attributeValue("id");
String mimeType = siElement.attributeValue("mime-type");
String profile = siElement.attributeValue("profile");
......@@ -147,22 +147,26 @@ public class DefaultFileTransferManager extends BasicModule implements FileTrans
return transfer;
}
public void addFileTransferInterceptor(FileTransferInterceptor interceptor) {
fileTransferInterceptorList.add(interceptor);
}
public void removeFileTransferInterceptor(FileTransferInterceptor interceptor) {
fileTransferInterceptorList.remove(interceptor);
}
public void fireFileTransferIntercept(FileTransferProgress transfer)
public void fireFileTransferIntercept(FileTransferProgress transfer, boolean isReady)
throws FileTransferRejectedException
{
fireFileTransferIntercept(fileTransferMap.get(transfer.getSessionID()), isReady);
}
private void fireFileTransferMetaIntercept(FileTransfer transfer) throws
FileTransferRejectedException
private void fireFileTransferIntercept(FileTransfer transfer, boolean isReady)
throws FileTransferRejectedException
{
for(FileTransferInterceptor interceptor : fileTransferInterceptorList) {
interceptor.interceptFileTransfer(transfer, isReady);
}
}
/**
......@@ -187,13 +191,17 @@ public class DefaultFileTransferManager extends BasicModule implements FileTrans
if (iq.getType().equals(IQ.Type.set)) {
JID from = iq.getFrom();
JID to = iq.getTo();
String packetID = iq.getID();
FileTransfer transfer =
createFileTransfer(packetID, from, to, childElement);
createFileTransfer(from, to, childElement);
if (transfer == null || !acceptIncomingFileTransferRequest(transfer)) {
throw new PacketRejectedException();
try {
if (transfer == null || !acceptIncomingFileTransferRequest(transfer)) {
throw new PacketRejectedException();
}
}
catch (FileTransferRejectedException e) {
throw new PacketRejectedException(e);
}
}
}
......
......@@ -31,6 +31,6 @@ public interface FileTransferInterceptor {
* not go through.
*
*/
void interceptFileTransfer(FileTransferProgress transfer, boolean isReady)
void interceptFileTransfer(FileTransfer transfer, boolean isReady)
throws FileTransferRejectedException;
}
......@@ -44,7 +44,7 @@ public interface FileTransferManager extends Module {
* @param transfer the transfer to test for acceptance
* @return true if it should be accepted false if it should not.
*/
boolean acceptIncomingFileTransferRequest(FileTransfer transfer);
boolean acceptIncomingFileTransferRequest(FileTransfer transfer) throws FileTransferRejectedException;
/**
* Registers that a transfer has begun through the proxy connected to the server.
......@@ -62,5 +62,6 @@ public interface FileTransferManager extends Module {
void removeFileTransferInterceptor(FileTransferInterceptor interceptor);
void fireFileTransferIntercept(FileTransferProgress transfer) throws FileTransferRejectedException;
void fireFileTransferIntercept(FileTransferProgress transfer, boolean isReady)
throws FileTransferRejectedException;
}
......@@ -289,7 +289,7 @@ public class ProxyConnectionManager {
transfer.setTransferFuture(executor.submit(new Runnable() {
public void run() {
try {
transferManager.fireFileTransferIntercept(transfer);
transferManager.fireFileTransferIntercept(transfer, true);
}
catch (FileTransferRejectedException e) {
notifyFailure(transfer, e);
......
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