diff --git a/netquery/database.go b/netquery/database.go index ac47197c4..807c00974 100644 --- a/netquery/database.go +++ b/netquery/database.go @@ -57,6 +57,7 @@ type ( writeConn *sqlite.Conn } + // BatchExecute executes multiple queries in one transaction. BatchExecute struct { ID string SQL string diff --git a/netquery/orm/decoder.go b/netquery/orm/decoder.go index 5b87df829..21ce61468 100644 --- a/netquery/orm/decoder.go +++ b/netquery/orm/decoder.go @@ -461,6 +461,7 @@ func getKind(val reflect.Value) reflect.Kind { return NormalizeKind(kind) } +// NormalizeKind returns a normalized kind of the given kind. func NormalizeKind(kind reflect.Kind) reflect.Kind { switch { case kind >= reflect.Int && kind <= reflect.Int64: diff --git a/netquery/orm/encoder.go b/netquery/orm/encoder.go index 107f9f777..6dcd0e684 100644 --- a/netquery/orm/encoder.go +++ b/netquery/orm/encoder.go @@ -183,7 +183,7 @@ func DatetimeEncoder(loc *time.Location) EncodeFunc { case (normalizedKind == reflect.Int || normalizedKind == reflect.Uint || normalizedKind == reflect.Float64) && colDef.IsTime: seconds := int64(0) - switch normalizedKind { + switch normalizedKind { //nolint:exhaustive // Previous switch case assures these types. case reflect.Int: seconds = val.Int() case reflect.Uint: diff --git a/netquery/query.go b/netquery/query.go index a4502849f..804f85fbc 100644 --- a/netquery/query.go +++ b/netquery/query.go @@ -311,7 +311,7 @@ func (match Matcher) toSQLConditionClause(ctx context.Context, suffix string, co for idx, value := range values { var ( - encodedValue any = value + encodedValue any err error ) @@ -344,7 +344,7 @@ func (match Matcher) toSQLConditionClause(ctx context.Context, suffix string, co // NOTE(ppacher): for now we assume that the type of each element of values // is the same. We also can be sure that there is always at least one value. // - // FIXME(ppacher): if we start supporting values of different types here + // TODO(ppacher): if we start supporting values of different types here // we need to revisit the whole behavior as we might need to do more boolean // expression nesting to support that. kind := orm.NormalizeKind(reflect.TypeOf(values[0]).Kind()) diff --git a/netquery/query_handler.go b/netquery/query_handler.go index ae848a9e1..8e704d3e8 100644 --- a/netquery/query_handler.go +++ b/netquery/query_handler.go @@ -12,6 +12,7 @@ import ( "github.com/hashicorp/go-multierror" servertiming "github.com/mitchellh/go-server-timing" + "github.com/safing/portbase/log" "github.com/safing/portmaster/netquery/orm" ) @@ -27,6 +28,8 @@ type ( Database *Database } + // BatchQueryHandler implements http.Handler and allows to perform SQL + // query and aggregate functions on Database in batches. BatchQueryHandler struct { IsDevMode func() bool Database *Database @@ -116,8 +119,8 @@ func (qh *QueryHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) { return } - } + func (batch *BatchQueryHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) { timing := servertiming.FromContext(req.Context()) diff --git a/netquery/query_request.go b/netquery/query_request.go index e294d6ea6..b4a07041c 100644 --- a/netquery/query_request.go +++ b/netquery/query_request.go @@ -5,11 +5,13 @@ import ( "fmt" "strings" - "github.com/safing/portmaster/netquery/orm" "golang.org/x/exp/slices" + + "github.com/safing/portmaster/netquery/orm" ) type ( + // QueryRequestPayload describes the payload of a netquery query. QueryRequestPayload struct { Select Selects `json:"select"` Query Query `json:"query"` diff --git a/resolver/resolver_test.go b/resolver/resolver_test.go index a03b3eb97..397a914cd 100644 --- a/resolver/resolver_test.go +++ b/resolver/resolver_test.go @@ -119,7 +119,7 @@ func TestPublicSuffix(t *testing.T) { testSuffix(t, "golang.dev.", "golang.dev.", true) testSuffix(t, "golang.net.", "golang.net.", true) testSuffix(t, "play.golang.org.", "golang.org.", true) - testSuffix(t, "gophers.in.space.museum.", "in.space.museum.", true) + testSuffix(t, "gophers.in.space.museum.", "space.museum.", true) testSuffix(t, "0emm.com.", "0emm.com.", true) testSuffix(t, "a.0emm.com.", "", true) testSuffix(t, "b.c.d.0emm.com.", "c.d.0emm.com.", true)