composite

package
v0.0.0-...-f179113 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 5, 2024 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package composite implements a composite filter based on several types of filters and the logic of the filter application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// SafeBrowsing is the safe-browsing filter to apply, if any.
	SafeBrowsing *hashprefix.Filter

	// AdultBlocking is the adult-content filter to apply, if any.
	AdultBlocking *hashprefix.Filter

	// NewRegisteredDomains is the newly registered domains filter to apply, if
	// any.
	NewRegisteredDomains *hashprefix.Filter

	// GeneralSafeSearch is the general safe-search filter to apply, if any.
	GeneralSafeSearch *safesearch.Filter

	// YouTubeSafeSearch is the youtube safe-search filter to apply, if any.
	YouTubeSafeSearch *safesearch.Filter

	// Custom is the custom rule-list filter of the profile, if any.
	Custom *rulelist.Immutable

	// RuleLists are the enabled rule-list filters of the profile or filtering
	// group, if any.  All items must not be nil.
	RuleLists []*rulelist.Refreshable

	// ServiceLists are the rule-list filters of the profile's enabled blocked
	// services, if any.  All items must not be nil.
	ServiceLists []*rulelist.Immutable
}

Config is the configuration structure for the composite filter.

type Filter

type Filter struct {
	// contains filtered or unexported fields
}

Filter is a composite filter based on several types of safe-search and rule-list filters.

func New

func New(c *Config) (f *Filter)

New returns a new composite filter. c must not be nil.

func (*Filter) FilterRequest

func (f *Filter) FilterRequest(
	ctx context.Context,
	req *internal.Request,
) (r internal.Result, err error)

FilterRequest implements the internal.Interface interface for *Filter. The order in which the filters are applied is the following:

  1. Custom filter.
  2. Rule-list filters.
  3. Blocked-service filters.
  4. Dangerous-domains filter.
  5. Adult-content filter.
  6. General safe-search filter.
  7. YouTube safe-search filter.
  8. Newly-registered domains filter.

If f is empty, it returns nil with no error.

func (*Filter) FilterResponse

func (f *Filter) FilterResponse(
	_ context.Context,
	resp *internal.Response,
) (r internal.Result, err error)

FilterResponse implements the internal.Interface interface for *Filter. It returns the action created from the filter list network rule with the highest priority. If f is empty, it returns nil with no error. Note that rewrite results are not applied to responses.

func (*Filter) Map

func (f *Filter) Map(id int) (fltID internal.ID, svcID internal.BlockedServiceID)

Map implements the rulelist.IDMapper interface for *Filter. It returns the rule list data by its synthetic integer ID in the urlfilter engine. It panics if id is not found.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL