Skip to content

Commit

Permalink
Merge pull request #49 from markuslindenberg/master
Browse files Browse the repository at this point in the history
Add ability to override dialstring variables for destinations using mod_db entries
  • Loading branch information
denzs authored Dec 10, 2019
2 parents a6508f2 + 479139d commit b278648
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
12 changes: 12 additions & 0 deletions gofaxlib/fsdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package gofaxlib

import (
"fmt"
"strings"

"github.com/fiorix/go-eventsocket/eventsocket"
)

Expand Down Expand Up @@ -41,3 +43,13 @@ func FreeSwitchDBExists(c *eventsocket.Connection, realm string, key string) (bo

return result.Body == "true", nil
}

// FreeSwitchDBList returns a list of all keys in given realm
// If realm is empty, a list of all realms is returned
func FreeSwitchDBList(c *eventsocket.Connection, realm string) ([]string, error) {
result, err := c.Send(fmt.Sprintf("api db list/%s", realm))
if err != nil {
return []string{}, err
}
return strings.Split(result.Body, ","), nil
}
22 changes: 20 additions & 2 deletions gofaxsend/transmission.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (t *transmission) start() {
requestT38 = false
}

// Assemble dialstring
// Collect dialstring variables
dsVariablesMap := map[string]string{
"ignore_early_media": "true",
"origination_uuid": t.faxjob.UUID.String(),
Expand All @@ -133,6 +133,24 @@ func (t *transmission) start() {
"fax_verbose": strconv.FormatBool(gofaxlib.Config.Freeswitch.Verbose),
}

// Look up variable overrides for given number
overrideRealm := fmt.Sprintf("override-%s", t.faxjob.Number)
overrides, err := gofaxlib.FreeSwitchDBList(t.conn, overrideRealm)
if err != nil {
t.sessionlog.Log(err)
} else {
for _, varName := range overrides {
varValue, err := gofaxlib.FreeSwitchDBSelect(t.conn, overrideRealm, varName)
if err != nil {
t.sessionlog.Log(err)
} else {
t.sessionlog.Log(fmt.Sprintf("Overriding dialstring variable %s=%s", varName, varValue))
dsVariablesMap[varName] = varValue
}
}
}

// Assemble dialstring
var dsVariables bytes.Buffer
var dsGateways bytes.Buffer

Expand All @@ -152,7 +170,7 @@ func (t *transmission) start() {
}

dialstring := fmt.Sprintf("{%v}%v", dsVariables.String(), dsGateways.String())
//t.sessionlog.Logf("Dialstring: %v", dialstring)
t.sessionlog.Logf("Dialstring: %v", dialstring)

// Originate call
t.sessionlog.Log("Originating channel to", t.faxjob.Number, "using gateway", strings.Join(t.faxjob.Gateways, ","))
Expand Down

0 comments on commit b278648

Please sign in to comment.