From 877afcd3ba0f676efcf4ebeb6bf70b5c8de6f5e2 Mon Sep 17 00:00:00 2001 From: Thiago Camargo Date: Fri, 9 Feb 2007 03:49:43 +0000 Subject: [PATCH] Terminate a session instead Decline with an Error packet git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@7063 b35dd754-fafc-0310-a699-88a17e54d16e --- .../smackx/jingle/IncomingJingleSession.java | 8 +++--- .../smackx/jingle/JingleSession.java | 28 ++++++++++--------- .../smackx/jingle/JingleSessionRequest.java | 4 ++- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/IncomingJingleSession.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/IncomingJingleSession.java index 51210ce26..824dcd771 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/IncomingJingleSession.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/IncomingJingleSession.java @@ -174,7 +174,7 @@ public class IncomingJingleSession extends JingleSession { * * @return */ - JingleSessionRequest getInitialSessionRequest() { + public JingleSessionRequest getInitialSessionRequest() { return initialSessionRequest; } @@ -183,7 +183,7 @@ public class IncomingJingleSession extends JingleSession { * * @param initialRequest the initial Jingle packet */ - void setInitialSessionRequest(JingleSessionRequest initialRequest) { + public void setInitialSessionRequest(JingleSessionRequest initialRequest) { this.initialSessionRequest = initialRequest; } @@ -227,7 +227,7 @@ public class IncomingJingleSession extends JingleSession { * "Pending" state: we are waiting for the transport and content * negotiators. */ - private class Pending extends JingleNegotiator.State { + public class Pending extends JingleNegotiator.State { JingleMediaListener jingleMediaListener; @@ -373,7 +373,7 @@ public class IncomingJingleSession extends JingleSession { /** * "Active" state: we have an agreement about the session. */ - private class Active extends JingleNegotiator.State { + public class Active extends JingleNegotiator.State { public Active(JingleNegotiator neg) { super(neg); } diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSession.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSession.java index 86ebab1c0..78bc2507d 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSession.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSession.java @@ -118,6 +118,8 @@ public abstract class JingleSession extends JingleNegotiator { static int ccc = 0; + private boolean closed = false; + /** * Full featured JingleSession constructor * @@ -605,7 +607,7 @@ public abstract class JingleSession extends JingleNegotiator { * * @param iq The IQ to acknowledge */ - private IQ sendAck(IQ iq) { + public IQ sendAck(IQ iq) { IQ result = null; if (iq != null) { @@ -1074,17 +1076,12 @@ public abstract class JingleSession extends JingleNegotiator { */ public void terminate() throws XMPPException { System.out.println("State: " + this.getState()); - if (!invalidState()) { - Jingle result = null; - Jingle jout = new Jingle(Jingle.Action.SESSIONTERMINATE); - jout.setType(IQ.Type.SET); - sendFormattedJingle(jout); - triggerSessionClosed("Closed Locally"); - close(); - } - else { - throw new IllegalStateException("Session Not Started"); - } + Jingle result = null; + Jingle jout = new Jingle(Jingle.Action.SESSIONTERMINATE); + jout.setType(IQ.Type.SET); + sendFormattedJingle(jout); + triggerSessionClosed("Closed Locally"); + close(); } /** @@ -1095,9 +1092,14 @@ public abstract class JingleSession extends JingleNegotiator { destroyTransportNeg(); removePacketListener(); System.out.println("Negociation Closed"); + closed=true; super.close(); } + public boolean isClosed() { + return closed; + } + // Packet and error creation /** @@ -1142,7 +1144,7 @@ public abstract class JingleSession extends JingleNegotiator { XMPPError error = new XMPPError(new XMPPError.Condition(errStr)); iqError.setError(error); - System.out.println(iqError.toXML()); + System.out.println("Created Error Packet:" + iqError.toXML()); return iqError; } diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSessionRequest.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSessionRequest.java index e1c3c6908..e213f4b02 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSessionRequest.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/JingleSessionRequest.java @@ -8,7 +8,7 @@ import java.util.List; /** * A Jingle session request. - * + *

* This class is a facade of a received Jingle request. The user can have direct * access to the Jingle packet (JingleSessionRequest.getJingle() ) of * the request or can use the convencience methods provided by this class. @@ -76,6 +76,8 @@ public class JingleSessionRequest { session = manager.createIncomingJingleSession(this, pts); session.setInitialSessionRequest(this); + // Acknowledge the IQ reception + session.sendAck(this.getJingle()); } return session; }