Skip to content
This repository has been archived by the owner on Jan 24, 2023. It is now read-only.

Commit

Permalink
revert user-fetching in GetSourceAndDestination()
Browse files Browse the repository at this point in the history
in order to determine the user, we need CallInSession.GetDirection()
and not Call.GetDirection(), so the user cannot be set inside of
GetSourceAndDestination().
  • Loading branch information
costela committed May 29, 2019
1 parent 39cf83a commit fc3f607
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
15 changes: 6 additions & 9 deletions innovaphone/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (h Hold) String() string {
}

// GetSourceAndDestination returns the call's source and destination
func (call *CallInfo) GetSourceAndDestination() (src, dst *No, user string, err error) {
func (call *CallInfo) GetSourceAndDestination() (src, dst *No, err error) {
for _, no := range call.No {
switch no.Type {
case "this":
Expand All @@ -120,18 +120,15 @@ func (call *CallInfo) GetSourceAndDestination() (src, dst *No, user string, err
}
}

if call.GetDirection() == DirectionInbound {
src, dst = dst, src
user = src.Cn
} else {
user = dst.Cn
if src == nil || dst == nil {
return nil, nil, fmt.Errorf("call without src (%v) or dst (%v)", src, dst)
}

if src == nil || dst == nil {
return nil, nil, "", fmt.Errorf("call without src (%v) or dst (%v)", src, dst)
if call.GetDirection() == DirectionInbound {
src, dst = dst, src
}

return src, dst, user, nil
return src, dst, nil
}

// GetState returns the call's state
Expand Down
5 changes: 2 additions & 3 deletions innovaphone/innovaphone.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (session *Session) PollForever() (<-chan *CallInSession, <-chan error) {
sessionInterface: session,
CallInfo: call,
}
src, dst, user, err := cis.GetSourceAndDestination()
src, dst, err := cis.GetSourceAndDestination()
if err != nil {
logrus.WithField("call", call).Warn(err)
continue
Expand All @@ -149,7 +149,6 @@ func (session *Session) PollForever() (<-chan *CallInSession, <-chan error) {
"call": call,
"source": src.Normalize(),
"dest": dst.Normalize(),
"user": user,
"direction": dir,
"state": cis.GetState(),
"hold": cis.GetHold(),
Expand Down Expand Up @@ -196,7 +195,7 @@ type userCacheEntry struct {
// ShouldHandle decides whether a call involves any of the groups being filtered on (see Config.FilterOnGroup)
func (call *CallInSession) ShouldHandle() bool {
if config.Global.PBX.FilterOnGroup != "" {
src, dst, _, err := call.GetSourceAndDestination()
src, dst, err := call.GetSourceAndDestination()
if err != nil {
logrus.WithField("call", call).Warn(err)
return false
Expand Down
11 changes: 10 additions & 1 deletion zammad/zammad.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (zs *Session) ShutdownIfEmpty() {
func (zs *Session) Submit(ctx context.Context, call *innovaphone.CallInSession) error {
zs.stats.Add("events_total", 1)

src, dst, user, err := call.GetSourceAndDestination()
src, dst, err := call.GetSourceAndDestination()
if err != nil {
return err
}
Expand Down Expand Up @@ -169,6 +169,15 @@ func (zs *Session) Submit(ctx context.Context, call *innovaphone.CallInSession)
"direction": []string{dir.String()},
}

// "dir" here is session-based, not call-based
var user string
switch dir {
case innovaphone.DirectionInbound:
user = dst.Cn
case innovaphone.DirectionOutbound:
user = src.Cn
}

transition := stateTransition{curState: entry.State, newState: newState}
switch transition {
case
Expand Down

0 comments on commit fc3f607

Please sign in to comment.