util

package
v0.0.0-...-d115e7c Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DICT_FLAG_NONE        int = (0)
	DICT_FLAG_DUP_WARN    int = (1 << 0) /* warn about dups if not supported */
	DICT_FLAG_DUP_IGNORE  int = (1 << 1) /* ignore dups if not supported */
	DICT_FLAG_TRY0NULL    int = (1 << 2) /* do not append 0 to key/value */
	DICT_FLAG_TRY1NULL    int = (1 << 3) /* append 0 to key/value */
	DICT_FLAG_FIXED       int = (1 << 4) /* fixed key map */
	DICT_FLAG_PATTERN     int = (1 << 5) /* keys are patterns */
	DICT_FLAG_LOCK        int = (1 << 6) /* use temp lock before access */
	DICT_FLAG_DUP_REPLACE int = (1 << 7) /* replace dups if supported */
	DICT_FLAG_SYNC_UPDATE int = (1 << 8) /* sync updates if supported */
	DICT_FLAG_DEBUG       int = (1 << 9) /* log access */
	/*DICT_FLAG_FOLD_KEY int = (1<<10) /* lowercase the lookup key */
	DICT_FLAG_NO_REGSUB       int = (1 << 11) /* disallow regexp substitution */
	DICT_FLAG_NO_PROXY        int = (1 << 12) /* disallow proxy mapping */
	DICT_FLAG_NO_UNAUTH       int = (1 << 13) /* disallow unauthenticated data */
	DICT_FLAG_FOLD_FIX        int = (1 << 14) /* case-fold key with fixed-case map */
	DICT_FLAG_FOLD_MUL        int = (1 << 15) /* case-fold key with multi-case map */
	DICT_FLAG_FOLD_ANY        int = (DICT_FLAG_FOLD_FIX | DICT_FLAG_FOLD_MUL)
	DICT_FLAG_OPEN_LOCK       int = (1 << 16) /* perm lock if not multi-writer safe */
	DICT_FLAG_BULK_UPDATE     int = (1 << 17) /* optimize for bulk updates */
	DICT_FLAG_MULTI_WRITER    int = (1 << 18) /* multi-writer safe map */
	DICT_FLAG_UTF8_REQUEST    int = (1 << 19) /* activate UTF-8 if possible */
	DICT_FLAG_UTF8_ACTIVE     int = (1 << 20) /* UTF-8 proxy layer is present */
	DICT_FLAG_SRC_RHS_IS_FILE int = (1 << 21) /* Map source RHS is a file */
)

* See dict_open.c embedded manpage for flag definitions.

View Source
const (
	DICT_ERR_NONE   int = 0    /* no error */
	DICT_ERR_RETRY  int = (-1) /* soft error */
	DICT_ERR_CONFIG int = (-2) /* configuration error */
)

* dict->error values. Errors must be negative; smtpd_check depends on this.

View Source
const (
	DICT_SEQ_FUN_FIRST = 0 /* set cursor to first record */
	DICT_SEQ_FUN_NEXT  = 1 /* set cursor to next record */
)

* Sequence function types.

View Source
const (
	EXTPAR_FLAG_NONE    = (0)
	EXTPAR_FLAG_STRIP   = (1 << 0) /* "{ text }" -> "text" */
	EXTPAR_FLAG_EXTRACT = (1 << 1) /* hint from caller's caller */
)
View Source
const (
	MAC_EXP_BVAL_TRUE  = "true"
	MAC_EXP_BVAL_FALSE = ""
)
View Source
const (
	MAC_EXP_MODE_TEST = 0
	MAC_EXP_MODE_USE  = 1
)
View Source
const (
	MAC_EXP_FLAG_NONE      int = (0)
	MAC_EXP_FLAG_RECURSE   int = (1 << 0)
	MAC_EXP_FLAG_APPEND    int = (1 << 1)
	MAC_EXP_FLAG_SCAN      int = (1 << 2)
	MAC_EXP_FLAG_PRINTABLE int = (1 << 3)
)
View Source
const (
	MAC_EXP_OP_RES_TRUE  = 0
	MAC_EXP_OP_RES_FALSE = 1
	MAC_EXP_OP_RES_ERROR = 2
)
View Source
const (
	MAC_EXP_OP_TOK_NONE = 0 /* Sentinel */
	MAC_EXP_OP_TOK_EQ   = 1 /* == */
	MAC_EXP_OP_TOK_NE   = 2 /* != */
	MAC_EXP_OP_TOK_LT   = 3 /* < */
	MAC_EXP_OP_TOK_LE   = 4 /* <= */
	MAC_EXP_OP_TOK_GE   = 5 /* >= */
	MAC_EXP_OP_TOK_GT   = 6 /* > */
)

