siddiqsoft::sipmessage Class Reference¶
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
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¶
auto | getMethod () const Returns the SIP request method string. |
std::string_view | getMethodView () const Returns zero-copy view of request method string from internal JSON storage. |
auto | getUri () const Returns the SIP request URI string. |
std::string_view | getUriView () const Returns zero-copy view of request URI string from internal JSON storage. |
auto | getStatusCode () const Returns numeric response status code. |
auto | getReason () const Returns response reason phrase string. |
std::string_view | getReasonView () const Returns zero-copy view of response reason phrase. |
bool | isMessageRequest () const Returns true if message represents a SIP request. |
bool | isMessageResponse () const Returns true if message represents a SIP response. |
Header Management¶
auto& | headers () Provides direct reference to the /h headers JSON object. |
auto | getHeader (
const std::string& key,
std::optional<T> defaultValue = {}
) constRetrieves 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. |
auto | getCallID () const Returns the Call-ID header value. |
std::string_view | getCallIDView () const Returns zero-copy view of Call-ID header. |
std::string | getContentType () const Returns Content-Type header string. |
std::string_view | getContentTypeView () const Returns zero-copy view of Content-Type header. |
uint32_t | getContentLength () const Parses and returns Content-Length as integer. |
uint32_t | getExpires () const Parses and returns Expires header as integer. |
Body & SDP Management¶
auto& | body () Provides direct reference to the /b body JSON object. |
bool | hasBody () const Returns true if message body contains data. |
T | getBodyElement (
const nlohmann::json::json_pointer& jp,
const T& defaultValue
) constQueries 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 durationttx).
Member Function Documentation¶
Constructors¶
sipmessage()¶
Default constructor initializing an empty SIP message with standard metadata (version, timestamp, TTX counter).
sipmessage — An initialized empty SIP message instance.
// 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)¶
Constructs a SIP request message with method, request URI, Call-ID, and CSeq.
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. |
sipmessage — A populated SIP request message instance.
// 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)¶
Constructs a SIP response message with numeric status code and standard reason phrase.
uint32_t |
statusCode | Standard SIP status code (e.g. `200`, `404`, `503`). |
sipmessage — A populated SIP response message instance.
sipmessage(json)¶
Initializes sipmessage from an existing JSON document conforming to sip2json schema.
const nlohmann::json& |
src | Source JSON object conforming to sip2json schema. |
sipmessage — A deserialized message instance wrapping the JSON payload.
// 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()¶
Returns a copy of the SIP request method string.
auto (std::string) — Method string (e.g., "INVITE", "REGISTER"). Empty string if response.
getMethodView()¶
Returns zero-copy view of request method string from internal JSON storage.
std::string_view — Non-allocating view into internal JSON. Lifetime tied to parent sipmessage.
getUri()¶
getUriView()¶
getStatusCode()¶
getReason()¶
getReasonView()¶
isMessageRequest()¶
isMessageResponse()¶
Header Operations¶
headers()¶
Provides direct reference to the /h headers JSON object.
auto& (nlohmann::json&) — Mutable reference to the internal headers dictionary.
getHeader()¶
Retrieves header value matching key, converting to type T.
const std::string& |
key | Header name (case-insensitive via canonical mapping). |
std::optional<T> |
defaultValue | Optional fallback value returned if key is absent. |
auto (T) — Header value converted to type T. Returns defaultValue if header is not present.
setHeader()¶
Sets or updates header key-value pair. Returns *this for method chaining.
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). |
sipmessage& — Reference to *this enabling method chaining.
getCallID()¶
getCallIDView()¶
getContentType()¶
getContentTypeView()¶
getContentLength()¶
getExpires()¶
Body & SDP Operations¶
body()¶
hasBody()¶
getBodyElement()¶
Queries property within body JSON tree via RFC 6901 JSON pointer.
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. |
T — Extracted value converted to type T, or defaultValue if path does not exist.
setBody()¶
Sets value at specified JSON pointer path within the body object.
const nlohmann::json::json_pointer& |
jp | JSON Pointer path in body. |
const T& |
v | Value to assign. |
sipmessage& — Reference to *this enabling method chaining.