001/** 002 * 003 * Copyright the original author or authors 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.jivesoftware.smackx.bytestreams; 018 019import java.io.IOException; 020 021import org.jivesoftware.smack.SmackException; 022import org.jivesoftware.smack.XMPPException; 023 024import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager; 025import org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamManager; 026 027import org.jxmpp.jid.Jid; 028 029/** 030 * BytestreamManager provides a generic interface for bytestream managers. 031 * <p> 032 * There are two implementations of the interface. See {@link Socks5BytestreamManager} and 033 * {@link InBandBytestreamManager}. 034 * 035 * @author Henning Staib 036 */ 037public interface BytestreamManager { 038 039 /** 040 * Adds {@link BytestreamListener} that is called for every incoming bytestream request unless 041 * there is a user specific {@link BytestreamListener} registered. 042 * <p> 043 * See {@link Socks5BytestreamManager#addIncomingBytestreamListener(BytestreamListener)} and 044 * {@link InBandBytestreamManager#addIncomingBytestreamListener(BytestreamListener)} for further 045 * details. 046 * 047 * @param listener the listener to register 048 */ 049 void addIncomingBytestreamListener(BytestreamListener listener); 050 051 /** 052 * Removes the given listener from the list of listeners for all incoming bytestream requests. 053 * 054 * @param listener the listener to remove 055 */ 056 void removeIncomingBytestreamListener(BytestreamListener listener); 057 058 /** 059 * Adds {@link BytestreamListener} that is called for every incoming bytestream request unless 060 * there is a user specific {@link BytestreamListener} registered. 061 * <p> 062 * Use this method if you are awaiting an incoming bytestream request from a specific user. 063 * <p> 064 * See {@link Socks5BytestreamManager#addIncomingBytestreamListener(BytestreamListener, Jid)} 065 * and {@link InBandBytestreamManager#addIncomingBytestreamListener(BytestreamListener, Jid)} 066 * for further details. 067 * 068 * @param listener the listener to register 069 * @param initiatorJID the JID of the user that wants to establish a bytestream 070 */ 071 void addIncomingBytestreamListener(BytestreamListener listener, Jid initiatorJID); 072 073 /** 074 * Removes the listener for the given user. 075 * 076 * @param initiatorJID the JID of the user the listener should be removed 077 */ 078 void removeIncomingBytestreamListener(Jid initiatorJID); 079 080 /** 081 * Establishes a bytestream with the given user and returns the session to send/receive data 082 * to/from the user. 083 * <p> 084 * Use this method to establish bytestreams to users accepting all incoming bytestream requests 085 * since this method doesn't provide a way to tell the user something about the data to be sent. 086 * <p> 087 * To establish a bytestream after negotiation the kind of data to be sent (e.g. file transfer) 088 * use {@link #establishSession(Jid, String)}. 089 * <p> 090 * See {@link Socks5BytestreamManager#establishSession(Jid)} and 091 * {@link InBandBytestreamManager#establishSession(Jid)} for further details. 092 * 093 * @param targetJID the JID of the user a bytestream should be established 094 * @return the session to send/receive data to/from the user 095 * @throws XMPPException if an error occurred while establishing the session 096 * @throws IOException if an IO error occurred while establishing the session 097 * @throws InterruptedException if the thread was interrupted while waiting in a blocking 098 * operation 099 * @throws SmackException if an error occurs in Smack. 100 */ 101 BytestreamSession establishSession(Jid targetJID) throws XMPPException, IOException, 102 InterruptedException, SmackException; 103 104 /** 105 * Establishes a bytestream with the given user and returns the session to send/receive data 106 * to/from the user. 107 * <p> 108 * See {@link Socks5BytestreamManager#establishSession(Jid)} and 109 * {@link InBandBytestreamManager#establishSession(Jid)} for further details. 110 * 111 * @param targetJID the JID of the user a bytestream should be established 112 * @param sessionID the session ID for the bytestream request 113 * @return the session to send/receive data to/from the user 114 * @throws XMPPException if an error occurred while establishing the session 115 * @throws IOException if an IO error occurred while establishing the session 116 * @throws InterruptedException if the thread was interrupted while waiting in a blocking 117 * operation 118 * @throws SmackException if an error occurs in Smack. 119 */ 120 BytestreamSession establishSession(Jid targetJID, String sessionID) 121 throws XMPPException, IOException, InterruptedException, SmackException; 122 123}