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.PacketFilter; 19 import org.jivesoftware.smack.filter.PacketTypeFilter; 20 import org.jivesoftware.smack.packet.Packet; 21 import org.jivesoftware.smackx.bytestreams.ibb.packet.Data; 22 23 /** 24 * DataListener handles all In-Band Bytestream IQ stanzas containing a data 25 * packet extension that don't belong to an existing session. 26 * <p> 27 * If a data packet is received it looks if a stored In-Band Bytestream session 28 * exists. If no session with the given session ID exists an 29 * <item-not-found/> error is returned to the sender. 30 * <p> 31 * Data packets belonging to a running In-Band Bytestream session are processed 32 * by more specific listeners registered when an {@link InBandBytestreamSession} 33 * is created. 34 * 35 * @author Henning Staib 36 */ 37 class DataListener implements PacketListener { 38 39 /* manager containing the listeners and the XMPP connection */ 40 private final InBandBytestreamManager manager; 41 42 /* packet filter for all In-Band Bytestream data packets */ 43 private final PacketFilter dataFilter = new AndFilter( 44 new PacketTypeFilter(Data.class)); 45 46 /** 47 * Constructor. 48 * 49 * @param manager the In-Band Bytestream manager 50 */ 51 public DataListener(InBandBytestreamManager manager) { 52 this.manager = manager; 53 } 54 55 public void processPacket(Packet packet) { 56 Data data = (Data) packet; 57 InBandBytestreamSession ibbSession = this.manager.getSessions().get( 58 data.getDataPacketExtension().getSessionID()); 59 if (ibbSession == null) { 60 this.manager.replyItemNotFoundPacket(data); 61 } 62 } 63 64 /** 65 * Returns the packet filter for In-Band Bytestream data packets. 66 * 67 * @return the packet filter for In-Band Bytestream data packets 68 */ 69 protected PacketFilter getFilter() { 70 return this.dataFilter; 71 } 72 73 } 74