1999-04-17 08:37:12 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
1999-07-16 21:13:16 +08:00
|
|
|
| PHP version 4.0 |
|
1999-04-17 08:37:12 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2000-01-01 09:32:05 +08:00
|
|
|
| Copyright (c) 1997, 1998, 1999, 2000 The PHP Group |
|
1999-04-17 08:37:12 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2000-05-18 23:34:45 +08:00
|
|
|
| This source file is subject to version 2.02 of the PHP license, |
|
1999-07-16 21:13:16 +08:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
|
|
| available at through the world-wide-web at |
|
2000-05-18 23:34:45 +08:00
|
|
|
| http://www.php.net/license/2_02.txt. |
|
1999-07-16 21:13:16 +08:00
|
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@php.net so we can mail you a copy immediately. |
|
1999-04-17 08:37:12 +08:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Authors: Zeev Suraski <zeev@zend.com> |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "php.h"
|
2000-02-11 03:41:21 +08:00
|
|
|
#include "php_regex.h"
|
1999-12-05 03:19:57 +08:00
|
|
|
#include "php_browscap.h"
|
1999-04-17 08:37:12 +08:00
|
|
|
#include "php_ini.h"
|
|
|
|
|
|
|
|
#include "zend_globals.h"
|
|
|
|
|
|
|
|
HashTable browser_hash;
|
|
|
|
|
2000-07-23 19:32:18 +08:00
|
|
|
#define DEFAULT_SECTION_NAME "default browser capability settings"
|
2000-07-23 19:11:35 +08:00
|
|
|
|
|
|
|
static int browser_reg_compare(zval **browser,int num_args, va_list args, zend_hash_key *key)
|
1999-04-17 08:37:12 +08:00
|
|
|
{
|
2000-07-23 19:11:35 +08:00
|
|
|
zval *browser_name;
|
1999-04-17 08:37:12 +08:00
|
|
|
regex_t r;
|
2000-07-23 19:11:35 +08:00
|
|
|
char *lookup_browser_name = va_arg(args,char *);
|
|
|
|
zval **found_browser_entry = va_arg(args,zval **);
|
1999-04-17 08:37:12 +08:00
|
|
|
|
2000-07-23 19:11:35 +08:00
|
|
|
if (*found_browser_entry) { /* already found */
|
1999-04-17 08:37:12 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2000-07-23 19:32:18 +08:00
|
|
|
if(zend_hash_find((*browser)->value.obj.properties, "browser_name_pattern",sizeof("browser_name_pattern"),(void **) &browser_name) == FAILURE) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-04-17 08:37:12 +08:00
|
|
|
if (!strchr(browser_name->value.str.val,'*')) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (regcomp(&r,browser_name->value.str.val,REG_NOSUB)!=0) {
|
|
|
|
return 0;
|
|
|
|
}
|
1999-04-24 08:12:00 +08:00
|
|
|
if (regexec(&r,lookup_browser_name,0,NULL,0)==0) {
|
2000-07-23 19:11:35 +08:00
|
|
|
*found_browser_entry = *browser;
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
|
|
|
regfree(&r);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-06-24 03:55:49 +08:00
|
|
|
/* {{{ proto object get_browser(string browser_name)
|
|
|
|
Get information about the capabilities of a browser */
|
1999-05-16 19:19:26 +08:00
|
|
|
PHP_FUNCTION(get_browser)
|
1999-04-17 08:37:12 +08:00
|
|
|
{
|
2000-07-23 19:11:35 +08:00
|
|
|
zval **agent_name,**agent;
|
|
|
|
zval *found_browser_entry;
|
|
|
|
char *lookup_browser_name;
|
1999-04-17 08:37:12 +08:00
|
|
|
|
|
|
|
if (!INI_STR("browscap")) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2000-06-06 03:47:54 +08:00
|
|
|
switch(ZEND_NUM_ARGS()) {
|
1999-04-17 08:37:12 +08:00
|
|
|
case 0:
|
1999-08-03 03:17:14 +08:00
|
|
|
if (zend_hash_find(&EG(symbol_table), "HTTP_USER_AGENT", sizeof("HTTP_USER_AGENT"), (void **) &agent_name)==FAILURE) {
|
2000-07-23 19:11:35 +08:00
|
|
|
zend_error(E_WARNING,"HTTP_USER_AGENT variable is not set, cannot determine user agent name");
|
|
|
|
RETURN_FALSE;
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
1999-12-20 10:09:58 +08:00
|
|
|
if (zend_get_parameters_ex(1,&agent_name)==FAILURE) {
|
1999-04-17 08:37:12 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1999-12-20 10:09:58 +08:00
|
|
|
convert_to_string_ex(agent_name);
|
1999-04-17 08:37:12 +08:00
|
|
|
|
1999-12-20 10:09:58 +08:00
|
|
|
if (zend_hash_find(&browser_hash, (*agent_name)->value.str.val,(*agent_name)->value.str.len+1, (void **) &agent)==FAILURE) {
|
|
|
|
lookup_browser_name = (*agent_name)->value.str.val;
|
1999-04-24 08:12:00 +08:00
|
|
|
found_browser_entry = NULL;
|
2000-07-23 19:11:35 +08:00
|
|
|
zend_hash_apply_with_arguments(&browser_hash,(int (*)(void *, int, va_list, zend_hash_key *)) browser_reg_compare,2,lookup_browser_name,&found_browser_entry);
|
1999-04-17 08:37:12 +08:00
|
|
|
|
1999-04-24 08:12:00 +08:00
|
|
|
if (found_browser_entry) {
|
1999-12-20 10:09:58 +08:00
|
|
|
*agent = found_browser_entry;
|
2000-07-23 19:11:35 +08:00
|
|
|
} else if (zend_hash_find(&browser_hash, DEFAULT_SECTION_NAME, sizeof(DEFAULT_SECTION_NAME), (void **) &agent)==FAILURE) {
|
1999-04-17 08:37:12 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-12-20 10:09:58 +08:00
|
|
|
*return_value = **agent;
|
1999-04-17 08:37:12 +08:00
|
|
|
return_value->type = IS_OBJECT;
|
2000-07-23 19:11:35 +08:00
|
|
|
zval_copy_ctor(return_value);
|
2000-02-17 01:46:14 +08:00
|
|
|
return_value->value.obj.properties->pDestructor = ZVAL_DESTRUCTOR;
|
|
|
|
|
|
|
|
while (zend_hash_find((*agent)->value.obj.properties, "parent",sizeof("parent"), (void **) &agent_name)==SUCCESS) {
|
|
|
|
zval *tmp_copy;
|
1999-04-17 08:37:12 +08:00
|
|
|
|
1999-12-20 10:09:58 +08:00
|
|
|
if (zend_hash_find(&browser_hash,(*agent_name)->value.str.val, (*agent_name)->value.str.len+1, (void **)&agent)==FAILURE) {
|
1999-04-17 08:37:12 +08:00
|
|
|
break;
|
|
|
|
}
|
2000-07-23 19:11:35 +08:00
|
|
|
zend_hash_merge(return_value->value.obj.properties,(*agent)->value.obj.properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp_copy, sizeof(zval *), 0);
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
|
|
|
}
|
2000-03-29 19:38:47 +08:00
|
|
|
/* }}} */
|
1999-04-17 08:37:12 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* End:
|
|
|
|
*/
|