Ejemplo n.º 1
0
        internal static int GetChunkSize(IReadChunkBytes Source, out int chunkSize)
        {
            int num2     = 0;
            int nextByte = Source.NextByte;
            int num      = 0;

            switch (nextByte)
            {
            case 10:
            case 13:
                num++;
                nextByte = Source.NextByte;
                break;
            }
            while (nextByte != -1)
            {
                if ((nextByte >= 0x30) && (nextByte <= 0x39))
                {
                    nextByte -= 0x30;
                }
                else
                {
                    if ((nextByte >= 0x61) && (nextByte <= 0x66))
                    {
                        nextByte -= 0x61;
                    }
                    else if ((nextByte >= 0x41) && (nextByte <= 70))
                    {
                        nextByte -= 0x41;
                    }
                    else
                    {
                        Source.NextByte = nextByte;
                        chunkSize       = num2;
                        return(num);
                    }
                    nextByte += 10;
                }
                num2 *= 0x10;
                num2 += nextByte;
                num++;
                nextByte = Source.NextByte;
            }
            chunkSize = num2;
            return(-1);
        }
 internal static int GetChunkSize(IReadChunkBytes Source, out int chunkSize)
 {
     int num2 = 0;
     int nextByte = Source.NextByte;
     int num = 0;
     switch (nextByte)
     {
         case 10:
         case 13:
             num++;
             nextByte = Source.NextByte;
             break;
     }
     while (nextByte != -1)
     {
         if ((nextByte >= 0x30) && (nextByte <= 0x39))
         {
             nextByte -= 0x30;
         }
         else
         {
             if ((nextByte >= 0x61) && (nextByte <= 0x66))
             {
                 nextByte -= 0x61;
             }
             else if ((nextByte >= 0x41) && (nextByte <= 70))
             {
                 nextByte -= 0x41;
             }
             else
             {
                 Source.NextByte = nextByte;
                 chunkSize = num2;
                 return num;
             }
             nextByte += 10;
         }
         num2 *= 0x10;
         num2 += nextByte;
         num++;
         nextByte = Source.NextByte;
     }
     chunkSize = num2;
     return -1;
 }
Ejemplo n.º 3
0
        SkipPastCRLF(IReadChunkBytes Source) {
            int         BytesRead;
            int         Current;
            bool        Escape;
            bool        InQS;
            bool        HaveCR;
            bool        HaveLF;

            BytesRead = 0;
            Escape = false;
            InQS = false;
            HaveCR = false;
            HaveLF = false;

            GlobalLog.Enter("SkipPastCRLF");

            // Loop through the buffer, looking at each byte. We have a
            // pseudo state machine going here, and the action we take
            // with each byte depends on the state.

            Current = Source.NextByte;
            BytesRead++;

            while (Current != -1) {

                // If we saw a CR last time, it must be followed by an unescaped
                // LF, otherwise it's an error. If it is followed by a LF, and
                // we're not in a quoted string, then we've found our termination.
                // If we are in a quoted string, this could be the start of a LWS
                // production. Remember that, and next time through we'll
                // check to make sure that this is an LWS production.

                if (HaveCR) {
                    if (Current != '\n') {
                        // CR w/o a trailing LF is an error.
                        GlobalLog.Leave("SkipPastCRLF", 0);
                        return 0;
                    }
                    else {
                        if (Escape) {
                            // We have an CR, but they're trying to escape the
                            // LF. This is an error.

                            GlobalLog.Leave("SkipPastCRLF", 0);
                            return 0;
                        }

                        // If we're not in a quoted string, we're done.

                        if (!InQS) {
                            // We've found the terminating CRLF pair.
                            GlobalLog.Leave("SkipPastCRLF", 0);
                            return BytesRead;
                        }
                        else {
                            // We're in a quoted string, so set HaveLF
                            // so we remember to check for a LWS production next
                            // time.

                            HaveLF = true;

                            // We've proceessed this byte, set Escape so we don't
                            // do it again.

                            Escape = true;
                        }
                    }

                    // We're past the CR now, don't remember it any more.

                    HaveCR = false;
                }
                else {
                    // If HaveLF is set, we must be in a quoted string and have
                    // seen a CRLF pair. Make sure this character is a space or
                    // tab.

                    if (HaveLF) {
                        // We have a LF. For this to be valid, we have to have a
                        // space or tab be the next character.

                        if (Current != ' ' && Current != '\t') {
                            // Not a continuation, so return an error.
                            GlobalLog.Leave("SkipPastCRLF", 0);
                            return 0;
                        }

                        Escape = true;  // Don't process this byte again.
                        HaveLF = false;
                    }
                }

                // If we're escaping, just skip the next character.
                if (!Escape) {
                    switch (Current) {
                        case '"':
                            if (InQS) {
                                InQS = false;
                            }
                            else {
                                InQS = true;
                            }
                            break;
                        case '\\':
                            if (InQS) {
                                Escape = true;
                            }
                            break;
                        case '\r':
                            HaveCR = true;
                            break;

                        case '\n':

                            // If we get here, we have a LF without a preceding CR.
                            // This is an error.

                            GlobalLog.Leave("SkipPastCRLF", 0);
                            return 0;

                        default:
                            break;
                    }
                }
                else {
                    // We're escaping, do nothing but rest the Escape flag.

                    Escape = false;
                }

                Current = Source.NextByte;
                BytesRead++;
            }

            // If we get here, we never saw the terminating CRLF, so return -1.

            GlobalLog.Leave("SkipPastCRLF", -1);
            return -1;
        }
