public void computeUserAgent()

in core/src/main/java/com/alibaba/druid/support/http/stat/WebAppStat.java [524:802]


    public void computeUserAgent(String userAgent) {
        if (userAgent == null || userAgent.length() == 0) {
            return;
        }

        // Mozilla/5.0 (compatible;
        final int MOZILLA_COMPATIBLE_OFFSET = 25;

        boolean is360SE = userAgent.endsWith("360SE)");

        if (is360SE) {
            browser360SECount.incrementAndGet();
        }

        boolean isIE = userAgent.startsWith("MSIE", MOZILLA_COMPATIBLE_OFFSET);
        int iePrefixIndex = 30; // "Mozilla/5.0 (compatible; MSIE ".length();

        boolean isGoogleToolbar = false;

        if (!isIE) {
            isGoogleToolbar = userAgent.startsWith("GoogleToolbar", MOZILLA_COMPATIBLE_OFFSET);
            if (isGoogleToolbar) {
                // MSIE
                int tmp = userAgent.indexOf("IE ");
                if (tmp != -1) {
                    isIE = true;
                    iePrefixIndex = tmp + 3;
                }
            }
        }

        if (isIE) {
            browserIECount.incrementAndGet();

            char v1 = ' ', v2 = ' ';
            if (userAgent.length() > iePrefixIndex + 1) {
                v1 = userAgent.charAt(iePrefixIndex);
                v2 = userAgent.charAt(iePrefixIndex + 1);
            } else if (userAgent.length() > iePrefixIndex) {
                v1 = userAgent.charAt(iePrefixIndex);
            }

            switch (v1) {
                case '5':
                    browserIE5Count.incrementAndGet();
                    break;
                case '6':
                    browserIE6Count.incrementAndGet();
                    break;
                case '7':
                    browserIE7Count.incrementAndGet();
                    break;
                case '8':
                    browserIE8Count.incrementAndGet();
                    break;
                case '9':
                    browserIE9Count.incrementAndGet();
                    break;
                case '1':
                    if (v2 == '0') {
                        browserIE10Count.incrementAndGet();
                    }
                    break;
                default:
                    break;
            }

            osWindowsCount.incrementAndGet();

            computeUserAgentIEWindowsVersion(userAgent);

            if (userAgent.contains("Windows Phone")) {
                deviceWindowsPhoneCount.incrementAndGet();
            }

            return;
        }

        boolean isWindows = false;
        boolean isMac = false;
        boolean isIpad = false;
        boolean isIPhone = false;
        boolean isLinux = false;
        boolean isX11 = false;
        boolean isBSD = false;

        if (userAgent.startsWith("Windows", 13)) {
            isWindows = true;
        } else if (userAgent.startsWith("Macintosh", 13)) {
            isMac = true;
        } else if (userAgent.startsWith("iPad", 13)) {
            isIpad = true;
            isMac = true;
        } else if (userAgent.startsWith("iPhone", 13)) {
            isIPhone = true;
            isMac = true;
        } else if (userAgent.startsWith("Linux", 13)) {
            isLinux = true;
        } else if (userAgent.startsWith("X11", 13)) {
            isX11 = true;
        }

        boolean isAndroid = false;

        if (isWindows) {
            isWindows = true;

            osWindowsCount.incrementAndGet();

            if (userAgent.contains("Windows Phone")) {
                deviceWindowsPhoneCount.incrementAndGet();
            }
        } else if (isMac) {
            isMac = true;
            osMacOSXCount.incrementAndGet();
            if (isIpad && userAgent.contains("iPad")) {
                deviceIpadCount.incrementAndGet();
            } else if (isIPhone || userAgent.contains("iPhone")) {
                deviceIphoneCount.incrementAndGet();
            }
        } else if (isLinux) {
            osLinuxCount.incrementAndGet();
            isAndroid = computeUserAgentAndroid(userAgent);
        } else if (userAgent.contains("Symbian")) {
            osSymbianCount.incrementAndGet();
        } else if (userAgent.contains("Ubuntu")) {
            osLinuxCount.incrementAndGet();
            osLinuxUbuntuCount.incrementAndGet();
            isLinux = true;
        }

        if (isX11) {
            if (userAgent.contains("OpenBSD")) {
                osOpenBSDCount.incrementAndGet();
                isBSD = true;
            } else if (userAgent.contains("FreeBSD")) {
                osFreeBSDCount.incrementAndGet();
                isBSD = true;
            } else if ((!isLinux) && userAgent.contains("Linux")) {
                osLinuxCount.incrementAndGet();
                isLinux = true;
            }
        }

        boolean isOpera = userAgent.startsWith("Opera");

        if (isOpera) {
            if (userAgent.contains("Windows")) {
                osWindowsCount.incrementAndGet();
            } else if (userAgent.contains("Linux")) {
                osWindowsCount.incrementAndGet();
            } else if (userAgent.contains("Macintosh")) {
                osMacOSXCount.incrementAndGet();
            }
            browserOperaCount.incrementAndGet();
            return;
        }

        if (isWindows) {
            computeUserAgentFirefoxWindowsVersion(userAgent);
        }

        if (isWindows || isMac || isLinux || isBSD) {
            if (userAgent.contains("Chrome")) {
                browserChromeCount.incrementAndGet();
                return;
            }

            if ((!isAndroid) && userAgent.contains("Safari")) {
                browserSafariCount.incrementAndGet();
                return;
            }

            if (userAgent.contains("Firefox")) {
                browserFirefoxCount.incrementAndGet();
                return;
            }
        }

        if (userAgent.startsWith("User-Agent: ")) {
            String rest = userAgent.substring("User-Agent: ".length());
            computeUserAgent(rest);
        }

        boolean isJava = userAgent.startsWith("Java");

        if (isJava) {
            botCount.incrementAndGet();
        }

        if (userAgent.startsWith("msnbot")) {
            botCount.incrementAndGet();
            botMsnCount.incrementAndGet();
        } else if (userAgent.startsWith("Sosospider+")) {
            botCount.incrementAndGet();
            botSosoCount.incrementAndGet();
        } else if (userAgent.startsWith("Sogou")) {
            botCount.incrementAndGet();
            botSogouCount.incrementAndGet();
        } else if (userAgent.startsWith("HuaweiSymantecSpider")) {
            botCount.incrementAndGet();
        } else if (userAgent.startsWith("Yeti/")) {
            botCount.incrementAndGet();
        } else if (userAgent.startsWith("mahonie")) {
            botCount.incrementAndGet();
        } else if (userAgent.startsWith("findlinks")) {
            botCount.incrementAndGet();
        } else if (userAgent.startsWith("Updownerbot")) {
            botCount.incrementAndGet();
        } else if (userAgent.startsWith("DoCoMo/")) {
            botCount.incrementAndGet();
        } else if (userAgent.startsWith("Crawl")) {
            botCount.incrementAndGet();
        } else if (userAgent.startsWith("SkimBot")) {
            botCount.incrementAndGet();

        } else if (userAgent.startsWith("YoudaoBot", MOZILLA_COMPATIBLE_OFFSET)) {
            botCount.incrementAndGet();
            botYoudaoCount.incrementAndGet();
        } else if (userAgent.startsWith("bingbot", MOZILLA_COMPATIBLE_OFFSET)) {
            botCount.incrementAndGet();
            botBingCount.incrementAndGet();
        } else if (userAgent.startsWith("Googlebot", MOZILLA_COMPATIBLE_OFFSET)) {
            botCount.incrementAndGet();
            botGoogleCount.incrementAndGet();
        } else if (userAgent.startsWith("Baiduspider", MOZILLA_COMPATIBLE_OFFSET)) {
            botCount.incrementAndGet();
            botBaiduCount.incrementAndGet();
        } else if (userAgent.startsWith("MJ12bot", MOZILLA_COMPATIBLE_OFFSET)) {
            botCount.incrementAndGet();
            botBaiduCount.incrementAndGet();
        } else if (userAgent.startsWith("Mail.RU/", MOZILLA_COMPATIBLE_OFFSET)) {
            botCount.incrementAndGet();
        } else if (userAgent.startsWith("Yahoo!", MOZILLA_COMPATIBLE_OFFSET)) {
            botCount.incrementAndGet();
            botYahooCount.incrementAndGet();
        } else if (userAgent.startsWith("KaloogaBot", MOZILLA_COMPATIBLE_OFFSET)) {
            botCount.incrementAndGet();
        } else if (userAgent.startsWith("YandexBot", MOZILLA_COMPATIBLE_OFFSET)) {
            botCount.incrementAndGet();
        } else if (userAgent.startsWith("Ezooms/", MOZILLA_COMPATIBLE_OFFSET)) {
            botCount.incrementAndGet();
        } else if (userAgent.startsWith("Exabot/", MOZILLA_COMPATIBLE_OFFSET)) {
            botCount.incrementAndGet();
        } else if (userAgent.startsWith("AhrefsBot/", MOZILLA_COMPATIBLE_OFFSET)) {
            botCount.incrementAndGet();
        } else if (userAgent.startsWith("YodaoBot/", MOZILLA_COMPATIBLE_OFFSET)) {
            botCount.incrementAndGet();
        } else if (userAgent.startsWith("BeetleBot", MOZILLA_COMPATIBLE_OFFSET)) {
            botCount.incrementAndGet();
        } else if (userAgent.startsWith("archive.org_bot", MOZILLA_COMPATIBLE_OFFSET)) {
            botCount.incrementAndGet();
        } else if (userAgent.startsWith("aiHitBot", MOZILLA_COMPATIBLE_OFFSET)) {
            botCount.incrementAndGet();
        } else if (userAgent.startsWith("EventGuruBot", MOZILLA_COMPATIBLE_OFFSET)) {
            botCount.incrementAndGet();

        } else if (userAgent.equals("Mozilla/5.0 ()")) {
            botCount.incrementAndGet();
        } else if (userAgent.equals("\"Mozilla/5.0")) {
            botCount.incrementAndGet();
        } else if (userAgent.equals("Mozilla")) {
            botCount.incrementAndGet();
        } else if (userAgent.equals("-")) {
            botCount.incrementAndGet();
        } else if (userAgent.contains("Spider") || userAgent.contains("spider")) {
            botCount.incrementAndGet();
        } else if (userAgent.contains("crawl") || userAgent.contains("Crawl")) {
            botCount.incrementAndGet();
        } else if (userAgent.contains("Bot") || userAgent.contains("bot")) {
            botCount.incrementAndGet();
        }

        // Mozilla/5.0 ()
        // Mozilla/5.0 (compatible; Mail.RU/2.0)
        // Mozilla/5.0 (compatible; bingbot/2.0;
        // YoudaoBot

    }