Skip to content

siddiqsoft::sipmessage Class Reference

Namespace siddiqsoft
Inherits public nlohmann::json • #include <siddiqsoft/sipmessage.hpp>

Represents a Session Initiation Protocol (SIP) message with native JSON serialization. Provides accessors for start-line / status-line fields, standard RFC 3261 headers, SDP bodies, and metadata tracking.

Class Hierarchy & Inheritance

The following UML class diagram highlights siddiqsoft::sipmessage within the system architecture.

siddiqsoft::sipmessage Node1 siddiqsoft::sipmessage Node2 nlohmann::json Node2->Node1 Figure: GraphViz UML inheritance diagram for siddiqsoft::sipmessage

siddiqsoft::sipmessage Node1 siddiqsoft::sipmessage Node2 nlohmann::json Node2->Node1 Node3 std::string Node3->Node1 MetaLibName MetaParserVersion MetaSchemaVersion MetaUserAgentString MetaVersionString Node4 std::basic_string< Char > Node4->Node3 Figure: GraphViz UML collaboration diagram for siddiqsoft::sipmessage

Member Functions Summary

Constructors

sipmessage ()
Default constructor initializing an empty SIP message with standard metadata.
sipmessage (
const std::string& method,
const std::string& uri,
const std::string& callId = {},
uint32_t cseq = 0
)
Constructs a SIP request message with method, URI, Call-ID, and CSeq.
sipmessage (uint32_t statusCode)
Constructs a SIP response message with status code and standard reason phrase.
sipmessage (const nlohmann::json& src)
Initializes sipmessage from an existing JSON document.

Start-Line & Status-Line Accessors

autogetMethod () const
Returns the SIP request method string.
std::string_viewgetMethodView () const
Returns zero-copy view of request method string from internal JSON storage.
autogetUri () const
Returns the SIP request URI string.
std::string_viewgetUriView () const
Returns zero-copy view of request URI string from internal JSON storage.
autogetStatusCode () const
Returns numeric response status code.
autogetReason () const
Returns response reason phrase string.
std::string_viewgetReasonView () const
Returns zero-copy view of response reason phrase.
boolisMessageRequest () const
Returns true if message represents a SIP request.
boolisMessageResponse () const
Returns true if message represents a SIP response.

Header Management

auto&headers ()
Provides direct reference to the /h headers JSON object.
autogetHeader (
const std::string& key,
std::optional<T> defaultValue = {}
) const
Retrieves header value matching key, converting to type T.
sipmessage&setHeader (
const std::string& key,
const T& v
)
Sets or updates header key-value pair. Returns *this for chaining.
autogetCallID () const
Returns the Call-ID header value.
std::string_viewgetCallIDView () const
Returns zero-copy view of Call-ID header.
std::stringgetContentType () const
Returns Content-Type header string.
std::string_viewgetContentTypeView () const
Returns zero-copy view of Content-Type header.
uint32_tgetContentLength () const
Parses and returns Content-Length as integer.
uint32_tgetExpires () const
Parses and returns Expires header as integer.

Body & SDP Management

auto&body ()
Provides direct reference to the /b body JSON object.
boolhasBody () const
Returns true if message body contains data.
TgetBodyElement (
const nlohmann::json::json_pointer& jp,
const T& defaultValue
) const
Queries property within body JSON tree via RFC 6901 JSON pointer.
sipmessage&setBody (
const nlohmann::json::json_pointer& jp,
const T& v
)
Sets value at specified JSON pointer path within the body object.

Detailed Description

The sipmessage class represents a SIP message as a first-class JSON object by extending nlohmann::json. The internal structure partitions the message into standardized components:

  • /s: Start line / status line container (method, uri, version, statusCode, reasonPhrase).
  • /h: Headers dictionary mapping canonical header names to their wire values.
  • /b: Body dictionary containing unstructured payload strings or structured SDP arrays (/b/sdp).
  • /meta: Diagnostic and provenance metadata (version, timestamp, parse duration ttx).

Member Function Documentation

Constructors

sipmessage()

siddiqsoft::sipmessage::sipmessage();

Default constructor initializing an empty SIP message with standard metadata (version, timestamp, TTX counter).

Returns

sipmessage — An initialized empty SIP message instance.

