Esempio n. 1
0
        public static RTSPTransportHeader Parse(string header)
        {
            var transportHeader = new RTSPTransportHeader();

            if (header.NotNullOrBlank())
            {
                transportHeader.RawHeader = header;

                string[] fields = header.Split(';');

                transportHeader.TransportSpecifier = fields[0];
                transportHeader.BroadcastType      = fields[1];

                foreach (string field in fields.Where(x => x.Contains('=')))
                {
                    string fieldName  = field.Split('=')[0];
                    string fieldValue = field.Split('=')[1];

                    switch (fieldName.ToLower())
                    {
                    case CLIENT_RTP_PORT_FIELD_NAME:
                        transportHeader.ClientRTPPortRange = fieldValue.Trim();
                        break;

                    case DESTINATION_FIELD_NAME:
                        transportHeader.Destination = fieldValue.Trim();
                        break;

                    case SERVER_RTP_PORT_FIELD_NAME:
                        transportHeader.ServerRTPPortRange = fieldValue.Trim();
                        break;

                    case SOURCE_FIELD_NAME:
                        transportHeader.Source = fieldValue.Trim();
                        break;

                    case MODE_FIELD_NAME:
                        transportHeader.Mode = fieldValue.Trim();
                        break;

                    default:
                        logger.LogWarning("An RTSP Transport header parameter was not recognised. " + field);
                        break;
                    }
                }
            }

            return(transportHeader);
        }
Esempio n. 2
0
        public static RTSPTransportHeader Parse(string header)
        {
            var transportHeader = new RTSPTransportHeader();

            if (header.NotNullOrBlank())
            {
                transportHeader.RawHeader = header;

                string[] fields = header.Split(';');

                transportHeader.TransportSpecifier = fields[0];
                transportHeader.BroadcastType = fields[1];

                foreach(string field in fields.Where(x => x.Contains('=')))
                {
                    string fieldName = field.Split('=')[0];
                    string fieldValue = field.Split('=')[1];

                    switch(fieldName.ToLower())
                    {
                        case CLIENT_RTP_PORT_FIELD_NAME:
                            transportHeader.ClientRTPPortRange = fieldValue.Trim();
                            break;
                        case DESTINATION_FIELD_NAME:
                            transportHeader.Destination = fieldValue.Trim();
                            break;
                        case SERVER_RTP_PORT_FIELD_NAME:
                            transportHeader.ServerRTPPortRange = fieldValue.Trim();
                            break;
                        case SOURCE_FIELD_NAME:
                            transportHeader.Source = fieldValue.Trim();
                            break;
                        case MODE_FIELD_NAME:
                            transportHeader.Mode = fieldValue.Trim();
                            break;
                        default:
                            logger.Warn("An RTSP Transport header parameter was not recognised. " + field);
                            break;
                    }
                }
            }

            return transportHeader;
        }
Esempio n. 3
0
        public static RTSPHeader ParseRTSPHeaders(string[] headersCollection)
        {
            try
            {
                RTSPHeader rtspHeader = new RTSPHeader();

                string lastHeader = null;

                for (int lineIndex = 0; lineIndex < headersCollection.Length; lineIndex++)
                {
                    string headerLine = headersCollection[lineIndex];

                    if (headerLine == null || headerLine.Trim().Length == 0)
                    {
                        // No point processing blank headers.
                        continue;
                    }

                    string headerName  = null;
                    string headerValue = null;

                    // If the first character of a line is whitespace it's a continuation of the previous line.
                    if (headerLine.StartsWith(" "))
                    {
                        headerName  = lastHeader;
                        headerValue = headerLine.Trim();
                    }
                    else
                    {
                        string[] headerParts = headerLine.Trim().Split(delimiterChars, 2);

                        if (headerParts == null || headerParts.Length < 2)
                        {
                            logger.LogError("Invalid RTSP header, ignoring. header=" + headerLine + ".");

                            try
                            {
                                string errorHeaders = String.Join(m_CRLF, headersCollection);
                                logger.LogError("Full Invalid Headers: " + errorHeaders);
                            }
                            catch
                            {
                            }

                            continue;
                        }

                        headerName  = headerParts[0].Trim();
                        headerValue = headerParts[1].Trim();
                    }

                    try
                    {
                        string headerNameLower = headerName.ToLower();

                        #region Accept

                        if (headerNameLower == RTSPHeaders.RTSP_HEADER_ACCEPT.ToLower())
                        {
                            rtspHeader.Accept = headerValue;
                        }

                        #endregion

                        #region ContentType

                        if (headerNameLower == RTSPHeaders.RTSP_HEADER_CONTENTTYPE.ToLower())
                        {
                            rtspHeader.ContentType = headerValue;
                        }

                        #endregion

                        #region ContentLength

                        if (headerNameLower == RTSPHeaders.RTSP_HEADER_CONTENTLENGTH.ToLower())
                        {
                            rtspHeader.RawCSeq = headerValue;

                            if (headerValue == null || headerValue.Trim().Length == 0)
                            {
                                logger.LogWarning("Invalid RTSP header, the " + RTSPHeaders.RTSP_HEADER_CONTENTLENGTH +
                                                  " was empty.");
                            }
                            else if (!Int32.TryParse(headerValue.Trim(), out rtspHeader.ContentLength))
                            {
                                logger.LogWarning("Invalid RTSP header, the " + RTSPHeaders.RTSP_HEADER_CONTENTLENGTH +
                                                  " was not a valid 32 bit integer, " + headerValue + ".");
                            }
                        }

                        #endregion

                        #region CSeq

                        if (headerNameLower == RTSPHeaders.RTSP_HEADER_CSEQ.ToLower())
                        {
                            rtspHeader.RawCSeq = headerValue;

                            if (headerValue == null || headerValue.Trim().Length == 0)
                            {
                                rtspHeader.CSeqParserError = RTSPHeaderParserError.CSeqEmpty;
                                logger.LogWarning("Invalid RTSP header, the " + RTSPHeaders.RTSP_HEADER_CSEQ +
                                                  " was empty.");
                            }
                            else if (!Int32.TryParse(headerValue.Trim(), out rtspHeader.CSeq))
                            {
                                rtspHeader.CSeqParserError = RTSPHeaderParserError.CSeqNotValidInteger;
                                logger.LogWarning("Invalid SIP header, the " + RTSPHeaders.RTSP_HEADER_CSEQ +
                                                  " was not a valid 32 bit integer, " + headerValue + ".");
                            }
                        }

                        #endregion

                        #region Session

                        if (headerNameLower == RTSPHeaders.RTSP_HEADER_SESSION.ToLower())
                        {
                            rtspHeader.Session = headerValue;
                        }

                        #endregion

                        #region Transport

                        if (headerNameLower == RTSPHeaders.RTSP_HEADER_TRANSPORT.ToLower())
                        {
                            rtspHeader.Transport = RTSPTransportHeader.Parse(headerValue);
                        }

                        #endregion

                        else
                        {
                            rtspHeader.UnknownHeaders.Add(headerLine);
                        }

                        lastHeader = headerName;
                    }
                    catch (Exception parseExcp)
                    {
                        logger.LogError("Error parsing RTSP header " + headerLine + ". " + parseExcp.Message);
                        throw;
                    }
                }

                //sipHeader.Valid = sipHeader.Validate(out sipHeader.ValidationError);

                return(rtspHeader);
            }
            catch (ApplicationException)
            {
                throw;
            }
            catch (Exception excp)
            {
                logger.LogError("Exception ParseRTSPHeaders. " + excp.Message);
                throw;
            }
        }