cvs: php4 /ext/standard browscap.c
| From: | Jay Smith | Date: | Mon, 28 Apr 2003 21:49:47 +0000 |
| Subject: | cvs: php4 /ext/standard browscap.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-20566@lists.php.net to get a copy of this message | ||
jay Mon Apr 28 17:49:47 2003 EDT
Modified files:
/php4/ext/standard browscap.c
Log:
A few fixes Uwe suggested, plus plugged a memleak and a possible
overrun.
Index: php4/ext/standard/browscap.c
diff -u php4/ext/standard/browscap.c:1.70 php4/ext/standard/browscap.c:1.71
--- php4/ext/standard/browscap.c:1.70 Tue Mar 18 16:49:01 2003
+++ php4/ext/standard/browscap.c Mon Apr 28 17:49:47 2003
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: browscap.c,v 1.70 2003/03/18 21:49:01 jay Exp $ */
+/* $Id: browscap.c,v 1.71 2003/04/28 21:49:47 jay Exp $ */
#include "php.h"
#include "php_regex.h"
@@ -49,18 +49,7 @@
register int i, j;
char *t;
- for (i=0; i<Z_STRLEN_P(pattern); i++) {
- if (Z_STRVAL_P(pattern)[i]=='*' || Z_STRVAL_P(pattern)[i]=='?' ||
Z_STRVAL_P(pattern)[i]=='.') {
- break;
- }
- }
-
- if (i==Z_STRLEN_P(pattern)) { /* no wildcards */
- Z_STRVAL_P(pattern) = zend_strndup(Z_STRVAL_P(pattern), Z_STRLEN_P(pattern));
- return;
- }
-
- t = (char *) malloc(Z_STRLEN_P(pattern)*2 + 1);
+ t = (char *) malloc(Z_STRLEN_P(pattern)*2 + 3);
t[0] = '^';
for (i=0, j=1; i<Z_STRLEN_P(pattern); i++, j++) {
@@ -81,11 +70,12 @@
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 +102,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_ARRVAL_P(current_section), new_key, Z_STRLEN_P(arg1)+1, &new_property,
sizeof(zval *), NULL);
@@ -128,7 +118,6 @@
/*printf("'%s' (%d)\n",$1.value.str.val,$1.value.str.len+1);*/
current_section = (zval *) malloc(sizeof(zval));
INIT_PZVAL(current_section);
- array_init(current_section);
processed = (zval *) malloc(sizeof(zval));
INIT_PZVAL(processed);
unprocessed = (zval *) malloc(sizeof(zval));
@@ -225,8 +214,10 @@
}
/* }}} */
-/* {{{ proto object get_browser(string browser_name)
- Get information about the capabilities of a browser */
+/* {{{ proto mixed get_browser([string browser_name [, bool return_array]])
+ Get information about the capabilities of a browser. If browser_name is omitted
+ or null, HTTP_USER_AGENT is used. Returns an object by default; if return_array
+ is true, returns an array. */
PHP_FUNCTION(get_browser)
{
zval **agent_name = NULL, **agent, **retarr;
@@ -263,7 +254,7 @@
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) {
@@ -279,7 +270,7 @@
object_init(return_value);
zend_hash_copy(Z_OBJPROP_P(return_value), Z_ARRVAL_PP(agent), (copy_ctor_func_t) zval_add_ref,
(void *) &tmp_copy, sizeof(zval *));
}
-
+
while (zend_hash_find(Z_ARRVAL_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;