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

Merge branch '4.4'

This commit is contained in:
Florian Schmaus 2020-09-23 21:42:51 +02:00
commit 5782fff2a4
38 changed files with 426 additions and 227 deletions

View file

@ -29,14 +29,19 @@ import org.jivesoftware.smack.util.stringencoder.Base64;
*/
public class BoBData {
private final int maxAge;
private final Integer maxAge;
private final String type;
private byte[] contentBinary;
private String contentString;
private BoBData(String type, Integer maxAge) {
this.type = type;
this.maxAge = maxAge;
}
public BoBData(String type, byte[] content) {
this(type, content, -1);
this(type, content, null);
}
/**
@ -46,20 +51,18 @@ public class BoBData {
* @param content TODO javadoc me please
* @param maxAge TODO javadoc me please
*/
public BoBData(String type, byte[] content, int maxAge) {
this.type = type;
public BoBData(String type, byte[] content, Integer maxAge) {
this(type, maxAge);
this.contentBinary = content;
this.maxAge = maxAge;
}
public BoBData(String type, String content) {
this(type, content, -1);
this(type, content, null);
}
public BoBData(String type, String content, int maxAge) {
this.type = type;
public BoBData(String type, String content, Integer maxAge) {
this(type, maxAge);
this.contentString = content;
this.maxAge = maxAge;
}
/**
@ -67,7 +70,7 @@ public class BoBData {
*
* @return the max age
*/
public int getMaxAge() {
public Integer getMaxAge() {
return maxAge;
}

View file

@ -20,15 +20,15 @@ import java.util.Set;
public class BoBInfo {
private final Set<BoBHash> hashes;
private final Set<ContentId> hashes;
private final BoBData data;
BoBInfo(Set<BoBHash> hashes, BoBData data) {
BoBInfo(Set<ContentId> hashes, BoBData data) {
this.hashes = hashes;
this.data = data;
}
public Set<BoBHash> getHashes() {
public Set<ContentId> getHashes() {
return hashes;
}

View file

@ -1,6 +1,6 @@
/**
*
* Copyright 2016-2017 Fernando Ramirez, Florian Schmaus
* Copyright 2016-2020 Fernando Ramirez, Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -81,9 +81,9 @@ public final class BoBManager extends Manager {
return bobManager;
}
private static final LruCache<BoBHash, BoBData> BOB_CACHE = new LruCache<>(128);
private static final LruCache<ContentId, BoBData> BOB_CACHE = new LruCache<>(128);
private final Map<BoBHash, BoBInfo> bobs = new ConcurrentHashMap<>();
private final Map<ContentId, BoBInfo> bobs = new ConcurrentHashMap<>();
private BoBManager(XMPPConnection connection) {
super(connection);
@ -95,15 +95,16 @@ public final class BoBManager extends Manager {
@Override
public IQ handleIQRequest(IQ iqRequest) {
BoBIQ bobIQRequest = (BoBIQ) iqRequest;
ContentId contentId = bobIQRequest.getContentId();
BoBInfo bobInfo = bobs.get(bobIQRequest.getBoBHash());
BoBInfo bobInfo = bobs.get(contentId);
if (bobInfo == null) {
// TODO return item-not-found
return null;
}
BoBData bobData = bobInfo.getData();
BoBIQ responseBoBIQ = new BoBIQ(bobIQRequest.getBoBHash(), bobData);
BoBIQ responseBoBIQ = new BoBIQ(contentId, bobData);
responseBoBIQ.setType(Type.result);
responseBoBIQ.setTo(bobIQRequest.getFrom());
return responseBoBIQ;
@ -137,7 +138,7 @@ public final class BoBManager extends Manager {
* @throws NotConnectedException if the XMPP connection is not connected.
* @throws InterruptedException if the calling thread was interrupted.
*/
public BoBData requestBoB(Jid to, BoBHash bobHash) throws NotLoggedInException, NoResponseException,
public BoBData requestBoB(Jid to, ContentId bobHash) throws NotLoggedInException, NoResponseException,
XMPPErrorException, NotConnectedException, InterruptedException {
BoBData bobData = BOB_CACHE.lookup(bobHash);
if (bobData != null) {
@ -159,9 +160,9 @@ public final class BoBManager extends Manager {
public BoBInfo addBoB(BoBData bobData) {
// We only support SHA-1 for now.
BoBHash bobHash = new BoBHash(SHA1.hex(bobData.getContent()), "sha1");
ContentId bobHash = new ContentId(SHA1.hex(bobData.getContent()), "sha1");
Set<BoBHash> bobHashes = Collections.singleton(bobHash);
Set<ContentId> bobHashes = Collections.singleton(bobHash);
bobHashes = Collections.unmodifiableSet(bobHashes);
BoBInfo bobInfo = new BoBInfo(bobHashes, bobData);
@ -171,12 +172,12 @@ public final class BoBManager extends Manager {
return bobInfo;
}
public BoBInfo removeBoB(BoBHash bobHash) {
public BoBInfo removeBoB(ContentId bobHash) {
BoBInfo bobInfo = bobs.remove(bobHash);
if (bobInfo == null) {
return null;
}
for (BoBHash otherBobHash : bobInfo.getHashes()) {
for (ContentId otherBobHash : bobInfo.getHashes()) {
bobs.remove(otherBobHash);
}
return bobInfo;

View file

@ -19,29 +19,32 @@ package org.jivesoftware.smackx.bob;
import org.jivesoftware.smack.util.StringUtils;
/**
* Bits of Binary hash class.
* Content-ID class.
*
* @author Fernando Ramirez
* @author Florian Schmaus
* @see <a href="http://xmpp.org/extensions/xep-0231.html">XEP-0231: Bits of
* Binary</a>
* @see <a href="https://tools.ietf.org/html/rfc2392">RFC 2392: Content-ID and Message-ID Uniform Resource Locators</a>
*/
public class BoBHash {
public class ContentId {
private final String hash;
private final String hashType;
private final String cid;
private ContentId(String hash, String hashType, String cid) {
this.hash = StringUtils.requireNotNullNorEmpty(hash, "hash must not be null nor empty");
this.hashType = StringUtils.requireNotNullNorEmpty(hashType, "hashType must not be null nor empty");
this.cid = cid;
}
/**
* BoB hash constructor.
*
* @param hash TODO javadoc me please
* @param hashType TODO javadoc me please
*/
public BoBHash(String hash, String hashType) {
this.hash = StringUtils.requireNotNullNorEmpty(hash, "hash must not be null nor empty");
this.hashType = StringUtils.requireNotNullNorEmpty(hashType, "hashType must not be null nor empty");
this.cid = this.hashType + '+' + this.hash + "@bob.xmpp.org";
public ContentId(String hash, String hashType) {
this(hash, hashType, hashType + '+' + hash + "@bob.xmpp.org");
}
/**
@ -82,8 +85,8 @@ public class BoBHash {
@Override
public boolean equals(Object other) {
if (other instanceof BoBHash) {
BoBHash otherBob = (BoBHash) other;
if (other instanceof ContentId) {
ContentId otherBob = (ContentId) other;
return cid.equals(otherBob.cid);
}
return false;
@ -100,10 +103,10 @@ public class BoBHash {
* @param src TODO javadoc me please
* @return the BoB hash
*/
public static BoBHash fromSrc(String src) {
public static ContentId fromSrc(String src) {
String hashType = src.substring(src.lastIndexOf("cid:") + 4, src.indexOf("+"));
String hash = src.substring(src.indexOf("+") + 1, src.indexOf("@bob.xmpp.org"));
return new BoBHash(hash, hashType);
return new ContentId(hash, hashType);
}
/**
@ -112,10 +115,10 @@ public class BoBHash {
* @param cid TODO javadoc me please
* @return the BoB hash
*/
public static BoBHash fromCid(String cid) {
public static ContentId fromCid(String cid) {
String hashType = cid.substring(0, cid.indexOf("+"));
String hash = cid.substring(cid.indexOf("+") + 1, cid.indexOf("@bob.xmpp.org"));
return new BoBHash(hash, hashType);
return new ContentId(hash, hashType, cid);
}
}

View file

@ -0,0 +1,81 @@
/**
*
* Copyright 2020 Florian Schmaus
*
* 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.bob.element;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.util.Objects;
import org.jivesoftware.smack.util.XmlStringBuilder;
import org.jivesoftware.smackx.bob.BoBData;
import org.jivesoftware.smackx.bob.BoBManager;
import org.jivesoftware.smackx.bob.ContentId;
/**
* Bits of Binary data extension element.
*
* @author Florian Schmaus
* @see <a href="http://xmpp.org/extensions/xep-0231.html">XEP-0231: Bits of
* Binary</a>
*/
public class BoBDataExtension implements ExtensionElement {
public static final String ELEMENT = "data";
public static final String NAMESPACE = BoBManager.NAMESPACE;
private final ContentId cid;
private final BoBData bobData;
/**
* Bits of Binary data extension constructor.
*
* @param cid TODO javadoc me please
* @param bobData TODO javadoc me please
*/
public BoBDataExtension(ContentId cid, BoBData bobData) {
this.cid = Objects.requireNonNull(cid);
this.bobData = Objects.requireNonNull(bobData);
}
@Override
public String getElementName() {
return ELEMENT;
}
@Override
public String getNamespace() {
return NAMESPACE;
}
@Override
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
XmlStringBuilder xml = new XmlStringBuilder(this);
xml.attribute("cid", cid.getCid());
xml.attribute("type", bobData.getType());
xml.optAttribute("max-age", bobData.getMaxAge());
xml.rightAngleBracket();
xml.append(bobData.getContentBase64Encoded());
xml.closeElement(this);
return xml;
}
public static BoBDataExtension from(Message message) {
return message.getExtension(BoBDataExtension.class);
}
}

View file

@ -1,97 +0,0 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.bob.element;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.util.XmlStringBuilder;
import org.jivesoftware.smackx.bob.BoBHash;
import org.jivesoftware.smackx.xhtmlim.XHTMLText;
import org.jivesoftware.smackx.xhtmlim.packet.XHTMLExtension;
/**
* Bits of Binary extension element.
*
* @author Fernando Ramirez
* @see <a href="http://xmpp.org/extensions/xep-0231.html">XEP-0231: Bits of
* Binary</a>
*/
public class BoBExtension extends XHTMLExtension {
private final BoBHash bobHash;
private final String alt;
private final String paragraph;
/**
* Bits of Binary extension constructor.
*
* @param bobHash TODO javadoc me please
* @param alt TODO javadoc me please
* @param paragraph TODO javadoc me please
*/
public BoBExtension(BoBHash bobHash, String alt, String paragraph) {
this.bobHash = bobHash;
this.alt = alt;
this.paragraph = paragraph;
}
/**
* Get the BoB hash.
*
* @return the BoB hash
*/
public BoBHash getBoBHash() {
return bobHash;
}
/**
* Get the alt field.
*
* @return the alt field
*/
public String getAlt() {
return alt;
}
@Override
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
XmlStringBuilder xml = new XmlStringBuilder(this);
xml.rightAngleBracket();
xml.halfOpenElement(Message.BODY);
xml.xmlnsAttribute(XHTMLText.NAMESPACE);
xml.rightAngleBracket();
xml.openElement(XHTMLText.P);
xml.optEscape(paragraph);
xml.halfOpenElement(XHTMLText.IMG);
xml.optAttribute("alt", alt);
xml.attribute("src", bobHash.toSrc());
xml.closeEmptyElement();
xml.closeElement(XHTMLText.P);
xml.closeElement(Message.BODY);
xml.closeElement(this);
return xml;
}
public static BoBExtension from(Message message) {
return (BoBExtension) message.getExtensionElement(ELEMENT, NAMESPACE);
}
}

View file

@ -1,6 +1,6 @@
/**
*
* Copyright 2016 Fernando Ramirez
* Copyright 2016 Fernando Ramirez, 2020 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -19,8 +19,8 @@ package org.jivesoftware.smackx.bob.element;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.bob.BoBData;
import org.jivesoftware.smackx.bob.BoBHash;
import org.jivesoftware.smackx.bob.BoBManager;
import org.jivesoftware.smackx.bob.ContentId;
/**
* Bits of Binary IQ class.
@ -41,28 +41,40 @@ public class BoBIQ extends IQ {
*/
public static final String NAMESPACE = BoBManager.NAMESPACE;
private final BoBHash bobHash;
private final ContentId cid;
private final BoBData bobData;
/**
* Bits of Binary IQ constructor.
*
* @param bobHash TODO javadoc me please
* @param cid TODO javadoc me please
* @param bobData TODO javadoc me please
*/
public BoBIQ(BoBHash bobHash, BoBData bobData) {
public BoBIQ(ContentId cid, BoBData bobData) {
super(ELEMENT, NAMESPACE);
this.bobHash = bobHash;
this.cid = cid;
this.bobData = bobData;
}
/**
* Bits of Binary IQ constructor.
*
* @param bobHash TODO javadoc me please
* @param cid TODO javadoc me please
*/
public BoBIQ(BoBHash bobHash) {
this(bobHash, null);
public BoBIQ(ContentId cid) {
this(cid, null);
}
/**
* Get the BoB hash.
*
* @return the BoB hash
* @deprecated use {@link #getContentId()} instead.
*/
// TODO: Remove in Smack 4.5.
@Deprecated
public ContentId getBoBHash() {
return cid;
}
/**
@ -70,8 +82,8 @@ public class BoBIQ extends IQ {
*
* @return the BoB hash
*/
public BoBHash getBoBHash() {
return bobHash;
public ContentId getContentId() {
return cid;
}
/**
@ -85,7 +97,7 @@ public class BoBIQ extends IQ {
@Override
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
xml.attribute("cid", bobHash.getCid());
xml.attribute("cid", cid.getCid());
if (bobData != null) {
xml.optIntAttribute("max_age", bobData.getMaxAge());

View file

@ -0,0 +1,41 @@
/**
*
* Copyright 2020 Florian Schmaus
*
* 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.bob.provider;
import java.io.IOException;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smack.util.Pair;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
import org.jivesoftware.smackx.bob.BoBData;
import org.jivesoftware.smackx.bob.ContentId;
import org.jivesoftware.smackx.bob.element.BoBDataExtension;
public class BoBDataExtensionProvider extends ExtensionElementProvider<BoBDataExtension> {
@Override
public BoBDataExtension parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment)
throws XmlPullParserException, IOException {
Pair<ContentId, BoBData> parserResult = BoBProviderUtil.parseContentIdAndBobData(parser, initialDepth,
xmlEnvironment);
return new BoBDataExtension(parserResult.getFirst(), parserResult.getSecond());
}
}

View file

@ -20,12 +20,12 @@ import java.io.IOException;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smack.util.ParserUtils;
import org.jivesoftware.smack.util.Pair;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
import org.jivesoftware.smackx.bob.BoBData;
import org.jivesoftware.smackx.bob.BoBHash;
import org.jivesoftware.smackx.bob.ContentId;
import org.jivesoftware.smackx.bob.element.BoBIQ;
/**
@ -39,22 +39,10 @@ public class BoBIQProvider extends IQProvider<BoBIQ> {
@Override
public BoBIQ parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException {
String cid = parser.getAttributeValue("", "cid");
BoBHash bobHash = BoBHash.fromCid(cid);
Pair<ContentId, BoBData> parserResult = BoBProviderUtil.parseContentIdAndBobData(parser, initialDepth,
xmlEnvironment);
String dataType = parser.getAttributeValue("", "type");
int maxAge = ParserUtils.getIntegerAttribute(parser, "max-age", -1);
String base64EncodedData = parser.nextText();
BoBData bobData;
if (dataType != null) {
bobData = new BoBData(dataType, base64EncodedData, maxAge);
} else {
bobData = null;
}
return new BoBIQ(bobHash, bobData);
return new BoBIQ(parserResult.getFirst(), parserResult.getSecond());
}
}

View file

@ -0,0 +1,48 @@
/**
*
* Copyright 2020 Florian Schmaus
*
* 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.bob.provider;
import java.io.IOException;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.util.Pair;
import org.jivesoftware.smack.util.ParserUtils;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
import org.jivesoftware.smackx.bob.BoBData;
import org.jivesoftware.smackx.bob.ContentId;
public class BoBProviderUtil {
public static Pair<ContentId, BoBData> parseContentIdAndBobData(XmlPullParser parser, int initialDepth,
XmlEnvironment xmlEnvironment) throws IOException, XmlPullParserException {
String cid = parser.getAttributeValue("", "cid");
ContentId contentId = ContentId.fromCid(cid);
String dataType = parser.getAttributeValue("", "type");
Integer maxAge = ParserUtils.getIntegerAttribute(parser, "max-age");
String base64EncodedData = parser.nextText();
BoBData bobData = null;
if (dataType != null) {
bobData = new BoBData(dataType, base64EncodedData, maxAge);
}
return Pair.create(contentId, bobData);
}
}

View file

@ -1,6 +1,6 @@
/**
*
* Copyright 2013-2014 Georg Lukas
* Copyright 2013-2014 Georg Lukas, 2020 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -25,6 +25,7 @@ import javax.xml.namespace.QName;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.util.Objects;
import org.jivesoftware.smack.util.XmlStringBuilder;
import org.jivesoftware.smackx.delay.packet.DelayInformation;
@ -35,23 +36,24 @@ import org.jivesoftware.smackx.delay.packet.DelayInformation;
* @author Georg Lukas
* @see <a href="http://xmpp.org/extensions/xep-0297.html">XEP-0297: Stanza Forwarding</a>
*/
public class Forwarded implements ExtensionElement {
public class Forwarded<S extends Stanza> implements ExtensionElement {
public static final String NAMESPACE = "urn:xmpp:forward:0";
public static final String ELEMENT = "forwarded";
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
private final DelayInformation delay;
private final Stanza forwardedPacket;
private final S forwardedStanza;
/**
* Creates a new Forwarded stanza extension.
*
* @param delay an optional {@link DelayInformation} timestamp of the packet.
* @param fwdPacket the stanza that is forwarded (required).
* @param forwardedStanza the stanza that is forwarded (required).
* @deprecated use {@link #Forwarded(Stanza, DelayInformation)} instead.
*/
public Forwarded(DelayInformation delay, Stanza fwdPacket) {
this.delay = delay;
this.forwardedPacket = fwdPacket;
@Deprecated
public Forwarded(DelayInformation delay, S forwardedStanza) {
this(forwardedStanza, delay);
}
/**
@ -59,8 +61,19 @@ public class Forwarded implements ExtensionElement {
*
* @param fwdPacket the stanza that is forwarded (required).
*/
public Forwarded(Stanza fwdPacket) {
this(null, fwdPacket);
public Forwarded(S fwdPacket) {
this(fwdPacket, null);
}
/**
* Creates a new Forwarded stanza extension.
*
* @param forwardedStanza the stanza that is forwarded (required).
* @param delay an optional {@link DelayInformation} timestamp of the packet.
*/
public Forwarded(S forwardedStanza, DelayInformation delay) {
this.forwardedStanza = Objects.requireNonNull(forwardedStanza);
this.delay = delay;
}
@Override
@ -78,7 +91,7 @@ public class Forwarded implements ExtensionElement {
XmlStringBuilder xml = new XmlStringBuilder(this, enclosingNamespace);
xml.rightAngleBracket();
xml.optElement(getDelayInformation());
xml.append(forwardedPacket);
xml.append(forwardedStanza);
xml.closeElement(this);
return xml;
}
@ -88,8 +101,8 @@ public class Forwarded implements ExtensionElement {
*
* @return the {@link Stanza} (typically a message) that was forwarded.
*/
public Stanza getForwardedStanza() {
return forwardedPacket;
public S getForwardedStanza() {
return forwardedStanza;
}
/**
@ -101,12 +114,23 @@ public class Forwarded implements ExtensionElement {
return delay;
}
/**
* Check if this is forwarding a stanza of the provided class.
*
* @param stanzaClass the class to check for.
* @return <code>true</code> if this is forwarding a stanza of the provided class.
* @since 4.4
*/
public boolean isForwarded(Class<? extends Stanza> stanzaClass) {
return stanzaClass.isAssignableFrom(forwardedStanza.getClass());
}
/**
* Get the forwarded extension.
* @param packet TODO javadoc me please
* @return the Forwarded extension or null
*/
public static Forwarded from(Stanza packet) {
public static Forwarded<?> from(Stanza packet) {
return packet.getExtension(Forwarded.class);
}
@ -118,10 +142,10 @@ public class Forwarded implements ExtensionElement {
* @return a list a the extracted messages.
* @since 4.3.0
*/
public static List<Message> extractMessagesFrom(Collection<Forwarded> forwardedCollection) {
public static List<Message> extractMessagesFrom(Collection<Forwarded<Message>> forwardedCollection) {
List<Message> res = new ArrayList<>(forwardedCollection.size());
for (Forwarded forwarded : forwardedCollection) {
Message message = (Message) forwarded.forwardedPacket;
for (Forwarded<Message> forwarded : forwardedCollection) {
Message message = forwarded.getForwardedStanza();
res.add(message);
}
return res;

View file

@ -1,6 +1,6 @@
/**
*
* Copyright 2013-2014 Georg Lukas
* Copyright 2013-2014 Georg Lukas, 2020 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -38,14 +38,14 @@ import org.jivesoftware.smackx.forward.packet.Forwarded;
*
* @author Georg Lukas
*/
public class ForwardedProvider extends ExtensionElementProvider<Forwarded> {
public class ForwardedProvider extends ExtensionElementProvider<Forwarded<?>> {
public static final ForwardedProvider INSTANCE = new ForwardedProvider();
private static final Logger LOGGER = Logger.getLogger(ForwardedProvider.class.getName());
@Override
public Forwarded parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
public Forwarded<?> parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
DelayInformation di = null;
Stanza packet = null;
@ -86,6 +86,21 @@ public class ForwardedProvider extends ExtensionElementProvider<Forwarded> {
// TODO: Should be SmackParseException.
throw new IOException("forwarded extension must contain a packet");
}
return new Forwarded(di, packet);
return new Forwarded<>(packet, di);
}
public static Forwarded<Message> parseForwardedMessage(XmlPullParser parser, XmlEnvironment xmlEnvironment)
throws XmlPullParserException, IOException, SmackParsingException {
return parseForwardedMessage(parser, parser.getDepth(), xmlEnvironment);
}
@SuppressWarnings("unchecked")
public static Forwarded<Message> parseForwardedMessage(XmlPullParser parser, int initialDepth,
XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
Forwarded<?> forwarded = INSTANCE.parse(parser, initialDepth, xmlEnvironment);
if (!forwarded.isForwarded(Message.class)) {
throw new SmackParsingException("Expecting a forwarded message, but got " + forwarded);
}
return (Forwarded<Message>) forwarded;
}
}

View file

@ -37,7 +37,7 @@ import org.jivesoftware.smack.util.XmlStringBuilder;
*
* @author Gaston Dombiak
*/
public class XHTMLExtension implements ExtensionElement {
public final class XHTMLExtension implements ExtensionElement {
public static final String ELEMENT = "html";
public static final String NAMESPACE = "http://jabber.org/protocol/xhtml-im";

View file

@ -500,6 +500,12 @@
</extensionProvider>
<!-- XEP-0231: Bits of Binary -->
<extensionProvider>
<elementName>data</elementName>
<namespace>urn:xmpp:bob</namespace>
<className>org.jivesoftware.smackx.bob.provider.BoBDataExtensionProvider</className>
</extensionProvider>
<iqProvider>
<elementName>data</elementName>
<namespace>urn:xmpp:bob</namespace>

View file

@ -41,7 +41,7 @@ public class BoBIQTest extends SmackTestSuite {
@Test
public void checkBoBIQRequest() throws Exception {
BoBHash bobHash = new BoBHash("8f35fef110ffc5df08d579a50083ff9308fb6242", "sha1");
ContentId bobHash = new ContentId("8f35fef110ffc5df08d579a50083ff9308fb6242", "sha1");
BoBIQ createdBoBIQ = new BoBIQ(bobHash);
createdBoBIQ.setStanzaId("sarasa");
@ -55,7 +55,7 @@ public class BoBIQTest extends SmackTestSuite {
public void checkBoBIQResponse() throws Exception {
BoBIQ bobIQ = PacketParserUtils.parseStanza(sampleBoBIQResponse);
BoBHash bobHash = new BoBHash("8f35fef110ffc5df08d579a50083ff9308fb6242", "sha1");
ContentId bobHash = new ContentId("8f35fef110ffc5df08d579a50083ff9308fb6242", "sha1");
BoBData bobData = new BoBData("image/png", "sarasade2354j2".getBytes(StandardCharsets.UTF_8), 86400);
BoBIQ createdBoBIQ = new BoBIQ(bobHash, bobData);
@ -63,8 +63,8 @@ public class BoBIQTest extends SmackTestSuite {
createdBoBIQ.setTo(JidCreate.from("doctor@shakespeare.lit/pda"));
createdBoBIQ.setType(Type.result);
assertEquals(bobIQ.getBoBHash().getHash(), createdBoBIQ.getBoBHash().getHash());
assertEquals(bobIQ.getBoBHash().getHashType(), createdBoBIQ.getBoBHash().getHashType());
assertEquals(bobIQ.getContentId().getHash(), createdBoBIQ.getContentId().getHash());
assertEquals(bobIQ.getContentId().getHashType(), createdBoBIQ.getContentId().getHashType());
assertEquals(bobIQ.getBoBData().getMaxAge(), createdBoBIQ.getBoBData().getMaxAge());
assertEquals(bobIQ.getBoBData().getType(), createdBoBIQ.getBoBData().getType());
assertEquals(bobIQ.getBoBData().getContentBase64Encoded(), createdBoBIQ.getBoBData().getContentBase64Encoded());

View file

@ -45,7 +45,7 @@ public class ForwardedTest {
public void forwardedTest() throws Exception {
XmlPullParser parser;
String control;
Forwarded fwd;
Forwarded<?> fwd;
control = XMLBuilder.create("forwarded")
.a("xmlns", "urn:xmpp:forwarded:0")
@ -71,7 +71,7 @@ public class ForwardedTest {
public void forwardedWithDelayTest() throws Exception {
XmlPullParser parser;
String control;
Forwarded fwd;
Forwarded<?> fwd;
// @formatter:off
control = XMLBuilder.create("forwarded").a("xmlns", "urn:xmpp:forwarded:0")