Пример #1
0
        public void NotBeforeEndUnitTest()
        {
            Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

            byte[] sample = Encoding.ASCII.GetBytes("The quick brown fox jumped over...");

            bool hasFox = ByteBufferInfo.HasString(sample, 0, Int32.MaxValue, "fox", "brown");

            Assert.True(!hasFox, "The string was not found in the buffer.");
        }
Пример #2
0
        public void HasStringUnitTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            byte[] sample = Encoding.ASCII.GetBytes("The quick brown fox jumped over...");

            bool hasFox = ByteBufferInfo.HasString(sample, 0, Int32.MaxValue, "fox", null);

            Assert.True(hasFox, "The string was not found in the buffer.");
        }
Пример #3
0
        public SIPEndPoint LocalSIPEndPoint;  // The local SIP socket the message was received on or sent from.

        /// <summary>
        /// Attempts to parse a SIP message from a single buffer that can only contain a single message.
        /// </summary>
        /// <param name="buffer">The buffer that will be parsed for a SIP message.</param>
        /// <param name="localSIPEndPoint">The end point the message was received on.</param>
        /// <param name="remoteSIPEndPoint">The end point the message was received from.</param>
        /// <returns>If successful a SIP message or null if not.</returns>
        public static SIPMessageBuffer ParseSIPMessage(byte[] buffer, SIPEndPoint localSIPEndPoint,
                                                       SIPEndPoint remoteSIPEndPoint)
        {
            string message = null;

            try
            {
                if (buffer == null || buffer.Length < m_minFirstLineLength)
                {
                    // Ignore.
                    return(null);
                }
                else if (buffer.Length > SIPConstants.SIP_MAXIMUM_RECEIVE_LENGTH)
                {
                    throw new ApplicationException(
                              "SIP message received that exceeded the maximum allowed message length, ignoring.");
                }
                else if (!ByteBufferInfo.HasString(buffer, 0, buffer.Length, SIP_MESSAGE_IDENTIFIER, m_CRLF))
                {
                    // Message does not contain "SIP" anywhere on the first line, ignore.
                    return(null);
                }
                else
                {
                    message = Encoding.UTF8.GetString(buffer, 0, buffer.Length);
                    SIPMessageBuffer sipMessageBuffer = ParseSIPMessage(message, localSIPEndPoint, remoteSIPEndPoint);

                    if (sipMessageBuffer != null)
                    {
                        sipMessageBuffer.RawBuffer = buffer;
                        return(sipMessageBuffer);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            catch (Exception excp)
            {
                message = message.Replace("\n", "LF");
                message = message.Replace("\r", "CR");
                Logger.Logger.Error("Exception ParseSIPMessage. ->" + excp.Message + "->SIP Message=" + message + ".");
                return(null);
            }
        }
Пример #4
0
        public static RTSPMessage ParseRTSPMessage(byte[] buffer, IPEndPoint receivedFrom, IPEndPoint receivedOn)
        {
            string message = null;

            try
            {
                if (buffer == null || buffer.Length < m_minFirstLineLength)
                {
                    // Ignore.
                    return(null);
                }
                else if (buffer.Length > RTSPConstants.RTSP_MAXIMUM_LENGTH)
                {
                    Logger.Logger.Error(
                        "RTSP message received that exceeded the maximum allowed message length, ignoring.");
                    return(null);
                }
                else if (!ByteBufferInfo.HasString(buffer, 0, buffer.Length, RTSP_MESSAGE_IDENTIFIER, m_CRLF))
                {
                    // Message does not contain "RTSP" anywhrere on the first line, ignore.
                    return(null);
                }
                else
                {
                    message = Encoding.UTF8.GetString(buffer);
                    RTSPMessage rtspMessage = ParseRTSPMessage(message, receivedFrom, receivedOn);
                    rtspMessage.RawBuffer = buffer;

                    return(rtspMessage);
                }
            }
            catch (Exception excp)
            {
                message = message.Replace("\n", "LF");
                message = message.Replace("\r", "CR");
                Logger.Logger.Error("Exception ParseRTSPMessage. ->" + excp.Message + "->RTSP Message=" + message +
                                    ".");
                return(null);
            }
        }