// Path: src/main/java/com/yammer/httptunnel/util/DefaultTunnelIdGenerator.java
// public class DefaultTunnelIdGenerator implements TunnelIdGenerator {
// 
// 	private final SecureRandom generator;
// 
// 	/**
// 	 * Constructs a new instance using a new {@link SecureRandom} instance.
// 	 */
// 	public DefaultTunnelIdGenerator() {
// 		this(new SecureRandom());
// 	}
// 
// 	/**
// 	 * Constructs a new instance using the provided {@link SecureRandom} instance.
// 	 */
// 	public DefaultTunnelIdGenerator(SecureRandom generator) {
// 		this.generator = generator;
// 	}
// 
// 	@Override
// 	public synchronized String generateId() {
// 		// synchronized to ensure that this code is thread safe. The Sun
// 		// standard implementations seem to be synchronized or lock free
// 		// but are not documented as guaranteeing this
// 		return Integer.toHexString(generator.nextInt());
// 	}
// }
// 
// Path: src/main/java/com/yammer/httptunnel/util/TunnelIdGenerator.java
// public interface TunnelIdGenerator {
// 
// 	/**
// 	 * Generates the next tunnel ID to be used, which must be unique (i.e.
// 	 * ensure with high probability that it will not clash with an existing
// 	 * tunnel ID). This method must be thread safe, and preferably lock free.
// 	 */
// 	public String generateId();
// }


import java.util.Map;
import java.util.Map.Entry;
import org.jboss.netty.buffer.ChannelBufferFactory;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.channel.socket.ServerSocketChannel;
import org.jboss.netty.channel.socket.ServerSocketChannelConfig;
import com.yammer.httptunnel.util.DefaultTunnelIdGenerator;
import com.yammer.httptunnel.util.TunnelIdGenerator;
/*
 * Copyright 2011 The Netty Project
 *
 * The Netty Project licenses this file to you under the Apache License, version
 * 2.0 (the "License"); you may not use this file except in compliance with the
 * License. You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package com.yammer.httptunnel.server;




/**
 * Configuration for the server end of an HTTP tunnel. Any server socket channel
 * properties set here will be applied uniformly to the underlying server
 * channel, created from the channel factory provided to the
 * {@link HttpTunnelServerChannelFactory}.
 */
public class HttpTunnelServerChannelConfig implements ServerSocketChannelConfig {

	/**
	 * The default user-agent from which HTTP tunnel requests are allowed.
	 */
	public static final String DEFAULT_USER_AGENT = "HttpTunnel";

	static final String USER_AGENT_OPTION = "userAgent";
	static final String PIPELINE_FACTORY_OPTION = "pipelineFactory";
	static final String TUNNEL_ID_GENERATOR_OPTION = "tunnelIdGenerator";

	private static final String PROP_PKG = "org.jboss.netty.channel.socket.http.";

	private static final String PROP_UserAgent = PROP_PKG + USER_AGENT_OPTION;

	private String userAgent;
	private ServerSocketChannel realChannel;
	private TunnelIdGenerator tunnelIdGenerator;
	private ChannelPipelineFactory pipelineFactory;

	HttpTunnelServerChannelConfig() {
		userAgent = System.getProperty(PROP_UserAgent, DEFAULT_USER_AGENT);

		realChannel = null;
// Path: src/main/java/com/yammer/httptunnel/util/DefaultTunnelIdGenerator.java
// public class DefaultTunnelIdGenerator implements TunnelIdGenerator {
// 
// 	private final SecureRandom generator;
// 
// 	/**
// 	 * Constructs a new instance using a new {@link SecureRandom} instance.
// 	 */
// 	public DefaultTunnelIdGenerator() {
// 		this(new SecureRandom());
// 	}
// 
// 	/**
// 	 * Constructs a new instance using the provided {@link SecureRandom} instance.
// 	 */
// 	public DefaultTunnelIdGenerator(SecureRandom generator) {
// 		this.generator = generator;
// 	}
// 
// 	@Override
// 	public synchronized String generateId() {
// 		// synchronized to ensure that this code is thread safe. The Sun
// 		// standard implementations seem to be synchronized or lock free
// 		// but are not documented as guaranteeing this
// 		return Integer.toHexString(generator.nextInt());
// 	}
// }
// 
// Path: src/main/java/com/yammer/httptunnel/util/TunnelIdGenerator.java
// public interface TunnelIdGenerator {
// 
// 	/**
// 	 * Generates the next tunnel ID to be used, which must be unique (i.e.
// 	 * ensure with high probability that it will not clash with an existing
// 	 * tunnel ID). This method must be thread safe, and preferably lock free.
// 	 */
// 	public String generateId();
// }


// Path: src/main/java/com/yammer/httptunnel/server/HttpTunnelServerChannelConfig.java
import java.util.Map;
import java.util.Map.Entry;
import org.jboss.netty.buffer.ChannelBufferFactory;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.channel.socket.ServerSocketChannel;
import org.jboss.netty.channel.socket.ServerSocketChannelConfig;
import com.yammer.httptunnel.util.DefaultTunnelIdGenerator;
import com.yammer.httptunnel.util.TunnelIdGenerator;

/*
 * Copyright 2011 The Netty Project
 *
 * The Netty Project licenses this file to you under the Apache License, version
 * 2.0 (the "License"); you may not use this file except in compliance with the
 * License. You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package com.yammer.httptunnel.server;




/**
 * Configuration for the server end of an HTTP tunnel. Any server socket channel
 * properties set here will be applied uniformly to the underlying server
 * channel, created from the channel factory provided to the
 * {@link HttpTunnelServerChannelFactory}.
 */
public class HttpTunnelServerChannelConfig implements ServerSocketChannelConfig {

	/**
	 * The default user-agent from which HTTP tunnel requests are allowed.
	 */
	public static final String DEFAULT_USER_AGENT = "HttpTunnel";

	static final String USER_AGENT_OPTION = "userAgent";
	static final String PIPELINE_FACTORY_OPTION = "pipelineFactory";
	static final String TUNNEL_ID_GENERATOR_OPTION = "tunnelIdGenerator";

	private static final String PROP_PKG = "org.jboss.netty.channel.socket.http.";

	private static final String PROP_UserAgent = PROP_PKG + USER_AGENT_OPTION;

	private String userAgent;
	private ServerSocketChannel realChannel;
	private TunnelIdGenerator tunnelIdGenerator;
	private ChannelPipelineFactory pipelineFactory;

	HttpTunnelServerChannelConfig() {
		userAgent = System.getProperty(PROP_UserAgent, DEFAULT_USER_AGENT);

		realChannel = null;
		tunnelIdGenerator = new DefaultTunnelIdGenerator();