Beispiel #1
0
        public static RTSPResponse ParseRTSPResponse(RTSPMessage rtspMessage,
                                                     out RTSPResponseParserError responseParserError)
        {
            responseParserError = RTSPResponseParserError.None;

            try
            {
                RTSPResponse rtspResponse = new RTSPResponse();

                string statusLine = rtspMessage.FirstLine;

                int firstSpacePosn = statusLine.IndexOf(" ");

                rtspResponse.RTSPVersion = statusLine.Substring(0, firstSpacePosn).Trim();
                statusLine = statusLine.Substring(firstSpacePosn).Trim();
                rtspResponse.StatusCode   = Convert.ToInt32(statusLine.Substring(0, 3));
                rtspResponse.Status       = RTSPResponseStatusCodes.GetStatusTypeForCode(rtspResponse.StatusCode);
                rtspResponse.ReasonPhrase = statusLine.Substring(3).Trim();

                rtspResponse.Header = RTSPHeader.ParseRTSPHeaders(rtspMessage.RTSPHeaders);
                rtspResponse.Body   = rtspMessage.Body;

                //rtspResponse.Valid = rtspResponse.Validate(out sipResponse.ValidationError);

                return(rtspResponse);
            }
            catch (Exception excp)
            {
                logger.Error("Exception parsing RTSP reqsponse. " + excp.Message);
                throw new ApplicationException("There was an exception parsing an RTSP response. " + excp.Message);
            }
        }
        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.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.Logger.Error("Exception parsing RTSP request. URI, " + urlStr + ".");
                throw new ApplicationException("There was an exception parsing an RTSP request. " + excp.Message);
            }
        }