public TdrError.ErrorType unpack(ref byte[] buffer, int size, ref int usedSize, uint cutVer)
        {
            if (buffer == null || buffer.GetLength(0) == 0 || size > buffer.GetLength(0))
            {
                return(TdrError.ErrorType.TDR_ERR_INVALID_BUFFER_PARAMETER);
            }
            TdrReadBuf tdrReadBuf = ClassObjPool <TdrReadBuf> .Get();

            tdrReadBuf.set(ref buffer, size);
            TdrError.ErrorType result = this.unpack(ref tdrReadBuf, cutVer);
            usedSize = tdrReadBuf.getUsedSize();
            tdrReadBuf.Release();
            return(result);
        }
        public TdrError.ErrorType unpack(ref byte[] buffer, int size, ref int usedSize, uint cutVer)
        {
            if (((buffer == null) || (buffer.GetLength(0) == 0)) || (size > buffer.GetLength(0)))
            {
                return(TdrError.ErrorType.TDR_ERR_INVALID_BUFFER_PARAMETER);
            }
            TdrReadBuf srcBuf = ClassObjPool <TdrReadBuf> .Get();

            srcBuf.set(ref buffer, size);
            TdrError.ErrorType type = this.unpack(ref srcBuf, cutVer);
            usedSize = srcBuf.getUsedSize();
            srcBuf.Release();
            return(type);
        }
Beispiel #3
0
        public TdrError.ErrorType unpackTLV(ref byte[] buffer, int size, ref int used)
        {
            if (buffer == null || buffer.GetLength(0) == 0 || size > buffer.GetLength(0))
            {
                return(TdrError.ErrorType.TDR_ERR_INVALID_BUFFER_PARAMETER);
            }
            if (size < TdrTLV.TLV_MSG_MIN_SIZE)
            {
                return(TdrError.ErrorType.TDR_ERR_SHORT_BUF_FOR_READ);
            }
            TdrReadBuf tdrReadBuf = new TdrReadBuf(ref buffer, size);
            byte       b          = 0;

            TdrError.ErrorType errorType = tdrReadBuf.readUInt8(ref b);
            if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
            {
                return(errorType);
            }
            bool useVarInt;

            if (b == 170)
            {
                useVarInt = true;
            }
            else
            {
                if (b != 153)
                {
                    return(TdrError.ErrorType.TDR_ERR_BAD_TLV_MAGIC);
                }
                useVarInt = false;
            }
            int num = 0;

            tdrReadBuf.readInt32(ref num);
            if (size < num)
            {
                return(TdrError.ErrorType.TDR_ERR_SHORT_BUF_FOR_READ);
            }
            errorType = this.unpackTLV(ref tdrReadBuf, num - TdrTLV.TLV_MSG_MIN_SIZE, useVarInt);
            if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
            {
                return(errorType);
            }
            used = tdrReadBuf.getUsedSize();
            return(errorType);
        }
Beispiel #4
0
        public TdrError.ErrorType unpackTLV(ref byte[] buffer, int size, ref int used)
        {
            if (((buffer == null) || (buffer.GetLength(0) == 0)) || (size > buffer.GetLength(0)))
            {
                return(TdrError.ErrorType.TDR_ERR_INVALID_BUFFER_PARAMETER);
            }
            if (size < TdrTLV.TLV_MSG_MIN_SIZE)
            {
                return(TdrError.ErrorType.TDR_ERR_SHORT_BUF_FOR_READ);
            }
            TdrReadBuf srcBuf = new TdrReadBuf(ref buffer, size);

            TdrError.ErrorType type = TdrError.ErrorType.TDR_NO_ERROR;
            byte dest      = 0;
            bool useVarInt = true;

            type = srcBuf.readUInt8(ref dest);
            if (type == TdrError.ErrorType.TDR_NO_ERROR)
            {
                switch (dest)
                {
                case 170:
                    useVarInt = true;
                    break;

                case 0x99:
                    useVarInt = false;
                    break;

                default:
                    return(TdrError.ErrorType.TDR_ERR_BAD_TLV_MAGIC);
                }
                int num2 = 0;
                srcBuf.readInt32(ref num2);
                if (size < num2)
                {
                    return(TdrError.ErrorType.TDR_ERR_SHORT_BUF_FOR_READ);
                }
                type = this.unpackTLV(ref srcBuf, num2 - TdrTLV.TLV_MSG_MIN_SIZE, useVarInt);
                if (type == TdrError.ErrorType.TDR_NO_ERROR)
                {
                    used = srcBuf.getUsedSize();
                }
            }
            return(type);
        }
