Re: browscap.ini module error + fix
| From: | Uwe Schindler | Date: | Sun, 27 Apr 2003 11:39:33 +0000 |
| Subject: | Re: browscap.ini module error + fix | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-1051@lists.php.net to get a copy of this message | ||
Was only to look through the code. But the patch is here (PHP4.3 version).
Uwe
At 12:12 27.04.2003 +0100, Wez Furlong wrote:
>On Sun, 27 Apr 2003, Uwe Schindler wrote:
>
> > So I modified the browscap.c file that it adds a ^ at the beginning of
> > regex and a $ at the end of regex. After that all browsers are detected
> > exactly like in ASP. Browsers with errors are: IE, Konqueror, some
> spiders...
> >
> > The modification looks like that:
> > >/* {{{ convert_browscap_pattern
> > > */
>[snip]
>
> > If you also think thats right can you give my thetaphi@php.net CVS account
> > write access to ext/standard, i will then submit the modifications?
>
>Lets have a unified diff first? (see README.SUBMITTING_PATCH).
>
>--Wez.
Index: ext/standard/browscap.c =================================================================== RCS file: /repository/php4/ext/standard/browscap.c,v retrieving revision 1.60.2.6 diff -u -r1.60.2.6 browscap.c --- ext/standard/browscap.c 6 Jan 2003 21:43:50 -0000 1.60.2.6 +++ ext/standard/browscap.c 27 Apr 2003 11:37:48 -0000 @@ -60,9 +60,10 @@ return; } - t = (char *) malloc(Z_STRLEN_P(pattern)*2 + 1); - - for (i=0, j=0; i<Z_STRLEN_P(pattern); i++, j++) { + t = (char *) malloc(Z_STRLEN_P(pattern)*2 + 3); + t[0]='^'; + + for (i=0, j=1; i<Z_STRLEN_P(pattern); i++, j++) { switch (Z_STRVAL_P(pattern)[i]) { case '?': t[j] = '.'; @@ -80,11 +81,13 @@ break; } } - + if (j && (t[j-1] == '.')) { t[j++] = '*'; } - + + t[j++]='$'; + t[j]=0; Z_STRVAL_P(pattern) = t; Z_STRLEN_P(pattern) = j; @@ -112,7 +115,7 @@ Z_STRVAL_P(new_property) = Z_STRLEN_P(arg2)?zend_strndup(Z_STRVAL_P(arg2), Z_STRLEN_P(arg2)):""; Z_STRLEN_P(new_property) = Z_STRLEN_P(arg2); Z_TYPE_P(new_property) = IS_STRING; - + new_key = zend_strndup(Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)); zend_str_tolower(new_key, Z_STRLEN_P(arg1)); zend_hash_update(Z_OBJPROP_P(current_section), new_key, Z_STRLEN_P(arg1)+1, &new_property, sizeof(zval *), NULL); @@ -132,9 +135,9 @@ section_properties = (HashTable *) malloc(sizeof(HashTable)); _object_and_properties_init(current_section, ZEND_STANDARD_CLASS_DEF_PTR, section_properties ZEND_FILE_LINE_CC TSRMLS_CC); - + zend_hash_init(section_properties, 0, NULL, (dtor_func_t) browscap_entry_dtor, 1); - zend_hash_update(&browser_hash, Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)+1, (void *) ¤t_section, sizeof(zval *), NULL); + zend_hash_update(&browser_hash, Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)+1, (void *) ¤t_section, sizeof(zval *), NULL); Z_STRVAL_P(processed) = Z_STRVAL_P(arg1); Z_STRLEN_P(processed) = Z_STRLEN_P(arg1); @@ -225,7 +228,7 @@ php_error_docref(NULL TSRMLS_CC, E_WARNING, "browscap ini directive not set."); RETURN_FALSE; } - + switch(ZEND_NUM_ARGS()) { case 0: if (!PG(http_globals)[TRACK_VARS_SERVER] @@ -243,30 +246,30 @@ WRONG_PARAM_COUNT; break; } - + convert_to_string_ex(agent_name); if (zend_hash_find(&browser_hash, Z_STRVAL_PP(agent_name), Z_STRLEN_PP(agent_name)+1, (void **) &agent)==FAILURE) { lookup_browser_name = Z_STRVAL_PP(agent_name); found_browser_entry = NULL; zend_hash_apply_with_arguments(&browser_hash, (apply_func_args_t) browser_reg_compare, 2, lookup_browser_name, &found_browser_entry); - + if (found_browser_entry) { agent = &found_browser_entry; } else if (zend_hash_find(&browser_hash, DEFAULT_SECTION_NAME, sizeof(DEFAULT_SECTION_NAME), (void **) &agent)==FAILURE) { RETURN_FALSE; } } - + object_init(return_value); zend_hash_copy(Z_OBJPROP_P(return_value), Z_OBJPROP_PP(agent), (copy_ctor_func_t) zval_add_ref, (void *) &tmp_copy, sizeof(zval *)); - + while (zend_hash_find(Z_OBJPROP_PP(agent), "parent", sizeof("parent"), (void **) &agent_name)==SUCCESS) { if (zend_hash_find(&browser_hash, Z_STRVAL_PP(agent_name), Z_STRLEN_PP(agent_name)+1, (void **)&agent)==FAILURE) { break; } - + zend_hash_merge(Z_OBJPROP_P(return_value), Z_OBJPROP_PP(agent), (copy_ctor_func_t) zval_add_ref, (void *) &tmp_copy, sizeof(zval *), 0); } }
Index: ext/standard/browscap.c =================================================================== RCS file: /repository/php4/ext/standard/browscap.c,v retrieving revision 1.60.2.6 diff -u -r1.60.2.6 browscap.c --- ext/standard/browscap.c 6 Jan 2003 21:43:50 -0000 1.60.2.6 +++ ext/standard/browscap.c 27 Apr 2003 11:37:48 -0000 @@ -60,9 +60,10 @@ return; } - t = (char *) malloc(Z_STRLEN_P(pattern)*2 + 1); - - for (i=0, j=0; i<Z_STRLEN_P(pattern); i++, j++) { + t = (char *) malloc(Z_STRLEN_P(pattern)*2 + 3); + t[0]='^'; + + for (i=0, j=1; i<Z_STRLEN_P(pattern); i++, j++) { switch (Z_STRVAL_P(pattern)[i]) { case '?': t[j] = '.'; @@ -80,11 +81,13 @@ break; } } - + if (j && (t[j-1] == '.')) { t[j++] = '*'; } - + + t[j++]='$'; + t[j]=0; Z_STRVAL_P(pattern) = t; Z_STRLEN_P(pattern) = j; @@ -112,7 +115,7 @@ Z_STRVAL_P(new_property) = Z_STRLEN_P(arg2)?zend_strndup(Z_STRVAL_P(arg2), Z_STRLEN_P(arg2)):""; Z_STRLEN_P(new_property) = Z_STRLEN_P(arg2); Z_TYPE_P(new_property) = IS_STRING; - + new_key = zend_strndup(Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)); zend_str_tolower(new_key, Z_STRLEN_P(arg1)); zend_hash_update(Z_OBJPROP_P(current_section), new_key, Z_STRLEN_P(arg1)+1, &new_property, sizeof(zval *), NULL); @@ -132,9 +135,9 @@ section_properties = (HashTable *) malloc(sizeof(HashTable)); _object_and_properties_init(current_section, ZEND_STANDARD_CLASS_DEF_PTR, section_properties ZEND_FILE_LINE_CC TSRMLS_CC); - + zend_hash_init(section_properties, 0, NULL, (dtor_func_t) browscap_entry_dtor, 1); - zend_hash_update(&browser_hash, Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)+1, (void *) ¤t_section, sizeof(zval *), NULL); + zend_hash_update(&browser_hash, Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)+1, (void *) ¤t_section, sizeof(zval *), NULL); Z_STRVAL_P(processed) = Z_STRVAL_P(arg1); Z_STRLEN_P(processed) = Z_STRLEN_P(arg1); @@ -225,7 +228,7 @@ php_error_docref(NULL TSRMLS_CC, E_WARNING, "browscap ini directive not set."); RETURN_FALSE; } - + switch(ZEND_NUM_ARGS()) { case 0: if (!PG(http_globals)[TRACK_VARS_SERVER] @@ -243,30 +246,30 @@ WRONG_PARAM_COUNT; break; } - + convert_to_string_ex(agent_name); if (zend_hash_find(&browser_hash, Z_STRVAL_PP(agent_name), Z_STRLEN_PP(agent_name)+1, (void **) &agent)==FAILURE) { lookup_browser_name = Z_STRVAL_PP(agent_name); found_browser_entry = NULL; zend_hash_apply_with_arguments(&browser_hash, (apply_func_args_t) browser_reg_compare, 2, lookup_browser_name, &found_browser_entry); - + if (found_browser_entry) { agent = &found_browser_entry; } else if (zend_hash_find(&browser_hash, DEFAULT_SECTION_NAME, sizeof(DEFAULT_SECTION_NAME), (void **) &agent)==FAILURE) { RETURN_FALSE; } } - + object_init(return_value); zend_hash_copy(Z_OBJPROP_P(return_value), Z_OBJPROP_PP(agent), (copy_ctor_func_t) zval_add_ref, (void *) &tmp_copy, sizeof(zval *)); - + while (zend_hash_find(Z_OBJPROP_PP(agent), "parent", sizeof("parent"), (void **) &agent_name)==SUCCESS) { if (zend_hash_find(&browser_hash, Z_STRVAL_PP(agent_name), Z_STRLEN_PP(agent_name)+1, (void **)&agent)==FAILURE) { break; } - + zend_hash_merge(Z_OBJPROP_P(return_value), Z_OBJPROP_PP(agent), (copy_ctor_func_t) zval_add_ref, (void *) &tmp_copy, sizeof(zval *), 0); } }