config

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package config parses the text config file format for the washcookies tool.

Blank lines and comments prefixed by "#" are ignored, except as described under "Files" below. Otherwise each non-blank line specifies a rule in the following format:

<f>{<sep><field><op><arg>}+

f     -- "+" for Allow, "-" for Deny, "!" for Keep
sep   -- the separator character for criteria
field -- the name of a cookie field (see "Fields")
op    -- a comparison operator (see "Operators")
arg   -- an argument for comparison (possibly empty)

Files

Comment lines that begin with "#=" are treated as the pathnames of files to process. Shell variables such as $HOME are expanded.

Fields

Each cookie has the following fields:

domain -- the host or domain for which the cookie is delivered
path   -- the path for which the cookie is delivered
name   -- the name of the cookie
value  -- the content of the cookie

Operators

The operators are:

=  -- case-insensitive string equality
?  -- test for key existence in the cookie
~  -- regular expression search (RE2)
@  -- domain-name string matching

Any operator may be prefixed with '!' to negate the sense of the comparison. If the key and operator are omitted, "domain" and "@" are assumed. The "@" operator does case-insensitive string comparison, but if the argument starts with a period "." then it matches if the argument is a suffix of the value.

Matching

If a cookie is matched by any Keep ("!") rule, it is explicitly retained. Otherwise, if any Deny ("-") rule matches the cookie, it is discarded. Otherwise, if no Allow ("+") rule matches the cookie, it is discarded.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OpenStore

func OpenStore(path string) (cookies.Store, error)

OpenStore opens a cookie store for the specified path. The type of the contents is inferred from the filename.

Types

type Clause

type Clause struct {
	Field string // one of "domain", "path", "name", "value"
	Op    string // one of "=", "?", "~", "@" or their negation
	Arg   string // the RHS of the comparison

	// If Op is "~" or "!~", Expr is the compiled regular expression
	// corresponding to Arg. For other operators Expr == nil.
	Expr *regexp.Regexp
}

A Clause is a single term of a rule.

func (Clause) Match

func (c Clause) Match(ck cookies.C) bool

Match reports whether c matches the corresponding field of ck.

type Config

type Config struct {
	Files []string // any #= file lines
	Rules []Rule
}

Config represents the contents of a configuration file.

func Open

func Open(path string) (*Config, error)

Open opens and parses the configuration file at path.

func (*Config) Match

func (c *Config) Match(ck cookies.C) []Rule

Match returns a slice of rules matching the specified cookie, or nil if no rules match.

type Rule

type Rule struct {
	Tag     string // one of "+", "-", "!"
	Sep     string
	Clauses []Clause
	Reason  string
}

A Rule is a single rule.

func (Rule) Match

func (r Rule) Match(ck cookies.C) bool

Match reports whether r matches the given cookie.

Jump to

Keyboard shortcuts

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