Ejemplo n.º 4
0
        GetChunkSize(IReadChunkBytes Source, out int chunkSize) {
            int         BytesRead;
            int         Size;
            int         Current;

            GlobalLog.Enter("GetChunkSize");
            Size = 0;

            //
            // Loop while we have data. If we run out of data and exit the loop
            // at the bottom, then we've run out of data and haven't found the
            // length.

            Current = Source.NextByte;
            BytesRead = 0;

            if (Current == 10 || Current == 13) {
                GlobalLog.Print(" Got Char: " + Current.ToString("X"));
                BytesRead++;
                Current = Source.NextByte;
            }

            while (Current != -1) {
                // Get the next byte, and decode it.

                if (Current >= '0' && Current <= '9') {
                    // Normalize it to 0 based.

                    Current -= '0';

                }
                else {
                    // If we're here, this might be a hex digit.
                    // If it is, normalize it to 10 based.

                    if (Current >= 'a' && Current <= 'f') {
                        Current -= 'a';
                    }
                    else {
                        if (Current >= 'A' && Current <= 'F') {
                            Current -= 'A';
                        }
                        else {
                            // Done with the decoding. If we haven't actually
                            // decoded a digit yet, we'll end up returning
                            // 0, which will signal the error.


                            // Push back the byte we read and didn't use.

                            Source.NextByte = Current;

                            chunkSize = Size;

                            // Return how many bytes we took.

                            GlobalLog.Print("Chunk Size = " + Size.ToString());
                            GlobalLog.Leave("GetChunkSize", BytesRead);
                            return BytesRead;

                        }
                    }

                    // If we get here we've had an A-F digit, add 10
                    // to it to normalize it.

                    Current += 10;
                }

                // Update the size and our state.

                Size *= 16;
                Size += Current;

                BytesRead++;
                Current = Source.NextByte;
            }

            chunkSize = Size;
            GlobalLog.Print("*Chunk Size* = " + Size.ToString());
            GlobalLog.Leave("GetChunkSize", -1);
            return -1;
        }
