public RTMPAcknowledgement(RTMPConnection connection, uint bytesSoFar) : base(connection)
 {
     Header.Format        = RTMPMessageFormat.NoMessageId_8;
     Header.MessageTypeID = RTMPMessageTypeID.Acknowledgement;
     Header.ChunkStreamID = RTMPMessageChunkStreamID.LowLevelMessage;
     Body.MemoryWriter.Write(bytesSoFar);
 }
Example #2
0
 public RTMPSetChunkSize(RTMPConnection connection, uint chunkSize)
     : base(connection)
 {
     Header.MessageTypeID = RTMPMessageTypeID.SetChunkSize;
     ChunkSize = chunkSize;
     Body.MemoryWriter.Write(chunkSize);
 }
Example #3
0
 public RTMPSetChunkSize(RTMPConnection connection, uint chunkSize)
     : base(connection)
 {
     Header.MessageTypeID = RTMPMessageTypeID.SetChunkSize;
     ChunkSize            = chunkSize;
     Body.MemoryWriter.Write(chunkSize);
 }
 public RTMPUserControlMessage(RTMPConnection connection, UserControlMessage_EventType eventType)
     : base(connection)
 {
     EventType = eventType;
     Header.MessageTypeID = RTMPMessageTypeID.UserControlMessage;
     Body.MemoryWriter.Write((ushort)eventType);
 }
Example #5
0
        public RTMPMessageHeader(RTMPConnection connection, BinaryReader br)
        {
            Connection = connection;

            //format
            ReadFormatAndChunkStreamID(br);
            RTMPChunkStream csinfo = Connection.GetChunkStream((int)ChunkStreamID);

            //yay code repetition ftw!
            switch (Format)
            {
            case RTMPMessageFormat.BasicHeader_1:
                Timestamp       = csinfo.Timestamp;
                MessageLength   = csinfo.MessageLength;
                MessageTypeID   = csinfo.MessageTypeID;
                MessageStreamID = csinfo.MessageStreamID;
                break;

            case RTMPMessageFormat.BasicHeaderAndTime_4:
                ReadTimestamp(br);
                ReadExtendedTimestamp(br);

                csinfo.Timestamp = Timestamp;
                MessageLength    = csinfo.MessageLength;
                MessageTypeID    = csinfo.MessageTypeID;
                MessageStreamID  = csinfo.MessageStreamID;
                break;

            case RTMPMessageFormat.NoMessageId_8:
                ReadTimestamp(br);
                ReadMessageLength(br);
                ReadMessageTypeID(br);
                ReadExtendedTimestamp(br);

                csinfo.Timestamp     = Timestamp;
                csinfo.MessageLength = MessageLength;
                csinfo.MessageTypeID = MessageTypeID;
                MessageStreamID      = csinfo.MessageStreamID;
                break;

            case RTMPMessageFormat.FullHeader_12:
                ReadTimestamp(br);
                ReadMessageLength(br);
                ReadMessageTypeID(br);
                ReadMessageStreamID(br);
                ReadExtendedTimestamp(br);

                csinfo.Timestamp       = Timestamp;
                csinfo.MessageLength   = MessageLength;
                csinfo.MessageTypeID   = MessageTypeID;
                csinfo.MessageStreamID = MessageStreamID;
                break;
            }

            /*Timestamp = info.Timestamp;
             * MessageLengthFromHeader = info.MessageLength;
             * MessageTypeID = info.MessageTypeID;
             * MessageStreamID = info.MessageStreamID;*/
        }
Example #6
0
 public RTMPAcknowledgement(RTMPConnection connection, uint bytesSoFar)
     : base(connection)
 {
     Header.Format = RTMPMessageFormat.NoMessageId_8;
     Header.MessageTypeID = RTMPMessageTypeID.Acknowledgement;
     Header.ChunkStreamID = RTMPMessageChunkStreamID.LowLevelMessage;
     Body.MemoryWriter.Write(bytesSoFar);
 }
