parser

package
v0.0.0-...-de33553 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DEVICE_TYPE_INVALID              = -1
	DEVICE_TYPE_DESKTOP              = 0
	DEVICE_TYPE_SMARTPHONE           = 1
	DEVICE_TYPE_TABLET               = 2
	DEVICE_TYPE_FEATURE_PHONE        = 3
	DEVICE_TYPE_CONSOLE              = 4
	DEVICE_TYPE_TV                   = 5 // including set top boxes, blu-ray players,...
	DEVICE_TYPE_CAR_BROWSER          = 6
	DEVICE_TYPE_SMART_DISPLAY        = 7
	DEVICE_TYPE_CAMERA               = 8
	DEVICE_TYPE_PORTABLE_MEDIA_PAYER = 9
	DEVICE_TYPE_PHABLET              = 10
	DEVICE_TYPE_SMART_SPEAKER        = 11
	DEVICE_TYPE_WEARABLE             = 12 // including set watches, headsets
)
View Source
const (
	PlatformTypeARM  = "ARM"
	PlatformTypeX64  = "x64"
	PlatformTypeX86  = "x86"
	PlatformTypeNONE = ""
)
View Source
const FixtureFileBot = `bots.yml`
View Source
const FixtureFileOs = "oss.yml"
View Source
const FixtureFileVendor = "vendorfragments.yml"
View Source
const ParserNameBot = `bot`
View Source
const ParserNameOs = "os"
View Source
const ParserNameVendor = "vendorfragments"
View Source
const Unknown = "Unknown"
View Source
const UnknownShort = "UNK"
View Source
const VERSION_TRUNCATION_BUILD = 3

Versioning constant used to set versioning to build number Version examples are: 3.4.0.12, 5.6.334.0, 6.234.2.3, 0.200.3.1, 1.2.3.0, ...

View Source
const VERSION_TRUNCATION_MAJOR = 0

Versioning constant used to set max versioning to major version only Version examples are: 3, 5, 6, 200, 123, ...

View Source
const VERSION_TRUNCATION_MINOR = 1

Versioning constant used to set max versioning to minor version Version examples are: 3.4, 5.6, 6.234, 0.200, 1.23, ...

View Source
const VERSION_TRUNCATION_NONE = -1

Versioning constant used to set versioning to unlimited (no truncation)

View Source
const VERSION_TRUNCATION_PATCH = 2

Versioning constant used to set max versioning to path level Version examples are: 3.4.0, 5.6.344, 6.234.2, 0.200.3, 1.2.3, ...

Variables

View Source
var EmptyBotMatchResult = new(BotMatchResult)
View Source
var OperatingSystems = map[string]string{
	`AIX`: `AIX`,
	`AND`: `Android`,
	`AMG`: `AmigaOS`,
	`ATV`: `Apple TV`,
	`ARL`: `Arch Linux`,
	`BTR`: `BackTrack`,
	`SBA`: `Bada`,
	`BEO`: `BeOS`,
	`BLB`: `BlackBerry OS`,
	`QNX`: `BlackBerry Tablet OS`,
	`BMP`: `Brew`,
	`CES`: `CentOS`,
	`COS`: `Chrome OS`,
	`CYN`: `CyanogenMod`,
	`DEB`: `Debian`,
	`DFB`: `DragonFly`,
	`FED`: `Fedora`,
	`FOS`: `Firefox OS`,
	`FIR`: `Fire OS`,
	`BSD`: `FreeBSD`,
	`GNT`: `Gentoo`,
	`GTV`: `Google TV`,
	`HPX`: `HP-UX`,
	`HAI`: `Haiku OS`,
	`IRI`: `IRIX`,
	`INF`: `Inferno`,
	`KOS`: `KaiOS`,
	`KNO`: `Knoppix`,
	`KBT`: `Kubuntu`,
	`LIN`: `GNU/Linux`,
	`LBT`: `Lubuntu`,
	`VLN`: `VectorLinux`,
	`MAC`: `Mac`,
	`MAE`: `Maemo`,
	`MDR`: `Mandriva`,
	`SMG`: `MeeGo`,
	`MCD`: `MocorDroid`,
	`MIN`: `Mint`,
	`MLD`: `MildWild`,
	`MOR`: `MorphOS`,
	`NBS`: `NetBSD`,
	`MTK`: `MTK / Nucleus`,
	`WII`: `Nintendo`,
	`NDS`: `Nintendo Mobile`,
	`OS2`: `OS/2`,
	`T64`: `OSF1`,
	`OBS`: `OpenBSD`,
	`ORD`: `Ordissimo`,
	`PSP`: `PlayStation Portable`,
	`PS3`: `PlayStation`,
	`RHT`: `Red Hat`,
	`ROS`: `RISC OS`,
	`REM`: `Remix OS`,
	`RZD`: `RazoDroiD`,
	`SAB`: `Sabayon`,
	`SSE`: `SUSE`,
	`SAF`: `Sailfish OS`,
	`SLW`: `Slackware`,
	`SOS`: `Solaris`,
	`SYL`: `Syllable`,
	`SYM`: `Symbian`,
	`SYS`: `Symbian OS`,
	`S40`: `Symbian OS Series 40`,
	`S60`: `Symbian OS Series 60`,
	`SY3`: `Symbian^3`,
	`TDX`: `ThreadX`,
	`TIZ`: `Tizen`,
	`TOS`: `TmaxOS`,
	`UBT`: `Ubuntu`,
	`WTV`: `WebTV`,
	`WIN`: `Windows`,
	`WCE`: `Windows CE`,
	`WIO`: `Windows IoT`,
	`WMO`: `Windows Mobile`,
	`WPH`: `Windows Phone`,
	`WRT`: `Windows RT`,
	`XBX`: `Xbox`,
	`XBT`: `Xubuntu`,
	`YNS`: `YunOs`,
	`IOS`: `iOS`,
	`POS`: `palmOS`,
	`WOS`: `webOS`,
}

