processors

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2026 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AdguardExceptionPrefix = "@@"
	AdguardBlockPrefix     = "||"
	AdguardBlockSuffix     = "^"
	AdguardBlockSuffixFull = "$"
)

Variables

View Source
var Processors = NewProcessorRegistry()
View Source
var SpecialProcessors = NewSpecialProcessorRegistry()

SpecialProcessors Global instance of the special processor registry

Functions

func EqualUnorderedAdg added in v1.0.3

func EqualUnorderedAdg(a, b []string) bool

func ExtractAllowlistDomains

func ExtractAllowlistDomains(logger *multilog.Logger, content string) ([]string, []string)

func ExtractBlocklistDomains

func ExtractBlocklistDomains(logger *multilog.Logger, content string) ([]string, []string)

func ParseToAdguardEntry added in v1.0.3

func ParseToAdguardEntry(raw string) (string, bool)

ParseToAdguardEntry parses a raw URL string and returns an AdGuard folder-style entry

func RegisterGenericProcessor

func RegisterGenericProcessor(
	sourceType string,
	processFunc ProcessFunc,
	blocklistOnly bool,
	allowlistOnly bool,
)

RegisterGenericProcessor registers a processor with a custom processing function

func RegisterProcessor

func RegisterProcessor(sourceType string, processorCreator func(string, string) Processor)

RegisterProcessor registers a processor for both blocklist and allowlist types

func RegisterProcessorTypes

func RegisterProcessorTypes(
	sourceType string,
	listTypes []string,
	processorCreator func(string, string) Processor,
)

Types

type AdGuardAllowlistProcessor

type AdGuardAllowlistProcessor struct {
	BaseProcessor
}

AdGuardAllowlistProcessor handles AdGuard allowlist entries (different format)

func NewAdGuardAllowlistProcessor

func NewAdGuardAllowlistProcessor(sourceType, listType string) *AdGuardAllowlistProcessor

NewAdGuardAllowlistProcessor creates a new AdGuard allowlist processor

func (*AdGuardAllowlistProcessor) Process

func (p *AdGuardAllowlistProcessor) Process(_ *multilog.Logger, content string) ([]string, []string)

Process processes AdGuard allowlist entries

type AdGuardBlocklistProcessor

type AdGuardBlocklistProcessor struct {
	BaseProcessor
}

AdGuardBlocklistProcessor handles AdGuard blocklist entries

func NewAdGuardBlocklistProcessor

func NewAdGuardBlocklistProcessor(sourceType, listType string) *AdGuardBlocklistProcessor

NewAdGuardBlocklistProcessor creates a new AdGuard blocklist processor

func (*AdGuardBlocklistProcessor) Process

func (p *AdGuardBlocklistProcessor) Process(_ *multilog.Logger, content string) ([]string, []string)

Process processes AdGuard blocklist entries

type AdGuardDomainAllowlistProcessor added in v1.0.1

type AdGuardDomainAllowlistProcessor struct {
	BaseProcessor
}

AdGuardDomainAllowlistProcessor converts plain domains into AdGuard allowlist rules (@@||domain^)

func NewAdGuardDomainAllowlistProcessor added in v1.0.1

func NewAdGuardDomainAllowlistProcessor(sourceType, listType string) *AdGuardDomainAllowlistProcessor

NewAdGuardDomainAllowlistProcessor creates a new processor for adguard_domain allowlist

func (*AdGuardDomainAllowlistProcessor) Process added in v1.0.1

func (p *AdGuardDomainAllowlistProcessor) Process(_ *multilog.Logger, content string) ([]string, []string)

Process converts each valid domain into an AdGuard allow rule

type AdGuardDomainBlocklistProcessor added in v1.0.1

type AdGuardDomainBlocklistProcessor struct {
	BaseProcessor
}

AdGuardDomainBlocklistProcessor converts plain domains into AdGuard blocklist rules (||domain^)

func NewAdGuardDomainBlocklistProcessor added in v1.0.1

func NewAdGuardDomainBlocklistProcessor(sourceType, listType string) *AdGuardDomainBlocklistProcessor

NewAdGuardDomainBlocklistProcessor creates a new processor for adguard_domain blocklist

func (*AdGuardDomainBlocklistProcessor) Process added in v1.0.1

func (p *AdGuardDomainBlocklistProcessor) Process(_ *multilog.Logger, content string) ([]string, []string)

Process converts each valid domain into an AdGuard block rule

type AdGuardHttpUrlProcessor added in v1.0.3

type AdGuardHttpUrlProcessor struct {
	BaseProcessor
}

