mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-12-22 18:48:00 +01:00
Remove Pong class, add NAMESPACE to Ping
The Pong class was harmful, as people could try to use it with PacketTypeFilter, which wouldn't work, a Pong is just a plain IQ result without child XML.
This commit is contained in:
parent
bbf89c65bf
commit
76f8895ae3
4 changed files with 20 additions and 59 deletions
|
@ -47,7 +47,6 @@ import org.jivesoftware.smack.filter.PacketTypeFilter;
|
||||||
import org.jivesoftware.smack.packet.Packet;
|
import org.jivesoftware.smack.packet.Packet;
|
||||||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||||
import org.jivesoftware.smackx.ping.packet.Ping;
|
import org.jivesoftware.smackx.ping.packet.Ping;
|
||||||
import org.jivesoftware.smackx.ping.packet.Pong;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements the XMPP Ping as defined by XEP-0199. The XMPP Ping protocol allows one entity to
|
* Implements the XMPP Ping as defined by XEP-0199. The XMPP Ping protocol allows one entity to
|
||||||
|
@ -59,8 +58,6 @@ import org.jivesoftware.smackx.ping.packet.Pong;
|
||||||
* @see <a href="http://www.xmpp.org/extensions/xep-0199.html">XEP-0199:XMPP Ping</a>
|
* @see <a href="http://www.xmpp.org/extensions/xep-0199.html">XEP-0199:XMPP Ping</a>
|
||||||
*/
|
*/
|
||||||
public class PingManager extends Manager {
|
public class PingManager extends Manager {
|
||||||
public static final String NAMESPACE = "urn:xmpp:ping";
|
|
||||||
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(PingManager.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(PingManager.class.getName());
|
||||||
|
|
||||||
private static final Map<XMPPConnection, PingManager> INSTANCES = Collections
|
private static final Map<XMPPConnection, PingManager> INSTANCES = Collections
|
||||||
|
@ -137,15 +134,15 @@ public class PingManager extends Manager {
|
||||||
executorService = new ScheduledThreadPoolExecutor(1,
|
executorService = new ScheduledThreadPoolExecutor(1,
|
||||||
new PingExecutorThreadFactory(connection.getConnectionCounter()));
|
new PingExecutorThreadFactory(connection.getConnectionCounter()));
|
||||||
ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
|
ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
|
||||||
sdm.addFeature(PingManager.NAMESPACE);
|
sdm.addFeature(Ping.NAMESPACE);
|
||||||
INSTANCES.put(connection, this);
|
INSTANCES.put(connection, this);
|
||||||
|
|
||||||
connection.addPacketListener(new PacketListener() {
|
connection.addPacketListener(new PacketListener() {
|
||||||
// Send a Pong for every Ping
|
// Send a Pong for every Ping
|
||||||
@Override
|
@Override
|
||||||
public void processPacket(Packet packet) throws NotConnectedException {
|
public void processPacket(Packet packet) throws NotConnectedException {
|
||||||
Pong pong = new Pong(packet);
|
Ping ping = (Ping) packet;
|
||||||
connection().sendPacket(pong);
|
connection().sendPacket(ping.getPong());
|
||||||
}
|
}
|
||||||
}, PING_PACKET_FILTER);
|
}, PING_PACKET_FILTER);
|
||||||
connection.addConnectionListener(new AbstractConnectionListener() {
|
connection.addConnectionListener(new AbstractConnectionListener() {
|
||||||
|
@ -213,7 +210,7 @@ public class PingManager extends Manager {
|
||||||
* @throws NotConnectedException
|
* @throws NotConnectedException
|
||||||
*/
|
*/
|
||||||
public boolean isPingSupported(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException {
|
public boolean isPingSupported(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException {
|
||||||
return ServiceDiscoveryManager.getInstanceFor(connection()).supportsFeature(jid, PingManager.NAMESPACE);
|
return ServiceDiscoveryManager.getInstanceFor(connection()).supportsFeature(jid, Ping.NAMESPACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -17,22 +17,31 @@
|
||||||
package org.jivesoftware.smackx.ping.packet;
|
package org.jivesoftware.smackx.ping.packet;
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smackx.ping.PingManager;
|
|
||||||
|
|
||||||
public class Ping extends IQ {
|
public class Ping extends IQ {
|
||||||
|
|
||||||
public static final String ELEMENT = "ping";
|
public static final String ELEMENT = "ping";
|
||||||
|
public static final String NAMESPACE = "urn:xmpp:ping";
|
||||||
|
|
||||||
public Ping() {
|
public Ping() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Ping(String to) {
|
public Ping(String to) {
|
||||||
setTo(to);
|
setTo(to);
|
||||||
setType(IQ.Type.get);
|
setType(IQ.Type.get);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getChildElementXML() {
|
public String getChildElementXML() {
|
||||||
return "<" + ELEMENT + " xmlns=\'" + PingManager.NAMESPACE + "\' />";
|
return '<' + ELEMENT + " xmlns='" + NAMESPACE + "'/>";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a XMPP Pong for this Ping
|
||||||
|
*
|
||||||
|
* @return the Pong
|
||||||
|
*/
|
||||||
|
public IQ getPong() {
|
||||||
|
return createResultIQ(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,45 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Copyright 2012-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.ping.packet;
|
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
|
||||||
import org.jivesoftware.smack.packet.Packet;
|
|
||||||
|
|
||||||
public class Pong extends IQ {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Composes a Pong packet from a received ping packet. This basically swaps
|
|
||||||
* the 'from' and 'to' attributes. And sets the IQ type to result.
|
|
||||||
*
|
|
||||||
* @param ping
|
|
||||||
*/
|
|
||||||
public Pong(Packet ping) {
|
|
||||||
setType(IQ.Type.result);
|
|
||||||
setFrom(ping.getTo());
|
|
||||||
setTo(ping.getFrom());
|
|
||||||
setPacketID(ping.getPacketID());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the child element of the Pong reply, which is non-existent. This
|
|
||||||
* is why we return 'null' here. See e.g. Example 11 from
|
|
||||||
* http://xmpp.org/extensions/xep-0199.html#e2e
|
|
||||||
*/
|
|
||||||
public String getChildElementXML() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -191,7 +191,7 @@ public class PingTest extends InitExtensions {
|
||||||
public void checkSuccessfulDiscoRequest() throws Exception {
|
public void checkSuccessfulDiscoRequest() throws Exception {
|
||||||
ThreadedDummyConnection con = new ThreadedDummyConnection();
|
ThreadedDummyConnection con = new ThreadedDummyConnection();
|
||||||
DiscoverInfo info = new DiscoverInfo();
|
DiscoverInfo info = new DiscoverInfo();
|
||||||
info.addFeature(PingManager.NAMESPACE);
|
info.addFeature(Ping.NAMESPACE);
|
||||||
|
|
||||||
//@formatter:off
|
//@formatter:off
|
||||||
String reply =
|
String reply =
|
||||||
|
@ -213,7 +213,7 @@ public class PingTest extends InitExtensions {
|
||||||
public void checkUnuccessfulDiscoRequest() throws Exception {
|
public void checkUnuccessfulDiscoRequest() throws Exception {
|
||||||
ThreadedDummyConnection con = new ThreadedDummyConnection();
|
ThreadedDummyConnection con = new ThreadedDummyConnection();
|
||||||
DiscoverInfo info = new DiscoverInfo();
|
DiscoverInfo info = new DiscoverInfo();
|
||||||
info.addFeature(PingManager.NAMESPACE);
|
info.addFeature(Ping.NAMESPACE);
|
||||||
|
|
||||||
//@formatter:off
|
//@formatter:off
|
||||||
String reply =
|
String reply =
|
||||||
|
|
Loading…
Reference in a new issue