Skip to content

Commit

Permalink
support compact form
Browse files Browse the repository at this point in the history
  • Loading branch information
tj8000rpm committed Apr 11, 2018
1 parent 40ac30f commit 3fe6626
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
16 changes: 16 additions & 0 deletions packetbeat/protos/sip/sipMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,22 @@ func (msg *sipMessage) parseSIPHeaderToMap(cutPosS []int,cutPosE []int) (*map[st
continue
}

// Convert compact form to full form
if len(key) == 1{
switch(key){
case "i": key="call-id"
case "m": key="contact"
case "e": key="content-encoding"
case "l": key="content-length"
case "c": key="content-type"
case "f": key="from"
case "s": key="subject"
case "k": key="supported"
case "t": key="to"
case "v": key="via"
}
}

// Initialize and add to map, if first find the header name in process
_,ok := (*headers)[key]
if !ok{
Expand Down
13 changes: 7 additions & 6 deletions packetbeat/protos/sip/sipMessage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,15 +525,16 @@ func TestParseSIPHeaderToMap_compactform(t *testing.T){
offset12:=offset11+len(header10)
offset13:=offset12+len(header11)
offset14:=offset13+len(header12)
offset15:=offset14+len(header13)

cuts:=[]int{ offset0, offset1, offset2, offset3,
offset4, offset5, offset6, offset7,
offset8, offset9, offset10, offset11,
offset12}
cute:=[]int{ len(firstline)-2, offset1+len(header0)-2, offset2+len(header1)-2,
offset3+len(header2)-2, offset4+len(header3)-2, offset5+len(header4)-2,
offset6+len(header5)-2, offset7+len(header6)-2, offset8+len(header7)-2,
offset9+len(header8)-2, offset10+len(header9)-2, offset11+len(header10)-2,
offset12+len(header11)-2}
offset12, offset13, offset14, offset15}
cute:=[]int{ len(firstline)-2, offset1+len(header0)-2, offset2+len(header1)-2, offset3+len(header2)-2,
offset4+len(header3)-2, offset5+len(header4)-2, offset6+len(header5)-2, offset7+len(header6)-2,
offset8+len(header7)-2, offset9+len(header8)-2, offset10+len(header9)-2, offset11+len(header10)-2,
offset12+len(header11)-2, offset13+len(header12)-2, offset14+len(header13)-2, offset15+len(header14)-2}
msg := sipMessage{}
msg.raw = garbage
headers, first_lines:=msg.parseSIPHeaderToMap(cuts,cute)
Expand Down

0 comments on commit 3fe6626

Please sign in to comment.