Пример #1
0
        /// <summary>
        /// Connect to the required service with the token
        /// </summary> 
        /// <param name="token">The token recevied from proxy</param>
        /// <param name="globalMeta">The global meta</param>
        /// <param name="logger">The logger</param>
        /// <param name="meta">The meta</param>
        /// <param name="properties">Property bag to add any information to</param>
        /// <param name="credmgr">Credentials manager</param>
        /// <returns>The connected data adapter</returns>
        public override IDataAdapter Connect(ProxyToken token, Logger logger, MetaDictionary meta, MetaDictionary globalMeta, PropertyBag properties, CredentialsManagerService credmgr)
        {
            IpProxyToken iptoken = token as IpProxyToken;

            if ((iptoken != null) && IsFiltered(iptoken))
            {
                return base.Connect(token, logger, meta, globalMeta, properties, credmgr);
            }
            else
            {
                token.Status = NetStatusCodes.Blocked;
                return null;
            }
        }
Пример #2
0
        /// <summary>
        /// Bind to the required service with the token
        /// </summary> 
        /// <param name="token">The token recevied from proxy</param>
        /// <param name="globalMeta">The global meta</param>
        /// <param name="logger">The logger</param>
        /// <param name="meta">The meta</param>
        /// <param name="properties">Property bag to add any information to</param>
        /// <param name="credmgr">Credentials manager</param>
        /// <returns>The connected data adapter</returns>
        public override IDataAdapter Bind(ProxyToken token, Logger logger, MetaDictionary meta, MetaDictionary globalMeta, PropertyBag properties, CredentialsManagerService credmgr)
        {
            IDataAdapter adapter = null;
            IpProxyToken iptoken = token as IpProxyToken;

            if (iptoken != null)
            {
                if (iptoken.ClientType == IpProxyToken.IpClientType.Tcp)
                {
                    adapter = BindTcp(iptoken, logger, properties);
                }
                else
                {
                    throw new ArgumentException(CANAPE.Net.Properties.Resources.IpProxyClient_InvalidTokenType);
                }
            }

            return adapter;
        }
Пример #3
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="packetLog"></param>
        /// <param name="listener"></param>
        /// <param name="factory"></param>
        /// <param name="logger"></param>
        /// <param name="globalMeta"></param>
        /// <param name="history"></param>
        /// <param name="credentials"></param>
        /// <param name="proxyServer"></param>
        /// <param name="proxyClient"></param>
        /// <param name="filters"></param>
        /// <param name="defaultTimeout"></param>
        /// <param name="afterdata"></param>
        public ProxyNetworkService(IList <LogPacket> packetLog, INetworkListener listener, NetGraphFactory factory, Logger logger,
                                   MetaDictionary globalMeta, IList <ConnectionHistoryEntry> history, IDictionary <SecurityPrincipal, ICredentialObject> credentials,
                                   ProxyServer proxyServer, ProxyClient proxyClient, ProxyFilter[] filters, int defaultTimeout, bool afterdata)
        {
            _packetLog = packetLog;
            _logger    = logger;
            Listener   = listener;

            _factory           = factory;
            _connections       = new List <ConnectionEntry>();
            _globalMeta        = globalMeta;
            _history           = history;
            _subServices       = new List <ProxyNetworkService>();
            DefaultBinding     = NetworkLayerBinding.Default;
            _credentials       = new Dictionary <SecurityPrincipal, ICredentialObject>(credentials);
            _credentialManager = new CredentialsManagerService();
            _credentialManager.ResolveCredentials += _credentialManager_ResolveCredentials;
            _proxyClient    = proxyClient;
            _proxyServer    = proxyServer;
            _filters        = filters;
            _defaultTimeout = defaultTimeout;
            _afterData      = afterdata;
        }
Пример #4
0
 // Bind and connect are the same thing
 public override IDataAdapter Bind(ProxyToken token, Logger logger, MetaDictionary meta, MetaDictionary globalMeta, PropertyBag properties, CredentialsManagerService credmgr)
 {
     return(new SerialPortDataAdapter(_config.Create()));
 }
Пример #5
0
        /// <summary>
        /// Bind to the required service with the token
        /// </summary>
        /// <param name="token">The token recevied from proxy</param>
        /// <param name="globalMeta">The global meta</param>
        /// <param name="logger">The logger</param>
        /// <param name="meta">The meta</param>
        /// <param name="properties">Property bag to add any information to</param>
        /// <param name="credmgr">Credentials manager</param>
        /// <returns>The connected data adapter</returns>
        public override IDataAdapter Bind(ProxyToken token, Logger logger, MetaDictionary meta, MetaDictionary globalMeta, PropertyBag properties, CredentialsManagerService credmgr)
        {
            IDataAdapter adapter = null;
            IpProxyToken iptoken = token as IpProxyToken;

            if (iptoken != null)
            {
                if (iptoken.ClientType == IpProxyToken.IpClientType.Tcp)
                {
                    adapter = BindTcp(iptoken, logger, properties);
                }
                else
                {
                    throw new ArgumentException(CANAPE.Net.Properties.Resources.IpProxyClient_InvalidTokenType);
                }
            }

            return(adapter);
        }
Пример #6
0
 public override IDataAdapter Connect(ProxyToken token, Logger logger, MetaDictionary meta, MetaDictionary globalMeta, PropertyBag properties, CredentialsManagerService credmgr)
 {
     return new HttpProxyClientDataAdapter(_server, _service, _server._logger);
 }
Пример #7
0
        /// <summary>
        /// Connect to the required service with the token
        /// </summary>
        /// <param name="token">The token recevied from proxy</param>
        /// <param name="globalMeta">The global meta</param>
        /// <param name="logger">The logger</param>
        /// <param name="meta">The meta</param>
        /// <param name="properties">Property bag to add any information to</param>
        /// <param name="credmgr">Credentials manager</param>
        /// <returns>The connected data adapter</returns>
        public override IDataAdapter Connect(ProxyToken token, Logger logger, MetaDictionary meta, MetaDictionary globalMeta, PropertyBag properties, CredentialsManagerService credmgr)
        {
            IDataAdapter ret = null;

            token.Status = NetStatusCodes.ConnectFailure;

            if ((token is IpProxyToken) && ((IpProxyToken)token).ClientType == IpProxyToken.IpClientType.Tcp)
            {
                TcpClient client = new TcpClient();

                try
                {
                    client.Connect(_hostname, _port);

                    if (token is FullHttpProxyToken)
                    {
                        bool binary = false;

                        if ((token.Layers != null) && (token.Layers.Length > 0))
                        {
                            foreach (INetworkLayer layer in token.Layers)
                            {
                                // Find a binding layer
                                if (layer.Binding == NetworkLayerBinding.Client ||
                                    layer.Binding == NetworkLayerBinding.ClientAndServer ||
                                    layer.Binding == NetworkLayerBinding.Default)
                                {
                                    if (!(layer is HttpNetworkLayer))
                                    {
                                        binary = true;
                                    }

                                    break;
                                }
                            }
                        }

                        if (!binary)
                        {
                            ret = new FullHttpProxyDataAdapter(client, (FullHttpProxyToken)token, IpProxyClient.GetDescription((IpProxyToken)token), logger);
                            NetUtils.PopulateBagFromSocket(client.Client, properties);
                            token.Status = NetStatusCodes.Success;
                        }
                        else
                        {
                            ConnectWithIpProxyToken(client.GetStream(), (IpProxyToken)token, logger);
                            if (token.Status == NetStatusCodes.Success)
                            {
                                NetUtils.PopulateBagFromSocket(client.Client, properties);
                                ret = new TcpClientDataAdapter(client, IpProxyClient.GetDescription((IpProxyToken)token));
                            }
                        }
                    }
                    else
                    {
                        if (token is HttpProxyToken)
                        {
                            ConnectWithHttpProxyToken(client.GetStream(), (HttpProxyToken)token, logger);
                        }
                        else
                        {
                            ConnectWithIpProxyToken(client.GetStream(), (IpProxyToken)token, logger);
                        }

                        if (token.Status == NetStatusCodes.Success)
                        {
                            NetUtils.PopulateBagFromSocket(client.Client, properties);
                            ret = new TcpClientDataAdapter(client, IpProxyClient.GetDescription((IpProxyToken)token));
                        }
                    }
                }
                catch (SocketException ex)
                {
                    logger.LogException(ex);
                    token.Status = NetStatusCodes.ConnectFailure;
                }
                catch (IOException ex)
                {
                    logger.LogException(ex);
                    token.Status = NetStatusCodes.ConnectFailure;
                }
                finally
                {
                    if (ret == null)
                    {
                        client.Close();
                    }
                }
            }
            else
            {
                throw new ArgumentException(CANAPE.Net.Properties.Resources.HttpProxyClient_InvalidProxyToken);
            }

            return(ret);
        }
