Exemplo n.º 1
0
        private void SetNodeName()
        {
            int p = HostName.IndexOf('.');

            if (p < 0)
            {
                NodeName = HostName;
                NbtName  = HostName; // If there are no dots, assume it's a netbios name
            }
            else // if it has dot's assume it's a dns name
            {
                NodeName = HostName.Substring(0, p);

                NbtName = NodeName; // assume the nodename is a dns one

                if (NbtName.Length > 15)
                {
                    NbtName = NbtName.Substring(0, 15); // truncate down to 15 if needed
                }
                // Pad upto 15 if needed, and add to 16
                //fNBTName.PadRight(16, (char)0x20);

                while (NbtName.Length < 16)
                {
                    byte pad = 0x20;

                    NbtName += (char)pad;
                }
            }
        }
Exemplo n.º 2
0
        public BasicHttpBinding GetBinding()
        {
            var securityMode   = BasicHttpSecurityMode.None;
            var credentialType = HttpClientCredentialType.None;

            if (HostName.IndexOf(@"https://", StringComparison.OrdinalIgnoreCase) >= 0)
            {
                securityMode = BasicHttpSecurityMode.Transport;
            }
            else if (UseWindowsAuth)
            {
                securityMode   = BasicHttpSecurityMode.TransportCredentialOnly;
                credentialType = HttpClientCredentialType.Windows;
            }

            var result = new BasicHttpBinding(securityMode)
            {
                HostNameComparisonMode = HostNameComparisonMode,
                ReceiveTimeout         = ReceiveTimeout,
                SendTimeout            = SendTimeout,
                OpenTimeout            = OpenTimeout,
                CloseTimeout           = CloseTimeout,
                MaxBufferSize          = MaxBufferSize,
                MaxBufferPoolSize      = MaxBufferPoolSize,
                MaxReceivedMessageSize = MaxReceivedMessageSize,
                TransferMode           = TransferMode,
                MessageEncoding        = MessageEncoding,
                TextEncoding           = TextEncoding,
                BypassProxyOnLocal     = BypassProxyOnLocal,
                UseDefaultWebProxy     = UseDefaultWebProxy,
                ReaderQuotas           =
                {
                    MaxStringContentLength = MaxStringContentLength
                },
                ProxyAddress = ProxyAddress,
                AllowCookies = true
            };

            result.Security.Transport.ClientCredentialType = credentialType;

            return(result);
        }
Exemplo n.º 3
0
        public void Connect(string userName, string userPassword, string userResource, string serverName = null, string oAuthToken = null)
        {
            Jid            = XmppJid.Empty;
            UserName       = userName;
            UserPassword   = userPassword;
            UserResource   = userResource;
            UserOAuthToken = oAuthToken;
            ServerName     = string.IsNullOrWhiteSpace(serverName) ? HostName.Substring(HostName.IndexOf('.') + 1) : serverName;

            if (engine == null)
            {
                engine = new Thread(new ThreadStart(StartEngine));
                engine.IsBackground = true;
                engine.SetApartmentState(ApartmentState.STA);
            }

            engine.Start();
        }
