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

Merge master 4.2.1

This commit is contained in:
vanitasvitae 2017-08-14 22:15:23 +02:00
commit 9ff0333032
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
42 changed files with 357 additions and 256 deletions

View file

@ -159,7 +159,7 @@ public final class BoBManager extends Manager {
public BoBInfo addBoB(BoBData bobData) {
// We only support SHA-1 for now.
BoBHash bobHash = new BoBHash("sha1", SHA1.hex(bobData.getContent()));
BoBHash bobHash = new BoBHash(SHA1.hex(bobData.getContent()), "sha1");
Set<BoBHash> bobHashes = Collections.singleton(bobHash);
bobHashes = Collections.unmodifiableSet(bobHashes);

View file

@ -17,7 +17,6 @@
package org.jivesoftware.smackx.jingle.provider;
import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smackx.jingle.element.JingleContentTransportElement;
import org.xmlpull.v1.XmlPullParser;

View file

@ -17,7 +17,6 @@
package org.jivesoftware.smackx.jingle.provider;
import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smackx.jingle.element.JingleErrorElement;
import org.xmlpull.v1.XmlPullParser;

View file

@ -1011,7 +1011,7 @@ public class MultiUserChat {
*
* @param presenceInterceptor the stanza(/packet) interceptor to remove.
*/
public void removePresenceInterceptor(StanzaListener presenceInterceptor) {
public void removePresenceInterceptor(PresenceListener presenceInterceptor) {
presenceInterceptors.remove(presenceInterceptor);
}

View file

@ -39,6 +39,7 @@ import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.jivesoftware.smackx.pubsub.EventElement;
import org.jivesoftware.smackx.pubsub.Item;
import org.jivesoftware.smackx.pubsub.LeafNode;
import org.jivesoftware.smackx.pubsub.PubSubException.NotAPubSubNodeException;
import org.jivesoftware.smackx.pubsub.PubSubFeature;
import org.jivesoftware.smackx.pubsub.PubSubManager;
import org.jivesoftware.smackx.pubsub.filter.EventExtensionFilter;
@ -137,9 +138,10 @@ public final class PEPManager extends Manager {
* @throws InterruptedException
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotAPubSubNodeException
*/
public void publish(Item item, String node) throws NotConnectedException, InterruptedException,
NoResponseException, XMPPErrorException {
NoResponseException, XMPPErrorException, NotAPubSubNodeException {
XMPPConnection connection = connection();
PubSubManager pubSubManager = PubSubManager.getInstance(connection, connection.getUser().asEntityBareJid());
LeafNode pubSubNode = pubSubManager.getNode(node);

View file

@ -1,45 +0,0 @@
/**
*
* Copyright 2017 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.pubsub;
import org.jxmpp.jid.BareJid;
public abstract class PubSubAssertionError extends AssertionError {
/**
*
*/
private static final long serialVersionUID = 1L;
protected PubSubAssertionError(String message) {
super(message);
}
public static class DiscoInfoNodeAssertionError extends PubSubAssertionError {
/**
*
*/
private static final long serialVersionUID = 1L;
DiscoInfoNodeAssertionError(BareJid pubSubService, String nodeId) {
super("PubSub service '" + pubSubService + "' returned disco info result for node '" + nodeId
+ "', but it did not contain an Identity of type 'leaf' or 'collection' (and category 'pubsub'), which is not allowed according to XEP-60 5.3.");
}
}
}

View file

@ -18,6 +18,8 @@ package org.jivesoftware.smackx.pubsub;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
import org.jxmpp.jid.BareJid;
public abstract class PubSubException extends SmackException {
@ -27,6 +29,16 @@ public abstract class PubSubException extends SmackException {
*/
private static final long serialVersionUID = 1L;
private final String nodeId;
protected PubSubException(String nodeId) {
this.nodeId = nodeId;
}
public String getNodeId() {
return nodeId;
}
public static class NotALeafNodeException extends PubSubException {
/**
@ -34,21 +46,35 @@ public abstract class PubSubException extends SmackException {
*/
private static final long serialVersionUID = 1L;
private final String nodeId;
private final BareJid pubSubService;
NotALeafNodeException(String nodeId, BareJid pubSubService) {
this.nodeId = nodeId;
super(nodeId);
this.pubSubService = pubSubService;
}
public String getNodeId() {
return nodeId;
}
public BareJid getPubSubService() {
return pubSubService;
}
}
public static class NotAPubSubNodeException extends PubSubException {
/**
*
*/
private static final long serialVersionUID = 1L;
private final DiscoverInfo discoverInfo;
NotAPubSubNodeException(String nodeId, DiscoverInfo discoverInfo) {
super(nodeId);
this.discoverInfo = discoverInfo;
}
public DiscoverInfo getDiscoverInfo() {
return discoverInfo;
}
}
}

View file

@ -42,6 +42,7 @@ import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
import org.jivesoftware.smackx.disco.packet.DiscoverItems;
import org.jivesoftware.smackx.pubsub.PubSubException.NotALeafNodeException;
import org.jivesoftware.smackx.pubsub.PubSubException.NotAPubSubNodeException;
import org.jivesoftware.smackx.pubsub.packet.PubSub;
import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace;
import org.jivesoftware.smackx.pubsub.util.NodeUtils;
@ -229,8 +230,9 @@ public final class PubSubManager extends Manager {
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException
* @throws InterruptedException
* @throws NotAPubSubNodeException
*/
public <T extends Node> T getNode(String id) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
public <T extends Node> T getNode(String id) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, NotAPubSubNodeException
{
Node node = nodeMap.get(id);
@ -249,10 +251,7 @@ public final class PubSubManager extends Manager {
node = new CollectionNode(this, id);
}
else {
// XEP-60 5.3 states that
// "The 'disco#info' result MUST include an identity with a category of 'pubsub' and a type of either 'leaf' or 'collection'."
// If this is not the case, then we are dealing with an PubSub implementation that doesn't follow the specification.
throw new PubSubAssertionError.DiscoInfoNodeAssertionError(pubSubService, id);
throw new PubSubException.NotAPubSubNodeException(id, infoReply);
}
nodeMap.put(id, node);
}
@ -278,6 +277,9 @@ public final class PubSubManager extends Manager {
try {
return getNode(id);
}
catch (NotAPubSubNodeException e) {
return createNode(id);
}
catch (XMPPErrorException e1) {
if (e1.getXMPPError().getCondition() == Condition.item_not_found) {
try {
@ -286,7 +288,13 @@ public final class PubSubManager extends Manager {
catch (XMPPErrorException e2) {
if (e2.getXMPPError().getCondition() == Condition.conflict) {
// The node was created in the meantime, re-try getNode(). Note that this case should be rare.
return getNode(id);
try {
return getNode(id);
}
catch (NotAPubSubNodeException e) {
// Should not happen
throw new IllegalStateException(e);
}
}
throw e2;
}
@ -313,10 +321,11 @@ public final class PubSubManager extends Manager {
* @throws NotConnectedException
* @throws InterruptedException
* @throws XMPPErrorException
* @throws NotAPubSubNodeException
* @since 4.2.1
*/
public LeafNode getLeafNode(String id) throws NotALeafNodeException, NoResponseException, NotConnectedException,
InterruptedException, XMPPErrorException {
InterruptedException, XMPPErrorException, NotAPubSubNodeException {
Node node;
try {
node = getNode(id);