Parse native PJSIP endpoint names with caller display
This commit is contained in:
@@ -41,7 +41,9 @@ type appliedState struct {
|
||||
Trunks []loadedTrunk `json:"trunks"`
|
||||
}
|
||||
|
||||
var endpointLine = regexp.MustCompile(`(?m)^\s*Endpoint:\s+(\S+)`)
|
||||
// Asterisk prints Endpoint: <name>/<caller-id>; the slash and caller ID are
|
||||
// display metadata, not part of the configured endpoint name.
|
||||
var endpointLine = regexp.MustCompile(`(?m)^[ \t]*Endpoint:[ \t]+([^/< \t\r\n]+)(?:/[^ \t\r\n]+)?`)
|
||||
|
||||
func endpointOption(output []byte, name string) string {
|
||||
for line := range strings.SplitSeq(string(output), "\n") {
|
||||
|
||||
@@ -18,7 +18,7 @@ func TestLoaderPersistsOnlyVerifiedNativeReload(t *testing.T) {
|
||||
script := `#!/bin/sh
|
||||
case "$*" in
|
||||
*"pjsip show transports"*) echo 'Transport: go-sip-udp udp 0 0 0.0.0.0:5060' ;;
|
||||
*"pjsip show endpoints"*) echo 'Endpoint: <Endpoint/CID> <State> <Channels>'; echo 'Endpoint: trunk-shuqi Not in use' ;;
|
||||
*"pjsip show endpoints"*) echo 'Endpoint: <Endpoint/CID> <State> <Channels>'; echo 'Endpoint: trunk-shuqi/BD93205882 Not in use' ;;
|
||||
*"pjsip show endpoint trunk-shuqi"*) echo 'Aor: trunk-shuqi-aor allow: alaw transport: go-sip-udp context: go-sip-no-inbound'; echo 'from_user : BD93205882'; echo 'callerid : "BD93205882" <BD93205882>' ;;
|
||||
*"pjsip show aor trunk-shuqi-aor"*) echo 'Contact: sip:61.132.228.221:5060' ;;
|
||||
*) exit 9 ;;
|
||||
@@ -99,6 +99,14 @@ esac
|
||||
}
|
||||
}
|
||||
|
||||
func TestEndpointReadbackSeparatesCallerDisplayFromEndpointName(t *testing.T) {
|
||||
output := []byte(" Endpoint: <Endpoint/CID...> <State>\n Endpoint: trunk-shuqi/BD93205882 Not in use\n Endpoint: trunk-foreign/other Not in use\n")
|
||||
matches := endpointLine.FindAllSubmatch(output, -1)
|
||||
if len(matches) != 2 || string(matches[0][1]) != "trunk-shuqi" || string(matches[1][1]) != "trunk-foreign" {
|
||||
t.Fatalf("invalid endpoint names from native Asterisk listing: %q", matches)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoaderFailsClosedWithoutApprovedStaticTransport(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
loader := Loader{ConfigDir: dir, Asterisk: "/bin/true", LibraryDir: dir}
|
||||
|
||||
Reference in New Issue
Block a user