mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-12-24 19:47:58 +01:00
Remove errors
This commit is contained in:
parent
3f6df8e6c7
commit
3ed3f53189
58 changed files with 849 additions and 2028 deletions
|
@ -36,14 +36,12 @@ import org.jivesoftware.smack.XMPPConnection;
|
|||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.jivesoftware.smackx.jet.element.JetSecurityElement;
|
||||
import org.jivesoftware.smackx.jingle.JingleManager;
|
||||
import org.jivesoftware.smackx.jft.controller.OutgoingFileOfferController;
|
||||
import org.jivesoftware.smackx.jft.element.JingleFileTransferChildElement;
|
||||
import org.jivesoftware.smackx.jft.element.JingleFileTransferElement;
|
||||
import org.jivesoftware.smackx.jft.internal.JingleOutgoingFileOffer;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionChildElement;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentElement;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleElement;
|
||||
import org.jivesoftware.smackx.jingle_filetransfer.OutgoingJingleFileOffer;
|
||||
import org.jivesoftware.smackx.jft.element.JingleFileTransferElement;
|
||||
import org.jivesoftware.smackx.jft.element.JingleFileTransferChildElement;
|
||||
import org.jivesoftware.smackx.jingle_filetransfer.handler.FileTransferHandler;
|
||||
|
||||
import org.jxmpp.jid.FullJid;
|
||||
|
||||
|
@ -73,7 +71,7 @@ public final class JetManager extends Manager {
|
|||
return manager;
|
||||
}
|
||||
|
||||
public FileTransferHandler sendEncryptedFile(FullJid recipient, File file, String encryptionMethodNamespace) throws Exception {
|
||||
public OutgoingFileOfferController sendEncryptedFile(FullJid recipient, File file, String encryptionMethodNamespace) throws Exception {
|
||||
|
||||
JingleEncryptionMethod encryptionMethod = getEncryptionMethod(encryptionMethodNamespace);
|
||||
if (encryptionMethod == null) {
|
||||
|
@ -141,7 +139,7 @@ public final class JetManager extends Manager {
|
|||
ExtensionElement encryptionExtension = encryptionMethod.encryptJingleTransfer(recipient, keyAndIv);
|
||||
JetSecurityElement securityElement = new JetSecurityElement(contentName, encryptionExtension);
|
||||
|
||||
OutgoingJingleFileOffer offer = new OutgoingJingleFileOffer(connection(), recipient);
|
||||
JingleOutgoingFileOffer offer = new JingleOutgoingFileOffer(file);
|
||||
|
||||
JingleFileTransferChildElement fileTransferChild = JingleFileTransferChildElement.getBuilder().setFile(file).build();
|
||||
JingleFileTransferElement fileTransfer = new JingleFileTransferElement(Collections.<JingleContentDescriptionChildElement>singletonList(fileTransferChild));
|
||||
|
@ -149,12 +147,11 @@ public final class JetManager extends Manager {
|
|||
JingleContentElement content = JingleContentElement.getBuilder()
|
||||
.setCreator(JingleContentElement.Creator.initiator)
|
||||
.setName(contentName)
|
||||
.setTransport(offer.getTransportSession().createTransport())
|
||||
//.setTransport(offer.getTransportSession().createTransport())
|
||||
.setSecurity(securityElement)
|
||||
.setDescription(fileTransfer)
|
||||
.build();
|
||||
|
||||
JingleElement initiate = jutil.createSessionInitiate(recipient, JingleManager.randomId(), content);
|
||||
return offer;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,26 +18,14 @@ package org.jivesoftware.smackx.jet;
|
|||
|
||||
import java.io.File;
|
||||
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smackx.jingle_filetransfer.OutgoingJingleFileOffer;
|
||||
|
||||
import org.jxmpp.jid.FullJid;
|
||||
import org.jivesoftware.smackx.jft.internal.JingleOutgoingFileOffer;
|
||||
|
||||
/**
|
||||
* Created by vanitas on 14.07.17.
|
||||
*/
|
||||
public class OutgoingJetOffer extends OutgoingJingleFileOffer {
|
||||
|
||||
public OutgoingJetOffer(XMPPConnection connection, FullJid responder, String sid) {
|
||||
super(connection, responder, sid);
|
||||
}
|
||||
|
||||
public OutgoingJetOffer(XMPPConnection connection, FullJid recipient) {
|
||||
super(connection, recipient);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(File file) {
|
||||
public class OutgoingJetOffer extends JingleOutgoingFileOffer {
|
||||
|
||||
public OutgoingJetOffer(File file) {
|
||||
super(file);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,9 +22,9 @@ import java.util.logging.Logger;
|
|||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
||||
import org.jivesoftware.smack.util.Objects;
|
||||
import org.jivesoftware.smackx.jet.JetManager;
|
||||
import org.jivesoftware.smackx.jet.JingleEncryptionMethodManager;
|
||||
import org.jivesoftware.smackx.jet.element.JetSecurityElement;
|
||||
import org.jivesoftware.smackx.jet.internal.JetSecurity;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
|
@ -36,8 +36,8 @@ public class JetSecurityProvider extends ExtensionElementProvider<JetSecurityEle
|
|||
|
||||
@Override
|
||||
public JetSecurityElement parse(XmlPullParser parser, int initialDepth) throws Exception {
|
||||
String name = parser.getAttributeValue(JetManager.NAMESPACE, JetSecurityElement.ATTR_NAME);
|
||||
String type = parser.getAttributeValue(JetManager.NAMESPACE, JetSecurityElement.ATTR_TYPE);
|
||||
String name = parser.getAttributeValue(JetSecurity.NAMESPACE, JetSecurityElement.ATTR_NAME);
|
||||
String type = parser.getAttributeValue(JetSecurity.NAMESPACE, JetSecurityElement.ATTR_TYPE);
|
||||
ExtensionElement child;
|
||||
|
||||
Objects.requireNonNull(type);
|
||||
|
|
|
@ -1,3 +1,19 @@
|
|||
/**
|
||||
*
|
||||
* 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.jft;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -11,7 +27,7 @@ import org.jivesoftware.smack.XMPPConnection;
|
|||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||
import org.jivesoftware.smackx.jft.controller.OutgoingFileOfferController;
|
||||
import org.jivesoftware.smackx.jft.controller.OutgoingFileRequestController;
|
||||
import org.jivesoftware.smackx.jft.internal.AbstractJingleFileTransfer;
|
||||
import org.jivesoftware.smackx.jft.internal.JingleFileTransfer;
|
||||
import org.jivesoftware.smackx.jft.internal.JingleIncomingFileOffer;
|
||||
import org.jivesoftware.smackx.jft.internal.JingleIncomingFileRequest;
|
||||
import org.jivesoftware.smackx.jft.internal.JingleOutgoingFileOffer;
|
||||
|
@ -120,10 +136,10 @@ public final class JingleFileTransferManager extends Manager implements JingleDe
|
|||
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return AbstractJingleFileTransfer.NAMESPACE;
|
||||
return JingleFileTransfer.NAMESPACE;
|
||||
}
|
||||
|
||||
private void notifyTransfer(AbstractJingleFileTransfer transfer) {
|
||||
private void notifyTransfer(JingleFileTransfer transfer) {
|
||||
if (transfer.isOffer()) {
|
||||
notifyIncomingFileOfferListeners((JingleIncomingFileOffer) transfer);
|
||||
} else {
|
||||
|
@ -134,11 +150,11 @@ public final class JingleFileTransferManager extends Manager implements JingleDe
|
|||
@Override
|
||||
public void notifySessionInitiate(JingleSession session) {
|
||||
JingleContent content = session.getSoleContentOrThrow();
|
||||
notifyTransfer((AbstractJingleFileTransfer) content.getDescription());
|
||||
notifyTransfer((JingleFileTransfer) content.getDescription());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyContentAdd(JingleContent content) {
|
||||
notifyTransfer((AbstractJingleFileTransfer) content.getDescription());
|
||||
notifyTransfer((JingleFileTransfer) content.getDescription());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,19 @@
|
|||
/**
|
||||
*
|
||||
* 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.jft.callback;
|
||||
|
||||
import java.io.File;
|
||||
|
|
|
@ -1,3 +1,19 @@
|
|||
/**
|
||||
*
|
||||
* 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.jft.controller;
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,3 +1,19 @@
|
|||
/**
|
||||
*
|
||||
* 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.jft.controller;
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,3 +1,19 @@
|
|||
/**
|
||||
*
|
||||
* 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.jft.controller;
|
||||
|
||||
import org.jivesoftware.smackx.jft.listener.ProgressListener;
|
||||
|
@ -11,4 +27,5 @@ public interface JingleFileTransferController extends JingleDescriptionControlle
|
|||
void addProgressListener(ProgressListener listener);
|
||||
|
||||
void removeProgressListener(ProgressListener listener);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,24 @@
|
|||
/**
|
||||
*
|
||||
* 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.jft.controller;
|
||||
|
||||
/**
|
||||
* Created by vanitas on 27.07.17.
|
||||
*/
|
||||
public interface OutgoingFileOfferController extends JingleFileTransferController {
|
||||
|
||||
}
|
||||
|
|
|
@ -1,3 +1,19 @@
|
|||
/**
|
||||
*
|
||||
* 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.jft.controller;
|
||||
|
||||
/**
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.jivesoftware.smackx.jft.element;
|
|||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.util.Objects;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
import org.jivesoftware.smackx.jft.internal.JingleFileTransfer;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentElement;
|
||||
|
||||
/**
|
||||
|
@ -58,6 +59,6 @@ public class ChecksumElement implements ExtensionElement {
|
|||
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return JingleFileTransferElement.NAMESPACE_V5;
|
||||
return JingleFileTransfer.NAMESPACE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ package org.jivesoftware.smackx.jft.element;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smackx.jft.internal.AbstractJingleFileTransfer;
|
||||
import org.jivesoftware.smackx.jft.internal.JingleFileTransfer;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionElement;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionChildElement;
|
||||
|
||||
|
@ -38,6 +38,6 @@ public class JingleFileTransferElement extends JingleContentDescriptionElement {
|
|||
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return AbstractJingleFileTransfer.NAMESPACE;
|
||||
return JingleFileTransfer.NAMESPACE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,19 @@
|
|||
/**
|
||||
*
|
||||
* 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.jft.internal;
|
||||
|
||||
import org.jivesoftware.smackx.jft.element.JingleFileTransferElement;
|
||||
|
@ -6,7 +22,7 @@ import org.jivesoftware.smackx.jft.internal.file.AbstractJingleFileTransferFile;
|
|||
/**
|
||||
* Created by vanitas on 22.07.17.
|
||||
*/
|
||||
public abstract class AbstractJingleFileOffer<D extends AbstractJingleFileTransferFile> extends AbstractJingleFileTransfer {
|
||||
public abstract class AbstractJingleFileOffer<D extends AbstractJingleFileTransferFile> extends JingleFileTransfer {
|
||||
|
||||
protected D jingleFile;
|
||||
|
||||
|
|
|
@ -1,8 +1,24 @@
|
|||
/**
|
||||
*
|
||||
* 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.jft.internal;
|
||||
|
||||
/**
|
||||
* Created by vanitas on 22.07.17.
|
||||
*/
|
||||
public abstract class AbstractJingleFileRequest extends AbstractJingleFileTransfer {
|
||||
public abstract class AbstractJingleFileRequest extends JingleFileTransfer {
|
||||
|
||||
}
|
||||
|
|
|
@ -1,3 +1,19 @@
|
|||
/**
|
||||
*
|
||||
* 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.jft.internal;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -12,7 +28,7 @@ import org.jivesoftware.smackx.jingle.components.JingleDescription;
|
|||
/**
|
||||
* Created by vanitas on 22.07.17.
|
||||
*/
|
||||
public abstract class AbstractJingleFileTransfer extends JingleDescription<JingleFileTransferElement> implements JingleFileTransferController {
|
||||
public abstract class JingleFileTransfer extends JingleDescription<JingleFileTransferElement> implements JingleFileTransferController {
|
||||
|
||||
public static final String NAMESPACE_V5 = "urn:xmpp:jingle:apps:file-transfer:5";
|
||||
public static final String NAMESPACE = NAMESPACE_V5;
|
|
@ -1,3 +1,19 @@
|
|||
/**
|
||||
*
|
||||
* 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.jft.internal;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
|
@ -1,3 +1,19 @@
|
|||
/**
|
||||
*
|
||||
* 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.jft.internal;
|
||||
|
||||
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
||||
|
|
|
@ -1,3 +1,19 @@
|
|||
/**
|
||||
*
|
||||
* 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.jft.internal;
|
||||
|
||||
import java.io.File;
|
||||
|
|
|
@ -1,3 +1,19 @@
|
|||
/**
|
||||
*
|
||||
* 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.jft.internal;
|
||||
|
||||
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
||||
|
|
|
@ -1,3 +1,19 @@
|
|||
/**
|
||||
*
|
||||
* 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.jft.internal.file;
|
||||
|
||||
import java.util.Date;
|
||||
|
|
|
@ -1,3 +1,19 @@
|
|||
/**
|
||||
*
|
||||
* 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.jft.internal.file;
|
||||
|
||||
import java.io.File;
|
||||
|
|
|
@ -1,3 +1,19 @@
|
|||
/**
|
||||
*
|
||||
* 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.jft.internal.file;
|
||||
|
||||
import java.util.Date;
|
||||
|
|
|
@ -1,3 +1,19 @@
|
|||
/**
|
||||
*
|
||||
* 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.jft.listener;
|
||||
|
||||
import org.jivesoftware.smackx.jft.controller.IncomingFileOfferController;
|
||||
|
|
|
@ -1,3 +1,19 @@
|
|||
/**
|
||||
*
|
||||
* 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.jft.listener;
|
||||
|
||||
import org.jivesoftware.smackx.jft.controller.IncomingFileRequestController;
|
||||
|
|
|
@ -1,3 +1,19 @@
|
|||
/**
|
||||
*
|
||||
* 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.jft.listener;
|
||||
|
||||
/**
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.util.ArrayList;
|
|||
import org.jivesoftware.smack.util.ParserUtils;
|
||||
import org.jivesoftware.smackx.hashes.element.HashElement;
|
||||
import org.jivesoftware.smackx.hashes.provider.HashElementProvider;
|
||||
import org.jivesoftware.smackx.jft.internal.JingleFileTransfer;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionChildElement;
|
||||
import org.jivesoftware.smackx.jingle.provider.JingleContentDescriptionProvider;
|
||||
import org.jivesoftware.smackx.jft.element.JingleFileTransferElement;
|
||||
|
@ -113,4 +114,9 @@ public class JingleFileTransferProvider
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return JingleFileTransfer.NAMESPACE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,254 +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_filetransfer;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentElement;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleElement;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleReasonElement;
|
||||
import org.jivesoftware.smackx.jingle.transports.JingleTransportInitiationCallback;
|
||||
import org.jivesoftware.smackx.jingle.transports.JingleTransportManager;
|
||||
import org.jivesoftware.smackx.jingle_filetransfer.callback.IncomingFileOfferCallback;
|
||||
import org.jivesoftware.smackx.jft.element.JingleFileTransferElement;
|
||||
import org.jivesoftware.smackx.jingle_filetransfer.handler.FileTransferHandler;
|
||||
|
||||
import org.jxmpp.jid.FullJid;
|
||||
|
||||
/**
|
||||
* We are the responder and we are the recipient.
|
||||
*/
|
||||
public class IncomingJingleFileOffer extends JingleFileTransferSession implements IncomingFileOfferCallback {
|
||||
private static final Logger LOGGER = Logger.getLogger(IncomingJingleFileOffer.class.getName());
|
||||
private JingleElement pendingSessionInitiate = null;
|
||||
private ReceiveTask receivingThread;
|
||||
private File target;
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
if (state == State.active) {
|
||||
Future<?> task = queued.get(0);
|
||||
if (task != null) {
|
||||
task.cancel(true);
|
||||
queued.remove(task);
|
||||
}
|
||||
|
||||
notifyEndedListeners(JingleReasonElement.Reason.cancel);
|
||||
}
|
||||
}
|
||||
|
||||
public enum State {
|
||||
fresh,
|
||||
pending,
|
||||
sent_transport_replace,
|
||||
active,
|
||||
terminated
|
||||
}
|
||||
|
||||
private State state;
|
||||
|
||||
public IncomingJingleFileOffer(XMPPConnection connection, FullJid initiator, String sid) {
|
||||
super(connection, initiator, connection.getUser().asFullJidOrThrow(), Role.responder, sid, Type.offer);
|
||||
state = State.fresh;
|
||||
}
|
||||
|
||||
public IncomingJingleFileOffer(XMPPConnection connection, JingleElement request) {
|
||||
this(connection, request.getInitiator(), request.getSid());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IQ handleSessionInitiate(final JingleElement initiate)
|
||||
throws InterruptedException, XMPPException.XMPPErrorException, SmackException.NotConnectedException,
|
||||
SmackException.NoResponseException {
|
||||
JingleTransportMethodManager tm = JingleTransportMethodManager.getInstanceFor(connection);
|
||||
|
||||
if (state != State.fresh) {
|
||||
//Out of order (initiate after accept)
|
||||
LOGGER.log(Level.WARNING, "Action " + initiate.getAction() + " is out of order!");
|
||||
return jutil.createErrorOutOfOrder(initiate);
|
||||
}
|
||||
|
||||
this.contents.addAll(initiate.getContents());
|
||||
this.file = (JingleFileTransferElement) contents.get(0).getDescription();
|
||||
|
||||
JingleTransportManager<?> transportManager = tm.getTransportManager(initiate);
|
||||
if (transportManager == null) {
|
||||
//Try fallback.
|
||||
pendingSessionInitiate = initiate;
|
||||
transportManager = tm.getBestAvailableTransportManager();
|
||||
|
||||
if (transportManager == null) {
|
||||
//No usable transports.
|
||||
LOGGER.log(Level.WARNING, "No usable transports.");
|
||||
connection.createStanzaCollectorAndSend(jutil.createSessionTerminateUnsupportedTransports(getInitiator(), getSessionId()));
|
||||
state = State.terminated;
|
||||
return jutil.createAck(initiate);
|
||||
}
|
||||
|
||||
transportSession = transportManager.transportSession(this);
|
||||
jutil.sendTransportReplace(initiate.getFrom().asFullJidOrThrow(), getInitiator(),
|
||||
getSessionId(), contents.get(0).getCreator(), contents.get(0).getName(),
|
||||
transportSession.createTransport());
|
||||
state = State.sent_transport_replace;
|
||||
return jutil.createAck(initiate);
|
||||
}
|
||||
|
||||
transportSession = transportManager.transportSession(this);
|
||||
transportSession.processJingle(initiate);
|
||||
|
||||
state = State.pending;
|
||||
|
||||
JingleFileTransferManagerAlt.getInstanceFor(connection).notifyIncomingFileOffer(initiate,
|
||||
IncomingJingleFileOffer.this);
|
||||
|
||||
return jutil.createAck(initiate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IQ handleTransportReplace(final JingleElement transportReplace)
|
||||
throws InterruptedException, XMPPException.XMPPErrorException,
|
||||
SmackException.NotConnectedException, SmackException.NoResponseException {
|
||||
final JingleTransportManager<?> replacementManager = JingleTransportMethodManager.getInstanceFor(connection)
|
||||
.getTransportManager(transportReplace);
|
||||
|
||||
queued.add(JingleManager.getThreadPool().submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (replacementManager != null) {
|
||||
LOGGER.log(Level.INFO, "Accept transport-replace.");
|
||||
IncomingJingleFileOffer.this.transportSession = replacementManager.transportSession(IncomingJingleFileOffer.this);
|
||||
transportSession.processJingle(transportReplace);
|
||||
transportSession.initiateIncomingSession(new JingleTransportInitiationCallback() {
|
||||
@Override
|
||||
public void onSessionInitiated(BytestreamSession bytestreamSession) {
|
||||
LOGGER.log(Level.INFO, "Bytestream initiated. Start receiving.");
|
||||
receivingThread = new ReceiveTask(IncomingJingleFileOffer.this, bytestreamSession, file, target);
|
||||
queued.add(JingleManager.getThreadPool().submit(receivingThread));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onException(Exception e) {
|
||||
LOGGER.log(Level.SEVERE, "EXCEPTION IN INCOMING SESSION: ", e);
|
||||
}
|
||||
});
|
||||
|
||||
jutil.sendTransportAccept(transportReplace.getFrom().asFullJidOrThrow(),
|
||||
transportReplace.getInitiator(), transportReplace.getSid(),
|
||||
getContents().get(0).getCreator(), getContents().get(0).getName(),
|
||||
transportSession.createTransport());
|
||||
|
||||
} else {
|
||||
LOGGER.log(Level.INFO, "Unsupported transport. Reject transport-replace.");
|
||||
jutil.sendTransportReject(transportReplace.getFrom().asFullJidOrThrow(), transportReplace.getInitiator(),
|
||||
transportReplace.getSid(), getContents().get(0).getCreator(),
|
||||
getContents().get(0).getName(), transportReplace.getContents().get(0).getTransport());
|
||||
}
|
||||
} catch (InterruptedException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | SmackException.NoResponseException e) {
|
||||
LOGGER.log(Level.SEVERE, "Help me please!", e);
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
return jutil.createAck(transportReplace);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IQ handleTransportAccept(JingleElement transportAccept) {
|
||||
LOGGER.log(Level.INFO, "Received transport-accept.");
|
||||
if (state != State.sent_transport_replace) {
|
||||
LOGGER.log(Level.WARNING, "Session is in state " + state + ", so the transport-accept is out of order.");
|
||||
return jutil.createErrorOutOfOrder(transportAccept);
|
||||
}
|
||||
|
||||
JingleFileTransferManagerAlt.getInstanceFor(connection)
|
||||
.notifyIncomingFileOffer(pendingSessionInitiate, this);
|
||||
transportSession.processJingle(transportAccept);
|
||||
state = State.pending;
|
||||
return jutil.createAck(transportAccept);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTransportMethodFailed(String namespace) {
|
||||
//Nothing to do.
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileTransferHandler acceptIncomingFileOffer(final JingleElement request, final File target) {
|
||||
this.target = target;
|
||||
LOGGER.log(Level.INFO, "Client accepted incoming file offer. Try to start receiving.");
|
||||
if (transportSession == null) {
|
||||
//Unsupported transport
|
||||
LOGGER.log(Level.WARNING, "Unsupported Transport method.");
|
||||
try {
|
||||
jutil.sendSessionTerminateUnsupportedTransports(request.getFrom().asFullJidOrThrow(), sid);
|
||||
} catch (InterruptedException | SmackException.NoResponseException |
|
||||
SmackException.NotConnectedException | XMPPException.XMPPErrorException e) {
|
||||
LOGGER.log(Level.SEVERE, "Could not send session-terminate: " + e, e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
state = State.active;
|
||||
|
||||
try {
|
||||
jutil.sendSessionAccept(getInitiator(), sid, getContents().get(0).getCreator(),
|
||||
getContents().get(0).getName(), JingleContentElement.Senders.initiator, file,
|
||||
transportSession.createTransport());
|
||||
} catch (SmackException.NotConnectedException | SmackException.NoResponseException |
|
||||
XMPPException.XMPPErrorException | InterruptedException e) {
|
||||
LOGGER.log(Level.WARNING, "Could not send session-accept.", e);
|
||||
}
|
||||
|
||||
transportSession.initiateIncomingSession(new JingleTransportInitiationCallback() {
|
||||
@Override
|
||||
public void onSessionInitiated(BytestreamSession bytestreamSession) {
|
||||
LOGGER.log(Level.INFO, "Bytestream initiated. Start receiving.");
|
||||
receivingThread = new ReceiveTask(IncomingJingleFileOffer.this, bytestreamSession, file, target);
|
||||
queued.add(JingleManager.getThreadPool().submit(receivingThread));
|
||||
started = true;
|
||||
notifyStartedListeners();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onException(Exception e) {
|
||||
LOGGER.log(Level.SEVERE, "EXCEPTION IN INCOMING SESSION: ", e);
|
||||
}
|
||||
});
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void declineIncomingFileOffer(JingleElement request) {
|
||||
state = State.terminated;
|
||||
try {
|
||||
jutil.sendSessionTerminateDecline(request.getInitiator(), request.getSid());
|
||||
} catch (SmackException.NotConnectedException | SmackException.NoResponseException |
|
||||
XMPPException.XMPPErrorException | InterruptedException e) {
|
||||
LOGGER.log(Level.SEVERE, "Could not send session-terminate: " + e, e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,54 +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_filetransfer;
|
||||
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smackx.jingle.JingleManager;
|
||||
import org.jivesoftware.smackx.jingle.util.Role;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleElement;
|
||||
|
||||
import org.jxmpp.jid.FullJid;
|
||||
|
||||
/**
|
||||
* Request.
|
||||
*/
|
||||
public class JingleFileRequest extends JingleFileTransferSession {
|
||||
|
||||
public JingleFileRequest(XMPPConnection connection, FullJid initiator, FullJid responder, Role role, String sid) {
|
||||
super(connection, initiator, responder, role, sid, Type.request);
|
||||
}
|
||||
|
||||
public static JingleFileRequest createOutgoingFileRequest(XMPPConnection connection, FullJid recipient) {
|
||||
return new JingleFileRequest(connection, connection.getUser().asFullJidOrThrow(), recipient, Role.initiator,
|
||||
JingleManager.randomId());
|
||||
}
|
||||
|
||||
public static JingleFileRequest createIncomingFileRequest(XMPPConnection connection, JingleElement request) {
|
||||
return new JingleFileRequest(connection, request.getInitiator(), connection.getUser().asFullJidOrThrow(), Role.responder,
|
||||
request.getSid());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTransportMethodFailed(String namespace) {
|
||||
//Not implemented
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
|
||||
}
|
||||
}
|
|
@ -1,153 +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_filetransfer;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.jivesoftware.smack.Manager;
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||
import org.jivesoftware.smackx.jft.element.JingleFileTransferChildElement;
|
||||
import org.jivesoftware.smackx.jft.element.JingleFileTransferElement;
|
||||
import org.jivesoftware.smackx.jft.internal.AbstractJingleFileTransfer;
|
||||
import org.jivesoftware.smackx.jft.provider.JingleFileTransferProvider;
|
||||
import org.jivesoftware.smackx.jingle.JingleManager;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleAction;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionChildElement;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentElement;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleElement;
|
||||
import org.jivesoftware.smackx.jingle.provider.JingleContentProviderManager;
|
||||
import org.jivesoftware.smackx.jingle.transport.legacy.JingleUtil;
|
||||
import org.jivesoftware.smackx.jingle_filetransfer.callback.IncomingFileOfferCallback;
|
||||
import org.jivesoftware.smackx.jingle_filetransfer.handler.FileTransferHandler;
|
||||
import org.jivesoftware.smackx.jingle_filetransfer.listener.JingleFileTransferOfferListener;
|
||||
|
||||
import org.jxmpp.jid.FullJid;
|
||||
|
||||
/**
|
||||
* Manager for JingleFileTransfer (XEP-0234).
|
||||
*/
|
||||
public final class JingleFileTransferManagerAlt extends Manager {
|
||||
private static final Logger LOGGER = Logger.getLogger(JingleFileTransferManagerAlt.class.getName());
|
||||
|
||||
private static final WeakHashMap<XMPPConnection, JingleFileTransferManagerAlt> INSTANCES = new WeakHashMap<>();
|
||||
private final ArrayList<JingleFileTransferOfferListener> jingleFileTransferOfferListeners = new ArrayList<>();
|
||||
|
||||
private JingleFileTransferManagerAlt(XMPPConnection connection) {
|
||||
super(connection);
|
||||
ServiceDiscoveryManager.getInstanceFor(connection).addFeature(AbstractJingleFileTransfer.NAMESPACE_V5);
|
||||
JingleManager jingleManager = JingleManager.getInstanceFor(connection);
|
||||
jingleManager.addJingleDescriptionManager(this);
|
||||
JingleContentProviderManager.addJingleContentDescriptionProvider(
|
||||
JingleFileTransferElement.NAMESPACE_V5, new JingleFileTransferProvider());
|
||||
jutil = new JingleUtil(connection);
|
||||
}
|
||||
|
||||
public static JingleFileTransferManagerAlt getInstanceFor(XMPPConnection connection) {
|
||||
JingleFileTransferManagerAlt manager = INSTANCES.get(connection);
|
||||
if (manager == null) {
|
||||
manager = new JingleFileTransferManagerAlt(connection);
|
||||
INSTANCES.put(connection, manager);
|
||||
}
|
||||
return manager;
|
||||
}
|
||||
|
||||
public FileTransferHandler sendFile(FullJid recipient, File file)
|
||||
throws InterruptedException, XMPPException.XMPPErrorException,
|
||||
SmackException.NotConnectedException, SmackException.NoResponseException {
|
||||
OutgoingJingleFileOffer offer = new OutgoingJingleFileOffer(connection(), recipient);
|
||||
JingleManager.getInstanceFor(connection()).registerJingleSessionHandler(recipient, offer.getSessionId(), offer);
|
||||
offer.send(file);
|
||||
return offer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IQ handleJingleRequest(JingleElement jingle) {
|
||||
FullJid fullJid = jingle.getFrom().asFullJidOrThrow();
|
||||
String sid = jingle.getSid();
|
||||
|
||||
//Get handler
|
||||
JingleFileTransferSession handler;
|
||||
try {
|
||||
handler = createSessionHandler(jingle);
|
||||
} catch (IllegalArgumentException malformed) {
|
||||
return jutil.createErrorMalformedRequest(jingle);
|
||||
}
|
||||
|
||||
JingleManager.getInstanceFor(connection()).registerJingleSessionHandler(fullJid, sid, handler);
|
||||
|
||||
return handler.handleJingleSessionRequest(jingle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a session handler (FileOffer or FileRequest) for the request.
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
private JingleFileTransferSession createSessionHandler(JingleElement request) {
|
||||
if (request.getAction() != JingleAction.session_initiate) {
|
||||
LOGGER.log(Level.WARNING, "First received action must be session-initiate.");
|
||||
throw new IllegalArgumentException("Requests action MUST be session-initiate.");
|
||||
}
|
||||
|
||||
JingleContentElement content = request.getContents().get(0);
|
||||
//File Offer
|
||||
if (content.getSenders() == JingleContentElement.Senders.initiator) {
|
||||
return new IncomingJingleFileOffer(connection(), request);
|
||||
} //File Request
|
||||
else if (content.getSenders() == JingleContentElement.Senders.responder) {
|
||||
return JingleFileRequest.createIncomingFileRequest(connection(), request);
|
||||
}
|
||||
else {
|
||||
// If senders is neither initiator, nor responder, consider session malformed.
|
||||
// See XEP-0166 §6.3 Example 16 and XEP-0234 §4.1
|
||||
LOGGER.log(Level.WARNING, "Jingle has invalid sender value. Only initiator and responder are allowed.");
|
||||
throw new IllegalArgumentException("Requests content.senders MUST be either responder or initiator.");
|
||||
}
|
||||
}
|
||||
|
||||
public void notifyIncomingFileOffer(JingleElement initiate, IncomingFileOfferCallback callback) {
|
||||
for (JingleFileTransferOfferListener l : jingleFileTransferOfferListeners) {
|
||||
l.onFileOffer(initiate, callback);
|
||||
}
|
||||
}
|
||||
|
||||
public void addJingleFileTransferOfferListener(JingleFileTransferOfferListener listener) {
|
||||
jingleFileTransferOfferListeners.add(listener);
|
||||
}
|
||||
|
||||
public void removeJingleFileTransferOfferListener(JingleFileTransferOfferListener listener) {
|
||||
jingleFileTransferOfferListeners.remove(listener);
|
||||
}
|
||||
|
||||
public static JingleFileTransferElement fileTransferFromFile(File file) {
|
||||
JingleFileTransferChildElement.Builder fb = JingleFileTransferChildElement.getBuilder();
|
||||
fb.setFile(file)
|
||||
.setDescription("A file.")
|
||||
.setMediaType("application/octet-stream");
|
||||
|
||||
return new JingleFileTransferElement(Collections.<JingleContentDescriptionChildElement>singletonList(fb.build()));
|
||||
}
|
||||
}
|
|
@ -1,119 +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_filetransfer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smackx.jingle.transport.legacy.JingleUtil;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleReasonElement;
|
||||
import org.jivesoftware.smackx.jft.element.JingleFileTransferElement;
|
||||
import org.jivesoftware.smackx.jingle_filetransfer.handler.FileTransferHandler;
|
||||
|
||||
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 implements FileTransferHandler {
|
||||
|
||||
protected final ArrayList<EndedListener> endedListeners = new ArrayList<>();
|
||||
protected final ArrayList<StartedListener> startedListeners = new ArrayList<>();
|
||||
|
||||
protected boolean started, ended;
|
||||
|
||||
public enum Type {
|
||||
offer,
|
||||
request,
|
||||
;
|
||||
}
|
||||
|
||||
protected final XMPPConnection connection;
|
||||
protected final JingleUtil jutil;
|
||||
|
||||
protected JingleFileTransferElement file;
|
||||
|
||||
private final Type type;
|
||||
|
||||
public JingleFileTransferSession(XMPPConnection connection, FullJid initiator, FullJid responder, Role role, String sid, Type type) {
|
||||
super(initiator, responder, role, sid);
|
||||
this.type = type;
|
||||
this.connection = connection;
|
||||
this.jutil = new JingleUtil(connection);
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFinished() {
|
||||
return ended;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStarted() {
|
||||
return started;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEndedListener(EndedListener listener) {
|
||||
endedListeners.add(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addStartedListener(StartedListener listener) {
|
||||
startedListeners.add(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyEndedListeners(JingleReasonElement.Reason reason) {
|
||||
ended = true;
|
||||
for (EndedListener e : endedListeners) {
|
||||
e.onEnded(reason);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyStartedListeners() {
|
||||
started = true;
|
||||
for (StartedListener s : startedListeners) {
|
||||
s.onStarted();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public XMPPConnection getConnection() {
|
||||
return connection;
|
||||
}
|
||||
}
|
|
@ -1,229 +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_filetransfer;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.SmackFuture;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleElement;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentElement;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleReasonElement;
|
||||
import org.jivesoftware.smackx.jingle.transports.JingleTransportInitiationCallback;
|
||||
import org.jivesoftware.smackx.jingle.transports.JingleTransportManager;
|
||||
import org.jivesoftware.smackx.jft.element.JingleFileTransferElement;
|
||||
|
||||
import org.jxmpp.jid.FullJid;
|
||||
|
||||
/**
|
||||
* We are the initiator and we are the sender.
|
||||
*/
|
||||
public class OutgoingJingleFileOffer extends JingleFileTransferSession {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(OutgoingJingleFileOffer.class.getName());
|
||||
|
||||
@Override
|
||||
public void cancel() throws InterruptedException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException {
|
||||
switch (state) {
|
||||
case terminated:
|
||||
return;
|
||||
|
||||
case active:
|
||||
Future<?> task = queued.get(0);
|
||||
if (task != null) {
|
||||
task.cancel(true);
|
||||
queued.remove(task);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
}
|
||||
|
||||
jutil.sendSessionTerminateCancel(getRemote(), getSessionId());
|
||||
notifyEndedListeners(JingleReasonElement.Reason.cancel);
|
||||
}
|
||||
|
||||
public enum State {
|
||||
fresh,
|
||||
pending,
|
||||
sent_transport_replace,
|
||||
active,
|
||||
terminated
|
||||
}
|
||||
|
||||
private Runnable sendingThread;
|
||||
private File source;
|
||||
private State state;
|
||||
|
||||
|
||||
public OutgoingJingleFileOffer(XMPPConnection connection, FullJid responder, String sid) {
|
||||
super(connection, connection.getUser().asFullJidOrThrow(), responder, Role.initiator, sid, Type.offer);
|
||||
state = State.fresh;
|
||||
}
|
||||
|
||||
public OutgoingJingleFileOffer(XMPPConnection connection, FullJid recipient) {
|
||||
this(connection, recipient, JingleManager.randomId());
|
||||
}
|
||||
|
||||
public void send(File file) throws InterruptedException, XMPPException.XMPPErrorException,
|
||||
SmackException.NotConnectedException, SmackException.NoResponseException {
|
||||
source = file;
|
||||
String contentName = JingleManager.randomId();
|
||||
JingleFileTransferElement transfer = JingleFileTransferManagerAlt.fileTransferFromFile(file);
|
||||
|
||||
initiateFileOffer(transfer, JingleContentElement.Creator.initiator, contentName);
|
||||
}
|
||||
|
||||
public SmackFuture<?> sendAsync(File file) {
|
||||
source = file;
|
||||
String contentName = "jft-" + StringUtils.randomString(20);
|
||||
JingleFileTransferElement transfer = JingleFileTransferManagerAlt.fileTransferFromFile(file);
|
||||
return null; //TODO
|
||||
}
|
||||
|
||||
public void initiateFileOffer(JingleFileTransferElement file, JingleContentElement.Creator creator, String name) throws InterruptedException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException {
|
||||
if (state != State.fresh) {
|
||||
throw new IllegalStateException("This session is not fresh.");
|
||||
}
|
||||
|
||||
JingleTransportManager<?> transportManager = JingleTransportMethodManager.getInstanceFor(connection)
|
||||
.getBestAvailableTransportManager();
|
||||
|
||||
if (transportManager == null) {
|
||||
throw new IllegalStateException("There must be at least one workable transport method.");
|
||||
}
|
||||
|
||||
transportSession = transportManager.transportSession(this);
|
||||
|
||||
state = State.pending;
|
||||
|
||||
JingleElement initiate = jutil.createSessionInitiateFileOffer(getResponder(), getSessionId(), creator, name, file, transportSession.createTransport(), null);
|
||||
this.contents.addAll(initiate.getContents());
|
||||
|
||||
connection.sendStanza(initiate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IQ handleSessionAccept(JingleElement sessionAccept) throws SmackException.NotConnectedException, InterruptedException {
|
||||
// Out of order?
|
||||
if (state != State.pending) {
|
||||
LOGGER.log(Level.WARNING, "Session state is " + state + ", so session-accept is out of order.");
|
||||
return jutil.createErrorOutOfOrder(sessionAccept);
|
||||
}
|
||||
|
||||
state = State.active;
|
||||
|
||||
transportSession.processJingle(sessionAccept);
|
||||
|
||||
transportSession.initiateOutgoingSession(new JingleTransportInitiationCallback() {
|
||||
@Override
|
||||
public void onSessionInitiated(final BytestreamSession byteStream) {
|
||||
sendingThread = new SendTask(OutgoingJingleFileOffer.this, byteStream, source);
|
||||
queued.add(JingleManager.getThreadPool().submit(sendingThread));
|
||||
notifyStartedListeners();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onException(Exception e) {
|
||||
LOGGER.log(Level.SEVERE, "EXCEPTION IN OUTGOING SESSION:", e);
|
||||
}
|
||||
});
|
||||
|
||||
return jutil.createAck(sessionAccept);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IQ handleSessionTerminate(JingleElement sessionTerminate) {
|
||||
state = State.terminated;
|
||||
return jutil.createAck(sessionTerminate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IQ handleTransportReplace(final JingleElement transportReplace)
|
||||
throws InterruptedException, XMPPException.XMPPErrorException,
|
||||
SmackException.NotConnectedException, SmackException.NoResponseException {
|
||||
final JingleTransportManager<?> replacementManager = JingleTransportMethodManager.getInstanceFor(connection)
|
||||
.getTransportManager(transportReplace);
|
||||
|
||||
queued.add(JingleManager.getThreadPool().submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (replacementManager != null) {
|
||||
LOGGER.log(Level.INFO, "Accept transport-replace.");
|
||||
jutil.sendTransportAccept(transportReplace.getFrom().asFullJidOrThrow(),
|
||||
transportReplace.getInitiator(), transportReplace.getSid(),
|
||||
getContents().get(0).getCreator(), getContents().get(0).getName(),
|
||||
transportSession.createTransport());
|
||||
} else {
|
||||
LOGGER.log(Level.INFO, "Unsupported transport. Reject transport-replace.");
|
||||
jutil.sendTransportReject(transportReplace.getFrom().asFullJidOrThrow(), transportReplace.getInitiator(),
|
||||
transportReplace.getSid(), getContents().get(0).getCreator(),
|
||||
getContents().get(0).getName(), transportReplace.getContents().get(0).getTransport());
|
||||
}
|
||||
} catch (InterruptedException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | SmackException.NoResponseException e) {
|
||||
LOGGER.log(Level.SEVERE, "Help me please!", e);
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
return jutil.createAck(transportReplace);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IQ handleTransportAccept(JingleElement transportAccept)
|
||||
throws SmackException.NotConnectedException, InterruptedException {
|
||||
|
||||
return handleSessionAccept(transportAccept);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTransportMethodFailed(String namespace) {
|
||||
state = State.pending;
|
||||
JingleContentElement content = contents.get(0);
|
||||
failedTransportMethods.add(namespace);
|
||||
JingleTransportMethodManager tm = JingleTransportMethodManager.getInstanceFor(getConnection());
|
||||
JingleTransportManager<?> next = tm.getBestAvailableTransportManager(failedTransportMethods);
|
||||
|
||||
if (next == null) {
|
||||
//Failure
|
||||
try {
|
||||
jutil.sendSessionTerminateUnsupportedTransports(getRemote(), getSessionId());
|
||||
} catch (InterruptedException | SmackException.NoResponseException | SmackException.NotConnectedException | XMPPException.XMPPErrorException e) {
|
||||
LOGGER.log(Level.WARNING, "Could not send session-terminate.", e);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
//Replace transport
|
||||
this.transportSession = next.transportSession(this);
|
||||
try {
|
||||
jutil.sendTransportReplace(getRemote(), getInitiator(), getSessionId(), content.getCreator(), content.getName(),
|
||||
transportSession.createTransport());
|
||||
} catch (SmackException.NotConnectedException | SmackException.NoResponseException | XMPPException.XMPPErrorException | InterruptedException e) {
|
||||
LOGGER.log(Level.WARNING, "Could not send transport-replace.", e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,96 +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_filetransfer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleReasonElement;
|
||||
import org.jivesoftware.smackx.jft.element.JingleFileTransferElement;
|
||||
import org.jivesoftware.smackx.jft.element.JingleFileTransferChildElement;
|
||||
|
||||
/**
|
||||
* Thread for receiving data.
|
||||
*/
|
||||
public class ReceiveTask implements Runnable {
|
||||
private static final Logger LOGGER = Logger.getLogger(ReceiveTask.class.getName());
|
||||
|
||||
private final BytestreamSession byteStream;
|
||||
private final JingleFileTransferElement fileTransfer;
|
||||
private final File target;
|
||||
private final JingleFileTransferSession session;
|
||||
|
||||
public ReceiveTask(JingleFileTransferSession session, BytestreamSession byteStream, JingleFileTransferElement fileTransfer, File target) {
|
||||
this.byteStream = byteStream;
|
||||
this.fileTransfer = fileTransfer;
|
||||
this.target = target;
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
JingleFileTransferChildElement transfer = (JingleFileTransferChildElement) fileTransfer.getJingleContentDescriptionChildren().get(0);
|
||||
FileOutputStream outputStream = null;
|
||||
InputStream inputStream;
|
||||
|
||||
try {
|
||||
outputStream = new FileOutputStream(target);
|
||||
inputStream = byteStream.getInputStream();
|
||||
|
||||
byte[] filebuf = new byte[transfer.getSize()];
|
||||
int read = 0;
|
||||
byte[] bufbuf = new byte[4096];
|
||||
LOGGER.log(Level.INFO, "Begin receiving bytes.");
|
||||
while (read < filebuf.length) {
|
||||
int r = inputStream.read(bufbuf);
|
||||
if (r >= 0) {
|
||||
System.arraycopy(bufbuf, 0, filebuf, read, r);
|
||||
read += r;
|
||||
LOGGER.log(Level.INFO, "Read " + r + " (" + read + " of " + filebuf.length + ") bytes.");
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
outputStream.write(filebuf);
|
||||
LOGGER.log(Level.INFO, "File successfully received.");
|
||||
|
||||
} catch (IOException e) {
|
||||
LOGGER.log(Level.SEVERE, "Error while receiving data: ", e);
|
||||
} finally {
|
||||
try {
|
||||
byteStream.close();
|
||||
} catch (IOException e) {
|
||||
LOGGER.log(Level.SEVERE, "Could not close InputStream.", e);
|
||||
}
|
||||
if (outputStream != null) {
|
||||
try {
|
||||
outputStream.close();
|
||||
} catch (IOException e) {
|
||||
LOGGER.log(Level.SEVERE, "Could not close FileOutputStream.", e);
|
||||
}
|
||||
}
|
||||
|
||||
session.notifyEndedListeners(JingleReasonElement.Reason.success);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,84 +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_filetransfer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleReasonElement;
|
||||
|
||||
/**
|
||||
* Created by vanitas on 21.06.17.
|
||||
*/
|
||||
public class SendTask implements Runnable {
|
||||
private static final Logger LOGGER = Logger.getLogger(SendTask.class.getName());
|
||||
|
||||
private final BytestreamSession byteStream;
|
||||
private final JingleFileTransferSession session;
|
||||
private final File source;
|
||||
|
||||
public SendTask(JingleFileTransferSession session, BytestreamSession byteStream, File source) {
|
||||
this.byteStream = byteStream;
|
||||
this.source = source;
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
InputStream inputStream = null;
|
||||
OutputStream outputStream = null;
|
||||
|
||||
try {
|
||||
inputStream = new FileInputStream(source);
|
||||
outputStream = byteStream.getOutputStream();
|
||||
|
||||
byte[] filebuf = new byte[(int) source.length()];
|
||||
int r = inputStream.read(filebuf);
|
||||
|
||||
if (r < 0) {
|
||||
throw new IOException("Read returned -1");
|
||||
}
|
||||
|
||||
LOGGER.log(Level.INFO, "WRITE");
|
||||
outputStream.write(filebuf);
|
||||
outputStream.flush();
|
||||
LOGGER.log(Level.INFO, "WRITING FINISHED");
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOGGER.log(Level.SEVERE, "Could not send file: " + e, e);
|
||||
}
|
||||
|
||||
finally {
|
||||
try {
|
||||
if (inputStream != null) {
|
||||
inputStream.close();
|
||||
LOGGER.log(Level.INFO, "InputStream closed.");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LOGGER.log(Level.SEVERE, "Could not close session.", e);
|
||||
}
|
||||
|
||||
session.notifyEndedListeners(JingleReasonElement.Reason.success);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,32 +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_filetransfer.callback;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.jivesoftware.smackx.jingle.element.JingleElement;
|
||||
import org.jivesoftware.smackx.jingle_filetransfer.handler.FileTransferHandler;
|
||||
|
||||
/**
|
||||
* Callback used to accept/decline file offers.
|
||||
*/
|
||||
public interface IncomingFileOfferCallback {
|
||||
|
||||
FileTransferHandler acceptIncomingFileOffer(JingleElement request, File target);
|
||||
|
||||
void declineIncomingFileOffer(JingleElement request);
|
||||
}
|
|
@ -1,31 +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_filetransfer.callback;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.jivesoftware.smackx.jingle.element.JingleElement;
|
||||
|
||||
/**
|
||||
* Callback used to accept/decline file requests.
|
||||
*/
|
||||
public interface IncomingFileRequestCallback {
|
||||
|
||||
void acceptIncomingFileRequest(JingleElement request, File source);
|
||||
|
||||
void declineIncomingFileRequest(JingleElement request);
|
||||
}
|
|
@ -1,22 +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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smack's API for <a href="https://xmpp.org/extensions/xep-0234.html">XEP-0234: Jingle File Transfer</a>.
|
||||
* Callbacks.
|
||||
*/
|
||||
package org.jivesoftware.smackx.jingle_filetransfer.callback;
|
|
@ -1,81 +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_filetransfer.handler;
|
||||
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleReasonElement;
|
||||
|
||||
/**
|
||||
* Handler that provides some control over the JingleFileOffer session.
|
||||
*/
|
||||
public interface FileTransferHandler {
|
||||
|
||||
/**
|
||||
* Cancels the current file transfer.
|
||||
*/
|
||||
void cancel() throws InterruptedException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException;
|
||||
|
||||
/**
|
||||
* Returns true, if the file transfer is ended.
|
||||
* @return true if transfer ended.
|
||||
*/
|
||||
boolean isFinished();
|
||||
|
||||
/**
|
||||
* Returns true, if the file transfer is started.
|
||||
* @return true if started.
|
||||
*/
|
||||
boolean isStarted();
|
||||
|
||||
/**
|
||||
* Add a new FinishedListener.
|
||||
* @param listener listener
|
||||
*/
|
||||
void addEndedListener(EndedListener listener);
|
||||
|
||||
/**
|
||||
* Add a new AcceptedListener.
|
||||
* @param listener listener
|
||||
*/
|
||||
void addStartedListener(StartedListener listener);
|
||||
|
||||
/**
|
||||
* Notify all registered FinishedListeners that the file transfer has ended.
|
||||
*/
|
||||
void notifyEndedListeners(JingleReasonElement.Reason reason);
|
||||
|
||||
/**
|
||||
* Notify all registered AcceptedListeners that the file transfer session has been accepted by the remote user.
|
||||
*/
|
||||
void notifyStartedListeners();
|
||||
|
||||
/**
|
||||
* A FinishedListener will be notified by the SendFileHandler when the corresponding file transfer is ended.
|
||||
*/
|
||||
interface EndedListener {
|
||||
void onEnded(JingleReasonElement.Reason reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* An AcceptedListener will be notified by the SendFileHandler when the corresponding pending session has been
|
||||
* accepted by the remote user.
|
||||
*/
|
||||
interface StartedListener {
|
||||
void onStarted();
|
||||
}
|
||||
}
|
|
@ -1,22 +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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smack's API for <a href="https://xmpp.org/extensions/xep-0234.html">XEP-0234: Jingle File Transfer</a>.
|
||||
* Handlers.
|
||||
*/
|
||||
package org.jivesoftware.smackx.jingle_filetransfer.handler;
|
|
@ -1,28 +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_filetransfer.listener;
|
||||
|
||||
import org.jivesoftware.smackx.jingle.element.JingleElement;
|
||||
import org.jivesoftware.smackx.jingle_filetransfer.callback.IncomingFileOfferCallback;
|
||||
|
||||
/**
|
||||
* Listener for incoming Jingle File Transfer (XEP-0234) file offers.
|
||||
*/
|
||||
public interface JingleFileTransferOfferListener {
|
||||
|
||||
void onFileOffer(JingleElement request, IncomingFileOfferCallback callback);
|
||||
}
|
|
@ -1,22 +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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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;
|
|
@ -1,21 +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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smack's API for <a href="https://xmpp.org/extensions/xep-0234.html">XEP-0234: Jingle File Transfer</a>.
|
||||
*/
|
||||
package org.jivesoftware.smackx.jingle_filetransfer;
|
|
@ -14,7 +14,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.jingle_filetransfer;
|
||||
package org.jivesoftware.smackx.jft;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
|
|
@ -1,185 +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_filetransfer;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static junit.framework.TestCase.assertNull;
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
|
||||
import org.jivesoftware.smack.DummyConnection;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.test.util.SmackTestSuite;
|
||||
import org.jivesoftware.smack.test.util.TestUtils;
|
||||
import org.jivesoftware.smackx.hashes.HashManager;
|
||||
import org.jivesoftware.smackx.hashes.element.HashElement;
|
||||
import org.jivesoftware.smackx.jingle.transport.legacy.JingleUtil;
|
||||
import org.jivesoftware.smackx.jingle.JingleUtilTest;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentElement;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleElement;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleAction;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionChildElement;
|
||||
import org.jivesoftware.smackx.jingle.transports.jingle_ibb.element.JingleIBBTransport;
|
||||
import org.jivesoftware.smackx.jft.element.JingleFileTransferElement;
|
||||
import org.jivesoftware.smackx.jft.element.JingleFileTransferChildElement;
|
||||
import org.jivesoftware.smackx.jft.provider.JingleFileTransferProvider;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.jxmpp.jid.FullJid;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
import org.jxmpp.stringprep.XmppStringprepException;
|
||||
import org.jxmpp.util.XmppDateTime;
|
||||
|
||||
/**
|
||||
* Created by vanitas on 12.07.17.
|
||||
*/
|
||||
public class JingleUtilFileTransferTest extends SmackTestSuite {
|
||||
private XMPPConnection connection;
|
||||
private JingleUtil jutil;
|
||||
|
||||
private FullJid romeo;
|
||||
private FullJid juliet;
|
||||
|
||||
@Before
|
||||
public void setup() throws XmppStringprepException {
|
||||
connection = new DummyConnection(
|
||||
DummyConnection.getDummyConfigurationBuilder()
|
||||
.setUsernameAndPassword("romeo@montague.lit",
|
||||
"iluvJulibabe13").build());
|
||||
JingleManager jm = JingleManager.getInstanceFor(connection);
|
||||
jutil = new JingleUtil(connection);
|
||||
romeo = connection.getUser().asFullJidOrThrow();
|
||||
juliet = JidCreate.fullFrom("juliet@capulet.lit/balcony");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createSessionInitiateTest() throws Exception {
|
||||
JingleIBBTransport transport = new JingleIBBTransport("transid");
|
||||
Date date = new Date();
|
||||
HashElement hash = new HashElement(HashManager.ALGORITHM.SHA_256, "f4OxZX/x/FO5LcGBSKHWXfwtSx+j1ncoSt3SABJtkGk=");
|
||||
JingleFileTransferChildElement file = new JingleFileTransferChildElement(date, "desc", hash, "application/octet-stream", "name", 1337, null);
|
||||
JingleFileTransferElement description = new JingleFileTransferElement(Collections.<JingleContentDescriptionChildElement>singletonList(file));
|
||||
|
||||
String contentName = "content";
|
||||
|
||||
JingleElement initiate = jutil.createSessionInitiate(juliet, "letsstart", JingleContentElement.Creator.initiator, contentName, JingleContentElement.Senders.initiator, description, transport);
|
||||
JingleElement accept = jutil.createSessionAccept(juliet, "acceptID", JingleContentElement.Creator.initiator, contentName, JingleContentElement.Senders.initiator, description, transport);
|
||||
JingleElement fileOffer = jutil.createSessionInitiateFileOffer(juliet, "fileOffer", JingleContentElement.Creator.initiator, contentName, description, transport);
|
||||
|
||||
assertEquals(JingleAction.session_initiate, initiate.getAction());
|
||||
assertEquals(JingleAction.session_accept, accept.getAction());
|
||||
|
||||
assertEquals(romeo, initiate.getInitiator());
|
||||
assertEquals(romeo, accept.getResponder());
|
||||
//Must be null
|
||||
assertNull(initiate.getResponder());
|
||||
assertNull(accept.getInitiator());
|
||||
|
||||
assertEquals("letsstart", initiate.getSid());
|
||||
assertEquals("acceptID", accept.getSid());
|
||||
|
||||
assertEquals(1, initiate.getContents().size());
|
||||
assertEquals(1, accept.getContents().size());
|
||||
|
||||
JingleContentElement content = initiate.getContents().get(0);
|
||||
assertEquals(content.toXML().toString(), initiate.getContents().get(0).toXML().toString());
|
||||
assertEquals(content.toXML().toString(), accept.getContents().get(0).toXML().toString());
|
||||
|
||||
assertEquals("content", content.getName());
|
||||
assertEquals(JingleContentElement.Creator.initiator, content.getCreator());
|
||||
assertEquals(JingleContentElement.Senders.initiator, content.getSenders());
|
||||
|
||||
assertEquals(1, description.getJingleContentDescriptionChildren().size());
|
||||
assertEquals(file, description.getJingleContentDescriptionChildren().get(0));
|
||||
assertEquals(JingleFileTransferChildElement.ELEMENT, file.getElementName());
|
||||
assertEquals(JingleFileTransferElement.NAMESPACE_V5, description.getNamespace());
|
||||
assertEquals(date, file.getDate());
|
||||
assertEquals(hash, file.getHash());
|
||||
assertEquals("application/octet-stream", file.getMediaType());
|
||||
assertEquals("name", file.getName());
|
||||
assertEquals(1337, file.getSize());
|
||||
assertNull(file.getRange());
|
||||
|
||||
assertEquals(transport, content.getTransport());
|
||||
assertEquals("transid", transport.getSessionId());
|
||||
assertEquals(JingleIBBTransport.DEFAULT_BLOCK_SIZE, transport.getBlockSize());
|
||||
|
||||
String transportXML =
|
||||
"<transport xmlns='urn:xmpp:jingle:transports:ibb:1' " +
|
||||
"block-size='4096' " +
|
||||
"sid='transid'/>";
|
||||
assertXMLEqual(transportXML, transport.toXML().toString());
|
||||
|
||||
String descriptionXML =
|
||||
"<description xmlns='urn:xmpp:jingle:apps:file-transfer:5'>" +
|
||||
"<file>" +
|
||||
"<date>" + XmppDateTime.formatXEP0082Date(date) + "</date>" +
|
||||
"<desc>desc</desc>" +
|
||||
"<media-type>application/octet-stream</media-type>" +
|
||||
"<name>name</name>" +
|
||||
//"<range/>" + TODO: insert empty element when null?
|
||||
"<size>1337</size>" +
|
||||
"<hash xmlns='urn:xmpp:hashes:2' " +
|
||||
"algo='sha-256'>f4OxZX/x/FO5LcGBSKHWXfwtSx+j1ncoSt3SABJtkGk=</hash>" +
|
||||
"</file>" +
|
||||
"</description>";
|
||||
assertXMLEqual(descriptionXML, description.toXML().toString());
|
||||
|
||||
JingleFileTransferElement parsed = new JingleFileTransferProvider().parse(TestUtils.getParser(descriptionXML));
|
||||
assertEquals(1, parsed.getJingleContentDescriptionChildren().size());
|
||||
assertEquals(file.toXML().toString(), parsed.getJingleContentDescriptionChildren().get(0).toXML().toString());
|
||||
|
||||
String contentXML = "<content creator='initiator' name='content' senders='initiator'>" +
|
||||
descriptionXML +
|
||||
transportXML +
|
||||
"</content>";
|
||||
assertXMLEqual(contentXML, content.toXML().toString());
|
||||
|
||||
String initiateXML =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='session-initiate' " +
|
||||
"initiator='" + romeo + "' " +
|
||||
"sid='letsstart'>" +
|
||||
contentXML +
|
||||
"</jingle>";
|
||||
String xml = JingleUtilTest.getIQXML(romeo, juliet, initiate.getStanzaId(), initiateXML);
|
||||
assertXMLEqual(xml, initiate.toXML().toString());
|
||||
|
||||
String acceptXML =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='session-accept' " +
|
||||
"responder='" + romeo + "' " +
|
||||
"sid='acceptID'>" +
|
||||
contentXML +
|
||||
"</jingle>";
|
||||
xml = JingleUtilTest.getIQXML(romeo, juliet, accept.getStanzaId(), acceptXML);
|
||||
assertXMLEqual(xml, accept.toXML().toString());
|
||||
|
||||
String fileOfferXML =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='session-initiate' " +
|
||||
"initiator='" + romeo + "' " +
|
||||
"sid='fileOffer'>" +
|
||||
contentXML +
|
||||
"</jingle>";
|
||||
xml = JingleUtilTest.getIQXML(romeo, juliet, fileOffer.getStanzaId(), fileOfferXML);
|
||||
assertXMLEqual(xml, fileOffer.toXML().toString());
|
||||
}
|
||||
}
|
|
@ -1,9 +1,26 @@
|
|||
/**
|
||||
*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Created by vanitas on 27.07.17.
|
||||
*/
|
||||
public interface JingleDescriptionController {
|
||||
|
||||
enum State {
|
||||
pending, //Not yet accepted by us/peer
|
||||
negotiating, //Accepted, but still negotiating transports etc.
|
||||
|
|
|
@ -1,3 +1,19 @@
|
|||
/**
|
||||
*
|
||||
* 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;
|
||||
|
||||
import org.jivesoftware.smackx.jingle.JingleDescriptionController;
|
||||
|
|
|
@ -54,9 +54,9 @@ public class JingleContent {
|
|||
private String name;
|
||||
private String disposition;
|
||||
private JingleContentElement.Senders senders;
|
||||
private JingleDescription description;
|
||||
private JingleTransport transport;
|
||||
private JingleSecurity security;
|
||||
private JingleDescription<?> description;
|
||||
private JingleTransport<?> transport;
|
||||
private JingleSecurity<?> security;
|
||||
|
||||
private final List<Callback> callbacks = Collections.synchronizedList(new ArrayList<Callback>());
|
||||
private final Set<String> transportBlacklist = Collections.synchronizedSet(new HashSet<String>());
|
||||
|
@ -75,7 +75,7 @@ public class JingleContent {
|
|||
this(null, null, null, randomName(), null, creator, senders);
|
||||
}
|
||||
|
||||
public JingleContent(JingleDescription description, JingleTransport transport, JingleSecurity security, String name, String disposition, JingleContentElement.Creator creator, JingleContentElement.Senders senders) {
|
||||
public JingleContent(JingleDescription<?> description, JingleTransport<?> transport, JingleSecurity<?> security, String name, String disposition, JingleContentElement.Creator creator, JingleContentElement.Senders senders) {
|
||||
this.description = description;
|
||||
this.transport = transport;
|
||||
this.security = security;
|
||||
|
|
|
@ -1,3 +1,19 @@
|
|||
/**
|
||||
*
|
||||
* 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.components;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
|
@ -29,21 +29,20 @@ import java.util.logging.Logger;
|
|||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smackx.jingle.JingleDescriptionManager;
|
||||
import org.jivesoftware.smackx.jingle.JingleManager;
|
||||
import org.jivesoftware.smackx.jingle.util.Role;
|
||||
import org.jivesoftware.smackx.jingle.adapter.JingleTransportAdapter;
|
||||
import org.jivesoftware.smackx.jingle.callbacks.ContentAddCallback;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleAction;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionElement;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentElement;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentTransportElement;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentTransportInfoElement;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleElement;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleReasonElement;
|
||||
import org.jivesoftware.smackx.jingle.exception.UnsupportedDescriptionException;
|
||||
import org.jivesoftware.smackx.jingle.exception.UnsupportedSecurityException;
|
||||
import org.jivesoftware.smackx.jingle.exception.UnsupportedTransportException;
|
||||
import org.jivesoftware.smackx.jingle.JingleDescriptionManager;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleAction;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentElement;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentTransportInfoElement;
|
||||
import org.jivesoftware.smackx.jingle.util.Role;
|
||||
|
||||
import org.jxmpp.jid.FullJid;
|
||||
|
||||
|
@ -360,21 +359,6 @@ public class JingleSession {
|
|||
|
||||
for (final JingleContent content : descriptionCategory.getValue()) {
|
||||
descriptionManager.notifyContentAdd(content);
|
||||
|
||||
ContentAddCallback callback = new ContentAddCallback() {
|
||||
@Override
|
||||
public void acceptContentAdd() {
|
||||
contents.put(content.getName(), content);
|
||||
acceptedContents.add(content.getElement());
|
||||
// TODO: Send content-accept
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rejectContentAdd() {
|
||||
// TODO: Send content-reject
|
||||
}
|
||||
};
|
||||
descriptionManager
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ public abstract class JingleTransport<D extends JingleContentTransportElement> e
|
|||
private JingleContent parent;
|
||||
private final ArrayList<JingleTransportCandidate<?>> candidates = new ArrayList<>();
|
||||
|
||||
private JingleTransport peersProposal;
|
||||
private JingleTransport<?> peersProposal;
|
||||
private boolean isPeersProposal;
|
||||
|
||||
protected BytestreamSession bytestreamSession;
|
||||
|
@ -81,7 +81,7 @@ public abstract class JingleTransport<D extends JingleContentTransportElement> e
|
|||
public abstract void establishOutgoingBytestreamSession(XMPPConnection connection)
|
||||
throws SmackException.NotConnectedException, InterruptedException;
|
||||
|
||||
public void setPeersProposal(JingleTransport peersProposal) {
|
||||
public void setPeersProposal(JingleTransport<?> peersProposal) {
|
||||
this.peersProposal = peersProposal;
|
||||
peersProposal.isPeersProposal = true;
|
||||
}
|
||||
|
|
|
@ -100,7 +100,7 @@ public class JingleS5BTransport extends JingleTransport<JingleS5BTransportElemen
|
|||
.setDestinationAddress(dstAddr)
|
||||
.setMode(mode);
|
||||
|
||||
for (JingleTransportCandidate candidate : getCandidates()) {
|
||||
for (JingleTransportCandidate<?> candidate : getCandidates()) {
|
||||
builder.addTransportCandidate((JingleS5BTransportCandidateElement) candidate.getElement());
|
||||
}
|
||||
|
||||
|
@ -156,7 +156,7 @@ public class JingleS5BTransport extends JingleTransport<JingleS5BTransportElemen
|
|||
}
|
||||
|
||||
public JingleS5BTransportCandidate connectToCandidates(int timeout) {
|
||||
for (JingleTransportCandidate c : getCandidates()) {
|
||||
for (JingleTransportCandidate<?> c : getCandidates()) {
|
||||
int _timeout = timeout / getCandidates().size(); //TODO: Wise?
|
||||
try {
|
||||
return ((JingleS5BTransportCandidate) c).connect(_timeout);
|
||||
|
|
|
@ -67,6 +67,7 @@ public class JingleS5BTransportCandidate extends JingleTransportCandidate<Jingle
|
|||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JingleS5BTransportCandidateElement getElement() {
|
||||
return new JingleS5BTransportCandidateElement(
|
||||
getCandidateId(), getStreamHost().getAddress(),
|
||||
|
|
|
@ -14,6 +14,7 @@ public class S5BTransportException extends FailedTransportException {
|
|||
}
|
||||
|
||||
public static class CandidateError extends S5BTransportException {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
|
||||
public CandidateError(Throwable throwable) {
|
||||
super(throwable);
|
||||
|
@ -21,6 +22,7 @@ public class S5BTransportException extends FailedTransportException {
|
|||
}
|
||||
|
||||
public static class ProxyError extends S5BTransportException {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
|
||||
public ProxyError(Throwable throwable) {
|
||||
super(throwable);
|
||||
|
|
|
@ -18,64 +18,435 @@ package org.jivesoftware.smackx.jingle;
|
|||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static junit.framework.TestCase.assertNotNull;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jivesoftware.smack.DummyConnection;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.test.util.SmackTestSuite;
|
||||
|
||||
import org.jivesoftware.smackx.jingle.element.JingleElement;
|
||||
import org.jivesoftware.smack.test.util.TestUtils;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleAction;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentElement;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleElement;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleReasonElement;
|
||||
import org.jivesoftware.smackx.jingle.provider.JingleProvider;
|
||||
import org.jivesoftware.smackx.jingle.transport.jingle_ibb.element.JingleIBBTransportElement;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.jxmpp.jid.FullJid;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
import org.jxmpp.stringprep.XmppStringprepException;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* Test the Jingle class.
|
||||
* Test the JingleUtil class.
|
||||
*/
|
||||
public class JingleElementTest extends SmackTestSuite {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void emptyBuilderTest() {
|
||||
JingleElement.Builder builder = JingleElement.getBuilder();
|
||||
builder.build();
|
||||
}
|
||||
private FullJid romeo;
|
||||
private FullJid juliet;
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void onlySessionIdBuilderTest() {
|
||||
String sessionId = "testSessionId";
|
||||
@Before
|
||||
public void setup() throws XmppStringprepException {
|
||||
|
||||
JingleElement.Builder builder = JingleElement.getBuilder();
|
||||
builder.setSessionId(sessionId);
|
||||
builder.build();
|
||||
XMPPConnection connection = new DummyConnection(
|
||||
DummyConnection.getDummyConfigurationBuilder()
|
||||
.setUsernameAndPassword("romeo@montague.lit",
|
||||
"iluvJulibabe13").build());
|
||||
JingleManager jm = JingleManager.getInstanceFor(connection);
|
||||
romeo = connection.getUser().asFullJidOrThrow();
|
||||
juliet = JidCreate.fullFrom("juliet@capulet.lit/balcony");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parserTest() throws XmppStringprepException {
|
||||
String sessionId = "testSessionId";
|
||||
|
||||
JingleElement.Builder builder = JingleElement.getBuilder();
|
||||
builder.setSessionId(sessionId);
|
||||
builder.setAction(JingleAction.session_initiate);
|
||||
|
||||
FullJid romeo = JidCreate.fullFrom("romeo@montague.lit/orchard");
|
||||
FullJid juliet = JidCreate.fullFrom("juliet@capulet.lit/balcony");
|
||||
builder.setInitiator(romeo);
|
||||
builder.setResponder(juliet);
|
||||
|
||||
JingleElement jingle = builder.build();
|
||||
public void createSessionTerminateDeclineTest() throws Exception {
|
||||
JingleElement terminate = JingleElement.createSessionTerminate(juliet, "thisismadness", JingleReasonElement.Reason.decline);
|
||||
String jingleXML =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='session-terminate' " +
|
||||
"sid='thisismadness'>" +
|
||||
"<reason>" +
|
||||
"<decline/>" +
|
||||
"</reason>" +
|
||||
"</jingle>";
|
||||
String xml = getIQXML(romeo, juliet, terminate.getStanzaId(), jingleXML);
|
||||
assertXMLEqual(xml, terminate.toXML().toString());
|
||||
JingleElement jingle = new JingleProvider().parse(TestUtils.getParser(jingleXML));
|
||||
assertNotNull(jingle);
|
||||
assertEquals(romeo, jingle.getInitiator());
|
||||
assertEquals(juliet, jingle.getResponder());
|
||||
assertEquals(jingle.getAction(), JingleAction.session_initiate);
|
||||
assertEquals(sessionId, jingle.getSid());
|
||||
assertEquals(jingle.getAction(), JingleAction.session_terminate);
|
||||
assertEquals(jingle.getReason().asEnum(), JingleReasonElement.Reason.decline);
|
||||
}
|
||||
|
||||
String xml = "<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"initiator='romeo@montague.lit/orchard' " +
|
||||
"responder='juliet@capulet.lit/balcony' " +
|
||||
"action='session-initiate' " +
|
||||
"sid='" + sessionId + "'>" +
|
||||
"</jingle>";
|
||||
assertTrue(jingle.toXML().toString().contains(xml));
|
||||
@Test
|
||||
public void createSessionTerminateSuccessTest() throws Exception {
|
||||
JingleElement success = JingleElement.createSessionTerminate(juliet, "thisissparta", JingleReasonElement.Reason.success);
|
||||
String jingleXML =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='session-terminate' " +
|
||||
"sid='thisissparta'>" +
|
||||
"<reason>" +
|
||||
"<success/>" +
|
||||
"</reason>" +
|
||||
"</jingle>";
|
||||
String xml = getIQXML(romeo, juliet, success.getStanzaId(), jingleXML);
|
||||
assertXMLEqual(xml, success.toXML().toString());
|
||||
JingleElement jingle = new JingleProvider().parse(TestUtils.getParser(jingleXML));
|
||||
assertNotNull(jingle);
|
||||
assertEquals(jingle.getAction(), JingleAction.session_terminate);
|
||||
assertEquals(jingle.getReason().asEnum(), JingleReasonElement.Reason.success);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createSessionTerminateBusyTest() throws Exception {
|
||||
JingleElement busy = JingleElement.createSessionTerminate(juliet, "thisispatrick", JingleReasonElement.Reason.busy);
|
||||
String jingleXML =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='session-terminate' " +
|
||||
"sid='thisispatrick'>" +
|
||||
"<reason>" +
|
||||
"<busy/>" +
|
||||
"</reason>" +
|
||||
"</jingle>";
|
||||
String xml = getIQXML(romeo, juliet, busy.getStanzaId(), jingleXML);
|
||||
assertXMLEqual(xml, busy.toXML().toString());
|
||||
JingleElement jingle = new JingleProvider().parse(TestUtils.getParser(jingleXML));
|
||||
assertNotNull(jingle);
|
||||
assertEquals(jingle.getAction(), JingleAction.session_terminate);
|
||||
assertEquals(jingle.getReason().asEnum(), JingleReasonElement.Reason.busy);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createSessionTerminateAlternativeSessionTest() throws Exception {
|
||||
JingleElement busy = JingleElement.createSessionTerminate(juliet, "thisistherhythm", JingleReasonElement.AlternativeSession("ofthenight"));
|
||||
String jingleXML =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='session-terminate' " +
|
||||
"sid='thisistherhythm'>" +
|
||||
"<reason>" +
|
||||
"<alternative-session>" +
|
||||
"<sid>ofthenight</sid>" +
|
||||
"</alternative-session>" +
|
||||
"</reason>" +
|
||||
"</jingle>";
|
||||
String xml = getIQXML(romeo, juliet, busy.getStanzaId(), jingleXML);
|
||||
assertXMLEqual(xml, busy.toXML().toString());
|
||||
JingleElement jingle = new JingleProvider().parse(TestUtils.getParser(jingleXML));
|
||||
assertNotNull(jingle);
|
||||
assertEquals(jingle.getAction(), JingleAction.session_terminate);
|
||||
assertEquals(jingle.getReason().asEnum(), JingleReasonElement.Reason.alternative_session);
|
||||
JingleReasonElement.AlternativeSession alt = (JingleReasonElement.AlternativeSession) jingle.getReason();
|
||||
assertEquals("ofthenight", alt.getAlternativeSessionId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createSessionTerminateCancelTest() throws Exception {
|
||||
JingleElement cancel = JingleElement.createSessionTerminate(juliet, "thisistheend", JingleReasonElement.Reason.cancel);
|
||||
String jingleXML =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='session-terminate' " +
|
||||
"sid='thisistheend'>" +
|
||||
"<reason>" +
|
||||
"<cancel/>" +
|
||||
"</reason>" +
|
||||
"</jingle>";
|
||||
String xml = getIQXML(romeo, juliet, cancel.getStanzaId(), jingleXML);
|
||||
assertXMLEqual(xml, cancel.toXML().toString());
|
||||
JingleElement jingle = new JingleProvider().parse(TestUtils.getParser(jingleXML));
|
||||
assertNotNull(jingle);
|
||||
assertEquals(jingle.getAction(), JingleAction.session_terminate);
|
||||
assertEquals(jingle.getReason().asEnum(), JingleReasonElement.Reason.cancel);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createSessionTerminateUnsupportedTransportsTest() throws Exception {
|
||||
JingleElement unsupportedTransports = JingleElement.createSessionTerminate(juliet, "thisisus", JingleReasonElement.Reason.unsupported_transports);
|
||||
String jingleXML =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='session-terminate' " +
|
||||
"sid='thisisus'>" +
|
||||
"<reason>" +
|
||||
"<unsupported-transports/>" +
|
||||
"</reason>" +
|
||||
"</jingle>";
|
||||
String xml = getIQXML(romeo, juliet, unsupportedTransports.getStanzaId(), jingleXML);
|
||||
assertXMLEqual(xml, unsupportedTransports.toXML().toString());
|
||||
JingleElement jingle = new JingleProvider().parse(TestUtils.getParser(jingleXML));
|
||||
assertNotNull(jingle);
|
||||
assertEquals(jingle.getAction(), JingleAction.session_terminate);
|
||||
assertEquals(jingle.getReason().asEnum(), JingleReasonElement.Reason.unsupported_transports);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createSessionTerminateUnsupportedApplicationsTest() throws Exception {
|
||||
JingleElement unsupportedApplications = JingleElement.createSessionTerminate(juliet, "thisiswar", JingleReasonElement.Reason.unsupported_applications);
|
||||
String jingleXML =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='session-terminate' " +
|
||||
"sid='thisiswar'>" +
|
||||
"<reason>" +
|
||||
"<unsupported-applications/>" +
|
||||
"</reason>" +
|
||||
"</jingle>";
|
||||
String xml = getIQXML(romeo, juliet, unsupportedApplications.getStanzaId(), jingleXML);
|
||||
assertXMLEqual(xml, unsupportedApplications.toXML().toString());
|
||||
JingleElement jingle = new JingleProvider().parse(TestUtils.getParser(jingleXML));
|
||||
assertNotNull(jingle);
|
||||
assertEquals(jingle.getAction(), JingleAction.session_terminate);
|
||||
assertEquals(jingle.getReason().asEnum(), JingleReasonElement.Reason.unsupported_applications);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createSessionTerminateFailedTransportTest() throws IOException, SAXException {
|
||||
JingleElement failedTransport = JingleElement.createSessionTerminate(juliet, "derailed", JingleReasonElement.Reason.failed_transport);
|
||||
String jingleXML =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='session-terminate' " +
|
||||
"sid='derailed'>" +
|
||||
"<reason>" +
|
||||
"<failed-transport/>" +
|
||||
"</reason>" +
|
||||
"</jingle>";
|
||||
String xml = getIQXML(romeo, juliet, failedTransport.getStanzaId(), jingleXML);
|
||||
assertXMLEqual(xml, failedTransport.toXML().toString());
|
||||
assertEquals(JingleAction.session_terminate, failedTransport.getAction());
|
||||
assertEquals(JingleReasonElement.Reason.failed_transport, failedTransport.getReason().asEnum());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createSessionTerminateFailedApplicationTest() throws IOException, SAXException {
|
||||
JingleElement failedApplication = JingleElement.createSessionTerminate(juliet, "crashed", JingleReasonElement.Reason.failed_application);
|
||||
String jingleXML =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='session-terminate' " +
|
||||
"sid='crashed'>" +
|
||||
"<reason>" +
|
||||
"<failed-application/>" +
|
||||
"</reason>" +
|
||||
"</jingle>";
|
||||
String xml = getIQXML(romeo, juliet, failedApplication.getStanzaId(), jingleXML);
|
||||
assertXMLEqual(xml, failedApplication.toXML().toString());
|
||||
assertEquals(JingleAction.session_terminate, failedApplication.getAction());
|
||||
assertEquals(JingleReasonElement.Reason.failed_application, failedApplication.getReason().asEnum());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createSessionPingTest() throws Exception {
|
||||
JingleElement ping = JingleElement.createSessionPing(juliet, "thisisit");
|
||||
String jingleXML =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='session-info' " +
|
||||
"sid='thisisit'/>";
|
||||
String xml = getIQXML(romeo, juliet, ping.getStanzaId(), jingleXML);
|
||||
assertXMLEqual(xml, ping.toXML().toString());
|
||||
JingleElement jingle = new JingleProvider().parse(TestUtils.getParser(jingleXML));
|
||||
assertNotNull(jingle);
|
||||
assertEquals(JingleAction.session_info, jingle.getAction());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createSessionTerminateContentCancelTest() throws Exception {
|
||||
JingleElement cancel = JingleElement.createSessionTerminateContentCancel(juliet, "thisismumbo#5", JingleContentElement.Creator.initiator, "content123");
|
||||
String jingleXML =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='session-terminate' " +
|
||||
"sid='thisismumbo#5'>" +
|
||||
"<content creator='initiator' name='content123'/>" +
|
||||
"<reason>" +
|
||||
"<cancel/>" +
|
||||
"</reason>" +
|
||||
"</jingle>";
|
||||
String xml = getIQXML(romeo, juliet, cancel.getStanzaId(), jingleXML);
|
||||
assertXMLEqual(xml, cancel.toXML().toString());
|
||||
JingleElement jingle = new JingleProvider().parse(TestUtils.getParser(jingleXML));
|
||||
assertNotNull(jingle);
|
||||
assertEquals(JingleAction.session_terminate, jingle.getAction());
|
||||
assertEquals(JingleReasonElement.Reason.cancel, jingle.getReason().asEnum());
|
||||
assertEquals("thisismumbo#5", jingle.getSid());
|
||||
JingleContentElement content = jingle.getContents().get(0);
|
||||
assertNotNull(content);
|
||||
assertEquals("content123", content.getName());
|
||||
assertEquals(JingleContentElement.Creator.initiator, content.getCreator());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createSessionTerminateIncompatibleParameters() throws IOException, SAXException {
|
||||
JingleElement terminate = JingleElement.createSessionTerminate(juliet, "incompatibleSID", JingleReasonElement.Reason.incompatible_parameters);
|
||||
String jingleXML =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='session-terminate' " +
|
||||
"sid='incompatibleSID'>" +
|
||||
"<reason>" +
|
||||
"<incompatible-parameters/>" +
|
||||
"</reason>" +
|
||||
"</jingle>";
|
||||
String xml = getIQXML(romeo, juliet, terminate.getStanzaId(), jingleXML);
|
||||
assertXMLEqual(xml, terminate.toXML().toString());
|
||||
assertEquals(JingleReasonElement.Reason.incompatible_parameters, terminate.getReason().asEnum());
|
||||
assertEquals("incompatibleSID", terminate.getSid());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createTransportAcceptTest() throws IOException, SAXException {
|
||||
JingleElement transportAccept = JingleElement.createTransportAccept(juliet, romeo, "transAcc", JingleContentElement.Creator.initiator, "cname", new JingleIBBTransportElement("transid", JingleIBBTransportElement.DEFAULT_BLOCK_SIZE));
|
||||
String jingleXML =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='transport-accept' " +
|
||||
"initiator='" + romeo + "' " +
|
||||
"sid='transAcc'>" +
|
||||
"<content creator='initiator' name='cname'>" +
|
||||
"<transport xmlns='urn:xmpp:jingle:transports:ibb:1' " +
|
||||
"block-size='" + JingleIBBTransportElement.DEFAULT_BLOCK_SIZE + "' " +
|
||||
"sid='transid'/>" +
|
||||
"</content>" +
|
||||
"</jingle>";
|
||||
String xml = getIQXML(romeo, juliet, transportAccept.getStanzaId(), jingleXML);
|
||||
assertXMLEqual(xml, transportAccept.toXML().toString());
|
||||
assertEquals(JingleAction.transport_accept, transportAccept.getAction());
|
||||
assertEquals("transAcc", transportAccept.getSid());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createTransportRejectTest() {
|
||||
//TODO: Find example
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createTransportReplaceTest() throws IOException, SAXException {
|
||||
JingleElement transportReplace = JingleElement.createTransportReplace(juliet, romeo, "transAcc", JingleContentElement.Creator.initiator, "cname", new JingleIBBTransportElement("transid", JingleIBBTransportElement.DEFAULT_BLOCK_SIZE));
|
||||
String jingleXML =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='transport-replace' " +
|
||||
"initiator='" + romeo + "' " +
|
||||
"sid='transAcc'>" +
|
||||
"<content creator='initiator' name='cname'>" +
|
||||
"<transport xmlns='urn:xmpp:jingle:transports:ibb:1' " +
|
||||
"block-size='" + JingleIBBTransportElement.DEFAULT_BLOCK_SIZE + "' " +
|
||||
"sid='transid'/>" +
|
||||
"</content>" +
|
||||
"</jingle>";
|
||||
String xml = getIQXML(romeo, juliet, transportReplace.getStanzaId(), jingleXML);
|
||||
assertXMLEqual(xml, transportReplace.toXML().toString());
|
||||
assertEquals(JingleAction.transport_replace, transportReplace.getAction());
|
||||
assertEquals("transAcc", transportReplace.getSid());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createErrorMalformedRequestTest() throws Exception {
|
||||
JingleElement j = defaultJingle(romeo, "error123");
|
||||
IQ error = JingleElement.createJingleErrorMalformedRequest(j);
|
||||
String xml =
|
||||
"<iq " +
|
||||
"to='" + romeo + "' " +
|
||||
"from='" + romeo + "' " +
|
||||
"id='" + j.getStanzaId() + "' " +
|
||||
"type='error'>" +
|
||||
"<error type='cancel'>" +
|
||||
"<bad-request xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" +
|
||||
"</error>" +
|
||||
"</iq>";
|
||||
assertXMLEqual(xml, error.toXML().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createErrorTieBreakTest() throws IOException, SAXException {
|
||||
JingleElement j = defaultJingle(romeo, "thisistie");
|
||||
IQ error = JingleElement.createJingleErrorTieBreak(j);
|
||||
String xml =
|
||||
"<iq " +
|
||||
"to='" + romeo + "' " +
|
||||
"from='" + romeo + "' " +
|
||||
"id='" + j.getStanzaId() + "' " +
|
||||
"type='error'>" +
|
||||
"<error type='cancel'>" +
|
||||
"<conflict xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" +
|
||||
"<tie-break xmlns='urn:xmpp:jingle:errors:1'/>" +
|
||||
"</error>" +
|
||||
"</iq>";
|
||||
assertXMLEqual(xml, error.toXML().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createErrorUnknownSessionTest() throws IOException, SAXException {
|
||||
JingleElement j = defaultJingle(romeo, "youknownothingjohnsnow");
|
||||
IQ error = JingleElement.createJingleErrorUnknownSession(j);
|
||||
String xml =
|
||||
"<iq " +
|
||||
"to='" + romeo + "' " +
|
||||
"from='" + romeo + "' " +
|
||||
"id='" + j.getStanzaId() + "' " +
|
||||
"type='error'>" +
|
||||
"<error type='cancel'>" +
|
||||
"<item-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" +
|
||||
"<unknown-session xmlns='urn:xmpp:jingle:errors:1'/>" +
|
||||
"</error>" +
|
||||
"</iq>";
|
||||
assertXMLEqual(xml, error.toXML().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createErrorUnknownInitiatorTest() throws IOException, SAXException {
|
||||
JingleElement j = defaultJingle(romeo, "iamyourfather");
|
||||
IQ error = JingleElement.createJingleErrorUnknownInitiator(j);
|
||||
String xml =
|
||||
"<iq " +
|
||||
"to='" + romeo + "' " +
|
||||
"from='" + romeo + "' " +
|
||||
"id='" + j.getStanzaId() + "' " +
|
||||
"type='error'>" +
|
||||
"<error type='cancel'>" +
|
||||
"<service-unavailable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" +
|
||||
"</error>" +
|
||||
"</iq>";
|
||||
assertXMLEqual(xml, error.toXML().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createErrorOutOfOrderTest() throws IOException, SAXException {
|
||||
JingleElement j = defaultJingle(romeo, "yourfatheriam");
|
||||
IQ error = JingleElement.createJingleErrorOutOfOrder(j);
|
||||
String xml =
|
||||
"<iq " +
|
||||
"to='" + romeo + "' " +
|
||||
"from='" + romeo + "' " +
|
||||
"id='" + j.getStanzaId() + "' " +
|
||||
"type='error'>" +
|
||||
//"<error type='cancel'>" +
|
||||
"<error type='modify'>" + //TODO: Why?
|
||||
"<unexpected-request xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" +
|
||||
"<out-of-order xmlns='urn:xmpp:jingle:errors:1'/>" +
|
||||
"</error>" +
|
||||
"</iq>";
|
||||
assertXMLEqual(xml, error.toXML().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createErrorUnsupportedInfoTest() throws IOException, SAXException {
|
||||
JingleElement j = defaultJingle(romeo, "thisstatementiswrong");
|
||||
IQ error = JingleElement.createJingleErrorUnsupportedInfo(j);
|
||||
String xml =
|
||||
"<iq " +
|
||||
"to='" + romeo + "' " +
|
||||
"from='" + romeo + "' " +
|
||||
"id='" + j.getStanzaId() + "' " +
|
||||
"type='error'>" +
|
||||
"<error type='modify'>" +
|
||||
"<feature-not-implemented xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" +
|
||||
"<unsupported-info xmlns='urn:xmpp:jingle:errors:1'/>" +
|
||||
"</error>" +
|
||||
"</iq>";
|
||||
assertXMLEqual(xml, error.toXML().toString());
|
||||
}
|
||||
|
||||
public static String getIQXML(FullJid from, FullJid to, String stanzaId, String jingleXML) {
|
||||
return "<iq from='" + from + "' id='" + stanzaId + "' to='" + to + "' type='set'>" +
|
||||
jingleXML +
|
||||
"</iq>";
|
||||
}
|
||||
|
||||
private JingleElement defaultJingle(FullJid recipient, String sessionId) {
|
||||
return JingleElement.createSessionPing(recipient, sessionId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,452 +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;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static junit.framework.TestCase.assertNotNull;
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jivesoftware.smack.DummyConnection;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.test.util.SmackTestSuite;
|
||||
import org.jivesoftware.smack.test.util.TestUtils;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleAction;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentElement;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleElement;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleReasonElement;
|
||||
import org.jivesoftware.smackx.jingle.provider.JingleProvider;
|
||||
import org.jivesoftware.smackx.jingle.transport.jingle_ibb.element.JingleIBBTransportElement;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.jxmpp.jid.FullJid;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
import org.jxmpp.stringprep.XmppStringprepException;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* Test the JingleUtil class.
|
||||
*/
|
||||
public class JingleUtilTest extends SmackTestSuite {
|
||||
|
||||
private FullJid romeo;
|
||||
private FullJid juliet;
|
||||
|
||||
@Before
|
||||
public void setup() throws XmppStringprepException {
|
||||
|
||||
XMPPConnection connection = new DummyConnection(
|
||||
DummyConnection.getDummyConfigurationBuilder()
|
||||
.setUsernameAndPassword("romeo@montague.lit",
|
||||
"iluvJulibabe13").build());
|
||||
JingleManager jm = JingleManager.getInstanceFor(connection);
|
||||
romeo = connection.getUser().asFullJidOrThrow();
|
||||
juliet = JidCreate.fullFrom("juliet@capulet.lit/balcony");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createSessionTerminateDeclineTest() throws Exception {
|
||||
JingleElement terminate = JingleElement.createSessionTerminate(juliet, "thisismadness", JingleReasonElement.Reason.decline);
|
||||
String jingleXML =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='session-terminate' " +
|
||||
"sid='thisismadness'>" +
|
||||
"<reason>" +
|
||||
"<decline/>" +
|
||||
"</reason>" +
|
||||
"</jingle>";
|
||||
String xml = getIQXML(romeo, juliet, terminate.getStanzaId(), jingleXML);
|
||||
assertXMLEqual(xml, terminate.toXML().toString());
|
||||
JingleElement jingle = new JingleProvider().parse(TestUtils.getParser(jingleXML));
|
||||
assertNotNull(jingle);
|
||||
assertEquals(jingle.getAction(), JingleAction.session_terminate);
|
||||
assertEquals(jingle.getReason().asEnum(), JingleReasonElement.Reason.decline);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createSessionTerminateSuccessTest() throws Exception {
|
||||
JingleElement success = JingleElement.createSessionTerminate(juliet, "thisissparta", JingleReasonElement.Reason.success);
|
||||
String jingleXML =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='session-terminate' " +
|
||||
"sid='thisissparta'>" +
|
||||
"<reason>" +
|
||||
"<success/>" +
|
||||
"</reason>" +
|
||||
"</jingle>";
|
||||
String xml = getIQXML(romeo, juliet, success.getStanzaId(), jingleXML);
|
||||
assertXMLEqual(xml, success.toXML().toString());
|
||||
JingleElement jingle = new JingleProvider().parse(TestUtils.getParser(jingleXML));
|
||||
assertNotNull(jingle);
|
||||
assertEquals(jingle.getAction(), JingleAction.session_terminate);
|
||||
assertEquals(jingle.getReason().asEnum(), JingleReasonElement.Reason.success);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createSessionTerminateBusyTest() throws Exception {
|
||||
JingleElement busy = JingleElement.createSessionTerminate(juliet, "thisispatrick", JingleReasonElement.Reason.busy);
|
||||
String jingleXML =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='session-terminate' " +
|
||||
"sid='thisispatrick'>" +
|
||||
"<reason>" +
|
||||
"<busy/>" +
|
||||
"</reason>" +
|
||||
"</jingle>";
|
||||
String xml = getIQXML(romeo, juliet, busy.getStanzaId(), jingleXML);
|
||||
assertXMLEqual(xml, busy.toXML().toString());
|
||||
JingleElement jingle = new JingleProvider().parse(TestUtils.getParser(jingleXML));
|
||||
assertNotNull(jingle);
|
||||
assertEquals(jingle.getAction(), JingleAction.session_terminate);
|
||||
assertEquals(jingle.getReason().asEnum(), JingleReasonElement.Reason.busy);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createSessionTerminateAlternativeSessionTest() throws Exception {
|
||||
JingleElement busy = JingleElement.createSessionTerminate(juliet, "thisistherhythm", JingleReasonElement.AlternativeSession("ofthenight"));
|
||||
String jingleXML =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='session-terminate' " +
|
||||
"sid='thisistherhythm'>" +
|
||||
"<reason>" +
|
||||
"<alternative-session>" +
|
||||
"<sid>ofthenight</sid>" +
|
||||
"</alternative-session>" +
|
||||
"</reason>" +
|
||||
"</jingle>";
|
||||
String xml = getIQXML(romeo, juliet, busy.getStanzaId(), jingleXML);
|
||||
assertXMLEqual(xml, busy.toXML().toString());
|
||||
JingleElement jingle = new JingleProvider().parse(TestUtils.getParser(jingleXML));
|
||||
assertNotNull(jingle);
|
||||
assertEquals(jingle.getAction(), JingleAction.session_terminate);
|
||||
assertEquals(jingle.getReason().asEnum(), JingleReasonElement.Reason.alternative_session);
|
||||
JingleReasonElement.AlternativeSession alt = (JingleReasonElement.AlternativeSession) jingle.getReason();
|
||||
assertEquals("ofthenight", alt.getAlternativeSessionId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createSessionTerminateCancelTest() throws Exception {
|
||||
JingleElement cancel = JingleElement.createSessionTerminate(juliet, "thisistheend", JingleReasonElement.Reason.cancel);
|
||||
String jingleXML =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='session-terminate' " +
|
||||
"sid='thisistheend'>" +
|
||||
"<reason>" +
|
||||
"<cancel/>" +
|
||||
"</reason>" +
|
||||
"</jingle>";
|
||||
String xml = getIQXML(romeo, juliet, cancel.getStanzaId(), jingleXML);
|
||||
assertXMLEqual(xml, cancel.toXML().toString());
|
||||
JingleElement jingle = new JingleProvider().parse(TestUtils.getParser(jingleXML));
|
||||
assertNotNull(jingle);
|
||||
assertEquals(jingle.getAction(), JingleAction.session_terminate);
|
||||
assertEquals(jingle.getReason().asEnum(), JingleReasonElement.Reason.cancel);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createSessionTerminateUnsupportedTransportsTest() throws Exception {
|
||||
JingleElement unsupportedTransports = JingleElement.createSessionTerminate(juliet, "thisisus", JingleReasonElement.Reason.unsupported_transports);
|
||||
String jingleXML =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='session-terminate' " +
|
||||
"sid='thisisus'>" +
|
||||
"<reason>" +
|
||||
"<unsupported-transports/>" +
|
||||
"</reason>" +
|
||||
"</jingle>";
|
||||
String xml = getIQXML(romeo, juliet, unsupportedTransports.getStanzaId(), jingleXML);
|
||||
assertXMLEqual(xml, unsupportedTransports.toXML().toString());
|
||||
JingleElement jingle = new JingleProvider().parse(TestUtils.getParser(jingleXML));
|
||||
assertNotNull(jingle);
|
||||
assertEquals(jingle.getAction(), JingleAction.session_terminate);
|
||||
assertEquals(jingle.getReason().asEnum(), JingleReasonElement.Reason.unsupported_transports);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createSessionTerminateUnsupportedApplicationsTest() throws Exception {
|
||||
JingleElement unsupportedApplications = JingleElement.createSessionTerminate(juliet, "thisiswar", JingleReasonElement.Reason.unsupported_applications);
|
||||
String jingleXML =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='session-terminate' " +
|
||||
"sid='thisiswar'>" +
|
||||
"<reason>" +
|
||||
"<unsupported-applications/>" +
|
||||
"</reason>" +
|
||||
"</jingle>";
|
||||
String xml = getIQXML(romeo, juliet, unsupportedApplications.getStanzaId(), jingleXML);
|
||||
assertXMLEqual(xml, unsupportedApplications.toXML().toString());
|
||||
JingleElement jingle = new JingleProvider().parse(TestUtils.getParser(jingleXML));
|
||||
assertNotNull(jingle);
|
||||
assertEquals(jingle.getAction(), JingleAction.session_terminate);
|
||||
assertEquals(jingle.getReason().asEnum(), JingleReasonElement.Reason.unsupported_applications);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createSessionTerminateFailedTransportTest() throws IOException, SAXException {
|
||||
JingleElement failedTransport = JingleElement.createSessionTerminate(juliet, "derailed", JingleReasonElement.Reason.failed_transport);
|
||||
String jingleXML =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='session-terminate' " +
|
||||
"sid='derailed'>" +
|
||||
"<reason>" +
|
||||
"<failed-transport/>" +
|
||||
"</reason>" +
|
||||
"</jingle>";
|
||||
String xml = getIQXML(romeo, juliet, failedTransport.getStanzaId(), jingleXML);
|
||||
assertXMLEqual(xml, failedTransport.toXML().toString());
|
||||
assertEquals(JingleAction.session_terminate, failedTransport.getAction());
|
||||
assertEquals(JingleReasonElement.Reason.failed_transport, failedTransport.getReason().asEnum());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createSessionTerminateFailedApplicationTest() throws IOException, SAXException {
|
||||
JingleElement failedApplication = JingleElement.createSessionTerminate(juliet, "crashed", JingleReasonElement.Reason.failed_application);
|
||||
String jingleXML =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='session-terminate' " +
|
||||
"sid='crashed'>" +
|
||||
"<reason>" +
|
||||
"<failed-application/>" +
|
||||
"</reason>" +
|
||||
"</jingle>";
|
||||
String xml = getIQXML(romeo, juliet, failedApplication.getStanzaId(), jingleXML);
|
||||
assertXMLEqual(xml, failedApplication.toXML().toString());
|
||||
assertEquals(JingleAction.session_terminate, failedApplication.getAction());
|
||||
assertEquals(JingleReasonElement.Reason.failed_application, failedApplication.getReason().asEnum());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createSessionPingTest() throws Exception {
|
||||
JingleElement ping = JingleElement.createSessionPing(juliet, "thisisit");
|
||||
String jingleXML =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='session-info' " +
|
||||
"sid='thisisit'/>";
|
||||
String xml = getIQXML(romeo, juliet, ping.getStanzaId(), jingleXML);
|
||||
assertXMLEqual(xml, ping.toXML().toString());
|
||||
JingleElement jingle = new JingleProvider().parse(TestUtils.getParser(jingleXML));
|
||||
assertNotNull(jingle);
|
||||
assertEquals(JingleAction.session_info, jingle.getAction());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createSessionTerminateContentCancelTest() throws Exception {
|
||||
JingleElement cancel = JingleElement.createSessionTerminateContentCancel(juliet, "thisismumbo#5", JingleContentElement.Creator.initiator, "content123");
|
||||
String jingleXML =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='session-terminate' " +
|
||||
"sid='thisismumbo#5'>" +
|
||||
"<content creator='initiator' name='content123'/>" +
|
||||
"<reason>" +
|
||||
"<cancel/>" +
|
||||
"</reason>" +
|
||||
"</jingle>";
|
||||
String xml = getIQXML(romeo, juliet, cancel.getStanzaId(), jingleXML);
|
||||
assertXMLEqual(xml, cancel.toXML().toString());
|
||||
JingleElement jingle = new JingleProvider().parse(TestUtils.getParser(jingleXML));
|
||||
assertNotNull(jingle);
|
||||
assertEquals(JingleAction.session_terminate, jingle.getAction());
|
||||
assertEquals(JingleReasonElement.Reason.cancel, jingle.getReason().asEnum());
|
||||
assertEquals("thisismumbo#5", jingle.getSid());
|
||||
JingleContentElement content = jingle.getContents().get(0);
|
||||
assertNotNull(content);
|
||||
assertEquals("content123", content.getName());
|
||||
assertEquals(JingleContentElement.Creator.initiator, content.getCreator());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createSessionTerminateIncompatibleParameters() throws IOException, SAXException {
|
||||
JingleElement terminate = JingleElement.createSessionTerminate(juliet, "incompatibleSID", JingleReasonElement.Reason.incompatible_parameters);
|
||||
String jingleXML =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='session-terminate' " +
|
||||
"sid='incompatibleSID'>" +
|
||||
"<reason>" +
|
||||
"<incompatible-parameters/>" +
|
||||
"</reason>" +
|
||||
"</jingle>";
|
||||
String xml = getIQXML(romeo, juliet, terminate.getStanzaId(), jingleXML);
|
||||
assertXMLEqual(xml, terminate.toXML().toString());
|
||||
assertEquals(JingleReasonElement.Reason.incompatible_parameters, terminate.getReason().asEnum());
|
||||
assertEquals("incompatibleSID", terminate.getSid());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createTransportAcceptTest() throws IOException, SAXException {
|
||||
JingleElement transportAccept = JingleElement.createTransportAccept(juliet, romeo, "transAcc", JingleContentElement.Creator.initiator, "cname", new JingleIBBTransportElement("transid", JingleIBBTransportElement.DEFAULT_BLOCK_SIZE));
|
||||
String jingleXML =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='transport-accept' " +
|
||||
"initiator='" + romeo + "' " +
|
||||
"sid='transAcc'>" +
|
||||
"<content creator='initiator' name='cname'>" +
|
||||
"<transport xmlns='urn:xmpp:jingle:transports:ibb:1' " +
|
||||
"block-size='" + JingleIBBTransportElement.DEFAULT_BLOCK_SIZE + "' " +
|
||||
"sid='transid'/>" +
|
||||
"</content>" +
|
||||
"</jingle>";
|
||||
String xml = getIQXML(romeo, juliet, transportAccept.getStanzaId(), jingleXML);
|
||||
assertXMLEqual(xml, transportAccept.toXML().toString());
|
||||
assertEquals(JingleAction.transport_accept, transportAccept.getAction());
|
||||
assertEquals("transAcc", transportAccept.getSid());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createTransportRejectTest() {
|
||||
//TODO: Find example
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createTransportReplaceTest() throws IOException, SAXException {
|
||||
JingleElement transportReplace = JingleElement.createTransportReplace(juliet, romeo, "transAcc", JingleContentElement.Creator.initiator, "cname", new JingleIBBTransportElement("transid", JingleIBBTransportElement.DEFAULT_BLOCK_SIZE));
|
||||
String jingleXML =
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
"action='transport-replace' " +
|
||||
"initiator='" + romeo + "' " +
|
||||
"sid='transAcc'>" +
|
||||
"<content creator='initiator' name='cname'>" +
|
||||
"<transport xmlns='urn:xmpp:jingle:transports:ibb:1' " +
|
||||
"block-size='" + JingleIBBTransportElement.DEFAULT_BLOCK_SIZE + "' " +
|
||||
"sid='transid'/>" +
|
||||
"</content>" +
|
||||
"</jingle>";
|
||||
String xml = getIQXML(romeo, juliet, transportReplace.getStanzaId(), jingleXML);
|
||||
assertXMLEqual(xml, transportReplace.toXML().toString());
|
||||
assertEquals(JingleAction.transport_replace, transportReplace.getAction());
|
||||
assertEquals("transAcc", transportReplace.getSid());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createErrorMalformedRequestTest() throws Exception {
|
||||
JingleElement j = defaultJingle(romeo, "error123");
|
||||
IQ error = JingleElement.createJingleErrorMalformedRequest(j);
|
||||
String xml =
|
||||
"<iq " +
|
||||
"to='" + romeo + "' " +
|
||||
"from='" + romeo + "' " +
|
||||
"id='" + j.getStanzaId() + "' " +
|
||||
"type='error'>" +
|
||||
"<error type='cancel'>" +
|
||||
"<bad-request xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" +
|
||||
"</error>" +
|
||||
"</iq>";
|
||||
assertXMLEqual(xml, error.toXML().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createErrorTieBreakTest() throws IOException, SAXException {
|
||||
JingleElement j = defaultJingle(romeo, "thisistie");
|
||||
IQ error = JingleElement.createJingleErrorTieBreak(j);
|
||||
String xml =
|
||||
"<iq " +
|
||||
"to='" + romeo + "' " +
|
||||
"from='" + romeo + "' " +
|
||||
"id='" + j.getStanzaId() + "' " +
|
||||
"type='error'>" +
|
||||
"<error type='cancel'>" +
|
||||
"<conflict xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" +
|
||||
"<tie-break xmlns='urn:xmpp:jingle:errors:1'/>" +
|
||||
"</error>" +
|
||||
"</iq>";
|
||||
assertXMLEqual(xml, error.toXML().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createErrorUnknownSessionTest() throws IOException, SAXException {
|
||||
JingleElement j = defaultJingle(romeo, "youknownothingjohnsnow");
|
||||
IQ error = JingleElement.createJingleErrorUnknownSession(j);
|
||||
String xml =
|
||||
"<iq " +
|
||||
"to='" + romeo + "' " +
|
||||
"from='" + romeo + "' " +
|
||||
"id='" + j.getStanzaId() + "' " +
|
||||
"type='error'>" +
|
||||
"<error type='cancel'>" +
|
||||
"<item-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" +
|
||||
"<unknown-session xmlns='urn:xmpp:jingle:errors:1'/>" +
|
||||
"</error>" +
|
||||
"</iq>";
|
||||
assertXMLEqual(xml, error.toXML().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createErrorUnknownInitiatorTest() throws IOException, SAXException {
|
||||
JingleElement j = defaultJingle(romeo, "iamyourfather");
|
||||
IQ error = JingleElement.createJingleErrorUnknownInitiator(j);
|
||||
String xml =
|
||||
"<iq " +
|
||||
"to='" + romeo + "' " +
|
||||
"from='" + romeo + "' " +
|
||||
"id='" + j.getStanzaId() + "' " +
|
||||
"type='error'>" +
|
||||
"<error type='cancel'>" +
|
||||
"<service-unavailable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" +
|
||||
"</error>" +
|
||||
"</iq>";
|
||||
assertXMLEqual(xml, error.toXML().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createErrorOutOfOrderTest() throws IOException, SAXException {
|
||||
JingleElement j = defaultJingle(romeo, "yourfatheriam");
|
||||
IQ error = JingleElement.createJingleErrorOutOfOrder(j);
|
||||
String xml =
|
||||
"<iq " +
|
||||
"to='" + romeo + "' " +
|
||||
"from='" + romeo + "' " +
|
||||
"id='" + j.getStanzaId() + "' " +
|
||||
"type='error'>" +
|
||||
//"<error type='cancel'>" +
|
||||
"<error type='modify'>" + //TODO: Why?
|
||||
"<unexpected-request xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" +
|
||||
"<out-of-order xmlns='urn:xmpp:jingle:errors:1'/>" +
|
||||
"</error>" +
|
||||
"</iq>";
|
||||
assertXMLEqual(xml, error.toXML().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createErrorUnsupportedInfoTest() throws IOException, SAXException {
|
||||
JingleElement j = defaultJingle(romeo, "thisstatementiswrong");
|
||||
IQ error = JingleElement.createJingleErrorUnsupportedInfo(j);
|
||||
String xml =
|
||||
"<iq " +
|
||||
"to='" + romeo + "' " +
|
||||
"from='" + romeo + "' " +
|
||||
"id='" + j.getStanzaId() + "' " +
|
||||
"type='error'>" +
|
||||
"<error type='modify'>" +
|
||||
"<feature-not-implemented xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" +
|
||||
"<unsupported-info xmlns='urn:xmpp:jingle:errors:1'/>" +
|
||||
"</error>" +
|
||||
"</iq>";
|
||||
assertXMLEqual(xml, error.toXML().toString());
|
||||
}
|
||||
|
||||
public static String getIQXML(FullJid from, FullJid to, String stanzaId, String jingleXML) {
|
||||
return "<iq from='" + from + "' id='" + stanzaId + "' to='" + to + "' type='set'>" +
|
||||
jingleXML +
|
||||
"</iq>";
|
||||
}
|
||||
|
||||
private JingleElement defaultJingle(FullJid recipient, String sessionId) {
|
||||
return JingleElement.createSessionPing(recipient, sessionId);
|
||||
}
|
||||
}
|
|
@ -17,16 +17,13 @@
|
|||
package org.jivesoftware.smackx.jingle.transport.jingle_ibb;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static junit.framework.TestCase.assertFalse;
|
||||
import static junit.framework.TestCase.assertNotSame;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
|
||||
import org.jivesoftware.smack.test.util.SmackTestSuite;
|
||||
import org.jivesoftware.smack.test.util.TestUtils;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
|
||||
import org.jivesoftware.smackx.jingle.transports.jingle_ibb.element.JingleIBBTransport;
|
||||
import org.jivesoftware.smackx.jingle.transports.jingle_ibb.provider.JingleIBBTransportProvider;
|
||||
import org.jivesoftware.smackx.jingle.transport.jingle_ibb.element.JingleIBBTransportElement;
|
||||
import org.jivesoftware.smackx.jingle.transport.jingle_ibb.provider.JingleIBBTransportProvider;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -42,17 +39,17 @@ public class JingleIBBTransportTest extends SmackTestSuite {
|
|||
|
||||
String xml = "<transport xmlns='urn:xmpp:jingle:transports:ibb:1' block-size='8192' sid='" + sid + "'/>";
|
||||
|
||||
JingleIBBTransport transport = new JingleIBBTransport(size, sid);
|
||||
assertEquals(xml, transport.toXML().toString());
|
||||
assertEquals(size, transport.getBlockSize());
|
||||
assertEquals(sid, transport.getSessionId());
|
||||
JingleIBBTransport transport = new JingleIBBTransport(sid, size);
|
||||
assertEquals(xml, transport.getElement().toXML().toString());
|
||||
assertEquals(size, (short) transport.getBlockSize());
|
||||
assertEquals(sid, transport.getSid());
|
||||
|
||||
JingleIBBTransport parsed = new JingleIBBTransportProvider()
|
||||
JingleIBBTransportElement parsed = new JingleIBBTransportProvider()
|
||||
.parse(TestUtils.getParser(xml));
|
||||
assertEquals(transport, parsed);
|
||||
assertTrue(transport.equals(parsed));
|
||||
assertEquals(transport.getElement(), parsed);
|
||||
assertTrue(transport.getElement().equals(parsed));
|
||||
assertEquals(xml, parsed.toXML().toString());
|
||||
|
||||
/*
|
||||
JingleIBBTransport transport1 = new JingleIBBTransport((short) 1024);
|
||||
assertEquals((short) 1024, transport1.getBlockSize());
|
||||
assertNotSame(transport, transport1);
|
||||
|
@ -72,5 +69,6 @@ public class JingleIBBTransportTest extends SmackTestSuite {
|
|||
|
||||
JingleIBBTransport transport4 = new JingleIBBTransport("session-id");
|
||||
assertEquals(JingleIBBTransport.DEFAULT_BLOCK_SIZE, transport4.getBlockSize());
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ public class JingleS5BTransportTest extends SmackTestSuite {
|
|||
"</transport>";
|
||||
JingleS5BTransportElement transport = new JingleS5BTransportProvider().parse(TestUtils.getParser(xml));
|
||||
assertEquals("972b7bf47291ca609517f67f86b5081086052dad", transport.getDestinationAddress());
|
||||
assertEquals("vj3hs98y", transport.getStreamId());
|
||||
assertEquals("vj3hs98y", transport.getSid());
|
||||
assertEquals(Bytestream.Mode.tcp, transport.getMode());
|
||||
assertEquals(3, transport.getCandidates().size());
|
||||
|
||||
|
@ -126,7 +126,7 @@ public class JingleS5BTransportTest extends SmackTestSuite {
|
|||
.parse(TestUtils.getParser(candidateError));
|
||||
assertNull(candidateErrorTransport.getDestinationAddress());
|
||||
assertNotNull(candidateErrorTransport.getInfo());
|
||||
assertEquals("vj3hs98y", candidateErrorTransport.getStreamId());
|
||||
assertEquals("vj3hs98y", candidateErrorTransport.getSid());
|
||||
assertEquals(JingleS5BTransportInfoElement.CandidateError(),
|
||||
candidateErrorTransport.getInfo());
|
||||
assertEquals(candidateError, candidateErrorTransport.toXML().toString());
|
||||
|
@ -140,7 +140,7 @@ public class JingleS5BTransportTest extends SmackTestSuite {
|
|||
assertNull(proxyErrorTransport.getDestinationAddress());
|
||||
assertNotNull(proxyErrorTransport.getInfo());
|
||||
assertNotNull(candidateErrorTransport.getInfo());
|
||||
assertEquals("vj3hs98y", proxyErrorTransport.getStreamId());
|
||||
assertEquals("vj3hs98y", proxyErrorTransport.getSid());
|
||||
assertEquals(JingleS5BTransportInfoElement.ProxyError(),
|
||||
proxyErrorTransport.getInfo());
|
||||
assertEquals(proxyError, proxyErrorTransport.toXML().toString());
|
||||
|
|
|
@ -14,32 +14,17 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.jingle_filetransfer;
|
||||
|
||||
import static junit.framework.TestCase.fail;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
package org.jivesoftware.smackx.jft;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smackx.bytestreams.socks5.Socks5Proxy;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleElement;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleReasonElement;
|
||||
import org.jivesoftware.smackx.jingle_filetransfer.callback.IncomingFileOfferCallback;
|
||||
import org.jivesoftware.smackx.jingle_filetransfer.handler.FileTransferHandler;
|
||||
import org.jivesoftware.smackx.jingle_filetransfer.listener.JingleFileTransferOfferListener;
|
||||
|
||||
import org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest;
|
||||
import org.igniterealtime.smack.inttest.SmackIntegrationTest;
|
||||
import org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment;
|
||||
import org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint;
|
||||
import org.junit.AfterClass;
|
||||
import org.jxmpp.jid.FullJid;
|
||||
|
||||
/**
|
||||
* Created by vanitas on 29.06.17.
|
||||
|
@ -62,6 +47,7 @@ public class FileTransferTest extends AbstractSmackIntegrationTest {
|
|||
super(environment);
|
||||
}
|
||||
|
||||
/*
|
||||
@SmackIntegrationTest
|
||||
public void basicFileTransferTest() {
|
||||
final SimpleResultSyncPoint resultSyncPoint1 = new SimpleResultSyncPoint();
|
||||
|
@ -130,7 +116,8 @@ public class FileTransferTest extends AbstractSmackIntegrationTest {
|
|||
LOGGER.log(Level.INFO, "SUCCESSFULLY SENT AND RECEIVED");
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
private File prepareNewTestFile(String name) {
|
||||
File testFile = new File(tempDir, name);
|
||||
try {
|
|
@ -18,4 +18,4 @@
|
|||
/**
|
||||
* TODO describe me.
|
||||
*/
|
||||
package org.jivesoftware.smackx.jingle_filetransfer;
|
||||
package org.jivesoftware.smackx.jft;
|
Loading…
Reference in a new issue