Example
// Source: tests/regression/src/rule_of_five_tests.cpp:L28-L34
siddiqsoft::sipmessage msg;

EXPECT_TRUE(msg.contains("meta"));
EXPECT_FALSE(msg.value("/meta/version"_json_pointer, std::string {}).empty());
EXPECT_FALSE(msg.value("/meta/time"_json_pointer, std::string {}).empty());
EXPECT_EQ(0, msg.value("/meta/ttx"_json_pointer, -1));

sipmessage(request)

siddiqsoft::sipmessage::sipmessage(
    const std::string& method,
    const std::string& uri,
    const std::string& callId = {},
    uint32_t cseq = 0
);

Constructs a SIP request message with method, request URI, Call-ID, and CSeq.

Parameters
const std::string& method SIP method string (e.g. `INVITE`, `REGISTER`).
const std::string& uri Target SIP request URI.
const std::string& callId Optional Call-ID identifier string.
uint32_t cseq Optional initial sequence number.
Returns

sipmessage — A populated SIP request message instance.

Example
// Source: tests/regression/src/rule_of_five_tests.cpp:L40-L49
siddiqsoft::sipmessage original(siddiqsoft::METHOD_INVITE, "sip:test@example.com", "call-id-123", 1);
original.setHeader("X-Custom", "original-value");

EXPECT_EQ(original.getCallID(), "call-id-123");
EXPECT_EQ(original.getMethod(), siddiqsoft::METHOD_INVITE);
EXPECT_TRUE(original.isMessageRequest());

sipmessage(response)

siddiqsoft::sipmessage::sipmessage(
    uint32_t statusCode
);

Constructs a SIP response message with numeric status code and standard reason phrase.

Parameters
uint32_t statusCode Standard SIP status code (e.g. `200`, `404`, `503`).
Returns

sipmessage — A populated SIP response message instance.

Example
// Source: tests/regression/src/rule_of_five_tests.cpp:L99-L100
siddiqsoft::sipmessage response(200);

EXPECT_EQ(200, response.getStatusCode());
EXPECT_EQ("OK", response.getReason());
EXPECT_TRUE(response.isMessageResponse());

sipmessage(json)

siddiqsoft::sipmessage::sipmessage(
    const nlohmann::json& src
);

Initializes sipmessage from an existing JSON document conforming to sip2json schema.

Parameters
const nlohmann::json& src Source JSON object conforming to sip2json schema.
Returns

sipmessage — A deserialized message instance wrapping the JSON payload.

Example
// Source: tests/regression/src/rule_of_five_tests.cpp:L60-L70
nlohmann::json json_obj = {
    {"s", {{"type", "request"}, {"method", "INVITE"}, {"uri", "sip:test@example.com"}, {"version", "SIP/2.0"}}},
    {"h", {{"Call-ID", "test-call-id"}, {"User-Agent", "test-agent"}}},
    {"b", nullptr},
    {"meta", {{"version", "sip2json/3.2.0/1.0.2"}, {"time", "2024-01-01T00:00:00Z"}, {"ttx", 0}}}
};

siddiqsoft::sipmessage msg(json_obj);
EXPECT_EQ(siddiqsoft::METHOD_INVITE, msg.getMethod());
EXPECT_EQ("test-call-id", msg.getCallID());

Start-Line Accessors

getMethod()

auto siddiqsoft::sipmessage::getMethod() const;

Returns a copy of the SIP request method string.

Returns

auto (std::string) — Method string (e.g., "INVITE", "REGISTER"). Empty string if response.

Example
// Source: tests/regression/src/rule_of_five_tests.cpp:L48
siddiqsoft::sipmessage msg(siddiqsoft::METHOD_INVITE, "sip:test@example.com");
EXPECT_EQ(siddiqsoft::METHOD_INVITE, msg.getMethod());

getMethodView()

std::string_view siddiqsoft::sipmessage::getMethodView() const;

Returns zero-copy view of request method string from internal JSON storage.

Returns

std::string_view — Non-allocating view into internal JSON. Lifetime tied to parent sipmessage.

Example
// Source: tests/regression/src/stress_tests.cpp:L97
std::string_view methodView = sipm.getMethodView();
EXPECT_EQ("INVITE", methodView);

getUri()

auto siddiqsoft::sipmessage::getUri() const;

Returns a copy of the SIP request URI string.