Example #7
0
        public RTMPMessageHeader(RTMPConnection connection, BinaryReader br)
        {
            Connection = connection;

            //format
            ReadFormatAndChunkStreamID(br);
            RTMPChunkStream csinfo = Connection.GetChunkStream((int)ChunkStreamID);
            //yay code repetition ftw!
            switch (Format)
            {
                case RTMPMessageFormat.BasicHeader_1:
                    Timestamp = csinfo.Timestamp;
                    MessageLength = csinfo.MessageLength;
                    MessageTypeID = csinfo.MessageTypeID;
                    MessageStreamID = csinfo.MessageStreamID;
                    break;
                case RTMPMessageFormat.BasicHeaderAndTime_4:
                    ReadTimestamp(br);
                    ReadExtendedTimestamp(br);

                    csinfo.Timestamp = Timestamp;
                    MessageLength = csinfo.MessageLength;
                    MessageTypeID = csinfo.MessageTypeID;
                    MessageStreamID = csinfo.MessageStreamID;
                    break;
                case RTMPMessageFormat.NoMessageId_8:
                    ReadTimestamp(br);
                    ReadMessageLength(br);
                    ReadMessageTypeID(br);
                    ReadExtendedTimestamp(br);

                    csinfo.Timestamp = Timestamp;
                    csinfo.MessageLength = MessageLength;
                    csinfo.MessageTypeID = MessageTypeID;
                    MessageStreamID = csinfo.MessageStreamID;
                    break;
                case RTMPMessageFormat.FullHeader_12:
                    ReadTimestamp(br);
                    ReadMessageLength(br);
                    ReadMessageTypeID(br);
                    ReadMessageStreamID(br);
                    ReadExtendedTimestamp(br);

                    csinfo.Timestamp = Timestamp;
                    csinfo.MessageLength = MessageLength;
                    csinfo.MessageTypeID = MessageTypeID;
                    csinfo.MessageStreamID = MessageStreamID;
                    break;
            }

            /*Timestamp = info.Timestamp;
            MessageLengthFromHeader = info.MessageLength;
            MessageTypeID = info.MessageTypeID;
            MessageStreamID = info.MessageStreamID;*/
        }
Example #8
0
        public RTMPAudioMessage(RTMPConnection connection, int chunkStream, byte format, byte[] data)
            : base(connection)
        {
            Header.Format        = RTMPMessageFormat.NoMessageId_8;
            Header.MessageTypeID = RTMPMessageTypeID.AudioPacket;
            Header.ChunkStreamID = (RTMPMessageChunkStreamID)chunkStream;

            Format = format;
            Data   = data;
            Body.MemoryWriter.Write(format);
            Body.MemoryWriter.Write(data);
        }
Example #9
0
        public RTMPMessageBody(RTMPConnection connection, RTMPMessageHeader header, RTMPLib.Internal.BinaryReader br)
        {
            Connection = connection;

            byte[] buffer = null;
            if (header.MessageLength < 0)             //this is a follow up message
            {
                RTMPChunkStream csinfo = Connection.GetChunkStream((int)header.ChunkStreamID);
                buffer = br.ReadBytes(Math.Min(csinfo.RemainingBytes, Connection.IncomingChunkSize));
            }
            else
            {
                buffer = br.ReadBytes(Math.Min(header.MessageLength, Connection.IncomingChunkSize));
            }
            ms.Write(buffer, 0, buffer.Length);

            /*int remaining = connection.IncomingChunkSize;
             *
             * while (remaining > 0)
             * {
             *      byte[] buffer = br.ReadBytes(remaining);
             *      ms.Write(buffer, 0, buffer.Length);
             *      remaining -= ParentMessage.Connection.IncomingChunkSize;
             * }
             *
             * int remaining = ParentMessage.Header.MessageLength;
             * while (remaining > 0)
             * {
             *      byte[] buffer = br.ReadBytes(Math.Min(ParentMessage.Connection.IncomingChunkSize,remaining));
             *      ms.Write(buffer,0,buffer.Length);
             *      remaining -= ParentMessage.Connection.IncomingChunkSize;
             *      if (remaining > 0)
             *      {
             *              new RTMPMessageHeader(ParentMessage, br); // read the header for the next message piece
             *      }
             * }*/
            ms.Position  = 0;
            MemoryReader = new RTMPLib.Internal.BinaryReader(ms);
        }
Example #10
0
        public RTMPMessageBody(RTMPConnection connection, RTMPMessageHeader header, RTMPLib.Internal.BinaryReader br)
        {
            Connection = connection;

            byte[] buffer = null;
            if (header.MessageLength < 0) //this is a follow up message
            {
                RTMPChunkStream csinfo = Connection.GetChunkStream((int)header.ChunkStreamID);
                buffer = br.ReadBytes(Math.Min(csinfo.RemainingBytes, Connection.IncomingChunkSize));
            }
            else
            {
                buffer = br.ReadBytes(Math.Min(header.MessageLength, Connection.IncomingChunkSize));
            }
            ms.Write(buffer, 0, buffer.Length);
            /*int remaining = connection.IncomingChunkSize;

            while (remaining > 0)
            {
                byte[] buffer = br.ReadBytes(remaining);
                ms.Write(buffer, 0, buffer.Length);
                remaining -= ParentMessage.Connection.IncomingChunkSize;
            }

            int remaining = ParentMessage.Header.MessageLength;
            while (remaining > 0)
            {
                byte[] buffer = br.ReadBytes(Math.Min(ParentMessage.Connection.IncomingChunkSize,remaining));
                ms.Write(buffer,0,buffer.Length);
                remaining -= ParentMessage.Connection.IncomingChunkSize;
                if (remaining > 0)
                {
                    new RTMPMessageHeader(ParentMessage, br); // read the header for the next message piece
                }
            }*/
            ms.Position = 0;
            MemoryReader = new RTMPLib.Internal.BinaryReader(ms);
        }
 public RTMPUserControlMessage(RTMPConnection connection, UserControlMessage_EventType eventType) : base(connection)
 {
     EventType            = eventType;
     Header.MessageTypeID = RTMPMessageTypeID.UserControlMessage;
     Body.MemoryWriter.Write((ushort)eventType);
 }
