diff --git a/AGENTS.md b/AGENTS.md index fc71418..ebf34e2 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -44,7 +44,7 @@ PipeWire. The verified device/carrier combinations are in the README. | `interfaces/Imsd-Sms.cppm` | `imsd::sms` — the short message codecs SMS over IP rides on (TS 24.341 carries the bytes a 2G/3G phone puts in an RP-DATA, in a SIP MESSAGE body): the GSM 7-bit default alphabet with its extension table and the septet packing, UCS-2 (TS 23.038); the SM-TL PDUs (TS 23.040: SMS-SUBMIT built, one per segment with the concatenation header when the text needs more than one; SMS-DELIVER, SMS-STATUS-REPORT and SMS-SUBMIT-REPORT parsed; the SMS-DELIVER-REPORT that acknowledges a delivery; the user-data header — concatenation, application ports — and the `Reassembler` of a concatenated message); the SM-RL messages (TS 24.011: RP-DATA, RP-ACK, RP-ERROR in both directions, the cause values); EF_SMSP (TS 31.102 §4.2.27), where the (U)SIM names the service centre, and qmicli's hex dump of it. Byte-level only: no SIP, no clock, no I/O. | | `interfaces/Imsd-Aka.cppm` | `imsd::aka` — USIM AKA glue: the AKAv1-MD5 digest (RFC 3310), IMPI/IMPU/realm from IMSI + MCC/MNC, parsers for `qmicli --uim-get-card-status` and `mmcli` output, the AUTHENTICATE APDU and its response. | | `interfaces/Imsd-Ipsec.cppm` | `imsd::ipsec` — the two ESP SA pairs (TS 33.203) as `ip xfrm` argv lists, the Security-Server mechanism selection, and the reader that reconstructs SPIs/ports from `ip xfrm state`/`policy` text for a warm resume, and (1.0.0) `SaPeer`, the P-CSCF the kernel's pair is to, read from the `dir out` policies that carry imsd's fingerprint, `OwnXfrmDeleteCommands`, the deletes by exact key of what two rules select — the policies carrying imsd's fingerprint and the reqid-1/2 transport-mode ESP states in their direction or on the UE's ims-PDN address, whoever installed them (§12), and `FileNamesAnotherPair`, whether a state file's `spi_uc`/`spi_us` name the kernel's pair (unknown on either side decides nothing). | -| `interfaces/Imsd-Messages.cppm` | `imsd::msg` — every SIP request and response imsd sends, built from an explicit `Context` and per-request variables so the builders are pure functions; byte-pinned by `tests/Messages`. Also `IsEmergency`. | +| `interfaces/Imsd-Messages.cppm` | `imsd::msg` — every SIP request and response imsd sends, built from an explicit `Context` and per-request variables so the builders are pure functions; `tests/Messages` is their suite, which calls every builder but `BuildInviteResponse` (`tests/Engine` checks the responses `CallMachine` builds with it). Also `IsEmergency`. Since 1.2.0 the SIP MESSAGE of SMS over IP (`BuildMessageSms`: an RP-DATA to the service centre's PSI, or an RP-ACK/RP-ERROR to the IP-SM-GW with In-Reply-To — TS 24.341 5.3.1.2 and 5.3.2.4), the `+g.3gpp.smsip` Contact tag behind `Context::smsOverIp`, `BuildResponse`, a final for an inbound request outside a call — each `Via:` line echoed in order (the text layer reads long header names only, not RFC 3261 7.3.3's compact forms) and the To echoed with a tag added unless it already holds `tag=` (RFC 3261 8.2.6.2); the 488 and a 200 pinned — and `ScPsi`, the service centre's PSI from its international number, never a dialled-number guess. | | `interfaces/Imsd-Engine.cppm` | `imsd::engine` — the decisions as pure reducers: `CallMachine` (one call's dialog, returning `Action`s for the shell) and `RegRecovery` (the registration recovery policy, §7.4). | | `interfaces/Imsd-Qmi.cppm` | `imsd::qmi` — the QMI WDS request bytes `imsd-pcscf` sends (Bind Mux Data Port, Set IP Family, Get Packet Service Status, Get Current Settings, Get Profile Settings), the message/TLV parser, the P-CSCF list readers (0x22 flag, 0x23 IPv4, 0x24 FQDN, 0x2E IPv6 — the last one libqmi does not model). | | `interfaces/ImsdBus.cppm` | `imsd::bus` — the polkit gate in front of call control, shared by imsd and imsd-ofonod. GLib, so outside `imsd-core`. | @@ -277,8 +277,14 @@ What the suites pin: that disagrees with a length, short and overrunning buffers, the packet-service-status and profile PCSCF-via-PCO readers (present and absent TLVs) and the error names (OutOfCall, NoEffect, an unknown code as `?`). -- `Messages` — every outgoing SIP message byte-for-byte, cross-generated from - the Python reference stack imsd replaced. +- `Messages` — the outgoing SIP messages: the initial and the protected + REGISTER, the reg-event SUBSCRIBE and the INVITEs byte-for-byte, their + variants, the in-dialog requests, the ACKs, the CANCEL and + `BuildResponse200` by their lines, `BuildInviteResponse` not there + (`tests/Engine` checks the responses `CallMachine` builds with it); the + SMS over IP shapes (the + `+g.3gpp.smsip` tag, the MESSAGE with an RP-DATA, the delivery report + with In-Reply-To, a 488) pinned against TS 24.341's clauses. - `Sip` — the text layer's edge cases (empty header values, line anchoring, keepalive discards, a header read that stops at the first empty line — a body line spelling a header name picks nothing, leading empty lines are diff --git a/interfaces/Imsd-Messages.cppm b/interfaces/Imsd-Messages.cppm index dcb28de..145ae85 100644 --- a/interfaces/Imsd-Messages.cppm +++ b/interfaces/Imsd-Messages.cppm @@ -9,15 +9,20 @@ Every VoLTE message the daemon sends is assembled here from an explicit context and the per-request variables (tags, branches, CSeq) so the builders are pure functions with no hidden state: the engine owns the dialog bookkeeping and the transport owns the socket, this module only formats bytes. That makes -each message byte-pinnable — tests/Messages compares the output against strings -cross-generated from the Python reference stack, header for header. +each message byte-pinnable — tests/Messages compares a REGISTER pair and an INVITE +with strings cross-generated from the Python reference stack, header for header. Covers: the unprotected + protected REGISTER and the refresh re-REGISTER (sec-agree, Security-Client/Verify, AKAv1-MD5 Authorization); the INVITE with an AMR-WB SDP offer and IMS MMTEL feature tags; the in-dialog PRACK/BYE and 2xx/non-2xx ACK; CANCEL (reusing the INVITE branch); the 200 OK that echoes -an inbound request's dialog headers; and the UAS responses to an inbound -INVITE (100/180/200 and rejection finals). Pure std C++. +an inbound request's dialog headers; the finals of the inbound MESSAGE +path, each `Via:` line echoed and the To tagged unless it holds `tag=` +(RFC 3261 8.2.6.2; long header names only); the UAS responses to an +inbound INVITE (100/180/200 +and rejection finals); and the SIP MESSAGE that carries a short message's +RP-DATA to the service centre, or its RP-ACK/RP-ERROR back to the IP-SM-GW +(TS 24.341). Pure std C++. */ export module Imsd:Messages; @@ -70,6 +75,13 @@ export namespace imsd::msg { // never fabricate one: the network reads it to learn which access // the UE is reachable on (stock sends it in every REGISTER/INVITE). std::string panInfo; + // Advertise SMS over IP in the REGISTER Contact (+g.3gpp.smsip, TS + // 24.341 5.3.2.2): the network then delivers terminating short + // messages and submit reports to imsd as SIP MESSAGEs (a network that + // also has a NAS SMS path chooses by operator policy, 5.3.3.4.2 NOTE + // 2). Off unless the shell has SMS over IP handling to offer and turns + // it on from its configuration. + bool smsOverIp = false; }; // A Via line: "Via: SIP/2.0/ [local]:;branch=z9hG4bK;rport". @@ -124,12 +136,13 @@ export namespace imsd::msg { // matching compares the value as a string, so the encoding must match // what the network selects on — the stock modem sends exactly // urn%3Aurn-7%3A..., diag capture 2026-07-18). +sip.instance carries the - // IMEI URN when known. Deliberately NOT +g.3gpp.smsip: it routes - // terminating SMS over IMS to a stack with no SMSoIP handling yet, - // silently losing texts — and exact tag parity including smsip + - // nw-init-ussi was tested live (2026-07-20, stored binding echo-verified) - // and did NOT change terminating access-domain selection, so the tags - // buy nothing. + // IMEI URN when known. +g.3gpp.smsip only when the shell asks + // (Context::smsOverIp): it routes terminating SMS over IMS to imsd, + // which loses texts unless the daemon handles them — and exact tag + // parity including smsip + nw-init-ussi was tested live (2026-07-20, + // stored binding echo-verified) and did NOT change terminating + // access-domain selection for calls, so for calls the tags buy nothing. + // The tag follows the ICSI. // The binding user-part every Contact we emit carries (see // Context::contactUser). inline std::string_view ContactUser(const Context& c) { @@ -141,6 +154,7 @@ export namespace imsd::msg { std::string s; if (!c.instanceId.empty()) s += std::format(";+sip.instance=\"<{}>\"", c.instanceId); s += ";+g.3gpp.icsi-ref=\"urn%3Aurn-7%3A3gpp-service.ims.icsi.mmtel\""; + if (c.smsOverIp) s += ";+g.3gpp.smsip"; return s; } @@ -178,6 +192,19 @@ export namespace imsd::msg { return std::format("sip:{};phone-context={}@{};user=phone", t, domain, domain); } + // The service centre's PSI a submission is addressed to (TS 24.341 + // 5.3.1.2 NOTE 1: the SC's E.164 number as a SIP URI with user=phone, + // or a tel URI; the home domain as its host is imsd's choice). Only an + // international number makes one — RuriFor's + // dialled-number guess (a trunk 0 is Dutch) has no place here; a + // service centre in another form is nullopt, and the caller says so. + inline std::optional ScPsi(std::string_view e164, std::string_view domain) { + if (e164.size() < 2 || e164[0] != '+') return std::nullopt; + for (char ch : e164.substr(1)) + if (ch < '0' || ch > '9') return std::nullopt; + return std::format("sip:{}@{};user=phone", e164, domain); + } + namespace detail { inline std::string Join(std::span lines) { std::string s; @@ -495,6 +522,28 @@ export namespace imsd::msg { return std::format("{}\r\n", detail::Join(l)); } + // The final for an inbound MESSAGE outside a call's dialog — the 200 to one we took, the 488 to + // one we did not: each `Via:` line echoed in order (the response + // travels the proxy chain back, RFC 3261 8.2.6.2; long header names only, + // not the compact forms), From, To with + // `toTag` added unless the request's To holds `tag=` (8.2.6.2 again), + // Call-ID and CSeq; no body. The shell's answers to any other request + // outside a call but an INVITE (an OPTIONS, a NOTIFY, a method it does + // not handle) keep BuildResponse200's hop-by-hop shape, as before. + std::string BuildResponse(const Context&, std::string_view request, int code, std::string_view text, std::string_view toTag) { + std::vector l = {std::format("SIP/2.0 {} {}", code, text)}; + for (auto v : imsd::sip::Headers(request, "Via")) l.push_back(std::format("Via: {}", v)); + if (auto f = imsd::sip::Header(request, "From")) l.push_back(std::format("From: {}", *f)); + if (auto t = imsd::sip::Header(request, "To")) { + if (t->contains("tag=")) l.push_back(std::format("To: {}", *t)); + else l.push_back(std::format("To: {};tag={}", *t, toTag)); + } + if (auto ci = imsd::sip::Header(request, "Call-ID")) l.push_back(std::format("Call-ID: {}", *ci)); + if (auto cs = imsd::sip::Header(request, "CSeq")) l.push_back(std::format("CSeq: {}", *cs)); + l.push_back("Content-Length: 0"); + return std::format("{}\r\n", detail::Join(l)); + } + // A 200 OK for an inbound request: echo Via/From/To/Call-ID/CSeq in order, // then either an SDP answer (with our Contact) or an empty body. // `extra` appends headers (Session-Expires echo for refreshes...). @@ -514,4 +563,42 @@ export namespace imsd::msg { l.push_back("Content-Length: 0"); return std::format("{}\r\n", detail::Join(l)); } + + // ---- SMS over IP ---------------------------------------------------- + + constexpr std::string_view SmsContentType = "application/vnd.3gpp.sms"; + + // A SIP MESSAGE carrying an SM-RL message (TS 24.011) as its body — the + // RP-DATA of a submission to the service centre's PSI (TS 24.341 + // 5.3.1.2: `target` is the Request-URI and the To — `ScPsi`), + // or the RP-ACK/RP-ERROR of a delivery report to the IP-SM-GW (5.3.2.4: + // `target` is the IP-SM-GW, `inReplyTo` the delivered MESSAGE's + // Call-ID). Out of dialog: a Call-ID of its own, CSeq 1, + // the registration's Route, our public identity in From, and no Contact + // (RFC 3428 §4). The same P-Preferred-Identity, P-Access-Network-Info + // and sec-agree headers as the INVITE and the reg-event SUBSCRIBE. + std::string BuildMessageSms(const Context& c, std::string_view target, std::string_view callid, std::string_view ftag, std::string_view branch, std::span rp, std::string_view inReplyTo = {}) { + std::vector l = { + std::format("MESSAGE {} SIP/2.0", target), + ViaLine(c, c.transport, c.portUs, branch), + "Max-Forwards: 70", + std::format("Route: {}", c.route), + std::format("From: <{}>;tag={}", CallerId(c), ftag), + std::format("To: <{}>", target), + std::format("Call-ID: {}", callid), + "CSeq: 1 MESSAGE", + }; + if (!inReplyTo.empty()) l.push_back(std::format("In-Reply-To: {}", inReplyTo)); + if (!c.ppi.empty()) l.push_back(std::format("P-Preferred-Identity: <{}>", c.ppi)); + if (!c.panInfo.empty()) l.push_back(std::format("P-Access-Network-Info: {}", c.panInfo)); + l.push_back(std::format("Security-Verify: {}", c.securityServer)); + l.push_back("Proxy-Require: sec-agree"); + l.push_back("Require: sec-agree"); + l.push_back(std::format("Content-Type: {}", SmsContentType)); + l.push_back(std::format("Content-Length: {}", rp.size())); + l.push_back(""); + std::string out = detail::Join(l); + out.append(reinterpret_cast(rp.data()), rp.size()); // lint-disable-line no-char-pointer + return out; + } } diff --git a/tests/Messages/main.cpp b/tests/Messages/main.cpp index 041ab0a..63c5bdc 100644 --- a/tests/Messages/main.cpp +++ b/tests/Messages/main.cpp @@ -2,9 +2,11 @@ // SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts® // lint-disable-file fixed-width-types -// Imsd:Messages unit tests — every builder compared byte-for-byte against a -// reference message cross-generated from the Python VoLTE stack with pinned -// tags/branches/SPIs. A divergence here is a wire-format change, i.e. a +// Imsd:Messages unit tests — the initial and the protected REGISTER and the INVITE +// compared byte-for-byte against a reference message cross-generated from the +// Python VoLTE stack with pinned tags/branches/SPIs; their variants and the other +// builders against a message written here or by their lines (BuildInviteResponse +// is not called). A divergence here is a wire-format change, i.e. a // registration or call that the commercial IMS core may reject; these are the // hardest pins in the project. Two deliberate post-parity divergences: // the REGISTER Contact carries +sip.instance and the MMTEL ICSI feature tag @@ -14,7 +16,11 @@ // TS 24.229 coding and what the stock modem sends on the wire; the Python // stack's plain-colon form is a different string under RFC 3841 matching // and left terminating access-domain selection routing incoming calls to -// CS fallback (observed live 2026-07-20). +// CS fallback (observed live 2026-07-20). Then the SMS over IP shapes: the +// +g.3gpp.smsip Contact tag behind Context::smsOverIp, the MESSAGE carrying +// an RP-DATA to the service centre and the one carrying an RP-ACK to the +// IP-SM-GW with In-Reply-To (TS 24.341 5.3.1.2, 5.3.2.4), and a final other +// than 200 for an inbound request. import std; import Imsd; @@ -226,6 +232,9 @@ int main() { Eq(RuriFor("+31612345678", c.id.domain), "sip:+31612345678@ims.mnc001.mcc001.3gppnetwork.org;user=phone", "ruri E.164"); Eq(RuriFor("0612345678", c.id.domain), "sip:+31612345678@ims.mnc001.mcc001.3gppnetwork.org;user=phone", "ruri Dutch national"); Eq(RuriFor("0031612345678", c.id.domain), "sip:+31612345678@ims.mnc001.mcc001.3gppnetwork.org;user=phone", "ruri 00 intl"); + // ---- ScPsi: the service centre's PSI is its international number, never a dialled-number guess + Eq(ScPsi("+31653131313", c.id.domain).value_or(""), "sip:+31653131313@ims.mnc001.mcc001.3gppnetwork.org;user=phone", "the service centre's PSI"); + Check(!ScPsi("0653131313", c.id.domain) && !ScPsi("0032475161616", c.id.domain) && !ScPsi("+", c.id.domain) && !ScPsi("+31 65", c.id.domain) && !ScPsi("+31653131313#", c.id.domain) && !ScPsi("+31*65", c.id.domain), "a national, a 00-prefixed, an empty or a spaced number, or a * or # in it, makes no PSI"); // ---- SUBSCRIBE (reg event, RFC 3680) — no Python counterpart; pinned // against the shape of the other protected in-flow requests @@ -416,6 +425,93 @@ int main() { Check(!BuildRegisterInitial(c, "cid@h", "ft", "br", 1, 2) .contains("User-Agent:"), "empty userAgent omits the header"); } + // ---- SMS over IP: the Contact tag, the MESSAGE both ways, a 488 + { + Context cs = MakeCtx(); + cs.smsOverIp = true; + std::string r1 = BuildRegisterInitial(cs, "REGCALLID@2001:db8::db43", "FTAG5678", "REGBRANCH123456", 7449812u, 176466735u); + Check(r1.contains("\r\nContact: ;+sip.instance=\"\";+g.3gpp.icsi-ref=\"urn%3Aurn-7%3A3gpp-service.ims.icsi.mmtel\";+g.3gpp.smsip;expires=600000\r\n"), "smsOverIp: +g.3gpp.smsip after the ICSI in the REGISTER Contact"); + Check(!Reg1.contains("smsip") && !BuildRegisterInitial(c, "REGCALLID@2001:db8::db43", "FTAG5678", "REGBRANCH123456", 7449812u, 176466735u).contains("smsip"), "the tag is off by default"); + Check(!BuildInvite(cs, Dialog{RuriFor("1233", cs.id.domain), "CID@x", "it", "ib"}, "v=0\r\n", false).contains("smsip"), "the INVITE Contact never carries it"); + + auto rp = imsd::util::FromHex("002a0007911356131313f31711000b916407281553f80000aa0ae8329bfd4697d9ec37"); + Check(rp && rp->size() == 35, "the RP-DATA fixture"); + std::string msg = BuildMessageSms(c, RuriFor("+31653131313", c.id.domain), "MSGCALLID@2001:db8::db43", "MTAG1234", "MSGBRANCH0000000000", *rp); + const std::string wantHead = + "MESSAGE sip:+31653131313@ims.mnc001.mcc001.3gppnetwork.org;user=phone SIP/2.0\r\n" + "Via: SIP/2.0/TCP [2001:db8::db43]:45062;branch=z9hG4bKMSGBRANCH0000000000;rport\r\n" + "Max-Forwards: 70\r\n" + "Route: \r\n" + "From: ;tag=MTAG1234\r\n" + "To: \r\n" + "Call-ID: MSGCALLID@2001:db8::db43\r\n" + "CSeq: 1 MESSAGE\r\n" + "P-Preferred-Identity: \r\n" + "P-Access-Network-Info: 3GPP-E-UTRAN-FDD;utran-cell-id-3gpp=0010112340ABCDE0\r\n" + "Security-Verify: ipsec-3gpp; q=0.1; alg=hmac-sha-1-96; ealg=aes-cbc; spi-c=86438593; spi-s=86438592; port-c=33421; port-s=6000\r\n" + "Proxy-Require: sec-agree\r\n" + "Require: sec-agree\r\n" + "Content-Type: application/vnd.3gpp.sms\r\n" + "Content-Length: 35\r\n" + "\r\n"; + Eq(msg.substr(0, wantHead.size()), wantHead, "MESSAGE with an RP-DATA to the service centre"); + Check(msg.size() == wantHead.size() + 35 && std::equal(rp->begin(), rp->end(), msg.begin() + static_cast(wantHead.size()), [](std::uint8_t b, char ch) { return b == static_cast(ch); }), "the RP-DATA bytes follow the headers verbatim"); + Check(!msg.contains("Contact:"), "no Contact in a MESSAGE (RFC 3428)"); + + std::vector ack = {0x02, 0x11, 0x41, 0x02, 0x00, 0x00}; + std::string rep = BuildMessageSms(c, "sip:ipsmgw.ims.mnc001.mcc001.3gppnetwork.org", "RPTCALLID@2001:db8::db43", "RTAG", "RBRANCH", ack, "abc123@ipsmgw"); + const std::string wantRep = + "MESSAGE sip:ipsmgw.ims.mnc001.mcc001.3gppnetwork.org SIP/2.0\r\n" + "Via: SIP/2.0/TCP [2001:db8::db43]:45062;branch=z9hG4bKRBRANCH;rport\r\n" + "Max-Forwards: 70\r\n" + "Route: \r\n" + "From: ;tag=RTAG\r\n" + "To: \r\n" + "Call-ID: RPTCALLID@2001:db8::db43\r\n" + "CSeq: 1 MESSAGE\r\n" + "In-Reply-To: abc123@ipsmgw\r\n" + "P-Preferred-Identity: \r\n" + "P-Access-Network-Info: 3GPP-E-UTRAN-FDD;utran-cell-id-3gpp=0010112340ABCDE0\r\n" + "Security-Verify: ipsec-3gpp; q=0.1; alg=hmac-sha-1-96; ealg=aes-cbc; spi-c=86438593; spi-s=86438592; port-c=33421; port-s=6000\r\n" + "Proxy-Require: sec-agree\r\n" + "Require: sec-agree\r\n" + "Content-Type: application/vnd.3gpp.sms\r\n" + "Content-Length: 6\r\n" + "\r\n"; + Eq(rep.substr(0, wantRep.size()), wantRep, "delivery report: the MESSAGE to the IP-SM-GW, In-Reply-To after the CSeq, the header block whole"); + Check(rep.size() == wantRep.size() + ack.size() && std::equal(ack.begin(), ack.end(), rep.begin() + static_cast(wantRep.size()), [](std::uint8_t b, char ch) { return b == static_cast(ch); }), "delivery report: the RP-ACK bytes follow the headers verbatim"); + Check(!rep.contains("Contact:"), "no Contact in a delivery report either"); + + const std::string inbound = + "MESSAGE sip:me@[2001:db8::db43]:45062 SIP/2.0\r\n" + "Via: SIP/2.0/UDP [2001:db8::105]:6000;branch=z9hG4bKnet1\r\n" + "Via: SIP/2.0/UDP [2001:db8::77]:5060;branch=z9hG4bKgw0\r\n" + "From: ;tag=N1\r\n" + "To: \r\n" + "Call-ID: in1@net\r\n" + "CSeq: 9 MESSAGE\r\n" + "Content-Length: 0\r\n\r\n"; + Eq(BuildResponse(c, inbound, 488, "Not Acceptable Here", "T488"), + "SIP/2.0 488 Not Acceptable Here\r\n" + "Via: SIP/2.0/UDP [2001:db8::105]:6000;branch=z9hG4bKnet1\r\n" + "Via: SIP/2.0/UDP [2001:db8::77]:5060;branch=z9hG4bKgw0\r\n" + "From: ;tag=N1\r\n" + "To: ;tag=T488\r\n" + "Call-ID: in1@net\r\n" + "CSeq: 9 MESSAGE\r\n" + "Content-Length: 0\r\n\r\n", "a 488 for an inbound MESSAGE echoes every Via and tags To"); + const std::string tagged = "MESSAGE sip:me@ims SIP/2.0\r\nVia: SIP/2.0/UDP [2001:db8::105]:6000;branch=z9hG4bKnet2\r\nFrom: ;tag=N2\r\nTo: ;tag=had\r\nCall-ID: in2@net\r\nCSeq: 1 MESSAGE\r\nContent-Length: 0\r\n\r\n"; + Check(BuildResponse(c, tagged, 200, "OK", "unused").contains("\r\nTo: ;tag=had\r\n"), "a To that already carries a tag is echoed as it is"); + { + const std::string body = "hi\r\nVia: SIP/2.0/UDP 192.0.2.66;branch=z9hG4bKx"; + const std::string tail = "Content-Length: 0\r\n\r\n"; + std::string bodied = inbound; + bodied.replace(bodied.size() - tail.size(), tail.size(), std::format("Content-Type: text/plain\r\nContent-Length: {}\r\n\r\n{}", body.size(), body)); + const std::string r = BuildResponse(c, bodied, 200, "OK", "T200"); + Check(imsd::sip::Headers(r, "Via").size() == 2 && !r.contains("192.0.2.66"), "a body line that starts with Via: is no Via: the final echoes the header section's two only"); + } + } + if (Failures == 0) std::println("Messages: all tests passed"); return Failures; }