1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-23 20:42:06 +01:00

Work on file transfer listeners

This commit is contained in:
vanitasvitae 2017-07-27 15:58:11 +02:00
parent 980c324f27
commit 5ce12974c8
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
12 changed files with 109 additions and 45 deletions

View file

@ -21,14 +21,12 @@ import org.jivesoftware.smackx.jft.listener.IncomingFileRequestListener;
import org.jivesoftware.smackx.jft.provider.JingleFileTransferProvider; import org.jivesoftware.smackx.jft.provider.JingleFileTransferProvider;
import org.jivesoftware.smackx.jingle.JingleDescriptionManager; import org.jivesoftware.smackx.jingle.JingleDescriptionManager;
import org.jivesoftware.smackx.jingle.JingleManager; import org.jivesoftware.smackx.jingle.JingleManager;
import org.jivesoftware.smackx.jingle.util.Role; import org.jivesoftware.smackx.jingle.JingleTransportManager;
import org.jivesoftware.smackx.jingle.callbacks.ContentAddCallback;
import org.jivesoftware.smackx.jingle.element.JingleContentElement;
import org.jivesoftware.smackx.jingle.element.JingleElement;
import org.jivesoftware.smackx.jingle.components.JingleContent; import org.jivesoftware.smackx.jingle.components.JingleContent;
import org.jivesoftware.smackx.jingle.components.JingleSession; import org.jivesoftware.smackx.jingle.components.JingleSession;
import org.jivesoftware.smackx.jingle.element.JingleContentElement;
import org.jivesoftware.smackx.jingle.provider.JingleContentProviderManager; import org.jivesoftware.smackx.jingle.provider.JingleContentProviderManager;
import org.jivesoftware.smackx.jingle.JingleTransportManager; import org.jivesoftware.smackx.jingle.util.Role;
import org.jxmpp.jid.FullJid; import org.jxmpp.jid.FullJid;
@ -126,7 +124,14 @@ public final class JingleFileTransferManager extends Manager implements JingleDe
} }
@Override @Override
public JingleElement notifyContentListeners(JingleContent content, ContentAddCallback callback) { public void notifySessionInitiate(JingleSession session) {
JingleContent content = session.getSoleContentOrThrow();
AbstractJingleFileTransfer transfer = (AbstractJingleFileTransfer) content.getDescription();
if (transfer.isOffer()) {
notifyIncomingFileOfferListeners((JingleIncomingFileOffer) transfer);
} else {
notifyIncomingFileRequestListeners((JingleIncomingFileRequest) transfer);
}
} }
} }

View file

@ -0,0 +1,27 @@
package org.jivesoftware.smackx.jft.callback;
import java.io.File;
import org.jivesoftware.smackx.jft.controller.IncomingFileOfferController;
import org.jivesoftware.smackx.jingle.callbacks.JingleCallback;
/**
* Created by vanitas on 27.07.17.
*/
public interface IncomingFileOfferCallback extends JingleCallback<IncomingFileOfferCallback.Destination> {
@Override
IncomingFileOfferController accept(Destination destination);
class Destination extends JingleCallback.Parameters {
private final File destination;
public Destination(File destination) {
this.destination = destination;
}
public File getDestination() {
return destination;
}
}
}

View file

@ -1,9 +1,10 @@
package org.jivesoftware.smackx.jft.controller; package org.jivesoftware.smackx.jft.controller;
import org.jivesoftware.smackx.jingle.controller.JingleDescriptionController; import org.jivesoftware.smackx.jingle.JingleDescriptionController;
/** /**
* Created by vanitas on 27.07.17. * Created by vanitas on 27.07.17.
*/ */
public interface IncomingFileOfferController extends JingleDescriptionController { public interface IncomingFileOfferController extends JingleDescriptionController {
} }

View file

