1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-12-08 20:11:08 +01:00

Merge branch '4.2' into master-paul-merged

This commit is contained in:
Florian Schmaus 2017-12-17 11:16:02 +01:00
commit 431e5b3c67
434 changed files with 1770 additions and 1517 deletions

View file

@ -123,7 +123,7 @@ public class CarbonExtension implements ExtensionElement {
/**
* Defines the direction of a {@link CarbonExtension} message.
*/
public static enum Direction {
public enum Direction {
received,
sent
}

View file

@ -48,7 +48,7 @@ public class ExplicitMessageEncryptionElement implements ExtensionElement {
private final String namespace;
private final String name;
private ExplicitMessageEncryptionProtocol(String namespace, String name) {
ExplicitMessageEncryptionProtocol(String namespace, String name) {
this.namespace = namespace;
this.name = name;
PROTOCOL_LUT.put(namespace, this);

View file

@ -90,7 +90,7 @@ public abstract class AbstractHttpOverXmpp extends IQ {
/**
* A builder for XMPP connection configurations.
* <p>
* See ConnectionConfiguration Buidler for more details.
* See ConnectionConfiguration Builder for more details.
* </p>
*
* @param <B> the builder type parameter.

View file

@ -64,7 +64,18 @@ import org.jxmpp.jid.DomainBareJid;
*/
public final class HttpFileUploadManager extends Manager {
/**
* Namespace of XEP-0363 v0.4 or higher. Constant value {@value #NAMESPACE}.
*
* @see <a href="https://xmpp.org/extensions/attic/xep-0363-0.4.0.html">XEP-0363 v0.4.0</a>
*/
public static final String NAMESPACE = "urn:xmpp:http:upload:0";
/**
* Namespace of XEP-0363 v0.2 or lower. Constant value {@value #NAMESPACE_0_2}.
*
* @see <a href="https://xmpp.org/extensions/attic/xep-0363-0.2.5.html">XEP-0363 v0.2.5</a>
*/
public static final String NAMESPACE_0_2 = "urn:xmpp:http:upload";
private static final Logger LOGGER = Logger.getLogger(HttpFileUploadManager.class.getName());
@ -459,6 +470,22 @@ public final class HttpFileUploadManager extends Manager {
}
}
public static UploadService.Version namespaceToVersion(String namespace) {
UploadService.Version version;
switch (namespace) {
case NAMESPACE:
version = Version.v0_3;
break;
case NAMESPACE_0_2:
version = Version.v0_2;
break;
default:
version = null;
break;
}
return version;
}
private static boolean containsHttpFileUploadNamespace(DiscoverInfo discoverInfo) {
return discoverInfo.containsFeature(NAMESPACE) || discoverInfo.containsFeature(NAMESPACE_0_2);
}

View file

@ -22,8 +22,19 @@ import org.jxmpp.jid.DomainBareJid;
public class UploadService {
enum Version {
public enum Version {
/**
* Upload service as specified in XEP-0363 v0.2 or lower.
*
* @see <a href="https://xmpp.org/extensions/attic/xep-0363-0.2.5.html">XEP-0363 v0.2.5</a>
*/
v0_2,
/**
* Upload service as specified in XEP-0363 v0.3 or higher.
*
* @see <a href="https://xmpp.org/extensions/attic/xep-0363-0.4.0.html">XEP-0363 v0.4.0</a>
*/
v0_3,
}

View file

@ -33,8 +33,9 @@ public class Slot extends IQ {
public static final String ELEMENT = "slot";
public static final String NAMESPACE = SlotRequest.NAMESPACE;
private final URL putUrl;
private final URL getUrl;
protected final URL putUrl;
protected final URL getUrl;
private final Map<String, String> headers;
public Slot(URL putUrl, URL getUrl) {
@ -73,12 +74,21 @@ public class Slot extends IQ {
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
xml.rightAngleBracket();
xml.element("put", putUrl.toString());
xml.element("get", getUrl.toString());
for (Map.Entry<String, String> entry : getHeaders().entrySet()) {
xml.openElement("header").attribute(entry.getKey(), entry.getValue());
xml.halfOpenElement("put").attribute("url", putUrl.toString());
if (headers.isEmpty()) {
xml.closeEmptyElement();
} else {
xml.rightAngleBracket();
for (Map.Entry<String, String> entry : getHeaders().entrySet()) {
xml.halfOpenElement("header").attribute("name", entry.getKey()).rightAngleBracket();
xml.escape(entry.getValue());
xml.closeElement("header");
}
xml.closeElement("put");
}
xml.halfOpenElement("get").attribute("url", getUrl.toString()).closeEmptyElement();
return xml;
}
}

View file

@ -28,4 +28,13 @@ public class Slot_V0_2 extends Slot {
super(putUrl, getUrl, null, NAMESPACE);
}
@Override
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
xml.rightAngleBracket();
xml.element("put", putUrl.toString());
xml.element("get", getUrl.toString());
return xml;
}
}

View file

@ -1,6 +1,6 @@
/**
*
* Copyright © 2017 Grigory Fedorov
* Copyright © 2017 Grigory Fedorov, 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,8 @@ import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smack.util.ParserUtils;
import org.jivesoftware.smackx.httpfileupload.HttpFileUploadManager;
import org.jivesoftware.smackx.httpfileupload.UploadService;
import org.jivesoftware.smackx.httpfileupload.element.Slot;
import org.jivesoftware.smackx.httpfileupload.element.Slot_V0_2;
@ -42,9 +44,13 @@ public class SlotProvider extends IQProvider<Slot> {
@Override
public Slot parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, SmackException {
final String namespace = parser.getNamespace();
final UploadService.Version version = HttpFileUploadManager.namespaceToVersion(namespace);
assert version != null;
URL putUrl = null;
URL getUrl = null;
Map<String, String> headers = null;
PutElement_V0_4_Content putElementV04Content = null;
outerloop: while (true) {
int event = parser.next();
@ -53,19 +59,33 @@ public class SlotProvider extends IQProvider<Slot> {
case XmlPullParser.START_TAG:
String name = parser.getName();
switch (name) {
case "put":
putUrl = new URL(parser.nextText());
break;
case "get":
getUrl = new URL(parser.nextText());
break;
case "header":
String headerName = ParserUtils.getRequiredAttribute(parser, "name");
String headerValue = ParserUtils.getRequiredNextText(parser);
if (headers == null) {
headers = new HashMap<>();
case "put": {
switch (version) {
case v0_2:
String putUrlString = parser.nextText();
putUrl = new URL(putUrlString);
break;
case v0_3:
putElementV04Content = parsePutElement_V0_4(parser);
break;
default:
throw new AssertionError();
}
headers.put(headerName, headerValue);
break;
}
case "get":
String getUrlString;
switch (version) {
case v0_2:
getUrlString = parser.nextText();
break;
case v0_3:
getUrlString = parser.getAttributeValue(null, "url");
break;
default:
throw new AssertionError();
}
getUrl = new URL(getUrlString);
break;
}
break;
@ -77,13 +97,67 @@ public class SlotProvider extends IQProvider<Slot> {
}
}
switch (namespace) {
case Slot.NAMESPACE:
return new Slot(putUrl, getUrl, headers);
case Slot_V0_2.NAMESPACE:
switch (version) {
case v0_3:
return new Slot(putElementV04Content.putUrl, getUrl, putElementV04Content.headers);
case v0_2:
return new Slot_V0_2(putUrl, getUrl);
default:
throw new AssertionError();
}
}
public static PutElement_V0_4_Content parsePutElement_V0_4(XmlPullParser parser) throws XmlPullParserException, IOException {
final int initialDepth = parser.getDepth();
String putUrlString = parser.getAttributeValue(null, "url");
URL putUrl = new URL(putUrlString);
Map<String, String> headers = null;
outerloop: while (true) {
int next = parser.next();
switch (next) {
case XmlPullParser.START_TAG:
String name = parser.getName();
switch (name) {
case "header":
String headerName = ParserUtils.getRequiredAttribute(parser, "name");
String headerValue = ParserUtils.getRequiredNextText(parser);
if (headers == null) {
headers = new HashMap<>();
}
headers.put(headerName, headerValue);
break;
default:
break;
}
break;
case XmlPullParser.END_TAG:
if (parser.getDepth() == initialDepth) {
break outerloop;
}
break;
}
}
return new PutElement_V0_4_Content(putUrl, headers);
}
public static final class PutElement_V0_4_Content {
private final URL putUrl;
private final Map<String, String> headers;
private PutElement_V0_4_Content(URL putUrl, Map<String, String> headers) {
this.putUrl = putUrl;
this.headers = headers;
}
public URL getPutUrl() {
return putUrl;
}
public Map<String, String> getHeaders() {
return headers;
}
}
}

View file

@ -26,6 +26,6 @@ import org.jxmpp.jid.Jid;
public interface ThingControlRequest {
public void processRequest(Jid from, Collection<SetData> setData) throws XMPPErrorException;
void processRequest(Jid from, Collection<SetData> setData) throws XMPPErrorException;
}

View file

@ -29,7 +29,7 @@ public class IoTSetResponse extends IQ {
public IoTSetResponse(IoTSetRequest iotSetRequest) {
this();
initialzeAsResultFor(iotSetRequest);
initializeAsResultFor(iotSetRequest);
}
@Override

View file

@ -32,7 +32,7 @@ public abstract class SetData implements NamedElement {
private final String toStringCache;
private Type() {
Type() {
toStringCache = this.name().toLowerCase(Locale.US);
}

View file

@ -18,6 +18,6 @@ package org.jivesoftware.smackx.iot.data;
public interface ThingMomentaryReadOutRequest {
public void momentaryReadOutRequest(ThingMomentaryReadOutResult callback);
void momentaryReadOutRequest(ThingMomentaryReadOutResult callback);
}

View file

@ -22,6 +22,6 @@ import org.jivesoftware.smackx.iot.data.element.IoTDataField;
public interface ThingMomentaryReadOutResult {
public void momentaryReadOut(List<? extends IoTDataField> results);
void momentaryReadOut(List<? extends IoTDataField> results);
}

View file

@ -24,7 +24,7 @@ public class IoTDataRequest extends IQ {
public static final String NAMESPACE = Constants.IOT_SENSORDATA_NAMESPACE;
/**
* The sequence nummber. According to XEP-0323 an xs:int.
* The sequence number. According to XEP-0323 an xs:int.
*/
private final int seqNr;

View file

@ -20,6 +20,6 @@ import org.jxmpp.jid.BareJid;
public interface ThingStateChangeListener {
public void owned(BareJid owner);
void owned(BareJid owner);
}

View file

@ -25,7 +25,7 @@ public class Tag implements NamedElement {
public enum Type {
str,
num;
num
}
private final String name;

View file

@ -161,8 +161,8 @@ public final class IoTProvisioningManager extends Manager {
// Notify the recommended friend that we will now accept his
// friendship requests.
final XMPPConnection connection = connection();
Friend friendNotifiacation = new Friend(connection.getUser().asBareJid());
Message notificationMessage = new Message(friendJid, friendNotifiacation);
Friend friendNotification = new Friend(connection.getUser().asBareJid());
Message notificationMessage = new Message(friendJid, friendNotification);
connection.sendStanza(notificationMessage);
} else {
// Check is the message was send from a thing we previously
@ -236,7 +236,7 @@ public final class IoTProvisioningManager extends Manager {
}
catch (NoResponseException | XMPPErrorException | NotConnectedException | InterruptedException e) {
LOGGER.log(Level.WARNING,
"Could not determine privisioning server. Ignoring friend request from " + from, e);
"Could not determine provisioning server. Ignoring friend request from " + from, e);
}
if (provisioningServer == null) {
return null;
@ -420,7 +420,7 @@ public final class IoTProvisioningManager extends Manager {
if (!provisioningServer.equals(stanza.getFrom())) {
if (log) {
LOGGER.warning("Ignoring request '" + stanza
+ "' because not from provising server '" + provisioningServer
+ "' because not from provisioning server '" + provisioningServer
+ "'.");
}
return false;

View file

@ -239,11 +239,11 @@ public final class MamManager extends Manager {
/**
* Query an message archive like a MUC archive or a pubsub node archive, addressed by an archiveAddress, applying
* Query an message archive like a MUC archive or a PubSub node archive, addressed by an archiveAddress, applying
* filters: max count, start date, end date, from/to JID and with additional fields. When archiveAddress is null the
* default, the server will be requested.
*
* @param node The Pubsub node name, can be null
* @param node The PubSub node name, can be null
* @param max
* @param start
* @param end
@ -346,7 +346,7 @@ public final class MamManager extends Manager {
/**
* Returns a page of the archive.
*
* @param node The Pubsub node name, can be null
* @param node The PubSub node name, can be null
* @param dataForm
* @param rsmSet
* @return the MAM query result
@ -498,7 +498,7 @@ public final class MamManager extends Manager {
/**
* Get the form fields supported by the server.
*
* @param node The Pubsub node name, can be null
* @param node The PubSub node name, can be null
* @return the list of form fields.
* @throws NoResponseException
* @throws XMPPErrorException
@ -521,7 +521,7 @@ public final class MamManager extends Manager {
private MamQueryResult queryArchive(MamQueryIQ mamQueryIq) throws NoResponseException, XMPPErrorException,
NotConnectedException, InterruptedException, NotLoggedInException {
final XMPPConnection connection = getAuthenticatedConnectionOrThrow();
MamFinIQ mamFinIQ = null;
MamFinIQ mamFinIQ;
StanzaCollector mamFinIQCollector = connection.createStanzaCollector(new IQReplyFilter(mamQueryIq, connection));

View file

@ -82,7 +82,7 @@ public class MultiUserChatLight {
* Same as {@link #fromRoomFilter} together with
* {@link MessageTypeFilter#GROUPCHAT}.
*/
private final StanzaFilter fromRoomGroupchatFilter;
private final StanzaFilter fromRoomGroupChatFilter;
private final StanzaListener messageListener;
@ -93,7 +93,7 @@ public class MultiUserChatLight {
this.room = room;
fromRoomFilter = FromMatchesFilter.create(room);
fromRoomGroupchatFilter = new AndFilter(fromRoomFilter, MessageTypeFilter.GROUPCHAT);
fromRoomGroupChatFilter = new AndFilter(fromRoomFilter, MessageTypeFilter.GROUPCHAT);
messageListener = new StanzaListener() {
@Override
@ -105,7 +105,7 @@ public class MultiUserChatLight {
}
};
connection.addSyncStanzaListener(messageListener, fromRoomGroupchatFilter);
connection.addSyncStanzaListener(messageListener, fromRoomGroupChatFilter);
}
/**
@ -266,7 +266,7 @@ public class MultiUserChatLight {
throws Exception {
MUCLightCreateIQ createMUCLightIQ = new MUCLightCreateIQ(room, roomName, occupants);
messageCollector = connection.createStanzaCollector(fromRoomGroupchatFilter);
messageCollector = connection.createStanzaCollector(fromRoomGroupChatFilter);
try {
connection.createStanzaCollectorAndSend(createMUCLightIQ).nextResultOrThrow();

View file

@ -96,7 +96,7 @@ public final class MultiUserChatLightManager extends Manager {
private MultiUserChatLight createNewMucLightAndAddToMap(EntityBareJid jid) {
MultiUserChatLight multiUserChatLight = new MultiUserChatLight(connection(), jid);
multiUserChatLights.put(jid, new WeakReference<MultiUserChatLight>(multiUserChatLight));
multiUserChatLights.put(jid, new WeakReference<>(multiUserChatLight));
return multiUserChatLight;
}
@ -193,11 +193,11 @@ public final class MultiUserChatLightManager extends Manager {
*/
public List<Jid> getRoomsBlocked(DomainBareJid mucLightService)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCLightBlockingIQ muclIghtBlockingIQResult = getBlockingList(mucLightService);
MUCLightBlockingIQ mucLightBlockingIQResult = getBlockingList(mucLightService);
List<Jid> jids = new ArrayList<>();
if (muclIghtBlockingIQResult.getRooms() != null) {
jids.addAll(muclIghtBlockingIQResult.getRooms().keySet());
if (mucLightBlockingIQResult.getRooms() != null) {
jids.addAll(mucLightBlockingIQResult.getRooms().keySet());
}
return jids;
@ -215,11 +215,11 @@ public final class MultiUserChatLightManager extends Manager {
*/
public List<Jid> getUsersBlocked(DomainBareJid mucLightService)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCLightBlockingIQ muclIghtBlockingIQResult = getBlockingList(mucLightService);
MUCLightBlockingIQ mucLightBlockingIQResult = getBlockingList(mucLightService);
List<Jid> jids = new ArrayList<>();
if (muclIghtBlockingIQResult.getUsers() != null) {
jids.addAll(muclIghtBlockingIQResult.getUsers().keySet());
if (mucLightBlockingIQResult.getUsers() != null) {
jids.addAll(mucLightBlockingIQResult.getUsers().keySet());
}
return jids;
@ -234,9 +234,9 @@ public final class MultiUserChatLightManager extends Manager {
StanzaFilter responseFilter = new IQReplyFilter(mucLightBlockingIQ, connection());
IQ responseIq = connection().createStanzaCollectorAndSend(responseFilter, mucLightBlockingIQ)
.nextResultOrThrow();
MUCLightBlockingIQ muclIghtBlockingIQResult = (MUCLightBlockingIQ) responseIq;
MUCLightBlockingIQ mucLightBlockingIQResult = (MUCLightBlockingIQ) responseIq;
return muclIghtBlockingIQResult;
return mucLightBlockingIQResult;
}
/**

View file

@ -254,7 +254,7 @@
<namespace>urn:xmpp:hints</namespace>
<className>org.jivesoftware.smackx.hints.provider.StoreHintProvider</className>
</extensionProvider>
g
<!-- XEP-0363: HTTP File Upload -->
<iqProvider>
<elementName>slot</elementName>