Пример #1
0
        public static RTSPURL ParseRTSPURL(string url, out RTSPHeaderParserError parserError)
        {
            try
            {
                parserError = RTSPHeaderParserError.None;

                RTSPURL rtspURL = new RTSPURL();

                if (url == null || url.Trim().Length == 0)
                {
                    throw new ApplicationException("An RTSP URI cannot be parsed from an empty string.");
                }
                else
                {
                    int transAddrPosn = url.IndexOf(TRANSPORT_ADDR_SEPARATOR);

                    if (transAddrPosn == -1)
                    {
                        parserError = RTSPHeaderParserError.MandatoryColonMissing;
                        return(null);
                    }
                    else
                    {
                        rtspURL.URLTransport = url.Substring(0, transAddrPosn);
                        string urlHostPortion = url.Substring(transAddrPosn + TRANSPORT_ADDR_SEPARATOR.Length);

                        int hostDelimIndex = urlHostPortion.IndexOf(HOST_ADDR_DELIMITER);
                        if (hostDelimIndex != -1)
                        {
                            rtspURL.Host = urlHostPortion.Substring(0, hostDelimIndex);
                            rtspURL.Path = urlHostPortion.Substring(hostDelimIndex);
                        }
                        else
                        {
                            rtspURL.Host = urlHostPortion;
                        }
                    }

                    return(rtspURL);
                }
            }
            catch (ApplicationException appExcp)
            {
                throw appExcp;
            }
            catch (Exception excp)
            {
                throw new ApplicationException("There was an exception parsing an RTSP URL. " + excp.Message + " url=" + url);
            }
        }
Пример #2
0
        public static RTSPRequest ParseRTSPRequest(RTSPMessage rtspMessage, out RTSPRequestParserError requestParserError)
        {
            requestParserError = RTSPRequestParserError.None;
            string urlStr = null;

            try
            {
                var rtspRequest = new RTSPRequest();

                string statusLine = rtspMessage.FirstLine;

                int firstSpacePosn = statusLine.IndexOf(" ", StringComparison.OrdinalIgnoreCase);

                string method = statusLine.Substring(0, firstSpacePosn).Trim();
                rtspRequest.Method = RTSPMethods.GetMethod(method);
                if (rtspRequest.Method == RTSPMethodsEnum.UNKNOWN)
                {
                    rtspRequest.UnknownMethod = method;
                    logger.Warn("Unknown RTSP method received " + rtspRequest.Method + ".");
                }

                statusLine = statusLine.Substring(firstSpacePosn).Trim();
                int secondSpacePosn = statusLine.IndexOf(" ");

                if (secondSpacePosn != -1)
                {
                    urlStr = statusLine.Substring(0, secondSpacePosn);

                    rtspRequest.URL         = RTSPURL.ParseRTSPURL(urlStr);
                    rtspRequest.RTSPVersion = statusLine.Substring(secondSpacePosn, statusLine.Length - secondSpacePosn).Trim();
                    rtspRequest.Header      = (rtspMessage.RTSPHeaders != null) ? RTSPHeader.ParseRTSPHeaders(rtspMessage.RTSPHeaders) : new RTSPHeader(0, null);
                    rtspRequest.Body        = rtspMessage.Body;

                    return(rtspRequest);
                }
                else
                {
                    throw new ApplicationException("URI was missing on RTSP request.");
                }
            }
            catch (Exception excp)
            {
                logger.Error("Exception parsing RTSP request. URI, " + urlStr + ".");
                throw new ApplicationException("There was an exception parsing an RTSP request. " + excp.Message);
            }
        }
Пример #3
0
        public RTSPRequest(RTSPMethodsEnum method, string url)
        {
            RTSPHeaderParserError urlParserError = RTSPHeaderParserError.None;

            try
            {
                Method = method;

                URL = RTSPURL.ParseRTSPURL(url, out urlParserError);
                if (urlParserError != RTSPHeaderParserError.None)
                {
                    throw new ApplicationException("Error parsing RTSP URL, " + urlParserError.ToString() + ".");
                }

                RTSPVersion = m_rtspFullVersion;
            }
            catch (Exception excp)
            {
                logger.Error("Exception RTSPRequest Ctor. " + excp.Message + ".");
            }
        }
Пример #4
0
 public RTSPRequest(RTSPMethodsEnum method, RTSPURL url)
 {
     Method      = method;
     URL         = url;
     RTSPVersion = m_rtspFullVersion;
 }