Skip to content

Commit

Permalink
Merge: + querylog: preserve searching compatibility with the previous…
Browse files Browse the repository at this point in the history
… version

* commit 'a7742a366511e272a8c24dc5fcd1a62759c2bacb':
  - querylog: fix linter issue
  + querylog: preserve searching compatibility with the previous version
  • Loading branch information
szolin committed Nov 19, 2019
2 parents 6ae0a0e + a7742a3 commit 0d4dce5
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion querylog/querylog_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ func readJSONValue(s, name string) string {
return s[start:end]
}

// nolint (gocyclo)
func (r *Reader) applySearch(str string) bool {
if r.search.ResponseStatus == responseStatusFiltered {
boolVal, ok := readJSONBool(str, "IsFiltered")
Expand All @@ -406,8 +407,26 @@ func (r *Reader) applySearch(str string) bool {
}
}

mq := dns.Msg{}

if len(r.search.Domain) != 0 {
val := readJSONValue(str, "QH")
if len(val) == 0 {
// pre-v0.99.3 compatibility
val = readJSONValue(str, "Question")
if len(val) == 0 {
return false
}
bval, err := base64.StdEncoding.DecodeString(val)
if err != nil {
return false
}
err = mq.Unpack(bval)
if err != nil {
return false
}
val = strings.TrimSuffix(mq.Question[0].Name, ".")
}
if len(val) == 0 {
return false
}
Expand All @@ -421,7 +440,26 @@ func (r *Reader) applySearch(str string) bool {
if len(r.search.QuestionType) != 0 {
val := readJSONValue(str, "QT")
if len(val) == 0 {
return false
// pre-v0.99.3 compatibility
if len(mq.Question) == 0 {
val = readJSONValue(str, "Question")
if len(val) == 0 {
return false
}
bval, err := base64.StdEncoding.DecodeString(val)
if err != nil {
return false
}
err = mq.Unpack(bval)
if err != nil {
return false
}
}
ok := false
val, ok = dns.TypeToString[mq.Question[0].Qtype]
if !ok {
return false
}
}
if val != r.search.QuestionType {
return false
Expand Down

0 comments on commit 0d4dce5

Please sign in to comment.