Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parse Via and add via_branch to protocol_header #490

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type HeplifyServer struct {
ForceALegID bool `default:"false"`
CustomHeader []string `default:""`
IgnoreCaseCH bool `default:"false"`
SIPHeader []string `default:"ruri_user,ruri_domain,from_user,from_tag,to_user,callid,cseq,method,user_agent"`
SIPHeader []string `default:"ruri_user,ruri_domain,from_user,from_tag,to_user,callid,cseq,method,user_agent,via_branch"`
LogDbg string `default:""`
LogLvl string `default:"info"`
LogStd bool `default:"false"`
Expand Down
2 changes: 1 addition & 1 deletion database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func buildTemplate() *fasttemplate.Template {
var dataTemplate string
sh := config.Setting.SIPHeader
if len(sh) < 1 {
sh = []string{"ruri_user", "ruri_domain", "from_user", "from_tag", "to_user", "callid", "cseq", "method", "user_agent"}
sh = []string{"ruri_user", "ruri_domain", "from_user", "from_tag", "to_user", "callid", "cseq", "method", "user_agent", "via_branch"}
}

for _, v := range sh {
Expand Down
2 changes: 2 additions & 0 deletions decoder/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ func (h *HEP) EscapeFields(w io.Writer, tag string) (int, error) {
return WriteJSONString(w, h.SIP.ToTag)
case "via":
return WriteJSONString(w, h.SIP.ViaOne)
case "via_branch":
return WriteJSONString(w, h.SIP.ViaOneBranch)
case "contact_user":
return WriteJSONString(w, h.SIP.ContactUser)
case "contact_domain":
Expand Down
2 changes: 1 addition & 1 deletion example/homer7_config/heplify-server.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ ConfigHTTPAddr = ""
# AlegIDs = ["X-CID","P-Charging-Vector,icid-value=\"?(.*?)(?:\"|;|$)","X-BroadWorks-Correlation-Info"]
# DiscardMethod = ["OPTIONS","NOTIFY"]
# CustomHeader = ["X-CustomerIP","X-Billing"]
# SIPHeader = ["callid","callid_aleg","method","ruri_user","ruri_domain","from_user","from_domain","from_tag","to_user","to_domain","to_tag","via","contact_user"]
# SIPHeader = ["callid","callid_aleg","method","ruri_user","ruri_domain","from_user","from_domain","from_tag","to_user","to_domain","to_tag","via","contact_user","via_branch"]
# LogDbg = "hep,sql,loki"
# LogLvl = "warning"
# ConfigHTTPAddr = "0.0.0.0:9876"
Expand Down
36 changes: 32 additions & 4 deletions sipparser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ type SipMsg struct {
RTPStatVal string
ViaOne string
ViaOneBranch string
ViaCount int
Privacy string
RemotePartyIdVal string
DiversionVal string
Expand Down Expand Up @@ -598,15 +599,42 @@ func (s *SipMsg) parseVia(str string) {
s.Via = append(s.Via, v)
}
*/
if len(s.ViaOne) == 0 {
s.ViaCount = 0
}
s.ViaOne = str
if a := strings.Index(str, "branch="); a > -1 && a < len(str) {
loopMaxCount := 0
for {
a := strings.Index(str, "branch=")
if a < 0 || a >= len(str) {
break
}
if loopMaxCount > 100 {
break
}
b := str[a:]
l := len(b)
if c := strings.Index(b, ";"); c > -1 && c < l && l > 7 {
s.ViaOneBranch = b[7:c]
c := strings.Index(b, ";")
d := strings.Index(b, ",")
if d > -1 && d < c {
c = d
}
if c > -1 && c < l && l > 7 {
if len(s.ViaOneBranch) == 0 {
s.ViaOneBranch = b[7:c]
} else {
s.ViaOneBranch = s.ViaOneBranch + ";" + b[7:c]
}
} else if l > 7 {
s.ViaOneBranch = b[7:]
if len(s.ViaOneBranch) == 0 {
s.ViaOneBranch = b[7:]
} else {
s.ViaOneBranch = s.ViaOneBranch + ";" + b[7:]
}
}
str = b[7:]
s.ViaCount++
loopMaxCount++
}
}

Expand Down