Returns

auto (std::string) — URI string (e.g. "sip:user@host.com"). Empty if missing.

Example
// Source: tests/regression/src/stress_tests.cpp:L175
std::string uri = sipm.getUri();
EXPECT_EQ("sip:test@test.com", uri);

getUriView()

std::string_view siddiqsoft::sipmessage::getUriView() const;

Returns zero-copy view of request URI string from internal JSON storage.

Returns

std::string_view — Non-allocating view of the request URI string.

Example
// Source: tests/regression/src/stress_tests.cpp:L175
std::string_view uriView = sipm.getUriView();
EXPECT_EQ("sip:test@test.com", uriView);

getStatusCode()

auto siddiqsoft::sipmessage::getStatusCode() const;

Returns numeric response status code.

Returns

auto (uint32_t) — Status code (e.g. 200, 404). Returns 0 if message is a request.

Example
// Source: tests/regression/src/stress_tests.cpp:L115
uint32_t code = sipm.getStatusCode();
EXPECT_EQ(200u, code);

getReason()

auto siddiqsoft::sipmessage::getReason() const;

Returns response reason phrase string.

Returns

auto (std::string) — Reason phrase string (e.g. "OK", "Not Found").

Example
// Source: tests/regression/src/stress_tests.cpp:L74
siddiqsoft::sipmessage resp(200);
EXPECT_EQ("OK", resp.getReason());

getReasonView()

std::string_view siddiqsoft::sipmessage::getReasonView() const;

Returns zero-copy view of response reason phrase.

Returns

std::string_view — Non-allocating view of response reason phrase.

Example
// Source: tests/regression/src/stress_tests.cpp:L74
std::string_view reason = resp.getReasonView();
EXPECT_EQ("OK", reason);

isMessageRequest()

bool siddiqsoft::sipmessage::isMessageRequest() const;

Returns true if message represents a SIP request.

Returns

booltrue if message represents a request; false otherwise.

Example
// Source: tests/regression/src/rule_of_five_tests.cpp:L85
EXPECT_TRUE(moved.isMessageRequest());

isMessageResponse()

bool siddiqsoft::sipmessage::isMessageResponse() const;

Returns true if message represents a SIP response.

Returns

booltrue if message represents a response; false otherwise.

Example
// Source: tests/regression/src/rule_of_five_tests.cpp:L100
EXPECT_TRUE(response.isMessageResponse());

Header Operations

headers()

auto& siddiqsoft::sipmessage::headers();

Provides direct reference to the /h headers JSON object.

Returns

auto& (nlohmann::json&) — Mutable reference to the internal headers dictionary.

Example
// Source: tests/regression/src/synthetics.cpp:L84-L89
EXPECT_TRUE(sipm.contains("/h/Via"_json_pointer));
auto via = sipm["h"]["Via"];
EXPECT_TRUE(via.is_array());

getHeader()

template <class T> auto siddiqsoft::sipmessage::getHeader(
    const std::string& key,
    std::optional<T> defaultValue = {}
) const;

Retrieves header value matching key, converting to type T.

Parameters
const std::string& key Header name (case-insensitive via canonical mapping).
std::optional<T> defaultValue Optional fallback value returned if key is absent.
Returns

auto (T) — Header value converted to type T. Returns defaultValue if header is not present.

Example
// Source: tests/regression/src/rule_of_five_tests.cpp:L47
std::string customVal = copy.getHeader<std::string>("X-Custom");
EXPECT_EQ("original-value", customVal);

setHeader()

template <typename T> sipmessage& siddiqsoft::sipmessage::setHeader(
    const std::string& key,
    const T& v
);

Sets or updates header key-value pair. Returns *this for method chaining.

Parameters
const std::string& key Header name string or static constant (e.g. `siddiqsoft::HF_FROM`).
const T& v Header value (string, integer, or convertible type).
Returns

sipmessage& — Reference to *this enabling method chaining.

Example
// Source: tests/regression/src/stress_tests.cpp:L137-L138
sipm.setHeader(siddiqsoft::HF_TO, "sip:test@test.com")
    .setHeader(siddiqsoft::HF_FROM, "sip:sender@sender.com");

getCallID()

auto siddiqsoft::sipmessage::getCallID() const;

Returns the Call-ID header value.

Returns

