From fd9ee780ed713c10f122f9eb83e07bfdf09ce4a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Espino?= Date: Wed, 7 Mar 2018 17:56:24 +0000 Subject: Readding uasurfer library (#8420) --- vendor/github.com/avct/uasurfer/.gitignore | 56 ++ vendor/github.com/avct/uasurfer/.travis.yml | 11 + vendor/github.com/avct/uasurfer/LICENSE | 192 ++++ vendor/github.com/avct/uasurfer/README.md | 169 ++++ vendor/github.com/avct/uasurfer/browser.go | 192 ++++ vendor/github.com/avct/uasurfer/const_string.go | 49 + vendor/github.com/avct/uasurfer/device.go | 60 ++ vendor/github.com/avct/uasurfer/system.go | 336 +++++++ vendor/github.com/avct/uasurfer/uasurfer.go | 227 +++++ vendor/github.com/avct/uasurfer/uasurfer_test.go | 1074 ++++++++++++++++++++++ 10 files changed, 2366 insertions(+) create mode 100644 vendor/github.com/avct/uasurfer/.gitignore create mode 100644 vendor/github.com/avct/uasurfer/.travis.yml create mode 100644 vendor/github.com/avct/uasurfer/LICENSE create mode 100644 vendor/github.com/avct/uasurfer/README.md create mode 100644 vendor/github.com/avct/uasurfer/browser.go create mode 100644 vendor/github.com/avct/uasurfer/const_string.go create mode 100644 vendor/github.com/avct/uasurfer/device.go create mode 100644 vendor/github.com/avct/uasurfer/system.go create mode 100644 vendor/github.com/avct/uasurfer/uasurfer.go create mode 100644 vendor/github.com/avct/uasurfer/uasurfer_test.go (limited to 'vendor') diff --git a/vendor/github.com/avct/uasurfer/.gitignore b/vendor/github.com/avct/uasurfer/.gitignore new file mode 100644 index 000000000..35ba52a16 --- /dev/null +++ b/vendor/github.com/avct/uasurfer/.gitignore @@ -0,0 +1,56 @@ +# Compiled bin # +################### + + +# Compiled source # +################### +*.dll +*.exe +*.o +*.so + +# Packages # +############ +# it's better to unpack these files and commit the raw source +# git has its own built in compression methods +*.7z +*.dmg +*.gz +*.iso +*.jar +*.rar +*.tar +*.zip + +# Configuration Files # +####################### +*.cfg + +# Logs and databases # +###################### +*.log +*.sql +*.sqlite +logs +coverage.html +coverage.out + +# Test Files # +####################### +*.test + +# OS generated files # +###################### +.DS_Store +.DS_Store? +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db + +# go.rice generated files +*.rice-box.go + +# Dev Tools # +###################### +.vagrant \ No newline at end of file diff --git a/vendor/github.com/avct/uasurfer/.travis.yml b/vendor/github.com/avct/uasurfer/.travis.yml new file mode 100644 index 000000000..77b64e6f2 --- /dev/null +++ b/vendor/github.com/avct/uasurfer/.travis.yml @@ -0,0 +1,11 @@ +sudo: false + +language: go + +go: + - 1.9.x + - 1.8.x + - 1.7.x + +script: + - go test diff --git a/vendor/github.com/avct/uasurfer/LICENSE b/vendor/github.com/avct/uasurfer/LICENSE new file mode 100644 index 000000000..a092343b2 --- /dev/null +++ b/vendor/github.com/avct/uasurfer/LICENSE @@ -0,0 +1,192 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + Copyright 2015 Avocet Systems Ltd. + http://avocet.io/opensource + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + Copyright 2015 Avocet Systems Ltd. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. \ No newline at end of file diff --git a/vendor/github.com/avct/uasurfer/README.md b/vendor/github.com/avct/uasurfer/README.md new file mode 100644 index 000000000..2a4ab608d --- /dev/null +++ b/vendor/github.com/avct/uasurfer/README.md @@ -0,0 +1,169 @@ +[![Build Status](https://travis-ci.org/avct/uasurfer.svg?branch=master)](https://travis-ci.org/avct/uasurfer) [![GoDoc](https://godoc.org/github.com/avct/uasurfer?status.svg)](https://godoc.org/github.com/avct/uasurfer) [![Go Report Card](https://goreportcard.com/badge/github.com/avct/uasurfer)](https://goreportcard.com/report/github.com/avct/uasurfer) + +# uasurfer + +![uasurfer-100px](https://cloud.githubusercontent.com/assets/597902/16172506/9debc136-357a-11e6-90fb-c7c46f50dff0.png) + +**User Agent Surfer** (uasurfer) is a lightweight Golang package that parses and abstracts [HTTP User-Agent strings](https://en.wikipedia.org/wiki/User_agent) with particular attention to device type. + +The following information is returned by uasurfer from a raw HTTP User-Agent string: + +| Name | Example | Coverage in 192,792 parses | +|----------------|---------|--------------------------------| +| Browser name | `chrome` | 99.85% | +| Browser version | `53` | 99.17% | +| Platform | `ipad` | 99.97% | +| OS name | `ios` | 99.96% | +| OS version | `10` | 98.81% | +| Device type | `tablet` | 99.98% | + +Layout engine, browser language, and other esoteric attributes are not parsed. + +Coverage is estimated from a random sample of real UA strings collected across thousands of sources in US and EU mid-2016. + +## Usage + +### Parse(ua string) Function + +The `Parse()` function accepts a user agent `string` and returns UserAgent struct with named constants and integers for versions (minor, major and patch separately), and the full UA string that was parsed (lowercase). A string can be retrieved by adding `.String()` to a variable, such as `uasurfer.BrowserName.String()`. + +``` +// Define a user agent string +myUA := "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36" + +// Parse() returns all attributes, including returning the full UA string last +ua, uaString := uasurfer.Parse(myUA) +``` + +where example UserAgent is: +``` +{ + Browser { + BrowserName: BrowserChrome, + Version: { + Major: 45, + Minor: 0, + Patch: 2454, + }, + }, + OS { + Platform: PlatformMac, + Name: OSMacOSX, + Version: { + Major: 10, + Minor: 10, + Patch: 5, + }, + }, + DeviceType: DeviceComputer, +} +``` + +**Usage note:** There are some OSes that do not return a version, see docs below. Linux is typically not reported with a specific Linux distro name or version. + +#### Browser Name +* `BrowserChrome` - Google [Chrome](https://en.wikipedia.org/wiki/Google_Chrome), [Chromium](https://en.wikipedia.org/wiki/Chromium_(web_browser)) +* `BrowserSafari` - Apple [Safari](https://en.wikipedia.org/wiki/Safari_(web_browser)), Google Search ([GSA](https://itunes.apple.com/us/app/google/id284815942)) +* `BrowserIE` - Microsoft [Internet Explorer](https://en.wikipedia.org/wiki/Internet_Explorer), [Edge](https://en.wikipedia.org/wiki/Microsoft_Edge) +* `BrowserFirefox` - Mozilla [Firefox](https://en.wikipedia.org/wiki/Firefox), GNU [IceCat](https://en.wikipedia.org/wiki/GNU_IceCat), [Iceweasel](https://en.wikipedia.org/wiki/Mozilla_Corporation_software_rebranded_by_the_Debian_project#Iceweasel), [Seamonkey](https://en.wikipedia.org/wiki/SeaMonkey) +* `BrowserAndroid` - Android [WebView](https://developer.chrome.com/multidevice/webview/overview) (Android OS <4.4 only) +* `BrowserOpera` - [Opera](https://en.wikipedia.org/wiki/Opera_(web_browser)) +* `BrowserUCBrowser` - [UC Browser](https://en.wikipedia.org/wiki/UC_Browser) +* `BrowserSilk` - Amazon [Silk](https://en.wikipedia.org/wiki/Amazon_Silk) +* `BrowserSpotify` - [Spotify](https://en.wikipedia.org/wiki/Spotify#Clients) desktop client +* `BrowserBlackberry` - RIM [BlackBerry](https://en.wikipedia.org/wiki/BlackBerry) +* `BrowserUnknown` - Unknown + +#### Browser Version + +Browser version returns an `unint8` of the major version attribute of the User-Agent String. For example Chrome 45.0.23423 would return `45`. The intention is to support math operators with versions, such as "do XYZ for Chrome version >23". + +Unknown version is returned as `0`. + +#### Platform +* `PlatformWindows` - Microsoft Windows +* `PlatformMac` - Apple Macintosh +* `PlatformLinux` - Linux, including Android and other OSes +* `PlatformiPad` - Apple iPad +* `PlatformiPhone` - Apple iPhone +* `PlatformBlackberry` - RIM Blackberry +* `PlatformWindowsPhone` Microsoft Windows Phone & Mobile +* `PlatformKindle` - Amazon Kindle & Kindle Fire +* `PlatformPlaystation` - Sony Playstation, Vita, PSP +* `PlatformXbox` - Microsoft Xbox - `PlatformXbox` +* `PlatformNintendo` - Nintendo DS, Wii, etc. +* `PlatformUnknown` - Unknown + +#### OS Name +* `OSWindows` +* `OSMacOSX` - includes "macOS Sierra" +* `OSiOS` +* `OSAndroid` +* `OSChromeOS` +* `OSWebOS` +* `OSLinux` +* `OSPlaystation` +* `OSXbox` +* `OSNintendo` +* `OSUnknown` + +#### OS Version + +OS X major version is alway 10 with consecutive minor versions indicating release releases (10 - Yosemite, 11 - El Capitain, 12 Sierra, etc). Windows version is NT version. `Version{0, 0, 0}` indicated version is unknown or not evaluated. +Versions can be compared using `Less` function: `if ver1.Less(ver2) {}` + +Here are some examples across the platform, os.name, and os.version: + +* For Windows XP (Windows NT 5.1), "`PlatformWindows`" is the platform, "`OSWindows`" is the name, and `{5, 1, 0}` the version. +* For OS X 10.5.1, "`PlatformMac`" is the platform, "`OSMacOSX`" the name, and `{10, 5, 1}` the version. +* For Android 5.1, "`PlatformLinux`" is the platform, "`OSAndroid`" is the name, and `{5, 1, 0}` the version. +* For iOS 5.1, "`PlatformiPhone`" or "`PlatformiPad`" is the platform, "`OSiOS`" is the name, and `{5, 1, 0}` the version. + +###### Windows Version Guide + +* Windows 10 - `{10, 0, 0}` +* Windows 8.1 - `{6, 3, 0}` +* Windows 8 - `{6, 2, 0}` +* Windows 7 - `{6, 1, 0}` +* Windows Vista - `{6, 0, 0}` +* Windows XP - `{5, 1, 0}` or `{5, 2, 0}` +* Windows 2000 - `{5, 0, 0}` + +Windows 95, 98, and ME represent 0.01% of traffic worldwide and are not available through this package at this time. + +#### DeviceType +DeviceType is typically quite accurate, though determining between phones and tablets on Android is not always possible due to how some vendors design their UA strings. A mobile Android device without tablet indicator defaults to being classified as a phone. DeviceTV supports major brands such as Philips, Sharp, Vizio and steaming boxes such as Apple, Google, Roku, Amazon. + +* `DeviceComputer` +* `DevicePhone` +* `DeviceTablet` +* `DeviceTV` +* `DeviceConsole` +* `DeviceWearable` +* `DeviceUnknown` + +## Example Combinations of Attributes +* Surface RT -> `OSWindows8`, `DeviceTablet`, OSVersion >= `6` +* Android Tablet -> `OSAndroid`, `DeviceTablet` +* Microsoft Edge -> `BrowserIE`, BrowserVersion >= `12.0.0` + +## To do + +* Remove compiled regexp in favor of string.Contains wherever possible (lowers mem/alloc) +* Better version support on Firefox derivatives (e.g. SeaMonkey) +* Potential additional browser support: + * "NetFront" (1% share in India) + * "QQ Browser" (6.5% share in China) + * "Sogou Explorer" (5% share in China) + * "Maxthon" (1.5% share in China) + * "Nokia" +* Potential additional OS support: + * "Nokia" (5% share in India) + * "Series 40" (5.5% share in India) + * Windows 2003 Server +* iOS safari browser identification based on iOS version +* Add android version to browser identification +* old Macs + * "opera/9.64 (macintosh; ppc mac os x; u; en) presto/2.1.1" +* old Windows + * "mozilla/5.0 (windows nt 4.0; wow64) applewebkit/537.36 (khtml, like gecko) chrome/37.0.2049.0 safari/537.36" diff --git a/vendor/github.com/avct/uasurfer/browser.go b/vendor/github.com/avct/uasurfer/browser.go new file mode 100644 index 000000000..e156818ab --- /dev/null +++ b/vendor/github.com/avct/uasurfer/browser.go @@ -0,0 +1,192 @@ +package uasurfer + +import ( + "strings" +) + +// Browser struct contains the lowercase name of the browser, along +// with its browser version number. Browser are grouped together without +// consideration for device. For example, Chrome (Chrome/43.0) and Chrome for iOS +// (CriOS/43.0) would both return as "chrome" (name) and 43.0 (version). Similarly +// Internet Explorer 11 and Edge 12 would return as "ie" and "11" or "12", respectively. +// type Browser struct { +// Name BrowserName +// Version struct { +// Major int +// Minor int +// Patch int +// } +// } + +// Retrieve browser name from UA strings +func (u *UserAgent) evalBrowserName(ua string) bool { + // Blackberry goes first because it reads as MSIE & Safari + if strings.Contains(ua, "blackberry") || strings.Contains(ua, "playbook") || strings.Contains(ua, "bb10") || strings.Contains(ua, "rim ") { + u.Browser.Name = BrowserBlackberry + return u.isBot() + } + + if strings.Contains(ua, "applewebkit") { + switch { + case strings.Contains(ua, "opr/") || strings.Contains(ua, "opios/"): + u.Browser.Name = BrowserOpera + + case strings.Contains(ua, "silk/"): + u.Browser.Name = BrowserSilk + + case strings.Contains(ua, "edge/") || strings.Contains(ua, "iemobile/") || strings.Contains(ua, "msie "): + u.Browser.Name = BrowserIE + + case strings.Contains(ua, "ucbrowser/") || strings.Contains(ua, "ucweb/"): + u.Browser.Name = BrowserUCBrowser + + // Edge, Silk and other chrome-identifying browsers must evaluate before chrome, unless we want to add more overhead + case strings.Contains(ua, "chrome/") || strings.Contains(ua, "crios/") || strings.Contains(ua, "chromium/") || strings.Contains(ua, "crmo/"): + u.Browser.Name = BrowserChrome + + case strings.Contains(ua, "android") && !strings.Contains(ua, "chrome/") && strings.Contains(ua, "version/") && !strings.Contains(ua, "like android"): + // Android WebView on Android >= 4.4 is purposefully being identified as Chrome above -- https://developer.chrome.com/multidevice/webview/overview + u.Browser.Name = BrowserAndroid + + case strings.Contains(ua, "fxios"): + u.Browser.Name = BrowserFirefox + + case strings.Contains(ua, " spotify/"): + u.Browser.Name = BrowserSpotify + + // AppleBot uses webkit signature as well + case strings.Contains(ua, "applebot"): + u.Browser.Name = BrowserAppleBot + + // presume it's safari unless an esoteric browser is being specified (webOSBrowser, SamsungBrowser, etc.) + case strings.Contains(ua, "like gecko") && strings.Contains(ua, "mozilla/") && strings.Contains(ua, "safari/") && !strings.Contains(ua, "linux") && !strings.Contains(ua, "android") && !strings.Contains(ua, "browser/") && !strings.Contains(ua, "os/"): + u.Browser.Name = BrowserSafari + + // if we got this far and the device is iPhone or iPad, assume safari. Some agents don't actually contain the word "safari" + case strings.Contains(ua, "iphone") || strings.Contains(ua, "ipad"): + u.Browser.Name = BrowserSafari + + // Google's search app on iPhone, leverages native Safari rather than Chrome + case strings.Contains(ua, " gsa/"): + u.Browser.Name = BrowserSafari + + default: + goto notwebkit + + } + return u.isBot() + } + +notwebkit: + switch { + case strings.Contains(ua, "msie") || strings.Contains(ua, "trident"): + u.Browser.Name = BrowserIE + + case strings.Contains(ua, "gecko") && (strings.Contains(ua, "firefox") || strings.Contains(ua, "iceweasel") || strings.Contains(ua, "seamonkey") || strings.Contains(ua, "icecat")): + u.Browser.Name = BrowserFirefox + + case strings.Contains(ua, "presto") || strings.Contains(ua, "opera"): + u.Browser.Name = BrowserOpera + + case strings.Contains(ua, "ucbrowser"): + u.Browser.Name = BrowserUCBrowser + + case strings.Contains(ua, "applebot"): + u.Browser.Name = BrowserAppleBot + + case strings.Contains(ua, "baiduspider"): + u.Browser.Name = BrowserBaiduBot + + case strings.Contains(ua, "adidxbot") || strings.Contains(ua, "bingbot") || strings.Contains(ua, "bingpreview"): + u.Browser.Name = BrowserBingBot + + case strings.Contains(ua, "duckduckbot"): + u.Browser.Name = BrowserDuckDuckGoBot + + case strings.Contains(ua, "facebot") || strings.Contains(ua, "facebookexternalhit"): + u.Browser.Name = BrowserFacebookBot + + case strings.Contains(ua, "googlebot"): + u.Browser.Name = BrowserGoogleBot + + case strings.Contains(ua, "linkedinbot"): + u.Browser.Name = BrowserLinkedInBot + + case strings.Contains(ua, "msnbot"): + u.Browser.Name = BrowserMsnBot + + case strings.Contains(ua, "pingdom.com_bot"): + u.Browser.Name = BrowserPingdomBot + + case strings.Contains(ua, "twitterbot"): + u.Browser.Name = BrowserTwitterBot + + case strings.Contains(ua, "yandex") || strings.Contains(ua, "yadirectfetcher"): + u.Browser.Name = BrowserYandexBot + + case strings.Contains(ua, "yahoo"): + u.Browser.Name = BrowserYahooBot + + case strings.Contains(ua, "phantomjs"): + u.Browser.Name = BrowserBot + + default: + u.Browser.Name = BrowserUnknown + + } + + return u.isBot() +} + +// Retrieve browser version +// Methods used in order: +// 1st: look for generic version/# +// 2nd: look for browser-specific instructions (e.g. chrome/34) +// 3rd: infer from OS (iOS only) +func (u *UserAgent) evalBrowserVersion(ua string) { + // if there is a 'version/#' attribute with numeric version, use it -- except for Chrome since Android vendors sometimes hijack version/# + if u.Browser.Name != BrowserChrome && u.Browser.Version.findVersionNumber(ua, "version/") { + return + } + + switch u.Browser.Name { + case BrowserChrome: + // match both chrome and crios + _ = u.Browser.Version.findVersionNumber(ua, "chrome/") || u.Browser.Version.findVersionNumber(ua, "crios/") || u.Browser.Version.findVersionNumber(ua, "crmo/") + + case BrowserIE: + if u.Browser.Version.findVersionNumber(ua, "msie ") || u.Browser.Version.findVersionNumber(ua, "edge/") { + return + } + + // get MSIE version from trident version https://en.wikipedia.org/wiki/Trident_(layout_engine) + if u.Browser.Version.findVersionNumber(ua, "trident/") { + // convert trident versions 3-7 to MSIE version + if (u.Browser.Version.Major >= 3) && (u.Browser.Version.Major <= 7) { + u.Browser.Version.Major += 4 + } + } + + case BrowserFirefox: + _ = u.Browser.Version.findVersionNumber(ua, "firefox/") || u.Browser.Version.findVersionNumber(ua, "fxios/") + + case BrowserSafari: // executes typically if we're on iOS and not using a familiar browser + u.Browser.Version = u.OS.Version + // early Safari used a version number +1 to OS version + if (u.Browser.Version.Major <= 3) && (u.Browser.Version.Major >= 1) { + u.Browser.Version.Major++ + } + + case BrowserUCBrowser: + _ = u.Browser.Version.findVersionNumber(ua, "ucbrowser/") + + case BrowserOpera: + _ = u.Browser.Version.findVersionNumber(ua, "opr/") || u.Browser.Version.findVersionNumber(ua, "opios/") || u.Browser.Version.findVersionNumber(ua, "opera/") + + case BrowserSilk: + _ = u.Browser.Version.findVersionNumber(ua, "silk/") + + case BrowserSpotify: + _ = u.Browser.Version.findVersionNumber(ua, "spotify/") + } +} diff --git a/vendor/github.com/avct/uasurfer/const_string.go b/vendor/github.com/avct/uasurfer/const_string.go new file mode 100644 index 000000000..2fa21d86d --- /dev/null +++ b/vendor/github.com/avct/uasurfer/const_string.go @@ -0,0 +1,49 @@ +// Code generated by "stringer -type=DeviceType,BrowserName,OSName,Platform -output=const_string.go"; DO NOT EDIT. + +package uasurfer + +import "fmt" + +const _DeviceType_name = "DeviceUnknownDeviceComputerDeviceTabletDevicePhoneDeviceConsoleDeviceWearableDeviceTV" + +var _DeviceType_index = [...]uint8{0, 13, 27, 39, 50, 63, 77, 85} + +func (i DeviceType) String() string { + if i < 0 || i >= DeviceType(len(_DeviceType_index)-1) { + return fmt.Sprintf("DeviceType(%d)", i) + } + return _DeviceType_name[_DeviceType_index[i]:_DeviceType_index[i+1]] +} + +const _BrowserName_name = "BrowserUnknownBrowserChromeBrowserIEBrowserSafariBrowserFirefoxBrowserAndroidBrowserOperaBrowserBlackberryBrowserUCBrowserBrowserSilkBrowserNokiaBrowserNetFrontBrowserQQBrowserMaxthonBrowserSogouExplorerBrowserSpotifyBrowserBotBrowserAppleBotBrowserBaiduBotBrowserBingBotBrowserDuckDuckGoBotBrowserFacebookBotBrowserGoogleBotBrowserLinkedInBotBrowserMsnBotBrowserPingdomBotBrowserTwitterBotBrowserYandexBotBrowserYahooBot" + +var _BrowserName_index = [...]uint16{0, 14, 27, 36, 49, 63, 77, 89, 106, 122, 133, 145, 160, 169, 183, 203, 217, 227, 242, 257, 271, 291, 309, 325, 343, 356, 373, 390, 406, 421} + +func (i BrowserName) String() string { + if i < 0 || i >= BrowserName(len(_BrowserName_index)-1) { + return fmt.Sprintf("BrowserName(%d)", i) + } + return _BrowserName_name[_BrowserName_index[i]:_BrowserName_index[i+1]] +} + +const _OSName_name = "OSUnknownOSWindowsPhoneOSWindowsOSMacOSXOSiOSOSAndroidOSBlackberryOSChromeOSOSKindleOSWebOSOSLinuxOSPlaystationOSXboxOSNintendoOSBot" + +var _OSName_index = [...]uint8{0, 9, 23, 32, 40, 45, 54, 66, 76, 84, 91, 98, 111, 117, 127, 132} + +func (i OSName) String() string { + if i < 0 || i >= OSName(len(_OSName_index)-1) { + return fmt.Sprintf("OSName(%d)", i) + } + return _OSName_name[_OSName_index[i]:_OSName_index[i+1]] +} + +const _Platform_name = "PlatformUnknownPlatformWindowsPlatformMacPlatformLinuxPlatformiPadPlatformiPhonePlatformiPodPlatformBlackberryPlatformWindowsPhonePlatformPlaystationPlatformXboxPlatformNintendoPlatformBot" + +var _Platform_index = [...]uint8{0, 15, 30, 41, 54, 66, 80, 92, 110, 130, 149, 161, 177, 188} + +func (i Platform) String() string { + if i < 0 || i >= Platform(len(_Platform_index)-1) { + return fmt.Sprintf("Platform(%d)", i) + } + return _Platform_name[_Platform_index[i]:_Platform_index[i+1]] +} diff --git a/vendor/github.com/avct/uasurfer/device.go b/vendor/github.com/avct/uasurfer/device.go new file mode 100644 index 000000000..70c00b112 --- /dev/null +++ b/vendor/github.com/avct/uasurfer/device.go @@ -0,0 +1,60 @@ +package uasurfer + +import ( + "strings" +) + +func (u *UserAgent) evalDevice(ua string) { + switch { + + case u.OS.Platform == PlatformWindows || u.OS.Platform == PlatformMac || u.OS.Name == OSChromeOS: + if strings.Contains(ua, "mobile") || strings.Contains(ua, "touch") { + u.DeviceType = DeviceTablet // windows rt, linux haxor tablets + return + } + u.DeviceType = DeviceComputer + + case u.OS.Platform == PlatformiPad || u.OS.Platform == PlatformiPod || strings.Contains(ua, "tablet") || strings.Contains(ua, "kindle/") || strings.Contains(ua, "playbook"): + u.DeviceType = DeviceTablet + + case u.OS.Platform == PlatformiPhone || u.OS.Platform == PlatformBlackberry || strings.Contains(ua, "phone"): + u.DeviceType = DevicePhone + + // long list of smarttv and tv dongle identifiers + case strings.Contains(ua, "tv") || strings.Contains(ua, "crkey") || strings.Contains(ua, "googletv") || strings.Contains(ua, "aftb") || strings.Contains(ua, "adt-") || strings.Contains(ua, "roku") || strings.Contains(ua, "viera") || strings.Contains(ua, "aquos") || strings.Contains(ua, "dtv") || strings.Contains(ua, "appletv") || strings.Contains(ua, "smarttv") || strings.Contains(ua, "tuner") || strings.Contains(ua, "smart-tv") || strings.Contains(ua, "hbbtv") || strings.Contains(ua, "netcast") || strings.Contains(ua, "vizio"): + u.DeviceType = DeviceTV + + case u.OS.Name == OSAndroid: + // android phones report as "mobile", android tablets should not but often do -- http://android-developers.blogspot.com/2010/12/android-browser-user-agent-issues.html + if strings.Contains(ua, "mobile") { + u.DeviceType = DevicePhone + return + } + + if strings.Contains(ua, "tablet") || strings.Contains(ua, "nexus 7") || strings.Contains(ua, "nexus 9") || strings.Contains(ua, "nexus 10") || strings.Contains(ua, "xoom") { + u.DeviceType = DeviceTablet + return + } + + u.DeviceType = DevicePhone // default to phone + + case u.OS.Platform == PlatformPlaystation || u.OS.Platform == PlatformXbox || u.OS.Platform == PlatformNintendo: + u.DeviceType = DeviceConsole + + case strings.Contains(ua, "glass") || strings.Contains(ua, "watch") || strings.Contains(ua, "sm-v"): + u.DeviceType = DeviceWearable + + // specifically above "mobile" string check as Kindle Fire tablets report as "mobile" + case u.Browser.Name == BrowserSilk || u.OS.Name == OSKindle && !strings.Contains(ua, "sd4930ur"): + u.DeviceType = DeviceTablet + + case strings.Contains(ua, "mobile") || strings.Contains(ua, "touch") || strings.Contains(ua, " mobi") || strings.Contains(ua, "webos"): //anything "mobile"/"touch" that didn't get captured as tablet, console or wearable is presumed a phone + u.DeviceType = DevicePhone + + case u.OS.Name == OSLinux: // linux goes last since it's in so many other device types (tvs, wearables, android-based stuff) + u.DeviceType = DeviceComputer + + default: + u.DeviceType = DeviceUnknown + } +} diff --git a/vendor/github.com/avct/uasurfer/system.go b/vendor/github.com/avct/uasurfer/system.go new file mode 100644 index 000000000..e823c9cc7 --- /dev/null +++ b/vendor/github.com/avct/uasurfer/system.go @@ -0,0 +1,336 @@ +package uasurfer + +import ( + "regexp" + "strconv" + "strings" +) + +var ( + amazonFireFingerprint = regexp.MustCompile("\\s(k[a-z]{3,5}|sd\\d{4}ur)\\s") //tablet or phone +) + +func (u *UserAgent) evalOS(ua string) bool { + + s := strings.IndexRune(ua, '(') + e := strings.IndexRune(ua, ')') + if s > e { + s = 0 + e = len(ua) + } + if e == -1 { + e = len(ua) + } + + agentPlatform := ua[s+1 : e] + specsEnd := strings.Index(agentPlatform, ";") + var specs string + if specsEnd != -1 { + specs = agentPlatform[:specsEnd] + } else { + specs = agentPlatform + } + + //strict OS & version identification + switch specs { + case "android": + u.evalLinux(ua, agentPlatform) + + case "bb10", "playbook": + u.OS.Platform = PlatformBlackberry + u.OS.Name = OSBlackberry + + case "x11", "linux": + u.evalLinux(ua, agentPlatform) + + case "ipad", "iphone", "ipod touch", "ipod": + u.evaliOS(specs, agentPlatform) + + case "macintosh": + u.evalMacintosh(ua) + + default: + switch { + // Blackberry + case strings.Contains(ua, "blackberry") || strings.Contains(ua, "playbook"): + u.OS.Platform = PlatformBlackberry + u.OS.Name = OSBlackberry + + // Windows Phone + case strings.Contains(agentPlatform, "windows phone "): + u.evalWindowsPhone(agentPlatform) + + // Windows, Xbox + case strings.Contains(ua, "windows ") || strings.Contains(ua, "microsoft-cryptoapi"): + u.evalWindows(ua) + + // Kindle + case strings.Contains(ua, "kindle/") || amazonFireFingerprint.MatchString(agentPlatform): + u.OS.Platform = PlatformLinux + u.OS.Name = OSKindle + + // Linux (broader attempt) + case strings.Contains(ua, "linux"): + u.evalLinux(ua, agentPlatform) + + // WebOS (non-linux flagged) + case strings.Contains(ua, "webos") || strings.Contains(ua, "hpwos"): + u.OS.Platform = PlatformLinux + u.OS.Name = OSWebOS + + // Nintendo + case strings.Contains(ua, "nintendo"): + u.OS.Platform = PlatformNintendo + u.OS.Name = OSNintendo + + // Playstation + case strings.Contains(ua, "playstation") || strings.Contains(ua, "vita") || strings.Contains(ua, "psp"): + u.OS.Platform = PlatformPlaystation + u.OS.Name = OSPlaystation + + // Android + case strings.Contains(ua, "android"): + u.evalLinux(ua, agentPlatform) + + // Apple CFNetwork + case strings.Contains(ua, "cfnetwork") && strings.Contains(ua, "darwin"): + u.evalMacintosh(ua) + + default: + u.OS.Platform = PlatformUnknown + u.OS.Name = OSUnknown + } + } + + return u.isBot() +} + +func (u *UserAgent) isBot() bool { + + if u.OS.Platform == PlatformBot || u.OS.Name == OSBot { + u.DeviceType = DeviceComputer + return true + } + + if u.Browser.Name >= BrowserBot && u.Browser.Name <= BrowserYahooBot { + u.OS.Platform = PlatformBot + u.OS.Name = OSBot + u.DeviceType = DeviceComputer + return true + } + + return false +} + +// evalLinux returns the `Platform`, `OSName` and Version of UAs with +// 'linux' listed as their platform. +func (u *UserAgent) evalLinux(ua string, agentPlatform string) { + + switch { + // Kindle Fire + case strings.Contains(ua, "kindle") || amazonFireFingerprint.MatchString(agentPlatform): + // get the version of Android if available, though we don't call this OSAndroid + u.OS.Platform = PlatformLinux + u.OS.Name = OSKindle + u.OS.Version.findVersionNumber(agentPlatform, "android ") + + // Android, Kindle Fire + case strings.Contains(ua, "android") || strings.Contains(ua, "googletv"): + // Android + u.OS.Platform = PlatformLinux + u.OS.Name = OSAndroid + u.OS.Version.findVersionNumber(agentPlatform, "android ") + + // ChromeOS + case strings.Contains(ua, "cros"): + u.OS.Platform = PlatformLinux + u.OS.Name = OSChromeOS + + // WebOS + case strings.Contains(ua, "webos") || strings.Contains(ua, "hpwos"): + u.OS.Platform = PlatformLinux + u.OS.Name = OSWebOS + + // Linux, "Linux-like" + case strings.Contains(ua, "x11") || strings.Contains(ua, "bsd") || strings.Contains(ua, "suse") || strings.Contains(ua, "debian") || strings.Contains(ua, "ubuntu"): + u.OS.Platform = PlatformLinux + u.OS.Name = OSLinux + + default: + u.OS.Platform = PlatformLinux + u.OS.Name = OSLinux + } +} + +// evaliOS returns the `Platform`, `OSName` and Version of UAs with +// 'ipad' or 'iphone' listed as their platform. +func (u *UserAgent) evaliOS(uaPlatform string, agentPlatform string) { + + switch uaPlatform { + // iPhone + case "iphone": + u.OS.Platform = PlatformiPhone + u.OS.Name = OSiOS + u.OS.getiOSVersion(agentPlatform) + + // iPad + case "ipad": + u.OS.Platform = PlatformiPad + u.OS.Name = OSiOS + u.OS.getiOSVersion(agentPlatform) + + // iPod + case "ipod touch", "ipod": + u.OS.Platform = PlatformiPod + u.OS.Name = OSiOS + u.OS.getiOSVersion(agentPlatform) + + default: + u.OS.Platform = PlatformiPad + u.OS.Name = OSUnknown + } +} + +func (u *UserAgent) evalWindowsPhone(agentPlatform string) { + u.OS.Platform = PlatformWindowsPhone + + if u.OS.Version.findVersionNumber(agentPlatform, "windows phone os ") || u.OS.Version.findVersionNumber(agentPlatform, "windows phone ") { + u.OS.Name = OSWindowsPhone + } else { + u.OS.Name = OSUnknown + } +} + +func (u *UserAgent) evalWindows(ua string) { + + switch { + //Xbox -- it reads just like Windows + case strings.Contains(ua, "xbox"): + u.OS.Platform = PlatformXbox + u.OS.Name = OSXbox + if !u.OS.Version.findVersionNumber(ua, "windows nt ") { + u.OS.Version.Major = 6 + u.OS.Version.Minor = 0 + u.OS.Version.Patch = 0 + } + + // No windows version + case !strings.Contains(ua, "windows "): + u.OS.Platform = PlatformWindows + u.OS.Name = OSUnknown + + case strings.Contains(ua, "windows nt ") && u.OS.Version.findVersionNumber(ua, "windows nt "): + u.OS.Platform = PlatformWindows + u.OS.Name = OSWindows + + case strings.Contains(ua, "windows xp"): + u.OS.Platform = PlatformWindows + u.OS.Name = OSWindows + u.OS.Version.Major = 5 + u.OS.Version.Minor = 1 + u.OS.Version.Patch = 0 + + default: + u.OS.Platform = PlatformWindows + u.OS.Name = OSUnknown + + } +} + +func (u *UserAgent) evalMacintosh(uaPlatformGroup string) { + u.OS.Platform = PlatformMac + if i := strings.Index(uaPlatformGroup, "os x 10"); i != -1 { + u.OS.Name = OSMacOSX + u.OS.Version.parse(uaPlatformGroup[i+5:]) + + return + } + u.OS.Name = OSUnknown +} + +func (v *Version) findVersionNumber(s string, m string) bool { + if ind := strings.Index(s, m); ind != -1 { + return v.parse(s[ind+len(m):]) + } + return false +} + +// getiOSVersion accepts the platform portion of a UA string and returns +// a Version. +func (o *OS) getiOSVersion(uaPlatformGroup string) { + if i := strings.Index(uaPlatformGroup, "cpu iphone os "); i != -1 { + o.Version.parse(uaPlatformGroup[i+14:]) + return + } + + if i := strings.Index(uaPlatformGroup, "cpu os "); i != -1 { + o.Version.parse(uaPlatformGroup[i+7:]) + return + } + + o.Version.parse(uaPlatformGroup) +} + +// strToInt simply accepts a string and returns a `int`, +// with '0' being default. +func strToInt(str string) int { + i, _ := strconv.Atoi(str) + return i +} + +// strToVer accepts a string and returns a Version, +// with {0, 0, 0} being default. +func (v *Version) parse(str string) bool { + if len(str) == 0 || str[0] < '0' || str[0] > '9' { + return false + } + for i := 0; i < 3; i++ { + empty := true + val := 0 + l := len(str) - 1 + + for k, c := range str { + if c >= '0' && c <= '9' { + if empty { + val = int(c) - 48 + empty = false + if k == l { + str = str[:0] + } + continue + } + + if val == 0 { + if c == '0' { + if k == l { + str = str[:0] + } + continue + } + str = str[k:] + break + } + + val = 10*val + int(c) - 48 + if k == l { + str = str[:0] + } + continue + } + str = str[k+1:] + break + } + + switch i { + case 0: + v.Major = val + + case 1: + v.Minor = val + + case 2: + v.Patch = val + } + } + return true +} diff --git a/vendor/github.com/avct/uasurfer/uasurfer.go b/vendor/github.com/avct/uasurfer/uasurfer.go new file mode 100644 index 000000000..15aac6d40 --- /dev/null +++ b/vendor/github.com/avct/uasurfer/uasurfer.go @@ -0,0 +1,227 @@ +// Package uasurfer provides fast and reliable abstraction +// of HTTP User-Agent strings. The philosophy is to identify +// technologies that holds >1% market share, and to avoid +// expending resources and accuracy on guessing at esoteric UA +// strings. +package uasurfer + +import "strings" + +//go:generate stringer -type=DeviceType,BrowserName,OSName,Platform -output=const_string.go + +// DeviceType (int) returns a constant. +type DeviceType int + +// A complete list of supported devices in the +// form of constants. +const ( + DeviceUnknown DeviceType = iota + DeviceComputer + DeviceTablet + DevicePhone + DeviceConsole + DeviceWearable + DeviceTV +) + +// BrowserName (int) returns a constant. +type BrowserName int + +// A complete list of supported web browsers in the +// form of constants. +const ( + BrowserUnknown BrowserName = iota + BrowserChrome + BrowserIE + BrowserSafari + BrowserFirefox + BrowserAndroid + BrowserOpera + BrowserBlackberry + BrowserUCBrowser + BrowserSilk + BrowserNokia + BrowserNetFront + BrowserQQ + BrowserMaxthon + BrowserSogouExplorer + BrowserSpotify + BrowserBot // Bot list begins here + BrowserAppleBot + BrowserBaiduBot + BrowserBingBot + BrowserDuckDuckGoBot + BrowserFacebookBot + BrowserGoogleBot + BrowserLinkedInBot + BrowserMsnBot + BrowserPingdomBot + BrowserTwitterBot + BrowserYandexBot + BrowserYahooBot // Bot list ends here +) + +// OSName (int) returns a constant. +type OSName int + +// A complete list of supported OSes in the +// form of constants. For handling particular versions +// of operating systems (e.g. Windows 2000), see +// the README.md file. +const ( + OSUnknown OSName = iota + OSWindowsPhone + OSWindows + OSMacOSX + OSiOS + OSAndroid + OSBlackberry + OSChromeOS + OSKindle + OSWebOS + OSLinux + OSPlaystation + OSXbox + OSNintendo + OSBot +) + +// Platform (int) returns a constant. +type Platform int + +// A complete list of supported platforms in the +// form of constants. Many OSes report their +// true platform, such as Android OS being Linux +// platform. +const ( + PlatformUnknown Platform = iota + PlatformWindows + PlatformMac + PlatformLinux + PlatformiPad + PlatformiPhone + PlatformiPod + PlatformBlackberry + PlatformWindowsPhone + PlatformPlaystation + PlatformXbox + PlatformNintendo + PlatformBot +) + +type Version struct { + Major int + Minor int + Patch int +} + +func (v Version) Less(c Version) bool { + if v.Major < c.Major { + return true + } + + if v.Major > c.Major { + return false + } + + if v.Minor < c.Minor { + return true + } + + if v.Minor > c.Minor { + return false + } + + return v.Patch < c.Patch +} + +type UserAgent struct { + Browser Browser + OS OS + DeviceType DeviceType +} + +type Browser struct { + Name BrowserName + Version Version +} + +type OS struct { + Platform Platform + Name OSName + Version Version +} + +// Reset resets the UserAgent to it's zero value +func (ua *UserAgent) Reset() { + ua.Browser = Browser{} + ua.OS = OS{} + ua.DeviceType = DeviceUnknown +} + +// Parse accepts a raw user agent (string) and returns the UserAgent. +func Parse(ua string) *UserAgent { + dest := new(UserAgent) + parse(ua, dest) + return dest +} + +// ParseUserAgent is the same as Parse, but populates the supplied UserAgent. +// It is the caller's responsibility to call Reset() on the UserAgent before +// passing it to this function. +func ParseUserAgent(ua string, dest *UserAgent) { + parse(ua, dest) +} + +func parse(ua string, dest *UserAgent) { + ua = normalise(ua) + switch { + case len(ua) == 0: + dest.OS.Platform = PlatformUnknown + dest.OS.Name = OSUnknown + dest.Browser.Name = BrowserUnknown + dest.DeviceType = DeviceUnknown + + // stop on on first case returning true + case dest.evalOS(ua): + case dest.evalBrowserName(ua): + default: + dest.evalBrowserVersion(ua) + dest.evalDevice(ua) + } +} + +// normalise normalises the user supplied agent string so that +// we can more easily parse it. +func normalise(ua string) string { + if len(ua) <= 1024 { + var buf [1024]byte + ascii := copyLower(buf[:len(ua)], ua) + if !ascii { + // Fall back for non ascii characters + return strings.ToLower(ua) + } + return string(buf[:len(ua)]) + } + // Fallback for unusually long strings + return strings.ToLower(ua) +} + +// copyLower copies a lowercase version of s to b. It assumes s contains only single byte characters +// and will panic if b is nil or is not long enough to contain all the bytes from s. +// It returns early with false if any characters were non ascii. +func copyLower(b []byte, s string) bool { + for j := 0; j < len(s); j++ { + c := s[j] + if c > 127 { + return false + } + + if 'A' <= c && c <= 'Z' { + c += 'a' - 'A' + } + + b[j] = c + } + return true +} diff --git a/vendor/github.com/avct/uasurfer/uasurfer_test.go b/vendor/github.com/avct/uasurfer/uasurfer_test.go new file mode 100644 index 000000000..7a4688bb2 --- /dev/null +++ b/vendor/github.com/avct/uasurfer/uasurfer_test.go @@ -0,0 +1,1074 @@ +package uasurfer + +import "testing" + +var testUAVars = []struct { + UA string + UserAgent +}{ + // Empty + {"", + UserAgent{}}, + + // Single char + {"a", + UserAgent{}}, + + // Some random string + {"some random string", + UserAgent{}}, + + // Potentially malformed ua + {")(", + UserAgent{}}, + + // iPhone + {"Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X) AppleWebKit/546.10 (KHTML, like Gecko) Version/6.0 Mobile/7E18WD Safari/8536.25", + UserAgent{ + Browser{BrowserSafari, Version{6, 0, 0}}, OS{PlatformiPhone, OSiOS, Version{7, 0, 0}}, DevicePhone}}, + + {"Mozilla/5.0 (iPhone; CPU iPhone OS 8_0_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12A405 Safari/600.1.4", + UserAgent{ + Browser{BrowserSafari, Version{8, 0, 0}}, OS{PlatformiPhone, OSiOS, Version{8, 0, 2}}, DevicePhone}}, + + // iPad + {"Mozilla/5.0(iPad; U; CPU iPhone OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314 Safari/531.21.10", + UserAgent{ + Browser{BrowserSafari, Version{4, 0, 4}}, OS{PlatformiPad, OSiOS, Version{3, 2, 0}}, DeviceTablet}}, + + {"Mozilla/5.0 (iPad; CPU OS 9_0 like Mac OS X) AppleWebKit/601.1.17 (KHTML, like Gecko) Version/8.0 Mobile/13A175 Safari/600.1.4", + UserAgent{ + Browser{BrowserSafari, Version{8, 0, 0}}, OS{PlatformiPad, OSiOS, Version{9, 0, 0}}, DeviceTablet}}, + + {"Mozilla/5.0 (iPhone; CPU iPhone OS 10_0 like Mac OS X) AppleWebKit/602.1.32 (KHTML, like Gecko) Version/10.0 Mobile/14A5261v Safari/602.1", + UserAgent{ + Browser{BrowserSafari, Version{10, 0, 0}}, OS{PlatformiPhone, OSiOS, Version{10, 0, 0}}, DevicePhone}}, + + // Chrome + {"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36", + UserAgent{ + Browser{BrowserChrome, Version{43, 0, 2357}}, OS{PlatformMac, OSMacOSX, Version{10, 10, 4}}, DeviceComputer}}, + + {"Mozilla/5.0 (iPhone; U; CPU iPhone OS 5_1_1 like Mac OS X; en) AppleWebKit/534.46.0 (KHTML, like Gecko) CriOS/19.0.1084.60 Mobile/9B206 Safari/534.48.3", + UserAgent{ + Browser{BrowserChrome, Version{19, 0, 1084}}, OS{PlatformiPhone, OSiOS, Version{5, 1, 1}}, DevicePhone}}, + + {"Mozilla/5.0 (Linux; Android 6.0; Nexus 5X Build/MDB08L) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.76 Mobile Safari/537.36", + UserAgent{ + Browser{BrowserChrome, Version{46, 0, 2490}}, OS{PlatformLinux, OSAndroid, Version{6, 0, 0}}, DevicePhone}}, + + // Chromium (Chrome) + {"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.19 (KHTML, like Gecko) Ubuntu/11.10 Chromium/18.0.1025.142 Chrome/18.0.1025.142 Safari/535.19", + UserAgent{ + Browser{BrowserChrome, Version{18, 0, 1025}}, OS{PlatformLinux, OSLinux, Version{0, 0, 0}}, DeviceComputer}}, + + {"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36", + UserAgent{ + Browser{BrowserChrome, Version{45, 0, 2454}}, OS{PlatformMac, OSMacOSX, Version{10, 11, 0}}, DeviceComputer}}, + + //TODO: refactor "getVersion()" to handle this device/chrome version douchebaggery + // {"Mozilla/5.0 (Linux; Android 4.4.2; en-gb; SAMSUNG SM-G800F Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Version/1.6 Chrome/28.0.1500.94 Mobile Safari/537.36", + // UserAgent{ + // Browser{BrowserChrome, Version{28,0,1500}, OS{PlatformLinux, OSAndroid, Version{4,4,2}}, DevicePhone}}, + + // Safari + {"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/600.7.12 (KHTML, like Gecko) Version/8.0.7 Safari/600.7.12", + UserAgent{ + Browser{BrowserSafari, Version{8, 0, 7}}, OS{PlatformMac, OSMacOSX, Version{10, 10, 4}}, DeviceComputer}}, + + {"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_5; en-us) AppleWebKit/525.26.2 (KHTML, like Gecko) Version/3.2 Safari/525.26.12", + UserAgent{ + Browser{BrowserSafari, Version{3, 2, 0}}, OS{PlatformMac, OSMacOSX, Version{10, 5, 5}}, DeviceComputer}}, + + {"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12) AppleWebKit/602.1.32 (KHTML, like Gecko) Version/10.0 Safari/602.1.32", // macOS Sierra dev beta + UserAgent{ + Browser{BrowserSafari, Version{10, 0, 0}}, OS{PlatformMac, OSMacOSX, Version{10, 12, 0}}, DeviceComputer}}, + + // Firefox + {"Mozilla/5.0 (iPhone; CPU iPhone OS 8_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) FxiOS/1.0 Mobile/12F69 Safari/600.1.4", + UserAgent{ + Browser{BrowserFirefox, Version{1, 0, 0}}, OS{PlatformiPhone, OSiOS, Version{8, 3, 0}}, DevicePhone}}, + + {"Mozilla/5.0 (Android 4.4; Tablet; rv:41.0) Gecko/41.0 Firefox/41.0", + UserAgent{ + Browser{BrowserFirefox, Version{41, 0, 0}}, OS{PlatformLinux, OSAndroid, Version{4, 4, 0}}, DeviceTablet}}, + + {"Mozilla/5.0 (Android; Mobile; rv:40.0) Gecko/40.0 Firefox/40.0", + UserAgent{ + Browser{BrowserFirefox, Version{40, 0, 0}}, OS{PlatformLinux, OSAndroid, Version{0, 0, 0}}, DevicePhone}}, + + {"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:38.0) Gecko/20100101 Firefox/38.0", + UserAgent{ + Browser{BrowserFirefox, Version{38, 0, 0}}, OS{PlatformLinux, OSLinux, Version{0, 0, 0}}, DeviceComputer}}, + + // Silk + {"Mozilla/5.0 (Linux; U; Android 4.4.3; de-de; KFTHWI Build/KTU84M) AppleWebKit/537.36 (KHTML, like Gecko) Silk/3.47 like Chrome/37.0.2026.117 Safari/537.36", + UserAgent{ + Browser{BrowserSilk, Version{3, 47, 0}}, OS{PlatformLinux, OSKindle, Version{4, 4, 3}}, DeviceTablet}}, + + {"Mozilla/5.0 (Linux; U; en-us; KFJWI Build/IMM76D) AppleWebKit/535.19 (KHTML like Gecko) Silk/2.4 Safari/535.19 Silk-Acceleratedtrue", + UserAgent{ + Browser{BrowserSilk, Version{2, 4, 0}}, OS{PlatformLinux, OSKindle, Version{0, 0, 0}}, DeviceTablet}}, + + // Opera + {"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36 OPR/18.0.1284.68", + UserAgent{ + Browser{BrowserOpera, Version{18, 0, 1284}}, OS{PlatformWindows, OSWindows, Version{6, 1, 0}}, DeviceComputer}}, + + {"Mozilla/5.0 (iPhone; CPU iPhone OS 8_4 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) OPiOS/10.2.0.93022 Mobile/12H143 Safari/9537.53", + UserAgent{ + Browser{BrowserOpera, Version{10, 2, 0}}, OS{PlatformiPhone, OSiOS, Version{8, 4, 0}}, DevicePhone}}, + + // Internet Explorer -- https://msdn.microsoft.com/en-us/library/hh869301(v=vs.85).aspx + {"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.123", + UserAgent{ + Browser{BrowserIE, Version{12, 123, 0}}, OS{PlatformWindows, OSWindows, Version{10, 0, 0}}, DeviceComputer}}, + + {"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)", + UserAgent{ + Browser{BrowserIE, Version{10, 0, 0}}, OS{PlatformWindows, OSWindows, Version{6, 2, 0}}, DeviceComputer}}, + + {"Mozilla/5.0 (Windows NT 6.3; Trident/7.0; .NET4.0E; .NET4.0C; rv:11.0) like Gecko", + UserAgent{ + Browser{BrowserIE, Version{11, 0, 0}}, OS{PlatformWindows, OSWindows, Version{6, 3, 0}}, DeviceComputer}}, + + {"Mozilla/5.0 (Windows Phone 10.0; Android 4.2.1; DEVICE INFO) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Mobile Safari/537.36 Edge/12.123", + UserAgent{ + Browser{BrowserIE, Version{12, 123, 0}}, OS{PlatformWindowsPhone, OSWindowsPhone, Version{10, 0, 0}}, DevicePhone}}, + + {"Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 520) like iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537", + UserAgent{ + Browser{BrowserIE, Version{11, 0, 0}}, OS{PlatformWindowsPhone, OSWindowsPhone, Version{8, 1, 0}}, DevicePhone}}, + + {"Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0; SV1; .NET CLR 1.1.4322; .NET CLR 1.0.3705; .NET CLR 2.0.50727)", + UserAgent{ + Browser{BrowserIE, Version{5, 0, 1}}, OS{PlatformWindows, OSWindows, Version{5, 0, 0}}, DeviceComputer}}, + + {"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/4.0; GTB6.4; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; OfficeLiveConnector.1.3; OfficeLivePatch.0.0; .NET CLR 1.1.4322)", + UserAgent{ + Browser{BrowserIE, Version{7, 0, 0}}, OS{PlatformWindows, OSWindows, Version{6, 1, 0}}, DeviceComputer}}, + + {"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; ARM; Trident/6.0; Touch)", //Windows Surface RT tablet + UserAgent{ + Browser{BrowserIE, Version{10, 0, 0}}, OS{PlatformWindows, OSWindows, Version{6, 2, 0}}, DeviceTablet}}, + + // UC Browser + {"Mozilla/5.0 (Linux; U; Android 2.3.4; en-US; MT11i Build/4.0.2.A.0.62) AppleWebKit/534.31 (KHTML, like Gecko) UCBrowser/9.0.1.275 U3/0.8.0 Mobile Safari/534.31", + UserAgent{ + Browser{BrowserUCBrowser, Version{9, 0, 1}}, OS{PlatformLinux, OSAndroid, Version{2, 3, 4}}, DevicePhone}}, + + {"Mozilla/5.0 (Linux; U; Android 4.0.4; en-US; Micromax P255 Build/IMM76D) AppleWebKit/534.31 (KHTML, like Gecko) UCBrowser/9.2.0.308 U3/0.8.0 Mobile Safari/534.31", + UserAgent{ + Browser{BrowserUCBrowser, Version{9, 2, 0}}, OS{PlatformLinux, OSAndroid, Version{4, 0, 4}}, DevicePhone}}, + + {"UCWEB/2.0 (Java; U; MIDP-2.0; en-US; MicromaxQ5) U2/1.0.0 UCBrowser/9.4.0.342 U2/1.0.0 Mobile", + UserAgent{ + Browser{BrowserUCBrowser, Version{9, 4, 0}}, OS{PlatformUnknown, OSUnknown, Version{0, 0, 0}}, DevicePhone}}, + + // Nokia Browser + // {"Mozilla/5.0 (Series40; Nokia501/14.0.4/java_runtime_version=Nokia_Asha_1_2; Profile/MIDP-2.1 Configuration/CLDC-1.1) Gecko/20100401 S40OviBrowser/4.0.0.0.45", + // UserAgent{ + // Browser{BrowserUnknown, Version{4,0,0}}, OS{PlatformUnknown, OSUnknown, Version{0,0,0}}, DevicePhone}}, + + // {"Mozilla/5.0 (Symbian/3; Series60/5.3 NokiaN8-00/111.040.1511; Profile/MIDP-2.1 Configuration/CLDC-1.1 ) AppleWebKit/535.1 (KHTML, like Gecko) NokiaBrowser/8.3.1.4 Mobile Safari/535.1", + // UserAgent{ + // Browser{BrowserUnknown, Version{8,0,0}}, OS{PlatformUnknown, OSUnknown, Version{0,0,0}}, DevicePhone}}, + + // {"NokiaN97/21.1.107 (SymbianOS/9.4; Series60/5.0 Mozilla/5.0; Profile/MIDP-2.1 Configuration/CLDC-1.1) AppleWebkit/525 (KHTML, like Gecko) BrowserNG/7.1.4", + // BrowserUnknown, Version{7,0,0}}, OS{PlatformUnknown, OSUnknown, Version{0,0,0}}, DevicePhone}}, + + // ChromeOS + {"Mozilla/5.0 (X11; U; CrOS i686 9.10.0; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.0.253.0 Safari/532.5", + UserAgent{ + Browser{BrowserChrome, Version{4, 0, 253}}, OS{PlatformLinux, OSChromeOS, Version{0, 0, 0}}, DeviceComputer}}, + + // iPod, iPod Touch + {"mozilla/5.0 (ipod touch; cpu iphone os 9_3_3 like mac os x) applewebkit/601.1.46 (khtml, like gecko) version/9.0 mobile/13g34 safari/601.1", + UserAgent{ + Browser{BrowserSafari, Version{9, 0, 0}}, OS{PlatformiPod, OSiOS, Version{9, 3, 3}}, DeviceTablet}}, + + {"mozilla/5.0 (ipod; cpu iphone os 6_1_6 like mac os x) applewebkit/536.26 (khtml, like gecko) version/6.0 mobile/10b500 safari/8536.25", + UserAgent{ + Browser{BrowserSafari, Version{6, 0, 0}}, OS{PlatformiPod, OSiOS, Version{6, 1, 6}}, DeviceTablet}}, + + // WebOS + {"Mozilla/5.0 (hp-tablet; Linux; hpwOS/3.0.0; U; de-DE) AppleWebKit/534.6 (KHTML, like Gecko) wOSBrowser/233.70 Safari/534.6 TouchPad/1.0", + UserAgent{ + Browser{BrowserUnknown, Version{0, 0, 0}}, OS{PlatformLinux, OSWebOS, Version{0, 0, 0}}, DeviceTablet}}, + + {"Mozilla/5.0 (webOS/1.4.1.1; U; en-US) AppleWebKit/532.2 (KHTML, like Gecko) Version/1.0 Safari/532.2 Pre/1.0", + UserAgent{ + Browser{BrowserUnknown, Version{1, 0, 0}}, OS{PlatformLinux, OSWebOS, Version{0, 0, 0}}, DevicePhone}}, + + // Android WebView (Android <= 4.3) + {"Mozilla/5.0 (Linux; U; Android 2.2; en-us; DROID2 GLOBAL Build/S273) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1", + UserAgent{ + Browser{BrowserAndroid, Version{4, 0, 0}}, OS{PlatformLinux, OSAndroid, Version{2, 2, 0}}, DevicePhone}}, + + {"Mozilla/5.0 (Linux; U; Android 4.0.3; de-ch; HTC Sensation Build/IML74K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari53/4.30", + UserAgent{ + Browser{BrowserAndroid, Version{4, 0, 0}}, OS{PlatformLinux, OSAndroid, Version{4, 0, 3}}, DevicePhone}}, + + // BlackBerry + {"Mozilla/5.0 (PlayBook; U; RIM Tablet OS 2.1.0; en-US) AppleWebKit/536.2+ (KHTML, like Gecko) Version/7.2.1.0 Safari/536.2+", + UserAgent{ + Browser{BrowserBlackberry, Version{7, 2, 1}}, OS{PlatformBlackberry, OSBlackberry, Version{0, 0, 0}}, DeviceTablet}}, + + {"Mozilla/5.0 (BB10; Kbd) AppleWebKit/537.35+ (KHTML, like Gecko) Version/10.2.1.1925 Mobile Safari/537.35+", + UserAgent{ + Browser{BrowserBlackberry, Version{10, 2, 1}}, OS{PlatformBlackberry, OSBlackberry, Version{0, 0, 0}}, DevicePhone}}, + + {"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0) BlackBerry8703e/4.1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/104", + UserAgent{ + Browser{BrowserBlackberry, Version{0, 0, 0}}, OS{PlatformBlackberry, OSBlackberry, Version{0, 0, 0}}, DevicePhone}}, + + // Windows Phone + {"Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 625; ANZ941)", + UserAgent{ + Browser{BrowserIE, Version{10, 0, 0}}, OS{PlatformWindowsPhone, OSWindowsPhone, Version{8, 0, 0}}, DevicePhone}}, + + {"Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; NOKIA; Lumia 900)", + UserAgent{ + Browser{BrowserIE, Version{9, 0, 0}}, OS{PlatformWindowsPhone, OSWindowsPhone, Version{7, 5, 0}}, DevicePhone}}, + + // Kindle eReader + {"Mozilla/5.0 (Linux; U; en-US) AppleWebKit/528.5+ (KHTML, like Gecko, Safari/528.5+) Version/4.0 Kindle/3.0 (screen 600×800; rotate)", + UserAgent{ + Browser{BrowserUnknown, Version{4, 0, 0}}, OS{PlatformLinux, OSKindle, Version{0, 0, 0}}, DeviceTablet}}, + + {"Mozilla/5.0 (X11; U; Linux armv7l like Android; en-us) AppleWebKit/531.2+ (KHTML, like Gecko) Version/5.0 Safari/533.2+ Kindle/3.0+", + UserAgent{ + Browser{BrowserUnknown, Version{5, 0, 0}}, OS{PlatformLinux, OSKindle, Version{0, 0, 0}}, DeviceTablet}}, + + // Amazon Fire + {"Mozilla/5.0 (Linux; U; Android 4.4.3; de-de; KFTHWI Build/KTU84M) AppleWebKit/537.36 (KHTML, like Gecko) Silk/3.67 like Chrome/39.0.2171.93 Safari/537.36", + UserAgent{ + Browser{BrowserSilk, Version{3, 67, 0}}, OS{PlatformLinux, OSKindle, Version{4, 4, 3}}, DeviceTablet}}, // Fire tablet + + {"Mozilla/5.0 (Linux; U; Android 4.2.2; en­us; KFTHWI Build/JDQ39) AppleWebKit/537.36 (KHTML, like Gecko) Silk/3.22 like Chrome/34.0.1847.137 Mobile Safari/537.36", + UserAgent{ + Browser{BrowserSilk, Version{3, 22, 0}}, OS{PlatformLinux, OSKindle, Version{4, 2, 2}}, DeviceTablet}}, // Fire tablet, but with "Mobile" + + {"Mozilla/5.0 (Linux; Android 4.4.4; SD4930UR Build/KTU84P) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/34.0.0.0 Mobile Safari/537.36 [FB_IAB/FB4A;FBAV/35.0.0.48.273;]", + UserAgent{ + Browser{BrowserChrome, Version{34, 0, 0}}, OS{PlatformLinux, OSKindle, Version{4, 4, 4}}, DevicePhone}}, // Facebook app on Fire Phone + + {"mozilla/5.0 (linux; android 4.4.3; kfthwi build/ktu84m) applewebkit/537.36 (khtml, like gecko) version/4.0 chrome/34.0.0.0 safari/537.36 [pinterest/android]", + UserAgent{ + Browser{BrowserChrome, Version{34, 0, 0}}, OS{PlatformLinux, OSKindle, Version{4, 4, 3}}, DeviceTablet}}, // Fire tablet running pinterest + + // extra logic to identify phone when using silk has not been added + // {"Mozilla/5.0 (Linux; Android 4.4.4; SD4930UR Build/KTU84P) AppleWebKit/537.36 (KHTML, like Gecko) Silk/3.67 like Chrome/39.0.2171.93 Mobile Safari/537.36", + // UserAgent{ + // Browser{BrowserSilk, Version{3,0,0}}, OS{PlatformLinux, OSKindle, Version{4,0,0}}, DevicePhone}}, // Silk on Fire Phone + + // Nintendo + {"Opera/9.30 (Nintendo Wii; U; ; 2047-7; fr)", + UserAgent{ + Browser{BrowserOpera, Version{9, 30, 0}}, OS{PlatformNintendo, OSNintendo, Version{0, 0, 0}}, DeviceConsole}}, + + {"Mozilla/5.0 (Nintendo WiiU) AppleWebKit/534.52 (KHTML, like Gecko) NX/2.1.0.8.21 NintendoBrowser/1.0.0.7494.US", + UserAgent{ + Browser{BrowserUnknown, Version{0, 0, 0}}, OS{PlatformNintendo, OSNintendo, Version{0, 0, 0}}, DeviceConsole}}, + + // Xbox + {"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; Xbox)", //Xbox 360 + UserAgent{ + Browser{BrowserIE, Version{9, 0, 0}}, OS{PlatformXbox, OSXbox, Version{6, 1, 0}}, DeviceConsole}}, + + // Playstation + {"Mozilla/5.0 (PlayStation 4 4.50) AppleWebKit/601.2 (KHTML, like Gecko)", + UserAgent{ + Browser{BrowserUnknown, Version{0, 0, 0}}, OS{PlatformPlaystation, OSPlaystation, Version{0, 0, 0}}, DeviceConsole}}, + + {"Mozilla/5.0 (Playstation Vita 1.61) AppleWebKit/531.22.8 (KHTML, like Gecko) Silk/3.2", + UserAgent{ + Browser{BrowserSilk, Version{3, 2, 0}}, OS{PlatformPlaystation, OSPlaystation, Version{0, 0, 0}}, DeviceConsole}}, + + // Smart TVs and TV dongles + {"Mozilla/5.0 (CrKey armv7l 1.4.15250) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.0 Safari/537.36", // Chromecast + UserAgent{ + Browser{BrowserChrome, Version{31, 0, 1650}}, OS{PlatformUnknown, OSUnknown, Version{0, 0, 0}}, DeviceTV}}, + + {"Mozilla/5.0 (Linux; GoogleTV 3.2; VAP430 Build/MASTER) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.77 Safari/534.24", // Google TV + UserAgent{ + Browser{BrowserChrome, Version{11, 0, 696}}, OS{PlatformLinux, OSAndroid, Version{0, 0, 0}}, DeviceTV}}, + + {"Mozilla/5.0 (Linux; Android 5.0; ADT-1 Build/LPX13D) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.89 Mobile Safari/537.36", // Android TV + UserAgent{ + Browser{BrowserChrome, Version{40, 0, 2214}}, OS{PlatformLinux, OSAndroid, Version{5, 0, 0}}, DeviceTV}}, + + {"Mozilla/5.0 (Linux; Android 4.2.2; AFTB Build/JDQ39) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.173 Mobile Safari/537.22", // Amazon Fire + UserAgent{ + Browser{BrowserChrome, Version{25, 0, 1364}}, OS{PlatformLinux, OSAndroid, Version{4, 2, 2}}, DeviceTV}}, + + {"Mozilla/5.0 (Unknown; Linux armv7l) AppleWebKit/537.1+ (KHTML, like Gecko) Safari/537.1+ LG Browser/6.00.00(+mouse+3D+SCREEN+TUNER; LGE; GLOBAL-PLAT5; 03.07.01; 0x00000001;); LG NetCast.TV-2013/03.17.01 (LG, GLOBAL-PLAT4, wired)", // LG TV + UserAgent{ + Browser{BrowserUnknown, Version{0, 0, 0}}, OS{PlatformLinux, OSLinux, Version{0, 0, 0}}, DeviceTV}}, + + {"Mozilla/5.0 (X11; FreeBSD; U; Viera; de-DE) AppleWebKit/537.11 (KHTML, like Gecko) Viera/3.10.0 Chrome/23.0.1271.97 Safari/537.11", // Panasonic Viera + UserAgent{ + Browser{BrowserChrome, Version{23, 0, 1271}}, OS{PlatformLinux, OSLinux, Version{0, 0, 0}}, DeviceTV}}, + + // TODO: not catching "browser/" and reporting as safari -- ua string not being fully checked? + // {"Mozilla/5.0 (DTV) AppleWebKit/531.2+ (KHTML, like Gecko) Espial/6.1.5 AQUOSBrowser/2.0 (US01DTV;V;0001;0001)", // Sharp Aquos + // BrowserUnknown, Version{0,0,0}}, OS{PlatformUnknown, OSUnknown, Version{0,0,0}}, DeviceTV}}, + + {"Roku/DVP-5.2 (025.02E03197A)", // Roku + UserAgent{ + Browser{BrowserUnknown, Version{0, 0, 0}}, OS{PlatformUnknown, OSUnknown, Version{0, 0, 0}}, DeviceTV}}, + + {"mozilla/5.0 (smart-tv; linux; tizen 2.3) applewebkit/538.1 (khtml, like gecko) samsungbrowser/1.0 tv safari/538.1", // Samsung SmartTV + UserAgent{ + Browser{BrowserUnknown, Version{0, 0, 0}}, OS{PlatformLinux, OSLinux, Version{0, 0, 0}}, DeviceTV}}, + + {"mozilla/5.0 (linux; u) applewebkit/537.36 (khtml, like gecko) version/4.0 mobile safari/537.36 smarttv/6.0 (netcast)", + UserAgent{ + Browser{BrowserUnknown, Version{4, 0, 0}}, OS{PlatformLinux, OSLinux, Version{0, 0, 0}}, DeviceTV}}, + + // Google search app (GSA) for iOS -- it's Safari in disguise as of v6 + {"Mozilla/5.0 (iPad; CPU OS 8_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) GSA/6.0.51363 Mobile/12F69 Safari/600.1.4", + UserAgent{ + Browser{BrowserSafari, Version{8, 3, 0}}, OS{PlatformiPad, OSiOS, Version{8, 3, 0}}, DeviceTablet}}, + + // Spotify (applicable for advertising applications) + {"Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Spotify/1.0.9.133 Safari/537.36", + UserAgent{ + Browser{BrowserSpotify, Version{1, 0, 9}}, OS{PlatformWindows, OSWindows, Version{5, 1, 0}}, DeviceComputer}}, + + {"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Spotify/1.0.9.133 Safari/537.36", + UserAgent{ + Browser{BrowserSpotify, Version{1, 0, 9}}, OS{PlatformMac, OSMacOSX, Version{10, 10, 2}}, DeviceComputer}}, + + // OCSP fetchers + {"Microsoft-CryptoAPI/10.0", + UserAgent{ + Browser{BrowserUnknown, Version{0, 0, 0}}, OS{PlatformWindows, OSUnknown, Version{0, 0, 0}}, DeviceComputer}}, + {"trustd (unknown version) CFNetwork/811.7.2 Darwin/16.7.0 (x86_64)", + UserAgent{ + Browser{BrowserUnknown, Version{0, 0, 0}}, OS{PlatformMac, OSUnknown, Version{0, 0, 0}}, DeviceComputer}}, + {"ocspd (unknown version) CFNetwork/520.5.3 Darwin/11.4.2 (x86_64)(MacBookAir5%2C2)", + UserAgent{ + Browser{BrowserUnknown, Version{0, 0, 0}}, OS{PlatformMac, OSUnknown, Version{0, 0, 0}}, DeviceComputer}}, + // Bots + {"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/600.2.5 (KHTML, like Gecko) Version/8.0.2 Safari/600.2.5 (Applebot/0.1; +http://www.apple.com/go/applebot)", + UserAgent{ + Browser{BrowserAppleBot, Version{0, 0, 0}}, OS{PlatformBot, OSBot, Version{10, 10, 1}}, DeviceComputer}}, + + {"Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)", + UserAgent{ + Browser{BrowserBaiduBot, Version{0, 0, 0}}, OS{PlatformBot, OSBot, Version{0, 0, 0}}, DeviceComputer}}, + + {"Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)", + UserAgent{ + Browser{BrowserBingBot, Version{0, 0, 0}}, OS{PlatformBot, OSBot, Version{0, 0, 0}}, DeviceComputer}}, + + {"DuckDuckBot/1.0; (+http://duckduckgo.com/duckduckbot.html)", + UserAgent{ + Browser{BrowserDuckDuckGoBot, Version{0, 0, 0}}, OS{PlatformBot, OSBot, Version{0, 0, 0}}, DeviceComputer}}, + + {"facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)", + UserAgent{ + Browser{BrowserFacebookBot, Version{0, 0, 0}}, OS{PlatformBot, OSBot, Version{0, 0, 0}}, DeviceComputer}}, + + {"Facebot/1.0", + UserAgent{ + Browser{BrowserFacebookBot, Version{0, 0, 0}}, OS{PlatformBot, OSBot, Version{0, 0, 0}}, DeviceComputer}}, + + {"Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)", + UserAgent{ + Browser{BrowserGoogleBot, Version{0, 0, 0}}, OS{PlatformBot, OSBot, Version{0, 0, 0}}, DeviceComputer}}, + + {"LinkedInBot/1.0 (compatible; Mozilla/5.0; Jakarta Commons-HttpClient/3.1 +http://www.linkedin.com)", + UserAgent{ + Browser{BrowserLinkedInBot, Version{0, 0, 0}}, OS{PlatformBot, OSBot, Version{0, 0, 0}}, DeviceComputer}}, + + {"msnbot/2.0b (+http://search.msn.com/msnbot.htm)", + UserAgent{ + Browser{BrowserMsnBot, Version{0, 0, 0}}, OS{PlatformBot, OSBot, Version{0, 0, 0}}, DeviceComputer}}, + + {"Pingdom.com_bot_version_1.4_(http://www.pingdom.com/)", + UserAgent{ + Browser{BrowserPingdomBot, Version{0, 0, 0}}, OS{PlatformBot, OSBot, Version{0, 0, 0}}, DeviceComputer}}, + + {"Twitterbot/1.0", + UserAgent{ + Browser{BrowserTwitterBot, Version{0, 0, 0}}, OS{PlatformBot, OSBot, Version{0, 0, 0}}, DeviceComputer}}, + + {"Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)", + UserAgent{ + Browser{BrowserYandexBot, Version{0, 0, 0}}, OS{PlatformBot, OSBot, Version{0, 0, 0}}, DeviceComputer}}, + + {"Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)", + UserAgent{ + Browser{BrowserYahooBot, Version{0, 0, 0}}, OS{PlatformBot, OSBot, Version{0, 0, 0}}, DeviceComputer}}, + + // {"Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)", + // BrowserBot, Version{0,0,0}}, OS{PlatformBot, OSBot, Version{6,0,0}}, DeviceComputer}}, + + {"mozilla/5.0 (unknown; linux x86_64) applewebkit/538.1 (khtml, like gecko) phantomjs/2.1.1 safari/538.1", + UserAgent{ + Browser{BrowserBot, Version{0, 0, 0}}, OS{PlatformBot, OSBot, Version{0, 0, 0}}, DeviceComputer}}, + + // Unknown or partially handled + {"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.1b3pre) Gecko/20090223 SeaMonkey/2.0a3", //Seamonkey (~FF) + UserAgent{ + Browser{BrowserFirefox, Version{0, 0, 0}}, OS{PlatformMac, OSMacOSX, Version{10, 4, 0}}, DeviceComputer}}, + + {"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en; rv:1.9.0.8pre) Gecko/2009022800 Camino/2.0b3pre", //Camino (~FF) + UserAgent{ + Browser{BrowserUnknown, Version{0, 0, 0}}, OS{PlatformMac, OSMacOSX, Version{10, 5, 0}}, DeviceComputer}}, + + {"Mozilla/5.0 (Mobile; rv:26.0) Gecko/26.0 Firefox/26.0", //firefox OS + UserAgent{ + Browser{BrowserFirefox, Version{26, 0, 0}}, OS{PlatformUnknown, OSUnknown, Version{0, 0, 0}}, DevicePhone}}, + + {"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.45 Safari/535.19", //chrome for android having requested desktop site + UserAgent{ + Browser{BrowserChrome, Version{18, 0, 1025}}, OS{PlatformLinux, OSLinux, Version{0, 0, 0}}, DeviceComputer}}, + + {"Opera/9.80 (S60; SymbOS; Opera Mobi/352; U; de) Presto/2.4.15 Version/10.00", + UserAgent{ + Browser{BrowserOpera, Version{10, 0, 0}}, OS{PlatformUnknown, OSUnknown, Version{0, 0, 0}}, DevicePhone}}, + + // BrowserQQ + // {"Mozilla/5.0 (Windows NT 6.2; WOW64; Trident/7.0; Touch; .NET4.0E; .NET4.0C; .NET CLR 3.5.30729; .NET CLR 2.0.50727; .NET CLR 3.0.30729; InfoPath.3; Tablet PC 2.0; QQBrowser/7.6.21433.400; rv:11.0) like Gecko", + // UserAgent{ + // Browser{BrowserQQ, Version{7,0,0}}, OS{PlatformWindows, OSWindows, Version{8,0,0}}, DeviceTablet}}, + + // {"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.124 Safari/537.36 QQBrowser/9.0.2191.400", + // UserAgent{ + // Browser{BrowserQQ, Version{9,0,0}}, OS{PlatformWindows, OSWindows, Version{7,0,0}}, DeviceComputer}}, + + // ANDROID TESTS + + {"Mozilla/5.0 (Linux; U; Android 1.0; en-us; dream) AppleWebKit/525.10+ (KHTML,like Gecko) Version/3.0.4 Mobile Safari/523.12.2", + UserAgent{ + Browser{BrowserAndroid, Version{3, 0, 4}}, OS{PlatformLinux, OSAndroid, Version{1, 0, 0}}, DevicePhone}}, + + {"Mozilla/5.0 (Linux; U; Android 1.0; en-us; generic) AppleWebKit/525.10 (KHTML, like Gecko) Version/3.0.4 Mobile Safari/523.12.2", + UserAgent{ + Browser{BrowserAndroid, Version{3, 0, 4}}, OS{PlatformLinux, OSAndroid, Version{1, 0, 0}}, DevicePhone}}, + + {"Mozilla/5.0 (Linux; U; Android 1.0.3; de-de; A80KSC Build/ECLAIR) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17", + UserAgent{ + Browser{BrowserAndroid, Version{4, 0, 0}}, OS{PlatformLinux, OSAndroid, Version{1, 0, 3}}, DevicePhone}}, + + {"Mozilla/5.0 (Linux; U; Android 1.5; en-gb; T-Mobile G1 Build/CRC1) AppleWebKit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1", + UserAgent{ + Browser{BrowserAndroid, Version{3, 1, 2}}, OS{PlatformLinux, OSAndroid, Version{1, 5, 0}}, DevicePhone}}, + + {"Mozilla/5.0 (Linux; U; Android 1.5; es-; FBW1_4 Build/MASTER) AppleWebKit/525.10+ (KHTML, like Gecko) Version/3.0.4 Mobile Safari/523.12.2", + UserAgent{ + Browser{BrowserAndroid, Version{3, 0, 4}}, OS{PlatformLinux, OSAndroid, Version{1, 5, 0}}, DevicePhone}}, + + {"Mozilla/5.0 (Linux U; Android 1.5 en-us hero) AppleWebKit/525.10+ (KHTML, like Gecko) Version/3.0.4 Mobile Safari/523.12.2", + UserAgent{ + Browser{BrowserAndroid, Version{3, 0, 4}}, OS{PlatformLinux, OSAndroid, Version{1, 5, 0}}, DevicePhone}}, + + {"Mozilla/5.0 (Linux; U; Android 1.5; en-us; Opus One Build/RBE.00.00) AppleWebKit/528.18.1 (KHTML, like Gecko) Version/3.1.1 Mobile Safari/525.20.1", + UserAgent{ + Browser{BrowserAndroid, Version{3, 1, 1}}, OS{PlatformLinux, OSAndroid, Version{1, 5, 0}}, DevicePhone}}, + + {"Mozilla/5.0 (Linux; U; Android 1.6; ar-us; SonyEricssonX10i Build/R2BA026) AppleWebKit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1", + UserAgent{ + Browser{BrowserAndroid, Version{3, 1, 2}}, OS{PlatformLinux, OSAndroid, Version{1, 6, 0}}, DevicePhone}}, + + // TODO: support names of Android OS? + //{"Mozilla/5.0 (Linux; U; Android Donut; de-de; HTC Tattoo 1.52.161.1 Build/Donut) AppleWebKit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1", + // UserAgent{ + // Browser{BrowserAndroid, Version{3, 1, 2}}, OS{PlatformLinux, OSAndroid, Version{1, 0, 0}}, DevicePhone}}, + + {"Mozilla/5.0 (Linux; U; Android 1.6; en-gb; HTC Tattoo Build/DRC79) AppleWebKit/525.10+ (KHTML, like Gecko) Version/3.0.4 Mobile Safari/523.12.2", + UserAgent{ + Browser{BrowserAndroid, Version{3, 0, 4}}, OS{PlatformLinux, OSAndroid, Version{1, 6, 0}}, DevicePhone}}, + + {"Mozilla/5.0 (Linux; U; Android 1.6; ja-jp; Docomo HT-03A Build/DRD08) AppleWebKit/525.10 (KHTML, like Gecko) Version/3.0.4 Mobile Safari/523.12.2", + UserAgent{ + Browser{BrowserAndroid, Version{3, 0, 4}}, OS{PlatformLinux, OSAndroid, Version{1, 6, 0}}, DevicePhone}}, + + {"Mozilla/5.0 (Linux; U; Android 2.1; en-us; Nexus One Build/ERD62) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17", + UserAgent{ + Browser{BrowserAndroid, Version{4, 0, 0}}, OS{PlatformLinux, OSAndroid, Version{2, 1, 0}}, DevicePhone}}, + + {"Mozilla/5.0 (Linux; U; Android 2.1-update1; en-au; HTC_Desire_A8183 V1.16.841.1 Build/ERE27) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17", + UserAgent{ + Browser{BrowserAndroid, Version{4, 0, 0}}, OS{PlatformLinux, OSAndroid, Version{2, 1, 0}}, DevicePhone}}, + + {"Mozilla/5.0 (Linux; U; Android 2.1; en-us; generic) AppleWebKit/525.10+ (KHTML, like Gecko) Version/3.0.4 Mobile Safari/523.12.2", + UserAgent{ + Browser{BrowserAndroid, Version{3, 0, 4}}, OS{PlatformLinux, OSAndroid, Version{2, 1, 0}}, DevicePhone}}, + + // TODO support named versions of Android? + {"Mozilla/5.0 (Linux; U; Android Eclair; en-us; sholes) AppleWebKit/525.10+ (KHTML, like Gecko) Version/3.0.4 Mobile Safari/523.12.2", + UserAgent{ + Browser{BrowserAndroid, Version{3, 0, 4}}, OS{PlatformLinux, OSAndroid, Version{0, 0, 0}}, DevicePhone}}, + + {"Mozilla/5.0 (Linux; U; Android 2.2; en-sa; HTC_DesireHD_A9191 Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1", + UserAgent{ + Browser{BrowserAndroid, Version{4, 0, 0}}, OS{PlatformLinux, OSAndroid, Version{2, 2, 0}}, DevicePhone}}, + + {"Mozilla/5.0 (Linux; U; Android 2.2.1; en-gb; HTC_DesireZ_A7272 Build/FRG83D) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1", + UserAgent{ + Browser{BrowserAndroid, Version{4, 0, 0}}, OS{PlatformLinux, OSAndroid, Version{2, 2, 1}}, DevicePhone}}, + + {"Mozilla/5.0 (Linux; U; Android 2.3.3; en-us; Sensation_4G Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/5.0 Safari/533.16", + UserAgent{ + Browser{BrowserAndroid, Version{5, 0, 0}}, OS{PlatformLinux, OSAndroid, Version{2, 3, 3}}, DevicePhone}}, + + {"Mozilla/5.0 (Linux; U; Android 2.3.5; ko-kr; SHW-M250S Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1", + UserAgent{ + Browser{BrowserAndroid, Version{4, 0, 0}}, OS{PlatformLinux, OSAndroid, Version{2, 3, 5}}, DevicePhone}}, + + {"Mozilla/5.0 (Linux; U; Android 2.3.7; ja-jp; L-02D Build/GWK74) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1", + UserAgent{ + Browser{BrowserAndroid, Version{4, 0, 0}}, OS{PlatformLinux, OSAndroid, Version{2, 3, 7}}, DevicePhone}}, + + // TODO: is tablet, not phone + {"Mozilla/5.0 (Linux; U; Android 3.0; xx-xx; Transformer TF101 Build/HRI66) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13", + UserAgent{ + Browser{BrowserAndroid, Version{4, 0, 0}}, OS{PlatformLinux, OSAndroid, Version{3, 0, 0}}, DevicePhone}}, + + {"Mozilla/5.0 (Linux; U; Android 3.0; en-us; Xoom Build/HRI39) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13", + UserAgent{ + Browser{BrowserAndroid, Version{4, 0, 0}}, OS{PlatformLinux, OSAndroid, Version{3, 0, 0}}, DeviceTablet}}, + + {"Mozilla/5.0 (Linux; U; Android 4.0.1; en-us; sdk Build/ICS_MR0) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30", + UserAgent{ + Browser{BrowserAndroid, Version{4, 0, 0}}, OS{PlatformLinux, OSAndroid, Version{4, 0, 1}}, DevicePhone}}, + + // TODO support "android-" version prefix + // However, can't find reference to this naming scheme in real-world UA gathering + // {"Mozilla/5.0 (Linux; U; Android-4.0.3; en-us; Galaxy Nexus Build/IML74K) AppleWebKit/535.7 (KHTML, like Gecko) CrMo/16.0.912.75 Mobile Safari/535.7", + // UserAgent{ + // Browser{BrowserChrome, Version{16,0,0}}, OS{PlatformLinux, OSAndroid, Version{4,0,0}}, DevicePhone}}, + + {"Mozilla/5.0 (Linux; U; Android 4.1.1; en-us; Nexus S Build/JRO03E) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30", + UserAgent{ + Browser{BrowserAndroid, Version{4, 0, 0}}, OS{PlatformLinux, OSAndroid, Version{4, 1, 1}}, DevicePhone}}, + + {"Mozilla/5.0 (Linux; U; Android 4.1; en-gb; Build/JRN84D) AppleWebKit/534.30 (KHTML like Gecko) Version/4.0 Mobile Safari/534.30", + UserAgent{ + Browser{BrowserAndroid, Version{4, 0, 0}}, OS{PlatformLinux, OSAndroid, Version{4, 1, 0}}, DevicePhone}}, + + {"Mozilla/5.0 (Linux; U; Android 4.1.1; el-gr; MB525 Build/JRO03H; CyanogenMod-10) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30", + UserAgent{ + Browser{BrowserAndroid, Version{4, 0, 0}}, OS{PlatformLinux, OSAndroid, Version{4, 1, 1}}, DevicePhone}}, + + {"Mozilla/5.0 (Linux; U; Android 4.1.1; fr-fr; MB525 Build/JRO03H; CyanogenMod-10) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30", + UserAgent{ + Browser{BrowserAndroid, Version{4, 0, 0}}, OS{PlatformLinux, OSAndroid, Version{4, 1, 1}}, DevicePhone}}, + + {"Mozilla/5.0 (Linux; U; Android 4.2; en-us; Nexus 10 Build/JVP15I) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Safari/534.30", + UserAgent{ + Browser{BrowserAndroid, Version{4, 0, 0}}, OS{PlatformLinux, OSAndroid, Version{4, 2, 0}}, DeviceTablet}}, + + {"Mozilla/5.0 (Linux; U; Android 4.2; ro-ro; LT18i Build/4.1.B.0.431) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30", + UserAgent{ + Browser{BrowserAndroid, Version{4, 0, 0}}, OS{PlatformLinux, OSAndroid, Version{4, 2, 0}}, DevicePhone}}, + + {"Mozilla/5.0 (Linux; Android 4.3; Nexus 7 Build/JWR66D) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.111 Safari/537.36", + UserAgent{ + Browser{BrowserChrome, Version{27, 0, 1453}}, OS{PlatformLinux, OSAndroid, Version{4, 3, 0}}, DeviceTablet}}, + + {"Mozilla/5.0 (Linux; Android 4.4; Nexus 7 Build/KOT24) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.105 Safari/537.36", + UserAgent{ + Browser{BrowserChrome, Version{30, 0, 1599}}, OS{PlatformLinux, OSAndroid, Version{4, 4, 0}}, DeviceTablet}}, + + {"Mozilla/5.0 (Linux; Android 4.4; Nexus 4 Build/KRT16E) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.105 Mobile Safari", + UserAgent{ + Browser{BrowserChrome, Version{30, 0, 1599}}, OS{PlatformLinux, OSAndroid, Version{4, 4, 0}}, DevicePhone}}, + + {"Mozilla/5.0 (Linux; Android 6.0.1; SM-G930V Build/MMB29M) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.98 Mobile Safari/537.36", + UserAgent{ + Browser{BrowserChrome, Version{52, 0, 2743}}, OS{PlatformLinux, OSAndroid, Version{6, 0, 1}}, DevicePhone}}, + + {"Mozilla/5.0 (Linux; Android 7.0; Nexus 5X Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.98 Mobile Safari/537.36", + UserAgent{ + Browser{BrowserChrome, Version{52, 0, 2743}}, OS{PlatformLinux, OSAndroid, Version{7, 0, 0}}, DevicePhone}}, + + {"Mozilla/5.0 (Linux; Android 7.0; Nexus 6P Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/52.0.2743.98 Mobile Safari/537.36", + UserAgent{ + Browser{BrowserChrome, Version{52, 0, 2743}}, OS{PlatformLinux, OSAndroid, Version{7, 0, 0}}, DevicePhone}}, + + // BLACKBERRY TESTS + + {"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0) BlackBerry8703e/4.1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/104", + UserAgent{ + Browser{BrowserBlackberry, Version{0, 0, 0}}, OS{PlatformBlackberry, OSBlackberry, Version{0, 0, 0}}, DevicePhone}}, + + {"Mozilla/5.0 (BB10; Touch) AppleWebKit/537.10+ (KHTML, like Gecko) Version/10.1.0.4633 Mobile Safari/537.10+", + UserAgent{ + Browser{BrowserBlackberry, Version{10, 1, 0}}, OS{PlatformBlackberry, OSBlackberry, Version{0, 0, 0}}, DevicePhone}}, + + {"Mozilla/5.0 (BB10; Kbd) AppleWebKit/537.35+ (KHTML, like Gecko) Version/10.2.1.1925 Mobile Safari/537.35+", + UserAgent{ + Browser{BrowserBlackberry, Version{10, 2, 1}}, OS{PlatformBlackberry, OSBlackberry, Version{0, 0, 0}}, DevicePhone}}, + + {"Mozilla/5.0 (PlayBook; U; RIM Tablet OS 1.0.0; en-US) AppleWebKit/534.11 (KHTML, like Gecko) Version/7.1.0.7 Safari/534.11", + UserAgent{ + Browser{BrowserBlackberry, Version{7, 1, 0}}, OS{PlatformBlackberry, OSBlackberry, Version{0, 0, 0}}, DeviceTablet}}, + + {"Mozilla/5.0 (PlayBook; U; RIM Tablet OS 2.1.0; en-US) AppleWebKit/536.2+ (KHTML, like Gecko) Version/7.2.1.0 Safari/536.2+", + UserAgent{ + Browser{BrowserBlackberry, Version{7, 2, 1}}, OS{PlatformBlackberry, OSBlackberry, Version{0, 0, 0}}, DeviceTablet}}, + + {"Mozilla/5.0 (X11; U; CrOS i686 9.10.0; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.0.253.0 Safari/532.5", + UserAgent{ + Browser{BrowserChrome, Version{4, 0, 253}}, OS{PlatformLinux, OSChromeOS, Version{0, 0, 0}}, DeviceComputer}}, + + {"Mozilla/5.0 (X11; CrOS armv7l 5500.100.6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.120 Safari/537.36", + UserAgent{ + Browser{BrowserChrome, Version{34, 0, 1847}}, OS{PlatformLinux, OSChromeOS, Version{0, 0, 0}}, DeviceComputer}}, + + // {"Mozilla/5.0 (Mobile; rv:14.0) Gecko/14.0 Firefox/14.0", + // UserAgent{ + // Browser{BrowserFirefox, 14, OSFirefoxOS, 14}, DevicePhone}}, + + // {"Mozilla/5.0 (Mobile; rv:17.0) Gecko/17.0 Firefox/17.0", + // UserAgent{ + // Browser{BrowserFirefox, , OSFirefoxOS}, DevicePhone}}, + + // {"Mozilla/5.0 (Mobile; rv:18.1) Gecko/18.1 Firefox/18.1", + // UserAgent{ + // Browser{BrowserFirefox, , OSFirefoxOS}, DevicePhone}}, + + // {"Mozilla/5.0 (Tablet; rv:18.1) Gecko/18.1 Firefox/18.1", + // UserAgent{ + // Browser{BrowserFirefox, , OSFirefoxOS}, DevicePhone}}, + + // {"Mozilla/5.0 (Mobile; LG-D300; rv:18.1) Gecko/18.1 Firefox/18.1", + // UserAgent{ + // Browser{BrowserFirefox, , OSFirefoxOS}, DevicePhone}}, + + {"Mozilla/5.0(iPad; U; CPU iPhone OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314 Safari/531.21.10", + UserAgent{ + Browser{BrowserSafari, Version{4, 0, 4}}, OS{PlatformiPad, OSiOS, Version{3, 2, 0}}, DeviceTablet}}, + + {"Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7", + UserAgent{ + Browser{BrowserSafari, Version{4, 0, 5}}, OS{PlatformiPhone, OSiOS, Version{4, 0, 0}}, DevicePhone}}, + + {"Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3", + UserAgent{ + Browser{BrowserSafari, Version{5, 1, 0}}, OS{PlatformiPhone, OSiOS, Version{5, 0, 0}}, DevicePhone}}, + + {"Mozilla/5.0 (iPad; CPU OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3", + UserAgent{ + Browser{BrowserSafari, Version{5, 1, 0}}, OS{PlatformiPad, OSiOS, Version{5, 0, 0}}, DeviceTablet}}, + + {"Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25", + UserAgent{ + Browser{BrowserSafari, Version{6, 0, 0}}, OS{PlatformiPad, OSiOS, Version{6, 0, 0}}, DeviceTablet}}, + + {"Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X) AppleWebKit/546.10 (KHTML, like Gecko) Version/6.0 Mobile/7E18WD Safari/8536.25", + UserAgent{ + Browser{BrowserSafari, Version{6, 0, 0}}, OS{PlatformiPhone, OSiOS, Version{7, 0, 0}}, DevicePhone}}, + + {"Mozilla/5.0 (iPad; CPU OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53", + UserAgent{ + Browser{BrowserSafari, Version{7, 0, 0}}, OS{PlatformiPad, OSiOS, Version{7, 0, 0}}, DeviceTablet}}, + + {"Mozilla/5.0 (iPad; CPU OS 7_0_2 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A501 Safari/9537.53", + UserAgent{ + Browser{BrowserSafari, Version{7, 0, 0}}, OS{PlatformiPad, OSiOS, Version{7, 0, 2}}, DeviceTablet}}, + + {"Mozilla/5.0 (iPhone; CPU iPhone OS 10_2_1 like Mac OS X) AppleWebKit/602.4.6 (KHTML, like Gecko) Mobile/14D27 [FBAN/FBIOS;FBAV/86.0.0.48.52;FBBV/53842252;FBDV/iPhone9,1;FBMD/iPhone;FBSN/iOS;FBSV/10.2.1;FBSS/2;FBCR/Verizon;FBID/phone;FBLC/en_US;FBOP/5;FBRV/0]", + UserAgent{ + Browser{BrowserSafari, Version{10, 2, 1}}, OS{PlatformiPhone, OSiOS, Version{10, 2, 1}}, DevicePhone}}, + + // TODO handle default browser based on iOS version + // {"Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/538.34.9 (KHTML, like Gecko) Mobile/12A4265u", + // UserAgent{ + // Browser{BrowserSafari, Version{8,0,0}}, OS{PlatformiPhone, OSiOS, Version{8,0,0}}, DevicePhone}}, + + // TODO extrapolate browser from iOS version + // {"Mozilla/5.0 (iPad; CPU OS 8_0 like Mac OS X) AppleWebKit/538.34.9 (KHTML, like Gecko) Mobile/12A4265u", + // UserAgent{ + // Browser{BrowserSafari, Version{8,0,0}}, OS{PlatformiPad, OSiOS, Version{8,0,0}}, DeviceTablet}}, + + {"Mozilla/5.0 (iPhone; CPU iPhone OS 8_0_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12A405 Safari/600.1.4", + UserAgent{ + Browser{BrowserSafari, Version{8, 0, 0}}, OS{PlatformiPhone, OSiOS, Version{8, 0, 2}}, DevicePhone}}, + + {"Mozilla/5.0 (X11; U; Linux x86_64; en; rv:1.9.0.14) Gecko/20080528 Ubuntu/9.10 (karmic) Epiphany/2.22 Firefox/3.0", + UserAgent{ + Browser{BrowserFirefox, Version{3, 0, 0}}, OS{PlatformLinux, OSLinux, Version{0, 0, 0}}, DeviceComputer}}, + + // Can't parse browser due to limitation of user agent library + {"Mozilla/5.0 (X11; U; Linux x86_64; zh-TW; rv:1.9.0.8) Gecko/2009032712 Ubuntu/8.04 (hardy) Firefox/3.0.8 GTB5", + UserAgent{ + Browser{BrowserFirefox, Version{3, 0, 8}}, OS{PlatformLinux, OSLinux, Version{0, 0, 0}}, DeviceComputer}}, + + {"Mozilla/5.0 (compatible; Konqueror/3.5; Linux; x86_64) KHTML/3.5.5 (like Gecko) (Debian)", + UserAgent{ + Browser{BrowserUnknown, Version{0, 0, 0}}, OS{PlatformLinux, OSLinux, Version{0, 0, 0}}, DeviceComputer}}, + + {"Mozilla/5.0 (X11; U; Linux i686; de; rv:1.9.1.5) Gecko/20091112 Iceweasel/3.5.5 (like Firefox/3.5.5; Debian-3.5.5-1)", + UserAgent{ + Browser{BrowserFirefox, Version{3, 5, 5}}, OS{PlatformLinux, OSLinux, Version{0, 0, 0}}, DeviceComputer}}, + + // TODO consider bot? + // {"Miro/2.0.4 (http://www.getmiro.com/; Darwin 10.3.0 i386)", + // UserAgent{ + // Browser{BrowserUnknown, Version{0,0,0}}, OS{PlatformMac, OSMacOSX, Version{3,0,0}}, DeviceComputer}}, + + {"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.1b3pre) Gecko/20090223 SeaMonkey/2.0a3", + UserAgent{ + Browser{BrowserFirefox, Version{0, 0, 0}}, OS{PlatformMac, OSMacOSX, Version{10, 4, 0}}, DeviceComputer}}, + + {"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_5; en-us) AppleWebKit/525.26.2 (KHTML, like Gecko) Version/3.2 Safari/525.26.12", + UserAgent{ + Browser{BrowserSafari, Version{3, 2, 0}}, OS{PlatformMac, OSMacOSX, Version{10, 5, 5}}, DeviceComputer}}, + + {"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en; rv:1.9.0.8pre) Gecko/2009022800 Camino/2.0b3pre", + UserAgent{ + Browser{BrowserUnknown, Version{0, 0, 0}}, OS{PlatformMac, OSMacOSX, Version{10, 5, 0}}, DeviceComputer}}, + + {"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_2; en-US) AppleWebKit/533.1 (KHTML, like Gecko) Chrome/5.0.329.0 Safari/533.1", + UserAgent{ + Browser{BrowserChrome, Version{5, 0, 329}}, OS{PlatformMac, OSMacOSX, Version{10, 6, 2}}, DeviceComputer}}, + + {"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6 (.NET CLR 3.5.30729)", + UserAgent{ + Browser{BrowserFirefox, Version{3, 5, 6}}, OS{PlatformMac, OSMacOSX, Version{10, 6, 0}}, DeviceComputer}}, + + {"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/534.52.7 (KHTML, like Gecko) Version/5.1.2 Safari/534.52.7", + UserAgent{ + Browser{BrowserSafari, Version{5, 1, 2}}, OS{PlatformMac, OSMacOSX, Version{10, 7, 2}}, DeviceComputer}}, + + {"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:9.0) Gecko/20111222 Thunderbird/9.0.1", + UserAgent{ + Browser{BrowserUnknown, Version{0, 0, 0}}, OS{PlatformMac, OSMacOSX, Version{10, 7, 0}}, DeviceComputer}}, + + {"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.75 Safari/535.7", + UserAgent{ + Browser{BrowserChrome, Version{16, 0, 912}}, OS{PlatformMac, OSMacOSX, Version{10, 7, 2}}, DeviceComputer}}, + + {"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8) AppleWebKit/535.18.5 (KHTML, like Gecko) Version/5.2 Safari/535.18.5", + UserAgent{ + Browser{BrowserSafari, Version{5, 2, 0}}, OS{PlatformMac, OSMacOSX, Version{10, 8, 0}}, DeviceComputer}}, + + {"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_8; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.0.249.0 Safari/532.5", + UserAgent{ + Browser{BrowserChrome, Version{4, 0, 249}}, OS{PlatformMac, OSMacOSX, Version{10, 8, 0}}, DeviceComputer}}, + + {"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9) AppleWebKit/537.35.1 (KHTML, like Gecko) Version/6.1 Safari/537.35.1", + UserAgent{ + Browser{BrowserSafari, Version{6, 1, 0}}, OS{PlatformMac, OSMacOSX, Version{10, 9, 0}}, DeviceComputer}}, + + {"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10) AppleWebKit/538.34.48 (KHTML, like Gecko) Version/8.0 Safari/538.35.8", + UserAgent{ + Browser{BrowserSafari, Version{8, 0, 0}}, OS{PlatformMac, OSMacOSX, Version{10, 10, 0}}, DeviceComputer}}, + + {"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10) AppleWebKit/538.32 (KHTML, like Gecko) Version/7.1 Safari/538.4", + UserAgent{ + Browser{BrowserSafari, Version{7, 1, 0}}, OS{PlatformMac, OSMacOSX, Version{10, 10, 0}}, DeviceComputer}}, + + {"Opera/9.80 (S60; SymbOS; Opera Mobi/352; U; de) Presto/2.4.15 Version/10.00", + UserAgent{ + Browser{BrowserOpera, Version{10, 0, 0}}, OS{PlatformUnknown, OSUnknown, Version{0, 0, 0}}, DevicePhone}}, + + {"Opera/9.80 (S60; SymbOS; Opera Mobi/352; U; de) Presto/2.4.15 Version/10.00", + UserAgent{ + Browser{BrowserOpera, Version{10, 0, 0}}, OS{PlatformUnknown, OSUnknown, Version{0, 0, 0}}, DevicePhone}}, + + // TODO: support OneBrowser? https://play.google.com/store/apps/details?id=com.tencent.ibibo.mtt&hl=en_GB + // {"OneBrowser/3.1 (NokiaN70-1/5.0638.3.0.1)", + // UserAgent{ + // Browser{BrowserUnknown, Version{0,0,0}}, OS{PlatformUnknown, OSUnknown, Version{0,0,0}}, DevicePhone}}, + + // WebOS reports itself as safari :( + {"Mozilla/5.0 (webOS/1.0; U; en-US) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/1.0 Safari/525.27.1 Pre/1.0", + UserAgent{ + Browser{BrowserUnknown, Version{1, 0, 0}}, OS{PlatformLinux, OSWebOS, Version{0, 0, 0}}, DevicePhone}}, + + {"Mozilla/5.0 (webOS/1.4.1.1; U; en-US) AppleWebKit/532.2 (KHTML, like Gecko) Version/1.0 Safari/532.2 Pre/1.0", + UserAgent{ + Browser{BrowserUnknown, Version{1, 0, 0}}, OS{PlatformLinux, OSWebOS, Version{0, 0, 0}}, DevicePhone}}, + + {"Mozilla/5.0 (hp-tablet; Linux; hpwOS/3.0.0; U; de-DE) AppleWebKit/534.6 (KHTML, like Gecko) wOSBrowser/233.70 Safari/534.6 TouchPad/1.0", + UserAgent{ + Browser{BrowserUnknown, Version{0, 0, 0}}, OS{PlatformLinux, OSWebOS, Version{0, 0, 0}}, DeviceTablet}}, + + {"Mozilla/5.0 (hp-tablet; Linux; hpwOS/3.0.2; U; en-US) AppleWebKit/534.6 (KHTML, like Gecko) wOSBrowser/234.40.1 Safari/534.6 TouchPad/1.0", + UserAgent{ + Browser{BrowserUnknown, Version{0, 0, 0}}, OS{PlatformLinux, OSWebOS, Version{0, 0, 0}}, DeviceTablet}}, + + {"Opera/9.30 (Nintendo Wii; U; ; 2047-7; fr)", + UserAgent{ + Browser{BrowserOpera, Version{9, 30, 0}}, OS{PlatformNintendo, OSNintendo, Version{0, 0, 0}}, DeviceConsole}}, + + {"Mozilla/5.0 (Nintendo WiiU) AppleWebKit/534.52 (KHTML, like Gecko) NX/2.1.0.8.21 NintendoBrowser/1.0.0.7494.US", + UserAgent{ + Browser{BrowserUnknown, Version{0, 0, 0}}, OS{PlatformNintendo, OSNintendo, Version{0, 0, 0}}, DeviceConsole}}, + + {"Mozilla/5.0 (Nintendo WiiU) AppleWebKit/536.28 (KHTML, like Gecko) NX/3.0.3.12.6 NintendoBrowser/2.0.0.9362.US", + UserAgent{ + Browser{BrowserUnknown, Version{0, 0, 0}}, OS{PlatformNintendo, OSNintendo, Version{0, 0, 0}}, DeviceConsole}}, + + // TODO fails to get opera first -- but is this a real UA string or an uncommon spoof? + // {"Mozilla/4.0 (compatible; MSIE 5.0; Windows 2000) Opera 6.0 [en]", + // BrowserIE, Version{5,0,0}}, OS{PlatformWindows, OSWindows, Version{4,0,0}}, DeviceComputer}}, + + {"Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0; SV1; .NET CLR 1.1.4322; .NET CLR 1.0.3705; .NET CLR 2.0.50727)", + UserAgent{ + Browser{BrowserIE, Version{5, 0, 1}}, OS{PlatformWindows, OSWindows, Version{5, 0, 0}}, DeviceComputer}}, + + {"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/4.0; GTB6.4; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; OfficeLiveConnector.1.3; OfficeLivePatch.0.0; .NET CLR 1.1.4322)", + UserAgent{ + Browser{BrowserIE, Version{7, 0, 0}}, OS{PlatformWindows, OSWindows, Version{6, 1, 0}}, DeviceComputer}}, + + {"Mozilla/5.0 (Windows; U; Windows NT 6.1; sk; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7", + UserAgent{ + Browser{BrowserFirefox, Version{3, 5, 7}}, OS{PlatformWindows, OSWindows, Version{6, 1, 0}}, DeviceComputer}}, + + {"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)", + UserAgent{ + Browser{BrowserIE, Version{10, 0, 0}}, OS{PlatformWindows, OSWindows, Version{6, 2, 0}}, DeviceComputer}}, + + {"Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) YaBrowser/1.0.1084.5402 Chrome/19.0.1084.5402 Safari/536.5", + UserAgent{ + Browser{BrowserChrome, Version{19, 0, 1084}}, OS{PlatformWindows, OSWindows, Version{6, 2, 0}}, DeviceComputer}}, + + {"Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.15 (KHTML, like Gecko) Chrome/24.0.1295.0 Safari/537.15", + UserAgent{ + Browser{BrowserChrome, Version{24, 0, 1295}}, OS{PlatformWindows, OSWindows, Version{6, 2, 0}}, DeviceComputer}}, + + {"Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; Touch; rv:11.0) like Gecko", + UserAgent{ + Browser{BrowserIE, Version{11, 0, 0}}, OS{PlatformWindows, OSWindows, Version{6, 3, 0}}, DeviceTablet}}, + + {"Mozilla/5.0 (IE 11.0; Windows NT 6.3; Trident/7.0; .NET4.0E; .NET4.0C; rv:11.0) like Gecko", + UserAgent{ + Browser{BrowserIE, Version{11, 0, 0}}, OS{PlatformWindows, OSWindows, Version{6, 3, 0}}, DeviceComputer}}, + + // {"Mozilla/4.0 (compatible; MSIE 4.01; Windows 95)", + // UserAgent{ + // Browser{BrowserIE, Version{5,0,0}}, OS{PlatformWindows, OSWindows95, Version{5,0,0}}, DeviceComputer}}, + + // {"Mozilla/4.0 (compatible; MSIE 5.0; Windows 95) Opera 6.02 [en]", + // UserAgent{ + // Browser{BrowserIE, Version{5,0,0}}, OS{PlatformWindows, OSWindows95, Version{5,0,0}}, DeviceComputer}}, + + // {"Mozilla/4.0 (compatible; MSIE 6.0b; Windows 98; YComp 5.0.0.0)", + // UserAgent{ + // Browser{BrowserIE, Version{6,0,0}}, OS{PlatformWindows, OSWindows98, Version{5,0,0}}, DeviceComputer}}, + + // {"Mozilla/4.0 (compatible; MSIE 4.01; Windows 98)", + // UserAgent{ + // Browser{BrowserIE, Version{4,0,0}}, OS{PlatformWindows, OSWindows98, Version{5,0,0}}, DeviceComputer}}, + + // {"Mozilla/5.0 (Windows; U; Windows 98; en-US; rv:1.8.1.8pre) Gecko/20071019 Firefox/2.0.0.8 Navigator/9.0.0.1", + // UserAgent{ + // Browser{BrowserFirefox, Version{2,0,0}}, OS{PlatformWindows, OSWindows98, Version{5,0,0}}, DeviceComputer}}, + + //Can't parse due to limitation of user agent library + // {"Mozilla/5.0 (Windows; U; Windows CE 5.1; rv:1.8.1a3) Gecko/20060610 Minimo/0.016", + // UserAgent{ + // Browser{ BrowserUnknown, Version{0,0,0}}, OS{PlatformWindowsPhone, OSWindowsPhone, Version{0,0,0}}, DevicePhone}}, + + // {"Mozilla/4.0 (compatible; MSIE 4.01; Windows CE; 176x220)", + // UserAgent{ + // Browser{BrowserIE, Version{4,0,0}}, OS{PlatformWindowsPhone, OSWindowsPhone, Version{0,0,0}}, DevicePhone}}, + + // Can't parse browser due to limitation of user agent library + // {"Mozilla/4.0 (compatible; MSIE 5.0; Windows ME) Opera 6.0 [de]", + // UserAgent{ + // Browser{BrowserUnknown, OSWindowsME}, DeviceComputer}}, + + {"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 1.1.4322; InfoPath.2; .NET CLR 3.5.21022; .NET CLR 3.5.30729; MS-RTC LM 8; OfficeLiveConnector.1.4; OfficeLivePatch.1.3; .NET CLR 3.0.30729)", + UserAgent{ + Browser{BrowserIE, Version{8, 0, 0}}, OS{PlatformWindows, OSWindows, Version{6, 0, 0}}, DeviceComputer}}, + + {"Mozilla/5.0 (Windows; U; Windows NT 5.1; cs; rv:1.9.1.8) Gecko/20100202 Firefox/3.5.8", + UserAgent{ + Browser{BrowserFirefox, Version{3, 5, 8}}, OS{PlatformWindows, OSWindows, Version{5, 1, 0}}, DeviceComputer}}, + + {"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; )", + UserAgent{ + Browser{BrowserIE, Version{7, 0, 0}}, OS{PlatformWindows, OSWindows, Version{5, 1, 0}}, DeviceComputer}}, + + // Can't parse due to limitation of user agent library + {"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Windows Phone 6.5.3.5)", + UserAgent{ + Browser{BrowserIE, Version{6, 0, 0}}, OS{PlatformWindowsPhone, OSWindowsPhone, Version{6, 5, 3}}, DevicePhone}}, + + // desktop mode for Windows Phone 7 + {"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; XBLWP7; ZuneWP7)", + UserAgent{ + Browser{BrowserIE, Version{7, 0, 0}}, OS{PlatformWindows, OSWindows, Version{6, 1, 0}}, DeviceComputer}}, + + // mobile mode for Windows Phone 7 + {"Mozilla/4.0 (compatible; MSIE 7.0; Windows Phone OS 7.0; Trident/3.1; IEMobile/7.0; HTC; T8788)", + UserAgent{ + Browser{BrowserIE, Version{7, 0, 0}}, OS{PlatformWindowsPhone, OSWindowsPhone, Version{7, 0, 0}}, DevicePhone}}, + + {"Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0)", + UserAgent{ + Browser{BrowserIE, Version{9, 0, 0}}, OS{PlatformWindowsPhone, OSWindowsPhone, Version{7, 5, 0}}, DevicePhone}}, + + {"Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 920)", + UserAgent{ + Browser{BrowserIE, Version{10, 0, 0}}, OS{PlatformWindowsPhone, OSWindowsPhone, Version{8, 0, 0}}, DevicePhone}}, + + {"Mozilla/5.0 (Windows Phone 8.1; ARM; Trident/7.0; Touch IEMobile/11.0; HTC; Windows Phone 8S by HTC) like Gecko", + UserAgent{ + Browser{BrowserIE, Version{11, 0, 0}}, OS{PlatformWindowsPhone, OSWindowsPhone, Version{8, 1, 0}}, DevicePhone}}, + + {"Mozilla/5.0 (Windows Phone 8.1; ARM; Trident/7.0; Touch IEMobile/11.0; NOKIA; 909) like Gecko", + UserAgent{ + Browser{BrowserIE, Version{11, 0, 0}}, OS{PlatformWindowsPhone, OSWindowsPhone, Version{8, 1, 0}}, DevicePhone}}, + + {"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; Xbox)", + UserAgent{ + Browser{BrowserIE, Version{9, 0, 0}}, OS{PlatformXbox, OSXbox, Version{6, 1, 0}}, DeviceConsole}}, +} + +func TestAgentSurfer(t *testing.T) { + for _, determined := range testUAVars { + t.Run("", func(t *testing.T) { + testFuncs := []func(string) *UserAgent{ + Parse, + func(ua string) *UserAgent { + u := new(UserAgent) + ParseUserAgent(ua, u) + return u + }, + } + + for _, f := range testFuncs { + ua := f(determined.UA) + + if ua.Browser.Name != determined.Browser.Name { + t.Errorf("browserName: got %v, wanted %v", ua.Browser.Name, determined.Browser.Name) + t.Logf("agent: %s", determined.UA) + } + + if ua.Browser.Version != determined.Browser.Version { + t.Errorf("browser version: got %d, wanted %d", ua.Browser.Version, determined.Browser.Version) + t.Logf("agent: %s", determined.UA) + } + + if ua.OS.Platform != determined.OS.Platform { + t.Errorf("platform: got %v, wanted %v", ua.OS.Platform, determined.OS.Platform) + t.Logf("agent: %s", determined.UA) + } + + if ua.OS.Name != determined.OS.Name { + t.Errorf("os: got %s, wanted %s", ua.OS.Name, determined.OS.Name) + t.Logf("agent: %s", determined.UA) + } + + if ua.OS.Version != determined.OS.Version { + t.Errorf("os version: got %d, wanted %d", ua.OS.Version, determined.OS.Version) + t.Logf("agent: %s", determined.UA) + } + + if ua.DeviceType != determined.DeviceType { + t.Errorf("device type: got %v, wanted %v", ua.DeviceType, determined.DeviceType) + t.Logf("agent: %s", determined.UA) + } + } + }) + } +} + +func BenchmarkAgentSurfer(b *testing.B) { + num := len(testUAVars) + b.ResetTimer() + for i := 0; i < b.N; i++ { + Parse(testUAVars[i%num].UA) + } +} + +func BenchmarkAgentSurferReuse(b *testing.B) { + dest := new(UserAgent) + num := len(testUAVars) + b.ResetTimer() + for i := 0; i < b.N; i++ { + dest.Reset() + ParseUserAgent(testUAVars[i%num].UA, dest) + } +} + +func BenchmarkEvalSystem(b *testing.B) { + num := len(testUAVars) + v := UserAgent{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + v.evalOS(testUAVars[i%num].UA) + } +} + +func BenchmarkEvalBrowserName(b *testing.B) { + num := len(testUAVars) + v := UserAgent{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + v.evalBrowserName(testUAVars[i%num].UA) + } +} + +func BenchmarkEvalBrowserVersion(b *testing.B) { + num := len(testUAVars) + v := UserAgent{} + b.ResetTimer() + for i := 0; i < b.N; i++ { + v.Browser.Name = testUAVars[i%num].Browser.Name + v.evalBrowserVersion(testUAVars[i%num].UA) + } +} + +func BenchmarkEvalDevice(b *testing.B) { + num := len(testUAVars) + v := UserAgent{} + + b.ResetTimer() + for i := 0; i < b.N; i++ { + v.OS.Name = testUAVars[i%num].OS.Name + v.OS.Platform = testUAVars[i%num].OS.Platform + v.Browser.Name = testUAVars[i%num].Browser.Name + v.evalDevice(testUAVars[i%num].UA) + } +} + +// Chrome for Mac +func BenchmarkParseChromeMac(b *testing.B) { + b.ResetTimer() + for i := 0; i < b.N; i++ { + Parse("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36") + } +} + +// Chrome for Windows +func BenchmarkParseChromeWin(b *testing.B) { + b.ResetTimer() + for i := 0; i < b.N; i++ { + Parse("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36") + } +} + +// Chrome for Android +func BenchmarkParseChromeAndroid(b *testing.B) { + b.ResetTimer() + for i := 0; i < b.N; i++ { + Parse("Mozilla/5.0 (Linux; Android 4.4.2; GT-P5210 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.93 Safari/537.36") + } +} + +// Safari for Mac +func BenchmarkParseSafariMac(b *testing.B) { + b.ResetTimer() + for i := 0; i < b.N; i++ { + Parse("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/600.7.12 (KHTML, like Gecko) Version/8.0.7 Safari/600.7.12") + } +} + +// Safari for iPad +func BenchmarkParseSafariiPad(b *testing.B) { + b.ResetTimer() + for i := 0; i < b.N; i++ { + Parse("Mozilla/5.0 (iPad; CPU OS 8_1_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B440 Safari/600.1.4") + } +} -- cgit v1.2.3-1-g7c22