@ -1,6 +1,6 @@
package org.jivesoftware.smackx.jft.controller; package org.jivesoftware.smackx.jft.controller;
import org.jivesoftware.smackx.jingle.controller.JingleDescriptionController; import org.jivesoftware.smackx.jingle.JingleDescriptionController;
/** /**
* Created by vanitas on 27.07.17. * Created by vanitas on 27.07.17.

View file

@ -11,4 +11,7 @@ public abstract class AbstractJingleFileTransfer extends JingleDescription<Jingl
public static final String NAMESPACE_V5 = "urn:xmpp:jingle:apps:file-transfer:5"; public static final String NAMESPACE_V5 = "urn:xmpp:jingle:apps:file-transfer:5";
public static final String NAMESPACE = NAMESPACE_V5; public static final String NAMESPACE = NAMESPACE_V5;
public abstract boolean isOffer();
public abstract boolean isRequest();
} }

View file

@ -4,7 +4,6 @@ package org.jivesoftware.smackx.jingle;
* Created by vanitas on 27.07.17. * Created by vanitas on 27.07.17.
*/ */
public interface JingleDescriptionController { public interface JingleDescriptionController {
enum State { enum State {
pending, //Not yet accepted by us/peer pending, //Not yet accepted by us/peer
negotiating, //Accepted, but still negotiating transports etc. negotiating, //Accepted, but still negotiating transports etc.

View file

@ -1,27 +0,0 @@
/**
*
* 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.
*/
package org.jivesoftware.smackx.jingle.callbacks;
/**
* Callback that gets called when the user accepts a content-add request.
*/
public interface ContentAddCallback {
void acceptContentAdd();
void rejectContentAdd();
}

View file

@ -0,0 +1,17 @@
package org.jivesoftware.smackx.jingle.callbacks;
import org.jivesoftware.smackx.jingle.JingleDescriptionController;
/**
* Created by vanitas on 27.07.17.
*/
public interface JingleCallback<P extends JingleCallback.Parameters> {
JingleDescriptionController accept(P parameters);
void decline();
class Parameters {
}
}

View file

@ -260,7 +260,7 @@ public class JingleContent {
connection.createStanzaCollectorAndSend(transportReplace).nextResultOrThrow(); connection.createStanzaCollectorAndSend(transportReplace).nextResultOrThrow();
} }
public void onContentAccept(XMPPConnection connection, ) public void onContentAccept(XMPPConnection connection)
throws SmackException.NotConnectedException, InterruptedException { throws SmackException.NotConnectedException, InterruptedException {
//Establish transport //Establish transport
if (isReceiving()) { if (isReceiving()) {

View file

@ -0,0 +1,27 @@
package org.jivesoftware.smackx.jingle.components;
import java.io.IOException;
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
/**
* Created by vanitas on 27.07.17.
*/
public abstract class JingleSecurityBytestreamSession implements BytestreamSession {
protected BytestreamSession wrapped;
@Override
public int getReadTimeout() throws IOException {
return wrapped.getReadTimeout();
}
@Override
public void setReadTimeout(int timeout) throws IOException {
wrapped.setReadTimeout(timeout);
}
public JingleSecurityBytestreamSession(BytestreamSession session) {
this.wrapped = session;
}
}

View file

@ -81,6 +81,26 @@ public class JingleSession {
addContent(JingleContent.fromElement(content)); addContent(JingleContent.fromElement(content));
} }
public ConcurrentHashMap<String, JingleContent> getContents() {
return contents;
}
public JingleContent getContent(String name) {
return contents.get(name);
}
public JingleContent getSoleContentOrThrow() {
if (contents.isEmpty()) {
return null;
}
if (contents.size() > 1) {
throw new IllegalStateException();
}
return contents.values().iterator().next();
}
public static JingleSession fromSessionInitiate(JingleManager manager, JingleElement initiate) public static JingleSession fromSessionInitiate(JingleManager manager, JingleElement initiate)
throws UnsupportedSecurityException, UnsupportedDescriptionException, UnsupportedTransportException { throws UnsupportedSecurityException, UnsupportedDescriptionException, UnsupportedTransportException {
if (initiate.getAction() != JingleAction.session_initiate) { if (initiate.getAction() != JingleAction.session_initiate) {

View file

@ -1,8 +0,0 @@
package org.jivesoftware.smackx.jingle.controller;
/**
* Created by vanitas on 27.07.17.
*/
public interface JingleDescriptionController {
}