Beispiel #5
0
        public TdrError.ErrorType load(ref byte[] buffer, int size, ref int usedSize, uint cutVer)
        {
            if (null == buffer || 0 == buffer.GetLength(0) || size > buffer.GetLength(0))
            {
#if (DEBUG)
                TdrDebug.tdrTrace();
#endif
                return(TdrError.ErrorType.TDR_ERR_INVALID_BUFFER_PARAMETER);
            }

            TdrReadBuf         srcBuf = new TdrReadBuf(ref buffer, size);
            TdrError.ErrorType ret    = load(ref srcBuf, cutVer);

            usedSize = srcBuf.getUsedSize();

            return(ret);
        }
Beispiel #6
0
        public TdrError.ErrorType load(ref byte [] buffer, int size, ref int usedSize, uint cutVer)
        {
            if (null == buffer || 0 == buffer.GetLength(0) || size > buffer.GetLength(0))
            {
#if (DEBUG)
                StackTrace st = new StackTrace(true);
                for (int i = 0; i < st.FrameCount; i++)
                {
                    if (null != st.GetFrame(i).GetFileName())
                    {
                        Console.WriteLine("TSF4G_TRACE:  " + st.GetFrame(i).ToString());
                    }
                }
#endif
                return(TdrError.ErrorType.TDR_ERR_INVALID_BUFFER_PARAMETER);
            }

            TdrReadBuf         srcBuf = new TdrReadBuf(ref buffer, size);
            TdrError.ErrorType ret    = load(ref srcBuf, cutVer);

            usedSize = srcBuf.getUsedSize();

            return(ret);
        }
        public TdrError.ErrorType unpackTLV(ref TdrReadBuf srcBuf, int length, bool useVarInt)
        {
            if (srcBuf == null || length <= 0)
            {
                return(TdrError.ErrorType.TDR_ERR_ARG_IS_NULL);
            }
            TdrError.ErrorType errorType = TdrError.ErrorType.TDR_NO_ERROR;
            uint tagid    = 0u;
            int  num      = 0;
            int  usedSize = srcBuf.getUsedSize();

            while (srcBuf.getUsedSize() < usedSize + length)
            {
                errorType = srcBuf.readVarUInt32(ref tagid);
                if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                {
                    return(errorType);
                }
                uint fieldId = TdrTLV.getFieldId(tagid);
                uint num2    = fieldId;
                if (num2 != 1u)
                {
                    if (num2 != 2u)
                    {
                        uint typeId = TdrTLV.getTypeId(tagid);
                        errorType = TdrTLV.skipUnknownFields(ref srcBuf, (TdrTLV.TdrTLVTypeId)typeId);
                        if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                        {
                            return(errorType);
                        }
                    }
                    else
                    {
                        if (!this.has_HeaderContent())
                        {
                            this.set_has_HeaderContent();
                        }
                        int num3 = 0;
                        errorType = srcBuf.readInt32(ref num3);
                        if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                        {
                            return(errorType);
                        }
                        if (num3 >= 260)
                        {
                            return(TdrError.ErrorType.TDR_ERR_STR_LEN_TOO_BIG);
                        }
                        errorType = srcBuf.readCString(ref this.szHeaderContent, num3);
                        if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                        {
                            return(errorType);
                        }
                    }
                }
                else
                {
                    if (!this.has_HeaderName())
                    {
                        this.set_has_HeaderName();
                    }
                    int num4 = 0;
                    errorType = srcBuf.readInt32(ref num4);
                    if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        return(errorType);
                    }
                    if (num4 >= 80)
                    {
                        return(TdrError.ErrorType.TDR_ERR_STR_LEN_TOO_BIG);
                    }
                    errorType = srcBuf.readCString(ref this.szHeaderName, num4);
                    if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        return(errorType);
                    }
                }
            }
            if (srcBuf.getUsedSize() > usedSize + length)
            {
                return(TdrError.ErrorType.TDR_ERR_UNMATCHED_LENGTH);
            }
            if (num < this.requiredFieldNum())
            {
                return(TdrError.ErrorType.TDR_ERR_LOST_REQUIRED_FIELD);
            }
            return(errorType);
        }