Example #12
0
 public RTMPAMF0Message(RTMPConnection connection)
     : base(connection)
 {
     Header.MessageTypeID = RTMPMessageTypeID.AMF0;
 }
Example #13
0
 public RTMPAMF0Message(RTMPConnection connection)
     : base(connection)
 {
     Header.MessageTypeID = RTMPMessageTypeID.AMF0;
 }
Example #14
0
 public RTMPChunkStream(RTMPConnection connection)
 {
     Connection = connection;
 }
Example #15
0
        public override V3Message execute(Request message, RequestContext context)
        {
            object returnValue = null;

            switch (operation)
            {
            case SUBSCRIBE_OPERATION:
            {
                IDestination destObj =
                    ORBConfig.GetInstance().GetDataServices().GetDestinationManager().GetDestination(destination);
                Hashtable headers = new Hashtable();

                RTMPConnection connection = (RTMPConnection)ConnectionHub.getConnectionLocal();

                if (destObj != null)
                {
                    String selectorName = (String)this.headers["DSSelector"];
                    String subtopic     = (String)this.headers["DSSubtopic"];
                    String dsId         = connection == null ? (String)this.headers["DSId"] : connection.GetHashCode().ToString();
                    String channel      = (String)this.headers["DSEndpoint"];

                    Subscriber subscriber = SubscriptionsManager.GetInstance().getSubscriber(
                        Subscriber.buildId(dsId, destObj.GetName(), subtopic, selectorName));

                    if (clientId == null || clientId.Equals(""))
                    {
                        clientId = Guid.NewGuid().ToString().ToUpper();
                    }

                    if (subscriber != null)
                    {
                        if (subscriber.addClient(clientId.ToString()))
                        {
                            destObj.GetServiceHandler().HandleSubscribe(subscriber, clientId.ToString(), this);
                        }

                        return(new AckMessage(messageId, clientId, null, headers));
                    }

                    object wsContext = ThreadContext.getProperties()[ORBConstants.WEB_SOCKET_MODE];

                    if (wsContext != null)
                    {
                        subscriber = new WebSocketSubscriber(selectorName, destObj, (UserContext)wsContext);
                    }
                    else if (connection != null)
                    {
                        subscriber = new DedicatedSubscriber(selectorName, destObj);
                        subscriber.setChannelId(RTMPHandler.getChannelId());
                        subscriber.setConnection(connection);
                    }
                    else
                    {
                        subscriber = SubscriberFactory.CreateSubscriber(channel, selectorName, destObj);
                    }

                    subscriber.setDSId(dsId);
                    subscriber.setSubtopic(subtopic);
                    subscriber.addClient((String)clientId);

                    try
                    {
                        SubscriptionsManager.GetInstance().AddSubscriber(dsId, destObj.GetName(), subscriber);
                    }
                    catch (Exception e)
                    {
                        if (Log.isLogging(LoggingConstants.EXCEPTION))
                        {
                            Log.log(LoggingConstants.EXCEPTION, e);
                        }
                    }

                    destObj.GetServiceHandler().HandleSubscribe(subscriber, clientId.ToString(), this);
                }
                else
                {
                    String error = "Unknown destination " + destination + ". Cannot handle subscription request";

                    if (Log.isLogging(LoggingConstants.ERROR))
                    {
                        Log.log(LoggingConstants.ERROR, error);
                    }

                    return(new ErrMessage(messageId, new Exception(error)));
                }

                return(new AckMessage(messageId, clientId, null, headers));
            }
            break;

            case UNSUBSCRIBE_OPERATION:
            {
                String subtopic     = (String)this.headers["DSSubtopic"];
                String dsId         = (String)this.headers["DSId"];
                String selectorName = (String)this.headers["DSSelector"];

                RTMPConnection connection = (RTMPConnection)ConnectionHub.getConnectionLocal();

                if (connection != null)
                {
                    dsId = connection.GetHashCode().ToString();
                }

                Subscriber subscriber = SubscriptionsManager.GetInstance().getSubscriber(
                    Subscriber.buildId(dsId, destination, subtopic, selectorName));

                if (subscriber != null)
                {
                    SubscriptionsManager.GetInstance().unsubscribe(subscriber, clientId.ToString(), this);
                }
            }
            break;

            case DISCONNECT_OPERATION:
            {
                String         dsId       = (String)this.headers["DSId"];
                RTMPConnection connection = (RTMPConnection)ConnectionHub.getConnectionLocal();

                if (connection != null)
                {
                    dsId = connection.GetHashCode().ToString();
                }

                SubscriptionsManager subscriptionsManager = SubscriptionsManager.GetInstance();
                List <Subscriber>    subscribers          = subscriptionsManager.getSubscribersByDsId(dsId);

                if (subscribers != null)
                {
                    foreach (Subscriber subscriber in subscribers)
                    {
                        if (subscriber != null)
                        {
                            subscriptionsManager.unsubscribe(subscriber, this);
                        }
                    }
                }

                subscriptionsManager.removeSubscriber(dsId);
            }
            break;

            case POLL_OPERATION:
            {
                String dsId = (String)this.headers["DSId"];

                RTMPConnection connection = (RTMPConnection)ConnectionHub.getConnectionLocal();

                if (connection != null)
                {
                    dsId = connection.GetHashCode().ToString() + "";
                }

                try
                {
                    WebORBArray <V3Message> messages =
                        new WebORBArray <V3Message>(SubscriptionsManager.GetInstance().getMessages(dsId));

                    if (messages.Count == 0)
                    {
                        return(new AckMessage(null, null, null, new Hashtable()));
                    }

                    return(new CommandMessage(CLIENT_SYNC_OPERATION, messages));
                }
                catch (Exception e)
                {
                    String error = "Invalid client id " + dsId;

                    if (Log.isLogging(LoggingConstants.ERROR))
                    {
                        Log.log(LoggingConstants.ERROR, error, e);
                    }

                    return(new ErrMessage(messageId, new Exception(error)));
                }
            }
            break;

            case CLIENT_PING_OPERATION:
            {
                Hashtable headers = new Hashtable();

                RTMPConnection connection = (RTMPConnection)ConnectionHub.getConnectionLocal();
                if (connection != null)
                {
                    headers.Add("DSId", connection.GetHashCode().ToString());
                }
                else
                {
                    headers.Add("DSId", Guid.NewGuid().ToString().ToUpper());
                }

                return(new AckMessage(messageId, clientId, null, headers));
            }
            break;

            case LOGOUT_OPERATION:
            {
                ThreadContext.setCallerCredentials(null, null);
                Thread.CurrentPrincipal = null;
            }
            break;

            case LOGIN_OPERATION:
            {
                String credentials = (String)((IAdaptingType)((object[])body.body)[0]).defaultAdapt();
                byte[] bytes       = Convert.FromBase64String(credentials);
                credentials = new String(Encoding.UTF8.GetChars(bytes));
                IAuthenticationHandler authHandler = ORBConfig.GetInstance().getSecurity().GetAuthenticationHandler();

                if (authHandler == null)
                {
                    ErrMessage errorMessage = new ErrMessage(messageId, new ServiceException("Missing authentication handler"));
                    errorMessage.faultCode = "Client.Authentication";
                    return(errorMessage);
                }

                int    index    = credentials.IndexOf(":");
                string userid   = null;
                string password = null;

                if (index != -1 && index != 0 && index != credentials.Length - 1)
                {
                    userid   = credentials.Substring(0, index);
                    password = credentials.Substring(index + 1);

                    try
                    {
                        IPrincipal principal = authHandler.CheckCredentials(userid, password, message);

                        try
                        {
                            Thread.CurrentPrincipal = principal;
                            ThreadContext.currentHttpContext().User = principal;
                        }
                        catch (Exception exception)
                        {
                            if (Log.isLogging(LoggingConstants.ERROR))
                            {
                                Log.log(LoggingConstants.ERROR,
                                        "Unable to set current principal. Make sure your current permission set allows Principal Control",
                                        exception);
                            }

                            throw exception;
                        }

                        Credentials creds = new Credentials();
                        creds.userid   = userid;
                        creds.password = password;
                        ThreadContext.setCallerCredentials(creds, principal);
                    }
                    catch (Exception exception)
                    {
                        ErrMessage errorMessage = new ErrMessage(messageId, exception);
                        errorMessage.faultCode = "Client.Authentication";
                        return(errorMessage);
                    }
                }
                else
                {
                    ErrMessage errorMessage = new ErrMessage(messageId, new ServiceException("Invalid credentials"));
                    errorMessage.faultCode = "Client.Authentication";
                    return(errorMessage);
                }
            }
            break;
            }

            return(new AckMessage(messageId, clientId, returnValue, new Hashtable()));
        }
Example #16
0
 public RTMPChunkStream(RTMPConnection connection)
 {
     Connection = connection;
 }