xivo/asterisk: allow dots in channel interfaces - #191
Conversation
The interface character class rejected `.`, so any channel whose exten or
context contains a dot failed to match and raised InvalidChannelError.
Sanitized examples of the two reported shapes:
Local/.98@default-key-0000-internal-00003196;1
Local/01.23.45.67.89@default-key-xxxxx-internal-00006c75;1
The second is a French number dialed with dot separators, which is how the
partner reported it (BUG-123 / WP-1576).
In wazo-call-logd this is reached through _remove_duplicate_participants().
It used to abort the whole wazo-call-logs run, which is what the reported
traceback shows; since the per-linkedid try/except it only drops the
affected group, so those calls now silently produce no CDR instead.
`.` joins `*`, `+`, `#` and `|`, which were each added the same way.
Backtracking is unchanged: the interface still resolves to exten@context,
splitting at the last `-` before the uniqueid.
device_regexp has the same gap but is left alone here: it parses dialplan
hints, and it uses .match() rather than .search(), so a dotted value
truncates silently rather than raising.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Build succeeded. ✔️ wazo-tox-py311 SUCCESS in 2m 52s |
|
I propose generalizing the regex to concern itself with the relevant expectations on channel syntax. The important requirements based on existing usages (wazo-calld, wazo-call-logd):
We don't need to constraint the character set of the endpoint resource, and we don't need to know all the possible formats of channel-type-specific resources, as long as we can distinguish the identifier of the endpoint and the channel-specific suffixes. My suggestion: try this regex against existing test cases in xivo-lib-python. To be safe, we can run wazo-calld and wazo-call-logd integration tests against this PR as well (dummy PRs with depends-on). |
|
Also note: we'll eventually want to support the |
Rather than whitelisting the characters a channel resource may contain -- a list that has grown one fix at a time, most recently for dots -- match on the structure Asterisk actually guarantees: the technology prefix, and the discriminator each channel driver appends to make the name unique. Whatever lies between them is the resource, unconstrained. The discriminator is per-driver, not central; ast_channel_alloc takes it as name_fmt from the caller. Anchoring on it means -<uniqueid> in hex (PJSIP and Local '%08x', DAHDI '%x', IAX2 a decimal call number), plus ;<leg> for the two halves of a local channel, and /%p for chan_websocket, which appends the channel pointer after a slash instead of a uniqueid. Requiring the discriminator makes the match stricter than before: a suffix-less string such as PJSIP/my-line now raises InvalidChannelError where it used to yield the truncated interface 'my'. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Build succeeded. ✔️ wazo-tox-py311 SUCCESS in 2m 34s |
Did the fixes and ran tests on both repos. Had to fix 3 tests fixtures in wazo-call-logd because the format used was invalid: wazo-platform/wazo-call-logd#301 |
DrPyser
left a comment
There was a problem hiding this comment.
LGTM, tested on my stack and could validate that . and WebSocket channels do not produce errors anymore.
Only channels in form "CLIEval/2" produce InvalidChannelError, but that does not matter for now (those are channels resulting from asterisk CLI function evaluation for debugging purposes).
Thank you! Hopefully we stop seeing that kind of issues.
|
Build succeeded (gate pipeline). ✔️ wazo-tox-py311 SUCCESS in 2m 40s |
The interface character class rejected
., so any channel whose exten or context contains a dot failed to match and raised InvalidChannelError. Sanitized examples of the two reported shapes:The second is a French number dialed with dot separators, which is how the partner reported it (BUG-123 / WP-1576).
In wazo-call-logd this is reached through _remove_duplicate_participants(). It used to abort the whole wazo-call-logs run, which is what the reported traceback shows; since the per-linkedid try/except it only drops the affected group, so those calls now silently produce no CDR instead.
.joins*,+,#and|, which were each added the same way. Backtracking is unchanged: the interface still resolves to exten@context, splitting at the last-before the uniqueid.device_regexp has the same gap but is left alone here: it parses dialplan hints, and it uses .match() rather than .search(), so a dotted value truncates silently rather than raising.
Note
Medium Risk
Shared channel parsing regex changes how real Asterisk channel names are accepted or rejected, which affects downstream call-log/CDR flows; behavior is tightened at the end anchor but broadened for resource characters.
Overview
Fixes
InvalidChannelErrorfor Asterisk channel strings whose resource (exten/context) contains dots or other characters outside the oldchannel_regexpclass—including reportedLocal/.98@…and dot-separated French number shapes.channel_regexpis rewritten to treat the resource as unconstrained(.+)and to anchor the suffix as either the usual-<hex uniqueid>(optional;<leg>for Local) or WebSocket’s/0x<pointer>.websocketis added as a technology. Inline comments document how drivers build channel names.Channels without a valid discriminator (e.g.
PJSIP/my-line) are now explicitly rejected.device_regexpis unchanged in this PR.Tests cover dots, dotted numbers, IAX2 resources with
%/!, WebSocket channels, and missing uniqueids.Reviewed by Cursor Bugbot for commit 593ec55. Bugbot is set up for automated code reviews on this repo. Configure here.