/* Copyright (C) <2007-2016> SatIp.RtspSample is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. SatIp.RtspSample is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with SatIp.RtspSample. If not, see . */ using System.Collections.Generic; using System.Text; namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.SatIp.Rtsp { /// /// A simple class that can be used to serialise RTSP requests. /// public class RtspRequest { private readonly RtspMethod _method; private readonly string _uri; private readonly int _majorVersion; private readonly int _minorVersion; private IDictionary _headers = new Dictionary(); private string _body = string.Empty; /// /// Initialise a new instance of the class. /// /// The request method. /// The request URI /// The major version number. /// The minor version number. public RtspRequest(RtspMethod method, string uri, int majorVersion, int minorVersion) { _method = method; _uri = uri; _majorVersion = majorVersion; _minorVersion = minorVersion; } /// /// Get the request method. /// public RtspMethod Method { get { return _method; } } /// /// Get the request URI. /// public string Uri { get { return _uri; } } /// /// Get the request major version number. /// public int MajorVersion { get { return _majorVersion; } } /// /// Get the request minor version number. /// public int MinorVersion { get { return _minorVersion; } } /// /// Get or set the request headers. /// public IDictionary Headers { get { return _headers; } set { _headers = value; } } /// /// Get or set the request body. /// public string Body { get { return _body; } set { _body = value; } } /// /// Serialise this request. /// /// raw request bytes public byte[] Serialise() { var request = new StringBuilder(); request.AppendFormat("{0} {1} RTSP/{2}.{3}\r\n", _method, _uri, _majorVersion, _minorVersion); foreach (var header in _headers) { request.AppendFormat("{0}: {1}\r\n", header.Key, header.Value); } request.AppendFormat("\r\n{0}", _body); return Encoding.UTF8.GetBytes(request.ToString()); } } }