Exemplo n.º 4
0
        /// <summary>
        /// The Jones client constructor
        /// </summary>
        /// <param name="service">Service Name</param>
        /// <param name="hostname">Hostname</param>
        /// <param name="zkclient">Zookeeper Client connection object</param>
        /// <param name="callback">Callback function for any changes to the config tree</param>
        public SimpleJonesClient(string service, string hostname = null, IZookClient zkclient = null, Action <Dictionary <string, string> > callback = null)
        {
            // initialize the hostname
            if (String.IsNullOrEmpty(hostname))
            {
                // get FDQN
                // http://stackoverflow.com/questions/804700/how-to-find-fqdn-of-local-machine-in-c-net
                // http://support.microsoft.com/kb/303902
                HostName = System.Net.Dns.GetHostEntry("LocalHost").HostName.ToLower();

                int idx = HostName.IndexOf(".");
                if (idx > 0)
                {
                    HostName = HostName.Substring(0, idx);
                }
            }

            if (zkclient != null)
            {
                _zkclient = zkclient;
            }

            // initialize the dictionary to hold the configurations
            Config = new Dictionary <string, string>();

            // set the service name
            ServiceName = service;

            // this is our callback for Config View ZNode changes, to refresh our
            // this.Config
            ConfigViewNodeChangeWatcher = new WatcherWrapper(e =>
            {
                _zkclient.GetData(e.Path, ConfigViewNodeChangeWatcher).ContinueWith(d =>
                {
                    string conf_data = Encoding.UTF8.GetString(d.Result.Data);

                    Config = DeserializeNodeMap(conf_data);

                    if (callback != null)
                    {
                        callback.Invoke(Config);
                    }
                });
            });

            NodeMapPath = String.Format(@"/services/{0}/nodemaps", ServiceName);

            #region get the current Config from the view

            string current_conf_path = "";
            var    tnm = _zkclient.GetData(NodeMapPath, false).ContinueWith(c =>
            {
                string conf_path_json = Encoding.UTF8.GetString(c.Result.Data);

                try
                {
                    current_conf_path = DeserializeNodeMap(conf_path_json)[HostName];
                }
                catch (Exception)
                {
                    // fail-safe default configs when there's no machine-specific config is found
                    current_conf_path = String.Format(@"/services/{0}/conf", ServiceName);
                }

                var td = _zkclient.GetData(current_conf_path, ConfigViewNodeChangeWatcher).ContinueWith(d =>
                {
                    // this part is important so this.Config will not be empty on constructor completion!
                    string conf_data = Encoding.UTF8.GetString(d.Result.Data);

                    Config = DeserializeNodeMap(conf_data);
                });

                td.Wait();     // synchronous wait
            });

            tnm.Wait(); // synchronous wait

            #endregion
        }
