2007-03-03 06:20:17 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Copyright 2003-2006 Jive Software.
|
|
|
|
*
|
2014-02-17 18:57:38 +01:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
2007-03-03 06:20:17 +01:00
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
2014-02-19 10:38:30 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2007-03-03 06:20:17 +01:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2007-01-04 18:25:30 +01:00
|
|
|
package org.jivesoftware.smackx.jingle;
|
|
|
|
|
2014-02-19 10:38:30 +01:00
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
2014-03-12 11:50:05 +01:00
|
|
|
import org.jivesoftware.smack.SmackException;
|
2007-01-04 18:25:30 +01:00
|
|
|
import org.jivesoftware.smack.XMPPException;
|
2014-03-03 11:31:06 +01:00
|
|
|
import org.jivesoftware.smackx.jingle.packet.Jingle;
|
2007-01-04 18:25:30 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A Jingle session request.
|
2007-02-09 04:49:43 +01:00
|
|
|
* <p/>
|
2007-01-04 18:25:30 +01:00
|
|
|
* This class is a facade of a received Jingle request. The user can have direct
|
|
|
|
* access to the Jingle packet (<i>JingleSessionRequest.getJingle() </i>) of
|
|
|
|
* the request or can use the convencience methods provided by this class.
|
|
|
|
*
|
|
|
|
* @author Alvaro Saurin
|
|
|
|
*/
|
|
|
|
public class JingleSessionRequest {
|
|
|
|
|
2014-02-19 10:38:30 +01:00
|
|
|
private static final Logger LOGGER = Logger.getLogger(JingleSessionRequest.class.getName());
|
2008-12-06 03:15:42 +01:00
|
|
|
|
|
|
|
private final Jingle jingle; // The Jingle packet
|
2007-01-04 18:25:30 +01:00
|
|
|
|
|
|
|
private final JingleManager manager; // The manager associated to this
|
|
|
|
|
|
|
|
// request
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A recieve request is constructed from the Jingle Initiation request
|
|
|
|
* received from the initator.
|
|
|
|
*
|
|
|
|
* @param manager The manager handling this request
|
|
|
|
* @param jingle The jingle IQ recieved from the initiator.
|
|
|
|
*/
|
|
|
|
public JingleSessionRequest(JingleManager manager, Jingle jingle) {
|
|
|
|
this.manager = manager;
|
|
|
|
this.jingle = jingle;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the fully-qualified jabber ID of the user that requested this
|
|
|
|
* session.
|
|
|
|
*
|
|
|
|
* @return Returns the fully-qualified jabber ID of the user that requested
|
|
|
|
* this session.
|
|
|
|
*/
|
|
|
|
public String getFrom() {
|
|
|
|
return jingle.getFrom();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the session ID that uniquely identifies this session.
|
|
|
|
*
|
|
|
|
* @return Returns the session ID that uniquely identifies this session
|
|
|
|
*/
|
|
|
|
public String getSessionID() {
|
|
|
|
return jingle.getSid();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-05-20 00:54:19 +02:00
|
|
|
* Returns the Jingle packet that was sent by the requester which contains
|
2007-01-04 18:25:30 +01:00
|
|
|
* the parameters of the session.
|
|
|
|
*/
|
|
|
|
public Jingle getJingle() {
|
|
|
|
return jingle;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Accepts this request and creates the incoming Jingle session.
|
|
|
|
*
|
|
|
|
* @param pts list of supported Payload Types
|
|
|
|
* @return Returns the <b><i>IncomingJingleSession</b></i> on which the
|
|
|
|
* negotiation can be carried out.
|
|
|
|
*/
|
2008-05-20 00:54:19 +02:00
|
|
|
// public synchronized JingleSession accept(List<PayloadType> pts) throws XMPPException {
|
|
|
|
// JingleSession session = null;
|
|
|
|
// synchronized (manager) {
|
|
|
|
// session = manager.createIncomingJingleSession(this, pts);
|
|
|
|
// // Acknowledge the IQ reception
|
|
|
|
// session.setSid(this.getSessionID());
|
|
|
|
// //session.sendAck(this.getJingle());
|
|
|
|
// //session.respond(this.getJingle());
|
|
|
|
// }
|
|
|
|
// return session;
|
|
|
|
// }
|
2007-01-04 18:25:30 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Accepts this request and creates the incoming Jingle session.
|
|
|
|
*
|
|
|
|
* @return Returns the <b><i>IncomingJingleSession</b></i> on which the
|
|
|
|
* negotiation can be carried out.
|
2014-03-12 11:50:05 +01:00
|
|
|
* @throws SmackException
|
2007-01-04 18:25:30 +01:00
|
|
|
*/
|
2014-03-12 11:50:05 +01:00
|
|
|
public synchronized JingleSession accept() throws XMPPException, SmackException {
|
2008-05-20 00:54:19 +02:00
|
|
|
JingleSession session = null;
|
2007-01-04 18:25:30 +01:00
|
|
|
synchronized (manager) {
|
|
|
|
session = manager.createIncomingJingleSession(this);
|
2007-02-14 03:35:04 +01:00
|
|
|
// Acknowledge the IQ reception
|
|
|
|
session.setSid(this.getSessionID());
|
|
|
|
//session.sendAck(this.getJingle());
|
2008-05-20 00:54:19 +02:00
|
|
|
session.updatePacketListener();
|
|
|
|
session.receivePacketAndRespond(this.getJingle());
|
2007-01-04 18:25:30 +01:00
|
|
|
}
|
|
|
|
return session;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Rejects the session request.
|
|
|
|
*/
|
|
|
|
public synchronized void reject() {
|
2008-12-06 03:15:42 +01:00
|
|
|
JingleSession session = null;
|
2007-01-04 18:25:30 +01:00
|
|
|
synchronized (manager) {
|
2008-12-06 03:15:42 +01:00
|
|
|
try {
|
|
|
|
session = manager.createIncomingJingleSession(this);
|
|
|
|
// Acknowledge the IQ reception
|
|
|
|
session.setSid(this.getSessionID());
|
|
|
|
//session.sendAck(this.getJingle());
|
|
|
|
session.updatePacketListener();
|
|
|
|
session.terminate("Declined");
|
2014-03-19 14:22:20 +01:00
|
|
|
} catch (Exception e) {
|
|
|
|
LOGGER.log(Level.SEVERE, "Exception in reject", e);
|
2008-12-06 03:15:42 +01:00
|
|
|
}
|
2007-01-04 18:25:30 +01:00
|
|
|
}
|
2008-12-06 03:15:42 +01:00
|
|
|
}
|
2007-01-04 18:25:30 +01:00
|
|
|
}
|