Known operating systems mapped to their internal short codes

View Source
var OsFamilies = map[string][]string{
	`Android`:               []string{`AND`, `CYN`, `FIR`, `REM`, `RZD`, `MLD`, `MCD`, `YNS`},
	`AmigaOS`:               []string{`AMG`, `MOR`},
	`Apple TV`:              []string{`ATV`},
	`BlackBerry`:            []string{`BLB`, `QNX`},
	`Brew`:                  []string{`BMP`},
	`BeOS`:                  []string{`BEO`, `HAI`},
	`Chrome OS`:             []string{`COS`},
	`Firefox OS`:            []string{`FOS`, `KOS`},
	`Gaming Console`:        []string{`WII`, `PS3`},
	`Google TV`:             []string{`GTV`},
	`IBM`:                   []string{`OS2`},
	`iOS`:                   []string{`IOS`},
	`RISC OS`:               []string{`ROS`},
	`GNU/Linux`:             []string{`LIN`, `ARL`, `DEB`, `KNO`, `MIN`, `UBT`, `KBT`, `XBT`, `LBT`, `FED`, `RHT`, `VLN`, `MDR`, `GNT`, `SAB`, `SLW`, `SSE`, `CES`, `BTR`, `SAF`, `ORD`, `TOS`},
	`Mac`:                   []string{`MAC`},
	`Mobile Gaming Console`: []string{`PSP`, `NDS`, `XBX`},
	`Real-time OS`:          []string{`MTK`, `TDX`},
	`Other Mobile`:          []string{`WOS`, `POS`, `SBA`, `TIZ`, `SMG`, `MAE`},
	`Symbian`:               []string{`SYM`, `SYS`, `SY3`, `S60`, `S40`},
	`Unix`:                  []string{`SOS`, `AIX`, `HPX`, `BSD`, `NBS`, `OBS`, `DFB`, `SYL`, `IRI`, `T64`, `INF`},
	`WebTV`:                 []string{`WTV`},
	`Windows`:               []string{`WIN`},
	`Windows Mobile`:        []string{`WPH`, `WMO`, `WCE`, `WRT`, `WIO`},
}

Operating system families mapped to the short codes of the associated operating systems

Functions

func ArrayContainsString

func ArrayContainsString(list []string, v string) bool

func BuildByMatch

func BuildByMatch(item string, matches []string) string

func BuildModel

func BuildModel(m string, matches []string) string

func BuildVersion

func BuildVersion(versionString string, matches []string) string

func FindBrand

func FindBrand(key string) string

func GetAvailableDeviceTypeNames

func GetAvailableDeviceTypeNames() []string

Returns names of all available device types

func GetBotCreater

func GetBotCreater(name string) func(string) BotParser

func GetDeviceName

func GetDeviceName(deviceType int) string

Returns the name of the given device type

func GetDeviceType

func GetDeviceType(deviceName string) int

func GetFullName

func GetFullName(brandId string) string

Returns the full brand name for the given short name

func GetOsFamily

func GetOsFamily(osLabel string) string

func GetOsNameFromId

func GetOsNameFromId(os, ver string) string

func GetShortName

func GetShortName(name string) string

func MatchUserAgent

