コード例 #1
0
ファイル: RegionURI.cs プロジェクト: StolenRuby/consortium
        public RegionURI(string _originalURI, GridInfo gi)
        {
            originalURI = _originalURI;
            Parse(_originalURI);

            if (!HasHost)
            {
                Flags |= URIFlags.IsLocalGrid;
                return;
            }
            if (gi == null)
            {
                return;
            }

            if (gi.IsLocalGrid(HostUrl) == 1)
            {
                Host   = string.Empty;
                Flags &= ~URIFlags.HasHost;
                Flags |= URIFlags.IsLocalGrid;
                return;
            }
            if (!ResolveDNS())
            {
                Flags = URIFlags.None;
            }
        }
コード例 #2
0
ファイル: RegionURI.cs プロジェクト: StolenRuby/consortium
 public RegionURI(string _originalURI)
 {
     originalURI = _originalURI;
     Parse(_originalURI);
     if (!HasHost)
     {
         Flags |= URIFlags.IsLocalGrid;
     }
 }
コード例 #3
0
ファイル: RegionURI.cs プロジェクト: StolenRuby/consortium
 public bool ResolveDNS()
 {
     if ((Flags & URIFlags.HasHost) != 0)
     {
         IPAddress ip = Util.GetHostFromDNS(Host);
         if (ip != null)
         {
             IP     = ip;
             Flags |= URIFlags.HasResolvedHost;
             return(true);
         }
     }
     return(false);
 }
