mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-27 05:15:47 +00:00
return error if dtmf create results in invalid characters
This commit is contained in:
@@ -4,16 +4,18 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"regexp"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"github.com/jwetzell/showbridge-go/internal/config"
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SipResponseDTMFCreate struct {
|
type SipResponseDTMFCreate struct {
|
||||||
config config.ProcessorConfig
|
config config.ProcessorConfig
|
||||||
PreWait int
|
PreWait int
|
||||||
PostWait int
|
PostWait int
|
||||||
Digits *template.Template
|
Digits *template.Template
|
||||||
|
validDTMF *regexp.Regexp
|
||||||
}
|
}
|
||||||
|
|
||||||
type SipDTMFResponse struct {
|
type SipDTMFResponse struct {
|
||||||
@@ -33,6 +35,10 @@ func (scc *SipResponseDTMFCreate) Process(ctx context.Context, payload any) (any
|
|||||||
|
|
||||||
digitsString := digitsBuffer.String()
|
digitsString := digitsBuffer.String()
|
||||||
|
|
||||||
|
if !scc.validDTMF.MatchString(digitsString) {
|
||||||
|
return nil, errors.New("sip.response.dtmf.create result of digits template contains invalid characters")
|
||||||
|
}
|
||||||
|
|
||||||
return SipDTMFResponse{
|
return SipDTMFResponse{
|
||||||
PreWait: scc.PreWait,
|
PreWait: scc.PreWait,
|
||||||
PostWait: scc.PostWait,
|
PostWait: scc.PostWait,
|
||||||
@@ -91,7 +97,7 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &SipResponseDTMFCreate{config: config, Digits: digitsTemplate, PreWait: int(preWaitNum), PostWait: int(postWaitNum)}, nil
|
return &SipResponseDTMFCreate{config: config, Digits: digitsTemplate, PreWait: int(preWaitNum), PostWait: int(postWaitNum), validDTMF: regexp.MustCompile(`^[0-9*#A-Da-d]+$`)}, nil
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user