sip: ResponseOf compares a response's CSeq as its number and its method
ResponseOf matched a response to a request by its Call-ID and by its CSeq compared as text. RFC 3261 25.1 writes the CSeq as 1*DIGIT LWS Method, so a response may part the two by a tab or by more than one space, and one written so was no transaction's: a REGISTER's wait ran out without a reply. CSeqParts takes a CSeq value as its number and its method: the digits it begins with, the spaces or tabs after them, the method to the value's end. ResponseOf compares the two as 20.16 has two CSeqs equal, "if the sequence number and the request method are identical": the number as a number — zeros before it do not make it another — and the method to the letter. A value of another shape matches nothing. Tested by tests/Sip: a final whose CSeq has two spaces, a tab or both between its parts, or zeros before its number, is the transaction's, and so is its 100 Trying; another number, another method, a method in other letter case, and a CSeq without its number, its method or the white space between them are not.
This commit is contained in:
parent
1267fe1ada
commit
78c702546a
3 changed files with 50 additions and 4 deletions
|
|
@ -136,6 +136,21 @@ namespace imsd::sip {
|
|||
if (ec != std::errc{}) return std::nullopt;
|
||||
return v;
|
||||
}
|
||||
|
||||
// A CSeq value as its sequence number and its method (RFC 3261 25.1:
|
||||
// 1*DIGIT LWS Method): the digits the trimmed value begins with, less
|
||||
// the zeros before the number, the spaces or tabs after them, then the
|
||||
// method to the value's end. nullopt where no space or tab follows the
|
||||
// digits.
|
||||
std::optional<std::pair<std::string_view, std::string_view>> CSeqParts(std::string_view v) {
|
||||
v = Trim(v);
|
||||
const std::size_t digits = v.find_first_not_of("0123456789");
|
||||
const std::size_t method = v.find_first_not_of(" \t", digits);
|
||||
if (method == digits) return std::nullopt;
|
||||
std::string_view number = v.substr(0, digits);
|
||||
while (number.starts_with('0')) number.remove_prefix(1);
|
||||
return std::pair{number, v.substr(method)};
|
||||
}
|
||||
}
|
||||
|
||||
export namespace imsd::sip {
|
||||
|
|
@ -178,9 +193,16 @@ export namespace imsd::sip {
|
|||
|
||||
// True for a response of the transaction (callid, cseq) — the reply a
|
||||
// wait for that request may judge. A request, another transaction's
|
||||
// response or anything else a socket delivers is not.
|
||||
// response or anything else a socket delivers is not. Two CSeqs are
|
||||
// equal "if the sequence number and the request method are identical"
|
||||
// (RFC 3261 20.16): they are compared so, whatever spaces or tabs part
|
||||
// the two and whatever zeros stand before the number.
|
||||
bool ResponseOf(std::string_view msg, std::string_view callid, std::string_view cseq) {
|
||||
return Status(msg).has_value() && Header(msg, "Call-ID") == callid && Header(msg, "CSeq") == cseq;
|
||||
if (!Status(msg).has_value() || Header(msg, "Call-ID") != callid) return false;
|
||||
const auto theirs = Header(msg, "CSeq");
|
||||
if (!theirs) return false;
|
||||
const auto a = CSeqParts(*theirs), b = CSeqParts(cseq);
|
||||
return a && b && *a == *b;
|
||||
}
|
||||
|
||||
// Retry-After of a response (RFC 3261 20.33), in seconds; nullopt when
|
||||
|
|
|
|||
Loading…
Reference in a new issue