AdGuardHttpUrlProcessor converts http/https URLs into AdGuard blocklist rules (||host/path$)

func NewAdGuardHttpUrlProcessor added in v1.0.3

func NewAdGuardHttpUrlProcessor(sourceType, listType string) *AdGuardHttpUrlProcessor

NewAdGuardHttpUrlProcessor creates a new processor for adguard_httpurl

func (*AdGuardHttpUrlProcessor) Process added in v1.0.3

func (p *AdGuardHttpUrlProcessor) Process(_ *multilog.Logger, content string) ([]string, []string)

Process converts each valid http/https URL into an AdGuard block rule

type AdguardCsvHttpUrlFindProcessor added in v1.0.3

type AdguardCsvHttpUrlFindProcessor struct {
	BaseProcessor
}

AdguardCsvHttpUrlFindProcessor extracts http/https URLs from CSV lines and converts them into AdGuard block rules

func NewAdguardCsvHttpUrlFindProcessor added in v1.0.3

func NewAdguardCsvHttpUrlFindProcessor(sourceType, listType string) *AdguardCsvHttpUrlFindProcessor

func (*AdguardCsvHttpUrlFindProcessor) Process added in v1.0.3

func (p *AdguardCsvHttpUrlFindProcessor) Process(_ *multilog.Logger, content string) ([]string, []string)

type BaseProcessor

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

BaseProcessor provides common functionality for all processors

func NewBaseProcessor

func NewBaseProcessor(sourceType, listType string) BaseProcessor

NewBaseProcessor creates a new base processor with the given source type and list type

func (*BaseProcessor) GetListType

func (bp *BaseProcessor) GetListType() string

GetListType returns the list type identifier for this processor

func (*BaseProcessor) GetSourceType

func (bp *BaseProcessor) GetSourceType() string

GetSourceType returns the source type identifier for this processor

type DomainCommentProcessor added in v0.2.0

type DomainCommentProcessor struct {
	BaseProcessor
}

func NewDomainCommentProcessor added in v0.2.0

func NewDomainCommentProcessor(sourceType, listType string) *DomainCommentProcessor

func (*DomainCommentProcessor) Process added in v0.2.0

func (p *DomainCommentProcessor) Process(_ *multilog.Logger, content string) ([]string, []string)

type DomainCsvHttpUrlFindProcessor added in v0.3.0

type DomainCsvHttpUrlFindProcessor struct {
	BaseProcessor
}

func NewDomainCsvHttpUrlFindProcessor added in v0.3.0

func NewDomainCsvHttpUrlFindProcessor(sourceType, listType string) *DomainCsvHttpUrlFindProcessor

func (*DomainCsvHttpUrlFindProcessor) Process added in v0.3.0

func (p *DomainCsvHttpUrlFindProcessor) Process(_ *multilog.Logger, content string) ([]string, []string)

type DomainCustomCsvBlackbookProcessor added in v0.2.0

type DomainCustomCsvBlackbookProcessor struct {
	BaseProcessor
}

func NewDomainCustomCsvBlackbookProcessor added in v0.2.0

func NewDomainCustomCsvBlackbookProcessor(sourceType, listType string) *DomainCustomCsvBlackbookProcessor

func (*DomainCustomCsvBlackbookProcessor) Process added in v0.2.0

func (p *DomainCustomCsvBlackbookProcessor) Process(_ *multilog.Logger, content string) ([]string, []string)

type DomainCustomCsvMaltrailProcessor

type DomainCustomCsvMaltrailProcessor struct {
	BaseProcessor
}

func NewDomainCustomCsvMaltrailProcessor

func NewDomainCustomCsvMaltrailProcessor(sourceType, listType string) *DomainCustomCsvMaltrailProcessor

func (*DomainCustomCsvMaltrailProcessor) Process

func (p *DomainCustomCsvMaltrailProcessor) Process(_ *multilog.Logger, content string) ([]string, []string)

type DomainCustomHtmlCcamProcessor added in v0.3.0

type DomainCustomHtmlCcamProcessor struct {
	BaseProcessor
}

DomainCustomHtmlCcamProcessor implements a processor for extracting domain names from HTML content, specifically focussing on CCAM-formatted HTML tables.

func NewDomainCustomHtmlCcamProcessor added in v0.3.0

func NewDomainCustomHtmlCcamProcessor(sourceType, listType string) *DomainCustomHtmlCcamProcessor

NewDomainCustomHtmlCcamProcessor creates a new instance of DomainCustomHtmlCcamProcessor.