Пример #8
0
 public override IDataAdapter Bind(ProxyToken token, Logger logger, MetaDictionary meta, MetaDictionary globalMeta, PropertyBag properties, CredentialsManagerService credmgr)
 {
     return null;
 }
Пример #9
0
 public override IDataAdapter Bind(ProxyToken token, Logger logger, MetaDictionary meta, MetaDictionary globalMeta, PropertyBag properties, CredentialsManagerService credmgr)
 {
     return(null);
 }
Пример #10
0
        /// <summary>
        /// Connect the client
        /// </summary>
        /// <param name="token">The proxy token</param>
        /// <param name="logger">The proxy logger instance</param>
        /// <param name="meta">The proxy meta data</param>
        /// <param name="globalMeta">The proxy global meta data</param>
        /// <param name="properties">The proxy property bag</param>
        /// <param name="credmgr">Credentials manager</param>
        /// <returns>The connected adapter</returns>
        public override IDataAdapter Connect(ProxyToken token, Logger logger, MetaDictionary meta, MetaDictionary globalMeta, PropertyBag properties, CredentialsManagerService credmgr)
        {
            IDataAdapter ret = null;

            for (int i = 0; i < _clients.Length; ++i)
            {
                ret = _clients[i].Connect(token, logger, meta, globalMeta, properties, credmgr);

                if (ret != null)
                {
                    break;
                }
            }

            if ((ret == null) && (token.Status == NetStatusCodes.Success))
            {
                ret = new IpProxyClient().Connect(token, logger, meta, globalMeta, properties, credmgr);
            }

            return(ret);
        }
Пример #11
0
 /// <summary>
 /// Connect to the required service with the token
 /// </summary> 
 /// <param name="token">The token recevied from proxy</param>
 /// <param name="globalMeta">The global meta</param>
 /// <param name="logger">The logger</param>
 /// <param name="meta">The meta</param>
 /// <param name="properties">Property bag to add any information to</param>        
 /// <param name="credmgr">Credentials manager</param>
 /// <returns>The connected data adapter</returns>
 public abstract IDataAdapter Connect(ProxyToken token, Logger logger, MetaDictionary meta, MetaDictionary globalMeta, PropertyBag properties, CredentialsManagerService credmgr);
Пример #12
0
 public override IDataAdapter Connect(ProxyToken token, Logger logger, MetaDictionary meta, MetaDictionary globalMeta, PropertyBag properties, CredentialsManagerService credmgr)
 {
     return new StreamDataAdapter(new NamedPipeClientStream(".", _pipeName, PipeDirection.InOut));
 }
Пример #13
0
 public override CANAPE.DataAdapters.IDataAdapter Bind(ProxyToken token, Logger logger, MetaDictionary meta, MetaDictionary globalMeta, PropertyBag properties, CredentialsManagerService credmgr)
 {
     throw new NotImplementedException();
 }
Пример #14
0
 public override IDataAdapter Connect(ProxyToken token, Logger logger, MetaDictionary meta, MetaDictionary globalMeta, PropertyBag properties, CredentialsManagerService credmgr)
 {
     return(new HttpProxyClientDataAdapter(_server, _service, _server._logger));
 }
Пример #15
0
 public override CANAPE.DataAdapters.IDataAdapter Bind(ProxyToken token, Logger logger, MetaDictionary meta, MetaDictionary globalMeta, PropertyBag properties, CredentialsManagerService credmgr)
 {
     throw new NotImplementedException();
 }
Пример #16
0
 public override IDataAdapter Connect(ProxyToken token, Logger logger, MetaDictionary meta, MetaDictionary globalMeta, PropertyBag properties, CredentialsManagerService credmgr)
 {
     return(new StreamDataAdapter(new NamedPipeClientStream(".", _pipeName, PipeDirection.InOut)));
 }
