Ejemplo n.º 1
0
		public ProxyClientListenerTask(ProxyConfig config)
		{
			Console.WriteLine("ProxyClientListenerTask {0} created.", this);
			m_config = config;
			logger = Logger.getInstance();
		}
Ejemplo n.º 2
0
		public bool loadConfiguration()
		{

			try
			{
				using (StreamReader sr = new StreamReader(initFilePath))
				{
					String line;

					String listenHost=null;
					String targetHost=null;
					String serviceName=null;
					int idx = 0 ;

					while ((line = sr.ReadLine()) != null)
					{
						line.Trim();
						//skip comments or blank lines.
						if (line.StartsWith("#") || line.Length==0)
						{
							continue;
						}
						else if (line.StartsWith("["))
						{
							idx = line.LastIndexOf("]");
							serviceName = line.Substring(1, idx-1).Trim();
						}
						else if (line.StartsWith("accept"))
						{	
							idx = line.IndexOf("=") + 1;
							listenHost = line.Substring(idx).Trim();
						}
						else if (line.StartsWith("connect"))
						{
							idx = line.IndexOf("=") + 1;
							targetHost = line.Substring(idx).Trim();
							if (serviceName.Length > 0 && targetHost.Length > 0 && listenHost.Length > 0)
							{
								String listenPort;
								String listenIP;
								String targetPort;
								String targetIP;

								ProxyConfig cfg = new ProxyConfig();
								cfg.serviceName = serviceName;

								idx = listenHost.IndexOf(":");
								if (idx > 0)
								{
									listenIP = listenHost.Substring(0, idx);
									listenPort = listenHost.Substring(idx+1);
									cfg.localEP = new IPEndPoint(IPAddress.Parse(listenIP), Int32.Parse(listenPort));
								}
								else
								{
									listenPort = listenHost;
									cfg.localEP = new IPEndPoint(IPAddress.Any, Int32.Parse(listenPort));
								}

								idx = targetHost.IndexOf(":");
								targetIP = targetHost.Substring(0, idx);
								targetPort = targetHost.Substring(idx+1);
								cfg.serverEP = new IPEndPoint(IPAddress.Parse(targetIP), Int32.Parse(targetPort));

								m_proxyConfigs.Add(cfg);
								logger.debug("Loaded Proxy config: " + cfg.asString());

								//clear out values
								serviceName = null;
								targetHost = null;
								listenHost = null;
							}
						}
						else if (line.IndexOf("=") > 0)
						{
							idx = line.IndexOf("=");
							String key = line.Substring(0, idx);
							String param = line.Substring(idx+1);
							m_params.Add(key, param);
						}
						else
						{
							logger.warn("Ignoring unknown configuration line: {0}.", line);
						}
					}
				}

				return true;
			}
			catch (Exception e)
			{
				logger.error("Unable to read configuration file: {0}", configFile);
				logger.error("The exception is {0}.", e);
			}

			return false;
		}
Ejemplo n.º 3
0
 public ProxyClientListenerTask(ProxyConfig config)
 {
     Console.WriteLine("ProxyClientListenerTask {0} created.", this);
     m_config = config;
     logger   = Logger.getInstance();
 }
Ejemplo n.º 4
0
        public bool loadConfiguration()
        {
            try
            {
                using (StreamReader sr = new StreamReader(initFilePath))
                {
                    String line;

                    String listenHost  = null;
                    String targetHost  = null;
                    String serviceName = null;
                    int    idx         = 0;

                    while ((line = sr.ReadLine()) != null)
                    {
                        line.Trim();
                        //skip comments or blank lines.
                        if (line.StartsWith("#") || line.Length == 0)
                        {
                            continue;
                        }
                        else if (line.StartsWith("["))
                        {
                            idx         = line.LastIndexOf("]");
                            serviceName = line.Substring(1, idx - 1).Trim();
                        }
                        else if (line.StartsWith("accept"))
                        {
                            idx        = line.IndexOf("=") + 1;
                            listenHost = line.Substring(idx).Trim();
                        }
                        else if (line.StartsWith("connect"))
                        {
                            idx        = line.IndexOf("=") + 1;
                            targetHost = line.Substring(idx).Trim();
                            if (serviceName.Length > 0 && targetHost.Length > 0 && listenHost.Length > 0)
                            {
                                String listenPort;
                                String listenIP;
                                String targetPort;
                                String targetIP;

                                ProxyConfig cfg = new ProxyConfig();
                                cfg.serviceName = serviceName;

                                idx = listenHost.IndexOf(":");
                                if (idx > 0)
                                {
                                    listenIP    = listenHost.Substring(0, idx);
                                    listenPort  = listenHost.Substring(idx + 1);
                                    cfg.localEP = new IPEndPoint(IPAddress.Parse(listenIP), Int32.Parse(listenPort));
                                }
                                else
                                {
                                    listenPort  = listenHost;
                                    cfg.localEP = new IPEndPoint(IPAddress.Any, Int32.Parse(listenPort));
                                }

                                idx          = targetHost.IndexOf(":");
                                targetIP     = targetHost.Substring(0, idx);
                                targetPort   = targetHost.Substring(idx + 1);
                                cfg.serverEP = new IPEndPoint(IPAddress.Parse(targetIP), Int32.Parse(targetPort));

                                m_proxyConfigs.Add(cfg);
                                logger.debug("Loaded Proxy config: " + cfg.asString());

                                //clear out values
                                serviceName = null;
                                targetHost  = null;
                                listenHost  = null;
                            }
                        }
                        else if (line.IndexOf("=") > 0)
                        {
                            idx = line.IndexOf("=");
                            String key   = line.Substring(0, idx);
                            String param = line.Substring(idx + 1);
                            m_params.Add(key, param);
                        }
                        else
                        {
                            logger.warn("Ignoring unknown configuration line: {0}.", line);
                        }
                    }
                }

                return(true);
            }
            catch (Exception e)
            {
                logger.error("Unable to read configuration file: {0}", configFile);
                logger.error("The exception is {0}.", e);
            }

            return(false);
        }