SIPSorcery.SIP.SIPResponse.ParseSIPResponse C# (CSharp) Method

ParseSIPResponse() public static method

public static ParseSIPResponse ( SIPMessage sipMessage ) : SIPResponse
sipMessage SIPMessage
return SIPResponse
        public static SIPResponse ParseSIPResponse(SIPMessage sipMessage)
        {
            try
            {
                SIPResponse sipResponse = new SIPResponse();
                sipResponse.LocalSIPEndPoint = sipMessage.LocalSIPEndPoint;
                sipResponse.RemoteSIPEndPoint = sipMessage.RemoteSIPEndPoint;
                string statusLine = sipMessage.FirstLine;

                int firstSpacePosn = statusLine.IndexOf(" ");

                sipResponse.SIPVersion = statusLine.Substring(0, firstSpacePosn).Trim();
                statusLine = statusLine.Substring(firstSpacePosn).Trim();
                sipResponse.StatusCode = Convert.ToInt32(statusLine.Substring(0, 3));
                sipResponse.Status = SIPResponseStatusCodes.GetStatusTypeForCode(sipResponse.StatusCode);
                sipResponse.ReasonPhrase = statusLine.Substring(3).Trim();

                sipResponse.Header = SIPHeader.ParseSIPHeaders(sipMessage.SIPHeaders);
                sipResponse.Body = sipMessage.Body;

                return sipResponse;
            }
            catch (SIPValidationException)
            {
                throw;
            }
            catch (Exception excp)
            {
                logger.Error("Exception ParseSIPResponse. " + excp.Message);
                logger.Error(sipMessage.RawMessage);
                throw new SIPValidationException(SIPValidationFieldsEnum.Response, "Error parsing SIP Response");
            }
        }

Same methods

SIPResponse::ParseSIPResponse ( string sipMessageStr ) : SIPResponse

Usage Example

Exemplo n.º 1
0
            public void MatchOnRequestAndResponseTest()
            {
                SIPTransactionEngine transactionEngine = new SIPTransactionEngine();
                SIPEndPoint          dummySIPEndPoint  = new SIPEndPoint(new IPEndPoint(IPAddress.Loopback, 1234));

                SIPRequest inviteRequest = SIPRequest.ParseSIPRequest("INVITE sip:dummy@udp:127.0.0.1:12014 SIP/2.0" + m_CRLF +
                                                                      "Via: SIP/2.0/UDP 127.0.0.1:1234;branch=z9hG4bK5f37455955ca433a902f8fea0ce2dc27" + m_CRLF +
                                                                      "To: <sip:dummy@udp:127.0.0.1:12014>" + m_CRLF +
                                                                      "From: <sip:[email protected]>;tag=2062917371" + m_CRLF +
                                                                      "Call-ID: 8ae45c15425040179a4285d774ccbaf6" + m_CRLF +
                                                                      "CSeq: 1 INVITE" + m_CRLF +
                                                                      "Contact: <sip:127.0.0.1:1234>" + m_CRLF +
                                                                      "Max-Forwards: 70" + m_CRLF +
                                                                      "User-Agent: unittest" + m_CRLF +
                                                                      "Content-Length: 5" + m_CRLF +
                                                                      "Content-Type: application/sdp" + m_CRLF +
                                                                      m_CRLF +
                                                                      "dummy");

                SIPTransaction transaction = new UACInviteTransaction(new SIPTransport(MockSIPDNSManager.Resolve, null), inviteRequest, dummySIPEndPoint, dummySIPEndPoint, null);

                transactionEngine.AddTransaction(transaction);

                SIPResponse sipResponse = SIPResponse.ParseSIPResponse("SIP/2.0 603 Nothing listening" + m_CRLF +
                                                                       "Via: SIP/2.0/UDP 127.0.0.1:1234;branch=z9hG4bK5f37455955ca433a902f8fea0ce2dc27;rport=12013" + m_CRLF +
                                                                       "To: <sip:dummy@udp:127.0.0.1:12014>" + m_CRLF +
                                                                       "From: <sip:[email protected]>;tag=2062917371" + m_CRLF +
                                                                       "Call-ID: 8ae45c15425040179a4285d774ccbaf6" + m_CRLF +
                                                                       "CSeq: 1 INVITE" + m_CRLF +
                                                                       "Content-Length: 0" + m_CRLF +
                                                                       m_CRLF);

                Assert.IsNotNull(transactionEngine.GetTransaction(sipResponse), "Transaction should have matched, check the hashing mechanism.");
            }
All Usage Examples Of SIPSorcery.SIP.SIPResponse::ParseSIPResponse