Пример #17
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="packetLog"></param>
        /// <param name="listener"></param>
        /// <param name="factory"></param>
        /// <param name="logger"></param>
        /// <param name="globalMeta"></param>
        /// <param name="history"></param>
        /// <param name="credentials"></param>
        /// <param name="proxyServer"></param>
        /// <param name="proxyClient"></param>
        /// <param name="filters"></param>
        /// <param name="defaultTimeout"></param>
        /// <param name="afterdata"></param>
        public ProxyNetworkService(IList<LogPacket> packetLog, INetworkListener listener, NetGraphFactory factory, Logger logger, 
            MetaDictionary globalMeta, IList<ConnectionHistoryEntry> history, IDictionary<SecurityPrincipal, ICredentialObject> credentials, 
            ProxyServer proxyServer, ProxyClient proxyClient, ProxyFilter[] filters, int defaultTimeout, bool afterdata)
        {
            _packetLog = packetLog;
            _logger = logger;
            Listener = listener;

            _factory = factory;
            _connections = new List<ConnectionEntry>();
            _globalMeta = globalMeta;
            _history = history;
            _subServices = new List<ProxyNetworkService>();
            DefaultBinding = NetworkLayerBinding.Default;
            _credentials = new Dictionary<SecurityPrincipal, ICredentialObject>(credentials);
            _credentialManager = new CredentialsManagerService();
            _credentialManager.ResolveCredentials += _credentialManager_ResolveCredentials;
            _proxyClient = proxyClient;
            _proxyServer = proxyServer;
            _filters = filters;
            _defaultTimeout = defaultTimeout;
            _afterData = afterdata;
        }
Пример #18
0
 public override IDataAdapter Connect(ProxyToken token, Logger logger, MetaDictionary meta, MetaDictionary globalMeta, PropertyBag properties, CredentialsManagerService credmgr)
 {
     return new SerialPortDataAdapter(_config.Create());
 }
Пример #19
0
        /// <summary>
        /// Connection to the socks server
        /// </summary>
        /// <param name="token">The proxy token</param>
        /// <param name="logger">Logger</param>
        /// <param name="globalMeta">Global meta</param>
        /// <param name="meta">Meta</param>
        /// <param name="credmgr">Credentials manager</param>
        /// <param name="properties">Property bag to populate</param>
        /// <returns>A connected data adapter, or null if not available</returns>
        /// <exception cref="SocketException">Throw if cannot connect</exception>
        /// <exception cref="ArgumentException">Throw if invalid operation occurs</exception>
        /// <exception cref="EndOfStreamException">Throw if stream ends before reading all data</exception>
        public override IDataAdapter Connect(ProxyToken token, Logger logger, MetaDictionary meta, MetaDictionary globalMeta, PropertyBag properties, CredentialsManagerService credmgr)
        {
            IDataAdapter ret = null;

            if (token is IpProxyToken)
            {
                IpProxyToken iptoken = token as IpProxyToken;
                TcpClient client = new TcpClient();

                try
                {
                    client.Connect(_hostname, _port);

                    if (_version == SupportedVersion.Version4)
                    {
                        if (_sendHostName && !String.IsNullOrWhiteSpace(iptoken.Hostname))
                        {
                            ConnectVersion4a(client.GetStream(), iptoken, logger);
                        }
                        else
                        {
                            ConnectVersion4(client.GetStream(), iptoken, logger);
                        }
                    }
                    else
                    {
                        ConnectVersion5(client.GetStream(), iptoken, logger);
                    }

                    if (iptoken.Status == NetStatusCodes.Success)
                    {
                        NetUtils.PopulateBagFromSocket(client.Client, properties);

                        ret = new TcpClientDataAdapter(client, IpProxyClient.GetDescription((IpProxyToken)token));
                    }
                }
                catch (SocketException ex)
                {
                    logger.LogException(ex);
                    token.Status = NetStatusCodes.ConnectFailure;
                }
                catch (IOException ex)
                {
                    logger.LogException(ex);
                    token.Status = NetStatusCodes.ConnectFailure;
                }
                finally
                {
                    if (ret == null)
                    {
                        client.Close();
                    }
                }
            }
            else
            {
                throw new ArgumentException(CANAPE.Net.Properties.Resources.SocksProxyClient_InvalidProxyToken3);
            }

            return ret;
        }