Beispiel #8
0
        public TdrError.ErrorType unpackTLV(ref TdrReadBuf srcBuf, int length, bool useVarInt)
        {
            if ((srcBuf == null) || (length <= 0))
            {
                return(TdrError.ErrorType.TDR_ERR_ARG_IS_NULL);
            }
            TdrError.ErrorType type = TdrError.ErrorType.TDR_NO_ERROR;
            uint dest = 0;
            int  num3 = 0;
            int  num4 = srcBuf.getUsedSize();

            while (srcBuf.getUsedSize() < (num4 + length))
            {
                type = srcBuf.readVarUInt32(ref dest);
                if (type != TdrError.ErrorType.TDR_NO_ERROR)
                {
                    return(type);
                }
                switch (TdrTLV.getFieldId(dest))
                {
                case 1:
                    if (!this.has_Len())
                    {
                        this.set_has_Len();
                    }
                    if (useVarInt)
                    {
                        type = srcBuf.readVarUInt16(ref this.wLen);
                        if (type != TdrError.ErrorType.TDR_NO_ERROR)
                        {
                            return(type);
                        }
                        continue;
                    }
                    type = srcBuf.readUInt16(ref this.wLen);
                    if (type == TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        continue;
                    }
                    return(type);

                case 2:
                {
                    if (!this.has_Data())
                    {
                        this.set_has_Data();
                    }
                    int num5 = 0;
                    type = srcBuf.readInt32(ref num5);
                    if (type != TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        return(type);
                    }
                    if (num5 == 0)
                    {
                        return(TdrError.ErrorType.TDR_ERR_NULL_ARRAY);
                    }
                    int num6 = srcBuf.getUsedSize();
                    for (int i = 0; i < 0xffff; i++)
                    {
                        type = srcBuf.readUInt8(ref this.szData[i]);
                        if (type != TdrError.ErrorType.TDR_NO_ERROR)
                        {
                            return(type);
                        }
                        if (srcBuf.getUsedSize() > (num6 + num5))
                        {
                            return(TdrError.ErrorType.TDR_ERR_UNMATCHED_LENGTH);
                        }
                        if (srcBuf.getUsedSize() == (num6 + num5))
                        {
                            this.wLen = (ushort)(i + 1);
                            break;
                        }
                    }
                    continue;
                }
                }
                uint num8 = TdrTLV.getTypeId(dest);
                type = TdrTLV.skipUnknownFields(ref srcBuf, (TdrTLV.TdrTLVTypeId)num8);
                if (type != TdrError.ErrorType.TDR_NO_ERROR)
                {
                    return(type);
                }
            }
            if (srcBuf.getUsedSize() > (num4 + length))
            {
                return(TdrError.ErrorType.TDR_ERR_UNMATCHED_LENGTH);
            }
            if (num3 < this.requiredFieldNum())
            {
                return(TdrError.ErrorType.TDR_ERR_LOST_REQUIRED_FIELD);
            }
            return(type);
        }
        public TdrError.ErrorType unpackTLV(ref TdrReadBuf srcBuf, int length, bool useVarInt)
        {
            if (srcBuf == null || length <= 0)
            {
                return(TdrError.ErrorType.TDR_ERR_ARG_IS_NULL);
            }
            TdrError.ErrorType errorType = TdrError.ErrorType.TDR_NO_ERROR;
            uint tagid    = 0u;
            int  num      = 0;
            int  usedSize = srcBuf.getUsedSize();

            while (srcBuf.getUsedSize() < usedSize + length)
            {
                errorType = srcBuf.readVarUInt32(ref tagid);
                if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                {
                    return(errorType);
                }
                switch (TdrTLV.getFieldId(tagid))
                {
                case 1u:
                    if (!this.has_Async())
                    {
                        this.set_has_Async();
                    }
                    if (useVarInt)
                    {
                        errorType = srcBuf.readVarUInt32(ref this.dwAsync);
                        if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                        {
                            return(errorType);
                        }
                    }
                    else
                    {
                        errorType = srcBuf.readUInt32(ref this.dwAsync);
                        if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                        {
                            return(errorType);
                        }
                    }
                    break;

                case 2u:
                    if (!this.has_Flag())
                    {
                        this.set_has_Flag();
                    }
                    errorType = srcBuf.readUInt8(ref this.bFlag);
                    if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        return(errorType);
                    }
                    break;

                case 3u:
                    if (!this.has_Domain())
                    {
                        this.set_has_Domain();
                    }
                    errorType = srcBuf.readUInt8(ref this.bDomain);
                    if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        return(errorType);
                    }
                    break;

                case 4u:
                    if (!this.has_CmdFmt())
                    {
                        this.set_has_CmdFmt();
                    }
                    errorType = srcBuf.readUInt8(ref this.bCmdFmt);
                    if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        return(errorType);
                    }
                    break;

                case 5u:
                {
                    int length2 = 0;
                    errorType = srcBuf.readInt32(ref length2);
                    if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        return(errorType);
                    }
                    long num2 = 0L;
                    errorType = this.stCommand.unpackTLV(ref num2, ref srcBuf, length2, useVarInt);
                    if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        return(errorType);
                    }
                    this.bCmdFmt = (byte)num2;
                    break;
                }

                default:
                {
                    uint typeId = TdrTLV.getTypeId(tagid);
                    errorType = TdrTLV.skipUnknownFields(ref srcBuf, (TdrTLV.TdrTLVTypeId)typeId);
                    if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        return(errorType);
                    }
                    break;
                }
                }
            }
            if (srcBuf.getUsedSize() > usedSize + length)
            {
                return(TdrError.ErrorType.TDR_ERR_UNMATCHED_LENGTH);
            }
            if (num < this.requiredFieldNum())
            {
                return(TdrError.ErrorType.TDR_ERR_LOST_REQUIRED_FIELD);
            }
            return(errorType);
        }
        public TdrError.ErrorType unpackTLV(ref TdrReadBuf srcBuf, int length, bool useVarInt)
        {
            if (srcBuf == null || length <= 0)
            {
                return(TdrError.ErrorType.TDR_ERR_ARG_IS_NULL);
            }
            TdrError.ErrorType errorType = TdrError.ErrorType.TDR_NO_ERROR;
            uint tagid    = 0u;
            int  num      = 0;
            int  usedSize = srcBuf.getUsedSize();

            while (srcBuf.getUsedSize() < usedSize + length)
            {
                errorType = srcBuf.readVarUInt32(ref tagid);
                if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                {
                    return(errorType);
                }
                switch (TdrTLV.getFieldId(tagid))
                {
                case 1u:
                {
                    if (!this.has_RequestMethod())
                    {
                        this.set_has_RequestMethod();
                    }
                    int num2 = 0;
                    errorType = srcBuf.readInt32(ref num2);
                    if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        return(errorType);
                    }
                    if (num2 >= 32)
                    {
                        return(TdrError.ErrorType.TDR_ERR_STR_LEN_TOO_BIG);
                    }
                    errorType = srcBuf.readCString(ref this.szRequestMethod, num2);
                    if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        return(errorType);
                    }
                    break;
                }

                case 2u:
                {
                    if (!this.has_RequestUri())
                    {
                        this.set_has_RequestUri();
                    }
                    int num3 = 0;
                    errorType = srcBuf.readInt32(ref num3);
                    if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        return(errorType);
                    }
                    if (num3 >= 1024)
                    {
                        return(TdrError.ErrorType.TDR_ERR_STR_LEN_TOO_BIG);
                    }
                    errorType = srcBuf.readCString(ref this.szRequestUri, num3);
                    if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        return(errorType);
                    }
                    break;
                }

                case 3u:
                {
                    if (!this.has_HttpVersion())
                    {
                        this.set_has_HttpVersion();
                    }
                    int num4 = 0;
                    errorType = srcBuf.readInt32(ref num4);
                    if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        return(errorType);
                    }
                    if (num4 >= 32)
                    {
                        return(TdrError.ErrorType.TDR_ERR_STR_LEN_TOO_BIG);
                    }
                    errorType = srcBuf.readCString(ref this.szHttpVersion, num4);
                    if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        return(errorType);
                    }
                    break;
                }

                default:
                {
                    uint typeId = TdrTLV.getTypeId(tagid);
                    errorType = TdrTLV.skipUnknownFields(ref srcBuf, (TdrTLV.TdrTLVTypeId)typeId);
                    if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        return(errorType);
                    }
                    break;
                }
                }
            }
            if (srcBuf.getUsedSize() > usedSize + length)
            {
                return(TdrError.ErrorType.TDR_ERR_UNMATCHED_LENGTH);
            }
            if (num < this.requiredFieldNum())
            {
                return(TdrError.ErrorType.TDR_ERR_LOST_REQUIRED_FIELD);
            }
            return(errorType);
        }
        public TdrError.ErrorType unpackTLV(ref TdrReadBuf srcBuf, int length, bool useVarInt)
        {
            if (srcBuf == null || length <= 0)
            {
                return(TdrError.ErrorType.TDR_ERR_ARG_IS_NULL);
            }
            TdrError.ErrorType errorType = TdrError.ErrorType.TDR_NO_ERROR;
            uint tagid    = 0u;
            int  num      = 0;
            int  usedSize = srcBuf.getUsedSize();

            while (srcBuf.getUsedSize() < usedSize + length)
            {
                errorType = srcBuf.readVarUInt32(ref tagid);
                if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                {
                    return(errorType);
                }
                switch (TdrTLV.getFieldId(tagid))
                {
                case 1u:
                {
                    if (!this.has_RequestLine())
                    {
                        this.set_has_RequestLine();
                    }
                    int length2 = 0;
                    errorType = srcBuf.readInt32(ref length2);
                    if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        return(errorType);
                    }
                    errorType = this.stRequestLine.unpackTLV(ref srcBuf, length2, useVarInt);
                    if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        return(errorType);
                    }
                    break;
                }

                case 2u:
                {
                    if (!this.has_HttpHeaders())
                    {
                        this.set_has_HttpHeaders();
                    }
                    int length3 = 0;
                    errorType = srcBuf.readInt32(ref length3);
                    if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        return(errorType);
                    }
                    errorType = this.stHttpHeaders.unpackTLV(ref srcBuf, length3, useVarInt);
                    if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        return(errorType);
                    }
                    break;
                }

                case 3u:
                {
                    if (!this.has_RequestContent())
                    {
                        this.set_has_RequestContent();
                    }
                    int length4 = 0;
                    errorType = srcBuf.readInt32(ref length4);
                    if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        return(errorType);
                    }
                    errorType = this.stRequestContent.unpackTLV(ref srcBuf, length4, useVarInt);
                    if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        return(errorType);
                    }
                    break;
                }

                default:
                {
                    uint typeId = TdrTLV.getTypeId(tagid);
                    errorType = TdrTLV.skipUnknownFields(ref srcBuf, (TdrTLV.TdrTLVTypeId)typeId);
                    if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        return(errorType);
                    }
                    break;
                }
                }
            }
            if (srcBuf.getUsedSize() > usedSize + length)
            {
                return(TdrError.ErrorType.TDR_ERR_UNMATCHED_LENGTH);
            }
            if (num < this.requiredFieldNum())
            {
                return(TdrError.ErrorType.TDR_ERR_LOST_REQUIRED_FIELD);
            }
            return(errorType);
        }
        public TdrError.ErrorType unpackTLV(ref long selector, ref TdrReadBuf srcBuf, int length, bool useVarInt)
        {
            if (srcBuf == null || length == 0)
            {
                return(TdrError.ErrorType.TDR_ERR_INVALID_BUFFER_PARAMETER);
            }
            int  usedSize = srcBuf.getUsedSize();
            uint tagid    = 0u;

            TdrError.ErrorType errorType = srcBuf.readVarUInt32(ref tagid);
            if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
            {
                return(errorType);
            }
            uint fieldId = TdrTLV.getFieldId(tagid);

            switch (fieldId)
            {
            case 0u:
                if (useVarInt)
                {
                    errorType = srcBuf.readVarInt32(ref this.iNilCmd);
                    if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        return(errorType);
                    }
                }
                else
                {
                    errorType = srcBuf.readInt32(ref this.iNilCmd);
                    if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        return(errorType);
                    }
                }
                break;

            case 1u:
            {
                if (this.szStrCmd == null)
                {
                    this.szStrCmd = new byte[64];
                }
                int num = 0;
                errorType = srcBuf.readInt32(ref num);
                if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                {
                    return(errorType);
                }
                if (num >= 64)
                {
                    return(TdrError.ErrorType.TDR_ERR_STR_LEN_TOO_BIG);
                }
                errorType = srcBuf.readCString(ref this.szStrCmd, num);
                if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                {
                    return(errorType);
                }
                break;
            }

            case 2u:
                if (useVarInt)
                {
                    errorType = srcBuf.readVarInt32(ref this.iIntCmd);
                    if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        return(errorType);
                    }
                }
                else
                {
                    errorType = srcBuf.readInt32(ref this.iIntCmd);
                    if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        return(errorType);
                    }
                }
                break;

            default:
                errorType = TdrError.ErrorType.TDR_ERR_SUSPICIOUS_SELECTOR;
                break;
            }
            if (srcBuf.getUsedSize() > usedSize + length)
            {
                return(TdrError.ErrorType.TDR_ERR_UNMATCHED_LENGTH);
            }
            selector = (long)((ulong)fieldId);
            return(errorType);
        }
