From f05b2081202df891ad322f2cf725ef72226d8a26 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Fri, 4 Jul 2014 23:51:00 +0200 Subject: [PATCH] Remove some duplicate IQ code and some dead code in Socks5PacketUtils. --- .../bytestreams/socks5/Socks5PacketUtils.java | 5 -- .../smackx/jingle/JingleSession.java | 59 +------------------ .../smackx/workgroup/agent/AgentSession.java | 9 +-- 3 files changed, 4 insertions(+), 69 deletions(-) diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5PacketUtils.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5PacketUtils.java index 8beb028ce..98c1c77b5 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5PacketUtils.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5PacketUtils.java @@ -39,7 +39,6 @@ public class Socks5PacketUtils { */ public static Bytestream createBytestreamInitiation(String from, String to, String sessionID) { Bytestream bytestream = new Bytestream(); - bytestream.getPacketID(); bytestream.setFrom(from); bytestream.setTo(to); bytestream.setSessionID(sessionID); @@ -57,7 +56,6 @@ public class Socks5PacketUtils { */ public static Bytestream createBytestreamResponse(String from, String to) { Bytestream streamHostInfo = new Bytestream(); - streamHostInfo.getPacketID(); streamHostInfo.setFrom(from); streamHostInfo.setTo(to); streamHostInfo.setType(IQ.Type.result); @@ -73,7 +71,6 @@ public class Socks5PacketUtils { */ public static DiscoverItems createDiscoverItems(String from, String to) { DiscoverItems discoverItems = new DiscoverItems(); - discoverItems.getPacketID(); discoverItems.setFrom(from); discoverItems.setTo(to); discoverItems.setType(IQ.Type.result); @@ -89,7 +86,6 @@ public class Socks5PacketUtils { */ public static DiscoverInfo createDiscoverInfo(String from, String to) { DiscoverInfo discoverInfo = new DiscoverInfo(); - discoverInfo.getPacketID(); discoverInfo.setFrom(from); discoverInfo.setTo(to); discoverInfo.setType(IQ.Type.result); @@ -112,7 +108,6 @@ public class Socks5PacketUtils { } }; - response.getPacketID(); response.setFrom(from); response.setTo(to); response.setType(IQ.Type.result); diff --git a/smack-jingle/src/main/java/org/jivesoftware/smackx/jingle/JingleSession.java b/smack-jingle/src/main/java/org/jivesoftware/smackx/jingle/JingleSession.java index fa12a4d80..b2b3f871a 100644 --- a/smack-jingle/src/main/java/org/jivesoftware/smackx/jingle/JingleSession.java +++ b/smack-jingle/src/main/java/org/jivesoftware/smackx/jingle/JingleSession.java @@ -505,7 +505,7 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList if (iq != null) { // Don't acknowledge ACKs, errors... if (iq.getType().equals(IQ.Type.set)) { - IQ ack = createIQ(iq.getPacketID(), iq.getFrom(), iq.getTo(), IQ.Type.result); + IQ ack = IQ.createResultIQ(iq); // No! Don't send it. Let it flow to the normal way IQ results get processed and sent. // getConnection().sendPacket(ack); @@ -1017,59 +1017,6 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList // Packet and error creation - /** - * A convience method to create an IQ packet. - * - * @param ID - * The packet ID of the - * @param to - * To whom the packet is addressed. - * @param from - * From whom the packet is sent. - * @param type - * The iq type of the packet. - * @return The created IQ packet. - */ - public static IQ createIQ(String ID, String to, String from, IQ.Type type) { - IQ iqPacket = new IQ() { - public String getChildElementXML() { - return null; - } - }; - - iqPacket.setPacketID(ID); - iqPacket.setTo(to); - iqPacket.setFrom(from); - iqPacket.setType(type); - - return iqPacket; - } - - /** - * A convience method to create an error packet. - * - * @param ID - * The packet ID of the - * @param to - * To whom the packet is addressed. - * @param from - * From whom the packet is sent. - * @param errCode - * The error code. - * @param error - * The XMPPError string. - * @return The created IQ packet. - */ - public static IQ createError(String ID, String to, String from, int errCode, XMPPError error) { - - IQ iqError = createIQ(ID, to, from, IQ.Type.error); - iqError.setError(error); - - LOGGER.fine("Created Error Packet:" + iqError.toXML()); - - return iqError; - } - /** * Complete and send an error. Complete all the null fields in an IQ error * reponse, using the sesssion information we have or some info from the @@ -1083,12 +1030,12 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList public IQ createJingleError(IQ iq, JingleError jingleError) { IQ errorPacket = null; if (jingleError != null) { - errorPacket = createIQ(getSid(), iq.getFrom(), iq.getTo(), IQ.Type.error); - List extList = new ArrayList(); extList.add(jingleError); XMPPError error = new XMPPError(XMPPError.Type.CANCEL, jingleError.toString(), "", extList); + errorPacket = IQ.createErrorResponse(iq, error); + // Fill in the fields with the info from the Jingle packet errorPacket.setPacketID(iq.getPacketID()); errorPacket.setError(error); diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/AgentSession.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/AgentSession.java index 9df988865..3d707ed58 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/AgentSession.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/agent/AgentSession.java @@ -667,14 +667,7 @@ public class AgentSession { private void handlePacket(Packet packet) throws NotConnectedException { if (packet instanceof OfferRequestProvider.OfferRequestPacket) { // Acknowledge the IQ set. - IQ reply = new IQ() { - public String getChildElementXML() { - return null; - } - }; - reply.setPacketID(packet.getPacketID()); - reply.setTo(packet.getFrom()); - reply.setType(IQ.Type.result); + IQ reply = IQ.createResultIQ((IQ) packet); connection.sendPacket(reply); fireOfferRequestEvent((OfferRequestProvider.OfferRequestPacket)packet);