ret->negotiate = NULL;
Socket new_connection(SockAddr addr, char *hostname,		      int port, int privport,		      int oobinline, int nodelay, Plug plug){    static struct socket_function_table socket_fn_table = {	sk_proxy_plug,	sk_proxy_close,	sk_proxy_write,	sk_proxy_write_oob,	sk_proxy_flush,	sk_proxy_set_private_ptr,	sk_proxy_get_private_ptr,	sk_proxy_set_frozen,	sk_proxy_socket_error    };    static struct plug_function_table plug_fn_table = {	plug_proxy_closing,	plug_proxy_receive,	plug_proxy_sent,	plug_proxy_accepting    };    if (cfg.proxy_type != PROXY_NONE &&	proxy_for_destination(addr, hostname, port))    {	Proxy_Socket ret;	Proxy_Plug pplug;	SockAddr proxy_addr;	char * proxy_canonical_name;	ret = smalloc(sizeof(struct Socket_proxy_tag));	ret->fn = &socket_fn_table;	ret->plug = plug;	ret->remote_addr = addr;	ret->remote_port = port;	/* XXX review these initialisations, and initialise other fields	 * in Proxy_Socket structure */	ret->error = NULL;	ret->pending_flush = 0;	ret->freeze = 0;	bufchain_init(&ret->pending_input_data);	bufchain_init(&ret->pending_output_data);	bufchain_init(&ret->pending_oob_output_data);	ret->sub_socket = NULL;	ret->state = PROXY_STATE_NEW;	if (cfg.proxy_type == PROXY_HTTP) {	    ret->negotiate = proxy_http_negotiate;	} else if (cfg.proxy_type == PROXY_SOCKS) {	    if (cfg.proxy_socks_version == 4)		ret->negotiate = proxy_socks4_negotiate;	    else		ret->negotiate = proxy_socks5_negotiate;	} else if (cfg.proxy_type == PROXY_TELNET) {	    ret->negotiate = proxy_telnet_negotiate;	} else {	    ret->error = "Proxy error: Unknown proxy method";	    return (Socket) ret;	}	/* create the proxy plug to map calls from the actual	 * socket into our proxy socket layer */	pplug = smalloc(sizeof(struct Plug_proxy_tag));	pplug->fn = &plug_fn_table;	pplug->proxy_socket = ret;	/* look-up proxy */	proxy_addr = sk_namelookup(cfg.proxy_host,				   &proxy_canonical_name);	sfree(proxy_canonical_name);	/* create the actual socket we will be using,	 * connected to our proxy server and port.	 */	ret->sub_socket = sk_new(proxy_addr, cfg.proxy_port,				 privport, oobinline,				 nodelay, (Plug) pplug);	if (sk_socket_error(ret->sub_socket) != NULL)	    return (Socket) ret;	sk_addr_free(proxy_addr);	/* start the proxy negotiation process... */	sk_set_frozen(ret->sub_socket, 0);	ret->negotiate(ret, PROXY_CHANGE_NEW);	return (Socket) ret;    }    /* no proxy, so just return the direct socket */    return sk_new(addr, port, privport, oobinline, nodelay, plug);}