コード例 #1
0
        private static ByteBuffer EncodeFlexInvoke(RtmpContext context, FlexInvoke invoke)
        {
            ByteBuffer stream = ByteBuffer.Allocate(0x400);

            stream.AutoExpand = true;
            RtmpWriter writer = new RtmpWriter(stream);

            writer.WriteByte(0);
            writer.WriteData(context.ObjectEncoding, invoke.Cmd);
            writer.WriteData(context.ObjectEncoding, invoke.InvokeId);
            writer.WriteData(context.ObjectEncoding, invoke.CmdData);
            object response = invoke.Response;

            writer.WriteData(context.ObjectEncoding, response);
            return(stream);
        }
コード例 #2
0
        static ByteBuffer EncodeNotifyOrInvoke(RtmpContext context, Notify invoke)
        {
            //MemoryStreamEx output = new MemoryStreamEx();
            ByteBuffer output = ByteBuffer.Allocate(1024);

            output.AutoExpand = true;
            RtmpWriter writer = new RtmpWriter(output);

            //Set legacy collection flag from context
            writer.UseLegacyCollection = context.UseLegacyCollection;
            writer.UseLegacyThrowable  = context.UseLegacyThrowable;

            IServiceCall serviceCall = invoke.ServiceCall;
            bool         isPending   = serviceCall.Status == Call.STATUS_PENDING;

            if (!isPending)
            {
                //log.debug("Call has been executed, send result");
                writer.WriteData(context.ObjectEncoding, serviceCall.IsSuccess ? "_result" : "_error");
            }
            else
            {
                //log.debug("This is a pending call, send request");
                string action = (serviceCall.ServiceName == null) ? serviceCall.ServiceMethodName : serviceCall.ServiceName + "." + serviceCall.ServiceMethodName;
                writer.WriteData(context.ObjectEncoding, action);
            }
            if (invoke is Invoke)
            {
                writer.WriteData(context.ObjectEncoding, invoke.InvokeId);
                writer.WriteData(context.ObjectEncoding, invoke.ConnectionParameters);
            }
            if (!isPending && (invoke is Invoke))
            {
                IPendingServiceCall pendingCall = (IPendingServiceCall)serviceCall;
                if (!serviceCall.IsSuccess && !(pendingCall.Result is StatusASO))
                {
                    StatusASO status = GenerateErrorResult(StatusASO.NC_CALL_FAILED, serviceCall.Exception);
                    pendingCall.Result = status;
                }
                writer.WriteData(context.ObjectEncoding, pendingCall.Result);
            }
            else
            {
                //log.debug("Writing params");
                object[] args = invoke.ServiceCall.Arguments;
                if (args != null)
                {
                    foreach (object element in args)
                    {
                        writer.WriteData(context.ObjectEncoding, element);
                    }
                }
            }
            return(output);
        }
コード例 #3
0
        private static ByteBuffer EncodeNotifyOrInvoke(RtmpContext context, Notify invoke)
        {
            ByteBuffer stream = ByteBuffer.Allocate(0x400);

            stream.AutoExpand = true;
            RtmpWriter   writer      = new RtmpWriter(stream);
            IServiceCall serviceCall = invoke.ServiceCall;
            bool         flag        = serviceCall.Status == 1;

            if (!flag)
            {
                writer.WriteData(context.ObjectEncoding, "_result");
            }
            else
            {
                string data = (serviceCall.ServiceName == null) ? serviceCall.ServiceMethodName : (serviceCall.ServiceName + "." + serviceCall.ServiceMethodName);
                writer.WriteData(context.ObjectEncoding, data);
            }
            if (invoke is Invoke)
            {
                writer.WriteData(context.ObjectEncoding, invoke.InvokeId);
                writer.WriteData(context.ObjectEncoding, invoke.ConnectionParameters);
            }
            if (!flag && (invoke is Invoke))
            {
                IPendingServiceCall call2 = (IPendingServiceCall)serviceCall;
                if (!serviceCall.IsSuccess)
                {
                    StatusASO saso = GenerateErrorResult("NetConnection.Call.Failed", serviceCall.Exception);
                    call2.Result = saso;
                }
                writer.WriteData(context.ObjectEncoding, call2.Result);
                return(stream);
            }
            object[] arguments = invoke.ServiceCall.Arguments;
            if (arguments != null)
            {
                foreach (object obj2 in arguments)
                {
                    writer.WriteData(context.ObjectEncoding, obj2);
                }
            }
            return(stream);
        }
コード例 #4
0
		static void EncodeSharedObject(RtmpContext context, ISharedObjectMessage so, ByteBuffer output)
		{
			RtmpWriter writer = new RtmpWriter(output);
            //Set legacy collection flag from context
            writer.UseLegacyCollection = context.UseLegacyCollection;
            writer.UseLegacyThrowable = context.UseLegacyThrowable;

			writer.WriteUTF(so.Name);
			// SO version
			writer.WriteInt32(so.Version);
			// Encoding (this always seems to be 2 for persistent shared objects)
			writer.WriteInt32(so.IsPersistent ? 2 : 0);
			// unknown field
			writer.WriteInt32(0);
			
			int mark, len = 0;

			foreach(ISharedObjectEvent sharedObjectEvent in so.Events)
			{
				byte type = SharedObjectTypeMapping.ToByte(sharedObjectEvent.Type);
				switch(sharedObjectEvent.Type) 
				{
                    case SharedObjectEventType.SERVER_CONNECT:
                    case SharedObjectEventType.CLIENT_INITIAL_DATA:
					case SharedObjectEventType.CLIENT_CLEAR_DATA:
						writer.WriteByte(type);
						writer.WriteInt32(0);
						break;
                    case SharedObjectEventType.SERVER_DELETE_ATTRIBUTE:
                    case SharedObjectEventType.CLIENT_DELETE_DATA:
					case SharedObjectEventType.CLIENT_UPDATE_ATTRIBUTE:
						writer.WriteByte(type);
						mark = (int)output.Position;
						output.Skip(4); // we will be back
						writer.WriteUTF(sharedObjectEvent.Key);
						len = (int)output.Position - mark - 4;
						output.PutInt(mark, len);
						break;
					case SharedObjectEventType.SERVER_SET_ATTRIBUTE:
					case SharedObjectEventType.CLIENT_UPDATE_DATA:
						if (sharedObjectEvent.Key == null) 
						{
							// Update multiple attributes in one request
							IDictionary initialData = sharedObjectEvent.Value as IDictionary;
							foreach(DictionaryEntry entry in initialData)
							{
								writer.WriteByte(type);
								mark = (int)output.Position;
								output.Skip(4); // we will be back
								string key = entry.Key as string;
								object value = entry.Value;
								writer.WriteUTF(key);
								writer.WriteData(context.ObjectEncoding, value);
								
								len = (int)output.Position - mark - 4;
								output.PutInt(mark, len);
							}
						} 
						else 
						{
							writer.WriteByte(type);
							mark = (int)output.Position;
							output.Skip(4); // we will be back
							writer.WriteUTF(sharedObjectEvent.Key);
							writer.WriteData(context.ObjectEncoding, sharedObjectEvent.Value);
							//writer.WriteData(sharedObjectEvent.Value);

							len = (int)output.Position - mark - 4;
							output.PutInt(mark, len);
						}
						break;
					case SharedObjectEventType.CLIENT_SEND_MESSAGE:
					case SharedObjectEventType.SERVER_SEND_MESSAGE:
						// Send method name and value
						writer.WriteByte(type);
						mark = (int)output.Position;
						output.Skip(4); // we will be back

						// Serialize name of the handler to call
						writer.WriteData(context.ObjectEncoding, sharedObjectEvent.Key);
						//writer.WriteUTF(sharedObjectEvent.Key);
						// Serialize the arguments
						foreach(object arg in sharedObjectEvent.Value as IList)
						{
							writer.WriteData(context.ObjectEncoding, arg);
						}
						//writer.WriteData(sharedObjectEvent.Value as IList);
						len = (int)output.Position - mark - 4;
						//output.PutInt(mark, len);
						output.PutInt(mark, len);
						break;
					case SharedObjectEventType.CLIENT_STATUS:
						writer.WriteByte(type);
						mark = (int)output.Position;
						output.Skip(4); // we will be back
						writer.WriteUTF(sharedObjectEvent.Key);
						writer.WriteUTF(sharedObjectEvent.Value as string);
						len = (int)output.Position - mark - 4;
						output.PutInt(mark, len);
						break;
                    case SharedObjectEventType.SERVER_DISCONNECT:
                        writer.WriteByte(type);
                        output.PutInt((int)output.Position, 0);
                        break;
					default:
#if !SILVERLIGHT
                        _log.Error("Unknown event " + sharedObjectEvent.Type.ToString());
#endif
						writer.WriteByte(type);
						mark = (int)output.Position;
						output.Skip(4); // we will be back
                        if (sharedObjectEvent.Key != null)
                        {
                            writer.WriteUTF(sharedObjectEvent.Key);
                            writer.WriteData(context.ObjectEncoding, sharedObjectEvent.Value);
                        }
						len = (int)output.Position - mark - 4;
						output.PutInt(mark, len);
						break;
				}
			}
		}
コード例 #5
0
		static ByteBuffer EncodeFlexInvoke(RtmpContext context, FlexInvoke invoke)
		{
			ByteBuffer output = ByteBuffer.Allocate(1024);
			output.AutoExpand = true;
			RtmpWriter writer = new RtmpWriter(output);
            //Set legacy collection flag from context
            writer.UseLegacyCollection = context.UseLegacyCollection;
            writer.UseLegacyThrowable = context.UseLegacyThrowable;
			
			writer.WriteByte(0);
			//writer.WriteData(context.ObjectEncoding, invoke.Cmd);
            IServiceCall serviceCall = invoke.ServiceCall;
            bool isPending = serviceCall.Status == Call.STATUS_PENDING;
            if (!isPending)
            {
                //log.debug("Call has been executed, send result");
                if (serviceCall.IsSuccess)
                    writer.WriteData(context.ObjectEncoding, "_result");
                else
                    writer.WriteData(context.ObjectEncoding, "_error");
            }
            else
            {
                //log.debug("This is a pending call, send request");
                writer.WriteData(context.ObjectEncoding, serviceCall.ServiceMethodName);
            }
			writer.WriteData(context.ObjectEncoding, invoke.InvokeId);
			writer.WriteData(context.ObjectEncoding, invoke.CmdData);
			//object response = invoke.Response;
			//writer.WriteData(context.ObjectEncoding, response);
            if (!isPending)
            {
                IPendingServiceCall pendingCall = (IPendingServiceCall)serviceCall;
                /*
                if (!serviceCall.IsSuccess)
                {
                    StatusASO status = GenerateErrorResult(StatusASO.NC_CALL_FAILED, serviceCall.Exception);
                    pendingCall.Result = status;
                }
                */
                writer.WriteData(context.ObjectEncoding, pendingCall.Result);
            }
            else
            {
                //log.debug("Writing params");
                object[] args = invoke.ServiceCall.Arguments;
                if (args != null)
                {
                    foreach (object element in args)
                    {
                        writer.WriteData(context.ObjectEncoding, element);
                    }
                }
            }
			return output;
		}
コード例 #6
0
		static ByteBuffer EncodeNotifyOrInvoke(RtmpContext context, Notify invoke)
		{
			//MemoryStreamEx output = new MemoryStreamEx();
			ByteBuffer output = ByteBuffer.Allocate(1024);
			output.AutoExpand = true;
			RtmpWriter writer = new RtmpWriter(output);
            //Set legacy collection flag from context
            writer.UseLegacyCollection = context.UseLegacyCollection;
            writer.UseLegacyThrowable = context.UseLegacyThrowable;

			IServiceCall serviceCall = invoke.ServiceCall;
			bool isPending = serviceCall.Status == Call.STATUS_PENDING;
			if (!isPending) 
			{
				//log.debug("Call has been executed, send result");
                writer.WriteData(context.ObjectEncoding, serviceCall.IsSuccess ? "_result" : "_error");
			}
			else
			{
				//log.debug("This is a pending call, send request");
				string action = (serviceCall.ServiceName == null) ? serviceCall.ServiceMethodName : serviceCall.ServiceName + "." + serviceCall.ServiceMethodName;
				writer.WriteData(context.ObjectEncoding, action);
			}
			if(invoke is Invoke)
			{
				writer.WriteData(context.ObjectEncoding, invoke.InvokeId);
				writer.WriteData(context.ObjectEncoding, invoke.ConnectionParameters);
			}
			if(!isPending && (invoke is Invoke)) 
			{
				IPendingServiceCall pendingCall = (IPendingServiceCall)serviceCall;
                if (!serviceCall.IsSuccess && !(pendingCall.Result is StatusASO))
                {
                    StatusASO status = GenerateErrorResult(StatusASO.NC_CALL_FAILED, serviceCall.Exception);
                    pendingCall.Result = status;
                }
				writer.WriteData(context.ObjectEncoding, pendingCall.Result);
			}
			else
			{
				//log.debug("Writing params");
				object[] args = invoke.ServiceCall.Arguments;
				if (args != null) 
				{
					foreach(object element in args)
					{
						writer.WriteData(context.ObjectEncoding, element);
					}
				}
			}
			return output;
		}
コード例 #7
0
        private static void EncodeSharedObject(RtmpContext context, ISharedObjectMessage so, ByteBuffer output)
        {
            RtmpWriter writer = new RtmpWriter(output);

            writer.WriteUTF(so.Name);
            writer.WriteInt32(so.Version);
            writer.WriteInt32(so.IsPersistent ? 2 : 0);
            writer.WriteInt32(0);
            int num2 = 0;

            foreach (ISharedObjectEvent event2 in so.Events)
            {
                int  position;
                byte num3 = SharedObjectTypeMapping.ToByte(event2.Type);
                switch (event2.Type)
                {
                case SharedObjectEventType.SERVER_CONNECT:
                case SharedObjectEventType.CLIENT_CLEAR_DATA:
                case SharedObjectEventType.CLIENT_INITIAL_DATA:
                {
                    writer.WriteByte(num3);
                    writer.WriteInt32(0);
                    continue;
                }

                case SharedObjectEventType.SERVER_DISCONNECT:
                {
                    writer.WriteByte(num3);
                    output.PutInt((int)output.Position, 0);
                    continue;
                }

                case SharedObjectEventType.SERVER_SET_ATTRIBUTE:
                case SharedObjectEventType.CLIENT_UPDATE_DATA:
                {
                    if (event2.Key != null)
                    {
                        break;
                    }
                    IDictionary dictionary = event2.Value as IDictionary;
                    foreach (DictionaryEntry entry in dictionary)
                    {
                        writer.WriteByte(num3);
                        position = (int)output.Position;
                        output.Skip(4);
                        string key  = entry.Key as string;
                        object data = entry.Value;
                        writer.WriteUTF(key);
                        writer.WriteData(context.ObjectEncoding, data);
                        num2 = (((int)output.Position) - position) - 4;
                        output.PutInt(position, num2);
                    }
                    continue;
                }

                case SharedObjectEventType.SERVER_DELETE_ATTRIBUTE:
                case SharedObjectEventType.CLIENT_DELETE_DATA:
                case SharedObjectEventType.CLIENT_UPDATE_ATTRIBUTE:
                {
                    writer.WriteByte(num3);
                    position = (int)output.Position;
                    output.Skip(4);
                    writer.WriteUTF(event2.Key);
                    num2 = (((int)output.Position) - position) - 4;
                    output.PutInt(position, num2);
                    continue;
                }

                case SharedObjectEventType.SERVER_SEND_MESSAGE:
                case SharedObjectEventType.CLIENT_SEND_MESSAGE:
                {
                    writer.WriteByte(num3);
                    position = (int)output.Position;
                    output.Skip(4);
                    writer.WriteData(context.ObjectEncoding, event2.Key);
                    foreach (object obj3 in event2.Value as IList)
                    {
                        writer.WriteData(context.ObjectEncoding, obj3);
                    }
                    num2 = (((int)output.Position) - position) - 4;
                    output.PutInt(position, num2);
                    continue;
                }

                case SharedObjectEventType.CLIENT_STATUS:
                {
                    writer.WriteByte(num3);
                    position = (int)output.Position;
                    output.Skip(4);
                    writer.WriteUTF(event2.Key);
                    writer.WriteUTF(event2.Value as string);
                    num2 = (((int)output.Position) - position) - 4;
                    output.PutInt(position, num2);
                    continue;
                }

                default:
                    goto Label_033A;
                }
                writer.WriteByte(num3);
                position = (int)output.Position;
                output.Skip(4);
                writer.WriteUTF(event2.Key);
                writer.WriteData(context.ObjectEncoding, event2.Value);
                num2 = (((int)output.Position) - position) - 4;
                output.PutInt(position, num2);
                continue;
Label_033A:
                _log.Error("Unknown event " + event2.Type.ToString());
                writer.WriteByte(num3);
                position = (int)output.Position;
                output.Skip(4);
                if (event2.Key != null)
                {
                    writer.WriteUTF(event2.Key);
                    writer.WriteData(context.ObjectEncoding, event2.Value);
                }
                num2 = (((int)output.Position) - position) - 4;
                output.PutInt(position, num2);
            }
        }
コード例 #8
0
        static void EncodeSharedObject(RtmpContext context, ISharedObjectMessage so, ByteBuffer output)
        {
            RtmpWriter writer = new RtmpWriter(output);

            //Set legacy collection flag from context
            writer.UseLegacyCollection = context.UseLegacyCollection;
            writer.UseLegacyThrowable  = context.UseLegacyThrowable;

            writer.WriteUTF(so.Name);
            // SO version
            writer.WriteInt32(so.Version);
            // Encoding (this always seems to be 2 for persistent shared objects)
            writer.WriteInt32(so.IsPersistent ? 2 : 0);
            // unknown field
            writer.WriteInt32(0);

            int mark, len = 0;

            foreach (ISharedObjectEvent sharedObjectEvent in so.Events)
            {
                byte type = SharedObjectTypeMapping.ToByte(sharedObjectEvent.Type);
                switch (sharedObjectEvent.Type)
                {
                case SharedObjectEventType.SERVER_CONNECT:
                case SharedObjectEventType.CLIENT_INITIAL_DATA:
                case SharedObjectEventType.CLIENT_CLEAR_DATA:
                    writer.WriteByte(type);
                    writer.WriteInt32(0);
                    break;

                case SharedObjectEventType.SERVER_DELETE_ATTRIBUTE:
                case SharedObjectEventType.CLIENT_DELETE_DATA:
                case SharedObjectEventType.CLIENT_UPDATE_ATTRIBUTE:
                    writer.WriteByte(type);
                    mark = (int)output.Position;
                    output.Skip(4);                             // we will be back
                    writer.WriteUTF(sharedObjectEvent.Key);
                    len = (int)output.Position - mark - 4;
                    output.PutInt(mark, len);
                    break;

                case SharedObjectEventType.SERVER_SET_ATTRIBUTE:
                case SharedObjectEventType.CLIENT_UPDATE_DATA:
                    if (sharedObjectEvent.Key == null)
                    {
                        // Update multiple attributes in one request
                        IDictionary initialData = sharedObjectEvent.Value as IDictionary;
                        foreach (DictionaryEntry entry in initialData)
                        {
                            writer.WriteByte(type);
                            mark = (int)output.Position;
                            output.Skip(4);                                     // we will be back
                            string key   = entry.Key as string;
                            object value = entry.Value;
                            writer.WriteUTF(key);
                            writer.WriteData(context.ObjectEncoding, value);

                            len = (int)output.Position - mark - 4;
                            output.PutInt(mark, len);
                        }
                    }
                    else
                    {
                        writer.WriteByte(type);
                        mark = (int)output.Position;
                        output.Skip(4);                                 // we will be back
                        writer.WriteUTF(sharedObjectEvent.Key);
                        writer.WriteData(context.ObjectEncoding, sharedObjectEvent.Value);
                        //writer.WriteData(sharedObjectEvent.Value);

                        len = (int)output.Position - mark - 4;
                        output.PutInt(mark, len);
                    }
                    break;

                case SharedObjectEventType.CLIENT_SEND_MESSAGE:
                case SharedObjectEventType.SERVER_SEND_MESSAGE:
                    // Send method name and value
                    writer.WriteByte(type);
                    mark = (int)output.Position;
                    output.Skip(4);                             // we will be back

                    // Serialize name of the handler to call
                    writer.WriteData(context.ObjectEncoding, sharedObjectEvent.Key);
                    //writer.WriteUTF(sharedObjectEvent.Key);
                    // Serialize the arguments
                    foreach (object arg in sharedObjectEvent.Value as IList)
                    {
                        writer.WriteData(context.ObjectEncoding, arg);
                    }
                    //writer.WriteData(sharedObjectEvent.Value as IList);
                    len = (int)output.Position - mark - 4;
                    //output.PutInt(mark, len);
                    output.PutInt(mark, len);
                    break;

                case SharedObjectEventType.CLIENT_STATUS:
                    writer.WriteByte(type);
                    mark = (int)output.Position;
                    output.Skip(4);                             // we will be back
                    writer.WriteUTF(sharedObjectEvent.Key);
                    writer.WriteUTF(sharedObjectEvent.Value as string);
                    len = (int)output.Position - mark - 4;
                    output.PutInt(mark, len);
                    break;

                case SharedObjectEventType.SERVER_DISCONNECT:
                    writer.WriteByte(type);
                    output.PutInt((int)output.Position, 0);
                    break;

                default:
#if !SILVERLIGHT
                    _log.Error("Unknown event " + sharedObjectEvent.Type.ToString());
#endif
                    writer.WriteByte(type);
                    mark = (int)output.Position;
                    output.Skip(4);                             // we will be back
                    if (sharedObjectEvent.Key != null)
                    {
                        writer.WriteUTF(sharedObjectEvent.Key);
                        writer.WriteData(context.ObjectEncoding, sharedObjectEvent.Value);
                    }
                    len = (int)output.Position - mark - 4;
                    output.PutInt(mark, len);
                    break;
                }
            }
        }
コード例 #9
0
        static ByteBuffer EncodeFlexInvoke(RtmpContext context, FlexInvoke invoke)
        {
            ByteBuffer output = ByteBuffer.Allocate(1024);

            output.AutoExpand = true;
            RtmpWriter writer = new RtmpWriter(output);

            //Set legacy collection flag from context
            writer.UseLegacyCollection = context.UseLegacyCollection;
            writer.UseLegacyThrowable  = context.UseLegacyThrowable;

            writer.WriteByte(0);
            //writer.WriteData(context.ObjectEncoding, invoke.Cmd);
            IServiceCall serviceCall = invoke.ServiceCall;
            bool         isPending   = serviceCall.Status == Call.STATUS_PENDING;

            if (!isPending)
            {
                //log.debug("Call has been executed, send result");
                if (serviceCall.IsSuccess)
                {
                    writer.WriteData(context.ObjectEncoding, "_result");
                }
                else
                {
                    writer.WriteData(context.ObjectEncoding, "_error");
                }
            }
            else
            {
                //log.debug("This is a pending call, send request");
                writer.WriteData(context.ObjectEncoding, serviceCall.ServiceMethodName);
            }
            writer.WriteData(context.ObjectEncoding, invoke.InvokeId);
            writer.WriteData(context.ObjectEncoding, invoke.CmdData);
            //object response = invoke.Response;
            //writer.WriteData(context.ObjectEncoding, response);
            if (!isPending)
            {
                IPendingServiceCall pendingCall = (IPendingServiceCall)serviceCall;

                /*
                 * if (!serviceCall.IsSuccess)
                 * {
                 *  StatusASO status = GenerateErrorResult(StatusASO.NC_CALL_FAILED, serviceCall.Exception);
                 *  pendingCall.Result = status;
                 * }
                 */
                writer.WriteData(context.ObjectEncoding, pendingCall.Result);
            }
            else
            {
                //log.debug("Writing params");
                object[] args = invoke.ServiceCall.Arguments;
                if (args != null)
                {
                    foreach (object element in args)
                    {
                        writer.WriteData(context.ObjectEncoding, element);
                    }
                }
            }
            return(output);
        }