1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-25 13:32:07 +01:00

Rename IQ.ELEMENT to IQ.IQ_ELEMENT

to avoid confusion between the IQ element 'iq' and the IQs child
element. ELEMENT defined in an IQ sublcass should contain the *child*
element.

Add element to StreamInitation and fix FileTransferManager which still
used a packet listener instead of an IQ request handler to handle
incoming stream initiation requests.
This commit is contained in:
Florian Schmaus 2015-01-11 21:52:06 +01:00
parent f1a1215f35
commit b0cecee710
6 changed files with 19 additions and 15 deletions

View file

@ -543,7 +543,7 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
String name = parser.getName(); String name = parser.getName();
switch (name) { switch (name) {
case Message.ELEMENT: case Message.ELEMENT:
case IQ.ELEMENT: case IQ.IQ_ELEMENT:
case Presence.ELEMENT: case Presence.ELEMENT:
parseAndProcessStanza(parser); parseAndProcessStanza(parser);
break; break;

View file

@ -40,7 +40,8 @@ import org.jivesoftware.smack.util.XmlStringBuilder;
*/ */
public abstract class IQ extends Packet { public abstract class IQ extends Packet {
public static final String ELEMENT = "iq"; // Don't name this field 'ELEMENT'. When it comes to IQ, ELEMENT is the child element!
public static final String IQ_ELEMENT = "iq";
public static final String QUERY_ELEMENT = "query"; public static final String QUERY_ELEMENT = "query";
private final String childElementName; private final String childElementName;
@ -98,7 +99,7 @@ public abstract class IQ extends Packet {
@Override @Override
public final XmlStringBuilder toXML() { public final XmlStringBuilder toXML() {
XmlStringBuilder buf = new XmlStringBuilder(); XmlStringBuilder buf = new XmlStringBuilder();
buf.halfOpenElement(ELEMENT); buf.halfOpenElement(IQ_ELEMENT);
addCommonAttributes(buf); addCommonAttributes(buf);
if (type == null) { if (type == null) {
buf.attribute("type", "get"); buf.attribute("type", "get");
@ -108,7 +109,7 @@ public abstract class IQ extends Packet {
} }
buf.rightAngleBracket(); buf.rightAngleBracket();
buf.append(getChildElementXML()); buf.append(getChildElementXML());
buf.closeElement(ELEMENT); buf.closeElement(IQ_ELEMENT);
return buf; return buf;
} }

View file

@ -149,7 +149,7 @@ public class PacketParserUtils {
switch (name) { switch (name) {
case Message.ELEMENT: case Message.ELEMENT:
return parseMessage(parser); return parseMessage(parser);
case IQ.ELEMENT: case IQ.IQ_ELEMENT:
return parseIQ(parser); return parseIQ(parser);
case Presence.ELEMENT: case Presence.ELEMENT:
return parsePresence(parser); return parsePresence(parser);

View file

@ -30,6 +30,9 @@ import org.jivesoftware.smack.util.XmlStringBuilder;
* @author Alexander Wenckus * @author Alexander Wenckus
*/ */
public class Bytestream extends IQ { public class Bytestream extends IQ {
public static final String ELEMENT = QUERY_ELEMENT;
/** /**
* The XMPP namespace of the SOCKS5 Bytestream * The XMPP namespace of the SOCKS5 Bytestream
*/ */
@ -49,7 +52,7 @@ public class Bytestream extends IQ {
* The default constructor * The default constructor
*/ */
public Bytestream() { public Bytestream() {
super(QUERY_ELEMENT, NAMESPACE); super(ELEMENT, NAMESPACE);
} }
/** /**

View file

@ -17,14 +17,11 @@
package org.jivesoftware.smackx.filetransfer; package org.jivesoftware.smackx.filetransfer;
import org.jivesoftware.smack.Manager; import org.jivesoftware.smack.Manager;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.filter.AndFilter; import org.jivesoftware.smack.iqrequest.AbstractIqRequestHandler;
import org.jivesoftware.smack.filter.IQTypeFilter; import org.jivesoftware.smack.iqrequest.IQRequestHandler.Mode;
import org.jivesoftware.smack.filter.PacketTypeFilter;
import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.XMPPError; import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smackx.si.packet.StreamInitiation; import org.jivesoftware.smackx.si.packet.StreamInitiation;
import org.jxmpp.util.XmppStringUtils; import org.jxmpp.util.XmppStringUtils;
@ -73,15 +70,18 @@ public class FileTransferManager extends Manager {
super(connection); super(connection);
this.fileTransferNegotiator = FileTransferNegotiator this.fileTransferNegotiator = FileTransferNegotiator
.getInstanceFor(connection); .getInstanceFor(connection);
connection.addAsyncPacketListener(new PacketListener() { connection.registerIQRequestHandler(new AbstractIqRequestHandler(StreamInitiation.ELEMENT,
public void processPacket(Packet packet) { StreamInitiation.NAMESPACE, IQ.Type.set, Mode.async) {
@Override
public IQ handleIQRequest(IQ packet) {
StreamInitiation si = (StreamInitiation) packet; StreamInitiation si = (StreamInitiation) packet;
final FileTransferRequest request = new FileTransferRequest(FileTransferManager.this, si); final FileTransferRequest request = new FileTransferRequest(FileTransferManager.this, si);
for (final FileTransferListener listener : listeners) { for (final FileTransferListener listener : listeners) {
listener.fileTransferRequest(request); listener.fileTransferRequest(request);
} }
return null;
} }
}, new AndFilter(new PacketTypeFilter(StreamInitiation.class), IQTypeFilter.SET)); });
} }
/** /**

View file

@ -948,7 +948,7 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
final String name = parser.getName(); final String name = parser.getName();
switch (name) { switch (name) {
case Message.ELEMENT: case Message.ELEMENT:
case IQ.ELEMENT: case IQ.IQ_ELEMENT:
case Presence.ELEMENT: case Presence.ELEMENT:
try { try {
parseAndProcessStanza(parser); parseAndProcessStanza(parser);