Returns:

  • A configured DomainCustomHtmlCcamProcessor instance

func (*DomainCustomHtmlCcamProcessor) Process added in v0.3.0

func (p *DomainCustomHtmlCcamProcessor) Process(logger *multilog.Logger, content string) ([]string, []string)

Process extracts valid domain names from HTML table cells. It parses the HTML content, finds all table cells, and extracts domains from each cell. Duplicate domains are automatically removed.

Parameters:

  • logger: Logger for recording operations and errors
  • content: The HTML content to process

Returns:

  • A slice of valid domain names found in the content, sorted alphabetically
  • A slice of invalid entries that couldn't be parsed as domains

type DomainCustomHtmlPuppyScamsProcessor added in v0.3.0

type DomainCustomHtmlPuppyScamsProcessor struct {
	BaseProcessor
}

DomainCustomHtmlPuppyScamsProcessor implements a processor for extracting domain names from HTML content, specifically focusing on PuppyScams.

func NewDomainCustomHtmlPuppyScamsProcessor added in v0.3.0

func NewDomainCustomHtmlPuppyScamsProcessor(sourceType, listType string) *DomainCustomHtmlPuppyScamsProcessor

NewDomainCustomHtmlPuppyScamsProcessor creates a new instance of DomainCustomHtmlPuppyScamsProcessor.

Returns:

  • A configured DomainCustomHtmlPuppyScamsProcessor instance

func (*DomainCustomHtmlPuppyScamsProcessor) Process added in v0.3.0

func (p *DomainCustomHtmlPuppyScamsProcessor) Process(logger *multilog.Logger, content string) ([]string, []string)

Process extracts valid domain names from HTML tags.

Parameters:

  • logger: Logger for recording operations and errors
  • content: The HTML content to process

Returns:

  • A slice of valid domain names found in the content, sorted alphabetically
  • A slice of invalid entries that couldn't be parsed as domains

type DomainHttpUrlProcessor added in v0.2.0

type DomainHttpUrlProcessor struct {
	BaseProcessor
}

DomainHttpUrlProcessor implements a processor for extracting domain names from HTTP and HTTPS URLs.

func NewDomainHttpUrlProcessor added in v0.2.0

func NewDomainHttpUrlProcessor(sourceType, listType string) *DomainHttpUrlProcessor

NewDomainHttpUrlProcessor creates a new instance of DomainHttpUrlProcessor.

Returns:

  • A configured DomainHttpUrlProcessor instance

func (*DomainHttpUrlProcessor) Process added in v0.2.0

func (p *DomainHttpUrlProcessor) Process(_ *multilog.Logger, content string) ([]string, []string)

Process extracts valid domain names from HTTP/HTTPS URLs. It parses each line, extracts the domain from URLs, and validates them. Duplicate domains are automatically removed.

Parameters:

  • logger: Logger for recording operations and errors
  • content: The content containing URLs to process

Returns:

  • A slice of valid domain names found in the content
  • A slice of invalid entries that couldn't be parsed

type DomainTopProcessor

type DomainTopProcessor struct {
	BaseProcessor
}

func NewDomainTopProcessor

func NewDomainTopProcessor(sourceType, listType string) *DomainTopProcessor

func (*DomainTopProcessor) Process

func (p *DomainTopProcessor) Process(_ *multilog.Logger, content string) ([]string, []string)

type DomainUrlProcessor added in v0.3.0

type DomainUrlProcessor struct {
	BaseProcessor
}

func NewDomainUrlProcessor added in v0.3.0

func NewDomainUrlProcessor(sourceType, listType string) *DomainUrlProcessor

func (*DomainUrlProcessor) Process added in v0.3.0

func (p *DomainUrlProcessor) Process(_ *multilog.Logger, content string) ([]string, []string)

type DomainWithCommentSuffixProcessor added in v0.2.0

type DomainWithCommentSuffixProcessor struct {
	BaseProcessor
}

func NewDomainWithCommentSuffixProcessor added in v0.2.0

func NewDomainWithCommentSuffixProcessor(sourceType, listType string) *DomainWithCommentSuffixProcessor

func (*DomainWithCommentSuffixProcessor) Process added in v0.2.0

func (p *DomainWithCommentSuffixProcessor) Process(_ *multilog.Logger, content string) ([]string, []string)

type GenericProcessor

type GenericProcessor struct {
	BaseProcessor
	// contains filtered or unexported fields
}

GenericProcessor is a customizable processor that uses a function for processing

func NewGenericProcessor

func NewGenericProcessor(sourceType, listType string, processFunc ProcessFunc) *GenericProcessor

