예제 #1
0
        public ED2KFileLinkImpl(string pszName,
                                string pszSize,
                                string pszHash,
                                string[] allParams,
                                string pszSources)
        {
            try
            {
                //name_ = Encoding.UTF8.GetString(HttpUtility.UrlDecodeToBytes(pszName));
                name_ = Uri.UnescapeDataString(pszName);
                name_ = name_.Trim();

                if (string.IsNullOrEmpty(name_))
                {
                    throw new MuleException("Invalid File Link:" + pszName);
                }
            }
            catch (Exception ex)
            {
                throw new MuleException("Invalid File Link:" + pszName, ex);
            }

            SourcesList    = null;
            HashSet        = null;
            aichHashValid_ = false;

            strSize_ = pszSize;
            if (ulong.TryParse(pszSize, out size_))
            {
                if (size_ > MuleConstants.MAX_EMULE_FILE_SIZE)
                {
                    throw new MuleException("Too Large File:" + pszSize);
                }
            }
            else
            {
                throw new MuleException("Invalid File Size:" + pszSize);
            }

            if (pszHash.Length != 32)
            {
                throw new MuleException("Invalid File Hash Format:" + pszHash);
            }

            if (!MpdUtilities.DecodeHexString(pszHash, hash_))
            {
                throw new MuleException("Invalid File Hash Format:" + pszHash);
            }

            HandleParams(allParams);

            HandleSources(pszSources);
        }
예제 #2
0
        private void HandleParams(string[] allParams)
        {
            if (allParams == null || allParams.Length == 0)
            {
                return;
            }

            bool bError = false;

            for (int i = 0; !bError && i < allParams.Length; i++)
            {
                string strParam = allParams[i];

                string[] tokens = strParam.Split('=');

                if (tokens == null || tokens.Length < 2)
                {
                    //TODO:Log
                    continue;
                }

                string strTok = tokens[0];
                if (strTok.Equals("s"))
                {
                    string strURL = strParam.Substring(strTok.Length + 1);

                    if (!string.IsNullOrEmpty(strURL))
                    {
                        if (Uri.IsWellFormedUriString(strURL, UriKind.RelativeOrAbsolute))
                        {
                            Uri uri = new Uri(strURL, UriKind.RelativeOrAbsolute);

                            UnresolvedHostname hostname =
                                MuleApplication.Instance.ED2KObjectManager.CreateUnresolvedHostname();

                            hostname.Url      = strURL;
                            hostname.HostName = uri.Host;
                            hostname.Port     = Convert.ToUInt16(uri.Port);
                            hostnameSourcesList_.Add(hostname);
                        }
                        else
                        {
                            //ASSERT(0);
                            //TODO:Log
                        }
                    }
                    else
                    {
                        //ASSERT(0);
                        //TODO:Log
                    }
                }
                else if (strTok.Equals("p"))
                {
                    string strPartHashs = tokens[1];

                    if (HashSet != null)
                    {
                        //ASSERT(0);
                        //TODO:Log
                        bError = true;
                        break;
                    }

                    HashSet = MpdObjectManager.CreateSafeMemFile(256);
                    HashSet.WriteHash16(hash_);
                    HashSet.WriteUInt16(0);

                    int      iPartHashs = 0;
                    string[] strHashs   = strPartHashs.Split(':');

                    while (strHashs != null && iPartHashs < strHashs.Length)
                    {
                        if (string.IsNullOrEmpty(strHashs[iPartHashs]))
                        {
                            //TODO:Log
                            continue;
                        }

                        byte[] aucPartHash = new byte[16];
                        if (!MpdUtilities.DecodeHexString(strHashs[iPartHashs], aucPartHash))
                        {
                            bError = true;
                            break;
                        }
                        HashSet.WriteHash16(aucPartHash);
                        iPartHashs++;
                    }

                    if (bError)
                    {
                        break;
                    }

                    HashSet.Seek(16, System.IO.SeekOrigin.Begin);
                    HashSet.WriteUInt16(Convert.ToUInt16(iPartHashs));
                    HashSet.Seek(0, System.IO.SeekOrigin.Begin);
                }
                else if (strTok.Equals("h"))
                {
                    string strHash = strParam.Substring(strTok.Length + 1);
                    if (!string.IsNullOrEmpty(strHash))
                    {
                        if (MpdUtilities.DecodeBase32(strHash.ToCharArray(), aichHash_.RawHash) == MuleConstants.HASHSIZE)
                        {
                            aichHashValid_ = true;
                        }
                        else
                        {
                            //ASSERT(0);
                            //TODO:Log
                        }
                    }
                    else
                    {
                        //ASSERT(0);
                        //TODO:Log
                    }
                }
                else
                {
                    //ASSERT(0);
                    //TODO:Log
                }
            }

            if (bError)
            {
                HashSet = null;
            }
        }