* Token codes, public so tha they are available to mac_expand_add_relop()

View Source
const (
	MAC_EXP_OP_STR_EQ  = "=="
	MAC_EXP_OP_STR_NE  = "!="
	MAC_EXP_OP_STR_LT  = "<"
	MAC_EXP_OP_STR_LE  = "<="
	MAC_EXP_OP_STR_GE  = ">="
	MAC_EXP_OP_STR_GT  = ">"
	MAC_EXP_OP_STR_ANY = "\"" + MAC_EXP_OP_STR_EQ +
		"\" or \"" + MAC_EXP_OP_STR_NE + "\"" +
		"\" or \"" + MAC_EXP_OP_STR_LT + "\"" +
		"\" or \"" + MAC_EXP_OP_STR_LE + "\"" +
		"\" or \"" + MAC_EXP_OP_STR_GE + "\"" +
		"\" or \"" + MAC_EXP_OP_STR_GT + "\""
)

* Relational operators. The MAC_EXP_OP_TOK_* are defined in the header * file.

View Source
const (
	MAC_PARSE_LITERAL int = 1              // The content of buf is literal text.
	MAC_PARSE_EXPR    int = 2              // The content of buf is a macro expression.
	MAC_PARSE_VARNAME int = MAC_PARSE_EXPR // 2.1 compatibility
)
View Source
const (
	MAC_PARSE_OK    int = 0        // No errors detected during macro parsing
	MAC_PARSE_ERROR int = (1 << 0) // A parsing error was detected.
	MAC_PARSE_UNDEF int = (1 << 1) // A macro was expanded but not defined.
	MAC_PARSE_USER  int = 2        // start user definitions
)
View Source
const (
	MYFLOCK_STYLE_FLOCK int = 1
	MYFLOCK_STYLE_FCNTL int = 2
)

* Lock styles.

View Source
const (
	MYFLOCK_OP_NONE      int = 0
	MYFLOCK_OP_SHARED    int = 1 << 1
	MYFLOCK_OP_EXCLUSIVE int = 1 << 2
	MYFLOCK_OP_NOWAIT    int = 1 << 3
	MYFLOCK_OP_BITS      int = (MYFLOCK_OP_SHARED | MYFLOCK_OP_EXCLUSIVE | MYFLOCK_OP_NOWAIT)
)

* Lock request types.

View Source
const (
	CHARS_COMMA_SP string = ", \t\r\n" // list separator
	CHARS_SPACE    string = " \t\r\n"  // word separator
	CHARS_BRACE    string = "{}"       // grouping
)

* The subsets of flags that control how a map is used. These are relevant * mainly for proxymap support. Note: some categories overlap. * * DICT_FLAG_IMPL_MASK - flags that are set by the map implementation itself. * * DICT_FLAG_PARANOID - requestor flags that forbid the use of insecure map * types for security-sensitive operations. These flags are checked by the * map implementation itself upon open, lookup etc. requests. * * DICT_FLAG_RQST_MASK - all requestor flags, including paranoid flags, that * the requestor may change between open, lookup etc. requests. These * specify requestor properties, not map properties. * * DICT_FLAG_INST_MASK - none of the above flags. The requestor may not change * these flags between open, lookup, etc. requests (although a map may make * changes to its copy of some of these flags). The proxymap server opens * only one map instance for all client requests with the same values of * these flags, and the proxymap client uses its own saved copy of these * flags. DICT_FLAG_SRC_RHS_IS_FILE is an example of such a flag.