NewGenericProcessor creates a new processor with custom processing logic

func (*GenericProcessor) Process

func (gp *GenericProcessor) Process(logger *multilog.Logger, content string) ([]string, []string)

Process delegates to the custom process function

type HostnameProcessor

type HostnameProcessor struct {
	BaseProcessor
}

func NewHostnameProcessor

func NewHostnameProcessor(sourceType, listType string) *HostnameProcessor

func (*HostnameProcessor) Process

func (p *HostnameProcessor) Process(_ *multilog.Logger, content string) ([]string, []string)

type Ipv4CidrProcessor added in v0.2.0

type Ipv4CidrProcessor struct {
	BaseProcessor
}

func NewIpv4CidrProcessor added in v0.2.0

func NewIpv4CidrProcessor(sourceType, listType string) *Ipv4CidrProcessor

func (*Ipv4CidrProcessor) Process added in v0.2.0

func (p *Ipv4CidrProcessor) Process(logger *multilog.Logger, content string) ([]string, []string)

type Ipv4CsvHttpUrlFindProcessor added in v0.3.0

type Ipv4CsvHttpUrlFindProcessor struct {
	BaseProcessor
}

func NewIpv4CsvHttpUrlFindProcessor added in v0.3.0

func NewIpv4CsvHttpUrlFindProcessor(sourceType, listType string) *Ipv4CsvHttpUrlFindProcessor

func (*Ipv4CsvHttpUrlFindProcessor) Process added in v0.3.0

func (p *Ipv4CsvHttpUrlFindProcessor) Process(_ *multilog.Logger, content string) ([]string, []string)

type Ipv4CustomHtmlCcamProcessor added in v0.3.0

type Ipv4CustomHtmlCcamProcessor struct {
	BaseProcessor
}

Ipv4CustomHtmlCcamProcessor implements a processor for extracting IPv4 addresses from HTML content, specifically targeting CCAM-formatted HTML tables.

func NewIpv4CustomHtmlCcamProcessor added in v0.3.0

func NewIpv4CustomHtmlCcamProcessor(sourceType, listType string) *Ipv4CustomHtmlCcamProcessor

NewIpv4CustomHtmlCcamProcessor creates a new instance of Ipv4CustomHtmlCcamProcessor.

Returns:

  • A configured Ipv4CustomHtmlCcamProcessor instance

func (*Ipv4CustomHtmlCcamProcessor) Process added in v0.3.0

func (p *Ipv4CustomHtmlCcamProcessor) Process(logger *multilog.Logger, content string) ([]string, []string)

Process extracts valid IPv4 addresses from HTML table cells. It parses the HTML content, finds all table cells, and extracts IPv4 addresses from each cell. Duplicate addresses are automatically removed.

Parameters:

  • logger: Logger for recording operations and errors
  • content: The HTML content to process

Returns:

  • A slice of valid IPv4 addresses found in the content, sorted alphabetically
  • A slice of invalid entries that couldn't be parsed as IPv4 addresses

type Ipv4FindProcessor

type Ipv4FindProcessor struct {
	BaseProcessor
}

func NewIpv4FindProcessor

func NewIpv4FindProcessor(sourceType, listType string) *Ipv4FindProcessor

func (*Ipv4FindProcessor) Process

func (p *Ipv4FindProcessor) Process(_ *multilog.Logger, content string) ([]string, []string)

type Ipv4FromDomainProcessor added in v0.4.0

type Ipv4FromDomainProcessor struct {
	BaseProcessor
}

func NewIpv4FromDomainProcessor added in v0.4.0

func NewIpv4FromDomainProcessor(sourceType, listType string) *Ipv4FromDomainProcessor

func (*Ipv4FromDomainProcessor) Process added in v0.4.0

func (p *Ipv4FromDomainProcessor) Process(logger *multilog.Logger, content string) ([]string, []string)

type Ipv4HttpUrlProcessor added in v0.2.0

type Ipv4HttpUrlProcessor struct {
	BaseProcessor
}

func NewIpv4HttpUrlProcessor added in v0.2.0

func NewIpv4HttpUrlProcessor(sourceType, listType string) *Ipv4HttpUrlProcessor

func (*Ipv4HttpUrlProcessor) Process added in v0.2.0

func (p *Ipv4HttpUrlProcessor) Process(_ *multilog.Logger, content string) ([]string, []string)

type Ipv4RangeProcessor added in v0.2.0

type Ipv4RangeProcessor struct {
	BaseProcessor
}

func NewIpv4RangeProcessor added in v0.2.0

