diff --git a/config/config.go b/config/config.go index 7bdff35e..915dc2e9 100644 --- a/config/config.go +++ b/config/config.go @@ -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"` diff --git a/database/database.go b/database/database.go index 4f864b01..d93ef5a8 100644 --- a/database/database.go +++ b/database/database.go @@ -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 { diff --git a/decoder/decoder.go b/decoder/decoder.go index 6c3f3900..38db5e2e 100644 --- a/decoder/decoder.go +++ b/decoder/decoder.go @@ -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": diff --git a/example/homer7_config/heplify-server.toml b/example/homer7_config/heplify-server.toml index 8edd3b52..8152e890 100644 --- a/example/homer7_config/heplify-server.toml +++ b/example/homer7_config/heplify-server.toml @@ -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" diff --git a/sipparser/parser.go b/sipparser/parser.go index 6ae73186..a0771ea4 100644 --- a/sipparser/parser.go +++ b/sipparser/parser.go @@ -80,6 +80,7 @@ type SipMsg struct { RTPStatVal string ViaOne string ViaOneBranch string + ViaCount int Privacy string RemotePartyIdVal string DiversionVal string @@ -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++ } }