private static ByteBuffer EncodeSharedObject(RtmpContext context, ISharedObjectMessage so) { ByteBuffer output = ByteBuffer.Allocate(0x80); output.AutoExpand = true; EncodeSharedObject(context, so, output); return(output); }
static ByteBuffer EncodeFlexSharedObject(RtmpContext context, ISharedObjectMessage so) { ByteBuffer output = ByteBuffer.Allocate(128); output.AutoExpand = true; output.Put((byte)0); EncodeSharedObject(context, so, output); return(output); }
public override void DispatchEvent(IEvent evt) { if (evt.EventType != EventType.SHARED_OBJECT || !(evt is ISharedObjectMessage)) { // Don't know how to handle this event. base.DispatchEvent(evt); return; } ISharedObjectMessage msg = (ISharedObjectMessage)evt; if (msg.HasSource) { BeginUpdate(msg.Source); } else { BeginUpdate(); } try { foreach (ISharedObjectEvent sharedObjectEvent in msg.Events) { switch (sharedObjectEvent.Type) { case SharedObjectEventType.SERVER_CONNECT: if (!IsConnectionAllowed()) { _so.ReturnError(StatusASO.SO_NO_READ_ACCESS); } else if (msg.HasSource) { IEventListener source = msg.Source; if (source is RtmpConnection) { (source as RtmpConnection).RegisterBasicScope(this); } else { AddEventListener(source); } } break; case SharedObjectEventType.SERVER_DISCONNECT: if (msg.HasSource) { IEventListener source = msg.Source; if (source is RtmpConnection) { (source as RtmpConnection).UnregisterBasicScope(this); } else { RemoveEventListener(source); } } break; case SharedObjectEventType.SERVER_SET_ATTRIBUTE: if (!IsWriteAllowed(sharedObjectEvent.Key, sharedObjectEvent.Value)) { _so.ReturnAttributeValue(sharedObjectEvent.Key); _so.ReturnError(StatusASO.SO_NO_WRITE_ACCESS); } else { SetAttribute(sharedObjectEvent.Key, sharedObjectEvent.Value); } break; case SharedObjectEventType.SERVER_DELETE_ATTRIBUTE: if (!IsDeleteAllowed(sharedObjectEvent.Key)) { _so.ReturnAttributeValue(sharedObjectEvent.Key); _so.ReturnError(StatusASO.SO_NO_WRITE_ACCESS); } else { RemoveAttribute(sharedObjectEvent.Key); } break; case SharedObjectEventType.SERVER_SEND_MESSAGE: // Ignore request silently if not allowed if (IsSendAllowed(sharedObjectEvent.Key, sharedObjectEvent.Value as IList)) { SendMessage(sharedObjectEvent.Key, sharedObjectEvent.Value as IList); } break; default: log.Warn("Unknown SO event: " + sharedObjectEvent.Type.ToString()); break; } } } finally { EndUpdate(); } }
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; } } }
static ByteBuffer EncodeSharedObject(RtmpContext context, ISharedObjectMessage so) { ByteBuffer output = ByteBuffer.Allocate(128); output.AutoExpand = true; EncodeSharedObject(context, so, output); return output; }
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); } }
public override void DispatchEvent(IEvent evt) { if (!((evt.EventType == EventType.SHARED_OBJECT) && (evt is ISharedObjectMessage))) { base.DispatchEvent(evt); } else { ISharedObjectMessage message = (ISharedObjectMessage)evt; if (message.HasSource) { this.BeginUpdate(message.Source); } else { this.BeginUpdate(); } try { foreach (ISharedObjectEvent event2 in message.Events) { IEventListener source; switch (event2.Type) { case SharedObjectEventType.SERVER_CONNECT: { if (this.IsConnectionAllowed()) { break; } this._so.ReturnError("SharedObject.NoReadAccess"); continue; } case SharedObjectEventType.SERVER_DISCONNECT: { if (message.HasSource) { source = message.Source; if (!(source is RtmpConnection)) { goto Label_012E; } (source as RtmpConnection).UnregisterBasicScope(this); } continue; } case SharedObjectEventType.SERVER_SET_ATTRIBUTE: { if (this.IsWriteAllowed(event2.Key, event2.Value)) { goto Label_0179; } this._so.ReturnAttributeValue(event2.Key); this._so.ReturnError("SharedObject.NoWriteAccess"); continue; } case SharedObjectEventType.SERVER_DELETE_ATTRIBUTE: { if (this.IsDeleteAllowed(event2.Key)) { goto Label_01C8; } this._so.ReturnAttributeValue(event2.Key); this._so.ReturnError("SharedObject.NoWriteAccess"); continue; } case SharedObjectEventType.SERVER_SEND_MESSAGE: { if (this.IsSendAllowed(event2.Key, event2.Value as IList)) { this.SendMessage(event2.Key, event2.Value as IList); } continue; } default: goto Label_020F; } if (message.HasSource) { source = message.Source; if (source is RtmpConnection) { (source as RtmpConnection).RegisterBasicScope(this); } else { this.AddEventListener(source); } } continue; Label_012E: this.RemoveEventListener(source); continue; Label_0179: this.SetAttribute(event2.Key, event2.Value); continue; Label_01C8: this.RemoveAttribute(event2.Key); continue; Label_020F: log.Warn("Unknown SO event: " + event2.Type.ToString()); } } finally { this.EndUpdate(); } } }
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; } } }