Ejemplo n.º 5
0
        internal static int SkipPastCRLF(IReadChunkBytes Source)
        {
            int  num      = 0;
            bool flag     = false;
            bool flag2    = false;
            bool flag3    = false;
            bool flag4    = false;
            int  nextByte = Source.NextByte;

            num++;
            while (nextByte != -1)
            {
                if (flag3)
                {
                    if (nextByte != 10)
                    {
                        return(0);
                    }
                    if (flag)
                    {
                        return(0);
                    }
                    if (!flag2)
                    {
                        return(num);
                    }
                    flag4 = true;
                    flag  = true;
                    flag3 = false;
                }
                else if (flag4)
                {
                    if ((nextByte != 0x20) && (nextByte != 9))
                    {
                        return(0);
                    }
                    flag  = true;
                    flag4 = false;
                }
                if (!flag)
                {
                    switch (nextByte)
                    {
                    case 0x22:
                        if (flag2)
                        {
                            flag2 = false;
                        }
                        else
                        {
                            flag2 = true;
                        }
                        break;

                    case 0x5c:
                        if (flag2)
                        {
                            flag = true;
                        }
                        break;

                    case 10:
                        return(0);

                    case 13:
                        flag3 = true;
                        break;
                    }
                }
                else
                {
                    flag = false;
                }
                nextByte = Source.NextByte;
                num++;
            }
            return(-1);
        }
Ejemplo n.º 6
0
        SkipPastCRLF(IReadChunkBytes Source)
        {
            int  BytesRead;
            int  Current;
            bool Escape;
            bool InQS;
            bool HaveCR;
            bool HaveLF;

            BytesRead = 0;
            Escape    = false;
            InQS      = false;
            HaveCR    = false;
            HaveLF    = false;

            GlobalLog.Enter("SkipPastCRLF");

            // Loop through the buffer, looking at each byte. We have a
            // pseudo state machine going here, and the action we take
            // with each byte depends on the state.

            Current = Source.NextByte;
            BytesRead++;

            while (Current != -1)
            {
                // If we saw a CR last time, it must be followed by an unescaped
                // LF, otherwise it's an error. If it is followed by a LF, and
                // we're not in a quoted string, then we've found our termination.
                // If we are in a quoted string, this could be the start of a LWS
                // production. Remember that, and next time through we'll
                // check to make sure that this is an LWS production.

                if (HaveCR)
                {
                    if (Current != '\n')
                    {
                        // CR w/o a trailing LF is an error.
                        GlobalLog.Leave("SkipPastCRLF", 0);
                        return(0);
                    }
                    else
                    {
                        if (Escape)
                        {
                            // We have an CR, but they're trying to escape the
                            // LF. This is an error.

                            GlobalLog.Leave("SkipPastCRLF", 0);
                            return(0);
                        }

                        // If we're not in a quoted string, we're done.

                        if (!InQS)
                        {
                            // We've found the terminating CRLF pair.
                            GlobalLog.Leave("SkipPastCRLF", 0);
                            return(BytesRead);
                        }
                        else
                        {
                            // We're in a quoted string, so set HaveLF
                            // so we remember to check for a LWS production next
                            // time.

                            HaveLF = true;

                            // We've proceessed this byte, set Escape so we don't
                            // do it again.

                            Escape = true;
                        }
                    }

                    // We're past the CR now, don't remember it any more.

                    HaveCR = false;
                }
                else
                {
                    // If HaveLF is set, we must be in a quoted string and have
                    // seen a CRLF pair. Make sure this character is a space or
                    // tab.

                    if (HaveLF)
                    {
                        // We have a LF. For this to be valid, we have to have a
                        // space or tab be the next character.

                        if (Current != ' ' && Current != '\t')
                        {
                            // Not a continuation, so return an error.
                            GlobalLog.Leave("SkipPastCRLF", 0);
                            return(0);
                        }

                        Escape = true;  // Don't process this byte again.
                        HaveLF = false;
                    }
                }

                // If we're escaping, just skip the next character.
                if (!Escape)
                {
                    switch (Current)
                    {
                    case '"':
                        if (InQS)
                        {
                            InQS = false;
                        }
                        else
                        {
                            InQS = true;
                        }
                        break;

                    case '\\':
                        if (InQS)
                        {
                            Escape = true;
                        }
                        break;

                    case '\r':
                        HaveCR = true;
                        break;

                    case '\n':

                        // If we get here, we have a LF without a preceding CR.
                        // This is an error.

                        GlobalLog.Leave("SkipPastCRLF", 0);
                        return(0);

                    default:
                        break;
                    }
                }
                else
                {
                    // We're escaping, do nothing but rest the Escape flag.

                    Escape = false;
                }

                Current = Source.NextByte;
                BytesRead++;
            }

            // If we get here, we never saw the terminating CRLF, so return -1.

            GlobalLog.Leave("SkipPastCRLF", -1);
            return(-1);
        }