Exemplo n.º 5
0
        //�f�[�^�擾�i����f�[�^�́A�����������j
        public bool Recv(Logger logger, SockTcp tcpObj, int timeout, ILife iLife)
        {
            var buf = tcpObj.LineRecv(timeout, iLife);

            if (buf == null)
            {
                return(false);
            }
            buf = Inet.TrimCrlf(buf);

            _urlEncoding = MLang.GetEncoding(buf);//URL�G���R�[�h�̌`����ۑ�����

            //Ver5.9.8
            if (_urlEncoding == null)
            {
                var sb = new StringBuilder();
                for (int i = 0; i < buf.Length; i++)
                {
                    sb.Append(String.Format("0x{0:X},", buf[i]));
                }
                logger.Set(LogKind.Error, tcpObj, 9999, String.Format("_urlEncoding==null buf.Length={0} buf={1}", buf.Length, sb.ToString()));
                //���̂܂ܗ�O�֓˓�������
            }

            var str = _urlEncoding.GetString(buf);

            // ���\�b�h�EURI�E�o�[�W�����ɕ���
            //"GET http://hostname:port@user:pass/path/filename.ext?param HTTP/1.1"
            RequestStr = str;

            //(�󔒂ŕ�������)�@"GET <=> http://hostname:port@user:pass/path/filename.ext?param HTTP/1.1"
            var index = str.IndexOf(' ');

            if (index < 0) //Ver5.0.0-a8
            {
                return(false);
            }

            //(�O��) "GET"
            var methodStr = str.Substring(0, index);

            foreach (HttpMethod m in Enum.GetValues(typeof(HttpMethod)))
            {
                if (methodStr.ToUpper() == m.ToString().ToUpper())
                {
                    HttpMethod = m;
                    break;
                }
            }
            if (HttpMethod == HttpMethod.Unknown)
            {
                logger.Set(LogKind.Secure, tcpObj, 1, string.Format("{0}", RequestStr));//�T�|�[�g�O�̃��\�b�h�ł��i������p���ł��܂���j
                return(false);
            }
            if (HttpMethod == HttpMethod.Connect)
            {
                Protocol = ProxyProtocol.Ssl;
                Port     = 443;//�f�t�H���g�̃|�[�g�ԍ���443�ɂȂ�
            }

            //(�㔼) "http://*****:*****@user:pass/path/filename.ext?param HTTP/1.1"
            str = str.Substring(index + 1);


            //(�󔒂ŕ�������)�@"http://*****:*****@user:pass/path/filename.ext?param <=> HTTP/1.1"
            index = str.IndexOf(' ');
            if (index < 0) //Ver5.0.0-a8
            {
                return(false);
            }
            //(�㔼) "HTTP/1.1"
            HttpVer = str.Substring(index + 1);

            if (HttpVer != "HTTP/0.9" && HttpVer != "HTTP/1.0" && HttpVer != "HTTP/1.1")
            {
                logger.Set(LogKind.Secure, tcpObj, 2, RequestStr);//�T�|�[�g�O�̃o�[�W�����ł��i������p���ł��܂���j
                return(false);
            }

            //(�O��) "http://*****:*****@user:pass/path/filename.ext?param"
            str = str.Substring(0, index);

            if (Protocol == ProxyProtocol.Unknown)  //�v���g�R���擾
            //("://"�������)�@"http <=> hostname:port@user:pass/path/filename.ext?param <=> HTTP/1.1"
            {
                index = str.IndexOf("://");
                if (index < 0) //Ver5.0.0-a8
                {
                    return(false);
                }
                //(�O��) "http"
                var protocolStr = str.Substring(0, index);

                if (protocolStr.ToLower() == "ftp")
                {
                    Protocol = ProxyProtocol.Ftp; //�v���g�R����FTP�ɏC��
                    Port     = 21;                //FTP�ڑ��̃f�t�H���g�̃|�[�g�ԍ���21�ɂȂ�
                }
                else if (protocolStr.ToLower() != "http")
                {
                    //Ver5.6.7
                    //Msg.Show(MsgKind.Error,"�݌v�G���[�@Request.Recv()");
                    //�G���[�\����|�b�v�A�b�v���烍�O�ɕύX
                    logger.Set(LogKind.Error, tcpObj, 29, string.Format("protocolStr={0}", protocolStr));
                    return(false);
                }
                else
                {
                    Protocol = ProxyProtocol.Http;
                }
                //(�㔼) "hostname:port@user:pass/path/filename.ext?param"
                str = str.Substring(index + 3);
            }
            //(�ŏ���"/"�ŕ�������)�@"hostname:port@user:pass <=> /path/filename.ext?param"
            index    = str.IndexOf('/');
            HostName = str;
            if (0 <= index)
            {
                //(�O��) ""hostname:port@user:pass"
                HostName = str.Substring(0, index);

                //(�㔼) "/path/filename.ext?param"
                str = str.Substring(index);
            }
            else
            {
                // GET http://hostname HTTP/1.0 �̂悤�ɁA���[�g�f�B���N�g�����w�肳��Ă��Ȃ��ꍇ�̑Ώ�
                str = "/";
            }

            //�z�X�g�������Ƀ��[�U���F�p�X���[�h�������Ă���ꍇ�̏���
            index = HostName.IndexOf("@");
            if (0 <= index)
            {
                var userpass = HostName.Substring(0, index);

                //���[�U���F�p�X���[�h��j������
                HostName = HostName.Substring(index + 1);

                var i = userpass.IndexOf(':');
                if (i == -1)
                {
                    User = userpass;
                }
                else
                {
                    User = userpass.Substring(0, i);
                    Pass = userpass.Substring(i + 1);
                }
            }
            //Ver5.1.2 IPv6�A�h���X�\�L�̃z�X�g���ɑΉ�
            var tmp = HostName.Split(new[] { '[', ']' });

            if (tmp.Length == 3) //IPv6�A�h���X�\�L�ł���Ɣ��f����
            {
                HostName = string.Format("[{0}]", tmp[1]);
                index    = tmp[2].IndexOf(":");
                if (0 <= index)
                {
                    var s = tmp[2].Substring(index + 1);
                    Port = Convert.ToInt32(s);
                }
            }
            else
            {
                //�z�X�g�������Ƀ|�[�g�ԍ��������Ă���ꍇ�̏���
                index = HostName.IndexOf(":");
                if (0 <= index)
                {
                    var s = HostName.Substring(index + 1);
                    Port     = Convert.ToInt32(s);
                    HostName = HostName.Substring(0, index);
                }
            }

            Uri = str;

            //CGI����
            if (-1 != Uri.LastIndexOf('?'))
            {
                Cgi = true;
            }

            //�g���q�擾
            if (!Cgi)
            {
                index = Uri.LastIndexOf('/');
                if (index != -1)
                {
                    str = Uri.Substring(index + 1);
                }
                index = str.LastIndexOf('.');
                if (index != -1)
                {
                    Ext = str.Substring(index + 1);
                }
            }
            return(true);
        }