void GetUnicodeInvalid (IdnMapping m, string s, object label)
		{
			try {
				m.GetUnicode (s);
				Assert.Fail (label != null ? label.ToString () + ":" + s : s);
			} catch (ArgumentException) {
			}
		}
示例#2
0
        // GET: Home
        public ActionResult Index(string id = "")
        {
            _logger.Debug("哈哈");

            string domin = Request.Headers["host"];
            //Regex r = new Regex(@"[\u4e00-\u9fa5]+");
            //Match mc = r.Match(domin);
            //if (mc.Length != 0)//含中文域名
            //{
            //    IdnMapping dd = new IdnMapping();
            //    domin = dd.GetUnicode(domin);
            //}
            IdnMapping dd = new IdnMapping();
            domin = dd.GetUnicode(domin);
            ViewBag.Domin = domin + " | "+id;
            return View();
        }
示例#3
0
        internal unsafe static string UnicodeEquivalent(char* hostname, int start, int end, ref bool allAscii, ref bool atLeastOneValidIdn)
        {
            IdnMapping map = new IdnMapping();

            // hostname already validated
            allAscii = true;
            atLeastOneValidIdn = false;
            string idn = null;
            if (end <= start)
                return idn;

            string unescapedHostname = Uri.StripBidiControlCharacter(hostname, start, (end - start));

            string unicodeEqvlHost = null;
            int curPos = 0;
            int newPos = 0;
            int length = unescapedHostname.Length;
            bool asciiLabel = true;
            bool foundAce = false;
            bool checkedAce = false;
            bool foundDot = false;


            // We run a loop where for every label
            // a) if label is ascii and no ace then we lowercase it
            // b) if label is ascii and ace and not valid idn then just lowercase it
            // c) if label is ascii and ace and is valid idn then get its unicode eqvl
            // d) if label is unicode then clean it by running it through idnmapping
            do
            {
                asciiLabel = true;
                foundAce = false;
                checkedAce = false;
                foundDot = false;

                //find the dot or hit the end
                newPos = curPos;
                while (newPos < length)
                {
                    char c = unescapedHostname[newPos];
                    if (!checkedAce)
                    {
                        checkedAce = true;
                        if ((newPos + 3 < length) && (c == 'x') && IsIdnAce(unescapedHostname, newPos))
                            foundAce = true;
                    }
                    if (asciiLabel && (c > '\x7F'))
                    {
                        asciiLabel = false;
                        allAscii = false;
                    }
                    if ((c == '.') || (c == '\u3002') ||    //IDEOGRAPHIC FULL STOP 
                        (c == '\uFF0E') ||                  //FULLWIDTH FULL STOP
                        (c == '\uFF61'))                    //HALFWIDTH IDEOGRAPHIC FULL STOP
                    {
                        foundDot = true;
                        break;
                    }
                    ++newPos;
                }

                if (!asciiLabel)
                {
                    string asciiForm = unescapedHostname.Substring(curPos, newPos - curPos);
                    try
                    {
                        asciiForm = map.GetAscii(asciiForm);
                    }
                    catch (ArgumentException)
                    {
                        throw new UriFormatException(SR.net_uri_BadUnicodeHostForIdn);
                    }

                    unicodeEqvlHost += map.GetUnicode(asciiForm);
                    if (foundDot)
                        unicodeEqvlHost += ".";
                }
                else
                {
                    bool aceValid = false;
                    if (foundAce)
                    {
                        // check ace validity
                        try
                        {
                            unicodeEqvlHost += map.GetUnicode(unescapedHostname.Substring(curPos, newPos - curPos));
                            if (foundDot)
                                unicodeEqvlHost += ".";
                            aceValid = true;
                            atLeastOneValidIdn = true;
                        }
                        catch (ArgumentException)
                        {
                            // not valid ace so treat it as a normal ascii label
                        }
                    }

                    if (!aceValid)
                    {
                        // for invalid aces we just lowercase the label
                        unicodeEqvlHost += unescapedHostname.Substring(curPos, newPos - curPos).ToLowerInvariant();
                        if (foundDot)
                            unicodeEqvlHost += ".";
                    }
                }

                curPos = newPos + (foundDot ? 1 : 0);
            } while (curPos < length);

            return unicodeEqvlHost;
        }
示例#4
0
        //
        // Will convert a host name into its unicode equivalent expanding any existing idn names present
        //
        internal unsafe static string UnicodeEquivalent(string idnHost, char* hostname, int start, int end)
        {
            IdnMapping map = new IdnMapping();

            // Test comon scenario first for perf
            // try to get unicode equivalent 
            try
            {
                return map.GetUnicode(idnHost);
            }
            catch (ArgumentException)
            {
            }
            // Here because something threw in GetUnicode above
            // Need to now check individual labels of they had an ace label that was not valid Idn name
            // or if there is a label with invalid Idn char.
            bool dummy = true;
            return UnicodeEquivalent(hostname, start, end, ref dummy, ref dummy);
        }