Ejemplo n.º 7
0
        GetChunkSize(IReadChunkBytes Source, out int chunkSize)
        {
            int BytesRead;
            int Size;
            int Current;

            GlobalLog.Enter("GetChunkSize");
            Size = 0;

            //
            // Loop while we have data. If we run out of data and exit the loop
            // at the bottom, then we've run out of data and haven't found the
            // length.

            Current   = Source.NextByte;
            BytesRead = 0;

            if (Current == 10 || Current == 13)
            {
                GlobalLog.Print(" Got Char: " + Current.ToString());
                BytesRead++;
                Current = Source.NextByte;
            }

            while (Current != -1)
            {
                // Get the next byte, and decode it.

                if (Current >= '0' && Current <= '9')
                {
                    // Normalize it to 0 based.

                    Current -= '0';
                }
                else
                {
                    // If we're here, this might be a hex digit.
                    // If it is, normalize it to 10 based.

                    if (Current >= 'a' && Current <= 'f')
                    {
                        Current -= 'a';
                    }
                    else
                    {
                        if (Current >= 'A' && Current <= 'F')
                        {
                            Current -= 'A';
                        }
                        else
                        {
                            // Done with the decoding. If we haven't actually
                            // decoded a digit yet, we'll end up returning
                            // 0, which will signal the error.


                            // Push back the byte we read and didn't use.

                            Source.NextByte = Current;

                            chunkSize = Size;

                            // Return how many bytes we took.

                            GlobalLog.Print("*Size* = " + Size.ToString());
                            GlobalLog.Leave("GetChunkSize", BytesRead);
                            return(BytesRead);
                        }
                    }

                    // If we get here we've had an A-F digit, add 10
                    // to it to normalize it.

                    Current += 10;
                }

                // Update the size and our state.

                Size *= 16;
                Size += Current;

                BytesRead++;
                Current = Source.NextByte;
            }

            chunkSize = Size;
            GlobalLog.Print("*Size* = " + Size.ToString());
            GlobalLog.Leave("GetChunkSize", -1);
            return(-1);
        }
        internal static int SkipPastCRLF(IReadChunkBytes Source)
        {
            int num = 0;
            bool flag = false;
            bool flag2 = false;
            bool flag3 = false;
            bool flag4 = false;
            int nextByte = Source.NextByte;
            num++;
            while (nextByte != -1)
            {
                if (flag3)
                {
                    if (nextByte != 10)
                    {
                        return 0;
                    }
                    if (flag)
                    {
                        return 0;
                    }
                    if (!flag2)
                    {
                        return num;
                    }
                    flag4 = true;
                    flag = true;
                    flag3 = false;
                }
                else if (flag4)
                {
                    if ((nextByte != 0x20) && (nextByte != 9))
                    {
                        return 0;
                    }
                    flag = true;
                    flag4 = false;
                }
                if (!flag)
                {
                    switch (nextByte)
                    {
                        case 0x22:
                            if (flag2)
                            {
                                flag2 = false;
                            }
                            else
                            {
                                flag2 = true;
                            }
                            break;

                        case 0x5c:
                            if (flag2)
                            {
                                flag = true;
                            }
                            break;

                        case 10:
                            return 0;

                        case 13:
                            flag3 = true;
                            break;
                    }
                }
                else
                {
                    flag = false;
                }
                nextByte = Source.NextByte;
                num++;
            }
            return -1;
        }