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.PacketListener; 17 import org.jivesoftware.smack.filter.AndFilter; 18 import org.jivesoftware.smack.filter.IQTypeFilter; 19 import org.jivesoftware.smack.filter.PacketFilter; 20 import org.jivesoftware.smack.filter.PacketTypeFilter; 21 import org.jivesoftware.smack.packet.IQ; 22 import org.jivesoftware.smack.packet.Packet; 23 import org.jivesoftware.smackx.bytestreams.ibb.packet.Close; 24 25 /** 26 * CloseListener handles all In-Band Bytestream close requests. 27 * <p> 28 * If a close request is received it looks if a stored In-Band Bytestream 29 * session exists and closes it. If no session with the given session ID exists 30 * an <item-not-found/> error is returned to the sender. 31 * 32 * @author Henning Staib 33 */ 34 class CloseListener implements PacketListener { 35 36 /* manager containing the listeners and the XMPP connection */ 37 private final InBandBytestreamManager manager; 38 39 /* packet filter for all In-Band Bytestream close requests */ 40 private final PacketFilter closeFilter = new AndFilter(new PacketTypeFilter( 41 Close.class), new IQTypeFilter(IQ.Type.SET)); 42 43 /** 44 * Constructor. 45 * 46 * @param manager the In-Band Bytestream manager 47 */ 48 protected CloseListener(InBandBytestreamManager manager) { 49 this.manager = manager; 50 } 51 52 public void processPacket(Packet packet) { 53 Close closeRequest = (Close) packet; 54 InBandBytestreamSession ibbSession = this.manager.getSessions().get( 55 closeRequest.getSessionID()); 56 if (ibbSession == null) { 57 this.manager.replyItemNotFoundPacket(closeRequest); 58 } 59 else { 60 ibbSession.closeByPeer(closeRequest); 61 this.manager.getSessions().remove(closeRequest.getSessionID()); 62 } 63 64 } 65 66 /** 67 * Returns the packet filter for In-Band Bytestream close requests. 68 * 69 * @return the packet filter for In-Band Bytestream close requests 70 */ 71 protected PacketFilter getFilter() { 72 return this.closeFilter; 73 } 74 75 } 76