Beispiel #13
0
        public TdrError.ErrorType unpackTLV(ref TdrReadBuf srcBuf, int length, bool useVarInt)
        {
            if ((srcBuf == null) || (length <= 0))
            {
                return(TdrError.ErrorType.TDR_ERR_ARG_IS_NULL);
            }
            TdrError.ErrorType type = TdrError.ErrorType.TDR_NO_ERROR;
            uint dest = 0;
            int  num3 = 0;
            int  num4 = srcBuf.getUsedSize();

            while (srcBuf.getUsedSize() < (num4 + length))
            {
                type = srcBuf.readVarUInt32(ref dest);
                if (type != TdrError.ErrorType.TDR_NO_ERROR)
                {
                    return(type);
                }
                switch (TdrTLV.getFieldId(dest))
                {
                case 1:
                {
                    if (!this.has_HttpVersion())
                    {
                        this.set_has_HttpVersion();
                    }
                    int num5 = 0;
                    type = srcBuf.readInt32(ref num5);
                    if (type == TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        if (num5 >= 0x20)
                        {
                            return(TdrError.ErrorType.TDR_ERR_STR_LEN_TOO_BIG);
                        }
                        type = srcBuf.readCString(ref this.szHttpVersion, num5);
                        if (type == TdrError.ErrorType.TDR_NO_ERROR)
                        {
                            continue;
                        }
                    }
                    return(type);
                }

                case 2:
                {
                    if (!this.has_StatusCode())
                    {
                        this.set_has_StatusCode();
                    }
                    int num6 = 0;
                    type = srcBuf.readInt32(ref num6);
                    if (type == TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        if (num6 >= 0x10)
                        {
                            return(TdrError.ErrorType.TDR_ERR_STR_LEN_TOO_BIG);
                        }
                        type = srcBuf.readCString(ref this.szStatusCode, num6);
                        if (type == TdrError.ErrorType.TDR_NO_ERROR)
                        {
                            continue;
                        }
                    }
                    return(type);
                }

                case 3:
                {
                    if (!this.has_ReasonPhrase())
                    {
                        this.set_has_ReasonPhrase();
                    }
                    int num7 = 0;
                    type = srcBuf.readInt32(ref num7);
                    if (type == TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        if (num7 >= 0x40)
                        {
                            return(TdrError.ErrorType.TDR_ERR_STR_LEN_TOO_BIG);
                        }
                        type = srcBuf.readCString(ref this.szReasonPhrase, num7);
                        if (type == TdrError.ErrorType.TDR_NO_ERROR)
                        {
                            continue;
                        }
                    }
                    return(type);
                }
                }
                uint num8 = TdrTLV.getTypeId(dest);
                type = TdrTLV.skipUnknownFields(ref srcBuf, (TdrTLV.TdrTLVTypeId)num8);
                if (type != TdrError.ErrorType.TDR_NO_ERROR)
                {
                    return(type);
                }
            }
            if (srcBuf.getUsedSize() > (num4 + length))
            {
                return(TdrError.ErrorType.TDR_ERR_UNMATCHED_LENGTH);
            }
            if (num3 < this.requiredFieldNum())
            {
                return(TdrError.ErrorType.TDR_ERR_LOST_REQUIRED_FIELD);
            }
            return(type);
        }
