Smack/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/handler/ResponderIncomingFileTransf...

73 lines
2.9 KiB
Java
Raw Normal View History

2017-06-09 23:16:15 +02:00
/**
*
* Copyright © 2017 Paul Schaub
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
2017-06-09 21:35:49 +02:00
package org.jivesoftware.smackx.jingle_filetransfer.handler;
import java.io.File;
import java.lang.ref.WeakReference;
import java.util.logging.Logger;
2017-06-10 17:16:22 +02:00
import org.jivesoftware.smack.XMPPConnection;
2017-06-09 21:35:49 +02:00
import org.jivesoftware.smack.packet.IQ;
2017-06-10 15:09:30 +02:00
import org.jivesoftware.smackx.jingle.AbstractJingleTransportManager;
2017-06-09 21:35:49 +02:00
import org.jivesoftware.smackx.jingle.JingleSessionHandler;
2017-06-10 15:09:30 +02:00
import org.jivesoftware.smackx.jingle.JingleTransportManager;
2017-06-09 21:35:49 +02:00
import org.jivesoftware.smackx.jingle.element.Jingle;
2017-06-10 15:09:30 +02:00
import org.jivesoftware.smackx.jingle.exception.UnsupportedJingleTransportException;
2017-06-09 21:35:49 +02:00
import org.jivesoftware.smackx.jingle_filetransfer.JingleFileTransferManager;
2017-06-09 23:16:15 +02:00
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransferChild;
2017-06-09 21:35:49 +02:00
import org.jxmpp.jid.FullJid;
/**
2017-06-09 23:16:15 +02:00
* This handler represents the state of the responders jingle session after the responder sent session-accept.
2017-06-09 21:35:49 +02:00
*/
2017-06-10 17:16:22 +02:00
public class ResponderIncomingFileTransferAccepted implements JingleSessionHandler {
2017-06-09 21:35:49 +02:00
2017-06-09 23:16:15 +02:00
private static final Logger LOGGER = Logger.getLogger(ResponderIncomingFileTransferAccepted.class.getName());
2017-06-09 21:35:49 +02:00
private final WeakReference<JingleFileTransferManager> manager;
2017-06-10 15:09:30 +02:00
private AbstractJingleTransportManager<?> transportManager;
2017-06-09 21:35:49 +02:00
private final File target;
private final int size;
private final FullJid initiator;
private final String sessionId;
2017-06-09 23:16:15 +02:00
public ResponderIncomingFileTransferAccepted(JingleFileTransferManager manager, Jingle initiate, File target) {
2017-06-09 21:35:49 +02:00
this.manager = new WeakReference<>(manager);
this.target = target;
2017-06-09 23:16:15 +02:00
this.size = ((JingleFileTransferChild) initiate.getContents().get(0).getDescription()
2017-06-09 21:35:49 +02:00
.getJingleContentDescriptionChildren().get(0)).getSize();
2017-06-10 15:09:30 +02:00
try {
this.transportManager = JingleTransportManager.getInstanceFor(manager.getConnection()).getJingleContentTransportManager(initiate);
} catch (UnsupportedJingleTransportException e) {
e.printStackTrace();
}
2017-06-09 21:35:49 +02:00
this.initiator = initiate.getInitiator();
this.sessionId = initiate.getSid();
}
@Override
2017-06-10 17:16:22 +02:00
public IQ handleJingleSessionRequest(Jingle jingle, String sessionId) {
return null;
2017-06-09 21:35:49 +02:00
}
@Override
2017-06-10 17:16:22 +02:00
public XMPPConnection getConnection() {
JingleFileTransferManager m = manager.get();
return m != null ? m.getConnection() : null;
2017-06-09 21:35:49 +02:00
}
}