engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200
TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
This commit is contained in:
parent
710f884575
commit
ef04b473a7
4 changed files with 203 additions and 94 deletions
52
AGENTS.md
52
AGENTS.md
|
|
@ -47,7 +47,7 @@ PipeWire. The verified device/carrier combinations are in the README.
|
||||||
| `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-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-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; `tests/Messages` is their suite. 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`, the final for an inbound MESSAGE outside a call's dialog (the 200, the 480, the 488): each Via row echoed in order and the To echoed with a tag added unless it already holds `tag=` (RFC 3261 8.2.6.2); since 1.2.1 `BuildBadRequest`, the 400 to a request cut short of the Content-Length read from it — any but an ACK or a CANCEL, in a call's dialog or not —, in that shape, a To tag it adds made from the request's header section and a secret of the run (RFC 3261 8.2.7); of requests that came whole, in-dialog requests, a MESSAGE among them, and the shell's answers to any other request outside a call — a NOTIFY, an OPTIONS, a method it does not handle; not an INVITE, whose 486 while a call exists is `BuildInviteResponse`'s — keep `BuildResponse200`'s hop-by-hop shape; and `ScPsi`, the service centre's PSI from its international number — never a dialled-number guess. |
|
| `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. 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`, the final for an inbound MESSAGE outside a call's dialog (the 200, the 480, the 488): each Via row echoed in order and the To echoed with a tag added unless it already holds `tag=` (RFC 3261 8.2.6.2); since 1.2.1 `BuildBadRequest`, the 400 to a request cut short of the Content-Length read from it — any but an ACK or a CANCEL, in a call's dialog or not —, in that shape, a To tag it adds made from the request's header section and a secret of the run (RFC 3261 8.2.7); of requests that came whole, in-dialog requests, a MESSAGE among them, and the shell's answers to any other request outside a call — a NOTIFY, an OPTIONS, a method it does not handle; not an INVITE, whose 486 while a call exists is `BuildInviteResponse`'s — keep `BuildResponse200`'s hop-by-hop shape; 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), `RegRecovery` (the registration recovery policy, §7.4) and, since 1.2.0, SMS over IP (§7.9): `SmsOutbound` (one short message of ours on its way to the service centre, segment by segment, returning `SmsAction`s) and `OnSmsMessage` (what an inbound MESSAGE outside a call's dialog leads to: its final, the message or status report it delivered, the delivery report to send), and `RecentTransactions` (an inbound request's retransmission — the same Call-ID, CSeq and Via branch within 32 s (`TimerJ`), the branch being the value of the first `branch=` of its first Via row and a request with none or an empty one never matched — answered with the same final and not handled again); `SameRecipient` and `StatusReportBook`, a status report's match to the message that asked for one — TP-MR and recipient — and its word for the whole message, with `SmsWordOrder`, the order of a message's words: the submission's first, a report's held until then (§7.9); `RunToken`, `SentSmsId` and `ReceivedSmsId`, the ids (§8.4); `StoredSms` with `FormatStoredSms`/`ParseStoredSms`, the record codec of the received-message store, and `StoredSmsBefore`, `List`'s order. |
|
| `interfaces/Imsd-Engine.cppm` | `imsd::engine` — the decisions as pure reducers: `CallMachine` (one call's dialog, returning `Action`s for the shell), `RegRecovery` (the registration recovery policy, §7.4) and, since 1.2.0, SMS over IP (§7.9): `SmsOutbound` (one short message of ours on its way to the service centre, segment by segment, returning `SmsAction`s) and `OnSmsMessage` (what an inbound MESSAGE outside a call's dialog leads to: its final, the message or status report it delivered, the delivery report to send), and `RecentTransactions` (an inbound request's retransmission — the same Call-ID, CSeq and Via branch within 32 s (`TimerJ`), the branch being the value of the first `branch=` of its first Via row and a request with none or an empty one never matched — answered with the same final and not handled again) and, since 1.2.1, `RecentSubmissions` (the Call-IDs of the MESSAGEs our submissions went out in, an hour each, by which a submit report for one that is no longer in flight is known for ours — TS 24.341 5.3.1.2); `SameRecipient` and `StatusReportBook`, a status report's match to the message that asked for one — TP-MR and recipient — and its word for the whole message, with `SmsWordOrder`, the order of a message's words: the submission's first, a report's held until then (§7.9); `RunToken`, `SentSmsId` and `ReceivedSmsId`, the ids (§8.4); `StoredSms` with `FormatStoredSms`/`ParseStoredSms`, the record codec of the received-message store, and `StoredSmsBefore`, `List`'s order. |
|
||||||
| `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/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 and messaging (`Gated`'s `Action` parameter names the action), shared by imsd and imsd-ofonod. GLib, so outside `imsd-core`. |
|
| `interfaces/ImsdBus.cppm` | `imsd::bus` — the polkit gate in front of call control and messaging (`Gated`'s `Action` parameter names the action), shared by imsd and imsd-ofonod. GLib, so outside `imsd-core`. |
|
||||||
| `implementations/main.cpp` | The `imsd` daemon shell: GLib main loop, GDBus service, sockets, subprocesses, the registration sequence and the run loop that pumps the core. |
|
| `implementations/main.cpp` | The `imsd` daemon shell: GLib main loop, GDBus service, sockets, subprocesses, the registration sequence and the run loop that pumps the core. |
|
||||||
|
|
@ -157,7 +157,7 @@ judgement of the final's wait and of the report's after the server ports' drain,
|
||||||
failure attributed by Call-ID, and the forwarding of a status report's
|
failure attributed by Call-ID, and the forwarding of a status report's
|
||||||
word to the bus — the transactions themselves are `SmsOutbound` and
|
word to the bus — the transactions themselves are `SmsOutbound` and
|
||||||
`OnSmsMessage` (a submit report's routing to the message in flight, by
|
`OnSmsMessage` (a submit report's routing to the message in flight, by
|
||||||
In-Reply-To, else RP-MR, is theirs), and the report's match to the message
|
In-Reply-To, else RP-MR, and past that to a MESSAGE of ours on record, is theirs), and the report's match to the message
|
||||||
that asked for one `SameRecipient`
|
that asked for one `SameRecipient`
|
||||||
and `StatusReportBook`, all with tests. The received-message store (§7.9)
|
and `StatusReportBook`, all with tests. The received-message store (§7.9)
|
||||||
keeps in the shell, among others, the `link(2)` publish and its retry with the next id,
|
keeps in the shell, among others, the `link(2)` publish and its retry with the next id,
|
||||||
|
|
@ -378,10 +378,13 @@ What the suites pin:
|
||||||
centre — and `OnSmsMessage`: a delivered message to the bus and its
|
centre — and `OnSmsMessage`: a delivered message to the bus and its
|
||||||
RP-ACK to the IP-SM-GW with In-Reply-To, a concatenated pair handed over
|
RP-ACK to the IP-SM-GW with In-Reply-To, a concatenated pair handed over
|
||||||
once whole and each segment acknowledged, a status report, a submit
|
once whole and each segment acknowledged, a status report, a submit
|
||||||
report routed to the message in flight (by In-Reply-To, else RP-MR), 488
|
report routed to the message in flight (by In-Reply-To, else RP-MR), 200
|
||||||
for one In-Reply-To no MESSAGE of ours in flight (a stranger's; ours once
|
and the journal's line for one In-Reply-To a MESSAGE of ours no longer
|
||||||
ended; ours once its segment was superseded), 200 for one without
|
in flight (ours once ended, an RP-ERROR's cause in the line; ours once
|
||||||
In-Reply-To for no message, an unusable TPDU acknowledged with an
|
its segment was followed by the next), 488 for a stranger's, 200 for one
|
||||||
|
without In-Reply-To that no message in flight owns; `RecentSubmissions`: a Call-ID on
|
||||||
|
record for 3600 s, the first of a list that is ours, each segment's
|
||||||
|
MESSAGE put on record as it goes out; an unusable TPDU acknowledged with an
|
||||||
RP-ERROR, a body that is no RP message, a page-mode text 200'd and
|
RP-ERROR, a body that is no RP message, a page-mode text 200'd and
|
||||||
logged, a short message while SMS over IP is off refused with 480;
|
logged, a short message while SMS over IP is off refused with 480;
|
||||||
a delivered MESSAGE whose header names come in compact form — the 200 and
|
a delivered MESSAGE whose header names come in compact form — the 200 and
|
||||||
|
|
@ -656,8 +659,10 @@ Rules:
|
||||||
`r23-phone-journal-2026-10-17-precise-and-modem-sms`; whether KPN's SC
|
`r23-phone-journal-2026-10-17-precise-and-modem-sms`; whether KPN's SC
|
||||||
sends them over this path is unknown), 8-bit data (an MMS
|
sends them over this path is unknown), 8-bit data (an MMS
|
||||||
notification), a message while SMS over IP is off (the 480), a submit
|
notification), a message while SMS over IP is off (the 480), a submit
|
||||||
report In-Reply-To no MESSAGE of ours in flight (the 488) or one without
|
report In-Reply-To no MESSAGE of ours in flight (1.2.0's 488: since then
|
||||||
In-Reply-To for no message in flight (the 200), a page-mode MESSAGE, a body that is no RP message, a text
|
the 200 for one of ours on record and the 488 for one that names none,
|
||||||
|
each with a line of its own that no bench on hardware has written) or one without
|
||||||
|
In-Reply-To that no message in flight owns (the 200), a page-mode MESSAGE, a body that is no RP message, a text
|
||||||
past 255 segments, an EF_SMSP
|
past 255 segments, an EF_SMSP
|
||||||
record 1 that cannot be read or holds no service centre, or one whose
|
record 1 that cannot be read or holds no service centre, or one whose
|
||||||
service centre is not an international number, a
|
service centre is not an international number, a
|
||||||
|
|
@ -1264,8 +1269,8 @@ emptied, never unlinked. The recovery policy's waits and the holds are
|
||||||
measured on the boot clock (`CLOCK_BOOTTIME`), so a suspend counts; the
|
measured on the boot clock (`CLOCK_BOOTTIME`), so a suspend counts; the
|
||||||
keepalive refresh gate, the CRLF keepalive, the reg-event retry and
|
keepalive refresh gate, the CRLF keepalive, the reg-event retry and
|
||||||
renewal timers and the times SMS over IP measures (§7.9: its two waits,
|
renewal timers and the times SMS over IP measures (§7.9: its two waits,
|
||||||
the 30-minute age-out, the retransmission table's 32 s) run on the steady
|
the 30-minute age-out, the retransmission table's 32 s, the submissions
|
||||||
clock and count awake seconds only.
|
table's hour) run on the steady clock and count awake seconds only.
|
||||||
|
|
||||||
The **reg-event subscription** (RFC 3680; the network's own view of the
|
The **reg-event subscription** (RFC 3680; the network's own view of the
|
||||||
binding) is one live dialog per registration, subscribed anew ahead of the
|
binding) is one live dialog per registration, subscribed anew ahead of the
|
||||||
|
|
@ -1601,8 +1606,11 @@ Lines the operator (and the scripts) look for, all prefixed `imsd: `:
|
||||||
the delivered MESSAGE: no delivery report RP-ACK|RP-ERROR sent`;
|
the delivered MESSAGE: no delivery report RP-ACK|RP-ERROR sent`;
|
||||||
`status report from <sc>: TP-MR n to <number>: … (discharged
|
`status report from <sc>: TP-MR n to <number>: … (discharged
|
||||||
<time>)`, `sms: status report for TP-MR n to <number>: no message of ours on record`;
|
<time>)`, `sms: status report for TP-MR n to <number>: no message of ours on record`;
|
||||||
`submit report (RP-ACK|RP-ERROR) In-Reply-To …: no MESSAGE of ours in flight; 488`,
|
`submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer
|
||||||
`submit report (…, RP-MR n) for no message in flight; 200`; `RP-DATA from
|
in flight; 200` (for an RP-ERROR, `(RP-ERROR, RP cause N (…)[, TP-FCS
|
||||||
|
0xNN (…)])` in the brackets),
|
||||||
|
`submit report (RP-ACK|RP-ERROR) In-Reply-To …: no MESSAGE of ours on record; 488`,
|
||||||
|
`submit report (…, RP-MR n) that no message in flight owns; 200`; `RP-DATA from
|
||||||
… whose TPDU is unusable (…): RP-ERROR`; `MESSAGE from … (<content
|
… whose TPDU is unusable (…): RP-ERROR`; `MESSAGE from … (<content
|
||||||
type>, N bytes):` followed by the body for a MESSAGE outside a call's dialog whose `Content-Type`
|
type>, N bytes):` followed by the body for a MESSAGE outside a call's dialog whose `Content-Type`
|
||||||
does not contain `application/vnd.3gpp.sms`, letter case ignored
|
does not contain `application/vnd.3gpp.sms`, letter case ignored
|
||||||
|
|
@ -1876,11 +1884,21 @@ do that answers without state.
|
||||||
reference start at random per start. A TPDU that is unusable — a delivery or a
|
reference start at random per start. A TPDU that is unusable — a delivery or a
|
||||||
status report that does not parse, or one of the submit-report type — is
|
status report that does not parse, or one of the submit-report type — is
|
||||||
acknowledged the same way with an RP-ERROR (cause 96, TP-FCS "TPDU not supported"). A submit
|
acknowledged the same way with an RP-ERROR (cause 96, TP-FCS "TPDU not supported"). A submit
|
||||||
report In-Reply-To no MESSAGE of ours in flight is answered 488 — one that
|
report In-Reply-To a MESSAGE of ours that is no longer in flight — its
|
||||||
is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by
|
message has ended (its report's wait run out, judged by the shell; a
|
||||||
the shell; a failure; sent) or its segment was superseded by the next, which
|
failure; sent) or its segment was followed by the next — is answered 200
|
||||||
gets the same answer; one without In-Reply-To for no message in flight,
|
and logged with the message's id and, for an RP-ERROR, its cause, for an
|
||||||
200. The journal names a received message's sender, size and time,
|
hour after that MESSAGE went out (`RecentSubmissions`: 5.3.1.2's 200 for
|
||||||
|
a report on "a short message submitted by the SM-over-IP sender", whose
|
||||||
|
Call-ID its NOTE 3 has the sender store). The bus hears nothing of it:
|
||||||
|
`failed` is a message's last word (§8.4), so a text the service centre
|
||||||
|
took after its wait had run out stays `failed` there, and the journal's
|
||||||
|
line is the record of it. One In-Reply-To no MESSAGE of ours on record —
|
||||||
|
a stranger's, ours of more than an hour ago, ours of before a restart —
|
||||||
|
is answered 488, which for the last two departs from the clause: it has
|
||||||
|
a 200 for every short message the sender submitted, and its NOTE 3 sets
|
||||||
|
the stored Call-ID no term; one without In-Reply-To that no message in flight
|
||||||
|
owns, 200. The journal names a received message's sender, size and time,
|
||||||
not its text (§12 has the cases in which a text does reach it); the text
|
not its text (§12 has the cases in which a text does reach it); the text
|
||||||
is in the store (the store bullet above) until
|
is in the store (the store bullet above) until
|
||||||
an app deletes it — unless it was not stored (`NOT stored`, the
|
an app deletes it — unless it was not stored (`NOT stored`, the
|
||||||
|
|
|
||||||
|
|
@ -1676,6 +1676,7 @@ private:
|
||||||
std::string smsc_; // the service centre's number (empty: none known)
|
std::string smsc_; // the service centre's number (empty: none known)
|
||||||
std::vector<std::uint8_t> scAddress_; // the same as the RP-DATA's destination: [octets][toa][digits]
|
std::vector<std::uint8_t> scAddress_; // the same as the RP-DATA's destination: [octets][toa][digits]
|
||||||
std::optional<std::uint8_t> smsValidity_; // EF_SMSP's TP-Validity-Period
|
std::optional<std::uint8_t> smsValidity_; // EF_SMSP's TP-Validity-Period
|
||||||
|
imsd::engine::RecentSubmissions smsSubmitted_; // the Call-IDs of the MESSAGEs our submissions went out in, an hour each: a late submit report is answered 200, not 488
|
||||||
std::optional<imsd::engine::SmsOutbound> smsOut_; // the message in flight
|
std::optional<imsd::engine::SmsOutbound> smsOut_; // the message in flight
|
||||||
std::deque<std::pair<std::string, imsd::engine::SmsOutbound::Params>> smsPending_; // queued behind it
|
std::deque<std::pair<std::string, imsd::engine::SmsOutbound::Params>> smsPending_; // queued behind it
|
||||||
std::set<std::string> reportCallIds_; // the delivery reports' Call-IDs, each until a final comes for it
|
std::set<std::string> reportCallIds_; // the delivery reports' Call-IDs, each until a final comes for it
|
||||||
|
|
@ -2932,7 +2933,7 @@ private:
|
||||||
p.tpMr = tpMr_; p.rpMr = rpMr_; p.concatRef = concatRef_;
|
p.tpMr = tpMr_; p.rpMr = rpMr_; p.concatRef = concatRef_;
|
||||||
const bool wantsReport = p.statusReport;
|
const bool wantsReport = p.statusReport;
|
||||||
const std::string destination = p.number;
|
const std::string destination = p.number;
|
||||||
smsOut_.emplace(ctx_, rng_, id, std::move(p));
|
smsOut_.emplace(ctx_, rng_, smsSubmitted_, id, std::move(p));
|
||||||
auto actions = smsOut_->Start(Mono());
|
auto actions = smsOut_->Start(Mono());
|
||||||
// on record from the start — the SC may deliver segment 1 and report on
|
// on record from the start — the SC may deliver segment 1 and report on
|
||||||
// it while segment 2 is still in flight — and only for a message that
|
// it while segment 2 is still in flight — and only for a message that
|
||||||
|
|
@ -3016,7 +3017,7 @@ private:
|
||||||
if (reply_) reply_(*again);
|
if (reply_) reply_(*again);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto r = imsd::engine::OnSmsMessage(ctx_, rng_, msg, reassembler_, smsOut_ ? &*smsOut_ : nullptr, Mono());
|
auto r = imsd::engine::OnSmsMessage(ctx_, rng_, msg, reassembler_, smsOut_ ? &*smsOut_ : nullptr, smsSubmitted_, Mono());
|
||||||
recentMessages_.Remember(key, r.response, Mono());
|
recentMessages_.Remember(key, r.response, Mono());
|
||||||
if (reply_) reply_(r.response);
|
if (reply_) reply_(r.response);
|
||||||
if (!r.reportCallId.empty()) reportCallIds_.insert(r.reportCallId);
|
if (!r.reportCallId.empty()) reportCallIds_.insert(r.reportCallId);
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,9 @@ MESSAGE outside a call's dialog leads to (the final for it, the message or
|
||||||
status report it delivered, the delivery report to send), with
|
status report it delivered, the delivery report to send), with
|
||||||
RecentTransactions (a retransmitted request within 32 s gets its final
|
RecentTransactions (a retransmitted request within 32 s gets its final
|
||||||
again and is not handled again; one whose first Via line has no
|
again and is not handled again; one whose first Via line has no
|
||||||
`branch=`, or an empty one, is never taken for a copy), and StatusReportBook with SameRecipient (a status
|
`branch=`, or an empty one, is never taken for a copy), RecentSubmissions (the
|
||||||
|
Call-IDs of the MESSAGEs our submissions went out in, an hour each: a submit
|
||||||
|
report for one no longer in flight is answered 200, not 488), and StatusReportBook with SameRecipient (a status
|
||||||
report's match to the message that asked for one, TP-MR and recipient, and
|
report's match to the message that asked for one, TP-MR and recipient, and
|
||||||
its word for the whole message), SmsWordOrder (the order of a message's
|
its word for the whole message), SmsWordOrder (the order of a message's
|
||||||
words) and the ids (RunToken, SentSmsId, ReceivedSmsId), and the received-message store's record codec
|
words) and the ids (RunToken, SentSmsId, ReceivedSmsId), and the received-message store's record codec
|
||||||
|
|
@ -1041,6 +1043,63 @@ export namespace imsd::engine {
|
||||||
std::map<std::uint8_t, std::shared_ptr<Message>> byMr_;
|
std::map<std::uint8_t, std::shared_ptr<Message>> byMr_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// The Call-IDs an In-Reply-To lists (RFC 3261 20.21: a callid, then
|
||||||
|
// more after commas), each without the white space around it.
|
||||||
|
std::vector<std::string_view> InReplyToCallIds(std::string_view inReplyTo) {
|
||||||
|
std::vector<std::string_view> ids;
|
||||||
|
for (auto part : std::views::split(inReplyTo, ','))
|
||||||
|
ids.push_back(imsd::sip::Trim(std::string_view(part.begin(), part.end())));
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
// An RP-ERROR's refusal in words: its RP cause and, when its submit
|
||||||
|
// report carries one, the TP-FCS.
|
||||||
|
std::string RpErrorWords(const imsd::sms::Rp& rp) {
|
||||||
|
std::string words = std::format("RP cause {} ({})", rp.cause.value_or(0), imsd::sms::RpCauseText(rp.cause.value_or(0)));
|
||||||
|
if (auto r = imsd::sms::ParseSubmitReport(rp.tpdu, true); r && r->failureCause)
|
||||||
|
words += std::format(", TP-FCS 0x{:02x} ({})", *r->failureCause, imsd::sms::FailureCauseText(*r->failureCause));
|
||||||
|
return words;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The MESSAGEs our submissions went out in, by Call-ID. TS 24.341
|
||||||
|
// 5.3.1.2 has a submit report answered 200 when its In-Reply-To
|
||||||
|
// "indicates that the request corresponds to a short message submitted
|
||||||
|
// by the SM-over-IP sender" and 488 when it does not, and its NOTE 3
|
||||||
|
// has the sender store the Call-ID for that. The message in flight
|
||||||
|
// knows its own MESSAGE (SmsOutbound); this table keeps every one for
|
||||||
|
// an hour after it went out, so a report that comes once its message
|
||||||
|
// has ended — its wait run out, say — or once its segment was followed
|
||||||
|
// by the next is still known for ours: answered 200 and logged with
|
||||||
|
// the message's id. Nothing else follows from it: a message that has
|
||||||
|
// ended has had its word on the bus, and `failed` is its last (§8.4);
|
||||||
|
// one whose next segment is in flight goes on as it was. The table is
|
||||||
|
// this run's.
|
||||||
|
class RecentSubmissions {
|
||||||
|
public:
|
||||||
|
static constexpr double Keep = 3600.0;
|
||||||
|
struct Entry { std::string id; std::size_t segment = 0, segments = 0; double at = 0; };
|
||||||
|
|
||||||
|
// the MESSAGE `callid` carried segment `segment` of `segments` of the message `id`
|
||||||
|
void Sent(std::string_view callid, std::string_view id, std::size_t segment, std::size_t segments, double now) {
|
||||||
|
Purge(now);
|
||||||
|
byCallId_[std::string(callid)] = Entry{std::string(id), segment, segments, now};
|
||||||
|
}
|
||||||
|
// The MESSAGE of ours an In-Reply-To names — of the Call-IDs it lists, the first on record.
|
||||||
|
std::optional<Entry> Named(std::string_view inReplyTo, double now) {
|
||||||
|
Purge(now);
|
||||||
|
for (std::string_view callid : InReplyToCallIds(inReplyTo))
|
||||||
|
if (auto it = byCallId_.find(callid); it != byCallId_.end()) return it->second;
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
std::size_t Size() const { return byCallId_.size(); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
void Purge(double now) {
|
||||||
|
std::erase_if(byCallId_, [&](const auto& e) { return now - e.second.at > Keep; });
|
||||||
|
}
|
||||||
|
std::map<std::string, Entry, std::less<>> byCallId_;
|
||||||
|
};
|
||||||
|
|
||||||
// The waits (TS 24.011 10: TR1M; TS 24.341 5.3.1.1 NOTE 1 has it
|
// The waits (TS 24.011 10: TR1M; TS 24.341 5.3.1.1 NOTE 1 has it
|
||||||
// exceed SIP timer F): a MESSAGE's final within 32 s
|
// exceed SIP timer F): a MESSAGE's final within 32 s
|
||||||
// of the MESSAGE or of its latest provisional, which starts the wait
|
// of the MESSAGE or of its latest provisional, which starts the wait
|
||||||
|
|
@ -1131,8 +1190,9 @@ export namespace imsd::engine {
|
||||||
};
|
};
|
||||||
enum class Phase { Idle, Sending, AwaitingReport, Done };
|
enum class Phase { Idle, Sending, AwaitingReport, Done };
|
||||||
|
|
||||||
SmsOutbound(const imsd::msg::Context& ctx, imsd::util::Rng& rng, std::string id, Params p)
|
// `submitted`: where each MESSAGE this message goes out in is put on record
|
||||||
: ctx_(ctx), rng_(rng), id_(std::move(id)), p_(std::move(p)) {}
|
SmsOutbound(const imsd::msg::Context& ctx, imsd::util::Rng& rng, RecentSubmissions& submitted, std::string id, Params p)
|
||||||
|
: ctx_(ctx), rng_(rng), submitted_(submitted), id_(std::move(id)), p_(std::move(p)) {}
|
||||||
|
|
||||||
const std::string& Id() const { return id_; }
|
const std::string& Id() const { return id_; }
|
||||||
// the segment in flight's MESSAGE (empty before the first went out)
|
// the segment in flight's MESSAGE (empty before the first went out)
|
||||||
|
|
@ -1199,11 +1259,8 @@ export namespace imsd::engine {
|
||||||
// order is its own) is taken as well.
|
// order is its own) is taken as well.
|
||||||
bool OwnsReport(std::string_view inReplyTo, std::optional<std::uint8_t> rpMr) const {
|
bool OwnsReport(std::string_view inReplyTo, std::optional<std::uint8_t> rpMr) const {
|
||||||
if (phase_ != Phase::AwaitingReport && phase_ != Phase::Sending) return false;
|
if (phase_ != Phase::AwaitingReport && phase_ != Phase::Sending) return false;
|
||||||
if (!inReplyTo.empty()) { // a list of Call-IDs (RFC 3261 20.21): ours among them
|
if (!inReplyTo.empty()) // a list of Call-IDs (RFC 3261 20.21): ours among them
|
||||||
for (auto part : std::views::split(inReplyTo, ','))
|
return std::ranges::contains(InReplyToCallIds(inReplyTo), std::string_view(callid_));
|
||||||
if (imsd::sip::Trim(std::string_view(part.begin(), part.end())) == callid_) return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return rpMr && *rpMr == CurrentRpMr();
|
return rpMr && *rpMr == CurrentRpMr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1216,10 +1273,7 @@ export namespace imsd::engine {
|
||||||
if (phase_ != Phase::AwaitingReport && phase_ != Phase::Sending) return out;
|
if (phase_ != Phase::AwaitingReport && phase_ != Phase::Sending) return out;
|
||||||
if (rp.type == imsd::sms::RpType::ErrorMt) {
|
if (rp.type == imsd::sms::RpType::ErrorMt) {
|
||||||
phase_ = Phase::Done;
|
phase_ = Phase::Done;
|
||||||
std::string why = std::format("segment {}/{} refused by the SC: RP cause {} ({})", seg_ + 1, tpdus_.size(), rp.cause.value_or(0), imsd::sms::RpCauseText(rp.cause.value_or(0)));
|
out.push_back(Fail(std::format("segment {}/{} refused by the SC: {}", seg_ + 1, tpdus_.size(), RpErrorWords(rp))));
|
||||||
if (auto r = imsd::sms::ParseSubmitReport(rp.tpdu, true); r && r->failureCause)
|
|
||||||
why += std::format(", TP-FCS 0x{:02x} ({})", *r->failureCause, imsd::sms::FailureCauseText(*r->failureCause));
|
|
||||||
out.push_back(Fail(why));
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
if (rp.type != imsd::sms::RpType::AckMt) return out;
|
if (rp.type != imsd::sms::RpType::AckMt) return out;
|
||||||
|
|
@ -1260,6 +1314,7 @@ export namespace imsd::engine {
|
||||||
|
|
||||||
void SendSegment(std::vector<SmsAction>& out, double now) {
|
void SendSegment(std::vector<SmsAction>& out, double now) {
|
||||||
callid_ = std::format("{}@{}", rng_.Token(16), ctx_.local);
|
callid_ = std::format("{}@{}", rng_.Token(16), ctx_.local);
|
||||||
|
submitted_.Sent(callid_, id_, seg_ + 1, tpdus_.size(), now);
|
||||||
std::vector<std::uint8_t> rp = imsd::sms::BuildRpData(CurrentRpMr(), p_.scAddress, tpdus_[seg_]);
|
std::vector<std::uint8_t> rp = imsd::sms::BuildRpData(CurrentRpMr(), p_.scAddress, tpdus_[seg_]);
|
||||||
out.push_back(SmsAction{SmsAction::Type::SendClient, imsd::msg::BuildMessageSms(ctx_, p_.scTarget, callid_, rng_.Token(8), rng_.Token(16), rp)});
|
out.push_back(SmsAction{SmsAction::Type::SendClient, imsd::msg::BuildMessageSms(ctx_, p_.scTarget, callid_, rng_.Token(8), rng_.Token(16), rp)});
|
||||||
out.push_back(LogAct(std::format("sms {}: segment {}/{} to {} via {}: MESSAGE sent (RP-MR {}, TP-MR {}, {} bytes)", id_, seg_ + 1, tpdus_.size(), p_.number, p_.scTarget, CurrentRpMr(), tpMrs_[seg_], tpdus_[seg_].size())));
|
out.push_back(LogAct(std::format("sms {}: segment {}/{} to {} via {}: MESSAGE sent (RP-MR {}, TP-MR {}, {} bytes)", id_, seg_ + 1, tpdus_.size(), p_.number, p_.scTarget, CurrentRpMr(), tpMrs_[seg_], tpdus_[seg_].size())));
|
||||||
|
|
@ -1282,6 +1337,7 @@ export namespace imsd::engine {
|
||||||
|
|
||||||
const imsd::msg::Context& ctx_;
|
const imsd::msg::Context& ctx_;
|
||||||
imsd::util::Rng& rng_;
|
imsd::util::Rng& rng_;
|
||||||
|
RecentSubmissions& submitted_;
|
||||||
std::string id_;
|
std::string id_;
|
||||||
Params p_;
|
Params p_;
|
||||||
std::vector<std::vector<std::uint8_t>> tpdus_;
|
std::vector<std::vector<std::uint8_t>> tpdus_;
|
||||||
|
|
@ -1478,8 +1534,9 @@ export namespace imsd::engine {
|
||||||
// else its From; one that gives neither URI gets none, which is logged.
|
// else its From; one that gives neither URI gets none, which is logged.
|
||||||
// An RP-ACK/RP-ERROR is a submit report: the message in
|
// An RP-ACK/RP-ERROR is a submit report: the message in
|
||||||
// flight (`outbound`) takes it and the MESSAGE is answered 200; one the
|
// flight (`outbound`) takes it and the MESSAGE is answered 200; one the
|
||||||
// message in flight does not own is answered 488 when its In-Reply-To is
|
// message in flight does not own is answered 200 and logged when its
|
||||||
// not empty, else 200 and logged. A MESSAGE whose Content-Type
|
// In-Reply-To names a MESSAGE of ours on record (`submitted`), 488 when
|
||||||
|
// it names none, and 200 and logged when it has no In-Reply-To. A MESSAGE whose Content-Type
|
||||||
// does not contain the SMS one, or whose body is no RP message, is
|
// does not contain the SMS one, or whose body is no RP message, is
|
||||||
// answered 200 and logged (the journal keeps what the 200 acknowledged). While SMS over IP is off (`ctx.smsOverIp`)
|
// answered 200 and logged (the journal keeps what the 200 acknowledged). While SMS over IP is off (`ctx.smsOverIp`)
|
||||||
// every MESSAGE whose Content-Type contains the SMS one is refused
|
// every MESSAGE whose Content-Type contains the SMS one is refused
|
||||||
|
|
@ -1487,7 +1544,7 @@ export namespace imsd::engine {
|
||||||
// and an RP-ACK would count a short message delivered to nobody, a failure lets the IP-SM-GW try the
|
// and an RP-ACK would count a short message delivered to nobody, a failure lets the IP-SM-GW try the
|
||||||
// modem's path (TS 24.341 5.3.3.4.2 NOTE 2) where the network gives the
|
// modem's path (TS 24.341 5.3.3.4.2 NOTE 2) where the network gives the
|
||||||
// modem one.
|
// modem one.
|
||||||
SmsInbound OnSmsMessage(const imsd::msg::Context& ctx, imsd::util::Rng& rng, std::string_view message, imsd::sms::Reassembler& reassembler, SmsOutbound* outbound, double now) {
|
SmsInbound OnSmsMessage(const imsd::msg::Context& ctx, imsd::util::Rng& rng, std::string_view message, imsd::sms::Reassembler& reassembler, SmsOutbound* outbound, RecentSubmissions& submitted, double now) {
|
||||||
using imsd::sms::RpType;
|
using imsd::sms::RpType;
|
||||||
SmsInbound r;
|
SmsInbound r;
|
||||||
const std::string toTag = rng.Token(10); // the To tag for the finals we give this request (RFC 3261 8.2.6.2; BuildResponse adds it unless the To holds `tag=`)
|
const std::string toTag = rng.Token(10); // the To tag for the finals we give this request (RFC 3261 8.2.6.2; BuildResponse adds it unless the To holds `tag=`)
|
||||||
|
|
@ -1524,11 +1581,16 @@ export namespace imsd::engine {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
if (!inReplyTo.empty()) {
|
if (!inReplyTo.empty()) {
|
||||||
|
if (auto ours = submitted.Named(inReplyTo, now)) {
|
||||||
|
// a MESSAGE of ours that is no longer in flight: the 200 stands (TS 24.341 5.3.1.2), and the journal keeps what the report said
|
||||||
|
r.actions.push_back(SmsAction{SmsAction::Type::Log, std::format("submit report ({}) In-Reply-To {}: sms {}'s segment {}/{}, no longer in flight; 200", rp.type == RpType::AckMt ? "RP-ACK" : std::format("RP-ERROR, {}", RpErrorWords(rp)), inReplyTo, ours->id, ours->segment, ours->segments)});
|
||||||
|
return r;
|
||||||
|
}
|
||||||
r.response = imsd::msg::BuildResponse(ctx, message, 488, "Not Acceptable Here", toTag);
|
r.response = imsd::msg::BuildResponse(ctx, message, 488, "Not Acceptable Here", toTag);
|
||||||
r.actions.push_back(SmsAction{SmsAction::Type::Log, std::format("submit report ({}) In-Reply-To {}: no MESSAGE of ours in flight; 488", rp.type == RpType::AckMt ? "RP-ACK" : "RP-ERROR", inReplyTo)});
|
r.actions.push_back(SmsAction{SmsAction::Type::Log, std::format("submit report ({}) In-Reply-To {}: no MESSAGE of ours on record; 488", rp.type == RpType::AckMt ? "RP-ACK" : "RP-ERROR", inReplyTo)});
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
r.actions.push_back(SmsAction{SmsAction::Type::Log, std::format("submit report ({}, RP-MR {}) for no message in flight; 200", rp.type == RpType::AckMt ? "RP-ACK" : "RP-ERROR", rp.mr)});
|
r.actions.push_back(SmsAction{SmsAction::Type::Log, std::format("submit report ({}, RP-MR {}) that no message in flight owns; 200", rp.type == RpType::AckMt ? "RP-ACK" : "RP-ERROR", rp.mr)});
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
// what is left is an RP-DATA: ParseRp gave one of the network's three
|
// what is left is an RP-DATA: ParseRp gave one of the network's three
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,8 @@
|
||||||
// delivery with no gateway for its report, a
|
// delivery with no gateway for its report, a
|
||||||
// delivered message to the bus and its RP-ACK to the IP-SM-GW with
|
// delivered message to the bus and its RP-ACK to the IP-SM-GW with
|
||||||
// In-Reply-To, a concatenated pair whole once, a status report, a submit
|
// In-Reply-To, a concatenated pair whole once, a status report, a submit
|
||||||
// report routed to the message in flight, 488 for one that is not ours, an
|
// report routed to the message in flight, 200 for one of ours no longer in
|
||||||
|
// flight (RecentSubmissions), 488 for one that is not ours, an
|
||||||
// unusable TPDU acknowledged with an RP-ERROR, a body that is no RP
|
// unusable TPDU acknowledged with an RP-ERROR, a body that is no RP
|
||||||
// message, a page-mode text 200'd and logged, a short message while SMS
|
// message, a page-mode text 200'd and logged, a short message while SMS
|
||||||
// over IP is off refused with 480, a delivered MESSAGE and a final whose
|
// over IP is off refused with 480, a delivered MESSAGE and a final whose
|
||||||
|
|
@ -1331,11 +1332,12 @@ int main() {
|
||||||
c.aor = "sip:+31611111111@ims.mnc001.mcc001.3gppnetwork.org";
|
c.aor = "sip:+31611111111@ims.mnc001.mcc001.3gppnetwork.org";
|
||||||
c.smsOverIp = true;
|
c.smsOverIp = true;
|
||||||
const SmsOutbound::Params p{"+31612345678", "Hello", "sip:+31653131313@ims.mnc001.mcc001.3gppnetwork.org;user=phone", kpnSc, 10, 20, 0x2A, 0xA9, false};
|
const SmsOutbound::Params p{"+31612345678", "Hello", "sip:+31653131313@ims.mnc001.mcc001.3gppnetwork.org;user=phone", kpnSc, 10, 20, 0x2A, 0xA9, false};
|
||||||
|
RecentSubmissions sub; // the MESSAGEs the messages below go out in; a check that needs an empty one makes its own
|
||||||
|
|
||||||
// a one-segment message: MESSAGE, 202, RP-ACK -> sent
|
// a one-segment message: MESSAGE, 202, RP-ACK -> sent
|
||||||
{
|
{
|
||||||
imsd::util::Rng rng(71);
|
imsd::util::Rng rng(71);
|
||||||
SmsOutbound m(c, rng, "ims-sms-1", p);
|
SmsOutbound m(c, rng, sub, "ims-sms-1", p);
|
||||||
auto a = m.Start(100.0);
|
auto a = m.Start(100.0);
|
||||||
const auto* sent = findSms(a, SmsAction::Type::SendClient);
|
const auto* sent = findSms(a, SmsAction::Type::SendClient);
|
||||||
Check(sent && sent->text.starts_with("MESSAGE sip:+31653131313@ims.mnc001.mcc001.3gppnetwork.org;user=phone SIP/2.0\r\n"), "outbound: the MESSAGE goes to the SC's PSI");
|
Check(sent && sent->text.starts_with("MESSAGE sip:+31653131313@ims.mnc001.mcc001.3gppnetwork.org;user=phone SIP/2.0\r\n"), "outbound: the MESSAGE goes to the SC's PSI");
|
||||||
|
|
@ -1360,7 +1362,7 @@ int main() {
|
||||||
// the final refuses it
|
// the final refuses it
|
||||||
{
|
{
|
||||||
imsd::util::Rng rng(72);
|
imsd::util::Rng rng(72);
|
||||||
SmsOutbound m(c, rng, "ims-sms-2", p);
|
SmsOutbound m(c, rng, sub, "ims-sms-2", p);
|
||||||
auto a = m.Start(0.0);
|
auto a = m.Start(0.0);
|
||||||
const std::string callid(imsd::sip::Header(findSms(a, SmsAction::Type::SendClient)->text, "Call-ID").value_or(""));
|
const std::string callid(imsd::sip::Header(findSms(a, SmsAction::Type::SendClient)->text, "Call-ID").value_or(""));
|
||||||
auto b = m.OnResponse(std::format("SIP/2.0 403 Forbidden\r\nCall-ID: {}\r\nCSeq: 1 MESSAGE\r\nWarning: 399 x \"no\"\r\nContent-Length: 0\r\n\r\n", callid), 403, 1.0);
|
auto b = m.OnResponse(std::format("SIP/2.0 403 Forbidden\r\nCall-ID: {}\r\nCSeq: 1 MESSAGE\r\nWarning: 399 x \"no\"\r\nContent-Length: 0\r\n\r\n", callid), 403, 1.0);
|
||||||
|
|
@ -1370,7 +1372,7 @@ int main() {
|
||||||
// a provisional keeps it waiting; the RP-ERROR fails it with the cause
|
// a provisional keeps it waiting; the RP-ERROR fails it with the cause
|
||||||
{
|
{
|
||||||
imsd::util::Rng rng(73);
|
imsd::util::Rng rng(73);
|
||||||
SmsOutbound m(c, rng, "ims-sms-3", p);
|
SmsOutbound m(c, rng, sub, "ims-sms-3", p);
|
||||||
auto a = m.Start(0.0);
|
auto a = m.Start(0.0);
|
||||||
const std::string callid(imsd::sip::Header(findSms(a, SmsAction::Type::SendClient)->text, "Call-ID").value_or(""));
|
const std::string callid(imsd::sip::Header(findSms(a, SmsAction::Type::SendClient)->text, "Call-ID").value_or(""));
|
||||||
m.OnResponse(final(callid, 100, "Trying"), 100, 5.0);
|
m.OnResponse(final(callid, 100, "Trying"), 100, 5.0);
|
||||||
|
|
@ -1384,13 +1386,13 @@ int main() {
|
||||||
// timeouts and a failed send
|
// timeouts and a failed send
|
||||||
{
|
{
|
||||||
imsd::util::Rng rng(74);
|
imsd::util::Rng rng(74);
|
||||||
SmsOutbound m(c, rng, "ims-sms-4", p);
|
SmsOutbound m(c, rng, sub, "ims-sms-4", p);
|
||||||
m.Start(0.0);
|
m.Start(0.0);
|
||||||
auto a = m.OnDeadline();
|
auto a = m.OnDeadline();
|
||||||
const auto* st = findSms(a, SmsAction::Type::State);
|
const auto* st = findSms(a, SmsAction::Type::State);
|
||||||
Check(st && st->state == "failed" && st->reason.contains("no answer to the MESSAGE"), "outbound: no final within the wait fails it");
|
Check(st && st->state == "failed" && st->reason.contains("no answer to the MESSAGE"), "outbound: no final within the wait fails it");
|
||||||
imsd::util::Rng rng2(75);
|
imsd::util::Rng rng2(75);
|
||||||
SmsOutbound m2(c, rng2, "ims-sms-5", p);
|
SmsOutbound m2(c, rng2, sub, "ims-sms-5", p);
|
||||||
auto b = m2.Start(0.0);
|
auto b = m2.Start(0.0);
|
||||||
const std::string callid(imsd::sip::Header(findSms(b, SmsAction::Type::SendClient)->text, "Call-ID").value_or(""));
|
const std::string callid(imsd::sip::Header(findSms(b, SmsAction::Type::SendClient)->text, "Call-ID").value_or(""));
|
||||||
m2.OnResponse(final(callid, 202, "Accepted"), 202, 1.0);
|
m2.OnResponse(final(callid, 202, "Accepted"), 202, 1.0);
|
||||||
|
|
@ -1398,7 +1400,7 @@ int main() {
|
||||||
st = findSms(d, SmsAction::Type::State);
|
st = findSms(d, SmsAction::Type::State);
|
||||||
Check(st && st->state == "failed" && st->reason.contains("no submit report"), "outbound: no submit report within its wait fails it");
|
Check(st && st->state == "failed" && st->reason.contains("no submit report"), "outbound: no submit report within its wait fails it");
|
||||||
imsd::util::Rng rng3(76);
|
imsd::util::Rng rng3(76);
|
||||||
SmsOutbound m3(c, rng3, "ims-sms-6", p);
|
SmsOutbound m3(c, rng3, sub, "ims-sms-6", p);
|
||||||
m3.Start(0.0);
|
m3.Start(0.0);
|
||||||
auto e = m3.OnSendFailed();
|
auto e = m3.OnSendFailed();
|
||||||
st = findSms(e, SmsAction::Type::State);
|
st = findSms(e, SmsAction::Type::State);
|
||||||
|
|
@ -1409,7 +1411,7 @@ int main() {
|
||||||
imsd::util::Rng rng(77);
|
imsd::util::Rng rng(77);
|
||||||
SmsOutbound::Params pl = p;
|
SmsOutbound::Params pl = p;
|
||||||
pl.text = std::string(200, 'x');
|
pl.text = std::string(200, 'x');
|
||||||
SmsOutbound m(c, rng, "ims-sms-7", pl);
|
SmsOutbound m(c, rng, sub, "ims-sms-7", pl);
|
||||||
auto a = m.Start(0.0);
|
auto a = m.Start(0.0);
|
||||||
Check(m.Segments() == 2 && m.TpMrs() == std::vector<std::uint8_t>{10, 11}, "outbound: 200 characters are two segments with consecutive TP-MRs");
|
Check(m.Segments() == 2 && m.TpMrs() == std::vector<std::uint8_t>{10, 11}, "outbound: 200 characters are two segments with consecutive TP-MRs");
|
||||||
const std::string callid(imsd::sip::Header(findSms(a, SmsAction::Type::SendClient)->text, "Call-ID").value_or(""));
|
const std::string callid(imsd::sip::Header(findSms(a, SmsAction::Type::SendClient)->text, "Call-ID").value_or(""));
|
||||||
|
|
@ -1433,21 +1435,21 @@ int main() {
|
||||||
imsd::util::Rng rng(78);
|
imsd::util::Rng rng(78);
|
||||||
SmsOutbound::Params bad = p;
|
SmsOutbound::Params bad = p;
|
||||||
bad.number = "nobody";
|
bad.number = "nobody";
|
||||||
SmsOutbound m(c, rng, "ims-sms-8", bad);
|
SmsOutbound m(c, rng, sub, "ims-sms-8", bad);
|
||||||
auto a = m.Start(0.0);
|
auto a = m.Start(0.0);
|
||||||
const auto* st = findSms(a, SmsAction::Type::State);
|
const auto* st = findSms(a, SmsAction::Type::State);
|
||||||
Check(st && st->state == "failed" && st->reason == "'nobody' is not a number" && m.Done() && !hasSms(a, SmsAction::Type::SendClient), "outbound: a destination that is no number fails at once");
|
Check(st && st->state == "failed" && st->reason == "'nobody' is not a number" && m.Done() && !hasSms(a, SmsAction::Type::SendClient), "outbound: a destination that is no number fails at once");
|
||||||
SmsOutbound::Params longNumber = p;
|
SmsOutbound::Params longNumber = p;
|
||||||
longNumber.number = "+" + std::string(21, '3');
|
longNumber.number = "+" + std::string(21, '3');
|
||||||
imsd::util::Rng rngL(80);
|
imsd::util::Rng rngL(80);
|
||||||
SmsOutbound mL(c, rngL, "ims-sms-10", longNumber);
|
SmsOutbound mL(c, rngL, sub, "ims-sms-10", longNumber);
|
||||||
auto l = mL.Start(0.0);
|
auto l = mL.Start(0.0);
|
||||||
st = findSms(l, SmsAction::Type::State);
|
st = findSms(l, SmsAction::Type::State);
|
||||||
Check(st && st->state == "failed" && st->reason.contains("is not a number") && !hasSms(l, SmsAction::Type::SendClient), "outbound: a destination of more than 20 digits is no number, not a text that does not fit");
|
Check(st && st->state == "failed" && st->reason.contains("is not a number") && !hasSms(l, SmsAction::Type::SendClient), "outbound: a destination of more than 20 digits is no number, not a text that does not fit");
|
||||||
SmsOutbound::Params noSc = p;
|
SmsOutbound::Params noSc = p;
|
||||||
noSc.scAddress.clear();
|
noSc.scAddress.clear();
|
||||||
imsd::util::Rng rng2(79);
|
imsd::util::Rng rng2(79);
|
||||||
SmsOutbound m2(c, rng2, "ims-sms-9", noSc);
|
SmsOutbound m2(c, rng2, sub, "ims-sms-9", noSc);
|
||||||
auto b = m2.Start(0.0);
|
auto b = m2.Start(0.0);
|
||||||
st = findSms(b, SmsAction::Type::State);
|
st = findSms(b, SmsAction::Type::State);
|
||||||
Check(st && st->state == "failed" && st->reason.contains("no service centre"), "outbound: no service centre fails at once");
|
Check(st && st->state == "failed" && st->reason.contains("no service centre"), "outbound: no service centre fails at once");
|
||||||
|
|
@ -1535,6 +1537,29 @@ int main() {
|
||||||
Check(ReceivedSmsId("7f3a9c21", 42, 1) != ReceivedSmsId("0b1d2e3f", 42, 1) && SentSmsId("7f3a9c21", 42, 1) != SentSmsId("0b1d2e3f", 42, 1), "two runs with different tokens: their ids differ at the same second and counter");
|
Check(ReceivedSmsId("7f3a9c21", 42, 1) != ReceivedSmsId("0b1d2e3f", 42, 1) && SentSmsId("7f3a9c21", 42, 1) != SentSmsId("0b1d2e3f", 42, 1), "two runs with different tokens: their ids differ at the same second and counter");
|
||||||
Check(ReceivedSmsId("ffffffff", std::numeric_limits<std::int64_t>::min(), std::numeric_limits<std::uint64_t>::max()).size() <= 64, "the longest received id is no longer than 64 bytes");
|
Check(ReceivedSmsId("ffffffff", std::numeric_limits<std::int64_t>::min(), std::numeric_limits<std::uint64_t>::max()).size() <= 64, "the longest received id is no longer than 64 bytes");
|
||||||
}
|
}
|
||||||
|
// the MESSAGEs our submissions went out in, on record for an hour each (the Call-ID TS 24.341 5.3.1.2 NOTE 3 has the sender store; the hour is imsd's)
|
||||||
|
{
|
||||||
|
RecentSubmissions book;
|
||||||
|
Check(RecentSubmissions::Keep == 3600.0 && book.Size() == 0 && !book.Named("a@h", 0.0), "submissions: an empty table names nothing; a MESSAGE is kept 3600 s");
|
||||||
|
book.Sent("a@h", "ims-sms-1", 1, 2, 100.0);
|
||||||
|
book.Sent("b@h", "ims-sms-1", 2, 2, 105.0);
|
||||||
|
const auto one = book.Named("a@h", 110.0);
|
||||||
|
Check(one && one->id == "ims-sms-1" && one->segment == 1 && one->segments == 2 && book.Size() == 2, "submissions: a Call-ID on record gives its message and segment");
|
||||||
|
const auto listed = book.Named(" x@y ,\tb@h , a@h", 110.0);
|
||||||
|
Check(listed && listed->segment == 2, "submissions: of a list of Call-IDs, the first that is ours");
|
||||||
|
Check(!book.Named("a@h2", 110.0) && !book.Named("", 110.0) && !book.Named("A@H", 110.0), "submissions: another Call-ID, an empty In-Reply-To and another letter case name none");
|
||||||
|
Check(book.Named("a@h", 100.0 + 3600.0) && !book.Named("a@h", 100.0 + 3600.5) && book.Named("b@h", 100.0 + 3600.5) && book.Size() == 1, "submissions: on record 3600 s after the MESSAGE went out, no longer");
|
||||||
|
book.Sent("c@h", "ims-sms-2", 1, 1, 105.0 + 3601.0);
|
||||||
|
Check(book.Size() == 1 && !book.Named("b@h", 105.0 + 3601.0) && book.Named("c@h", 105.0 + 3601.0), "submissions: a new MESSAGE's entry clears those past their hour");
|
||||||
|
// a message puts each MESSAGE it goes out in on record, with its segment
|
||||||
|
imsd::util::Rng rng(93);
|
||||||
|
SmsOutbound::Params two = p; two.text = std::string(200, 'A');
|
||||||
|
SmsOutbound m(c, rng, book, "ims-sms-21", two);
|
||||||
|
const std::string callid1(imsd::sip::Header(findSms(m.Start(4000.0), SmsAction::Type::SendClient)->text, "Call-ID").value_or(""));
|
||||||
|
const std::string callid2(imsd::sip::Header(findSms(m.OnReport(Rp{RpType::AckMt, 20, std::nullopt, {}, std::nullopt, std::nullopt}, 4001.0), SmsAction::Type::SendClient)->text, "Call-ID").value_or(""));
|
||||||
|
const auto first = book.Named(callid1, 4002.0), second = book.Named(callid2, 4002.0);
|
||||||
|
Check(first && first->id == "ims-sms-21" && first->segment == 1 && first->segments == 2 && first->at == 4000.0 && second && second->segment == 2 && second->at == 4001.0, "submissions: each segment's MESSAGE goes on record as it goes out");
|
||||||
|
}
|
||||||
// inbound MESSAGEs, as the IP-SM-GW sends them
|
// inbound MESSAGEs, as the IP-SM-GW sends them
|
||||||
auto inbound = [](std::string_view bodyHex, std::string_view extraHeaders = "") {
|
auto inbound = [](std::string_view bodyHex, std::string_view extraHeaders = "") {
|
||||||
auto b = *imsd::util::FromHex(bodyHex);
|
auto b = *imsd::util::FromHex(bodyHex);
|
||||||
|
|
@ -1544,7 +1569,7 @@ int main() {
|
||||||
{
|
{
|
||||||
imsd::util::Rng rng(80);
|
imsd::util::Rng rng(80);
|
||||||
Reassembler re;
|
Reassembler re;
|
||||||
auto r = OnSmsMessage(c, rng, inbound("011107911356131313F3001E040B911346610089F60000208062917314080CC8F71D14969741F977FD07"), re, nullptr, 50.0);
|
auto r = OnSmsMessage(c, rng, inbound("011107911356131313F3001E040B911346610089F60000208062917314080CC8F71D14969741F977FD07"), re, nullptr, sub, 50.0);
|
||||||
Check(r.response.starts_with("SIP/2.0 200 OK\r\n") && r.response.contains("Call-ID: in-011107@net\r\n"), "inbound: the MESSAGE is answered 200");
|
Check(r.response.starts_with("SIP/2.0 200 OK\r\n") && r.response.contains("Call-ID: in-011107@net\r\n"), "inbound: the MESSAGE is answered 200");
|
||||||
const auto* rec = findSms(r.actions, SmsAction::Type::Received);
|
const auto* rec = findSms(r.actions, SmsAction::Type::Received);
|
||||||
Check(rec && rec->received.from == "+31641600986" && rec->received.text == "How are you?" && rec->received.sc == "+31653131313" && rec->received.scts == "2002-08-26T19:37:41-00:00" && rec->received.segments == 1 && rec->received.tpdu.size() == 30, "inbound: the message reaches the bus");
|
Check(rec && rec->received.from == "+31641600986" && rec->received.text == "How are you?" && rec->received.sc == "+31653131313" && rec->received.scts == "2002-08-26T19:37:41-00:00" && rec->received.segments == 1 && rec->received.tpdu.size() == 30, "inbound: the message reaches the bus");
|
||||||
|
|
@ -1554,7 +1579,7 @@ int main() {
|
||||||
Check(rep && imsd::sip::Body(rep->text) == std::string("\x02\x11\x41\x02\x00\x00", 6) && imsd::sip::Header(rep->text, "Call-ID") == r.reportCallId, "inbound: the report is an RP-ACK with the SMS-DELIVER-REPORT, RP-MR echoed");
|
Check(rep && imsd::sip::Body(rep->text) == std::string("\x02\x11\x41\x02\x00\x00", 6) && imsd::sip::Header(rep->text, "Call-ID") == r.reportCallId, "inbound: the report is an RP-ACK with the SMS-DELIVER-REPORT, RP-MR echoed");
|
||||||
std::string other = inbound("011207911356131313F3001E040B911346610089F60000208062917314080CC8F71D14969741F977FD07");
|
std::string other = inbound("011207911356131313F3001E040B911346610089F60000208062917314080CC8F71D14969741F977FD07");
|
||||||
other.replace(other.find("From: <sip:ipsmgw@"), 18, "From: <sip:someone@");
|
other.replace(other.find("From: <sip:ipsmgw@"), 18, "From: <sip:someone@");
|
||||||
auto ro = OnSmsMessage(c, rng, other, re, nullptr, 51.0);
|
auto ro = OnSmsMessage(c, rng, other, re, nullptr, sub, 51.0);
|
||||||
const auto* repo = findSms(ro.actions, SmsAction::Type::SendClient);
|
const auto* repo = findSms(ro.actions, SmsAction::Type::SendClient);
|
||||||
Check(repo && repo->text.starts_with("MESSAGE sip:ipsmgw@ims.mnc001.mcc001.3gppnetwork.org SIP/2.0\r\n"), "inbound: with a From that names another, the report still goes to the P-Asserted-Identity");
|
Check(repo && repo->text.starts_with("MESSAGE sip:ipsmgw@ims.mnc001.mcc001.3gppnetwork.org SIP/2.0\r\n"), "inbound: with a From that names another, the report still goes to the P-Asserted-Identity");
|
||||||
}
|
}
|
||||||
|
|
@ -1567,8 +1592,8 @@ int main() {
|
||||||
Check(folded.contains("\r\nContent-Type:\r\n\tapplication/vnd.3gpp.sms\r\n") && framed == longForm, "folded MESSAGE: the datagram framer hands the long form's message on");
|
Check(folded.contains("\r\nContent-Type:\r\n\tapplication/vnd.3gpp.sms\r\n") && framed == longForm, "folded MESSAGE: the datagram framer hands the long form's message on");
|
||||||
imsd::util::Rng rng(80), rngLong(80);
|
imsd::util::Rng rng(80), rngLong(80);
|
||||||
Reassembler re, reLong;
|
Reassembler re, reLong;
|
||||||
auto r = OnSmsMessage(c, rng, framed.value_or(""), re, nullptr, 50.0);
|
auto r = OnSmsMessage(c, rng, framed.value_or(""), re, nullptr, sub, 50.0);
|
||||||
auto want = OnSmsMessage(c, rngLong, longForm, reLong, nullptr, 50.0);
|
auto want = OnSmsMessage(c, rngLong, longForm, reLong, nullptr, sub, 50.0);
|
||||||
const auto* rec = findSms(r.actions, SmsAction::Type::Received);
|
const auto* rec = findSms(r.actions, SmsAction::Type::Received);
|
||||||
Check(rec && rec->received.text == "How are you?" && r.response == want.response && hasSms(r.actions, SmsAction::Type::SendClient), "folded MESSAGE: taken for a short message, answered and reported on as its long form");
|
Check(rec && rec->received.text == "How are you?" && r.response == want.response && hasSms(r.actions, SmsAction::Type::SendClient), "folded MESSAGE: taken for a short message, answered and reported on as its long form");
|
||||||
}
|
}
|
||||||
|
|
@ -1579,8 +1604,8 @@ int main() {
|
||||||
Check(!compact.contains("Content-Type:") && !compact.contains("Call-ID:") && !compact.contains("Via:") && compact.contains("\r\nc: application/vnd.3gpp.sms\r\n") && compact.contains("\r\ni: in-011107@net\r\n") && compact.contains("\r\nv: SIP/2.0/TCP [2001:db8::105]:6000;branch=z9hG4bKn1\r\n") && compact.contains(std::format("\r\nl: {}\r\n", imsd::sip::Body(longForm).size())) && imsd::sip::Body(longForm).size() == 42 && imsd::sip::Body(compact) == imsd::sip::Body(longForm), "the compact MESSAGE carries `c:`, `i:`, `v:` and `l:`, the body of 42 bytes as it was");
|
Check(!compact.contains("Content-Type:") && !compact.contains("Call-ID:") && !compact.contains("Via:") && compact.contains("\r\nc: application/vnd.3gpp.sms\r\n") && compact.contains("\r\ni: in-011107@net\r\n") && compact.contains("\r\nv: SIP/2.0/TCP [2001:db8::105]:6000;branch=z9hG4bKn1\r\n") && compact.contains(std::format("\r\nl: {}\r\n", imsd::sip::Body(longForm).size())) && imsd::sip::Body(longForm).size() == 42 && imsd::sip::Body(compact) == imsd::sip::Body(longForm), "the compact MESSAGE carries `c:`, `i:`, `v:` and `l:`, the body of 42 bytes as it was");
|
||||||
imsd::util::Rng rng(80), rngLong(80);
|
imsd::util::Rng rng(80), rngLong(80);
|
||||||
Reassembler re, reLong;
|
Reassembler re, reLong;
|
||||||
auto r = OnSmsMessage(c, rng, compact, re, nullptr, 50.0);
|
auto r = OnSmsMessage(c, rng, compact, re, nullptr, sub, 50.0);
|
||||||
auto want = OnSmsMessage(c, rngLong, longForm, reLong, nullptr, 50.0);
|
auto want = OnSmsMessage(c, rngLong, longForm, reLong, nullptr, sub, 50.0);
|
||||||
const auto* rec = findSms(r.actions, SmsAction::Type::Received);
|
const auto* rec = findSms(r.actions, SmsAction::Type::Received);
|
||||||
const auto* rep = findSms(r.actions, SmsAction::Type::SendClient);
|
const auto* rep = findSms(r.actions, SmsAction::Type::SendClient);
|
||||||
const auto* wantRep = findSms(want.actions, SmsAction::Type::SendClient);
|
const auto* wantRep = findSms(want.actions, SmsAction::Type::SendClient);
|
||||||
|
|
@ -1589,7 +1614,7 @@ int main() {
|
||||||
Check(RecentTransactions::Key(compact) == "in-011107@net|1 MESSAGE|z9hG4bKn1" && RecentTransactions::Key(compact) == RecentTransactions::Key(longForm), "compact MESSAGE: the retransmission key from `i:` and `v:`");
|
Check(RecentTransactions::Key(compact) == "in-011107@net|1 MESSAGE|z9hG4bKn1" && RecentTransactions::Key(compact) == RecentTransactions::Key(longForm), "compact MESSAGE: the retransmission key from `i:` and `v:`");
|
||||||
// the final to a MESSAGE of ours, its Call-ID as `i:`
|
// the final to a MESSAGE of ours, its Call-ID as `i:`
|
||||||
imsd::util::Rng rngOut(81);
|
imsd::util::Rng rngOut(81);
|
||||||
SmsOutbound m(c, rngOut, "ims-sms-20", p);
|
SmsOutbound m(c, rngOut, sub, "ims-sms-20", p);
|
||||||
const std::string callid(imsd::sip::Header(findSms(m.Start(0.0), SmsAction::Type::SendClient)->text, "Call-ID").value_or(""));
|
const std::string callid(imsd::sip::Header(findSms(m.Start(0.0), SmsAction::Type::SendClient)->text, "Call-ID").value_or(""));
|
||||||
const std::string final202 = Compact(final(callid, 202, "Accepted"));
|
const std::string final202 = Compact(final(callid, 202, "Accepted"));
|
||||||
Check(final202.contains(std::format("\r\ni: {}\r\n", callid)) && !final202.contains("Call-ID:") && m.OwnsResponse(final202), "outbound: a final whose Call-ID comes as `i:` is the message in flight's");
|
Check(final202.contains(std::format("\r\ni: {}\r\n", callid)) && !final202.contains("Call-ID:") && m.OwnsResponse(final202), "outbound: a final whose Call-ID comes as `i:` is the message in flight's");
|
||||||
|
|
@ -1601,7 +1626,7 @@ int main() {
|
||||||
Reassembler re;
|
Reassembler re;
|
||||||
std::string req = inbound("011107911356131313F3001E040B911346610089F60000208062917314080CC8F71D14969741F977FD07");
|
std::string req = inbound("011107911356131313F3001E040B911346610089F60000208062917314080CC8F71D14969741F977FD07");
|
||||||
req.replace(req.find("in-011107@net"), 13, std::string("in-0111") + static_cast<char>(b) + "Route:x@net");
|
req.replace(req.find("in-011107@net"), 13, std::string("in-0111") + static_cast<char>(b) + "Route:x@net");
|
||||||
auto r = OnSmsMessage(c, rng, req, re, nullptr, 52.0);
|
auto r = OnSmsMessage(c, rng, req, re, nullptr, sub, 52.0);
|
||||||
const auto* rep = findSms(r.actions, SmsAction::Type::SendClient);
|
const auto* rep = findSms(r.actions, SmsAction::Type::SendClient);
|
||||||
Check(rep && hasSms(r.actions, SmsAction::Type::Received) && !rep->text.contains("In-Reply-To") && !rep->text.contains("Route:x") && imsd::sip::Body(rep->text) == std::string("\x02\x11\x41\x02\x00\x00", 6), std::format("inbound: a Call-ID with the byte 0x{:02x} in it is not written into the delivery report's In-Reply-To", b));
|
Check(rep && hasSms(r.actions, SmsAction::Type::Received) && !rep->text.contains("In-Reply-To") && !rep->text.contains("Route:x") && imsd::sip::Body(rep->text) == std::string("\x02\x11\x41\x02\x00\x00", 6), std::format("inbound: a Call-ID with the byte 0x{:02x} in it is not written into the delivery report's In-Reply-To", b));
|
||||||
}
|
}
|
||||||
|
|
@ -1609,11 +1634,11 @@ int main() {
|
||||||
for (bool first : {true, false}) {
|
for (bool first : {true, false}) {
|
||||||
imsd::util::Rng rng(92);
|
imsd::util::Rng rng(92);
|
||||||
Reassembler re;
|
Reassembler re;
|
||||||
SmsOutbound m(c, rng, "ims-sms-19", p);
|
SmsOutbound m(c, rng, sub, "ims-sms-19", p);
|
||||||
auto a = m.Start(0.0);
|
auto a = m.Start(0.0);
|
||||||
const std::string callid(imsd::sip::Header(findSms(a, SmsAction::Type::SendClient)->text, "Call-ID").value_or(""));
|
const std::string callid(imsd::sip::Header(findSms(a, SmsAction::Type::SendClient)->text, "Call-ID").value_or(""));
|
||||||
m.OnResponse(final(callid, 202, "Accepted"), 202, 1.0);
|
m.OnResponse(final(callid, 202, "Accepted"), 202, 1.0);
|
||||||
auto r = OnSmsMessage(c, rng, inbound("0314", first ? std::format("In-Reply-To: {}\r\nIn-Reply-To: x@y\r\n", callid) : std::format("In-Reply-To: x@y\r\nIn-Reply-To: {}\r\n", callid)), re, &m, 2.0);
|
auto r = OnSmsMessage(c, rng, inbound("0314", first ? std::format("In-Reply-To: {}\r\nIn-Reply-To: x@y\r\n", callid) : std::format("In-Reply-To: x@y\r\nIn-Reply-To: {}\r\n", callid)), re, &m, sub, 2.0);
|
||||||
const auto* st = findSms(r.actions, SmsAction::Type::State);
|
const auto* st = findSms(r.actions, SmsAction::Type::State);
|
||||||
Check(r.response.starts_with("SIP/2.0 200 OK") && st && st->state == "sent" && m.Done(), std::format("inbound: a submit report whose In-Reply-To rows list ours in the {} reaches the message in flight", first ? "first" : "second"));
|
Check(r.response.starts_with("SIP/2.0 200 OK") && st && st->state == "sent" && m.Done(), std::format("inbound: a submit report whose In-Reply-To rows list ours in the {} reaches the message in flight", first ? "first" : "second"));
|
||||||
}
|
}
|
||||||
|
|
@ -1624,7 +1649,7 @@ int main() {
|
||||||
std::string req = inbound("011107911356131313F30035040B911346610089F6000420806291731408220A502D41737365727465642D4964656E746974793A203C7369703A6576696C40783E");
|
std::string req = inbound("011107911356131313F30035040B911346610089F6000420806291731408220A502D41737365727465642D4964656E746974793A203C7369703A6576696C40783E");
|
||||||
const auto pai = req.find("P-Asserted-Identity:"); // without the header, a body line would be the first match
|
const auto pai = req.find("P-Asserted-Identity:"); // without the header, a body line would be the first match
|
||||||
if (pai != std::string::npos) req.erase(pai, req.find("\r\n", pai) + 2 - pai);
|
if (pai != std::string::npos) req.erase(pai, req.find("\r\n", pai) + 2 - pai);
|
||||||
auto r = OnSmsMessage(c, rng, req, re, nullptr, 52.0);
|
auto r = OnSmsMessage(c, rng, req, re, nullptr, sub, 52.0);
|
||||||
const auto* rec = findSms(r.actions, SmsAction::Type::Received);
|
const auto* rec = findSms(r.actions, SmsAction::Type::Received);
|
||||||
const auto* rep = findSms(r.actions, SmsAction::Type::SendClient);
|
const auto* rep = findSms(r.actions, SmsAction::Type::SendClient);
|
||||||
Check(rec && rec->received.data.size() == 34 && rep && rep->text.starts_with("MESSAGE sip:ipsmgw@ims.mnc001.mcc001.3gppnetwork.org SIP/2.0\r\n") && !rep->text.contains("evil"), "inbound: a header name in the body picks neither the report's target nor anything else");
|
Check(rec && rec->received.data.size() == 34 && rep && rep->text.starts_with("MESSAGE sip:ipsmgw@ims.mnc001.mcc001.3gppnetwork.org SIP/2.0\r\n") && !rep->text.contains("evil"), "inbound: a header name in the body picks neither the report's target nor anything else");
|
||||||
|
|
@ -1633,10 +1658,10 @@ int main() {
|
||||||
{
|
{
|
||||||
imsd::util::Rng rng(81);
|
imsd::util::Rng rng(81);
|
||||||
Reassembler re;
|
Reassembler re;
|
||||||
auto r2 = OnSmsMessage(c, rng, inbound("011207911356131313F3001E440B911316325476F80000620161220500800C0500037B02028442A15008"), re, nullptr, 60.0);
|
auto r2 = OnSmsMessage(c, rng, inbound("011207911356131313F3001E440B911316325476F80000620161220500800C0500037B02028442A15008"), re, nullptr, sub, 60.0);
|
||||||
Check(!hasSms(r2.actions, SmsAction::Type::Received) && hasSms(r2.actions, SmsAction::Type::SendClient) && re.Pending() == 1, "inbound: segment 2/2 first: acknowledged, nothing to the bus yet");
|
Check(!hasSms(r2.actions, SmsAction::Type::Received) && hasSms(r2.actions, SmsAction::Type::SendClient) && re.Pending() == 1, "inbound: segment 2/2 first: acknowledged, nothing to the bus yet");
|
||||||
const std::string seg1 = "440B911316325476F8000062016122050080A00500037B020182C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683";
|
const std::string seg1 = "440B911316325476F8000062016122050080A00500037B020182C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683";
|
||||||
auto r1 = OnSmsMessage(c, rng, inbound(std::format("011307911356131313F300{:02X}{}", seg1.size() / 2, seg1)), re, nullptr, 61.0);
|
auto r1 = OnSmsMessage(c, rng, inbound(std::format("011307911356131313F300{:02X}{}", seg1.size() / 2, seg1)), re, nullptr, sub, 61.0);
|
||||||
const auto* rec = findSms(r1.actions, SmsAction::Type::Received);
|
const auto* rec = findSms(r1.actions, SmsAction::Type::Received);
|
||||||
Check(rec && rec->received.text == std::string(153, 'A') + "BBBBB" && rec->received.segments == 2 && re.Pending() == 0, "inbound: segment 1/2 completes the message");
|
Check(rec && rec->received.text == std::string(153, 'A') + "BBBBB" && rec->received.segments == 2 && re.Pending() == 0, "inbound: segment 1/2 completes the message");
|
||||||
Check(hasSms(r1.actions, SmsAction::Type::SendClient), "inbound: segment 1/2 acknowledged too");
|
Check(hasSms(r1.actions, SmsAction::Type::SendClient), "inbound: segment 1/2 acknowledged too");
|
||||||
|
|
@ -1648,8 +1673,8 @@ int main() {
|
||||||
Reassembler re;
|
Reassembler re;
|
||||||
const std::string u1 = "440B911316325476F80008620161220500808C0500032A0201" + rep("00FC", 66) + "D83D";
|
const std::string u1 = "440B911316325476F80008620161220500808C0500032A0201" + rep("00FC", 66) + "D83D";
|
||||||
const std::string u2 = "440B911316325476F8000862016122050080100500032A0202DE00" + rep("0078", 4);
|
const std::string u2 = "440B911316325476F8000862016122050080100500032A0202DE00" + rep("0078", 4);
|
||||||
auto a1 = OnSmsMessage(c, rng, inbound(std::format("011407911356131313F300{:02X}{}", u1.size() / 2, u1)), re, nullptr, 62.0);
|
auto a1 = OnSmsMessage(c, rng, inbound(std::format("011407911356131313F300{:02X}{}", u1.size() / 2, u1)), re, nullptr, sub, 62.0);
|
||||||
auto a2 = OnSmsMessage(c, rng, inbound(std::format("011507911356131313F300{:02X}{}", u2.size() / 2, u2)), re, nullptr, 63.0);
|
auto a2 = OnSmsMessage(c, rng, inbound(std::format("011507911356131313F300{:02X}{}", u2.size() / 2, u2)), re, nullptr, sub, 63.0);
|
||||||
const auto* w = findSms(a2.actions, SmsAction::Type::Received);
|
const auto* w = findSms(a2.actions, SmsAction::Type::Received);
|
||||||
Check(!hasSms(a1.actions, SmsAction::Type::Received) && w && w->received.text == rep("ü", 66) + "😀xxxx" && w->received.segments == 2 && re.Pending() == 0, "inbound: a surrogate pair split across segments reaches the bus whole");
|
Check(!hasSms(a1.actions, SmsAction::Type::Received) && w && w->received.text == rep("ü", 66) + "😀xxxx" && w->received.segments == 2 && re.Pending() == 0, "inbound: a surrogate pair split across segments reaches the bus whole");
|
||||||
}
|
}
|
||||||
|
|
@ -1657,7 +1682,7 @@ int main() {
|
||||||
{
|
{
|
||||||
imsd::util::Rng rng(82);
|
imsd::util::Rng rng(82);
|
||||||
Reassembler re;
|
Reassembler re;
|
||||||
auto r = OnSmsMessage(c, rng, inbound("011207911356131313F30019062A0B911316325476F8620161220500806201612205708000"), re, nullptr, 70.0);
|
auto r = OnSmsMessage(c, rng, inbound("011207911356131313F30019062A0B911316325476F8620161220500806201612205708000"), re, nullptr, sub, 70.0);
|
||||||
const auto* sr = findSms(r.actions, SmsAction::Type::StatusReport);
|
const auto* sr = findSms(r.actions, SmsAction::Type::StatusReport);
|
||||||
Check(sr && sr->report.mr == 0x2A && sr->report.status == 0 && !hasSms(r.actions, SmsAction::Type::Received) && hasSms(r.actions, SmsAction::Type::SendClient), "inbound: a status report is handed over and acknowledged");
|
Check(sr && sr->report.mr == 0x2A && sr->report.status == 0 && !hasSms(r.actions, SmsAction::Type::Received) && hasSms(r.actions, SmsAction::Type::SendClient), "inbound: a status report is handed over and acknowledged");
|
||||||
}
|
}
|
||||||
|
|
@ -1665,11 +1690,11 @@ int main() {
|
||||||
{
|
{
|
||||||
imsd::util::Rng rng(84);
|
imsd::util::Rng rng(84);
|
||||||
Reassembler re;
|
Reassembler re;
|
||||||
SmsOutbound m(c, rng, "ims-sms-11", p);
|
SmsOutbound m(c, rng, sub, "ims-sms-11", p);
|
||||||
auto a = m.Start(0.0);
|
auto a = m.Start(0.0);
|
||||||
const std::string callid(imsd::sip::Header(findSms(a, SmsAction::Type::SendClient)->text, "Call-ID").value_or(""));
|
const std::string callid(imsd::sip::Header(findSms(a, SmsAction::Type::SendClient)->text, "Call-ID").value_or(""));
|
||||||
Check(m.State() == SmsOutbound::Phase::Sending && m.OwnsReport(callid, std::nullopt), "outbound: a report is owned while the MESSAGE's final is still due");
|
Check(m.State() == SmsOutbound::Phase::Sending && m.OwnsReport(callid, std::nullopt), "outbound: a report is owned while the MESSAGE's final is still due");
|
||||||
auto r = OnSmsMessage(c, rng, inbound("0314", std::format("In-Reply-To: {}\r\n", callid)), re, &m, 1.0);
|
auto r = OnSmsMessage(c, rng, inbound("0314", std::format("In-Reply-To: {}\r\n", callid)), re, &m, sub, 1.0);
|
||||||
const auto* st = findSms(r.actions, SmsAction::Type::State);
|
const auto* st = findSms(r.actions, SmsAction::Type::State);
|
||||||
Check(r.response.starts_with("SIP/2.0 200 OK") && st && st->state == "sent" && m.Done() && !m.OwnsResponse(final(callid, 202, "Accepted")), "outbound: the early RP-ACK ends the message as sent; the late 202 is nobody's");
|
Check(r.response.starts_with("SIP/2.0 200 OK") && st && st->state == "sent" && m.Done() && !m.OwnsResponse(final(callid, 202, "Accepted")), "outbound: the early RP-ACK ends the message as sent; the late 202 is nobody's");
|
||||||
}
|
}
|
||||||
|
|
@ -1678,22 +1703,23 @@ int main() {
|
||||||
imsd::util::Rng rng(85);
|
imsd::util::Rng rng(85);
|
||||||
Reassembler re;
|
Reassembler re;
|
||||||
SmsOutbound::Params two = p; two.text = std::string(200, 'A');
|
SmsOutbound::Params two = p; two.text = std::string(200, 'A');
|
||||||
SmsOutbound m(c, rng, "ims-sms-12", two);
|
SmsOutbound m(c, rng, sub, "ims-sms-12", two);
|
||||||
auto a = m.Start(0.0);
|
auto a = m.Start(0.0);
|
||||||
const std::string callid1(imsd::sip::Header(findSms(a, SmsAction::Type::SendClient)->text, "Call-ID").value_or(""));
|
const std::string callid1(imsd::sip::Header(findSms(a, SmsAction::Type::SendClient)->text, "Call-ID").value_or(""));
|
||||||
auto r = OnSmsMessage(c, rng, inbound("0314", std::format("In-Reply-To: {}\r\n", callid1)), re, &m, 1.0);
|
auto r = OnSmsMessage(c, rng, inbound("0314", std::format("In-Reply-To: {}\r\n", callid1)), re, &m, sub, 1.0);
|
||||||
const auto* seg2 = findSms(r.actions, SmsAction::Type::SendClient);
|
const auto* seg2 = findSms(r.actions, SmsAction::Type::SendClient);
|
||||||
const std::string callid2 = seg2 ? std::string(imsd::sip::Header(seg2->text, "Call-ID").value_or("")) : std::string();
|
const std::string callid2 = seg2 ? std::string(imsd::sip::Header(seg2->text, "Call-ID").value_or("")) : std::string();
|
||||||
Check(seg2 && !callid2.empty() && callid2 != callid1 && m.State() == SmsOutbound::Phase::Sending && !m.OwnsResponse(final(callid1, 202, "Accepted")) && m.OwnsResponse(final(callid2, 202, "Accepted")), "outbound: segment 1's early RP-ACK sends segment 2 under its own Call-ID; segment 1's late 202 is nobody's");
|
Check(seg2 && !callid2.empty() && callid2 != callid1 && m.State() == SmsOutbound::Phase::Sending && !m.OwnsResponse(final(callid1, 202, "Accepted")) && m.OwnsResponse(final(callid2, 202, "Accepted")), "outbound: segment 1's early RP-ACK sends segment 2 under its own Call-ID; segment 1's late 202 is nobody's");
|
||||||
// a second report for segment 1 once segment 2 is out: 488, the message untouched
|
// a second report for segment 1 once segment 2 is out: ours on record, so 200 and the journal, the message untouched
|
||||||
auto rs = OnSmsMessage(c, rng, inbound("0314", std::format("In-Reply-To: {}\r\n", callid1)), re, &m, 2.0);
|
auto rs = OnSmsMessage(c, rng, inbound("0314", std::format("In-Reply-To: {}\r\n", callid1)), re, &m, sub, 2.0);
|
||||||
Check(rs.response.starts_with("SIP/2.0 488 Not Acceptable Here\r\n") && m.State() == SmsOutbound::Phase::Sending && m.OwnsResponse(final(callid2, 202, "Accepted")), "inbound: a report for segment 1 after segment 2 went out: 488, the message untouched");
|
const auto* late = findSms(rs.actions, SmsAction::Type::Log);
|
||||||
|
Check(rs.response.starts_with("SIP/2.0 200 OK\r\n") && rs.actions.size() == 1 && late && late->text == std::format("submit report (RP-ACK) In-Reply-To {}: sms ims-sms-12's segment 1/2, no longer in flight; 200", callid1) && m.State() == SmsOutbound::Phase::Sending && m.OwnsResponse(final(callid2, 202, "Accepted")), "inbound: a report for segment 1 after segment 2 went out: 200 and its line, the message untouched");
|
||||||
}
|
}
|
||||||
// a text past 255 segments to a valid number: failed at once, naming the fit
|
// a text past 255 segments to a valid number: failed at once, naming the fit
|
||||||
{
|
{
|
||||||
imsd::util::Rng rng(86);
|
imsd::util::Rng rng(86);
|
||||||
SmsOutbound::Params big = p; big.text = std::string(255 * 153 + 1, 'A');
|
SmsOutbound::Params big = p; big.text = std::string(255 * 153 + 1, 'A');
|
||||||
SmsOutbound m(c, rng, "ims-sms-13", big);
|
SmsOutbound m(c, rng, sub, "ims-sms-13", big);
|
||||||
auto a = m.Start(0.0);
|
auto a = m.Start(0.0);
|
||||||
const auto* st = findSms(a, SmsAction::Type::State);
|
const auto* st = findSms(a, SmsAction::Type::State);
|
||||||
Check(st && st->state == "failed" && st->reason.contains("does not fit 255 segments") && m.Done() && !hasSms(a, SmsAction::Type::SendClient), "outbound: a text past 255 segments fails at once, naming the fit");
|
Check(st && st->state == "failed" && st->reason.contains("does not fit 255 segments") && m.Done() && !hasSms(a, SmsAction::Type::SendClient), "outbound: a text past 255 segments fails at once, naming the fit");
|
||||||
|
|
@ -1709,7 +1735,7 @@ int main() {
|
||||||
if (i == std::string::npos || j == std::string::npos) return 1;
|
if (i == std::string::npos || j == std::string::npos) return 1;
|
||||||
msg.erase(i, pai.size());
|
msg.erase(i, pai.size());
|
||||||
msg.replace(msg.find(from), from.size(), "From: anonymous;tag=N1");
|
msg.replace(msg.find(from), from.size(), "From: anonymous;tag=N1");
|
||||||
auto r = OnSmsMessage(c, rng, msg, re, nullptr, 51.0);
|
auto r = OnSmsMessage(c, rng, msg, re, nullptr, sub, 51.0);
|
||||||
bool said = false;
|
bool said = false;
|
||||||
for (const auto& x : r.actions) if (x.type == SmsAction::Type::Log && x.text.contains("no P-Asserted-Identity or From URI")) said = true;
|
for (const auto& x : r.actions) if (x.type == SmsAction::Type::Log && x.text.contains("no P-Asserted-Identity or From URI")) said = true;
|
||||||
Check(r.response.starts_with("SIP/2.0 200 OK") && hasSms(r.actions, SmsAction::Type::Received) && !hasSms(r.actions, SmsAction::Type::SendClient) && r.reportCallId.empty() && said, "inbound: no gateway for the delivery report — the message handed over, the absence logged");
|
Check(r.response.starts_with("SIP/2.0 200 OK") && hasSms(r.actions, SmsAction::Type::Received) && !hasSms(r.actions, SmsAction::Type::SendClient) && r.reportCallId.empty() && said, "inbound: no gateway for the delivery report — the message handed over, the absence logged");
|
||||||
|
|
@ -1718,11 +1744,11 @@ int main() {
|
||||||
{
|
{
|
||||||
imsd::util::Rng rng(88);
|
imsd::util::Rng rng(88);
|
||||||
Reassembler re;
|
Reassembler re;
|
||||||
SmsOutbound m(c, rng, "ims-sms-14", p);
|
SmsOutbound m(c, rng, sub, "ims-sms-14", p);
|
||||||
auto a = m.Start(0.0);
|
auto a = m.Start(0.0);
|
||||||
const std::string callid(imsd::sip::Header(findSms(a, SmsAction::Type::SendClient)->text, "Call-ID").value_or(""));
|
const std::string callid(imsd::sip::Header(findSms(a, SmsAction::Type::SendClient)->text, "Call-ID").value_or(""));
|
||||||
m.OnResponse(final(callid, 202, "Accepted"), 202, 1.0);
|
m.OnResponse(final(callid, 202, "Accepted"), 202, 1.0);
|
||||||
auto r = OnSmsMessage(c, rng, inbound("0314"), re, &m, 2.0);
|
auto r = OnSmsMessage(c, rng, inbound("0314"), re, &m, sub, 2.0);
|
||||||
const auto* st = findSms(r.actions, SmsAction::Type::State);
|
const auto* st = findSms(r.actions, SmsAction::Type::State);
|
||||||
Check(r.response.starts_with("SIP/2.0 200 OK") && st && st->state == "sent" && m.Done() && r.reportCallId.empty(), "inbound: a submit report without In-Reply-To reaches the message in flight by RP-MR");
|
Check(r.response.starts_with("SIP/2.0 200 OK") && st && st->state == "sent" && m.Done() && r.reportCallId.empty(), "inbound: a submit report without In-Reply-To reaches the message in flight by RP-MR");
|
||||||
}
|
}
|
||||||
|
|
@ -1730,46 +1756,48 @@ int main() {
|
||||||
{
|
{
|
||||||
imsd::util::Rng rng(83);
|
imsd::util::Rng rng(83);
|
||||||
Reassembler re;
|
Reassembler re;
|
||||||
SmsOutbound m(c, rng, "ims-sms-10", p);
|
SmsOutbound m(c, rng, sub, "ims-sms-10", p);
|
||||||
auto a = m.Start(0.0);
|
auto a = m.Start(0.0);
|
||||||
const std::string callid(imsd::sip::Header(findSms(a, SmsAction::Type::SendClient)->text, "Call-ID").value_or(""));
|
const std::string callid(imsd::sip::Header(findSms(a, SmsAction::Type::SendClient)->text, "Call-ID").value_or(""));
|
||||||
m.OnResponse(final(callid, 202, "Accepted"), 202, 1.0);
|
m.OnResponse(final(callid, 202, "Accepted"), 202, 1.0);
|
||||||
auto r = OnSmsMessage(c, rng, inbound("0314", std::format("In-Reply-To: {}\r\n", callid)), re, &m, 2.0);
|
auto r = OnSmsMessage(c, rng, inbound("0314", std::format("In-Reply-To: {}\r\n", callid)), re, &m, sub, 2.0);
|
||||||
const auto* st = findSms(r.actions, SmsAction::Type::State);
|
const auto* st = findSms(r.actions, SmsAction::Type::State);
|
||||||
Check(r.response.starts_with("SIP/2.0 200 OK") && st && st->state == "sent" && m.Done() && r.reportCallId.empty(), "inbound: the submit report reaches the message in flight and is answered 200");
|
Check(r.response.starts_with("SIP/2.0 200 OK") && st && st->state == "sent" && m.Done() && r.reportCallId.empty(), "inbound: the submit report reaches the message in flight and is answered 200");
|
||||||
auto r2 = OnSmsMessage(c, rng, inbound("0314", "In-Reply-To: nobody@x\r\n"), re, &m, 3.0);
|
auto r2 = OnSmsMessage(c, rng, inbound("0314", "In-Reply-To: nobody@x\r\n"), re, &m, sub, 3.0);
|
||||||
Check(r2.response.starts_with("SIP/2.0 488 Not Acceptable Here\r\n") && hasSms(r2.actions, SmsAction::Type::Log), "inbound: a report In-Reply-To a MESSAGE that is not ours: 488");
|
Check(r2.response.starts_with("SIP/2.0 488 Not Acceptable Here\r\n") && r2.actions.size() == 1 && findSms(r2.actions, SmsAction::Type::Log) && findSms(r2.actions, SmsAction::Type::Log)->text == "submit report (RP-ACK) In-Reply-To nobody@x: no MESSAGE of ours on record; 488", "inbound: a report In-Reply-To a MESSAGE that is not ours: 488 and its line");
|
||||||
// a report for our own MESSAGE once the message has ended (here: sent): 488, as for a stranger's
|
// a report for our own MESSAGE once the message has ended (here: sent): 200, nothing but the journal's line — a stranger's got 488 above
|
||||||
auto r4 = OnSmsMessage(c, rng, inbound("0314", std::format("In-Reply-To: {}\r\n", callid)), re, &m, 3.5);
|
auto r4 = OnSmsMessage(c, rng, inbound("0314", std::format("In-Reply-To: {}\r\n", callid)), re, &m, sub, 3.5);
|
||||||
Check(r4.response.starts_with("SIP/2.0 488 Not Acceptable Here\r\n") && hasSms(r4.actions, SmsAction::Type::Log), "inbound: a report for our own MESSAGE after the message ended: 488");
|
const auto* l4 = findSms(r4.actions, SmsAction::Type::Log);
|
||||||
// and once the report's wait ended it (OnDeadline): 488 too
|
Check(r4.response.starts_with("SIP/2.0 200 OK\r\n") && r4.actions.size() == 1 && l4 && l4->text == std::format("submit report (RP-ACK) In-Reply-To {}: sms ims-sms-10's segment 1/1, no longer in flight; 200", callid), "inbound: a report for our own MESSAGE after the message ended: 200 and its line, nothing to the bus");
|
||||||
SmsOutbound m3(c, rng, "ims-sms-13", p);
|
// and once the report's wait ended it (OnDeadline), an RP-ERROR that comes after: 200, its cause in the line
|
||||||
|
SmsOutbound m3(c, rng, sub, "ims-sms-13", p);
|
||||||
auto a3 = m3.Start(10.0);
|
auto a3 = m3.Start(10.0);
|
||||||
const std::string callid3(imsd::sip::Header(findSms(a3, SmsAction::Type::SendClient)->text, "Call-ID").value_or(""));
|
const std::string callid3(imsd::sip::Header(findSms(a3, SmsAction::Type::SendClient)->text, "Call-ID").value_or(""));
|
||||||
m3.OnResponse(final(callid3, 202, "Accepted"), 202, 11.0);
|
m3.OnResponse(final(callid3, 202, "Accepted"), 202, 11.0);
|
||||||
m3.OnDeadline();
|
m3.OnDeadline();
|
||||||
auto r5 = OnSmsMessage(c, rng, inbound("0314", std::format("In-Reply-To: {}\r\n", callid3)), re, &m3, 60.0);
|
auto r5 = OnSmsMessage(c, rng, inbound("05140126410A01C30062016122050080", std::format("In-Reply-To: {}\r\n", callid3)), re, &m3, sub, 60.0);
|
||||||
Check(m3.Done() && r5.response.starts_with("SIP/2.0 488 Not Acceptable Here\r\n"), "inbound: a report for our own MESSAGE after its wait ended it: 488");
|
const auto* l5 = findSms(r5.actions, SmsAction::Type::Log);
|
||||||
auto r3 = OnSmsMessage(c, rng, inbound("0314"), re, nullptr, 4.0);
|
Check(m3.Done() && r5.response.starts_with("SIP/2.0 200 OK\r\n") && r5.actions.size() == 1 && l5 && l5->text == std::format("submit report (RP-ERROR, RP cause 38 (network out of order), TP-FCS 0xc3 (invalid SME address)) In-Reply-To {}: sms ims-sms-13's segment 1/1, no longer in flight; 200", callid3), "inbound: an RP-ERROR for our own MESSAGE after its wait ended the message: 200, its cause and TP-FCS in the line");
|
||||||
|
auto r3 = OnSmsMessage(c, rng, inbound("0314"), re, nullptr, sub, 4.0);
|
||||||
Check(r3.response.starts_with("SIP/2.0 200 OK") && hasSms(r3.actions, SmsAction::Type::Log) && !hasSms(r3.actions, SmsAction::Type::SendClient), "inbound: a report without In-Reply-To for no message: 200 and the log");
|
Check(r3.response.starts_with("SIP/2.0 200 OK") && hasSms(r3.actions, SmsAction::Type::Log) && !hasSms(r3.actions, SmsAction::Type::SendClient), "inbound: a report without In-Reply-To for no message: 200 and the log");
|
||||||
}
|
}
|
||||||
// an unusable TPDU, a body that is no RP message, another content type
|
// an unusable TPDU, a body that is no RP message, another content type
|
||||||
{
|
{
|
||||||
imsd::util::Rng rng(84);
|
imsd::util::Rng rng(84);
|
||||||
Reassembler re;
|
Reassembler re;
|
||||||
auto r = OnSmsMessage(c, rng, inbound("011507911356131313F30002FFFF"), re, nullptr, 5.0);
|
auto r = OnSmsMessage(c, rng, inbound("011507911356131313F30002FFFF"), re, nullptr, sub, 5.0);
|
||||||
const auto* rep = findSms(r.actions, SmsAction::Type::SendClient);
|
const auto* rep = findSms(r.actions, SmsAction::Type::SendClient);
|
||||||
Check(r.response.starts_with("SIP/2.0 200 OK") && rep && imsd::sip::Body(rep->text) == std::string("\x04\x15\x01\x60\x41\x03\x00\xB0\x00", 9) && !hasSms(r.actions, SmsAction::Type::Received), "inbound: an unusable TPDU is acknowledged with an RP-ERROR (cause 96, TP-FCS B0)");
|
Check(r.response.starts_with("SIP/2.0 200 OK") && rep && imsd::sip::Body(rep->text) == std::string("\x04\x15\x01\x60\x41\x03\x00\xB0\x00", 9) && !hasSms(r.actions, SmsAction::Type::Received), "inbound: an unusable TPDU is acknowledged with an RP-ERROR (cause 96, TP-FCS B0)");
|
||||||
auto rs = OnSmsMessage(c, rng, inbound("011607911356131313F3000102"), re, nullptr, 5.2);
|
auto rs = OnSmsMessage(c, rng, inbound("011607911356131313F3000102"), re, nullptr, sub, 5.2);
|
||||||
const auto* reps = findSms(rs.actions, SmsAction::Type::SendClient);
|
const auto* reps = findSms(rs.actions, SmsAction::Type::SendClient);
|
||||||
Check(rs.response.starts_with("SIP/2.0 200 OK") && reps && imsd::sip::Body(reps->text) == std::string("\x04\x16\x01\x60\x41\x03\x00\xB0\x00", 9) && !hasSms(rs.actions, SmsAction::Type::StatusReport), "inbound: a status report that does not parse gets the same RP-ERROR");
|
Check(rs.response.starts_with("SIP/2.0 200 OK") && reps && imsd::sip::Body(reps->text) == std::string("\x04\x16\x01\x60\x41\x03\x00\xB0\x00", 9) && !hasSms(rs.actions, SmsAction::Type::StatusReport), "inbound: a status report that does not parse gets the same RP-ERROR");
|
||||||
auto rt = OnSmsMessage(c, rng, inbound("011707911356131313F300020100"), re, nullptr, 5.4);
|
auto rt = OnSmsMessage(c, rng, inbound("011707911356131313F300020100"), re, nullptr, sub, 5.4);
|
||||||
const auto* rept = findSms(rt.actions, SmsAction::Type::SendClient);
|
const auto* rept = findSms(rt.actions, SmsAction::Type::SendClient);
|
||||||
Check(rt.response.starts_with("SIP/2.0 200 OK") && rept && imsd::sip::Body(rept->text) == std::string("\x04\x17\x01\x60\x41\x03\x00\xB0\x00", 9) && !hasSms(rt.actions, SmsAction::Type::Received), "inbound: a TPDU of the submit-report type gets the same RP-ERROR");
|
Check(rt.response.starts_with("SIP/2.0 200 OK") && rept && imsd::sip::Body(rept->text) == std::string("\x04\x17\x01\x60\x41\x03\x00\xB0\x00", 9) && !hasSms(rt.actions, SmsAction::Type::Received), "inbound: a TPDU of the submit-report type gets the same RP-ERROR");
|
||||||
auto r2 = OnSmsMessage(c, rng, inbound("07"), re, nullptr, 6.0);
|
auto r2 = OnSmsMessage(c, rng, inbound("07"), re, nullptr, sub, 6.0);
|
||||||
Check(r2.response.starts_with("SIP/2.0 200 OK") && !r2.rp && hasSms(r2.actions, SmsAction::Type::Log) && !hasSms(r2.actions, SmsAction::Type::SendClient), "inbound: a body that is no RP message: 200 and the log");
|
Check(r2.response.starts_with("SIP/2.0 200 OK") && !r2.rp && hasSms(r2.actions, SmsAction::Type::Log) && !hasSms(r2.actions, SmsAction::Type::SendClient), "inbound: a body that is no RP message: 200 and the log");
|
||||||
const std::string plain = "MESSAGE sip:me@ims SIP/2.0\r\nVia: SIP/2.0/TCP [2001:db8::105]:6000;branch=z9hG4bKn2\r\nFrom: <sip:x@ims>;tag=1\r\nTo: <sip:me@ims>\r\nCall-ID: t1@net\r\nCSeq: 1 MESSAGE\r\nContent-Type: text/plain\r\nContent-Length: 2\r\n\r\nhi";
|
const std::string plain = "MESSAGE sip:me@ims SIP/2.0\r\nVia: SIP/2.0/TCP [2001:db8::105]:6000;branch=z9hG4bKn2\r\nFrom: <sip:x@ims>;tag=1\r\nTo: <sip:me@ims>\r\nCall-ID: t1@net\r\nCSeq: 1 MESSAGE\r\nContent-Type: text/plain\r\nContent-Length: 2\r\n\r\nhi";
|
||||||
auto r3 = OnSmsMessage(c, rng, plain, re, nullptr, 7.0);
|
auto r3 = OnSmsMessage(c, rng, plain, re, nullptr, sub, 7.0);
|
||||||
Check(r3.response.starts_with("SIP/2.0 200 OK") && !r3.rp && hasSms(r3.actions, SmsAction::Type::Log) && findSms(r3.actions, SmsAction::Type::Log)->text.contains("hi"), "inbound: a page-mode text is 200'd and logged with its body");
|
Check(r3.response.starts_with("SIP/2.0 200 OK") && !r3.rp && hasSms(r3.actions, SmsAction::Type::Log) && findSms(r3.actions, SmsAction::Type::Log)->text.contains("hi"), "inbound: a page-mode text is 200'd and logged with its body");
|
||||||
}
|
}
|
||||||
// the store's record codec
|
// the store's record codec
|
||||||
|
|
@ -1831,15 +1859,15 @@ int main() {
|
||||||
off.aor = c.aor;
|
off.aor = c.aor;
|
||||||
const std::string_view offeredHex = "011107911356131313F3001E040B911346610089F60000208062917314080CC8F71D14969741F977FD07";
|
const std::string_view offeredHex = "011107911356131313F3001E040B911346610089F60000208062917314080CC8F71D14969741F977FD07";
|
||||||
const std::string offered = inbound(offeredHex);
|
const std::string offered = inbound(offeredHex);
|
||||||
auto r = OnSmsMessage(off, rng, offered, re, nullptr, 8.0);
|
auto r = OnSmsMessage(off, rng, offered, re, nullptr, sub, 8.0);
|
||||||
Check(r.response.starts_with("SIP/2.0 480 Temporarily Unavailable\r\n") && r.response.contains("Call-ID: in-011107@net\r\n"), "off: a short message is refused with 480");
|
Check(r.response.starts_with("SIP/2.0 480 Temporarily Unavailable\r\n") && r.response.contains("Call-ID: in-011107@net\r\n"), "off: a short message is refused with 480");
|
||||||
Check(!hasSms(r.actions, SmsAction::Type::Received) && !hasSms(r.actions, SmsAction::Type::SendClient) && r.reportCallId.empty() && !r.rp && re.Pending() == 0, "off: nothing to the bus, no delivery report, nothing parsed");
|
Check(!hasSms(r.actions, SmsAction::Type::Received) && !hasSms(r.actions, SmsAction::Type::SendClient) && r.reportCallId.empty() && !r.rp && re.Pending() == 0, "off: nothing to the bus, no delivery report, nothing parsed");
|
||||||
const auto* log = findSms(r.actions, SmsAction::Type::Log);
|
const auto* log = findSms(r.actions, SmsAction::Type::Log);
|
||||||
Check(log && log->text.ends_with("while SMS_OVER_IMS is off: 480") && !log->text.contains("How are you") && !log->text.contains(std::string_view(offered).substr(offered.find("\r\n\r\n") + 4)) && !log->text.contains(imsd::util::ToHex(*imsd::util::FromHex(offeredHex))), "off: logged with a line that ends at the 480, without the text, the body or its hex");
|
Check(log && log->text.ends_with("while SMS_OVER_IMS is off: 480") && !log->text.contains("How are you") && !log->text.contains(std::string_view(offered).substr(offered.find("\r\n\r\n") + 4)) && !log->text.contains(imsd::util::ToHex(*imsd::util::FromHex(offeredHex))), "off: logged with a line that ends at the 480, without the text, the body or its hex");
|
||||||
const std::string plain = "MESSAGE sip:me@ims SIP/2.0\r\nVia: SIP/2.0/TCP [2001:db8::105]:6000;branch=z9hG4bKn3\r\nFrom: <sip:x@ims>;tag=1\r\nTo: <sip:me@ims>\r\nCall-ID: t2@net\r\nCSeq: 1 MESSAGE\r\nContent-Type: text/plain\r\nContent-Length: 2\r\n\r\nhi";
|
const std::string plain = "MESSAGE sip:me@ims SIP/2.0\r\nVia: SIP/2.0/TCP [2001:db8::105]:6000;branch=z9hG4bKn3\r\nFrom: <sip:x@ims>;tag=1\r\nTo: <sip:me@ims>\r\nCall-ID: t2@net\r\nCSeq: 1 MESSAGE\r\nContent-Type: text/plain\r\nContent-Length: 2\r\n\r\nhi";
|
||||||
auto r2 = OnSmsMessage(off, rng, plain, re, nullptr, 9.0);
|
auto r2 = OnSmsMessage(off, rng, plain, re, nullptr, sub, 9.0);
|
||||||
Check(r2.response.starts_with("SIP/2.0 200 OK") && hasSms(r2.actions, SmsAction::Type::Log), "off: a page-mode text is still 200'd and logged");
|
Check(r2.response.starts_with("SIP/2.0 200 OK") && hasSms(r2.actions, SmsAction::Type::Log), "off: a page-mode text is still 200'd and logged");
|
||||||
auto r3 = OnSmsMessage(off, rng, Compact(offered), re, nullptr, 9.5);
|
auto r3 = OnSmsMessage(off, rng, Compact(offered), re, nullptr, sub, 9.5);
|
||||||
Check(r3.response.starts_with("SIP/2.0 480 Temporarily Unavailable\r\n") && r3.response.contains("\r\nCall-ID: in-011107@net\r\n") && !r3.rp, "off: a short message whose content type comes as `c:` is refused with 480 too");
|
Check(r3.response.starts_with("SIP/2.0 480 Temporarily Unavailable\r\n") && r3.response.contains("\r\nCall-ID: in-011107@net\r\n") && !r3.rp, "off: a short message whose content type comes as `c:` is refused with 480 too");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue