Skip to content

Commit

Permalink
Extend the pcap loader to extract color information.
Browse files Browse the repository at this point in the history
When the PSML is generated, termshark now extracts the fg and bg colors
from the XML e.g.

<packet foreground='#000000' background='#95f4ff'>
<section>1</section>
<section>0.000000</section>
<section>192.168.3.131</section>
<section>72.14.213.138</section>
<section>HTTP</section>
<section>997</section>
<section>GET /complete/search?client=chrome&amp;hl=en-US&amp;q=cr HTTP/1.1 </section>
</packet>

This is stored along with the header names and packet fields.
  • Loading branch information
gcla committed Nov 16, 2019
1 parent ff449d1 commit 9e67f1d
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions pcap/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ type Loader struct {

sync.Mutex
PacketPsmlData [][]string
PacketPsmlColors []PacketColors
PacketPsmlHeaders []string
PacketCache *lru.Cache // i -> [pdml(i * 1000)..pdml(i+1*1000)]

Expand All @@ -192,6 +193,11 @@ type Loader struct {
opt Options
}

type PacketColors struct {
FG gowid.IColor
BG gowid.IColor
}

type Options struct {
CacheSize int
PacketsPerLoad int
Expand Down Expand Up @@ -234,6 +240,7 @@ func (c *Loader) resetData() {
c.Lock()
defer c.Unlock()
c.PacketPsmlData = make([][]string, 0)
c.PacketPsmlColors = make([]PacketColors, 0)
c.PacketPsmlHeaders = make([]string, 0, 10)
packetCache, err := lru.New(c.opt.CacheSize)
if err != nil {
Expand Down Expand Up @@ -297,6 +304,10 @@ func (c *Loader) PsmlHeaders() []string {
return c.PacketPsmlHeaders
}

func (c *Loader) PsmlColors() []PacketColors {
return c.PacketPsmlColors
}

//======================================================================

type Scheduler struct {
Expand Down Expand Up @@ -1546,6 +1557,7 @@ func (c *Loader) loadPsmlAsync(cb interface{}) {
// view, not the old view of a loader with old data.
c.Lock()
c.PacketPsmlData = make([][]string, 0)
c.PacketPsmlColors = make([]PacketColors, 0)
c.PacketPsmlHeaders = make([]string, 0, 10)
c.PacketCache.Purge()
c.LoadWasCancelled = false
Expand Down Expand Up @@ -1816,6 +1828,8 @@ func (c *Loader) loadPsmlAsync(cb interface{}) {
// </packet>

var curPsml []string
var fg string
var bg string
ready := false
empty := true
structure := false
Expand All @@ -1839,6 +1853,10 @@ func (c *Loader) loadPsmlAsync(cb interface{}) {
case "packet":
c.Lock()
c.PacketPsmlData = append(c.PacketPsmlData, curPsml)
c.PacketPsmlColors = append(c.PacketPsmlColors, PacketColors{
FG: psmlColorToIColor(fg),
BG: psmlColorToIColor(bg),
})
c.Unlock()

case "section":
Expand All @@ -1854,6 +1872,16 @@ func (c *Loader) loadPsmlAsync(cb interface{}) {
structure = true
case "packet":
curPsml = make([]string, 0, 10)
fg = ""
bg = ""
for _, attr := range tok.Attr {
switch attr.Name.Local {
case "foreground":
fg = attr.Value
case "background":
bg = attr.Value
}
}
case "section":
ready = true
empty = true
Expand Down Expand Up @@ -2035,6 +2063,16 @@ Loop:
return requests
}

//======================================================================

func psmlColorToIColor(col string) gowid.IColor {
if res, err := gowid.MakeRGBColorSafe(col); err != nil {
return nil
} else {
return res
}
}

//======================================================================
// Local Variables:
// mode: Go
Expand Down

0 comments on commit 9e67f1d

Please sign in to comment.