func MatchUserAgent(ua, regex string) []string

func NameEqual

func NameEqual(a string, b string) bool

func ReadRegexFileFromMemory

func ReadRegexFileFromMemory(file string, v interface{}) error

func ReadYamlFileFromDisk

func ReadYamlFileFromDisk(file string, v interface{}) error

func RegBotParser

func RegBotParser(name string, f func(string) BotParser)

func SetVersionTruncation

func SetVersionTruncation(t int)

func StringContainsLetter

func StringContainsLetter(ua string) bool

func StringEqualIgnoreCase

func StringEqualIgnoreCase(a string, b string) bool

Types

type Bot

type Bot struct {
	BotParserAbstract
}

Parses a user agent for bot information

func NewBot

func NewBot(fileName string) *Bot

type BotMatchResult

type BotMatchResult struct {
	Name     string   `yaml:"name" json:"name"`
	Category string   `yaml:"category" json:"category"`
	Url      string   `yaml:"url" json:"url"`
	Producer Producer `yaml:"producer" json:"producer"`
}

func (*BotMatchResult) Equal

func (b *BotMatchResult) Equal(a *BotMatchResult) bool

type BotParser

type BotParser interface {
	PreMatch(string) bool
	Parse(string) *BotMatchResult
	DiscardDetails(bool)
}

func NewBotParser

func NewBotParser(dir, name string) BotParser

type BotParserAbstract

type BotParserAbstract struct {
	Regexes    []*BotReg
	ParserName string
	// contains filtered or unexported fields
}

Abstract class for all bot parsers

func (*BotParserAbstract) DiscardDetails

func (b *BotParserAbstract) DiscardDetails(v bool)

func (*BotParserAbstract) Load

func (b *BotParserAbstract) Load(file string) error

func (*BotParserAbstract) Parse

func (b *BotParserAbstract) Parse(ua string) *BotMatchResult

Parses the current UA and checks whether it contains bot information

func (*BotParserAbstract) PreMatch

func (b *BotParserAbstract) PreMatch(ua string) bool

type BotReg

type BotReg struct {
	Regular        `yaml:",inline" json:",inline"`
	BotMatchResult `yaml:",inline" json:",inline"`
}

type MatchResult

type MatchResult interface {
	GetName() string
	SetName(string)
}

type OsMatchResult

type OsMatchResult struct {
	Name      string `yaml:"name" json:"name"`
	ShortName string `yaml:"short_name" json:"short_name"`
	Version   string `yaml:"version" json:"version"`
	Platform  string `yaml:"platform" json:"platform"`
}

type OsParser

type OsParser interface {
	PreMatch(string) bool
	Parse(string) *OsMatchResult
}

type OsReg

type OsReg struct {
	Regular `yaml:",inline" json:",inline"`
	Name    string `yaml:"name" json:"name"`
	Version string `yaml:"version" json:"version"`
}

type Oss

type Oss struct {
	Regexes []*OsReg
	// contains filtered or unexported fields
}

Parses the useragent for operating system information

func NewOss

func NewOss(file string) (*Oss, error)

func (*Oss) Parse

func (o *Oss) Parse(ua string) *OsMatchResult

func (*Oss) ParsePlatform

func (o *Oss) ParsePlatform(ua string) string

func (*Oss) PreMatch

func (o *Oss) PreMatch(ua string) bool

type PlatformReg

type PlatformReg struct {
	Name string
	Regular
}

type Producer

type Producer struct {
	Name string `yaml:"name" json:"name"`
	Url  string `yaml:"url" json:"url"`
}

type Regexp

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

func NewRegexp

func NewRegexp(re string) *Regexp

func (*Regexp) Compile

func (r *Regexp) Compile() error

func (*Regexp) FindStringSubmatch

func (r *Regexp) FindStringSubmatch(ua string) []string

func (*Regexp) MatchString

func (r *Regexp) MatchString(ua string) bool

func (*Regexp) MustCompile

func (r *Regexp) MustCompile()

type Regular

type Regular struct {
	Regex  string `yaml:"regex" json:"regex"`
	Regexp *Regexp
}

func (*Regular) Compile

func (r *Regular) Compile() *Regexp

func (*Regular) IsMatchUserAgent

func (r *Regular) IsMatchUserAgent(ua string) bool

func (*Regular) MatchUserAgent

func (r *Regular) MatchUserAgent(ua string) []string

type VendorFragments

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

Device parser for vendor fragment detection

func NewVendor

func NewVendor(file string) (*VendorFragments, error)

func (*VendorFragments) Parse

func (v *VendorFragments) Parse(ua string) string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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