Beispiel #14
0
        public TdrError.ErrorType unpackTLV(ref TdrReadBuf srcBuf, int length, bool useVarInt)
        {
            if ((srcBuf == null) || (length <= 0))
            {
                return(TdrError.ErrorType.TDR_ERR_ARG_IS_NULL);
            }
            TdrError.ErrorType type = TdrError.ErrorType.TDR_NO_ERROR;
            uint dest = 0;
            int  num3 = 0;
            int  num4 = srcBuf.getUsedSize();

            while (srcBuf.getUsedSize() < (num4 + length))
            {
                int  num5;
                uint num7;
                type = srcBuf.readVarUInt32(ref dest);
                if (type != TdrError.ErrorType.TDR_NO_ERROR)
                {
                    return(type);
                }
                switch (TdrTLV.getFieldId(dest))
                {
                case 1:
                    if (!this.has_Async())
                    {
                        this.set_has_Async();
                    }
                    if (useVarInt)
                    {
                        type = srcBuf.readVarUInt32(ref this.dwAsync);
                        if (type != TdrError.ErrorType.TDR_NO_ERROR)
                        {
                            return(type);
                        }
                        continue;
                    }
                    type = srcBuf.readUInt32(ref this.dwAsync);
                    if (type == TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        continue;
                    }
                    return(type);

                case 2:
                    if (!this.has_Flag())
                    {
                        this.set_has_Flag();
                    }
                    type = srcBuf.readUInt8(ref this.bFlag);
                    if (type == TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        continue;
                    }
                    return(type);

                case 3:
                    if (!this.has_Domain())
                    {
                        this.set_has_Domain();
                    }
                    type = srcBuf.readUInt8(ref this.bDomain);
                    if (type == TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        continue;
                    }
                    return(type);

                case 4:
                    if (!this.has_CmdFmt())
                    {
                        this.set_has_CmdFmt();
                    }
                    type = srcBuf.readUInt8(ref this.bCmdFmt);
                    if (type == TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        continue;
                    }
                    return(type);

                case 5:
                    num5 = 0;
                    type = srcBuf.readInt32(ref num5);
                    if (type == TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        break;
                    }
                    return(type);

                default:
                    goto Label_0177;
                }
                long selector = 0L;
                type = this.stCommand.unpackTLV(ref selector, ref srcBuf, num5, useVarInt);
                if (type != TdrError.ErrorType.TDR_NO_ERROR)
                {
                    return(type);
                }
                this.bCmdFmt = (byte)selector;
                continue;
Label_0177:
                num7 = TdrTLV.getTypeId(dest);
                type = TdrTLV.skipUnknownFields(ref srcBuf, (TdrTLV.TdrTLVTypeId)num7);
                if (type != TdrError.ErrorType.TDR_NO_ERROR)
                {
                    return(type);
                }
            }
            if (srcBuf.getUsedSize() > (num4 + length))
            {
                return(TdrError.ErrorType.TDR_ERR_UNMATCHED_LENGTH);
            }
            if (num3 < this.requiredFieldNum())
            {
                return(TdrError.ErrorType.TDR_ERR_LOST_REQUIRED_FIELD);
            }
            return(type);
        }
