Esempio n. 1
0
        /// <summary>
        /// Compares the <b>CSeq</b> header in this message with the message
        /// passed.
        /// </summary>
        /// <param name="message">The message to be compared.</param>
        /// <returns><c>true</c> if both headers have <b>CSeq</b> headers and their values match.</returns>
        public bool MatchCSeq(SipMessage message)
        {
            var v1 = this.GetHeader <SipCSeqValue>(SipHeader.CSeq);
            var v2 = message.GetHeader <SipCSeqValue>(SipHeader.CSeq);

            if (v1 == null || v2 == null)
            {
                return(false);
            }

            return(v1.Number == v2.Number && v1.Method == v2.Method);
        }
Esempio n. 2
0
        /// <summary>
        /// Generates a diagnostic trace of the message passed.
        /// </summary>
        /// <param name="title">The trace title.</param>
        /// <param name="message">The message.</param>
        public static void Trace(string title, SipMessage message)
        {
            StringBuilder sb = new StringBuilder(1024);
            SipRequest    request;
            SipResponse   response;
            string        summary;
            string        contentType;
            SipCSeqValue  vCSeq;
            string        cseqMethod;
            string        cseqNumber;

            vCSeq = message.GetHeader <SipCSeqValue>(SipHeader.CSeq);
            if (vCSeq == null)
            {
                cseqMethod = "????";
                cseqNumber = "CSeq:????";
            }
            else
            {
                cseqMethod = vCSeq.Method;
                cseqNumber = "CSeq:" + vCSeq.Number.ToString();
            }

            request = message as SipRequest;
            if (request != null)
            {
                summary = string.Format("{0} Request: {1} {2}", request.MethodText, request.Uri, cseqNumber);
            }
            else
            {
                response = (SipResponse)message;
                summary  = string.Format("{0} Response: {1} ({2}) {3}", cseqMethod, response.StatusCode, response.ReasonPhrase, cseqNumber);
            }

            sb.AppendLine(title);
            sb.AppendLine();
            sb.Append(message.ToString());

            contentType = message.GetHeaderText(SipHeader.ContentType);
            if (message.ContentLength > 0 && message.HasContentType(SipHelper.SdpMimeType))
            {
                sb.AppendLine(Helper.FromUTF8(message.Contents));
            }
            else
            {
                sb.AppendLine(Helper.HexDump(message.Contents, 16, HexDumpOption.ShowAll));
            }

            NetTrace.Write(SipHelper.TraceSubsystem, 0, "SIP: " + title, summary, sb.ToString());
        }