diff options
author | Christopher Speller <crspeller@gmail.com> | 2016-05-12 15:08:58 -0400 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2016-05-12 16:37:29 -0400 |
commit | 84d2482ddbff9564c9ad75b2d30af66e3ddfd44d (patch) | |
tree | 8bfa567d2b6381f4a996ada2deff8a16aa85a3ac /Godeps/_workspace/src/github.com/mssola/user_agent/bot.go | |
parent | d1efb66ad7b017f0fbfe6f0c20843b30f396e504 (diff) | |
download | chat-84d2482ddbff9564c9ad75b2d30af66e3ddfd44d.tar.gz chat-84d2482ddbff9564c9ad75b2d30af66e3ddfd44d.tar.bz2 chat-84d2482ddbff9564c9ad75b2d30af66e3ddfd44d.zip |
Updating go depencancies. Switching to go1.6 vendoring (#2949)
Diffstat (limited to 'Godeps/_workspace/src/github.com/mssola/user_agent/bot.go')
-rw-r--r-- | Godeps/_workspace/src/github.com/mssola/user_agent/bot.go | 122 |
1 files changed, 0 insertions, 122 deletions
diff --git a/Godeps/_workspace/src/github.com/mssola/user_agent/bot.go b/Godeps/_workspace/src/github.com/mssola/user_agent/bot.go deleted file mode 100644 index df0b6ccda..000000000 --- a/Godeps/_workspace/src/github.com/mssola/user_agent/bot.go +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright (C) 2014-2015 Miquel Sabaté Solà <mikisabate@gmail.com> -// This file is licensed under the MIT license. -// See the LICENSE file. - -package user_agent - -import ( - "regexp" - "strings" -) - -var botFromSiteRegexp = regexp.MustCompile("http://.+\\.\\w+") - -// Get the name of the bot from the website that may be in the given comment. If -// there is no website in the comment, then an empty string is returned. -func getFromSite(comment []string) string { - if len(comment) == 0 { - return "" - } - - // Where we should check the website. - idx := 2 - if len(comment) < 3 { - idx = 0 - } - - // Pick the site. - results := botFromSiteRegexp.FindStringSubmatch(comment[idx]) - if len(results) == 1 { - // If it's a simple comment, just return the name of the site. - if idx == 0 { - return results[0] - } - - // This is a large comment, usually the name will be in the previous - // field of the comment. - return strings.TrimSpace(comment[1]) - } - return "" -} - -// Returns true if the info that we currently have corresponds to the Google -// mobile bot. This function also modifies some attributes in the receiver -// accordingly. -func (p *UserAgent) googleBot() bool { - // This is a hackish way to detect Google's mobile bot. - if strings.Index(p.ua, "Googlebot") != -1 { - p.platform = "" - p.undecided = true - } - return p.undecided -} - -// Set the attributes of the receiver as given by the parameters. All the other -// parameters are set to empty. -func (p *UserAgent) setSimple(name, version string, bot bool) { - p.bot = bot - if !bot { - p.mozilla = "" - } - p.browser.Name = name - p.browser.Version = version - p.browser.Engine = "" - p.browser.EngineVersion = "" - p.os = "" - p.localization = "" -} - -// Fix some values for some weird browsers. -func (p *UserAgent) fixOther(sections []section) { - if len(sections) > 0 { - p.browser.Name = sections[0].name - p.browser.Version = sections[0].version - p.mozilla = "" - } -} - -// Check if we're dealing with a bot or with some weird browser. If that is the -// case, the receiver will be modified accordingly. -func (p *UserAgent) checkBot(sections []section) { - // If there's only one element, and it's doesn't have the Mozilla string, - // check whether this is a bot or not. - if len(sections) == 1 && sections[0].name != "Mozilla" { - p.mozilla = "" - - // Check whether the name has some suspicious "bot" in his name. - reg, _ := regexp.Compile("(?i)bot") - if reg.Match([]byte(sections[0].name)) { - p.setSimple(sections[0].name, "", true) - return - } - - // Tough luck, let's try to see if it has a website in his comment. - if name := getFromSite(sections[0].comment); name != "" { - // First of all, this is a bot. Moreover, since it doesn't have the - // Mozilla string, we can assume that the name and the version are - // the ones from the first section. - p.setSimple(sections[0].name, sections[0].version, true) - return - } - - // At this point we are sure that this is not a bot, but some weirdo. - p.setSimple(sections[0].name, sections[0].version, false) - } else { - // Let's iterate over the available comments and check for a website. - for _, v := range sections { - if name := getFromSite(v.comment); name != "" { - // Ok, we've got a bot name. - results := strings.SplitN(name, "/", 2) - version := "" - if len(results) == 2 { - version = results[1] - } - p.setSimple(results[0], version, true) - return - } - } - - // We will assume that this is some other weird browser. - p.fixOther(sections) - } -} |