001/*
002 *  Licensed to the Apache Software Foundation (ASF) under one
003 *  or more contributor license agreements.  See the NOTICE file
004 *  distributed with this work for additional information
005 *  regarding copyright ownership.  The ASF licenses this file
006 *  to you under the Apache License, Version 2.0 (the
007 *  "License"); you may not use this file except in compliance
008 *  with the License.  You may obtain a copy of the License at
009 *
010 *    http://www.apache.org/licenses/LICENSE-2.0
011 *
012 *  Unless required by applicable law or agreed to in writing,
013 *  software distributed under the License is distributed on an
014 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *  KIND, either express or implied.  See the License for the
016 *  specific language governing permissions and limitations
017 *  under the License.
018 *
019 */
020package org.apache.mina.proxy;
021
022import org.apache.mina.core.buffer.IoBuffer;
023import org.apache.mina.core.filterchain.IoFilter.NextFilter;
024import org.apache.mina.core.write.WriteRequest;
025import org.apache.mina.proxy.session.ProxyIoSession;
026
027/**
028 * ProxyLogicHandler.java - Interface implemented by classes containing proxy type specific logic.
029 * 
030 * @author <a href="http://mina.apache.org">Apache MINA Project</a>
031 * @since MINA 2.0.0-M3
032 */
033public interface ProxyLogicHandler {
034    /**
035     * Tests if handshake process is complete.
036     * 
037     * @return <tt>true</tt> if handshaking is complete and
038     * data can be sent through the proxy, false otherwise.
039     */
040    boolean isHandshakeComplete();
041
042    /**
043     * Handle incoming data during the handshake process. Should consume only the
044     * handshake data from the buffer, leaving any extra data in place.
045     * 
046     * @param nextFilter the next filter in the filter chain
047     * @param buf the buffer holding the received data
048     * @throws ProxyAuthException if authentication fails
049     */
050    void messageReceived(NextFilter nextFilter, IoBuffer buf) throws ProxyAuthException;
051
052    /**
053     * Called at each step of the handshake procedure.
054     * 
055     * @param nextFilter the next filter in filter chain
056     * @throws ProxyAuthException if authentication fails
057     */
058    void doHandshake(NextFilter nextFilter) throws ProxyAuthException;
059
060    /**
061     * @return the {@link ProxyIoSession}.
062     */
063    ProxyIoSession getProxyIoSession();
064
065    /**
066     * Enqueue a message to be written once handshaking is complete.
067     * 
068     * @param nextFilter the next filter in filter chain
069     * @param writeRequest the data to be written
070     */
071    void enqueueWriteRequest(final NextFilter nextFilter, final WriteRequest writeRequest);
072}