/// <summary> /// Checks if SIP response has all required values as response line,header fields and their values. /// Throws Exception if not valid SIP response. /// </summary> public void Validate() { // Via: + branch prameter // To: // From: // CallID: // CSeq if (Via.GetTopMostValue() == null) { throw new SIP_ParseException("Via: header field is missing !"); } if (Via.GetTopMostValue().Branch == null) { throw new SIP_ParseException("Via: header fields branch parameter is missing !"); } if (To == null) { throw new SIP_ParseException("To: header field is missing !"); } if (From == null) { throw new SIP_ParseException("From: header field is missing !"); } if (CallID == null) { throw new SIP_ParseException("CallID: header field is missing !"); } if (CSeq == null) { throw new SIP_ParseException("CSeq: header field is missing !"); } // TODO: INVITE 2xx must have only 1 contact header with SIP or SIPS. }
/// <summary> /// Checks if SIP request has all required values as request line,header fields and their values. /// Throws Exception if not valid SIP request. /// </summary> public void Validate() { // Request SIP version // Via: + branch prameter // To: // From: // CallID: // CSeq // Max-Forwards RFC 3261 8.1.1. if (!RequestLine.Version.ToUpper().StartsWith("SIP/2.0")) { throw new SIP_ParseException("Not supported SIP version '" + RequestLine.Version + "' !"); } if (Via.GetTopMostValue() == null) { throw new SIP_ParseException("Via: header field is missing !"); } if (Via.GetTopMostValue().Branch == null) { throw new SIP_ParseException("Via: header field branch parameter is missing !"); } if (To == null) { throw new SIP_ParseException("To: header field is missing !"); } if (From == null) { throw new SIP_ParseException("From: header field is missing !"); } if (CallID == null) { throw new SIP_ParseException("CallID: header field is missing !"); } if (CSeq == null) { throw new SIP_ParseException("CSeq: header field is missing !"); } if (MaxForwards == -1) { // We can fix it by setting it to default value 70. MaxForwards = 70; } /* RFC 3261 12.1.2 * When a UAC sends a request that can establish a dialog (such as an INVITE) it MUST * provide a SIP or SIPS URI with global scope (i.e., the same SIP URI can be used in * messages outside this dialog) in the Contact header field of the request. If the * request has a Request-URI or a topmost Route header field value with a SIPS URI, the * Contact header field MUST contain a SIPS URI. */ if (SIP_Utils.MethodCanEstablishDialog(RequestLine.Method)) { if (Contact.GetAllValues().Length == 0) { throw new SIP_ParseException( "Contact: header field is missing, method that can establish a dialog MUST provide a SIP or SIPS URI !"); } if (Contact.GetAllValues().Length > 1) { throw new SIP_ParseException( "There may be only 1 Contact: header for the method that can establish a dialog !"); } if (!Contact.GetTopMostValue().Address.IsSipOrSipsUri) { throw new SIP_ParseException( "Method that can establish a dialog MUST have SIP or SIPS uri in Contact: header !"); } } // TODO: Invite must have From:/To: tag // TODO: Check that request-Method equals CSeq method // TODO: PRACK must have RAck and RSeq header fields. // TODO: get in transport made request, so check if sips and sip set as needed. }