View Source
const DICT_FLAG_UTF8_MASK int = (DICT_FLAG_UTF8_REQUEST)
View Source
const DICT_OWNER_TRUSTED int = (0) // ex: root-owned config file
View Source
const DICT_OWNER_UNKNOWN int = (-1) // ex: unauthenticated tcp, proxy

* Note that trust levels are not in numerical order.

View Source
const DICT_OWNER_UNTRUSTED int = (1) // ex: non-root config file
View Source
const DONT_GRIPE = 0
View Source
const DO_GRIPE = 1
View Source
const INTERNAL_LOCK int = MYFLOCK_STYLE_FLOCK
View Source
const MAC_EXP_WHITESPACE string = CHARS_SPACE
View Source
const VALID_HOSTNAME_LEN = 255 /* RFC 1035 */
View Source
const VALID_LABEL_LEN = 63 /* RFC 1035 */

Variables

View Source
var DICT_TYPE_HT = "internal"
View Source
var MsgVerbose int = 0

Functions

func AllAlnum

func AllAlnum(str string) bool

func AllDig

func AllDig(str string) bool

func DictEval

func DictEval(dict_name string, value string, recursive bool) string

func DictLoadFileXt

func DictLoadFileXt(dict_name string, path string) error

func DictLoadFp

func DictLoadFp(dict_name string, fd *os.File)

func DictLookup

func DictLookup(dict_name string, name string) string

func DictRegister

func DictRegister(dict_name string, dict_info *Dict)

func DictUnregister

func DictUnregister(dict_name string)

func DictUpdate

func DictUpdate(dict_name string, name string, value string) error

func DirForest

func DirForest(path string, depth int) string

func ExtPar

func ExtPar(val string, parens string, flags int) (string, error)

func GetLogger

func GetLogger() *zap.Logger

func IsHSpace

func IsHSpace(r rune) bool

func LoggerConfig

func LoggerConfig(decorators map[string]string)

func MacExpand

func MacExpand(result *strings.Builder, pattern string, flags int, filter *string, lookup func(string, int, interface{}) (string, error), context interface{}) int

func MacParse

func MacParse(value string, action func(int, string, interface{}) int, context interface{}) int

MacParse locates macro references in string

MacParse breaks up its string argument into macro references and other text, and invokes the action routine for each item found. With each action routine call, the type argument indicates what was found, buf contains a copy of the text found, and context is passed on unmodified from the caller. The application is at liberty to clobber buf.

Values for type argument in action:

MAC_PARSE_LITERAL  // We parsed non-macro literal text
MAC_PARSE_EXPR     // either a bare macro name without the preceding "$",
                   // or all the text inside $() or ${}.

func MsgDPanic

func MsgDPanic(msg string, kv ...any)

func MsgDPanicf

func MsgDPanicf(format string, a ...any)

func MsgDebug

func MsgDebug(msg string, kv ...any)

func MsgDebugf

func MsgDebugf(format string, a ...any)

func MsgError

func MsgError(msg string, kv ...any)

func MsgErrorf

func MsgErrorf(format string, a ...any)

func MsgFatal

func MsgFatal(msg string, kv ...any)

func MsgFatalf

func MsgFatalf(format string, a ...any)

func MsgInfo

func MsgInfo(msg string, kv ...any)

func MsgInfof

func MsgInfof(format string, a ...any)

func MsgPanic

func MsgPanic(msg string, kv ...any)

func MsgPanicf

func MsgPanicf(format string, a ...any)

func MsgWarn

func MsgWarn(msg string, kv ...any)

func MsgWarnf