Beispiel #15
0
        public TdrError.ErrorType unpackTLV(ref TdrReadBuf srcBuf, int length, bool useVarInt)
        {
            if (srcBuf == null || length <= 0)
            {
                return(TdrError.ErrorType.TDR_ERR_ARG_IS_NULL);
            }
            TdrError.ErrorType errorType = TdrError.ErrorType.TDR_NO_ERROR;
            uint tagid    = 0u;
            int  num      = 0;
            int  usedSize = srcBuf.getUsedSize();

            while (srcBuf.getUsedSize() < usedSize + length)
            {
                errorType = srcBuf.readVarUInt32(ref tagid);
                if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                {
                    return(errorType);
                }
                uint fieldId = TdrTLV.getFieldId(tagid);
                uint num2    = fieldId;
                if (num2 != 1u)
                {
                    if (num2 != 2u)
                    {
                        uint typeId = TdrTLV.getTypeId(tagid);
                        errorType = TdrTLV.skipUnknownFields(ref srcBuf, (TdrTLV.TdrTLVTypeId)typeId);
                        if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                        {
                            return(errorType);
                        }
                    }
                    else
                    {
                        if (!this.has_Data())
                        {
                            this.set_has_Data();
                        }
                        int num3 = 0;
                        errorType = srcBuf.readInt32(ref num3);
                        if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                        {
                            return(errorType);
                        }
                        if (num3 == 0)
                        {
                            return(TdrError.ErrorType.TDR_ERR_NULL_ARRAY);
                        }
                        int usedSize2 = srcBuf.getUsedSize();
                        for (int i = 0; i < 1048576; i++)
                        {
                            errorType = srcBuf.readUInt8(ref this.szData[i]);
                            if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                            {
                                return(errorType);
                            }
                            if (srcBuf.getUsedSize() > usedSize2 + num3)
                            {
                                return(TdrError.ErrorType.TDR_ERR_UNMATCHED_LENGTH);
                            }
                            if (srcBuf.getUsedSize() == usedSize2 + num3)
                            {
                                this.dwDataLen = (uint)(i + 1);
                                break;
                            }
                        }
                    }
                }
                else
                {
                    if (!this.has_DataLen())
                    {
                        this.set_has_DataLen();
                    }
                    if (useVarInt)
                    {
                        errorType = srcBuf.readVarUInt32(ref this.dwDataLen);
                        if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                        {
                            return(errorType);
                        }
                    }
                    else
                    {
                        errorType = srcBuf.readUInt32(ref this.dwDataLen);
                        if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
                        {
                            return(errorType);
                        }
                    }
                }
            }
            if (srcBuf.getUsedSize() > usedSize + length)
            {
                return(TdrError.ErrorType.TDR_ERR_UNMATCHED_LENGTH);
            }
            if (num < this.requiredFieldNum())
            {
                return(TdrError.ErrorType.TDR_ERR_LOST_REQUIRED_FIELD);
            }
            return(errorType);
        }
