Class SipUtils
Static class containing various SIP related utility functions.
Inherited Members
Namespace: SipLib.Core
Assembly: SipLib.dll
Syntax
public static class SipUtils
Methods
| Edit this page View SourceAddEmergencyIdUrnCallInfoHeader(SIPRequest, string, string)
Adds a Call-Info header to a SIP request containing a purpose parameter of emergency-IncidentId or emergency-CallId. See Sectionss 2.1.6 and 2.1.7 of NENA-STA-010.3.
Declaration
public static void AddEmergencyIdUrnCallInfoHeader(SIPRequest Req, string strIdUrn, string PurposeParam)
Parameters
Type | Name | Description |
---|---|---|
SIPRequest | Req | SIPRequest to add the Call-Info header to. |
string | strIdUrn | String containing the Emergency ID URN built using the BuildEmergencyIdUrn() function. Must be a valid URN. |
string | PurposeParam | Purpose parameter to add to the Call-Info header. Must be either "emergency-CallId" or "emergency-IncidentId". |
BuildAckRequest(SIPResponse, SIPChannel)
Builds an ACK SIP Request message to send in response to a SIP response message. This method can be used to build an ACK request to send in response to a 200 OK response or a 4XX response message that requires an ACK request.
Declaration
public static SIPRequest BuildAckRequest(SIPResponse Res, SIPChannel SipChan)
Parameters
Type | Name | Description |
---|---|---|
SIPResponse | Res | SIP response message to build the ACK request for. |
SIPChannel | SipChan | SIPChannel on which the SIP response was received. |
Returns
Type | Description |
---|---|
SIPRequest | Returns an ACK SIPRequest object. |
BuildByeRequest(SIPRequest, SIPChannel, IPEndPoint, bool, int, SIPResponse)
Builds a BYE SIPRequest for in incoming or an outgoing call.
Declaration
public static SIPRequest BuildByeRequest(SIPRequest InvReq, SIPChannel SipChan, IPEndPoint RemIpe, bool IncomingCall, int LastCSeqNumber, SIPResponse InviteOkResponse)
Parameters
Type | Name | Description |
---|---|---|
SIPRequest | InvReq | Original INVITE message for the call. |
SIPChannel | SipChan | SIPChannel used to communicate with the remote endpoint. |
IPEndPoint | RemIpe | IPEndPoint to send the request to. |
bool | IncomingCall | If true then the call was an incoming call, i.e. the INVITE request was received. Else, the call was an outgoing call, i.e. the INVITE request was sent. |
int | LastCSeqNumber | Last CSeq number for the call dialog. |
SIPResponse | InviteOkResponse | OK message that was received in response to the INVITE request. This parameter is required if the call was an outgoing one and is currently on-line. |
Returns
Type | Description |
---|---|
SIPRequest | Returns a SIPRequest object containing the BYE or the CANCEL request. |
BuildCancelRequest(SIPRequest, SIPChannel, IPEndPoint, int)
Builds a BYE or a CANCEL for in incoming or an outgoing call.
Declaration
public static SIPRequest BuildCancelRequest(SIPRequest InvReq, SIPChannel SipChan, IPEndPoint RemIpe, int LastCSeqNumber)
Parameters
Type | Name | Description |
---|---|---|
SIPRequest | InvReq | Original INVITE message for the call. |
SIPChannel | SipChan | SIPChannel used to communicate with the remote endpoint. |
IPEndPoint | RemIpe | IPEndPoint to send the request to. |
int | LastCSeqNumber | Last CSeq number for the call dialog. |
Returns
Type | Description |
---|---|
SIPRequest | Returns a SIPRequest object containing the BYE or the CANCEL request. |
BuildEmergencyIdUrn(string, string)
Builds a emergency URN identifier string used for a Call Identifier or a Incident Identifier. See Sectionss 2.1.6 and 2.1.7 of NENA-STA-010.3.
Declaration
public static string BuildEmergencyIdUrn(string IdType, string strElemId)
Parameters
Type | Name | Description |
---|---|---|
string | IdType | Must be either "callid" or "incidentid" |
string | strElemId | Element Identifier of the element that is inserting the Call-Info header. For example: "bcf.state.pa.us". |
Returns
Type | Description |
---|---|
string | Returns a formatted Emergency Incident or Call ID URN. |
BuildFingerprintAttr(X509Certificate2)
Builds a fingerprint SDP attribute for a X.509 certificate. See RFC 4572.
Declaration
public static SdpAttribute BuildFingerprintAttr(X509Certificate2 Cert)
Parameters
Type | Name | Description |
---|---|---|
X509Certificate2 | Cert | The X.509 certificate to build the attribute for. |
Returns
Type | Description |
---|---|
SdpAttribute | Returns the SdpAttribute object that can be added to the SDP. |
BuildInDialogRequest(SIPMethodsEnum, SIPChannel, bool, SIPRequest, string, string, SIPResponse, ref int)
Builds an in-dialog SIP request.
Declaration
public static SIPRequest BuildInDialogRequest(SIPMethodsEnum Method, SIPChannel SipChan, bool IncomingCall, SIPRequest InvReq, string LocalTag, string RemoteTag, SIPResponse InviteOkResponse, ref int LastCSeqNumber)
Parameters
Type | Name | Description |
---|---|---|
SIPMethodsEnum | Method | Request method for the new in-dialog request |
SIPChannel | SipChan | SIPChannel that the call is on |
bool | IncomingCall | True if the original call was incoming or false if it was an outgoing call |
SIPRequest | InvReq | The original INVITE request |
string | LocalTag | The local tag for the SIP dialog |
string | RemoteTag | The remote tag for the SIP dialog |
SIPResponse | InviteOkResponse | The original OK response to the INVITE request |
int | LastCSeqNumber | The last CSeq number. This value is updated by this function. |
Returns
Type | Description |
---|---|
SIPRequest | Returns a new SIPRequest object. |
BuildOkToByeOrCancel(SIPRequest, SIPEndPoint)
Builds an OK response to a BYE or a CANCEL request.
Declaration
public static SIPResponse BuildOkToByeOrCancel(SIPRequest Req, SIPEndPoint RemIp)
Parameters
Type | Name | Description |
---|---|---|
SIPRequest | Req | Request message to send the OK response to. |
SIPEndPoint | RemIp | Verified end point of the request originator. |
Returns
Type | Description |
---|---|
SIPResponse | Returns a 200 OK SIPResponse object. |
BuildOkToInvite(SIPRequest, SIPChannel, string, string)
Builds a 200 OK SIPResponse message for an INVITE request.
Declaration
public static SIPResponse BuildOkToInvite(SIPRequest InvReq, SIPChannel SipChan, string strBody, string strContentType)
Parameters
Type | Name | Description |
---|---|---|
SIPRequest | InvReq | INVITE request message to build the response for. |
SIPChannel | SipChan | SIPChannel on which the INVITE message was received on and the 200 OK response will be sent on. |
string | strBody | Body of the 200 OK. |
string | strContentType | Value of the Content-Type header that describes the format of the message body. For example: "application/sdp" or "multipart/mixed; boundary=boundary1" |
Returns
Type | Description |
---|---|
SIPResponse | Returns a SIPResponse object containing the 200 OK response message. |
BuildResponse(SIPRequest, SIPResponseStatusCodesEnum, string, SIPChannel, string?)
Builds a SIP response message. A simple response is something like 100 Trying, 180 Ringing, or 404 Not Found that does not have a message body.
Declaration
public static SIPResponse BuildResponse(SIPRequest Sr, SIPResponseStatusCodesEnum StatCode, string ReasonPhrase, SIPChannel sipChannel, string? SipUserName)
Parameters
Type | Name | Description |
---|---|---|
SIPRequest | Sr | The SIP request to respond to. |
SIPResponseStatusCodesEnum | StatCode | Status code to use for the response. |
string | ReasonPhrase | The response reason text. Required. Must not be empty or null. |
SIPChannel | sipChannel | Contains transport information. Must be the SIPChannel on which the request message was received. |
string | SipUserName | SIP user name to use for the User part of the SIPURI. Optional, may be null. |
Returns
Type | Description |
---|---|
SIPResponse | Returns a SIPResponse that can be sent. |
GetCallInfoHeaderForPurpose(SIPHeader, string)
Gets the SIPCallInfoHeader for the Call-Info header that has a specified purpose parameter.
Declaration
public static SIPCallInfoHeader? GetCallInfoHeaderForPurpose(SIPHeader Sh, string strPurpose)
Parameters
Type | Name | Description |
---|---|---|
SIPHeader | Sh | SIPHeader object containing the SIP headers for the request or response to search in. |
string | strPurpose | Purpose parameter to search for. |
Returns
Type | Description |
---|---|
SIPCallInfoHeader | Returns a SIPCallInfoHeader object if the specified Call-Info header was found or null if it was not. |
GetCallInfoHeaderForPurpose(SIPHeader, string, SIPSchemesEnum)
Gets the SIPCallInfoHeader for the Call-Info header that has a specified purpose parameter.
Declaration
public static SIPCallInfoHeader? GetCallInfoHeaderForPurpose(SIPHeader Sh, string strPurpose, SIPSchemesEnum ExcludeScheme)
Parameters
Type | Name | Description |
---|---|---|
SIPHeader | Sh | SIPHeader object containing the SIP headers for the request or response to search in. |
string | strPurpose | Purpose parameter to search for. |
SIPSchemesEnum | ExcludeScheme | Exclude headers with a URI scheme equal to this value. |
Returns
Type | Description |
---|---|
SIPCallInfoHeader | Returns a SIPCallInfoHeader object if the specified Call-Info header was found or null if it was not. |
GetCallInfoValueForPurpose(SIPHeader, string)
Returns the header value of a Call-Info header that has a specified "purpose=" header parameter.
Declaration
public static string? GetCallInfoValueForPurpose(SIPHeader Sh, string strPurpose)
Parameters
Type | Name | Description |
---|---|---|
SIPHeader | Sh | SIPHeader object containing the SIP headers for the request or response to search in. |
string | strPurpose | Purpose parameter to search for. |
Returns
Type | Description |
---|---|
string | Returns the header value of the matching Call-Info header. Returns null if there is no Call-Info header with the specified purpose parameter. |
GetPaiOrFromUri(SIPHeader)
Gets the SIP URI from the P-Asserted-Identity header if present or from the From header if the the PAI header is not present.
Declaration
public static SIPURI GetPaiOrFromUri(SIPHeader Sh)
Parameters
Type | Name | Description |
---|---|---|
SIPHeader | Sh | Input request headers |
Returns
Type | Description |
---|---|
SIPURI | Returns a copy of the SIPURI |
GetRemoteSipUri(SIPHeader)
Gets the URI of the remote party for an incoming call.
Declaration
public static SIPURI? GetRemoteSipUri(SIPHeader Hdr)
Parameters
Type | Name | Description |
---|---|---|
SIPHeader | Hdr | The headers from the INVITE request of the incoming call. |
Returns
Type | Description |
---|---|
SIPURI | Returns the URI to send a request to for the call, such as a BYE or CANCEL request. |
Remarks
This method returns the URI specified in the top Record-Route header if it has a "lr" parameter or the URI in Contact header. If there is no Contact header then this method returns the URI from the From header.
GetRemoteUri(SIPRequest)
Gets the URI of the remote party for an incoming call. Only call this method for incoming calls.
Declaration
public static SIPURI? GetRemoteUri(SIPRequest InvReq)
Parameters
Type | Name | Description |
---|---|---|
SIPRequest | InvReq | INVITE request of the incoming call. |
Returns
Type | Description |
---|---|
SIPURI | Returns the URI to send a request to for the call, such as a BYE or CANCEL request. |
Remarks
This method returns the URI specified in the top Record-Route header if it has a "lr" parameter or the URI in Contact header. If there is no Contact header then this method returns the URI from the From header.
GetResponseReason(SIPResponseStatusCodesEnum)
Returns a reason text statement given a SIPResponseStatusCodesEnum value
Declaration
public static string GetResponseReason(SIPResponseStatusCodesEnum Code)
Parameters
Type | Name | Description |
---|---|---|
SIPResponseStatusCodesEnum | Code | Code to return a statement for. |
Returns
Type | Description |
---|---|
string | Returns a text string. Return "Unknown" if the input code not found. |
GetSipFragResponseCode(string)
Parses a SipFrag, checks for errors and returns the status code from the the SIP message fragment.
Declaration
public static int GetSipFragResponseCode(string SipFrag)
Parameters
Type | Name | Description |
---|---|---|
string | SipFrag | String containing the sipfrag, for example: "SIP/2.0 200 OK" |
Returns
Type | Description |
---|---|
int | Returns the status code. Returns 0 if the sipfrag is not valid. |
GetTopContactSipUri(SIPHeader)
Gets the SIPURI of the top-most Contact header from a SIP request or a SIP response.
Declaration
public static SIPURI? GetTopContactSipUri(SIPHeader Hdr)
Parameters
Type | Name | Description |
---|---|---|
SIPHeader | Hdr | SIPHeader containing the Contact header list. |
Returns
Type | Description |
---|---|
SIPURI | Returns the SIPURI of the top-most Contact header if there is one or null if there are no Contact header. |
IsInDialog(SIPRequest)
Determines of a request is in dialog or not.
Declaration
public static bool IsInDialog(SIPRequest Req)
Parameters
Type | Name | Description |
---|---|---|
SIPRequest | Req | Input SIP INVITE request |
Returns
Type | Description |
---|---|
bool | Returns true if the request is in-dialog or false if it is not. |
VerifyUdpEndPoint(SIPRequest, SIPEndPoint, SIPChannel)
Checks for the case where a message is received on the UDP transport protocol and the top most Via header does not have an rport parameter but does have a port number that is different than the source port that the message was received on.
Declaration
public static SIPEndPoint VerifyUdpEndPoint(SIPRequest SipMsg, SIPEndPoint RemIp, SIPChannel SipChannel)
Parameters
Type | Name | Description |
---|---|---|
SIPRequest | SipMsg | Received message. |
SIPEndPoint | RemIp | SIPEndPoint that the message was received from./// |
SIPChannel | SipChannel | SIPChannel that received the request message. |
Returns
Type | Description |
---|---|
SIPEndPoint | Returns the original end point if the transport protocol is not UDP or if it is UDP but the top most Via contains an rport parameter. Else returns a new endpoint constructed from the Sent By part of the Via header provided it has a port number specified. If not port number is specified, then the original end point is returned. |