示例#5
0
        //
        // Will convert a host name into its idn equivalent + tell you if it had a valid idn label
        //
        internal unsafe static string IdnEquivalent(char* hostname, int start, int end, ref bool allAscii, ref bool atLeastOneValidIdn)
        {
            string bidiStrippedHost = null;
            string idnEquivalent = IdnEquivalent(hostname, start, end, ref allAscii, ref bidiStrippedHost);

            if (idnEquivalent != null)
            {
                string strippedHost = (allAscii ? idnEquivalent : bidiStrippedHost);

                fixed (char* strippedHostPtr = strippedHost)
                {
                    int length = strippedHost.Length;
                    int newPos = 0;
                    int curPos = 0;
                    bool foundAce = false;
                    bool checkedAce = false;
                    bool foundDot = false;

                    do
                    {
                        foundAce = false;
                        checkedAce = false;
                        foundDot = false;

                        //find the dot or hit the end
                        newPos = curPos;
                        while (newPos < length)
                        {
                            char c = strippedHostPtr[newPos];
                            if (!checkedAce)
                            {
                                checkedAce = true;
                                if ((newPos + 3 < length) && IsIdnAce(strippedHostPtr, newPos))
                                {
                                    newPos += 4;
                                    foundAce = true;
                                    continue;
                                }
                            }

                            if ((c == '.') || (c == '\u3002') ||    //IDEOGRAPHIC FULL STOP 
                                (c == '\uFF0E') ||                  //FULLWIDTH FULL STOP
                                (c == '\uFF61'))                    //HALFWIDTH IDEOGRAPHIC FULL STOP
                            {
                                foundDot = true;
                                break;
                            }
                            ++newPos;
                        }

                        if (foundAce)
                        {
                            // check ace validity
                            try
                            {
                                IdnMapping map = new IdnMapping();
                                map.GetUnicode(new string(strippedHostPtr, curPos, newPos - curPos));
                                atLeastOneValidIdn = true;
                                break;
                            }
                            catch (ArgumentException)
                            {
                                // not valid ace so treat it as a normal ascii label
                            }
                        }

                        curPos = newPos + (foundDot ? 1 : 0);
                    } while (curPos < length);
                }
            }
            else
            {
                atLeastOneValidIdn = false;
            }
            return idnEquivalent;
        }
示例#6
0
        public void EmbeddedNulls()
        {
            var idn = new IdnMapping();

            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000"));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000", 0));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000", 0, 2));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000\u0101"));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000\u0101", 0));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000\u0101", 0, 3));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000\u0101\u0000"));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000\u0101\u0000", 0));
            Assert.Throws<ArgumentException>(() => idn.GetAscii("\u0101\u0000\u0101\u0000", 0, 4));
            Assert.Throws<ArgumentException>(() => idn.GetUnicode("abc\u0000", 0, 4));
            Assert.Throws<ArgumentException>(() => idn.GetUnicode("ab\u0000c", 0, 4));
        }
		void GetUnicode (IdnMapping m, string source, string expected, object label)
		{
			Assert.AreEqual (expected, m.GetUnicode (source), label != null ? label.ToString () : expected);
		}