コード例 #4
0
ファイル: RegionURI.cs プロジェクト: StolenRuby/consortium
        public void Parse(string inputURI)
        {
            Flags = URIFlags.None;
            if (string.IsNullOrWhiteSpace(inputURI))
            {
                return;
            }

            osUTF8Slice input = new osUTF8Slice(inputURI);

            input.SelfTrimStart((byte)' ');
            input.SelfTrimStart((byte)'+');

            int firstDot = input.IndexOf((byte)'.');

            if (firstDot == 0)
            {
                return;
            }

            osUTF8Slice tmpSlice;

            int indx = input.IndexOf(schemaSep);

            if (indx == 0)
            {
                return;
            }
            if (indx < 0)
            {
                indx = input.IndexOf(altschemaSep);
            }
            if (indx == 0)
            {
                return;
            }
            if (indx > 0)
            {
                if (indx < 2 || input.Length < indx + 4 || (firstDot > 0 && indx > firstDot))
                {
                    return;
                }

                bool issecure = false;
                tmpSlice = input.SubUTF8(0, indx).Clone();
                tmpSlice.ToASCIILowerSelf();

                if (tmpSlice.EndsWith((byte)'s'))
                {
                    issecure = true;
                    tmpSlice.SelfTrimEnd((byte)'s');
                }

                switch (tmpSlice.ToString())
                {
                case "hg":
                case "hop":
                case "http":
                case "surl":
                    if (issecure)
                    {
                        Schema = "https://";
                        Port   = 443;
                    }
                    break;

                default:
                    return;
                }

                indx += 3;
                input.SubUTF8Self(indx);
                firstDot -= indx;
            }

            int namestart = 0;

            if (firstDot > 0)
            {
                int         hostend = -1;
                osUTF8Slice hosttmp = input.Clone();
                indx = input.IndexOfAny(altPortSepPref);
                if (indx > 0)
                {
                    if (indx < firstDot)
                    {
                        return;
                    }

                    hostend = indx;
                    ++indx;
                    int  tmpport = 0;
                    byte c;
                    while (indx < input.Length)
                    {
                        c = input[indx];
                        if (c < (byte)'0' || c > (byte)'9')
                        {
                            break;
                        }
                        tmpport *= 10;
                        tmpport += c - (byte)'0';
                        ++indx;
                    }
                    if (indx > hostend + 1)
                    {
                        if (tmpport > 64 * 1024)
                        {
                            return;
                        }
                        Port = tmpport;
                    }
                    input.SubUTF8Self(indx);
                    input.SelfTrimStart(altnameSep);
                }
                else
                {
                    indx = input.IndexOfAny(altnameSep);
                    if (indx < 0)
                    {
                        hostend   = input.Length;
                        namestart = -1;
                    }
                    else
                    {
                        hostend   = indx;
                        namestart = indx + 1;
                    }
                }

                if (hostend <= 0)
                {
                    return;
                }

                hosttmp.SubUTF8Self(0, hostend);
                indx = hosttmp.IndexOf((byte)'@');
                if (indx >= 0)
                {
                    if (indx > 0)
                    {
                        tmpSlice = hosttmp.SubUTF8(0, indx);
                        int indx2 = tmpSlice.IndexOfAny(escapePref);
                        if (indx2 >= 0)
                        {
                            Username = Uri.UnescapeDataString(tmpSlice.ToString());
                            Username = Username.Replace('+', ' ');
                        }
                        else
                        {
                            Username = tmpSlice.ToString();
                        }
                        if (Username.Length > 0)
                        {
                            Flags |= URIFlags.HasUserName;
                        }
                    }
                    ++indx;
                    hosttmp.SubUTF8Self(indx);
                }
                if (hosttmp.Length == 0)
                {
                    Flags = URIFlags.None;
                    return;
                }

                indx = hosttmp.IndexOfAny(escapePref);
                if (indx >= 0)
                {
                    string blabla = Uri.UnescapeDataString(hosttmp.ToString());
                    blabla  = blabla.Replace('+', ' ');
                    hosttmp = new osUTF8Slice(blabla);
                }
                hosttmp.ToASCIILowerSelf();
                Host = hosttmp.ToString();
                UriHostNameType type = Uri.CheckHostName(Host);
                if (type == UriHostNameType.Unknown || type == UriHostNameType.Basic)
                {
                    Flags = URIFlags.None;
                    return;
                }

                Flags |= URIFlags.HasHost;
            }

            if (namestart < 0 || input.Length == 0)
            {
                return;
            }

            input.SubUTF8Self(namestart);
            input.SelfTrimStart((byte)' ');
            input.SelfTrimStart((byte)'+');

            int firstCoord = input.IndexOf((byte)'/');

            if (firstCoord == 0)
            {
                Flags = URIFlags.None;
                return;
            }
            if (firstCoord < 0)
            {
                firstCoord = input.IndexOf((byte)'(');
            }

            if (firstCoord > 0)
            {
                tmpSlice = input.SubUTF8(0, firstCoord);
            }
            else
            {
                tmpSlice = input;
            }
            indx = tmpSlice.IndexOfAny(escapePref);
            if (indx >= 0)
            {
                string blabla = Uri.UnescapeDataString(tmpSlice.ToString());
                blabla   = blabla.Replace('+', ' ');
                tmpSlice = new osUTF8Slice(blabla);
            }

            tmpSlice.SelfTrimEnd((byte)' ');
            if (tmpSlice.Length <= 0)
            {
                return;
            }

            RegionName = tmpSlice.ToString();
            Flags     |= URIFlags.HasRegionName;

            if (firstCoord > 0)
            {
                if (input[firstCoord] == (byte)'/')
                {
                    ++firstCoord;
                    int tmp = 0;
                    tmpSlice = input.SubUTF8(firstCoord);
                    int indx2 = 0;
                    while (indx2 < tmpSlice.Length)
                    {
                        byte c = tmpSlice[indx2];
                        if (c < (byte)'0' || c > (byte)'9')
                        {
                            break;
                        }
                        tmp *= 10;
                        tmp += c - (byte)'0';
                        ++indx2;
                    }
                    if (indx2 == 0)
                    {
                        Flags = URIFlags.None;
                        return;
                    }
                    X = tmp;
                    tmpSlice.SubUTF8Self(indx2);
                    indx = tmpSlice.IndexOf((byte)'/');
                    if (indx >= 0)
                    {
                        ++indx;
                        tmpSlice.SubUTF8Self(indx);
                        indx2 = 0;
                        tmp   = 0;
                        while (indx2 < tmpSlice.Length)
                        {
                            byte c = tmpSlice[indx2];
                            if (c < (byte)'0' || c > (byte)'9')
                            {
                                break;
                            }
                            tmp *= 10;
                            tmp += c - (byte)'0';
                            ++indx2;
                        }
                        if (indx2 == 0)
                        {
                            Flags = URIFlags.None;
                            return;
                        }
                        Y = tmp;
                        tmpSlice.SubUTF8Self(indx2);
                        indx = tmpSlice.IndexOf((byte)'/');
                        if (indx >= 0)
                        {
                            ++indx;
                            tmpSlice.SubUTF8Self(indx);
                            indx2 = 0;
                            tmp   = 0;
                            int sig = 1;
                            if (tmpSlice[indx2] == (byte)'-')
                            {
                                sig = -1;
                                indx2++;
                            }
                            while (indx2 < tmpSlice.Length)
                            {
                                byte c = tmpSlice[indx2];
                                if (c < (byte)'0' || c > (byte)'9')
                                {
                                    break;
                                }
                                tmp *= 10;
                                tmp += c - (byte)'0';
                                ++indx2;
                            }
                            if (indx2 == 0)
                            {
                                Flags = URIFlags.None;
                                return;
                            }
                            Z = sig * tmp;
                        }
                    }
                }
                else // (,,) case
                {
                    ++firstCoord;
                    int tmp = 0;
                    tmpSlice = input.SubUTF8(firstCoord);
                    int indx2 = tmpSlice.IndexOf((byte)')');
                    if (indx2 == 0)
                    {
                        return;
                    }
                    if (indx2 > 0)
                    {
                        tmpSlice.SubUTF8Self(0, indx2);
                    }

                    indx2 = 0;
                    tmpSlice.SelfTrimStart((byte)' ');
                    tmpSlice.SelfTrimStart((byte)'+');

                    while (indx2 < tmpSlice.Length)
                    {
                        byte c = tmpSlice[indx2];
                        if (c < (byte)'0' || c > (byte)'9')
                        {
                            break;
                        }
                        tmp *= 10;
                        tmp += c - (byte)'0';
                        ++indx2;
                    }
                    if (indx2 == 0)
                    {
                        Flags = URIFlags.None;
                        return;
                    }
                    X = tmp;
                    tmpSlice.SubUTF8Self(indx2);
                    indx = tmpSlice.IndexOf((byte)',');
                    if (indx >= 0)
                    {
                        ++indx;
                        tmpSlice.SubUTF8Self(indx);
                        tmpSlice.SelfTrimStart((byte)' ');
                        tmpSlice.SelfTrimStart((byte)'+');
                        indx2 = 0;
                        tmp   = 0;
                        while (indx2 < tmpSlice.Length)
                        {
                            byte c = tmpSlice[indx2];
                            if (c < (byte)'0' || c > (byte)'9')
                            {
                                break;
                            }
                            tmp *= 10;
                            tmp += c - (byte)'0';
                            ++indx2;
                        }
                        if (indx2 == 0)
                        {
                            Flags = URIFlags.None;
                            return;
                        }
                        Y = tmp;
                        tmpSlice.SubUTF8Self(indx2);
                        indx = tmpSlice.IndexOf((byte)',');
                        if (indx >= 0)
                        {
                            ++indx;
                            tmpSlice.SubUTF8Self(indx);
                            tmpSlice.SelfTrimStart((byte)' ');
                            tmpSlice.SelfTrimStart((byte)'+');
                            indx2 = 0;
                            tmp   = 0;
                            int sig = 1;
                            if (tmpSlice[indx2] == (byte)'-')
                            {
                                sig = -1;
                                indx2++;
                            }
                            while (indx2 < tmpSlice.Length)
                            {
                                byte c = tmpSlice[indx2];
                                if (c < (byte)'0' || c > (byte)'9')
                                {
                                    break;
                                }
                                tmp *= 10;
                                tmp += c - (byte)'0';
                                ++indx2;
                            }
                            if (indx2 == 0)
                            {
                                Flags = URIFlags.None;
                                return;
                            }
                            Z = sig * tmp;
                        }
                    }
                }
            }
            return;
        }