func MsgWarnf(format string, a ...any)

func MyFlock

func MyFlock(fd int, lock_style int, operation int) int

func MyStrTok

func MyStrTok(src string, sep string) []string

MyStrTok - safe tokenizer

func MyStrTokDQ

func MyStrTokDQ(src string, sep string) []string

func MyStrTokQ

func MyStrTokQ(src string, sep string, parens string) []string

MyStrTokQ - safe tokenizer with quoting support

func SafeGetenv

func SafeGetenv(name string) string

SafeGetenv - read environment variable with guard

func SetLogger

func SetLogger(logger *zap.Logger)

func SplitNameVal

func SplitNameVal(buf string) (string, string, error)

SplitNameVal takes a logical line from Readlline and expects text of the form "name = value" or "name =".

The buffer argument is broken up into name and value substrings.

func Unsafe

func Unsafe() bool

Unsafe Can we trust user-provided environment, working directory, etc.

func UpdateEnv

func UpdateEnv(preserve_list []string)

Types

type Dict

type Dict struct {
	Type     string /* for diagnostics */
	Name     string /* for diagnostics */
	Flags    int    /* see below */
	Lookup   func(string) (string, error)
	Update   func(string, string) error
	Delete   func(string) error
	Sequence func(int, *string, *string)
	Lock     func(int) int
	Close    func()
	LockType int       /* for read/write lock */
	LockFd   int       /* for read/write lock */
	StatFd   int       /* change detection */
	ModTime  time.Time /* mod time at open */
	Owner    DictOwner /* provenance */
	Error    int       /* last operation only */

}

func DictAlloc

func DictAlloc(dict_type string, dict_name string) *Dict

func DictFindForUpdate

func DictFindForUpdate(dict_name string) *Dict

func DictHandle

func DictHandle(dict_name string) *Dict

func DictHtOpen

func DictHtOpen(name string, _ int, flags int) *Dict

type DictOwner

type DictOwner struct {
	Status int // see below
	Uid    int // use only if status == UNTRUSTED
}

type DictUtf8Backup

type DictUtf8Backup struct {
	Lookup func(*Dict, string) string
	Update func(*Dict, string, string) int
	Delete func(*Dict, string) int
}

type LogicalLine

type LogicalLine struct {
	LineNo    int
	FirstLine int
	// contains filtered or unexported fields
}

func (*LogicalLine) Readllines

func (ll *LogicalLine) Readllines() (string, error)

type MacExpandContext

type MacExpandContext struct {
	Result  *strings.Builder
	Flags   int
	Filter  *string
	Lookup  func(string, int, interface{}) (string, error)
	Context interface{}
	Status  int
	Level   int
}

func (*MacExpandContext) String

func (m *MacExpandContext) String() string

type RuneScanner

type RuneScanner struct {
	Pos int
	Off int
	// contains filtered or unexported fields
}

func NewRuneScanner

func NewRuneScanner(str string) *RuneScanner

func (*RuneScanner) Emit

func (s *RuneScanner) Emit() string

func (*RuneScanner) End

func (s *RuneScanner) End(sync bool)

func (*RuneScanner) Next

func (s *RuneScanner) Next() rune

func (*RuneScanner) Peek

func (s *RuneScanner) Peek() rune

func (*RuneScanner) PosString

func (s *RuneScanner) PosString() string

func (*RuneScanner) Push

func (s *RuneScanner) Push()

func (*RuneScanner) Reset

func (s *RuneScanner) Reset()

func (*RuneScanner) Scan

func (s *RuneScanner) Scan() rune

func (*RuneScanner) Skip

func (s *RuneScanner) Skip(cmp func(rune) bool)

func (*RuneScanner) Span

func (s *RuneScanner) Span(cmp func(rune) bool)

func (*RuneScanner) String

func (s *RuneScanner) String() string

func (*RuneScanner) Sync

func (s *RuneScanner) Sync()

Jump to

Keyboard shortcuts

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