mirror of
https://github.com/yibaiba/hideck.git
synced 2026-12-06 16:01:13 +00:00
fix(ussi): handle typed-nil SIP messages after INVITE failure
This commit is contained in:
1 parent
5b2aa762a5
commit
e63efc09f3
3 files changed
+50
-3
No files matched your search
+13
-2
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func logUSSISIPRaw(deviceID, phase, direction string, message sip.Message) {
|
||||
if message == nil {
|
||||
if isNilSIPMessage(message) {
|
||||
return
|
||||
}
|
||||
raw := strings.TrimSpace(message.String())
|
||||
@@ -28,7 +28,7 @@ func logUSSISIPRaw(deviceID, phase, direction string, message sip.Message) {
|
||||
}
|
||||
|
||||
func ussiSIPRawLogMethodAndCallID(message sip.Message) (string, string) {
|
||||
if message == nil {
|
||||
if isNilSIPMessage(message) {
|
||||
return "", ""
|
||||
}
|
||||
method := ""
|
||||
@@ -47,6 +47,17 @@ func ussiSIPRawLogMethodAndCallID(message sip.Message) (string, string) {
|
||||
return method, callID
|
||||
}
|
||||
|
||||
func isNilSIPMessage(message sip.Message) bool {
|
||||
switch value := message.(type) {
|
||||
case *sip.Request:
|
||||
return value == nil
|
||||
case *sip.Response:
|
||||
return value == nil
|
||||
default:
|
||||
return message == nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Service) logInboundMismatch(phase, reason string, request *sip.Request) {
|
||||
method := ""
|
||||
if request != nil {
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ func (s *Service) Send(ctx context.Context, command string) (*Result, error) {
|
||||
imsendpoint.ClientInviteOptions{
|
||||
Request: request, Contact: request.Contact(), Timeout: int64(ussiTransactionTimeout),
|
||||
})
|
||||
if invite != nil {
|
||||
if invite != nil && invite.Response != nil {
|
||||
logUSSISIPRaw(s.deviceID, "initial_invite", "recv", invite.Response)
|
||||
}
|
||||
if err != nil {
|
||||
|
||||
@@ -18,6 +18,42 @@ const (
|
||||
finalText = "Balance: 10"
|
||||
)
|
||||
|
||||
func TestUSSILogTypedNil(t *testing.T) {
|
||||
for _, message := range []sip.Message{nil, (*sip.Request)(nil), (*sip.Response)(nil)} {
|
||||
logUSSISIPRaw("test", "recv", "recv", message)
|
||||
method, callID := ussiSIPRawLogMethodAndCallID(message)
|
||||
if method != "" || callID != "" {
|
||||
t.Fatalf("nil message metadata = %q %q", method, callID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type failedInviteEndpoint struct {
|
||||
*fakeEndpoint
|
||||
cause error
|
||||
}
|
||||
|
||||
func (endpoint *failedInviteEndpoint) StartClientInvite(context.Context, string, imsendpoint.ClientInviteOptions) (*imsendpoint.ClientInviteResult, error) {
|
||||
return &imsendpoint.ClientInviteResult{}, endpoint.cause
|
||||
}
|
||||
|
||||
func TestSendInviteWithoutResponse(t *testing.T) {
|
||||
for _, cause := range []error{errors.New("SIP stream closed"), nil} {
|
||||
endpoint := &failedInviteEndpoint{fakeEndpoint: newFakeEndpoint(t), cause: cause}
|
||||
service := NewService("dev-1", endpoint)
|
||||
result, err := service.Send(context.Background(), "*100#")
|
||||
if err == nil || result == nil || result.Status != 2 {
|
||||
t.Fatalf("result=%+v err=%v", result, err)
|
||||
}
|
||||
if cause != nil && !errors.Is(err, cause) {
|
||||
t.Fatalf("lost original failure: %v", err)
|
||||
}
|
||||
if service.ActiveSessionID() != "" {
|
||||
t.Fatal("failed session still active")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRecoveredTypeLayouts(t *testing.T) {
|
||||
assertFields(t, reflect.TypeOf(Context{}), []string{
|
||||
"LocalIP", "LocalPortC", "LocalPortS", "Transport", "Domain", "Realm", "AOR",
|
||||
|
||||
Reference in new issue
Block a user