示例#1
0
文件: main.cs 项目: prates/SPDYtools
 static void Main()
 {
     Dictionary<string, string> nam = new Dictionary<string, string>();
     nam.Add("teste", "teste");
     spdyserver.Namevalue name = new spdyserver.Namevalue(nam);
     byte [] result = name.Make(nam);
     Dictionary<string, string> final = name.Extract(result);
     Console.WriteLine(final.Count);
     System.Console.WriteLine(final["teste"]);
 }
示例#2
0
        public void encoding()
        {
            Dictionary <string, string> d = new Dictionary<string, string>();
            d.Add("teste","teste");
            d.Add("2323","3242");
            spdyserver.Namevalue name = new spdyserver.Namevalue(d);
            byte [] ret = name.Make(d);
            Dictionary <string, string> dict1 = name.Extract(ret);

            Console.WriteLine(dict1);
            Assert.AreEqual(d, dict1);
        }
示例#3
0
        public void Extract(byte [] stream)
        {
            //check type
            byte [] temp = new byte[4];
            System.Buffer.BlockCopy(stream, 0 , temp, 0, sizeof(UInt32));
            if(BitConverter.ToUInt32(temp, 0)>=0x80000000){//FRAME CONTROL
                byte [] temp32 = new byte[sizeof(UInt32)];
                Buffer.BlockCopy(stream, 0, temp32, 0, sizeof(UInt32));
                this.header.Add("Control", 1);

                this.header.Add("Version", BitConverter.ToUInt32(temp32, 0)&0x7fff0000);
                this.header["Version"]=this.header["Version"] >> 16;
                this.header.Add("Type", BitConverter.ToUInt32(temp32, 0)&0x0000ffff);
                Buffer.BlockCopy(stream, 4, temp32, 0, sizeof(UInt32));
                this.header.Add("Length", BitConverter.ToUInt32(temp32, 0)&0x00ffffff);
                this.header.Add("Flag", (BitConverter.ToUInt32(temp32, 0)&0xff000000)>>24);
                //TRATAMENTO DIFERENTE PARA CADA FRAME
                if(this.header["Type"]==1){//syn_streamxc
                    Buffer.BlockCopy(stream, 8, temp32, 0, sizeof(UInt32));
                    this.header.Add("StreamID", BitConverter.ToUInt32(temp32, 0));
                    Buffer.BlockCopy(stream, 12, temp32, 0, sizeof(UInt32));
                    this.header.Add("Associated", BitConverter.ToUInt32(temp32, 0));
                    Buffer.BlockCopy(stream, 16, temp32, 0, sizeof(UInt32));
                    this.header.Add("Priority", ((BitConverter.ToUInt32(temp32, 0)&0xe0000000)>>12));
                    spdyserver.Namevalue name = new spdyserver.Namevalue();
                    byte [] bod = new byte[stream.Length-18];
                    Buffer.BlockCopy(stream, 18, bod, 0, bod.Length);
                    this.body = name.Extract(bod);
                }else if(this.header["Type"]==2 || this.header["Type"]==8){//syn_replay or header
                    Buffer.BlockCopy(stream, 8, temp32, 0, sizeof(UInt32));
                    this.header.Add("StreamID", BitConverter.ToUInt32(temp32, 0));
                    spdyserver.Namevalue ex = new spdyserver.Namevalue();
                    byte [] bod = new byte[stream.Length-12];
                    Buffer.BlockCopy(stream, 12, bod, 0, bod.Length);
                    this.body = ex.Extract(bod);
                }else if(this.header["Type"]==3){//reset_stream
                    Buffer.BlockCopy(stream, 8, temp32, 0, sizeof(UInt32));
                    this.header.Add("StreamID", BitConverter.ToUInt32(temp32, 0));
                    Buffer.BlockCopy(stream, 12, temp32, 0, sizeof(UInt32));
                    this.header["Status_code"]=BitConverter.ToUInt32(temp32, 0);
                }else if (this.header["Type"]==6){//ping
                    Buffer.BlockCopy(stream, 8, temp32, 0, sizeof(UInt32));
                    this.header.Add("ID", BitConverter.ToUInt32(temp32, 0));
                }else if(this.header["Type"]==7){//Goaway
                    Buffer.BlockCopy(stream, 8, temp32, 0, sizeof(UInt32));
                    this.header.Add("Last", BitConverter.ToUInt32(temp32, 0));
                    Buffer.BlockCopy(stream, 12, temp32, 0, sizeof(UInt32));
                    this.header.Add("Status", BitConverter.ToUInt32(temp32, 0));
                }else if(this.header["Type"]==9){//WindowsUpdate
                    Buffer.BlockCopy(stream, 8, temp32, 0, sizeof(UInt32));
                    this.header.Add("StreamID", BitConverter.ToUInt32(temp32, 0));
                    Buffer.BlockCopy(stream, 12, temp32, 0, sizeof(UInt32));
                    this.header.Add("Size", BitConverter.ToUInt32(temp32, 0));
                }
            }else{//FRAME DATA
                UInt32 st = BitConverter.ToUInt32(temp, 0);
                this.header.Add("StreamID", st&0x7fffffff);
                Buffer.BlockCopy(stream, 4, temp, 0, sizeof(UInt32));
                this.header.Add("Length", BitConverter.ToUInt32(temp, 0)&0x00ffffff);
                this.header.Add("Flag", (BitConverter.ToUInt32(temp, 0)&0xff000000)>>24);
                byte [] dataTemp = new byte[this.header["Length"]];
                Buffer.BlockCopy(stream, 8, dataTemp, 0, dataTemp.Length);
                this.data = dataTemp;
            }
        }