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

Fix PubSub namespaces

Those were broken since 9e797c1b17 as they
always used the basic PubSub namespace, i.e. without a fragment. Which
resulted in e.g. delete requests look like

<iq to="pubsub.ec-xmpp" id="2GAeW-75" type="set">
  <pubsub xmlns="http://jabber.org/protocol/pubsub">
    <delete node="2e92d38c-9e90-47f6-8e26-330d25ebe96b"/>
  </pubsub>
</iq>

when the namespace should be in fact

http://jabber.org/protocol/pubsub#owner
This commit is contained in:
Florian Schmaus 2014-12-17 13:31:22 +01:00
parent d0341c1d94
commit add4ff5b5a
5 changed files with 70 additions and 69 deletions

View file

@ -32,23 +32,18 @@ public class PubSub extends IQ
public static final String ELEMENT = "pubsub";
public static final String NAMESPACE = "http://jabber.org/protocol/pubsub";
private PubSubNamespace ns = PubSubNamespace.BASIC;
public PubSub() {
super(ELEMENT, NAMESPACE);
}
public PubSub(String to, Type type) {
this();
setTo(to);
setType(type);
public PubSub(PubSubNamespace ns) {
super(ELEMENT, ns.getXmlns());
}
public PubSub(String to, Type type, PubSubNamespace ns) {
this(to, type);
if (ns != null) {
setPubSubNamespace(ns);
}
super(ELEMENT, (ns == null ? PubSubNamespace.BASIC : ns).getXmlns());
setTo(to);
setType(type);
}
/**
@ -60,49 +55,12 @@ public class PubSub extends IQ
return ELEMENT;
}
/**
* Returns the XML namespace of the extension sub-packet root element.
* According the specification the namespace is
* http://jabber.org/protocol/pubsub with a specific fragment depending
* on the request. The namespace is defined at <a href="http://xmpp.org/registrar/namespaces.html">XMPP Registrar</a> at
*
* The default value has no fragment.
*
* @return the XML namespace of the packet extension.
*/
public String getNamespace()
{
return ns.getXmlns();
}
/**
* Set the namespace for the packet if it something other than the default
* case of {@link PubSubNamespace#BASIC}. The {@link #getNamespace()} method will return
* the result of calling {@link PubSubNamespace#getXmlns()} on the specified enum.
*
* @param ns - The new value for the namespace.
*/
public void setPubSubNamespace(PubSubNamespace ns)
{
this.ns = ns;
}
@SuppressWarnings("unchecked")
public <PE extends PacketExtension> PE getExtension(PubSubElementType elem)
{
return (PE) getExtension(elem.getElementName(), elem.getNamespace().getXmlns());
}
/**
* Returns the current value of the namespace. The {@link #getNamespace()} method will return
* the result of calling {@link PubSubNamespace#getXmlns()} this value.
*
* @return The current value of the namespace.
*/
public PubSubNamespace getPubSubNamespace()
{
return ns;
}
/**
* Returns the XML representation of a pubsub element according the specification.
*

View file

@ -38,25 +38,22 @@ public class PubSubProvider extends IQProvider<PubSub>
@Override
public PubSub parse(XmlPullParser parser, int initialDepth)
throws XmlPullParserException, IOException, SmackException {
PubSub pubsub = new PubSub();
String namespace = parser.getNamespace();
pubsub.setPubSubNamespace(PubSubNamespace.valueOfFromXmlns(namespace));
boolean done = false;
PubSubNamespace pubSubNamespace = PubSubNamespace.valueOfFromXmlns(namespace);
PubSub pubsub = new PubSub(pubSubNamespace);
while (!done)
outerloop: while (true)
{
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG)
{
switch (eventType) {
case XmlPullParser.START_TAG:
PacketParserUtils.addPacketExtension(pubsub, parser);
}
else if (eventType == XmlPullParser.END_TAG)
{
if (parser.getName().equals("pubsub"))
{
done = true;
break;
case XmlPullParser.END_TAG:
if (parser.getDepth() == initialDepth) {
break outerloop;
}
break;
}
}
return pubsub;