Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:1594 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 99755 invoked by uid 1007); 16 May 2003 17:57:49 -0000 Message-ID: <20030516175749.99753.qmail@pb1.pair.com> To: internals@lists.php.net Reply-To: jay@php.net Mail-Copies-To: jay@php.net Date: Fri, 16 May 2003 13:57:48 -0400 References: <5.2.0.9.0.20030516182813.0292e370@pop3.web.de> Lines: 85 User-Agent: KNode/0.7.2 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart17266299.q9hKKxFUij" Content-Transfer-Encoding: 7Bit X-Posted-By: 216.94.11.234 Subject: Re: [PHP-DEV] Re: [PHP-CVS] cvs: php4(PHP_4_3) / NEWS From: jay@php.net (Jay Smith) --nextPart17266299.q9hKKxFUij Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8Bit Since you're still doing some browscap stuff, feel like testing a patch? I noticed today that some of the browsers reported by get_browser() are still pretty inaccurate. (Mozilla for instance is especially bad -- I'm getting it reported as "Netscape 5", despite the fact that it's clearly Mozilla 1.2.1.) This patch (against HEAD) makes the browser_reg_compare() function a bit more thourough in it's search for a browser. It doesn't bail out on the first match it finds, for instance, as there are usually better matches further down in the browscap.ini file. I've run it against as many user agent strings as I could find, and it's reporting things much better now. (Recognizing Mozilla, properly reporting Win98 instead of WinME in certain cases, finding the .NET CLR, finally reporting SunOS instead of linux, etc.) It's slightly slower because of an extra hash lookup, but I think the slight slow down is worth the extra precision. I can incorporate any further fixes you have, if you'd like. J Uwe Schindler wrote: > I told that a few days before... You should replace in browscap.ini the > fopen by a zend_file_handle with type FD or FILENAME. I changed that and > have a replacement for browscap.ini but I cannot submit it due to > insufficient karma. > > In the patch is also fixed one bug in the regular expression generated. > > But Sasha should change the code, too. > --nextPart17266299.q9hKKxFUij Content-Type: text/x-diff; name="browscap.patch" Content-Transfer-Encoding: 8Bit Content-Disposition: attachment; filename="browscap.patch" Index: browscap.c =================================================================== RCS file: /repository/php4/ext/standard/browscap.c,v retrieving revision 1.73 diff -u -r1.73 browscap.c --- browscap.c 16 May 2003 15:13:47 -0000 1.73 +++ browscap.c 16 May 2003 17:55:34 -0000 @@ -186,19 +186,29 @@ */ static int browser_reg_compare(zval **browser, int num_args, va_list args, zend_hash_key *key) { - zval **browser_name; + zval **browser_name, **current; regex_t r; char *lookup_browser_name = va_arg(args, char *); zval **found_browser_entry = va_arg(args, zval **); - if (*found_browser_entry) { /* already found */ - return 0; - } if (zend_hash_find(Z_ARRVAL_PP(browser), "browser_name_regex", sizeof("browser_name_regex"), (void **) &browser_name) == FAILURE) { return 0; } - if (Z_STRVAL_PP(browser_name)[0] != '^') { - return 0; + + if (*found_browser_entry) { + /* We've already found it, so don't compare to the default browser, + because it will match anything. */ + if (!strcmp(Z_STRVAL_PP(browser_name), "^.*$")) { + return 0; + } + /* If we've found a possible browser, check it's length. Longer user + agent strings are assumed to be more precise, so use them. */ + else if (zend_hash_find(Z_ARRVAL_PP(found_browser_entry), "browser_name_regex", sizeof("browser_name_regex"), (void**) ¤t) == FAILURE) { + return 0; + } + else if (Z_STRLEN_PP(current) > Z_STRLEN_PP(browser_name)) { + return 0; + } } if (regcomp(&r, Z_STRVAL_PP(browser_name), REG_NOSUB)!=0) { return 0; --nextPart17266299.q9hKKxFUij--