Пример #20
0
 /// <summary>
 /// Connect to the required service with the token
 /// </summary> 
 /// <param name="token">The token recevied from proxy</param>
 /// <param name="globalMeta">The global meta</param>
 /// <param name="logger">The logger</param>
 /// <param name="meta">The meta</param>
 /// <param name="properties">Property bag to add any information to</param>
 /// <param name="credmgr">Credentials manager</param>
 /// <returns>The connected data adapter</returns>
 public override IDataAdapter Connect(ProxyToken token, Logger logger, MetaDictionary meta, MetaDictionary globalMeta, PropertyBag properties, CredentialsManagerService credmgr)
 {
     return BuildProxyClient(token, logger).Connect(token, logger, meta, globalMeta, properties, credmgr);
 }
Пример #21
0
        /// <summary>
        /// Connect the client
        /// </summary>
        /// <param name="token">The proxy token</param>
        /// <param name="logger">The proxy logger instance</param>
        /// <param name="meta">The proxy meta data</param>
        /// <param name="globalMeta">The proxy global meta data</param>
        /// <param name="properties">The proxy property bag</param>
        /// <param name="credmgr">Credentials manager</param>
        /// <returns>The connected adapter</returns>
        public override IDataAdapter Connect(ProxyToken token, Logger logger, MetaDictionary meta, MetaDictionary globalMeta, PropertyBag properties, CredentialsManagerService credmgr)
        {
            IDataAdapter ret = null;

            for (int i = 0; i < _clients.Length; ++i)
            {
                ret = _clients[i].Connect(token, logger, meta, globalMeta, properties, credmgr);

                if (ret != null)
                {
                    break;
                }
            }

            if ((ret == null) && (token.Status == NetStatusCodes.Success))
            {
                ret = new IpProxyClient().Connect(token, logger, meta, globalMeta, properties, credmgr);
            }

            return ret;
        }
Пример #22
0
        /// <summary>
        /// Connection to the socks server
        /// </summary>
        /// <param name="token">The proxy token</param>
        /// <param name="logger">Logger</param>
        /// <param name="globalMeta">Global meta</param>
        /// <param name="meta">Meta</param>
        /// <param name="credmgr">Credentials manager</param>
        /// <param name="properties">Property bag to populate</param>
        /// <returns>A connected data adapter, or null if not available</returns>
        /// <exception cref="SocketException">Throw if cannot connect</exception>
        /// <exception cref="ArgumentException">Throw if invalid operation occurs</exception>
        /// <exception cref="EndOfStreamException">Throw if stream ends before reading all data</exception>
        public override IDataAdapter Connect(ProxyToken token, Logger logger, MetaDictionary meta, MetaDictionary globalMeta, PropertyBag properties, CredentialsManagerService credmgr)
        {
            IDataAdapter ret = null;

            if (token is IpProxyToken)
            {
                IpProxyToken iptoken = token as IpProxyToken;
                TcpClient    client  = new TcpClient();

                try
                {
                    client.Connect(_hostname, _port);

                    if (_version == SupportedVersion.Version4)
                    {
                        if (_sendHostName && !String.IsNullOrWhiteSpace(iptoken.Hostname))
                        {
                            ConnectVersion4a(client.GetStream(), iptoken, logger);
                        }
                        else
                        {
                            ConnectVersion4(client.GetStream(), iptoken, logger);
                        }
                    }
                    else
                    {
                        ConnectVersion5(client.GetStream(), iptoken, logger);
                    }

                    if (iptoken.Status == NetStatusCodes.Success)
                    {
                        NetUtils.PopulateBagFromSocket(client.Client, properties);

                        ret = new TcpClientDataAdapter(client, IpProxyClient.GetDescription((IpProxyToken)token));
                    }
                }
                catch (SocketException ex)
                {
                    logger.LogException(ex);
                    token.Status = NetStatusCodes.ConnectFailure;
                }
                catch (IOException ex)
                {
                    logger.LogException(ex);
                    token.Status = NetStatusCodes.ConnectFailure;
                }
                finally
                {
                    if (ret == null)
                    {
                        client.Close();
                    }
                }
            }
            else
            {
                throw new ArgumentException(CANAPE.Net.Properties.Resources.SocksProxyClient_InvalidProxyToken3);
            }

            return(ret);
        }
