blob: 166c146471a1e4eb83206afccf50cb75c2ea2b99 [file] [log] [blame]
Shuyi Chend7955ce2013-05-22 14:51:55 -07001/**
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 */
14package org.jivesoftware.smackx.bytestreams.ibb;
15
16import org.jivesoftware.smack.PacketListener;
17import org.jivesoftware.smack.filter.AndFilter;
18import org.jivesoftware.smack.filter.PacketFilter;
19import org.jivesoftware.smack.filter.PacketTypeFilter;
20import org.jivesoftware.smack.packet.Packet;
21import 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 * &lt;item-not-found/&gt; 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 */
37class 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}