Beispiel #16
0
        public TdrError.ErrorType unpackTLV(ref TdrReadBuf srcBuf, int length, bool useVarInt)
        {
            if ((srcBuf == null) || (length <= 0))
            {
                return(TdrError.ErrorType.TDR_ERR_ARG_IS_NULL);
            }
            TdrError.ErrorType type = TdrError.ErrorType.TDR_NO_ERROR;
            uint dest = 0;
            int  num3 = 0;
            int  num4 = srcBuf.getUsedSize();

            while (srcBuf.getUsedSize() < (num4 + length))
            {
                type = srcBuf.readVarUInt32(ref dest);
                if (type != TdrError.ErrorType.TDR_NO_ERROR)
                {
                    return(type);
                }
                switch (TdrTLV.getFieldId(dest))
                {
                case 1:
                {
                    if (!this.has_RequestLine())
                    {
                        this.set_has_RequestLine();
                    }
                    int num5 = 0;
                    type = srcBuf.readInt32(ref num5);
                    if (type == TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        type = this.stRequestLine.unpackTLV(ref srcBuf, num5, useVarInt);
                        if (type == TdrError.ErrorType.TDR_NO_ERROR)
                        {
                            continue;
                        }
                    }
                    return(type);
                }

                case 2:
                {
                    if (!this.has_HttpHeaders())
                    {
                        this.set_has_HttpHeaders();
                    }
                    int num6 = 0;
                    type = srcBuf.readInt32(ref num6);
                    if (type == TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        type = this.stHttpHeaders.unpackTLV(ref srcBuf, num6, useVarInt);
                        if (type == TdrError.ErrorType.TDR_NO_ERROR)
                        {
                            continue;
                        }
                    }
                    return(type);
                }

                case 3:
                {
                    if (!this.has_RequestContent())
                    {
                        this.set_has_RequestContent();
                    }
                    int num7 = 0;
                    type = srcBuf.readInt32(ref num7);
                    if (type == TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        type = this.stRequestContent.unpackTLV(ref srcBuf, num7, useVarInt);
                        if (type == TdrError.ErrorType.TDR_NO_ERROR)
                        {
                            continue;
                        }
                    }
                    return(type);
                }
                }
                uint num8 = TdrTLV.getTypeId(dest);
                type = TdrTLV.skipUnknownFields(ref srcBuf, (TdrTLV.TdrTLVTypeId)num8);
                if (type != TdrError.ErrorType.TDR_NO_ERROR)
                {
                    return(type);
                }
            }
            if (srcBuf.getUsedSize() > (num4 + length))
            {
                return(TdrError.ErrorType.TDR_ERR_UNMATCHED_LENGTH);
            }
            if (num3 < this.requiredFieldNum())
            {
                return(TdrError.ErrorType.TDR_ERR_LOST_REQUIRED_FIELD);
            }
            return(type);
        }
Beispiel #17
0
        public TdrError.ErrorType unpackTLV(ref long selector, ref TdrReadBuf srcBuf, int length, bool useVarInt)
        {
            if ((srcBuf == null) || (length == 0))
            {
                return(TdrError.ErrorType.TDR_ERR_INVALID_BUFFER_PARAMETER);
            }
            TdrError.ErrorType type = TdrError.ErrorType.TDR_NO_ERROR;
            int  num  = srcBuf.getUsedSize();
            uint dest = 0;

            type = srcBuf.readVarUInt32(ref dest);
            if (type == TdrError.ErrorType.TDR_NO_ERROR)
            {
                uint num3 = TdrTLV.getFieldId(dest);
                switch (num3)
                {
                case 0:
                    if (!useVarInt)
                    {
                        type = srcBuf.readInt32(ref this.iNilCmd);
                        if (type == TdrError.ErrorType.TDR_NO_ERROR)
                        {
                            break;
                        }
                        return(type);
                    }
                    type = srcBuf.readVarInt32(ref this.iNilCmd);
                    if (type == TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        break;
                    }
                    return(type);

                case 1:
                {
                    if (this.szStrCmd == null)
                    {
                        this.szStrCmd = new byte[0x40];
                    }
                    int num4 = 0;
                    type = srcBuf.readInt32(ref num4);
                    if (type == TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        if (num4 >= 0x40)
                        {
                            return(TdrError.ErrorType.TDR_ERR_STR_LEN_TOO_BIG);
                        }
                        type = srcBuf.readCString(ref this.szStrCmd, num4);
                        if (type == TdrError.ErrorType.TDR_NO_ERROR)
                        {
                            break;
                        }
                    }
                    return(type);
                }

                case 2:
                    if (!useVarInt)
                    {
                        type = srcBuf.readInt32(ref this.iIntCmd);
                        if (type == TdrError.ErrorType.TDR_NO_ERROR)
                        {
                            break;
                        }
                        return(type);
                    }
                    type = srcBuf.readVarInt32(ref this.iIntCmd);
                    if (type == TdrError.ErrorType.TDR_NO_ERROR)
                    {
                        break;
                    }
                    return(type);

                default:
                    type = TdrError.ErrorType.TDR_ERR_SUSPICIOUS_SELECTOR;
                    break;
                }
                if (srcBuf.getUsedSize() > (num + length))
                {
                    return(TdrError.ErrorType.TDR_ERR_UNMATCHED_LENGTH);
                }
                selector = num3;
            }
            return(type);
        }