auto (std::string) — Call-ID header string.

Example
// Source: tests/regression/src/rule_of_five_tests.cpp:L46
EXPECT_EQ(original.getCallID(), copy.getCallID());

getCallIDView()

std::string_view siddiqsoft::sipmessage::getCallIDView() const;

Returns zero-copy view of Call-ID header.

Returns

std::string_view — Non-allocating view into internal JSON for the Call-ID header.

Example
// Source: tests/regression/src/stress_tests.cpp:L98
ASSERT_EQ(callId, sipm.getCallIDView());

getContentType()

std::string siddiqsoft::sipmessage::getContentType() const;

Returns Content-Type header string.

Returns

std::string — Content-Type string (e.g. "application/sdp"). Empty if absent.

Example
// Source: tests/regression/src/stress_tests.cpp:L50
sipm.setHeader(siddiqsoft::HF_CONTENT_TYPE, "application/sdp");
EXPECT_EQ("application/sdp", sipm.getContentType());

getContentTypeView()

std::string_view siddiqsoft::sipmessage::getContentTypeView() const;

Returns zero-copy view of Content-Type header.

Returns

std::string_view — Non-allocating view of Content-Type header.

Example
// Source: tests/regression/src/stress_tests.cpp:L50
std::string_view ct = sipm.getContentTypeView();
EXPECT_EQ("application/sdp", ct);

getContentLength()

uint32_t siddiqsoft::sipmessage::getContentLength() const;

Parses and returns Content-Length as integer.

Returns

uint32_t — Content length in bytes. Defaults to 0 if absent.

Example
// Source: tests/regression/src/stress_tests.cpp:L51
EXPECT_EQ(0u, sipm.getContentLength());

getExpires()

uint32_t siddiqsoft::sipmessage::getExpires() const;

Parses and returns Expires header as integer.

Returns

uint32_t — Expiration period in seconds.

Example
// Source: tests/regression/src/test.cpp
sipm.setHeader(siddiqsoft::HF_EXPIRES, 3600);
EXPECT_EQ(3600u, sipm.getExpires());

Body & SDP Operations

body()

auto& siddiqsoft::sipmessage::body();

Provides direct reference to the /b body JSON object.

Returns

auto& (nlohmann::json&) — Mutable reference to body container.

Example
// Source: tests/regression/src/stress_tests.cpp:L208
ASSERT_TRUE(sipm.contains("/b/sdp"_json_pointer));
auto& b = sipm.body();
EXPECT_TRUE(b.contains("sdp"));

hasBody()

bool siddiqsoft::sipmessage::hasBody() const;

Returns true if message body contains data.

Returns

booltrue if /b exists and is non-empty; false otherwise.

Example
// Source: tests/regression/src/stress_tests.cpp:L208
EXPECT_TRUE(sipm.hasBody());

getBodyElement()

template <typename T> T siddiqsoft::sipmessage::getBodyElement(
    const nlohmann::json::json_pointer& jp,
    const T& defaultValue
) const;

Queries property within body JSON tree via RFC 6901 JSON pointer.

Parameters
const nlohmann::json::json_pointer& jp JSON Pointer path (e.g. `"/sdp/0/c/dn"_json_pointer`).
const T& defaultValue Fallback value returned if pointer is unresolved.
Returns

T — Extracted value converted to type T, or defaultValue if path does not exist.

Example
// Source: tests/regression/src/synthetics.cpp:L84
auto elem = sipm.getBodyElement<std::string>("/sdp/0/c/dn"_json_pointer, "0.0.0.0");
EXPECT_EQ("10.0.0.1", elem);

setBody()

template <typename T> sipmessage& siddiqsoft::sipmessage::setBody(
    const nlohmann::json::json_pointer& jp,
    const T& v
);

Sets value at specified JSON pointer path within the body object.

Parameters
const nlohmann::json::json_pointer& jp JSON Pointer path in body.
const T& v Value to assign.
Returns

sipmessage& — Reference to *this enabling method chaining.

Example
// Source: tests/regression/src/synthetics.cpp:L95
sipm.setBody("/sdp/0/c/dn"_json_pointer, "10.0.0.1");
EXPECT_EQ("10.0.0.1", sipm.getBodyElement<std::string>("/sdp/0/c/dn"_json_pointer, ""));