-
Notifications
You must be signed in to change notification settings - Fork 0
/
odbc_cdr.go
68 lines (59 loc) · 1.98 KB
/
odbc_cdr.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// mod_odbc_cdr
// apt-get install freeswitch-mod-odbc-cdr
// default install without configuration file "odbc_cdr.conf.xml", so read return error.
// request:
// hostname=D1130§ion=configuration&tag_name=configuration&key_name=name&key_value=odbc_cdr.conf
// response:
// <document type="freeswitch/xml">
// <section name="configuration">
// <configuration name="odbc_cdr.conf" description="ODBC CDR Configuration">
// <settings>
// <!--ADD your parameters here-->
// </settings>
// </configuration>
// </section>
// </document>
package odbc_cdr
import (
"errors"
"fmt"
"strings"
"github.com/gin-gonic/gin"
"github.com/spf13/viper"
)
func init() {}
func Read(c *gin.Context) (string, error) {
// file := fmt.Sprintf("%s/autoload_configs/%s", viper.GetString(`switch.conf`), MOD_CONF_NAME)
// content, err := os.ReadFile(file)
// return string(content), err
return "", errors.New("odbc_cdr.Read(c) nothing, default odbc_cdr.conf.xml not found")
}
func Default() (string, error) {
var err error
var tables string
alegname := viper.GetString(`switch.cdr.a-leg`)
blegname := viper.GetString(`switch.cdr.b-leg`)
bothname := viper.GetString(`switch.cdr.both`)
if len(alegname) > 0 {
table := fmt.Sprintf(ODBC_CDR_CONF_XML_TABLE_ALEG, alegname)
tables = fmt.Sprintf("%s\n%s", tables, table)
}
if len(blegname) > 0 {
table := fmt.Sprintf(ODBC_CDR_CONF_XML_TABLE_BLEG, blegname)
tables = fmt.Sprintf("%s\n%s", tables, table)
}
if len(bothname) > 0 {
table := fmt.Sprintf(ODBC_CDR_CONF_XML_TABLE_BOTH, bothname)
tables = fmt.Sprintf("%s\n%s", tables, table)
}
if len(tables) <= 0 {
err = errors.New(`odbc_cdr.conf no table defined`)
}
return fmt.Sprintf(ODBC_CDR_CONF_XML, tables), err
}
func Build(c *gin.Context, content string) (string, error) {
//<param name="odbc-dsn" value="$${pg_handle}"/>
newodbcdsn := `<param name="odbc-dsn" value="$${pg_handle}"/>`
newcontent := strings.ReplaceAll(content, ODBC_DSN, newodbcdsn)
return newcontent, nil
}