Пример #23
0
 public override IDataAdapter Connect(ProxyToken token, Logger logger, MetaDictionary meta, MetaDictionary globalMeta, PropertyBag properties, CredentialsManagerService credmgr)
 {
     return(new DataEndpointAdapter(_factory.Create(logger, meta, globalMeta), logger));
 }
Пример #24
0
 /// <summary>
 /// Connect to the required service with the token
 /// </summary>
 /// <param name="token">The token recevied from proxy</param>
 /// <param name="globalMeta">The global meta</param>
 /// <param name="logger">The logger</param>
 /// <param name="meta">The meta</param>
 /// <param name="properties">Property bag to add any information to</param>
 /// <param name="credmgr">Credentials manager</param>
 /// <returns>The connected data adapter</returns>
 public override IDataAdapter Connect(ProxyToken token, Logger logger, MetaDictionary meta, MetaDictionary globalMeta, PropertyBag properties, CredentialsManagerService credmgr)
 {
     // Just use the underlying code to do it for us
     return(base.Connect(new IpProxyToken(null, _hostname, _port, _clientType, _ipv6), logger, meta, globalMeta, properties, credmgr));
 }
Пример #25
0
 /// <summary>
 /// Bind to the required service with the token
 /// </summary>
 /// <param name="token">The token recevied from proxy</param>
 /// <param name="globalMeta">The global meta</param>
 /// <param name="logger">The logger</param>
 /// <param name="meta">The meta</param>
 /// <param name="properties">Property bag to add any information to</param>
 /// <param name="credmgr">Credentials manager</param>
 /// <returns>The connected data adapter</returns>
 public override IDataAdapter Bind(ProxyToken token, Logger logger, MetaDictionary meta, MetaDictionary globalMeta, PropertyBag properties, CredentialsManagerService credmgr)
 {
     return(BuildProxyClient(token, logger).Bind(token, logger, meta, globalMeta, properties, credmgr));
 }
Пример #26
0
        /// <summary>
        /// Connect to the required service with the token
        /// </summary>
        /// <param name="token">The token recevied from proxy</param>
        /// <param name="globalMeta">The global meta</param>
        /// <param name="logger">The logger</param>
        /// <param name="meta">The meta</param>
        /// <param name="properties">Property bag to add any information to</param>
        /// <param name="credmgr">Credentials manager</param>
        /// <returns>The connected data adapter</returns>
        public override IDataAdapter Connect(ProxyToken token, Logger logger, MetaDictionary meta, MetaDictionary globalMeta, PropertyBag properties, CredentialsManagerService credmgr)
        {
            IpProxyToken iptoken = token as IpProxyToken;

            if ((iptoken != null) && IsFiltered(iptoken))
            {
                return(base.Connect(token, logger, meta, globalMeta, properties, credmgr));
            }
            else
            {
                token.Status = NetStatusCodes.Blocked;
                return(null);
            }
        }
Пример #27
0
 public override IDataAdapter Connect(ProxyToken token, Logger logger, MetaDictionary meta, MetaDictionary globalMeta, PropertyBag properties, CredentialsManagerService credmgr)
 {
     return new DataEndpointAdapter(_factory.Create(logger, meta, globalMeta), logger);
 }
Пример #28
0
 /// <summary>
 /// Connect to the required service with the token
 /// </summary> 
 /// <param name="token">The token recevied from proxy</param>
 /// <param name="globalMeta">The global meta</param>
 /// <param name="logger">The logger</param>
 /// <param name="meta">The meta</param>
 /// <param name="properties">Property bag to add any information to</param>
 /// <param name="credmgr">Credentials manager</param>
 /// <returns>The connected data adapter</returns>
 public override IDataAdapter Connect(ProxyToken token, Logger logger, MetaDictionary meta, MetaDictionary globalMeta, PropertyBag properties, CredentialsManagerService credmgr)
 {
     // Just use the underlying code to do it for us
     return base.Connect(new IpProxyToken(null, _hostname, _port, _clientType, _ipv6), logger, meta, globalMeta, properties, credmgr);
 }
Пример #29
0
 /// <summary>
 /// Bind to the required service with the token
 /// </summary>
 /// <param name="token">The token recevied from proxy</param>
 /// <param name="globalMeta">The global meta</param>
 /// <param name="logger">The logger</param>
 /// <param name="meta">The meta</param>
 /// <param name="properties">Property bag to add any information to</param>
 /// <param name="credmgr">Credentials manager</param>
 /// <returns>The connected data adapter</returns>
 public abstract IDataAdapter Bind(ProxyToken token, Logger logger, MetaDictionary meta, MetaDictionary globalMeta, PropertyBag properties, CredentialsManagerService credmgr);
Пример #30
0
        /// <summary>
        /// Connect to the required service with the token
        /// </summary> 
        /// <param name="token">The token recevied from proxy</param>
        /// <param name="globalMeta">The global meta</param>
        /// <param name="logger">The logger</param>
        /// <param name="meta">The meta</param>
        /// <param name="properties">Property bag to add any information to</param>
        /// <param name="credmgr">Credentials manager</param>
        /// <returns>The connected data adapter</returns>
        public override IDataAdapter Connect(ProxyToken token, Logger logger, MetaDictionary meta, MetaDictionary globalMeta, PropertyBag properties, CredentialsManagerService credmgr)
        {
            IDataAdapter ret = null;

            token.Status = NetStatusCodes.ConnectFailure;

            if ((token is IpProxyToken) && ((IpProxyToken)token).ClientType == IpProxyToken.IpClientType.Tcp)
            {
                TcpClient client = new TcpClient();

                try
                {
                    client.Connect(_hostname, _port);

                    if (token is FullHttpProxyToken)
                    {
                        bool binary = false;

                        if ((token.Layers != null) && (token.Layers.Length > 0))
                        {
                            foreach (INetworkLayer layer in token.Layers)
                            {
                                // Find a binding layer
                                if (layer.Binding == NetworkLayerBinding.Client
                                    || layer.Binding == NetworkLayerBinding.ClientAndServer
                                    || layer.Binding == NetworkLayerBinding.Default)
                                {
                                    if (!(layer is HttpNetworkLayer))
                                    {
                                        binary = true;
                                    }

                                    break;
                                }
                            }
                        }

                        if (!binary)
                        {
                            ret = new FullHttpProxyDataAdapter(client, (FullHttpProxyToken)token, IpProxyClient.GetDescription((IpProxyToken)token), logger);
                            NetUtils.PopulateBagFromSocket(client.Client, properties);
                            token.Status = NetStatusCodes.Success;
                        }
                        else
                        {
                            ConnectWithIpProxyToken(client.GetStream(), (IpProxyToken)token, logger);
                            if (token.Status == NetStatusCodes.Success)
                            {
                                NetUtils.PopulateBagFromSocket(client.Client, properties);
                                ret = new TcpClientDataAdapter(client, IpProxyClient.GetDescription((IpProxyToken)token));
                            }
                        }
                    }
                    else
                    {
                        if (token is HttpProxyToken)
                        {
                            ConnectWithHttpProxyToken(client.GetStream(), (HttpProxyToken)token, logger);
                        }
                        else
                        {
                            ConnectWithIpProxyToken(client.GetStream(), (IpProxyToken)token, logger);
                        }

                        if (token.Status == NetStatusCodes.Success)
                        {
                            NetUtils.PopulateBagFromSocket(client.Client, properties);
                            ret = new TcpClientDataAdapter(client, IpProxyClient.GetDescription((IpProxyToken)token));
                        }
                    }
                }
                catch (SocketException ex)
                {
                    logger.LogException(ex);
                    token.Status = NetStatusCodes.ConnectFailure;
                }
                catch (IOException ex)
                {
                    logger.LogException(ex);
                    token.Status = NetStatusCodes.ConnectFailure;
                }
                finally
                {
                    if (ret == null)
                    {
                        client.Close();
                    }
                }
            }
            else
            {
                throw new ArgumentException(CANAPE.Net.Properties.Resources.HttpProxyClient_InvalidProxyToken);
            }

            return ret;
        }