From a892bb6f1685b84b74ba37e5a6a24ee8fb45eee7 Mon Sep 17 00:00:00 2001 From: steckbrief Date: Mon, 7 Aug 2017 12:57:57 +0200 Subject: Simplifying introduction of new XEP implementations, implements FS#250 and FS#251 (Privacy and Security settings), refactoring of location of some interfaces --- .../conversationsplus/xmpp/ping/Ping.java | 8 ++++ .../xmpp/ping/PingPacketHandler.java | 22 ++++++++++ .../conversationsplus/xmpp/ping/PingXep.java | 51 ++++++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 src/main/java/de/thedevstack/conversationsplus/xmpp/ping/Ping.java create mode 100644 src/main/java/de/thedevstack/conversationsplus/xmpp/ping/PingPacketHandler.java create mode 100644 src/main/java/de/thedevstack/conversationsplus/xmpp/ping/PingXep.java (limited to 'src/main/java/de/thedevstack/conversationsplus/xmpp/ping') diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/ping/Ping.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/ping/Ping.java new file mode 100644 index 00000000..ac201c01 --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/ping/Ping.java @@ -0,0 +1,8 @@ +package de.thedevstack.conversationsplus.xmpp.ping; + +/** + */ +public interface Ping { + String NAMESPACE = "urn:xmpp:ping"; + String ELEMENT = "ping"; +} diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/ping/PingPacketHandler.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/ping/PingPacketHandler.java new file mode 100644 index 00000000..14e8f57c --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/ping/PingPacketHandler.java @@ -0,0 +1,22 @@ +package de.thedevstack.conversationsplus.xmpp.ping; + +import de.thedevstack.conversationsplus.entities.Account; +import de.thedevstack.conversationsplus.utils.XmppSendUtil; +import de.thedevstack.conversationsplus.xmpp.IqPacketHandler; +import de.thedevstack.conversationsplus.xmpp.exceptions.IqPacketErrorException; +import de.thedevstack.conversationsplus.xmpp.exceptions.NotAllowedIqException; +import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket; +import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacketGenerator; + +/** + */ +public class PingPacketHandler implements IqPacketHandler { + @Override + public void handleIqPacket(Account account, IqPacket packet) throws IqPacketErrorException { + if (packet.getType() == IqPacket.TYPE.GET) { + XmppSendUtil.sendIqPacket(account, IqPacketGenerator.generateIqResultResponse(packet)); + } else { + throw new NotAllowedIqException(packet, "only type=get allowed for processing an XMPP Ping (XEP-0199)"); + } + } +} diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/ping/PingXep.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/ping/PingXep.java new file mode 100644 index 00000000..6036a64f --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/ping/PingXep.java @@ -0,0 +1,51 @@ +package de.thedevstack.conversationsplus.xmpp.ping; + +import de.thedevstack.conversationsplus.xmpp.AbstractXep; +import de.thedevstack.conversationsplus.xmpp.IqPacketHandler; + +/** + */ +public class PingXep extends AbstractXep { + public PingXep() { + super(); + } + + public PingXep(boolean enabled) { + super(enabled); + } + + @Override + public String xepNumber() { + return "0199"; + } + + @Override + public String shortName() { + return "ping"; + } + + @Override + public String name() { + return "XMPP Ping"; + } + + @Override + public String namespace() { + return Ping.NAMESPACE; + } + + @Override + public String featureNamespace() { + return Ping.NAMESPACE; + } + + @Override + public String elementName() { + return Ping.ELEMENT; + } + + @Override + public IqPacketHandler handler() { + return new PingPacketHandler(); + } +} -- cgit v1.2.3