1 /** 2 * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); 3 * you may not use this file except in compliance with the License. 4 * You may obtain a copy of the License at 5 * 6 * http://www.apache.org/licenses/LICENSE-2.0 7 * 8 * Unless required by applicable law or agreed to in writing, software 9 * distributed under the License is distributed on an "AS IS" BASIS, 10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 * See the License for the specific language governing permissions and 12 * limitations under the License. 13 */ 14 package org.jivesoftware.smackx.bytestreams.ibb; 15 16 import org.jivesoftware.smack.Connection; 17 import org.jivesoftware.smack.XMPPException; 18 import org.jivesoftware.smack.packet.IQ; 19 import org.jivesoftware.smackx.bytestreams.BytestreamRequest; 20 import org.jivesoftware.smackx.bytestreams.ibb.packet.Open; 21 22 /** 23 * InBandBytestreamRequest class handles incoming In-Band Bytestream requests. 24 * 25 * @author Henning Staib 26 */ 27 public class InBandBytestreamRequest implements BytestreamRequest { 28 29 /* the bytestream initialization request */ 30 private final Open byteStreamRequest; 31 32 /* 33 * In-Band Bytestream manager containing the XMPP connection and helper 34 * methods 35 */ 36 private final InBandBytestreamManager manager; 37 InBandBytestreamRequest(InBandBytestreamManager manager, Open byteStreamRequest)38 protected InBandBytestreamRequest(InBandBytestreamManager manager, 39 Open byteStreamRequest) { 40 this.manager = manager; 41 this.byteStreamRequest = byteStreamRequest; 42 } 43 44 /** 45 * Returns the sender of the In-Band Bytestream open request. 46 * 47 * @return the sender of the In-Band Bytestream open request 48 */ getFrom()49 public String getFrom() { 50 return this.byteStreamRequest.getFrom(); 51 } 52 53 /** 54 * Returns the session ID of the In-Band Bytestream open request. 55 * 56 * @return the session ID of the In-Band Bytestream open request 57 */ getSessionID()58 public String getSessionID() { 59 return this.byteStreamRequest.getSessionID(); 60 } 61 62 /** 63 * Accepts the In-Band Bytestream open request and returns the session to 64 * send/receive data. 65 * 66 * @return the session to send/receive data 67 * @throws XMPPException if stream is invalid. 68 */ accept()69 public InBandBytestreamSession accept() throws XMPPException { 70 Connection connection = this.manager.getConnection(); 71 72 // create In-Band Bytestream session and store it 73 InBandBytestreamSession ibbSession = new InBandBytestreamSession(connection, 74 this.byteStreamRequest, this.byteStreamRequest.getFrom()); 75 this.manager.getSessions().put(this.byteStreamRequest.getSessionID(), ibbSession); 76 77 // acknowledge request 78 IQ resultIQ = IQ.createResultIQ(this.byteStreamRequest); 79 connection.sendPacket(resultIQ); 80 81 return ibbSession; 82 } 83 84 /** 85 * Rejects the In-Band Bytestream request by sending a reject error to the 86 * initiator. 87 */ reject()88 public void reject() { 89 this.manager.replyRejectPacket(this.byteStreamRequest); 90 } 91 92 } 93