mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-23 20:42:06 +01:00
Start reworking JFT and JET code
This commit is contained in:
parent
e967849e5a
commit
438fc0e94b
27 changed files with 302 additions and 159 deletions
|
@ -34,14 +34,15 @@ import javax.crypto.spec.SecretKeySpec;
|
||||||
import org.jivesoftware.smack.Manager;
|
import org.jivesoftware.smack.Manager;
|
||||||
import org.jivesoftware.smack.XMPPConnection;
|
import org.jivesoftware.smack.XMPPConnection;
|
||||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||||
|
import org.jivesoftware.smack.util.StringUtils;
|
||||||
import org.jivesoftware.smackx.jet.element.JetSecurityElement;
|
import org.jivesoftware.smackx.jet.element.JetSecurityElement;
|
||||||
import org.jivesoftware.smackx.jingle.transport.legacy.JingleUtil;
|
import org.jivesoftware.smackx.jingle.JingleManager;
|
||||||
|
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionChildElement;
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleContentElement;
|
import org.jivesoftware.smackx.jingle.element.JingleContentElement;
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleElement;
|
import org.jivesoftware.smackx.jingle.element.JingleElement;
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionChildElement;
|
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.OutgoingJingleFileOffer;
|
import org.jivesoftware.smackx.jingle_filetransfer.OutgoingJingleFileOffer;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransfer;
|
import org.jivesoftware.smackx.jft.element.JingleFileTransferElement;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransferChild;
|
import org.jivesoftware.smackx.jft.element.JingleFileTransferChildElement;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.handler.FileTransferHandler;
|
import org.jivesoftware.smackx.jingle_filetransfer.handler.FileTransferHandler;
|
||||||
|
|
||||||
import org.jxmpp.jid.FullJid;
|
import org.jxmpp.jid.FullJid;
|
||||||
|
@ -53,16 +54,12 @@ public final class JetManager extends Manager {
|
||||||
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(JetManager.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(JetManager.class.getName());
|
||||||
|
|
||||||
public static final String NAMESPACE = "urn:xmpp:jingle:jet:0";
|
|
||||||
|
|
||||||
private static final WeakHashMap<XMPPConnection, JetManager> INSTANCES = new WeakHashMap<>();
|
private static final WeakHashMap<XMPPConnection, JetManager> INSTANCES = new WeakHashMap<>();
|
||||||
private final JingleUtil jutil;
|
|
||||||
|
|
||||||
private static final Map<String, JingleEncryptionMethod> encryptionMethods = new HashMap<>();
|
private static final Map<String, JingleEncryptionMethod> encryptionMethods = new HashMap<>();
|
||||||
|
|
||||||
private JetManager(XMPPConnection connection) {
|
private JetManager(XMPPConnection connection) {
|
||||||
super(connection);
|
super(connection);
|
||||||
jutil = new JingleUtil(connection);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JetManager getInstanceFor(XMPPConnection connection) {
|
public static JetManager getInstanceFor(XMPPConnection connection) {
|
||||||
|
@ -139,15 +136,15 @@ public final class JetManager extends Manager {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
String contentName = JingleManager.randomId();
|
String contentName = StringUtils.randomString(24);
|
||||||
|
|
||||||
ExtensionElement encryptionExtension = encryptionMethod.encryptJingleTransfer(recipient, keyAndIv);
|
ExtensionElement encryptionExtension = encryptionMethod.encryptJingleTransfer(recipient, keyAndIv);
|
||||||
JetSecurityElement securityElement = new JetSecurityElement(contentName, encryptionExtension);
|
JetSecurityElement securityElement = new JetSecurityElement(contentName, encryptionExtension);
|
||||||
|
|
||||||
OutgoingJingleFileOffer offer = new OutgoingJingleFileOffer(connection(), recipient);
|
OutgoingJingleFileOffer offer = new OutgoingJingleFileOffer(connection(), recipient);
|
||||||
|
|
||||||
JingleFileTransferChild fileTransferChild = JingleFileTransferChild.getBuilder().setFile(file).build();
|
JingleFileTransferChildElement fileTransferChild = JingleFileTransferChildElement.getBuilder().setFile(file).build();
|
||||||
JingleFileTransfer fileTransfer = new JingleFileTransfer(Collections.<JingleContentDescriptionChildElement>singletonList(fileTransferChild));
|
JingleFileTransferElement fileTransfer = new JingleFileTransferElement(Collections.<JingleContentDescriptionChildElement>singletonList(fileTransferChild));
|
||||||
|
|
||||||
JingleContentElement content = JingleContentElement.getBuilder()
|
JingleContentElement content = JingleContentElement.getBuilder()
|
||||||
.setCreator(JingleContentElement.Creator.initiator)
|
.setCreator(JingleContentElement.Creator.initiator)
|
||||||
|
|
|
@ -18,7 +18,7 @@ package org.jivesoftware.smackx.jet.element;
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||||
import org.jivesoftware.smackx.jet.JetManager;
|
import org.jivesoftware.smackx.jet.internal.JetSecurity;
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleContentSecurityElement;
|
import org.jivesoftware.smackx.jingle.element.JingleContentSecurityElement;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,6 +55,6 @@ public class JetSecurityElement extends JingleContentSecurityElement {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getNamespace() {
|
public String getNamespace() {
|
||||||
return JetManager.NAMESPACE;
|
return JetSecurity.NAMESPACE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
package org.jivesoftware.smackx.jet.internal;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||||
|
import org.jivesoftware.smackx.jet.element.JetSecurityElement;
|
||||||
|
import org.jivesoftware.smackx.jingle.element.JingleContentSecurityInfoElement;
|
||||||
|
import org.jivesoftware.smackx.jingle.element.JingleElement;
|
||||||
|
import org.jivesoftware.smackx.jingle.internal.JingleSecurity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by vanitas on 22.07.17.
|
||||||
|
*/
|
||||||
|
public class JetSecurity extends JingleSecurity<JetSecurityElement> {
|
||||||
|
|
||||||
|
public static final String NAMESPACE_V0 = "urn:xmpp:jingle:jet:0";
|
||||||
|
public static final String NAMESPACE = NAMESPACE_V0;
|
||||||
|
|
||||||
|
private ExtensionElement child;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JetSecurityElement getElement() {
|
||||||
|
return new JetSecurityElement(getParent().getName(), child);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JingleElement handleSecurityInfo(JingleContentSecurityInfoElement element, JingleElement wrapping) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
package org.jivesoftware.smackx.jft;
|
||||||
|
|
||||||
|
import java.util.WeakHashMap;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.Manager;
|
||||||
|
import org.jivesoftware.smack.XMPPConnection;
|
||||||
|
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||||
|
import org.jivesoftware.smackx.jft.internal.JingleFileTransfer;
|
||||||
|
import org.jivesoftware.smackx.jft.provider.JingleFileTransferProvider;
|
||||||
|
import org.jivesoftware.smackx.jingle.JingleDescriptionManager;
|
||||||
|
import org.jivesoftware.smackx.jingle.JingleManager;
|
||||||
|
import org.jivesoftware.smackx.jingle.callbacks.ContentAddCallback;
|
||||||
|
import org.jivesoftware.smackx.jingle.element.JingleElement;
|
||||||
|
import org.jivesoftware.smackx.jingle.internal.JingleContent;
|
||||||
|
import org.jivesoftware.smackx.jingle.provider.JingleContentProviderManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by vanitas on 22.07.17.
|
||||||
|
*/
|
||||||
|
public final class JingleFileTransferManager extends Manager implements JingleDescriptionManager {
|
||||||
|
|
||||||
|
private static final WeakHashMap<XMPPConnection, JingleFileTransferManager> INSTANCES = new WeakHashMap<>();
|
||||||
|
private final JingleManager jingleManager;
|
||||||
|
|
||||||
|
private JingleFileTransferManager(XMPPConnection connection) {
|
||||||
|
super(connection);
|
||||||
|
ServiceDiscoveryManager.getInstanceFor(connection).addFeature(getNamespace());
|
||||||
|
jingleManager = JingleManager.getInstanceFor(connection);
|
||||||
|
jingleManager.addJingleDescriptionManager(this);
|
||||||
|
JingleContentProviderManager.addJingleContentDescriptionProvider(getNamespace(), new JingleFileTransferProvider());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JingleFileTransferManager getInstanceFor(XMPPConnection connection) {
|
||||||
|
JingleFileTransferManager manager = INSTANCES.get(connection);
|
||||||
|
|
||||||
|
if (manager == null) {
|
||||||
|
manager = new JingleFileTransferManager(connection);
|
||||||
|
INSTANCES.put(connection, manager);
|
||||||
|
}
|
||||||
|
|
||||||
|
return manager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getNamespace() {
|
||||||
|
return JingleFileTransfer.NAMESPACE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JingleElement notifyContentListeners(JingleContent content, ContentAddCallback callback) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -14,7 +14,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.jivesoftware.smackx.jingle_filetransfer.element;
|
package org.jivesoftware.smackx.jft.element;
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||||
import org.jivesoftware.smack.util.Objects;
|
import org.jivesoftware.smack.util.Objects;
|
||||||
|
@ -24,16 +24,16 @@ import org.jivesoftware.smackx.jingle.element.JingleContentElement;
|
||||||
/**
|
/**
|
||||||
* Checksum element.
|
* Checksum element.
|
||||||
*/
|
*/
|
||||||
public class Checksum implements ExtensionElement {
|
public class ChecksumElement implements ExtensionElement {
|
||||||
public static final String ELEMENT = "checksum";
|
public static final String ELEMENT = "checksum";
|
||||||
public static final String ATTR_CREATOR = "creator";
|
public static final String ATTR_CREATOR = "creator";
|
||||||
public static final String ATTR_NAME = "name";
|
public static final String ATTR_NAME = "name";
|
||||||
|
|
||||||
private final JingleContentElement.Creator creator;
|
private final JingleContentElement.Creator creator;
|
||||||
private final String name;
|
private final String name;
|
||||||
private final JingleFileTransferChild file;
|
private final JingleFileTransferChildElement file;
|
||||||
|
|
||||||
public Checksum(JingleContentElement.Creator creator, String name, JingleFileTransferChild file) {
|
public ChecksumElement(JingleContentElement.Creator creator, String name, JingleFileTransferChildElement file) {
|
||||||
this.creator = creator;
|
this.creator = creator;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.file = Objects.requireNonNull(file, "file MUST NOT be null.");
|
this.file = Objects.requireNonNull(file, "file MUST NOT be null.");
|
||||||
|
@ -58,6 +58,6 @@ public class Checksum implements ExtensionElement {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getNamespace() {
|
public String getNamespace() {
|
||||||
return JingleFileTransfer.NAMESPACE_V5;
|
return JingleFileTransferElement.NAMESPACE_V5;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -14,7 +14,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.jivesoftware.smackx.jingle_filetransfer.element;
|
package org.jivesoftware.smackx.jft.element;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -26,7 +26,7 @@ import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionChildEleme
|
||||||
/**
|
/**
|
||||||
* Content of type File.
|
* Content of type File.
|
||||||
*/
|
*/
|
||||||
public class JingleFileTransferChild extends JingleContentDescriptionChildElement {
|
public class JingleFileTransferChildElement extends JingleContentDescriptionChildElement {
|
||||||
public static final String ELEMENT = "file";
|
public static final String ELEMENT = "file";
|
||||||
public static final String ELEM_DATE = "date";
|
public static final String ELEM_DATE = "date";
|
||||||
public static final String ELEM_DESC = "desc";
|
public static final String ELEM_DESC = "desc";
|
||||||
|
@ -42,7 +42,7 @@ public class JingleFileTransferChild extends JingleContentDescriptionChildElemen
|
||||||
private final int size;
|
private final int size;
|
||||||
private final Range range;
|
private final Range range;
|
||||||
|
|
||||||
public JingleFileTransferChild(Date date, String desc, HashElement hash, String mediaType, String name, int size, Range range) {
|
public JingleFileTransferChildElement(Date date, String desc, HashElement hash, String mediaType, String name, int size, Range range) {
|
||||||
this.date = date;
|
this.date = date;
|
||||||
this.desc = desc;
|
this.desc = desc;
|
||||||
this.hash = hash;
|
this.hash = hash;
|
||||||
|
@ -162,8 +162,8 @@ public class JingleFileTransferChild extends JingleContentDescriptionChildElemen
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JingleFileTransferChild build() {
|
public JingleFileTransferChildElement build() {
|
||||||
return new JingleFileTransferChild(date, desc, hash, mediaType, name, size, range);
|
return new JingleFileTransferChildElement(date, desc, hash, mediaType, name, size, range);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setFile(File file) {
|
public Builder setFile(File file) {
|
|
@ -14,25 +14,26 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.jivesoftware.smackx.jingle_filetransfer.element;
|
package org.jivesoftware.smackx.jft.element;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.jivesoftware.smackx.jft.internal.JingleFileTransfer;
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionElement;
|
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionElement;
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionChildElement;
|
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionChildElement;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* File element.
|
* File element.
|
||||||
*/
|
*/
|
||||||
public class JingleFileTransfer extends JingleContentDescriptionElement {
|
public class JingleFileTransferElement extends JingleContentDescriptionElement {
|
||||||
public static final String NAMESPACE_V5 = "urn:xmpp:jingle:apps:file-transfer:5";
|
|
||||||
|
|
||||||
public JingleFileTransfer(List<JingleContentDescriptionChildElement> payloads) {
|
|
||||||
|
public JingleFileTransferElement(List<JingleContentDescriptionChildElement> payloads) {
|
||||||
super(payloads);
|
super(payloads);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getNamespace() {
|
public String getNamespace() {
|
||||||
return NAMESPACE_V5;
|
return JingleFileTransfer.NAMESPACE;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -14,7 +14,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.jivesoftware.smackx.jingle_filetransfer.element;
|
package org.jivesoftware.smackx.jft.element;
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.NamedElement;
|
import org.jivesoftware.smack.packet.NamedElement;
|
||||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
import org.jivesoftware.smack.util.XmlStringBuilder;
|
|
@ -19,4 +19,4 @@
|
||||||
* Smack's API for <a href="https://xmpp.org/extensions/xep-0234.html">XEP-0234: Jingle File Transfer</a>.
|
* Smack's API for <a href="https://xmpp.org/extensions/xep-0234.html">XEP-0234: Jingle File Transfer</a>.
|
||||||
* Elements.
|
* Elements.
|
||||||
*/
|
*/
|
||||||
package org.jivesoftware.smackx.jingle_filetransfer.element;
|
package org.jivesoftware.smackx.jft.element;
|
|
@ -0,0 +1,7 @@
|
||||||
|
package org.jivesoftware.smackx.jft.internal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by vanitas on 22.07.17.
|
||||||
|
*/
|
||||||
|
public class JingleFileOffer extends JingleFileTransfer {
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package org.jivesoftware.smackx.jft.internal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by vanitas on 22.07.17.
|
||||||
|
*/
|
||||||
|
public class JingleFileRequest extends JingleFileTransfer {
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package org.jivesoftware.smackx.jft.internal;
|
||||||
|
|
||||||
|
import org.jivesoftware.smackx.jingle.internal.JingleDescription;
|
||||||
|
import org.jivesoftware.smackx.jft.element.JingleFileTransferElement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by vanitas on 22.07.17.
|
||||||
|
*/
|
||||||
|
public abstract class JingleFileTransfer extends JingleDescription<JingleFileTransferElement> {
|
||||||
|
|
||||||
|
public static final String NAMESPACE_V5 = "urn:xmpp:jingle:apps:file-transfer:5";
|
||||||
|
public static final String NAMESPACE = NAMESPACE_V5;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JingleFileTransferElement getElement() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -14,7 +14,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.jivesoftware.smackx.jingle_filetransfer.provider;
|
package org.jivesoftware.smackx.jft.provider;
|
||||||
|
|
||||||
import static org.xmlpull.v1.XmlPullParser.END_TAG;
|
import static org.xmlpull.v1.XmlPullParser.END_TAG;
|
||||||
import static org.xmlpull.v1.XmlPullParser.START_TAG;
|
import static org.xmlpull.v1.XmlPullParser.START_TAG;
|
||||||
|
@ -24,27 +24,27 @@ import org.jivesoftware.smack.util.ParserUtils;
|
||||||
import org.jivesoftware.smackx.hashes.element.HashElement;
|
import org.jivesoftware.smackx.hashes.element.HashElement;
|
||||||
import org.jivesoftware.smackx.hashes.provider.HashElementProvider;
|
import org.jivesoftware.smackx.hashes.provider.HashElementProvider;
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleContentElement;
|
import org.jivesoftware.smackx.jingle.element.JingleContentElement;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.element.Checksum;
|
import org.jivesoftware.smackx.jft.element.ChecksumElement;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransferChild;
|
import org.jivesoftware.smackx.jft.element.JingleFileTransferChildElement;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.element.Range;
|
import org.jivesoftware.smackx.jft.element.Range;
|
||||||
|
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provider for the Checksum element.
|
* Provider for the Checksum element.
|
||||||
*/
|
*/
|
||||||
public class ChecksumProvider extends ExtensionElementProvider<Checksum> {
|
public class ChecksumProvider extends ExtensionElementProvider<ChecksumElement> {
|
||||||
@Override
|
@Override
|
||||||
public Checksum parse(XmlPullParser parser, int initialDepth) throws Exception {
|
public ChecksumElement parse(XmlPullParser parser, int initialDepth) throws Exception {
|
||||||
JingleContentElement.Creator creator = null;
|
JingleContentElement.Creator creator = null;
|
||||||
String creatorString = parser.getAttributeValue(null, Checksum.ATTR_CREATOR);
|
String creatorString = parser.getAttributeValue(null, ChecksumElement.ATTR_CREATOR);
|
||||||
if (creatorString != null) {
|
if (creatorString != null) {
|
||||||
creator = JingleContentElement.Creator.valueOf(creatorString);
|
creator = JingleContentElement.Creator.valueOf(creatorString);
|
||||||
}
|
}
|
||||||
String name = parser.getAttributeValue(null, Checksum.ATTR_NAME);
|
String name = parser.getAttributeValue(null, ChecksumElement.ATTR_NAME);
|
||||||
|
|
||||||
|
|
||||||
JingleFileTransferChild.Builder cb = JingleFileTransferChild.getBuilder();
|
JingleFileTransferChildElement.Builder cb = JingleFileTransferChildElement.getBuilder();
|
||||||
HashElement hashElement = null;
|
HashElement hashElement = null;
|
||||||
Range range = null;
|
Range range = null;
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ public class ChecksumProvider extends ExtensionElementProvider<Checksum> {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case JingleFileTransferChild.ELEMENT:
|
case JingleFileTransferChildElement.ELEMENT:
|
||||||
if (hashElement != null) {
|
if (hashElement != null) {
|
||||||
cb.setHash(hashElement);
|
cb.setHash(hashElement);
|
||||||
}
|
}
|
||||||
|
@ -84,6 +84,6 @@ public class ChecksumProvider extends ExtensionElementProvider<Checksum> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new Checksum(creator, name, cb.build());
|
return new ChecksumElement(creator, name, cb.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -14,7 +14,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.jivesoftware.smackx.jingle_filetransfer.provider;
|
package org.jivesoftware.smackx.jft.provider;
|
||||||
|
|
||||||
import static org.xmlpull.v1.XmlPullParser.END_TAG;
|
import static org.xmlpull.v1.XmlPullParser.END_TAG;
|
||||||
import static org.xmlpull.v1.XmlPullParser.START_TAG;
|
import static org.xmlpull.v1.XmlPullParser.START_TAG;
|
||||||
|
@ -26,9 +26,9 @@ import org.jivesoftware.smackx.hashes.element.HashElement;
|
||||||
import org.jivesoftware.smackx.hashes.provider.HashElementProvider;
|
import org.jivesoftware.smackx.hashes.provider.HashElementProvider;
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionChildElement;
|
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionChildElement;
|
||||||
import org.jivesoftware.smackx.jingle.provider.JingleContentDescriptionProvider;
|
import org.jivesoftware.smackx.jingle.provider.JingleContentDescriptionProvider;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransfer;
|
import org.jivesoftware.smackx.jft.element.JingleFileTransferElement;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransferChild;
|
import org.jivesoftware.smackx.jft.element.JingleFileTransferChildElement;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.element.Range;
|
import org.jivesoftware.smackx.jft.element.Range;
|
||||||
|
|
||||||
import org.jxmpp.util.XmppDateTime;
|
import org.jxmpp.util.XmppDateTime;
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
|
@ -37,13 +37,13 @@ import org.xmlpull.v1.XmlPullParser;
|
||||||
* Provider for JingleContentDescriptionFileTransfer elements.
|
* Provider for JingleContentDescriptionFileTransfer elements.
|
||||||
*/
|
*/
|
||||||
public class JingleFileTransferProvider
|
public class JingleFileTransferProvider
|
||||||
extends JingleContentDescriptionProvider<JingleFileTransfer> {
|
extends JingleContentDescriptionProvider<JingleFileTransferElement> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JingleFileTransfer parse(XmlPullParser parser, int initialDepth) throws Exception {
|
public JingleFileTransferElement parse(XmlPullParser parser, int initialDepth) throws Exception {
|
||||||
ArrayList<JingleContentDescriptionChildElement> payloads = new ArrayList<>();
|
ArrayList<JingleContentDescriptionChildElement> payloads = new ArrayList<>();
|
||||||
boolean inRange = false;
|
boolean inRange = false;
|
||||||
JingleFileTransferChild.Builder builder = JingleFileTransferChild.getBuilder();
|
JingleFileTransferChildElement.Builder builder = JingleFileTransferChildElement.getBuilder();
|
||||||
HashElement inRangeHash = null;
|
HashElement inRangeHash = null;
|
||||||
Long length = null, offset = null;
|
Long length = null, offset = null;
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -53,23 +53,23 @@ public class JingleFileTransferProvider
|
||||||
|
|
||||||
if (tag == START_TAG) {
|
if (tag == START_TAG) {
|
||||||
switch (elem) {
|
switch (elem) {
|
||||||
case JingleFileTransferChild.ELEM_DATE:
|
case JingleFileTransferChildElement.ELEM_DATE:
|
||||||
builder.setDate(XmppDateTime.parseXEP0082Date(parser.nextText()));
|
builder.setDate(XmppDateTime.parseXEP0082Date(parser.nextText()));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case JingleFileTransferChild.ELEM_DESC:
|
case JingleFileTransferChildElement.ELEM_DESC:
|
||||||
builder.setDescription(parser.nextText());
|
builder.setDescription(parser.nextText());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case JingleFileTransferChild.ELEM_MEDIA_TYPE:
|
case JingleFileTransferChildElement.ELEM_MEDIA_TYPE:
|
||||||
builder.setMediaType(parser.nextText());
|
builder.setMediaType(parser.nextText());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case JingleFileTransferChild.ELEM_NAME:
|
case JingleFileTransferChildElement.ELEM_NAME:
|
||||||
builder.setName(parser.nextText());
|
builder.setName(parser.nextText());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case JingleFileTransferChild.ELEM_SIZE:
|
case JingleFileTransferChildElement.ELEM_SIZE:
|
||||||
builder.setSize(Integer.parseInt(parser.nextText()));
|
builder.setSize(Integer.parseInt(parser.nextText()));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -102,13 +102,13 @@ public class JingleFileTransferProvider
|
||||||
inRangeHash = null;
|
inRangeHash = null;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case JingleFileTransferChild.ELEMENT:
|
case JingleFileTransferChildElement.ELEMENT:
|
||||||
payloads.add(builder.build());
|
payloads.add(builder.build());
|
||||||
builder = JingleFileTransferChild.getBuilder();
|
builder = JingleFileTransferChildElement.getBuilder();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case JingleFileTransfer.ELEMENT:
|
case JingleFileTransferElement.ELEMENT:
|
||||||
return new JingleFileTransfer(payloads);
|
return new JingleFileTransferElement(payloads);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -19,4 +19,4 @@
|
||||||
* Smack's API for <a href="https://xmpp.org/extensions/xep-0234.html">XEP-0234: Jingle File Transfer</a>.
|
* Smack's API for <a href="https://xmpp.org/extensions/xep-0234.html">XEP-0234: Jingle File Transfer</a>.
|
||||||
* Providers.
|
* Providers.
|
||||||
*/
|
*/
|
||||||
package org.jivesoftware.smackx.jingle_filetransfer.provider;
|
package org.jivesoftware.smackx.jft.provider;
|
|
@ -32,7 +32,7 @@ import org.jivesoftware.smackx.jingle.element.JingleReasonElement;
|
||||||
import org.jivesoftware.smackx.jingle.transports.JingleTransportInitiationCallback;
|
import org.jivesoftware.smackx.jingle.transports.JingleTransportInitiationCallback;
|
||||||
import org.jivesoftware.smackx.jingle.transports.JingleTransportManager;
|
import org.jivesoftware.smackx.jingle.transports.JingleTransportManager;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.callback.IncomingFileOfferCallback;
|
import org.jivesoftware.smackx.jingle_filetransfer.callback.IncomingFileOfferCallback;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransfer;
|
import org.jivesoftware.smackx.jft.element.JingleFileTransferElement;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.handler.FileTransferHandler;
|
import org.jivesoftware.smackx.jingle_filetransfer.handler.FileTransferHandler;
|
||||||
|
|
||||||
import org.jxmpp.jid.FullJid;
|
import org.jxmpp.jid.FullJid;
|
||||||
|
@ -91,7 +91,7 @@ public class IncomingJingleFileOffer extends JingleFileTransferSession implement
|
||||||
}
|
}
|
||||||
|
|
||||||
this.contents.addAll(initiate.getContents());
|
this.contents.addAll(initiate.getContents());
|
||||||
this.file = (JingleFileTransfer) contents.get(0).getDescription();
|
this.file = (JingleFileTransferElement) contents.get(0).getDescription();
|
||||||
|
|
||||||
JingleTransportManager<?> transportManager = tm.getTransportManager(initiate);
|
JingleTransportManager<?> transportManager = tm.getTransportManager(initiate);
|
||||||
if (transportManager == null) {
|
if (transportManager == null) {
|
||||||
|
@ -120,7 +120,7 @@ public class IncomingJingleFileOffer extends JingleFileTransferSession implement
|
||||||
|
|
||||||
state = State.pending;
|
state = State.pending;
|
||||||
|
|
||||||
JingleFileTransferManager.getInstanceFor(connection).notifyIncomingFileOffer(initiate,
|
JingleFileTransferManagerAlt.getInstanceFor(connection).notifyIncomingFileOffer(initiate,
|
||||||
IncomingJingleFileOffer.this);
|
IncomingJingleFileOffer.this);
|
||||||
|
|
||||||
return jutil.createAck(initiate);
|
return jutil.createAck(initiate);
|
||||||
|
@ -183,7 +183,7 @@ public class IncomingJingleFileOffer extends JingleFileTransferSession implement
|
||||||
return jutil.createErrorOutOfOrder(transportAccept);
|
return jutil.createErrorOutOfOrder(transportAccept);
|
||||||
}
|
}
|
||||||
|
|
||||||
JingleFileTransferManager.getInstanceFor(connection)
|
JingleFileTransferManagerAlt.getInstanceFor(connection)
|
||||||
.notifyIncomingFileOffer(pendingSessionInitiate, this);
|
.notifyIncomingFileOffer(pendingSessionInitiate, this);
|
||||||
transportSession.processJingle(transportAccept);
|
transportSession.processJingle(transportAccept);
|
||||||
state = State.pending;
|
state = State.pending;
|
||||||
|
|
|
@ -29,45 +29,46 @@ import org.jivesoftware.smack.XMPPConnection;
|
||||||
import org.jivesoftware.smack.XMPPException;
|
import org.jivesoftware.smack.XMPPException;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||||
import org.jivesoftware.smackx.jingle.transport.legacy.JingleUtil;
|
import org.jivesoftware.smackx.jft.element.JingleFileTransferChildElement;
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleContentElement;
|
import org.jivesoftware.smackx.jft.element.JingleFileTransferElement;
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleElement;
|
import org.jivesoftware.smackx.jft.internal.JingleFileTransfer;
|
||||||
|
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.JingleAction;
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionChildElement;
|
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.provider.JingleContentProviderManager;
|
||||||
|
import org.jivesoftware.smackx.jingle.transport.legacy.JingleUtil;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.callback.IncomingFileOfferCallback;
|
import org.jivesoftware.smackx.jingle_filetransfer.callback.IncomingFileOfferCallback;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransfer;
|
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransferChild;
|
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.handler.FileTransferHandler;
|
import org.jivesoftware.smackx.jingle_filetransfer.handler.FileTransferHandler;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.listener.JingleFileTransferOfferListener;
|
import org.jivesoftware.smackx.jingle_filetransfer.listener.JingleFileTransferOfferListener;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.provider.JingleFileTransferProvider;
|
|
||||||
|
|
||||||
import org.jxmpp.jid.FullJid;
|
import org.jxmpp.jid.FullJid;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manager for JingleFileTransfer (XEP-0234).
|
* Manager for JingleFileTransfer (XEP-0234).
|
||||||
*/
|
*/
|
||||||
public final class JingleFileTransferManager extends Manager implements JingleHandler {
|
public final class JingleFileTransferManagerAlt extends Manager {
|
||||||
private static final Logger LOGGER = Logger.getLogger(JingleFileTransferManager.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(JingleFileTransferManagerAlt.class.getName());
|
||||||
|
|
||||||
private static final WeakHashMap<XMPPConnection, JingleFileTransferManager> INSTANCES = new WeakHashMap<>();
|
private static final WeakHashMap<XMPPConnection, JingleFileTransferManagerAlt> INSTANCES = new WeakHashMap<>();
|
||||||
private final ArrayList<JingleFileTransferOfferListener> jingleFileTransferOfferListeners = new ArrayList<>();
|
private final ArrayList<JingleFileTransferOfferListener> jingleFileTransferOfferListeners = new ArrayList<>();
|
||||||
private final JingleUtil jutil;
|
|
||||||
|
|
||||||
private JingleFileTransferManager(XMPPConnection connection) {
|
private JingleFileTransferManagerAlt(XMPPConnection connection) {
|
||||||
super(connection);
|
super(connection);
|
||||||
ServiceDiscoveryManager.getInstanceFor(connection).addFeature(JingleFileTransfer.NAMESPACE_V5);
|
ServiceDiscoveryManager.getInstanceFor(connection).addFeature(JingleFileTransfer.NAMESPACE_V5);
|
||||||
JingleManager jingleManager = JingleManager.getInstanceFor(connection);
|
JingleManager jingleManager = JingleManager.getInstanceFor(connection);
|
||||||
jingleManager.registerDescriptionHandler(JingleFileTransfer.NAMESPACE_V5, this);
|
jingleManager.addJingleDescriptionManager(this);
|
||||||
JingleContentProviderManager.addJingleContentDescriptionProvider(
|
JingleContentProviderManager.addJingleContentDescriptionProvider(
|
||||||
JingleFileTransfer.NAMESPACE_V5, new JingleFileTransferProvider());
|
JingleFileTransferElement.NAMESPACE_V5, new JingleFileTransferProvider());
|
||||||
jutil = new JingleUtil(connection);
|
jutil = new JingleUtil(connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JingleFileTransferManager getInstanceFor(XMPPConnection connection) {
|
public static JingleFileTransferManagerAlt getInstanceFor(XMPPConnection connection) {
|
||||||
JingleFileTransferManager manager = INSTANCES.get(connection);
|
JingleFileTransferManagerAlt manager = INSTANCES.get(connection);
|
||||||
if (manager == null) {
|
if (manager == null) {
|
||||||
manager = new JingleFileTransferManager(connection);
|
manager = new JingleFileTransferManagerAlt(connection);
|
||||||
INSTANCES.put(connection, manager);
|
INSTANCES.put(connection, manager);
|
||||||
}
|
}
|
||||||
return manager;
|
return manager;
|
||||||
|
@ -141,12 +142,12 @@ public final class JingleFileTransferManager extends Manager implements JingleHa
|
||||||
jingleFileTransferOfferListeners.remove(listener);
|
jingleFileTransferOfferListeners.remove(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JingleFileTransfer fileTransferFromFile(File file) {
|
public static JingleFileTransferElement fileTransferFromFile(File file) {
|
||||||
JingleFileTransferChild.Builder fb = JingleFileTransferChild.getBuilder();
|
JingleFileTransferChildElement.Builder fb = JingleFileTransferChildElement.getBuilder();
|
||||||
fb.setFile(file)
|
fb.setFile(file)
|
||||||
.setDescription("A file.")
|
.setDescription("A file.")
|
||||||
.setMediaType("application/octet-stream");
|
.setMediaType("application/octet-stream");
|
||||||
|
|
||||||
return new JingleFileTransfer(Collections.<JingleContentDescriptionChildElement>singletonList(fb.build()));
|
return new JingleFileTransferElement(Collections.<JingleContentDescriptionChildElement>singletonList(fb.build()));
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -21,7 +21,7 @@ import java.util.ArrayList;
|
||||||
import org.jivesoftware.smack.XMPPConnection;
|
import org.jivesoftware.smack.XMPPConnection;
|
||||||
import org.jivesoftware.smackx.jingle.transport.legacy.JingleUtil;
|
import org.jivesoftware.smackx.jingle.transport.legacy.JingleUtil;
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleReasonElement;
|
import org.jivesoftware.smackx.jingle.element.JingleReasonElement;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransfer;
|
import org.jivesoftware.smackx.jft.element.JingleFileTransferElement;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.handler.FileTransferHandler;
|
import org.jivesoftware.smackx.jingle_filetransfer.handler.FileTransferHandler;
|
||||||
|
|
||||||
import org.jxmpp.jid.FullJid;
|
import org.jxmpp.jid.FullJid;
|
||||||
|
@ -45,7 +45,7 @@ public abstract class JingleFileTransferSession extends JingleSession implements
|
||||||
protected final XMPPConnection connection;
|
protected final XMPPConnection connection;
|
||||||
protected final JingleUtil jutil;
|
protected final JingleUtil jutil;
|
||||||
|
|
||||||
protected JingleFileTransfer file;
|
protected JingleFileTransferElement file;
|
||||||
|
|
||||||
private final Type type;
|
private final Type type;
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ import org.jivesoftware.smackx.jingle.element.JingleContentElement;
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleReasonElement;
|
import org.jivesoftware.smackx.jingle.element.JingleReasonElement;
|
||||||
import org.jivesoftware.smackx.jingle.transports.JingleTransportInitiationCallback;
|
import org.jivesoftware.smackx.jingle.transports.JingleTransportInitiationCallback;
|
||||||
import org.jivesoftware.smackx.jingle.transports.JingleTransportManager;
|
import org.jivesoftware.smackx.jingle.transports.JingleTransportManager;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransfer;
|
import org.jivesoftware.smackx.jft.element.JingleFileTransferElement;
|
||||||
|
|
||||||
import org.jxmpp.jid.FullJid;
|
import org.jxmpp.jid.FullJid;
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ public class OutgoingJingleFileOffer extends JingleFileTransferSession {
|
||||||
SmackException.NotConnectedException, SmackException.NoResponseException {
|
SmackException.NotConnectedException, SmackException.NoResponseException {
|
||||||
source = file;
|
source = file;
|
||||||
String contentName = JingleManager.randomId();
|
String contentName = JingleManager.randomId();
|
||||||
JingleFileTransfer transfer = JingleFileTransferManager.fileTransferFromFile(file);
|
JingleFileTransferElement transfer = JingleFileTransferManagerAlt.fileTransferFromFile(file);
|
||||||
|
|
||||||
initiateFileOffer(transfer, JingleContentElement.Creator.initiator, contentName);
|
initiateFileOffer(transfer, JingleContentElement.Creator.initiator, contentName);
|
||||||
}
|
}
|
||||||
|
@ -99,11 +99,11 @@ public class OutgoingJingleFileOffer extends JingleFileTransferSession {
|
||||||
public SmackFuture<?> sendAsync(File file) {
|
public SmackFuture<?> sendAsync(File file) {
|
||||||
source = file;
|
source = file;
|
||||||
String contentName = "jft-" + StringUtils.randomString(20);
|
String contentName = "jft-" + StringUtils.randomString(20);
|
||||||
JingleFileTransfer transfer = JingleFileTransferManager.fileTransferFromFile(file);
|
JingleFileTransferElement transfer = JingleFileTransferManagerAlt.fileTransferFromFile(file);
|
||||||
return null; //TODO
|
return null; //TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initiateFileOffer(JingleFileTransfer file, JingleContentElement.Creator creator, String name) throws InterruptedException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException {
|
public void initiateFileOffer(JingleFileTransferElement file, JingleContentElement.Creator creator, String name) throws InterruptedException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException {
|
||||||
if (state != State.fresh) {
|
if (state != State.fresh) {
|
||||||
throw new IllegalStateException("This session is not fresh.");
|
throw new IllegalStateException("This session is not fresh.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,8 +25,8 @@ import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleReasonElement;
|
import org.jivesoftware.smackx.jingle.element.JingleReasonElement;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransfer;
|
import org.jivesoftware.smackx.jft.element.JingleFileTransferElement;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransferChild;
|
import org.jivesoftware.smackx.jft.element.JingleFileTransferChildElement;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Thread for receiving data.
|
* Thread for receiving data.
|
||||||
|
@ -35,11 +35,11 @@ public class ReceiveTask implements Runnable {
|
||||||
private static final Logger LOGGER = Logger.getLogger(ReceiveTask.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(ReceiveTask.class.getName());
|
||||||
|
|
||||||
private final BytestreamSession byteStream;
|
private final BytestreamSession byteStream;
|
||||||
private final JingleFileTransfer fileTransfer;
|
private final JingleFileTransferElement fileTransfer;
|
||||||
private final File target;
|
private final File target;
|
||||||
private final JingleFileTransferSession session;
|
private final JingleFileTransferSession session;
|
||||||
|
|
||||||
public ReceiveTask(JingleFileTransferSession session, BytestreamSession byteStream, JingleFileTransfer fileTransfer, File target) {
|
public ReceiveTask(JingleFileTransferSession session, BytestreamSession byteStream, JingleFileTransferElement fileTransfer, File target) {
|
||||||
this.byteStream = byteStream;
|
this.byteStream = byteStream;
|
||||||
this.fileTransfer = fileTransfer;
|
this.fileTransfer = fileTransfer;
|
||||||
this.target = target;
|
this.target = target;
|
||||||
|
@ -48,7 +48,7 @@ public class ReceiveTask implements Runnable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
JingleFileTransferChild transfer = (JingleFileTransferChild) fileTransfer.getJingleContentDescriptionChildren().get(0);
|
JingleFileTransferChildElement transfer = (JingleFileTransferChildElement) fileTransfer.getJingleContentDescriptionChildren().get(0);
|
||||||
FileOutputStream outputStream = null;
|
FileOutputStream outputStream = null;
|
||||||
InputStream inputStream;
|
InputStream inputStream;
|
||||||
|
|
||||||
|
|
|
@ -23,10 +23,10 @@ import org.jivesoftware.smack.test.util.TestUtils;
|
||||||
import org.jivesoftware.smackx.hashes.HashManager;
|
import org.jivesoftware.smackx.hashes.HashManager;
|
||||||
import org.jivesoftware.smackx.hashes.element.HashElement;
|
import org.jivesoftware.smackx.hashes.element.HashElement;
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleContentElement;
|
import org.jivesoftware.smackx.jingle.element.JingleContentElement;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.element.Checksum;
|
import org.jivesoftware.smackx.jft.element.ChecksumElement;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransferChild;
|
import org.jivesoftware.smackx.jft.element.JingleFileTransferChildElement;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.element.Range;
|
import org.jivesoftware.smackx.jft.element.Range;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.provider.ChecksumProvider;
|
import org.jivesoftware.smackx.jft.provider.ChecksumProvider;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -38,8 +38,8 @@ public class ChecksumTest extends SmackTestSuite {
|
||||||
@Test
|
@Test
|
||||||
public void parserTest() throws Exception {
|
public void parserTest() throws Exception {
|
||||||
HashElement hash = new HashElement(HashManager.ALGORITHM.SHA_256, "f4OxZX/x/FO5LcGBSKHWXfwtSx+j1ncoSt3SABJtkGk=");
|
HashElement hash = new HashElement(HashManager.ALGORITHM.SHA_256, "f4OxZX/x/FO5LcGBSKHWXfwtSx+j1ncoSt3SABJtkGk=");
|
||||||
JingleFileTransferChild file = new JingleFileTransferChild(null, null, hash, null, null, -1, null);
|
JingleFileTransferChildElement file = new JingleFileTransferChildElement(null, null, hash, null, null, -1, null);
|
||||||
Checksum checksum = new Checksum(JingleContentElement.Creator.initiator, "name", file);
|
ChecksumElement checksum = new ChecksumElement(JingleContentElement.Creator.initiator, "name", file);
|
||||||
|
|
||||||
String xml = "<checksum xmlns='urn:xmpp:jingle:apps:file-transfer:5' creator='initiator' name='name'>" +
|
String xml = "<checksum xmlns='urn:xmpp:jingle:apps:file-transfer:5' creator='initiator' name='name'>" +
|
||||||
"<file>" +
|
"<file>" +
|
||||||
|
@ -51,8 +51,8 @@ public class ChecksumTest extends SmackTestSuite {
|
||||||
assertXMLEqual(xml, new ChecksumProvider().parse(TestUtils.getParser(xml)).toXML().toString());
|
assertXMLEqual(xml, new ChecksumProvider().parse(TestUtils.getParser(xml)).toXML().toString());
|
||||||
|
|
||||||
Range range = new Range(12L,34L);
|
Range range = new Range(12L,34L);
|
||||||
file = new JingleFileTransferChild(null, null, hash, null, null, -1, range);
|
file = new JingleFileTransferChildElement(null, null, hash, null, null, -1, range);
|
||||||
checksum = new Checksum(JingleContentElement.Creator.initiator, "name", file);
|
checksum = new ChecksumElement(JingleContentElement.Creator.initiator, "name", file);
|
||||||
|
|
||||||
xml = "<checksum xmlns='urn:xmpp:jingle:apps:file-transfer:5' creator='initiator' name='name'>" +
|
xml = "<checksum xmlns='urn:xmpp:jingle:apps:file-transfer:5' creator='initiator' name='name'>" +
|
||||||
"<file>" +
|
"<file>" +
|
||||||
|
|
|
@ -36,9 +36,9 @@ import org.jivesoftware.smackx.jingle.element.JingleElement;
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleAction;
|
import org.jivesoftware.smackx.jingle.element.JingleAction;
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionChildElement;
|
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionChildElement;
|
||||||
import org.jivesoftware.smackx.jingle.transports.jingle_ibb.element.JingleIBBTransport;
|
import org.jivesoftware.smackx.jingle.transports.jingle_ibb.element.JingleIBBTransport;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransfer;
|
import org.jivesoftware.smackx.jft.element.JingleFileTransferElement;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransferChild;
|
import org.jivesoftware.smackx.jft.element.JingleFileTransferChildElement;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.provider.JingleFileTransferProvider;
|
import org.jivesoftware.smackx.jft.provider.JingleFileTransferProvider;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -74,8 +74,8 @@ public class JingleUtilFileTransferTest extends SmackTestSuite {
|
||||||
JingleIBBTransport transport = new JingleIBBTransport("transid");
|
JingleIBBTransport transport = new JingleIBBTransport("transid");
|
||||||
Date date = new Date();
|
Date date = new Date();
|
||||||
HashElement hash = new HashElement(HashManager.ALGORITHM.SHA_256, "f4OxZX/x/FO5LcGBSKHWXfwtSx+j1ncoSt3SABJtkGk=");
|
HashElement hash = new HashElement(HashManager.ALGORITHM.SHA_256, "f4OxZX/x/FO5LcGBSKHWXfwtSx+j1ncoSt3SABJtkGk=");
|
||||||
JingleFileTransferChild file = new JingleFileTransferChild(date, "desc", hash, "application/octet-stream", "name", 1337, null);
|
JingleFileTransferChildElement file = new JingleFileTransferChildElement(date, "desc", hash, "application/octet-stream", "name", 1337, null);
|
||||||
JingleFileTransfer description = new JingleFileTransfer(Collections.<JingleContentDescriptionChildElement>singletonList(file));
|
JingleFileTransferElement description = new JingleFileTransferElement(Collections.<JingleContentDescriptionChildElement>singletonList(file));
|
||||||
|
|
||||||
String contentName = "content";
|
String contentName = "content";
|
||||||
|
|
||||||
|
@ -108,8 +108,8 @@ public class JingleUtilFileTransferTest extends SmackTestSuite {
|
||||||
|
|
||||||
assertEquals(1, description.getJingleContentDescriptionChildren().size());
|
assertEquals(1, description.getJingleContentDescriptionChildren().size());
|
||||||
assertEquals(file, description.getJingleContentDescriptionChildren().get(0));
|
assertEquals(file, description.getJingleContentDescriptionChildren().get(0));
|
||||||
assertEquals(JingleFileTransferChild.ELEMENT, file.getElementName());
|
assertEquals(JingleFileTransferChildElement.ELEMENT, file.getElementName());
|
||||||
assertEquals(JingleFileTransfer.NAMESPACE_V5, description.getNamespace());
|
assertEquals(JingleFileTransferElement.NAMESPACE_V5, description.getNamespace());
|
||||||
assertEquals(date, file.getDate());
|
assertEquals(date, file.getDate());
|
||||||
assertEquals(hash, file.getHash());
|
assertEquals(hash, file.getHash());
|
||||||
assertEquals("application/octet-stream", file.getMediaType());
|
assertEquals("application/octet-stream", file.getMediaType());
|
||||||
|
@ -142,7 +142,7 @@ public class JingleUtilFileTransferTest extends SmackTestSuite {
|
||||||
"</description>";
|
"</description>";
|
||||||
assertXMLEqual(descriptionXML, description.toXML().toString());
|
assertXMLEqual(descriptionXML, description.toXML().toString());
|
||||||
|
|
||||||
JingleFileTransfer parsed = new JingleFileTransferProvider().parse(TestUtils.getParser(descriptionXML));
|
JingleFileTransferElement parsed = new JingleFileTransferProvider().parse(TestUtils.getParser(descriptionXML));
|
||||||
assertEquals(1, parsed.getJingleContentDescriptionChildren().size());
|
assertEquals(1, parsed.getJingleContentDescriptionChildren().size());
|
||||||
assertEquals(file.toXML().toString(), parsed.getJingleContentDescriptionChildren().get(0).toXML().toString());
|
assertEquals(file.toXML().toString(), parsed.getJingleContentDescriptionChildren().get(0).toXML().toString());
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ public abstract class JingleSecurity<D extends JingleContentSecurityElement> {
|
||||||
|
|
||||||
public abstract D getElement();
|
public abstract D getElement();
|
||||||
|
|
||||||
public abstract JingleElement handleSecurityInfo(JingleContentSecurityInfoElement element);
|
public abstract JingleElement handleSecurityInfo(JingleContentSecurityInfoElement element, JingleElement wrapping);
|
||||||
|
|
||||||
public void setParent(JingleContent parent) {
|
public void setParent(JingleContent parent) {
|
||||||
if (this.parent != parent) {
|
if (this.parent != parent) {
|
||||||
|
|
|
@ -1,10 +1,16 @@
|
||||||
package org.jivesoftware.smackx.jingle.transport.jingle_ibb;
|
package org.jivesoftware.smackx.jingle.transport.jingle_ibb;
|
||||||
|
|
||||||
|
import java.util.WeakHashMap;
|
||||||
|
|
||||||
import org.jivesoftware.smack.Manager;
|
import org.jivesoftware.smack.Manager;
|
||||||
import org.jivesoftware.smack.XMPPConnection;
|
import org.jivesoftware.smack.XMPPConnection;
|
||||||
|
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||||
|
import org.jivesoftware.smackx.jingle.JingleManager;
|
||||||
import org.jivesoftware.smackx.jingle.JingleTransportManager;
|
import org.jivesoftware.smackx.jingle.JingleTransportManager;
|
||||||
import org.jivesoftware.smackx.jingle.internal.JingleContent;
|
import org.jivesoftware.smackx.jingle.internal.JingleContent;
|
||||||
import org.jivesoftware.smackx.jingle.internal.JingleTransport;
|
import org.jivesoftware.smackx.jingle.internal.JingleTransport;
|
||||||
|
import org.jivesoftware.smackx.jingle.provider.JingleContentProviderManager;
|
||||||
|
import org.jivesoftware.smackx.jingle.transport.jingle_ibb.provider.JingleIBBTransportProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by vanitas on 21.07.17.
|
* Created by vanitas on 21.07.17.
|
||||||
|
@ -13,8 +19,25 @@ public class JingleIBBTransportManager extends Manager implements JingleTranspor
|
||||||
|
|
||||||
public static final short MAX_BLOCKSIZE = 8192;
|
public static final short MAX_BLOCKSIZE = 8192;
|
||||||
|
|
||||||
|
private static final WeakHashMap<XMPPConnection, JingleIBBTransportManager> INSTANCES = new WeakHashMap<>();
|
||||||
|
|
||||||
private JingleIBBTransportManager(XMPPConnection connection) {
|
private JingleIBBTransportManager(XMPPConnection connection) {
|
||||||
super(connection);
|
super(connection);
|
||||||
|
ServiceDiscoveryManager.getInstanceFor(connection).addFeature(getNamespace());
|
||||||
|
JingleManager jingleManager = JingleManager.getInstanceFor(connection);
|
||||||
|
jingleManager.addJingleTransportManager(this);
|
||||||
|
JingleContentProviderManager.addJingleContentTransportProvider(getNamespace(), new JingleIBBTransportProvider());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JingleIBBTransportManager getInstanceFor(XMPPConnection connection) {
|
||||||
|
JingleIBBTransportManager manager = INSTANCES.get(connection);
|
||||||
|
|
||||||
|
if (manager == null) {
|
||||||
|
manager = new JingleIBBTransportManager(connection);
|
||||||
|
INSTANCES.put(connection, manager);
|
||||||
|
}
|
||||||
|
|
||||||
|
return manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -151,7 +151,7 @@ public class JingleS5BTransport extends JingleTransport<JingleS5BTransportElemen
|
||||||
}
|
}
|
||||||
|
|
||||||
connection.createStanzaCollectorAndSend(transportManager.createCandidateUsed(this, selectedCandidate));
|
connection.createStanzaCollectorAndSend(transportManager.createCandidateUsed(this, selectedCandidate));
|
||||||
//connectIfReady();
|
connectIfReady();
|
||||||
}
|
}
|
||||||
|
|
||||||
public JingleS5BTransportCandidate connectToCandidates(int timeout) {
|
public JingleS5BTransportCandidate connectToCandidates(int timeout) {
|
||||||
|
@ -314,7 +314,7 @@ public class JingleS5BTransport extends JingleTransport<JingleS5BTransportElemen
|
||||||
//TODO: Alert! Illegal candidateId!
|
//TODO: Alert! Illegal candidateId!
|
||||||
}
|
}
|
||||||
|
|
||||||
//connectIfReady();
|
connectIfReady();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleCandidateActivate(JingleS5BTransportInfoElement info) {
|
private void handleCandidateActivate(JingleS5BTransportInfoElement info) {
|
||||||
|
@ -325,7 +325,7 @@ public class JingleS5BTransport extends JingleTransport<JingleS5BTransportElemen
|
||||||
|
|
||||||
private void handleCandidateError(JingleS5BTransportInfoElement info) {
|
private void handleCandidateError(JingleS5BTransportInfoElement info) {
|
||||||
((JingleS5BTransport) getPeersProposal()).setSelectedCandidate(CANDIDATE_FAILURE);
|
((JingleS5BTransport) getPeersProposal()).setSelectedCandidate(CANDIDATE_FAILURE);
|
||||||
//connectIfReady();
|
connectIfReady();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleProxyError(JingleS5BTransportInfoElement info) {
|
private void handleProxyError(JingleS5BTransportInfoElement info) {
|
||||||
|
|
|
@ -34,6 +34,8 @@ import org.jivesoftware.smack.util.StringUtils;
|
||||||
import org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamManager;
|
import org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamManager;
|
||||||
import org.jivesoftware.smackx.bytestreams.socks5.Socks5Proxy;
|
import org.jivesoftware.smackx.bytestreams.socks5.Socks5Proxy;
|
||||||
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
|
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
|
||||||
|
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||||
|
import org.jivesoftware.smackx.jingle.JingleManager;
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleElement;
|
import org.jivesoftware.smackx.jingle.element.JingleElement;
|
||||||
import org.jivesoftware.smackx.jingle.internal.JingleContent;
|
import org.jivesoftware.smackx.jingle.internal.JingleContent;
|
||||||
import org.jivesoftware.smackx.jingle.internal.JingleSession;
|
import org.jivesoftware.smackx.jingle.internal.JingleSession;
|
||||||
|
@ -68,53 +70,12 @@ public final class JingleS5BTransportManager extends Manager implements JingleTr
|
||||||
|
|
||||||
private JingleS5BTransportManager(XMPPConnection connection) {
|
private JingleS5BTransportManager(XMPPConnection connection) {
|
||||||
super(connection);
|
super(connection);
|
||||||
|
ServiceDiscoveryManager.getInstanceFor(connection).addFeature(getNamespace());
|
||||||
|
JingleManager jingleManager = JingleManager.getInstanceFor(connection);
|
||||||
|
jingleManager.addJingleTransportManager(this);
|
||||||
JingleContentProviderManager.addJingleContentTransportProvider(getNamespace(), new JingleS5BTransportProvider());
|
JingleContentProviderManager.addJingleContentTransportProvider(getNamespace(), new JingleS5BTransportProvider());
|
||||||
connection.addConnectionListener(new ConnectionListener() {
|
|
||||||
|
|
||||||
@Override
|
connection.addConnectionListener(connectionListener);
|
||||||
public void connected(XMPPConnection connection) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void authenticated(XMPPConnection connection, boolean resumed) {
|
|
||||||
if (connection.equals(connection())) {
|
|
||||||
try {
|
|
||||||
Socks5Proxy socks5Proxy = Socks5Proxy.getSocks5Proxy();
|
|
||||||
if (!socks5Proxy.isRunning()) {
|
|
||||||
socks5Proxy.start();
|
|
||||||
}
|
|
||||||
localStreamHosts = queryLocalStreamHosts();
|
|
||||||
availableStreamHosts = queryAvailableStreamHosts();
|
|
||||||
} catch (InterruptedException | SmackException.NoResponseException | SmackException.NotConnectedException | XMPPException.XMPPErrorException e) {
|
|
||||||
LOGGER.log(Level.WARNING, "Could not query available StreamHosts: " + e, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void connectionClosed() {
|
|
||||||
Socks5Proxy proxy = Socks5Proxy.getSocks5Proxy();
|
|
||||||
if (proxy.isRunning()) {
|
|
||||||
Socks5Proxy.getSocks5Proxy().stop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void connectionClosedOnError(Exception e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void reconnectionSuccessful() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void reconnectingIn(int seconds) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void reconnectionFailed(Exception e) {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JingleS5BTransportManager getInstanceFor(XMPPConnection connection) {
|
public static JingleS5BTransportManager getInstanceFor(XMPPConnection connection) {
|
||||||
|
@ -277,4 +238,51 @@ public final class JingleS5BTransportManager extends Manager implements JingleTr
|
||||||
public int compareTo(JingleTransportManager manager) {
|
public int compareTo(JingleTransportManager manager) {
|
||||||
return 1; // We are #1!
|
return 1; // We are #1!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ConnectionListener connectionListener = new ConnectionListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void connected(XMPPConnection connection) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void authenticated(XMPPConnection connection, boolean resumed) {
|
||||||
|
if (connection.equals(connection())) {
|
||||||
|
try {
|
||||||
|
Socks5Proxy socks5Proxy = Socks5Proxy.getSocks5Proxy();
|
||||||
|
if (!socks5Proxy.isRunning()) {
|
||||||
|
socks5Proxy.start();
|
||||||
|
}
|
||||||
|
localStreamHosts = queryLocalStreamHosts();
|
||||||
|
availableStreamHosts = queryAvailableStreamHosts();
|
||||||
|
} catch (InterruptedException | SmackException.NoResponseException | SmackException.NotConnectedException | XMPPException.XMPPErrorException e) {
|
||||||
|
LOGGER.log(Level.WARNING, "Could not query available StreamHosts: " + e, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void connectionClosed() {
|
||||||
|
Socks5Proxy proxy = Socks5Proxy.getSocks5Proxy();
|
||||||
|
if (proxy.isRunning()) {
|
||||||
|
Socks5Proxy.getSocks5Proxy().stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void connectionClosedOnError(Exception e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reconnectionSuccessful() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reconnectingIn(int seconds) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reconnectionFailed(Exception e) {
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,8 +73,8 @@ public class FileTransferTest extends AbstractSmackIntegrationTest {
|
||||||
File source = prepareNewTestFile("source");
|
File source = prepareNewTestFile("source");
|
||||||
final File target = new File(tempDir, "target");
|
final File target = new File(tempDir, "target");
|
||||||
|
|
||||||
JingleFileTransferManager aftm = JingleFileTransferManager.getInstanceFor(conOne);
|
JingleFileTransferManagerAlt aftm = JingleFileTransferManagerAlt.getInstanceFor(conOne);
|
||||||
JingleFileTransferManager bftm = JingleFileTransferManager.getInstanceFor(conTwo);
|
JingleFileTransferManagerAlt bftm = JingleFileTransferManagerAlt.getInstanceFor(conTwo);
|
||||||
|
|
||||||
bftm.addJingleFileTransferOfferListener(new JingleFileTransferOfferListener() {
|
bftm.addJingleFileTransferOfferListener(new JingleFileTransferOfferListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue