Exemple #1
0
        static Notify DecodeStreamMetadata(ByteBuffer stream)
        {
            RtmpReader reader        = new RtmpReader(stream);
            string     action        = reader.ReadData() as string;
            object     obj           = reader.ReadData();
            Notify     notify        = new Notify();
            int        dotIndex      = action.LastIndexOf(".");
            string     serviceName   = (dotIndex == -1) ? null : action.Substring(0, dotIndex);
            string     serviceMethod = (dotIndex == -1) ? action : action.Substring(dotIndex + 1, action.Length - dotIndex - 1);

            object[] parameters = new object[1] {
                obj
            };
            Call call = new Call(serviceName, serviceMethod, parameters);

            notify.ServiceCall = call;
            return(notify);
        }
Exemple #2
0
        static ISharedObjectMessage DecodeSharedObject(ByteBuffer stream)
        {
            RtmpReader reader = new RtmpReader(stream);
            string     name   = reader.ReadString();
            // Read version of SO to modify
            int version = reader.ReadInt32();
            // Read persistence informations
            bool persistent = reader.ReadInt32() == 2;

            // Skip unknown bytes
            //skip(4);
            reader.ReadInt32();

            SharedObjectMessage so = new SharedObjectMessage(null, name, version, persistent);

            DecodeSharedObject(so, stream, reader);
            return(so);
        }
Exemple #3
0
        static void DecodeSharedObject(SharedObjectMessage so, ByteBuffer stream, RtmpReader reader)
        {
            // Parse request body
            while (stream.HasRemaining)
            {
                byte typeCode = reader.ReadByte();
                SharedObjectEventType type = SharedObjectTypeMapping.ToType(typeCode);
                string key   = null;
                object value = null;

                int length = stream.GetInt();                //reader.ReadInt32();
                switch (type)
                {
                case SharedObjectEventType.CLIENT_STATUS:
                    // Status code
                    key = reader.ReadString();
                    // Status level
                    value = reader.ReadString();
                    break;

                case SharedObjectEventType.CLIENT_UPDATE_DATA: {
                    key   = reader.ReadString();
                    value = reader.ReadData();

                    /*
                     * key = null;
                     * // Map containing new attribute values
                     * Hashtable map = new Hashtable();
                     * int start = (int)stream.Position;
                     * while((int)stream.Position - start < length)
                     * {
                     *      string tmp = reader.ReadString();
                     *      map[tmp] = reader.ReadData();
                     * }
                     * value = map;
                     */
                }
                break;

                default:
                    if (type != SharedObjectEventType.SERVER_SEND_MESSAGE && type != SharedObjectEventType.CLIENT_SEND_MESSAGE)
                    {
                        if (length > 0)
                        {
                            key = reader.ReadString();
                            if (length > key.Length + 2)
                            {
                                value = reader.ReadData();
                            }
                        }
                    }
                    else
                    {
                        int start = (int)stream.Position;
                        // the "send" event seems to encode the handler name
                        // as complete AMF string including the string type byte
                        key = reader.ReadData() as string;
                        // read parameters
#if !(NET_1_1)
                        List <object> paramList = new List <object>();
#else
                        ArrayList paramList = new ArrayList();
#endif
                        while (stream.Position - start < length)
                        {
                            object tmp = reader.ReadData();
                            paramList.Add(tmp);
                        }
                        value = paramList;
                    }
                    break;
                }
                so.AddEvent(type, key, value);
            }
        }
Exemple #4
0
        static Notify DecodeNotifyOrInvoke(Notify notify, ByteBuffer stream, RtmpHeader header)
        {
            long       start  = stream.Position;
            RtmpReader reader = new RtmpReader(stream);
            string     action = reader.ReadData() as string;

            if (!(notify is Invoke))
            {
                //Don't decode "NetStream.send" requests
                stream.Position = start;
                notify.Data     = ByteBuffer.Allocate(stream.Remaining);
                notify.Data.Put(stream);
                //notify.setData(in.asReadOnlyBuffer());
                return(notify);
            }

            if (header == null || header.StreamId == 0)
            {
                double invokeId = (double)reader.ReadData();
                notify.InvokeId = (int)invokeId;
            }

            object[] parameters = Call.EmptyArguments;
            if (stream.HasRemaining)
            {
#if !(NET_1_1)
                List <object> paramList = new List <object>();
#else
                ArrayList paramList = new ArrayList();
#endif
                object obj = reader.ReadData();

                if (obj is IDictionary)
                {
                    // for connect we get a map
                    notify.ConnectionParameters = obj as IDictionary;
                }
                else if (obj != null)
                {
                    paramList.Add(obj);
                }

                while (stream.HasRemaining)
                {
                    paramList.Add(reader.ReadData());
                }
                parameters = paramList.ToArray();
            }

            int    dotIndex      = action.LastIndexOf(".");
            string serviceName   = (dotIndex == -1) ? null : action.Substring(0, dotIndex);
            string serviceMethod = (dotIndex == -1) ? action : action.Substring(dotIndex + 1, action.Length - dotIndex - 1);

            if (notify is Invoke)
            {
                PendingCall call = new PendingCall(serviceName, serviceMethod, parameters);
                notify.ServiceCall = call;
            }
            else
            {
                Call call = new Call(serviceName, serviceMethod, parameters);
                notify.ServiceCall = call;
            }
            return(notify);
        }
		static ISharedObjectMessage DecodeFlexSharedObject(ByteBuffer stream) {
			// Unknown byte, always 0?
			stream.Skip(1);
			RtmpReader reader = new RtmpReader(stream);
			string name = reader.ReadString();
			// Read version of SO to modify
			int version = reader.ReadInt32();
			// Read persistence informations
			bool persistent = reader.ReadInt32() == 2;
			// Skip unknown bytes
			reader.ReadInt32();

			SharedObjectMessage so = new FlexSharedObjectMessage(null, name, version, persistent);
			DecodeSharedObject(so, stream, reader);
			return so;
		}
		static void DecodeSharedObject(SharedObjectMessage so, ByteBuffer stream, RtmpReader reader) {
			// Parse request body
			while (stream.HasRemaining) {
				byte typeCode = reader.ReadByte();
				SharedObjectEventType type = SharedObjectTypeMapping.ToType(typeCode);
				string key = null;
				object value = null;

				int length = stream.GetInt();//reader.ReadInt32();
				switch (type) {
					case SharedObjectEventType.CLIENT_STATUS:
						// Status code
						key = reader.ReadString();
						// Status level
						value = reader.ReadString();
						break;
					case SharedObjectEventType.CLIENT_UPDATE_DATA: {
							key = reader.ReadString();
							value = reader.ReadData();
							/*
							key = null;
							// Map containing new attribute values
							Hashtable map = new Hashtable();
							int start = (int)stream.Position;
							while((int)stream.Position - start < length) 
							{
								string tmp = reader.ReadString();
								map[tmp] = reader.ReadData();
							}
							value = map;
							*/
						}
						break;
					default:
						if (type != SharedObjectEventType.SERVER_SEND_MESSAGE && type != SharedObjectEventType.CLIENT_SEND_MESSAGE) {
							if (length > 0) {
								key = reader.ReadString();
								if (length > key.Length + 2) {
									value = reader.ReadData();
								}
							}
						} else {
							int start = (int)stream.Position;
							// the "send" event seems to encode the handler name
							// as complete AMF string including the string type byte
							key = reader.ReadData() as string;
							// read parameters
#if !(NET_1_1)
							List<object> paramList = new List<object>();
#else
							ArrayList paramList = new ArrayList();
#endif
							while (stream.Position - start < length) {
								object tmp = reader.ReadData();
								paramList.Add(tmp);
							}
							value = paramList;
						}
						break;
				}
				so.AddEvent(type, key, value);
			}
		}
		static Notify DecodeNotifyOrInvoke(Notify notify, ByteBuffer stream, RtmpHeader header) {
			long start = stream.Position;
			RtmpReader reader = new RtmpReader(stream);
			string action = reader.ReadData() as string;

			if (!(notify is Invoke)) {
				//Don't decode "NetStream.send" requests
				stream.Position = start;
				notify.Data = ByteBuffer.Allocate(stream.Remaining);
				notify.Data.Put(stream);
				//notify.setData(in.asReadOnlyBuffer());
				return notify;
			}

			if (header == null || header.StreamId == 0) {
				double invokeId = (double)reader.ReadData();
				notify.InvokeId = (int)invokeId;
			}

			object[] parameters = Call.EmptyArguments;
			if (stream.HasRemaining) {
#if !(NET_1_1)
				List<object> paramList = new List<object>();
#else
                ArrayList paramList = new ArrayList();
#endif
				object obj = reader.ReadData();

				if (obj is IDictionary) {
					// for connect we get a map
					notify.ConnectionParameters = obj as IDictionary;
				} else if (obj != null) {
					paramList.Add(obj);
				}

				while (stream.HasRemaining) {
					paramList.Add(reader.ReadData());
				}
				parameters = paramList.ToArray();
			}

			int dotIndex = action.LastIndexOf(".");
			string serviceName = (dotIndex == -1) ? null : action.Substring(0, dotIndex);
			string serviceMethod = (dotIndex == -1) ? action : action.Substring(dotIndex + 1, action.Length - dotIndex - 1);

			if (notify is Invoke) {
				PendingCall call = new PendingCall(serviceName, serviceMethod, parameters);
				notify.ServiceCall = call;
			} else {
				Call call = new Call(serviceName, serviceMethod, parameters);
				notify.ServiceCall = call;
			}
			return notify;
		}
		static Notify DecodeStreamMetadata(ByteBuffer stream) {
			RtmpReader reader = new RtmpReader(stream);
			string action = reader.ReadData() as string;
			object obj = reader.ReadData();
			Notify notify = new Notify();
			int dotIndex = action.LastIndexOf(".");
			string serviceName = (dotIndex == -1) ? null : action.Substring(0, dotIndex);
			string serviceMethod = (dotIndex == -1) ? action : action.Substring(dotIndex + 1, action.Length - dotIndex - 1);
			object[] parameters = new object[1] { obj };
			Call call = new Call(serviceName, serviceMethod, parameters);
			notify.ServiceCall = call;
			return notify;
		}
		static FlexInvoke DecodeFlexInvoke(ByteBuffer stream) {
			int version = stream.ReadByte();
			RtmpReader reader = new RtmpReader(stream);
			string action = reader.ReadData() as string;
			int invokeId = System.Convert.ToInt32(reader.ReadData());
			object cmdData = reader.ReadData();

			object[] parameters = Call.EmptyArguments;
			if (stream.HasRemaining) {
#if !(NET_1_1)
				List<object> paramList = new List<object>();
#else
            ArrayList paramList = new ArrayList();
#endif
				while (stream.HasRemaining) {
					object obj = reader.ReadData();
					paramList.Add(obj);
				}
				parameters = paramList.ToArray();
			}
			/*
			int dotIndex = action == null ? -1 : action.LastIndexOf(".");
			string serviceName = (action == -1) ? null : action.Substring(0, dotIndex);
			string serviceMethod = (dotIndex == -1) ? action : action.Substring(dotIndex + 1, action.Length - dotIndex - 1);
			*/
			PendingCall call = new PendingCall(null, action, parameters);
			FlexInvoke invoke = new FlexInvoke(invokeId, cmdData);
			invoke.ServiceCall = call;
			return invoke;
		}