Skip to content

Commit

Permalink
Merge pull request #73 from luebke-dev/master
Browse files Browse the repository at this point in the history
allow extracting the called number from the sip diversion header
  • Loading branch information
markuslindenberg authored Dec 15, 2023
2 parents dc7fca8 + fd66d76 commit 851a868
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
3 changes: 3 additions & 0 deletions gofax.conf
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ enablet38 = true
; Send a T.38-ReINVITE when a fax was detected by tone detection while receiving (FreeSWITCH: fax_enable_t38_request)
requestt38 = true

; Extract the recipient from the sip diversion header
recipientfromdiversionheader = false

; Wait before answering a incoming call (ms)
answerafter = 2000

Expand Down
28 changes: 27 additions & 1 deletion gofaxd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"os"
"os/exec"
"path/filepath"
"regexp"
"strconv"

"github.com/gonicus/gofaxip/gofaxlib"
Expand Down Expand Up @@ -52,6 +53,19 @@ func NewEventSocketServer() *EventSocketServer {
return e
}

func getNumberFromSIPURI(uri string) (string, error) {
re := regexp.MustCompile(`sip:(\d+)@`)

matches := re.FindStringSubmatch(uri)

if len(matches) < 2 {
return "", fmt.Errorf("Number could not be extracted from SIP URI")
}

number := matches[1]
return number, nil
}

// Start starts a goroutine to listen for ESL connections and handle incoming calls
func (e *EventSocketServer) Start() {
go func() {
Expand Down Expand Up @@ -101,8 +115,20 @@ func (e *EventSocketServer) handler(c *eventsocket.Connection) {
c.Send("event plain CHANNEL_CALLSTATE CUSTOM spandsp::rxfaxnegociateresult spandsp::rxfaxpageresult spandsp::rxfaxresult")

// Extract Caller/Callee
var recipient string
if gofaxlib.Config.Gofaxd.RecipientFromDiversionHeader {
recipient, err = getNumberFromSIPURI(connectev.Get("Variable_sip_h_diversion"))
if err != nil {
logger.Logger.Println(err)
c.Execute("respond", "404", true)
c.Send("exit")
return
}
} else {
recipient = connectev.Get("Variable_sip_to_user")
}

gateway := connectev.Get("Variable_sip_gateway")
recipient := connectev.Get("Variable_sip_to_user")
cidname := connectev.Get("Channel-Caller-Id-Name")
cidnum := connectev.Get("Channel-Caller-Id-Number")

Expand Down
17 changes: 9 additions & 8 deletions gofaxlib/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,15 @@ type config struct {
Xferfaxlog string
}
Gofaxd struct {
EnableT38 bool
RequestT38 bool
Socket string
Answerafter uint64
Waittime uint64
FaxRcvdCmd string
DynamicConfig string
AllocateInboundDevices bool
EnableT38 bool
RequestT38 bool
RecipientFromDiversionHeader bool
Socket string
Answerafter uint64
Waittime uint64
FaxRcvdCmd string
DynamicConfig string
AllocateInboundDevices bool
}
Gofaxsend struct {
EnableT38 bool
Expand Down

0 comments on commit 851a868

Please sign in to comment.