func NewIpv4RangeProcessor(sourceType, listType string) *Ipv4RangeProcessor

func (*Ipv4RangeProcessor) Process added in v0.2.0

func (p *Ipv4RangeProcessor) Process(logger *multilog.Logger, content string) ([]string, []string)

type Ipv4UrlProcessor added in v0.3.0

type Ipv4UrlProcessor struct {
	BaseProcessor
}

func NewIpv4UrlProcessor added in v0.3.0

func NewIpv4UrlProcessor(sourceType, listType string) *Ipv4UrlProcessor

func (*Ipv4UrlProcessor) Process added in v0.3.0

func (p *Ipv4UrlProcessor) Process(_ *multilog.Logger, content string) ([]string, []string)

type Ipv6FindProcessor added in v0.3.0

type Ipv6FindProcessor struct {
	BaseProcessor
}

func NewIpv6FindProcessor added in v0.3.0

func NewIpv6FindProcessor(sourceType, listType string) *Ipv6FindProcessor

func (*Ipv6FindProcessor) Process added in v0.3.0

func (p *Ipv6FindProcessor) Process(_ *multilog.Logger, content string) ([]string, []string)

type Ipv6HtaccessProcessor added in v0.3.0

type Ipv6HtaccessProcessor struct {
	BaseProcessor
}

Ipv6HtaccessProcessor implements a processor for extracting IPv6 addresses from htaccess file content.

func NewIpv6HtaccessProcessor added in v0.3.0

func NewIpv6HtaccessProcessor(sourceType, listType string) *Ipv6HtaccessProcessor

func (*Ipv6HtaccessProcessor) Process added in v0.3.0

func (p *Ipv6HtaccessProcessor) Process(_ *multilog.Logger, content string) ([]string, []string)

type ProcessFunc

type ProcessFunc func(logger *multilog.Logger, content string) ([]string, []string)

ProcessFunc is a function type for the specific processing logic

type Processor

type Processor interface {
	// Process parses the content and returns valid and invalid entries
	Process(logger *multilog.Logger, content string) ([]string, []string)
	// GetSourceType returns the source type this processor handles
	GetSourceType() string
	// GetListType returns the list type this processor handles
	GetListType() string
}

Processor defines the interface that all processor types should implement. Each processor must be able to parse content and extract valid and invalid entries, as well as report its source type.

type ProcessorFactory

type ProcessorFactory func(sourceType, listType string) Processor

ProcessorFactory is a generic factory function type for creating processors

type ProcessorRegistry

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

ProcessorRegistry is a thread-safe registry for processors.

func NewProcessorRegistry

func NewProcessorRegistry() *ProcessorRegistry

NewProcessorRegistry provides a thread-safe registry for processors.

func (*ProcessorRegistry) GetProcessor

func (pr *ProcessorRegistry) GetProcessor(sourceType, listType string) (Processor, bool)

GetProcessor retrieves a processor for a source type and list type.

Parameters:

  • sourceType: The source type to look up
  • listType: The list type to look up

Returns:

  • The registered processor for the source type and list type
  • A boolean indicating whether a processor was found

func (*ProcessorRegistry) ListProcessors

func (pr *ProcessorRegistry) ListProcessors() map[string]Processor

ListProcessors returns a copy of all registered processors. The returned map is a clone of the registry, so modifications to it won't affect the actual registry.

Returns:

  • A map of composite keys (sourceType:listType) to processors

func (*ProcessorRegistry) RegisterProcessor

func (pr *ProcessorRegistry) RegisterProcessor(sourceType, listType string, processor Processor)

RegisterProcessor registers a processor for a source type and list type. If a processor for the given source type and list type already exists, it will be replaced.

Parameters:

  • sourceType: The source type identifier for this processor
  • listType: The list type identifier for this processor
  • processor: The processor implementation to register

type SpecialProcessorRegistry

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

SpecialProcessorRegistry provides a way to register processors with special conditions different handling for blocklists vs. allowlists

func NewSpecialProcessorRegistry

func NewSpecialProcessorRegistry() *SpecialProcessorRegistry

NewSpecialProcessorRegistry creates a new registry for special processors

func (*SpecialProcessorRegistry) GetProcessor

func (r *SpecialProcessorRegistry) GetProcessor(sourceType, listType string) (Processor, bool)

GetProcessor returns a processor for the requested source and list types

func (*SpecialProcessorRegistry) Register

func (r *SpecialProcessorRegistry) Register(sourceType, listType string, factory ProcessorFactory)

Register adds a processor factory for a specific source and list type

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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