UA source identification

UA source identification determines whether an incoming SIP request belongs to a specific phone line. In the Ozeki VoIP SIP SDK, this decision is made through the ISourceIdentifier interface, which can be implemented to provide custom logic for identifying requests received on that phone line.

Overview

By default, the SDK uses DefaultSourceIdentifier to decide whether an incoming request belongs to a phone line. The default logic is based on the Request-URI, which is the standard way to determine whether the request targets the local SIP identity associated with the line.

In normal SIP scenarios, this default behavior is sufficient. If the Request-URI matches the destination represented by the phone line, the SDK accepts the request as local and the incoming call can be processed normally.

Why custom source identification can be useful

Some PBXs route incoming SIP requests to the correct IP address and port, but do not rewrite the Request-URI to match the destination user. In such cases, the request may reach the correct endpoint while still appearing to target a foreign identity according to the default Request-URI-based check.

To handle this kind of interoperability issue, you can implement ISourceIdentifier and provide custom identification logic. This logic works at the phone line level, so it must decide whether the incoming request belongs to the specific phone line to which the custom source identifier was assigned.

A custom implementation can fully replace the default behavior or supplement it. A common approach is to run DefaultSourceIdentifier first, then apply additional matching rules only if the default Request-URI-based identification does not succeed.

Code example

The following example shows a custom ISourceIdentifier implementation that preserves the default Request-URI-based behavior and adds a fallback check based on the username in the To header. This example is provided only to demonstrate how custom identification logic can be implemented.


/// Identifies whether an initial SIP INVITE request should be handled by a specific
/// UA instance by applying the default identification logic and a compatibility
/// fallback based on the To header.
public class MySourceIdentifier : ISourceIdentifier
{
    DefaultSourceIdentifier defaultSourceIdentifier = new();

    public bool Identify(SIPUAInstanceInfo instanceInfo, SIPRequestInfo requestInfo)
    {
        // First, use the default identification logic.
        // This matches the request based on the Request-URI.
        if (defaultSourceIdentifier.Identify(instanceInfo, requestInfo))
        {
            return true;
        }

        // Fallback identification.
        // If the default matching fails, compare only the username part of the
        // To header with this UA instance's username.
        //
        // Warning: Matching on the To header is an implementation-specific
        // compatibility fallback and is not part of the standard identification logic.
        if (string.Equals(instanceInfo.Identity.UserName, requestInfo.To.UserName, StringComparison.OrdinalIgnoreCase))
        {
            return true;
        }

        // The request does not belong to this UA instance.
        return false;
    }
}

How to use it

To use custom source identification, assign an implementation of ISourceIdentifier to the phone lineโ€™s SourceIdentifier property. The SDK will then use that implementation to determine whether an incoming request belongs to that specific phone line.

line.SourceIdentifier = new MySourceIdentifier();

With this approach, the standard Request-URI-based logic can be preserved while additional matching rules are introduced for PBX environments that do not fully follow the expected routing behavior. This makes it possible to accept incoming requests that belong to the phone line even when the default identification logic alone would not classify them as local.

Summary

This page explains how the Ozeki VoIP SIP SDK determines whether an incoming SIP request belongs to a specific phone line. By default, DefaultSourceIdentifier uses the Request-URI for this decision, but developers can implement ISourceIdentifier to replace or extend that logic when PBX routing behavior requires additional checks, such as matching the username in the To header.


More information