1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-12 10:39:38 +02:00

More ground work

This commit is contained in:
vanitasvitae 2017-06-18 16:47:49 +02:00
parent dcb5da76d6
commit b91a9c120f
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
12 changed files with 385 additions and 83 deletions

View file

@ -0,0 +1,30 @@
/**
*
* 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_filetransfer;
import org.jivesoftware.smackx.jingle.Role;
import org.jxmpp.jid.FullJid;
/**
* Offer.
*/
public class JingleFileOffer extends JingleFileTransferSession {
public JingleFileOffer(FullJid initiator, FullJid responder, Role role, String sid) {
super(initiator, responder, role, sid, Type.offer);
}
}

View file

@ -0,0 +1,31 @@
/**
*
* 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_filetransfer;
import org.jivesoftware.smackx.jingle.Role;
import org.jxmpp.jid.FullJid;
/**
* Request.
*/
public class JingleFileRequest extends JingleFileTransferSession {
public JingleFileRequest(FullJid initiator, FullJid responder, Role role, String sid) {
super(initiator, responder, role, sid, Type.request);
}
}

View file

@ -20,16 +20,27 @@ import java.util.WeakHashMap;
import org.jivesoftware.smack.Manager;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.jivesoftware.smackx.jingle.JingleHandler;
import org.jivesoftware.smackx.jingle.JingleManager;
import org.jivesoftware.smackx.jingle.element.Jingle;
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransfer;
import org.jxmpp.jid.FullJid;
/**
* Manager for JingleFileTransfer (XEP-0234).
*/
public final class JingleFileTransferManager extends Manager {
public final class JingleFileTransferManager extends Manager implements JingleHandler {
private static final WeakHashMap<XMPPConnection, JingleFileTransferManager> INSTANCES = new WeakHashMap<>();
private JingleFileTransferManager(XMPPConnection connection) {
super(connection);
ServiceDiscoveryManager.getInstanceFor(connection).addFeature(JingleFileTransfer.NAMESPACE_V5);
JingleManager jingleManager = JingleManager.getInstanceFor(connection);
jingleManager.registerDescriptionHandler(JingleFileTransfer.NAMESPACE_V5, this);
}
public static JingleFileTransferManager getInstanceFor(XMPPConnection connection) {
@ -40,4 +51,13 @@ public final class JingleFileTransferManager extends Manager {
}
return manager;
}
@Override
public IQ handleJingleRequest(Jingle jingle) {
FullJid fullJid = jingle.getFrom().asFullJidOrThrow();
String sid = jingle.getSid();
JingleFileTransferSessionHandler handler = JingleFileTransferSessionHandler.getInstanceFor(connection());
JingleManager.getInstanceFor(connection()).registerJingleSessionHandler(fullJid, sid, handler);
return handler.handleJingleSessionRequest(jingle, jingle.getSid());
}
}

View file

@ -0,0 +1,61 @@
/**
*
* 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_filetransfer;
import org.jivesoftware.smackx.jingle.JingleSession;
import org.jivesoftware.smackx.jingle.Role;
import org.jxmpp.jid.FullJid;
/**
* Class representing a Jingle session in the context of Jingle File Transfer (XEP-0234).
*/
public abstract class JingleFileTransferSession extends JingleSession {
public enum Type {
offer,
request,
;
}
private final Type type;
public JingleFileTransferSession(FullJid initiator, FullJid responder, Role role, String sid, Type type) {
super(initiator, responder, role, sid);
this.type = type;
}
public Type getType() {
return type;
}
public boolean isOffer() {
return this.type == Type.offer;
}
public boolean isRequest() {
return this.type == Type.request;
}
public boolean isSender() {
return (isOffer() && isInitiator()) || (isRequest() && isResponder());
}
public boolean isReceiver() {
return (isRequest() && isInitiator()) || (isOffer() && isResponder());
}
}

View file

@ -0,0 +1,56 @@
/**
*
* 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_filetransfer;
import java.util.WeakHashMap;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.jingle.JingleSessionHandler;
import org.jivesoftware.smackx.jingle.JingleUtil;
import org.jivesoftware.smackx.jingle.element.Jingle;
/**
* Handler for JingleFileTransfer sessions.
*/
public final class JingleFileTransferSessionHandler implements JingleSessionHandler {
private static final WeakHashMap<XMPPConnection, JingleFileTransferSessionHandler> INSTANCES = new WeakHashMap<>();
private final XMPPConnection connection;
private final JingleUtil jutil;
private JingleFileTransferSessionHandler(XMPPConnection connection) {
this.connection = connection;
jutil = new JingleUtil(connection);
}
public static JingleFileTransferSessionHandler getInstanceFor(XMPPConnection connection) {
JingleFileTransferSessionHandler handler = INSTANCES.get(connection);
if (handler == null) {
handler = new JingleFileTransferSessionHandler(connection);
INSTANCES.put(connection, handler);
}
return handler;
}
@Override
public IQ handleJingleSessionRequest(Jingle jingle, String sessionId) {
return null;
}
}

View file

@ -0,0 +1,27 @@
/**
*
* 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_filetransfer.listener;
import org.jivesoftware.smackx.jingle.element.Jingle;
/**
* Created by vanitas on 18.06.17.
*/
public interface IncomingFileTransferListener {
void onIncomingJingleFileTransfer(Jingle request);
}

View file

@ -0,0 +1,22 @@
/**
*
* 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.
*/
/**
* Smack's API for <a href="https://xmpp.org/extensions/xep-0234.html">XEP-0234: Jingle File Transfer</a>.
* Listeners.
*/
package org.jivesoftware.smackx.jingle_filetransfer.listener;