示例#8
0
        public static List<string> GetImportableItems(int packageId, int itemTypeId)
        {
            List<string> items = new List<string>();

            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.IsAdmin | DemandAccount.NotDemo);
            if (accountCheck < 0) return items;

            // load item type
            if (itemTypeId > 0)
            {
                ServiceProviderItemType itemType = PackageController.GetServiceItemType(itemTypeId);

                // load group
                ResourceGroupInfo group = ServerController.GetResourceGroup(itemType.GroupId);

                // Is it DNS Zones? Then create a IDN Mapping object
                var isDnsZones = group.GroupName == "DNS";
                var idn = new IdnMapping();

                // get service id
                int serviceId = PackageController.GetPackageServiceId(packageId, group.GroupName);
                if (serviceId == 0)
                    return items;

                DataTable dtServiceItems = PackageController.GetServiceItemsDataSet(serviceId).Tables[0];
                DataTable dtPackageItems = PackageController.GetPackageItemsDataSet(packageId).Tables[0];

                // instantiate controller
                IImportController ctrl = null;
                try
                {
                    List<string> importableItems = null;
                    ctrl = Activator.CreateInstance(Type.GetType(group.GroupController)) as IImportController;
                    if (ctrl != null)
                    {
                        importableItems = ctrl.GetImportableItems(packageId, itemTypeId, Type.GetType(itemType.TypeName), group);
                    }

                    foreach (string importableItem in importableItems)
                    {
                        // filter items by service
                        bool serviceContains = false;
                        foreach (DataRow dr in dtServiceItems.Rows)
                        {
                            string serviceItemName = (string)dr["ItemName"];
                            int serviceItemTypeId = (int)dr["ItemTypeId"];

                            if (String.Compare(importableItem, serviceItemName, true) == 0
                                && serviceItemTypeId == itemTypeId)
                            {
                                serviceContains = true;
                                break;
                            }
                        }

                        // filter items by package
                        bool packageContains = false;
                        foreach (DataRow dr in dtPackageItems.Rows)
                        {
                            string packageItemName = (string)dr["ItemName"];
                            int packageItemTypeId = (int)dr["ItemTypeId"];

                            if (String.Compare(importableItem, packageItemName, true) == 0
                                && packageItemTypeId == itemTypeId)
                            {
                                packageContains = true;
                                break;
                            }
                        }

                        if (!serviceContains && !packageContains)
                        {
                            var itemToImport = importableItem;

                            // For DNS zones the compare has been made using ascii, convert to unicode if necessary to make the list of items easier to read
                            if (isDnsZones && itemToImport.StartsWith("xn--"))
                            {
                                itemToImport = idn.GetUnicode(importableItem);
                            }

                            items.Add(itemToImport);
                        }
                    }

                }
                catch { /* do nothing */ }
            }
            else
                return GetImportableCustomItems(packageId, itemTypeId);

            return items;
        }
 internal static unsafe string UnicodeEquivalent(char* hostname, int start, int end, ref bool allAscii, ref bool atLeastOneValidIdn)
 {
     IdnMapping mapping = new IdnMapping();
     allAscii = true;
     atLeastOneValidIdn = false;
     string str = null;
     if (end <= start)
     {
         return str;
     }
     string input = Uri.StripBidiControlCharacter(hostname, start, end - start);
     string str3 = null;
     int startIndex = 0;
     int index = 0;
     int length = input.Length;
     bool flag = true;
     bool flag2 = false;
     bool flag3 = false;
     bool flag4 = false;
     do
     {
         flag = true;
         flag2 = false;
         flag3 = false;
         flag4 = false;
         index = startIndex;
         while (index < length)
         {
             char ch = input[index];
             if (!flag3)
             {
                 flag3 = true;
                 if ((((index + 3) < length) && (ch == 'x')) && IsIdnAce(input, index))
                 {
                     flag2 = true;
                 }
             }
             if (flag && (ch > '\x007f'))
             {
                 flag = false;
                 allAscii = false;
             }
             if (((ch == '.') || (ch == '。')) || ((ch == 0xff0e) || (ch == 0xff61)))
             {
                 flag4 = true;
                 break;
             }
             index++;
         }
         if (!flag)
         {
             string unicode = input.Substring(startIndex, index - startIndex);
             try
             {
                 unicode = mapping.GetAscii(unicode);
             }
             catch (ArgumentException)
             {
                 throw new UriFormatException(SR.GetString("net_uri_BadUnicodeHostForIdn"));
             }
             str3 = str3 + mapping.GetUnicode(unicode);
             if (flag4)
             {
                 str3 = str3 + ".";
             }
         }
         else
         {
             bool flag5 = false;
             if (flag2)
             {
                 try
                 {
                     str3 = str3 + mapping.GetUnicode(input.Substring(startIndex, index - startIndex));
                     if (flag4)
                     {
                         str3 = str3 + ".";
                     }
                     flag5 = true;
                     atLeastOneValidIdn = true;
                 }
                 catch (ArgumentException)
                 {
                 }
             }
             if (!flag5)
             {
                 str3 = str3 + input.Substring(startIndex, index - startIndex).ToLowerInvariant();
                 if (flag4)
                 {
                     str3 = str3 + ".";
                 }
             }
         }
         startIndex = index + (flag4 ? 1 : 0);
     }
     while (startIndex < length);
     return str3;
 }
 internal static unsafe string UnicodeEquivalent(string idnHost, char* hostname, int start, int end)
 {
     IdnMapping mapping = new IdnMapping();
     try
     {
         return mapping.GetUnicode(idnHost);
     }
     catch (ArgumentException)
     {
     }
     bool allAscii = true;
     return UnicodeEquivalent(hostname, start, end, ref allAscii, ref allAscii);
 }
        public List<string> GetImportableItems(int packageId, int itemTypeId, Type itemType, ResourceGroupInfo group)
        {
            List<string> items = new List<string>();

            // get service id
            int serviceId = PackageController.GetPackageServiceId(packageId, group.GroupName);
            if (serviceId == 0)
                return items;

            // Mail provider
            DNSServer dns = new DNSServer();
            ServiceProviderProxy.Init(dns, serviceId);

            // IDN: The list of importable names is populated with unicode names, to make it easier for the user
            var idn = new IdnMapping();

            if (itemType == typeof(DnsZone))
                items.AddRange(dns.GetZones().Select(z =>
                    Encoding.UTF8.GetByteCount(z) == z.Length ? // IsASCII
                    idn.GetUnicode(z) : z ));

            return items;
        }