mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-22 22:32:06 +01:00
Add support for XEP-335: JSON Containers
and GCM JSON payloads for Google's GCM Cloud Connection Server.
This commit is contained in:
parent
ed66c838e1
commit
e63fe22647
9 changed files with 271 additions and 0 deletions
|
@ -67,6 +67,8 @@ Experimental Smack Extensions and currently supported XEPs by Smack (smack-exper
|
||||||
|---------------------------------------------|----------------------------------------------------------|----------------------------------------------------------------------------------------------------------|
|
|---------------------------------------------|----------------------------------------------------------|----------------------------------------------------------------------------------------------------------|
|
||||||
| Message Carbons | [XEP-0280](http://xmpp.org/extensions/xep-0280.html) | Keep all IM clients for a user engaged in a conversation, by carbon-copy outbound messages to all interested resources.
|
| Message Carbons | [XEP-0280](http://xmpp.org/extensions/xep-0280.html) | Keep all IM clients for a user engaged in a conversation, by carbon-copy outbound messages to all interested resources.
|
||||||
| [HTTP over XMPP transport](hoxt.html) | [XEP-0332](http://xmpp.org/extensions/xep-0332.html) | Allows to transport HTTP communication over XMPP peer-to-peer networks. |
|
| [HTTP over XMPP transport](hoxt.html) | [XEP-0332](http://xmpp.org/extensions/xep-0332.html) | Allows to transport HTTP communication over XMPP peer-to-peer networks. |
|
||||||
|
| JSON Containers | [XEP-0335](http://xmpp.org/extensions/xep-0335.html) | Encapsulation of JSON data within XMPP Stanzas. |
|
||||||
|
| Google GCM JSON payload | n/a | Semantically the same as XEP-0335: JSON Containers |
|
||||||
| Client State Indication | [XEP-0352](http://xmpp.org/extensions/xep-0352.html) | A way for the client to indicate its active/inactive state. |
|
| Client State Indication | [XEP-0352](http://xmpp.org/extensions/xep-0352.html) | A way for the client to indicate its active/inactive state. |
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -125,6 +125,10 @@ public class ProviderFileLoader implements ProviderLoader {
|
||||||
LOGGER.log(Level.SEVERE, "Could not find provider class", cnfe);
|
LOGGER.log(Level.SEVERE, "Could not find provider class", cnfe);
|
||||||
exceptions.add(cnfe);
|
exceptions.add(cnfe);
|
||||||
}
|
}
|
||||||
|
catch (InstantiationException ie) {
|
||||||
|
LOGGER.log(Level.SEVERE, "Could not instanciate " + className, ie);
|
||||||
|
exceptions.add(ie);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException illExc) {
|
catch (IllegalArgumentException illExc) {
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright © 2014 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.gcm.packet;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.packet.Packet;
|
||||||
|
import org.jivesoftware.smackx.json.packet.AbstractJsonPacketExtension;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* XMPP extension elements as used by Google's GCM Cloud Connection Server (XMPP).
|
||||||
|
* <p>
|
||||||
|
* This extension is semantically the same as {@link org.jivesoftware.smackx.json.packet.JsonPacketExtension}, but with
|
||||||
|
* a different element and namespace. It is used to exchange message stanzas with a JSON payload as extension element.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @see <a href="https://developer.android.com/google/gcm/ccs.html">GCM Cloud Connection Server (XMPP)</a>
|
||||||
|
*/
|
||||||
|
public class GcmPacketExtension extends AbstractJsonPacketExtension {
|
||||||
|
|
||||||
|
public static final String ELEMENT = "gcm";
|
||||||
|
public static final String NAMESPACE = "google:mobile:data";
|
||||||
|
|
||||||
|
public GcmPacketExtension(String json) {
|
||||||
|
super(json);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getNamespace() {
|
||||||
|
return NAMESPACE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getElementName() {
|
||||||
|
return ELEMENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the GCM packet extension from the packet.
|
||||||
|
*
|
||||||
|
* @param packet
|
||||||
|
* @return the GCM packet extension or null.
|
||||||
|
*/
|
||||||
|
public static GcmPacketExtension from(Packet packet) {
|
||||||
|
return packet.getExtension(ELEMENT, NAMESPACE);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright © 2014 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.gcm.provider;
|
||||||
|
|
||||||
|
import org.jivesoftware.smackx.gcm.packet.GcmPacketExtension;
|
||||||
|
import org.jivesoftware.smackx.json.packet.AbstractJsonPacketExtension;
|
||||||
|
import org.jivesoftware.smackx.json.provider.AbstractJsonExtensionProvider;
|
||||||
|
|
||||||
|
public class GcmExtensionProvider extends AbstractJsonExtensionProvider {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AbstractJsonPacketExtension from(String json) {
|
||||||
|
return new GcmPacketExtension(json);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright © 2014 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.json.packet;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.packet.PacketExtension;
|
||||||
|
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||||
|
|
||||||
|
public abstract class AbstractJsonPacketExtension implements PacketExtension {
|
||||||
|
|
||||||
|
private final String json;
|
||||||
|
|
||||||
|
protected AbstractJsonPacketExtension(String json) {
|
||||||
|
this.json = json;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final String getJson() {
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final XmlStringBuilder toXML() {
|
||||||
|
XmlStringBuilder xml = new XmlStringBuilder(this);
|
||||||
|
xml.rightAngleBracket();
|
||||||
|
xml.append(json);
|
||||||
|
xml.closeElement(this);
|
||||||
|
return xml;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright © 2014 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.json.packet;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.packet.Packet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* XMPP JSON Containers as defined in XEP-0335
|
||||||
|
*
|
||||||
|
* @see <a href="http://xmpp.org/extensions/xep-0335.html">XEP-0335: JSON Containers</a>
|
||||||
|
*/
|
||||||
|
public class JsonPacketExtension extends AbstractJsonPacketExtension {
|
||||||
|
|
||||||
|
public static final String ELEMENT = "json";
|
||||||
|
public static final String NAMESPACE = "urn:xmpp:json:0";
|
||||||
|
|
||||||
|
public JsonPacketExtension(String json) {
|
||||||
|
super(json);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getNamespace() {
|
||||||
|
return NAMESPACE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getElementName() {
|
||||||
|
return ELEMENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the JSON packet extension from the packet.
|
||||||
|
*
|
||||||
|
* @param packet
|
||||||
|
* @return the JSON packet extension or null.
|
||||||
|
*/
|
||||||
|
public static JsonPacketExtension from(Packet packet) {
|
||||||
|
return packet.getExtension(ELEMENT, NAMESPACE);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright © 2014 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.json.provider;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.SmackException;
|
||||||
|
import org.jivesoftware.smack.provider.PacketExtensionProvider;
|
||||||
|
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||||
|
import org.jivesoftware.smackx.json.packet.AbstractJsonPacketExtension;
|
||||||
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
|
public abstract class AbstractJsonExtensionProvider extends PacketExtensionProvider<AbstractJsonPacketExtension> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AbstractJsonPacketExtension parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException,
|
||||||
|
IOException, SmackException {
|
||||||
|
String json = PacketParserUtils.parseElementText(parser);
|
||||||
|
parser.next();
|
||||||
|
return from(json);
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract AbstractJsonPacketExtension from(String json);
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright © 2014 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.json.provider;
|
||||||
|
|
||||||
|
import org.jivesoftware.smackx.json.packet.AbstractJsonPacketExtension;
|
||||||
|
import org.jivesoftware.smackx.json.packet.JsonPacketExtension;
|
||||||
|
|
||||||
|
public class JsonExtensionProvider extends AbstractJsonExtensionProvider {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AbstractJsonPacketExtension from(String json) {
|
||||||
|
return new JsonPacketExtension(json);
|
||||||
|
}
|
||||||
|
}
|
|
@ -38,4 +38,18 @@
|
||||||
<className>org.jivesoftware.smackx.csi.provider.ClientStateIndicationFeatureProvider</className>
|
<className>org.jivesoftware.smackx.csi.provider.ClientStateIndicationFeatureProvider</className>
|
||||||
</streamFeatureProvider>
|
</streamFeatureProvider>
|
||||||
|
|
||||||
|
<!-- XEP-0335 JSON Containers -->
|
||||||
|
<extensionProvider>
|
||||||
|
<elementName>json</elementName>
|
||||||
|
<namespace>urn:xmpp:json:0</namespace>
|
||||||
|
<className>org.jivesoftware.smackx.json.provider.JsonExtensionProvider</className>
|
||||||
|
</extensionProvider>
|
||||||
|
|
||||||
|
<!-- GCM JSON payload -->
|
||||||
|
<extensionProvider>
|
||||||
|
<elementName>gcm</elementName>
|
||||||
|
<namespace></namespace>
|
||||||
|
<className>org.jivesoftware.smackx.gcm.provider.GcmExtensionProvider</className>
|
||||||
|
</extensionProvider>
|
||||||
|
|
||||||
</smackProviders>
|
</smackProviders>
|
||||||
|
|
Loading…
Reference in a new issue