PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/standard - browscap.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 176 228 77.2 %
Date: 2014-11-22 Functions: 12 13 92.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 7                                                        |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1997-2014 The PHP Group                                |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 3.01 of the PHP license,      |
       8             :    | that is bundled with this package in the file LICENSE, and is        |
       9             :    | available through the world-wide-web at the following url:           |
      10             :    | http://www.php.net/license/3_01.txt                                  |
      11             :    | If you did not receive a copy of the PHP license and are unable to   |
      12             :    | obtain it through the world-wide-web, please send a note to          |
      13             :    | license@php.net so we can mail you a copy immediately.               |
      14             :    +----------------------------------------------------------------------+
      15             :    | Author: Zeev Suraski <zeev@zend.com>                                 |
      16             :    +----------------------------------------------------------------------+
      17             :  */
      18             : 
      19             : /* $Id$ */
      20             : 
      21             : #include "php.h"
      22             : #include "php_browscap.h"
      23             : #include "php_ini.h"
      24             : #include "php_string.h"
      25             : #include "ext/pcre/php_pcre.h"
      26             : 
      27             : #include "zend_ini_scanner.h"
      28             : #include "zend_globals.h"
      29             : 
      30             : typedef struct {
      31             :         HashTable *htab;
      32             :         zval current_section;
      33             :         char *current_section_name;
      34             :         char filename[MAXPATHLEN];
      35             : } browser_data;
      36             : 
      37             : /* browser data defined in startup phase, eagerly loaded in MINIT */
      38             : static browser_data global_bdata = {0};
      39             : 
      40             : /* browser data defined in activation phase, lazily loaded in get_browser.
      41             :  * Per request and per thread, if applicable */
      42             : ZEND_BEGIN_MODULE_GLOBALS(browscap)
      43             :         browser_data activation_bdata;
      44             : ZEND_END_MODULE_GLOBALS(browscap)
      45             : 
      46             : ZEND_DECLARE_MODULE_GLOBALS(browscap)
      47             : 
      48             : #ifdef ZTS
      49             : #define BROWSCAP_G(v)   TSRMG(browscap_globals_id, zend_browscap_globals *, v)
      50             : #else
      51             : #define BROWSCAP_G(v)   (browscap_globals.v)
      52             : #endif
      53             : 
      54             : #define DEFAULT_SECTION_NAME "Default Browser Capability Settings"
      55             : 
      56             : /* OBJECTS_FIXME: This whole extension needs going through. The use of objects looks pretty broken here */
      57             : 
      58           0 : static void browscap_entry_dtor_request(zval *zvalue) /* {{{ */
      59             : {
      60           0 :         if (Z_TYPE_P(zvalue) == IS_ARRAY) {
      61           0 :                 zend_hash_destroy(Z_ARRVAL_P(zvalue));
      62           0 :                 efree(Z_ARR_P(zvalue));
      63           0 :         } else if (Z_TYPE_P(zvalue) == IS_STRING) {
      64           0 :                 zend_string_release(Z_STR_P(zvalue));
      65             :         }
      66           0 : }
      67             : /* }}} */
      68             : 
      69      119548 : static void browscap_entry_dtor_persistent(zval *zvalue) /* {{{ */ {
      70      119548 :         if (Z_TYPE_P(zvalue) == IS_ARRAY) {
      71       19188 :                 zend_hash_destroy(Z_ARRVAL_P(zvalue));
      72       19188 :                 free(Z_ARR_P(zvalue));
      73      100360 :         } else if (Z_TYPE_P(zvalue) == IS_STRING) {
      74      100360 :                 zend_string_release(Z_STR_P(zvalue));
      75             :         }
      76      119548 : }
      77             : /* }}} */
      78             : 
      79       19188 : static void convert_browscap_pattern(zval *pattern, int persistent) /* {{{ */
      80             : {
      81       19188 :         int i, j=0;
      82             :         char *t;
      83             :         zend_string *res;
      84             :         char *lc_pattern;
      85             : 
      86       38376 :         res = zend_string_safe_alloc(Z_STRLEN_P(pattern), 2, 4, persistent);
      87       19188 :         t = res->val;
      88             : 
      89       19188 :         lc_pattern = zend_str_tolower_dup(Z_STRVAL_P(pattern), Z_STRLEN_P(pattern));
      90             : 
      91       19188 :         t[j++] = '\xA7'; /* section sign */
      92       19188 :         t[j++] = '^';
      93             : 
      94      695178 :         for (i=0; i<Z_STRLEN_P(pattern); i++, j++) {
      95      675990 :                 switch (lc_pattern[i]) {
      96             :                         case '?':
      97        5352 :                                 t[j] = '.';
      98        5352 :                                 break;
      99             :                         case '*':
     100       41568 :                                 t[j++] = '.';
     101       41568 :                                 t[j] = '*';
     102       41568 :                                 break;
     103             :                         case '.':
     104       29280 :                                 t[j++] = '\\';
     105       29280 :                                 t[j] = '.';
     106       29280 :                                 break;
     107             :                         case '\\':
     108          78 :                                 t[j++] = '\\';
     109          78 :                                 t[j] = '\\';
     110          78 :                                 break;
     111             :                         case '(':
     112       12852 :                                 t[j++] = '\\';
     113       12852 :                                 t[j] = '(';
     114       12852 :                                 break;
     115             :                         case ')':
     116       12696 :                                 t[j++] = '\\';
     117       12696 :                                 t[j] = ')';
     118       12696 :                                 break;
     119             :                         case '\xA7':
     120           0 :                                 t[j++] = '\\';
     121           0 :                                 t[j] = '\xA7';
     122           0 :                                 break;
     123             :                         default:
     124      574164 :                                 t[j] = lc_pattern[i];
     125             :                                 break;
     126             :                 }
     127             :         }
     128             : 
     129       19188 :         t[j++] = '$';
     130       19188 :         t[j++] = '\xA7';
     131             : 
     132       19188 :         t[j]=0;
     133       19188 :         res->len = j;
     134       19188 :         Z_STR_P(pattern) = res;
     135       19188 :         efree(lc_pattern);
     136       19188 : }
     137             : /* }}} */
     138             : 
     139       79782 : static void php_browscap_parser_cb(zval *arg1, zval *arg2, zval *arg3, int callback_type, void *arg TSRMLS_DC) /* {{{ */
     140             : {
     141       79782 :         browser_data *bdata = arg;
     142       79782 :         int persistent = bdata->htab->u.flags & HASH_FLAG_PERSISTENT;
     143             :         
     144       79782 :         if (!arg1) {
     145           0 :                 return;
     146             :         }
     147             : 
     148       79782 :         switch (callback_type) {
     149             :                 case ZEND_INI_PARSER_ENTRY:
     150      121188 :                         if (Z_TYPE(bdata->current_section) != IS_UNDEF && arg2) {
     151             :                                 zval new_property;
     152             :                                 zend_string *new_key;
     153             : 
     154             :                                 /* parent entry can not be same as current section -> causes infinite loop! */
     155       98934 :                                 if (!strcasecmp(Z_STRVAL_P(arg1), "parent") && 
     156       19170 :                                         bdata->current_section_name != NULL &&
     157       19170 :                                         !strcasecmp(bdata->current_section_name, Z_STRVAL_P(arg2))
     158             :                                 ) {
     159           0 :                                         zend_error(E_CORE_ERROR, "Invalid browscap ini file: "
     160             :                                                 "'Parent' value cannot be same as the section name: %s "
     161             :                                                 "(in file %s)", bdata->current_section_name, INI_STR("browscap"));
     162           0 :                                         return;
     163             :                                 }
     164             : 
     165             :                                 /* Set proper value for true/false settings */
     166      214026 :                                 if ((Z_STRLEN_P(arg2) == 2 && !strncasecmp(Z_STRVAL_P(arg2), "on", sizeof("on") - 1)) ||
     167       62982 :                                         (Z_STRLEN_P(arg2) == 3 && !strncasecmp(Z_STRVAL_P(arg2), "yes", sizeof("yes") - 1)) ||
     168       76092 :                                         (Z_STRLEN_P(arg2) == 4 && !strncasecmp(Z_STRVAL_P(arg2), "true", sizeof("true") - 1))
     169             :                                 ) {
     170       28716 :                                         ZVAL_NEW_STR(&new_property, zend_string_init("1", sizeof("1")-1, persistent));
     171      196962 :                                 } else if (
     172       47040 :                                         (Z_STRLEN_P(arg2) == 2 && !strncasecmp(Z_STRVAL_P(arg2), "no", sizeof("no") - 1)) ||
     173       48624 :                                         (Z_STRLEN_P(arg2) == 3 && !strncasecmp(Z_STRVAL_P(arg2), "off", sizeof("off") - 1)) ||
     174       47376 :                                         (Z_STRLEN_P(arg2) == 4 && !strncasecmp(Z_STRVAL_P(arg2), "none", sizeof("none") - 1)) ||
     175       53496 :                                         (Z_STRLEN_P(arg2) == 5 && !strncasecmp(Z_STRVAL_P(arg2), "false", sizeof("false") - 1))
     176             :                                 ) {
     177             :                                         // TODO: USE STR_EMPTY_ALLOC()?
     178         852 :                                         ZVAL_NEW_STR(&new_property, zend_string_init("", sizeof("")-1, persistent));
     179             :                                 } else { /* Other than true/false setting */
     180       91620 :                                         ZVAL_STR(&new_property, zend_string_dup(Z_STR_P(arg2), persistent));
     181             :                                 }
     182      121188 :                                 new_key = zend_string_dup(Z_STR_P(arg1), persistent);
     183       60594 :                                 zend_str_tolower(new_key->val, new_key->len);
     184       60594 :                                 zend_hash_update(Z_ARRVAL(bdata->current_section), new_key, &new_property);
     185             :                                 zend_string_release(new_key);
     186             :                         }
     187       60594 :                         break;
     188             :                 case ZEND_INI_PARSER_SECTION: {
     189             :                                 zval processed;
     190             :                                 zval unprocessed;
     191             : 
     192             :                                 /*printf("'%s' (%d)\n",$1.value.str.val,$1.value.str.len + 1);*/
     193       19188 :                                 if (persistent) {
     194       19188 :                                         ZVAL_NEW_PERSISTENT_ARR(&bdata->current_section);
     195             :                                 } else {
     196           0 :                                         ZVAL_NEW_ARR(&bdata->current_section);
     197             :                                 }
     198       19188 :                                 zend_hash_init(Z_ARRVAL(bdata->current_section), 0, NULL,
     199             :                                                 (dtor_func_t) (persistent?browscap_entry_dtor_persistent
     200             :                                                                                                  :browscap_entry_dtor_request),
     201             :                                                 persistent);
     202       19188 :                                 if (bdata->current_section_name) {
     203       19182 :                                         pefree(bdata->current_section_name, persistent);
     204             :                                 }
     205       19188 :                                 bdata->current_section_name = pestrndup(Z_STRVAL_P(arg1),
     206             :                                                 Z_STRLEN_P(arg1), persistent);
     207             : 
     208       19188 :                                 zend_hash_update(bdata->htab, Z_STR_P(arg1), &bdata->current_section);
     209             : 
     210       19188 :                                 ZVAL_STR(&processed, Z_STR_P(arg1));
     211       38376 :                                 ZVAL_STR(&unprocessed, zend_string_dup(Z_STR_P(arg1), persistent));
     212             : 
     213       19188 :                                 convert_browscap_pattern(&processed, persistent);
     214       19188 :                                 zend_hash_str_update(Z_ARRVAL(bdata->current_section), "browser_name_regex", sizeof("browser_name_regex")-1, &processed);
     215       19188 :                                 zend_hash_str_update(Z_ARRVAL(bdata->current_section), "browser_name_pattern", sizeof("browser_name_pattern")-1, &unprocessed);
     216             :                         }
     217             :                         break;
     218             :         }
     219             : }
     220             : /* }}} */
     221             : 
     222           6 : static int browscap_read_file(char *filename, browser_data *browdata, int persistent TSRMLS_DC) /* {{{ */
     223             : {
     224           6 :         zend_file_handle fh = {{0}};
     225             :         
     226           6 :         if (filename == NULL || filename[0] == '\0') {
     227           0 :                 return FAILURE;
     228             :         }
     229             :         
     230          12 :         browdata->htab = pemalloc(sizeof *browdata->htab, persistent);
     231           6 :         if (browdata->htab == NULL) {
     232           0 :                 return FAILURE;
     233             :         }
     234             : 
     235           6 :         zend_hash_init_ex(browdata->htab, 0, NULL,
     236             :                         (dtor_func_t) (persistent?browscap_entry_dtor_persistent
     237             :                                                                          :browscap_entry_dtor_request),
     238             :                         persistent, 0);
     239             : 
     240           6 :         fh.handle.fp = VCWD_FOPEN(filename, "r");
     241           6 :         fh.opened_path = NULL;
     242           6 :         fh.free_filename = 0;
     243           6 :         if (!fh.handle.fp) {
     244           0 :                 zend_hash_destroy(browdata->htab);
     245           0 :                 pefree(browdata->htab, persistent);
     246           0 :                 browdata->htab = NULL;
     247           0 :                 zend_error(E_CORE_WARNING, "Cannot open '%s' for reading", filename);
     248           0 :                 return FAILURE;
     249             :         }
     250           6 :         fh.filename = filename;
     251           6 :         fh.type = ZEND_HANDLE_FP;
     252           6 :         browdata->current_section_name = NULL;
     253           6 :         zend_parse_ini_file(&fh, 1, ZEND_INI_SCANNER_RAW,
     254             :                         (zend_ini_parser_cb_t) php_browscap_parser_cb, browdata TSRMLS_CC);
     255           6 :         if (browdata->current_section_name != NULL) {
     256           6 :                 pefree(browdata->current_section_name, persistent);
     257           6 :                 browdata->current_section_name = NULL;
     258             :         }
     259             :         
     260           6 :         return SUCCESS;
     261             : }
     262             : /* }}} */
     263             : 
     264             : #ifdef ZTS
     265             : static void browscap_globals_ctor(zend_browscap_globals *browscap_globals TSRMLS_DC) /* {{{ */
     266             : {
     267             :         browscap_globals->activation_bdata.htab = NULL;
     268             :         ZVAL_UNDEF(&browscap_globals->activation_bdata.current_section);
     269             :         browscap_globals->activation_bdata.current_section_name = NULL;
     270             :         browscap_globals->activation_bdata.filename[0] = '\0';
     271             : }
     272             : /* }}} */
     273             : #endif
     274             : 
     275       20541 : static void browscap_bdata_dtor(browser_data *bdata, int persistent TSRMLS_DC) /* {{{ */
     276             : {
     277       20541 :         if (bdata->htab != NULL) {
     278           6 :                 zend_hash_destroy(bdata->htab);
     279           6 :                 pefree(bdata->htab, persistent);
     280           6 :                 bdata->htab = NULL;
     281             :         }
     282       20541 :         bdata->filename[0] = '\0';
     283             :         /* current_section_* are only used during parsing */
     284       20541 : }
     285             : /* }}} */
     286             : 
     287             : /* {{{ PHP_INI_MH
     288             :  */
     289       20507 : PHP_INI_MH(OnChangeBrowscap)
     290             : {
     291       20507 :         if (stage == PHP_INI_STAGE_STARTUP) {
     292             :                 /* value handled in browscap.c's MINIT */
     293       20507 :                 return SUCCESS;
     294           0 :         } else if (stage == PHP_INI_STAGE_ACTIVATE) {
     295           0 :                 browser_data *bdata = &BROWSCAP_G(activation_bdata);
     296           0 :                 if (bdata->filename[0] != '\0') {
     297           0 :                         browscap_bdata_dtor(bdata, 0 TSRMLS_CC);
     298             :                 }
     299           0 :                 if (VCWD_REALPATH(new_value->val, bdata->filename) == NULL) {
     300           0 :                         return FAILURE;
     301             :                 }
     302           0 :                 return SUCCESS;
     303             :         }
     304             :         
     305           0 :         return FAILURE;
     306             : }
     307             : /* }}} */
     308             : 
     309       20507 : PHP_MINIT_FUNCTION(browscap) /* {{{ */
     310             : {
     311       20507 :         char *browscap = INI_STR("browscap");
     312             : 
     313             : #ifdef ZTS
     314             :         ts_allocate_id(&browscap_globals_id, sizeof(browser_data),
     315             :                 browscap_globals_ctor, NULL);
     316             : #endif
     317             :         /* ctor call not really needed for non-ZTS */
     318             : 
     319       20507 :         if (browscap && browscap[0]) {
     320           6 :                 if (browscap_read_file(browscap, &global_bdata, 1 TSRMLS_CC) == FAILURE) {
     321           0 :                         return FAILURE;
     322             :                 }
     323             :         }
     324             : 
     325       20507 :         return SUCCESS;
     326             : }
     327             : /* }}} */
     328             : 
     329       20500 : PHP_RSHUTDOWN_FUNCTION(browscap) /* {{{ */
     330             : {
     331       20500 :         browser_data *bdata = &BROWSCAP_G(activation_bdata);
     332       20500 :         if (bdata->filename[0] != '\0') {
     333           0 :                 browscap_bdata_dtor(bdata, 0 TSRMLS_CC);
     334             :         }
     335             :         
     336       20500 :         return SUCCESS;
     337             : }
     338             : /* }}} */
     339             : 
     340       20541 : PHP_MSHUTDOWN_FUNCTION(browscap) /* {{{ */
     341             : {
     342       20541 :         browscap_bdata_dtor(&global_bdata, 1 TSRMLS_CC);
     343             :         
     344       20541 :         return SUCCESS;
     345             : }
     346             : /* }}} */
     347             : 
     348      127800 : static int browser_reg_compare(zval *browser TSRMLS_DC, int num_args, va_list args, zend_hash_key *key) /* {{{ */
     349             : {
     350             :         zval *browser_regex, *previous_match;
     351             :         pcre *re;
     352             :         int re_options;
     353             :         pcre_extra *re_extra;
     354      127800 :         char *lookup_browser_name = va_arg(args, char *);
     355      127800 :         int lookup_browser_length = va_arg(args, int);
     356      127800 :         zval *found_browser_entry = va_arg(args, zval *);
     357             : 
     358             :         /* See if we have an exact match, if so, we're done... */
     359      127800 :         if (Z_TYPE_P(found_browser_entry) == IS_ARRAY) {
     360       24916 :                 if ((previous_match = zend_hash_str_find(Z_ARRVAL_P(found_browser_entry), "browser_name_pattern", sizeof("browser_name_pattern")-1)) == NULL) {
     361           0 :                         return 0;
     362             :                 }
     363       24916 :                 else if (!strcasecmp(Z_STRVAL_P(previous_match), lookup_browser_name)) {
     364           0 :                         return 0;
     365             :                 }
     366             :         }
     367             : 
     368      127800 :         if ((browser_regex = zend_hash_str_find(Z_ARRVAL_P(browser), "browser_name_regex", sizeof("browser_name_regex")-1)) == NULL) {
     369           0 :                 return 0;
     370             :         }
     371             : 
     372      127800 :         re = pcre_get_compiled_regex(Z_STR_P(browser_regex), &re_extra, &re_options TSRMLS_CC);
     373      127800 :         if (re == NULL) {
     374           0 :                 return 0;
     375             :         }
     376             : 
     377      127800 :         if (pcre_exec(re, re_extra, lookup_browser_name, lookup_browser_length, 0, re_options, NULL, 0) == 0) {
     378             :                 /* If we've found a possible browser, we need to do a comparison of the
     379             :                    number of characters changed in the user agent being checked versus
     380             :                    the previous match found and the current match. */
     381          90 :                 if (Z_TYPE_P(found_browser_entry) == IS_ARRAY) {
     382          50 :                         size_t i, prev_len = 0, curr_len = 0;
     383          50 :                         zval *current_match = zend_hash_str_find(Z_ARRVAL_P(browser), "browser_name_pattern", sizeof("browser_name_pattern")-1);
     384             : 
     385          50 :                         if (!current_match) {
     386           0 :                                 return 0;
     387             :                         }
     388             : 
     389        2640 :                         for (i = 0; i < Z_STRLEN_P(previous_match); i++) {
     390        2590 :                                 switch (Z_STRVAL_P(previous_match)[i]) {
     391             :                                         case '?':
     392             :                                         case '*':
     393             :                                                 /* do nothing, ignore these characters in the count */
     394         201 :                                         break;
     395             : 
     396             :                                         default:
     397        2389 :                                                 ++prev_len;
     398             :                                 }
     399             :                         }
     400             : 
     401         948 :                         for (i = 0; i < Z_STRLEN_P(current_match); i++) {
     402         898 :                                 switch (Z_STRVAL_P(current_match)[i]) {
     403             :                                         case '?':
     404             :                                         case '*':
     405             :                                                 /* do nothing, ignore these characters in the count */
     406         110 :                                         break;
     407             : 
     408             :                                         default:
     409         788 :                                                 ++curr_len;
     410             :                                 }
     411             :                         }
     412             : 
     413             :                         /* Pick which browser pattern replaces the least amount of
     414             :                            characters when compared to the original user agent string... */
     415          50 :                         if (prev_len < curr_len) {
     416           7 :                                 ZVAL_COPY_VALUE(found_browser_entry, browser);
     417             :                         }
     418             :                 }
     419             :                 else {
     420          40 :                         ZVAL_COPY_VALUE(found_browser_entry, browser);
     421             :                 }
     422             :         }
     423             : 
     424      127800 :         return 0;
     425             : }
     426             : /* }}} */
     427             : 
     428         911 : static void browscap_zval_copy_ctor(zval *p) /* {{{ */
     429             : {
     430             :         zval_copy_ctor(p);
     431         911 : }
     432             : /* }}} */
     433             : 
     434             : /* {{{ proto mixed get_browser([string browser_name [, bool return_array]])
     435             :    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. */
     436          42 : PHP_FUNCTION(get_browser)
     437             : {
     438          42 :         char *agent_name = NULL;
     439          42 :         size_t agent_name_len = 0;
     440          42 :         zend_bool return_array = 0;
     441             :         zval *agent, *z_agent_name, *http_user_agent;
     442             :         zval found_browser_entry;
     443             :         char *lookup_browser_name;
     444             :         browser_data *bdata;
     445             : 
     446          42 :         if (BROWSCAP_G(activation_bdata).filename[0] != '\0') {
     447           0 :                 bdata = &BROWSCAP_G(activation_bdata);
     448           0 :                 if (bdata->htab == NULL) { /* not initialized yet */
     449           0 :                         if (browscap_read_file(bdata->filename, bdata, 0 TSRMLS_CC) == FAILURE) {
     450           0 :                                 RETURN_FALSE;
     451             :                         }
     452             :                 }
     453             :         } else {
     454          42 :                 if (!global_bdata.htab) {
     455           0 :                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "browscap ini directive not set");
     456           0 :                         RETURN_FALSE;
     457             :                 }
     458          42 :                 bdata = &global_bdata;
     459             :         }
     460             : 
     461          42 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!b", &agent_name, &agent_name_len, &return_array) == FAILURE) {
     462           1 :                 return;
     463             :         }
     464             : 
     465          41 :         if (agent_name == NULL) {
     466           1 :                 zend_string *key = zend_string_init("_SERVER", sizeof("_SERVER") - 1, 0);
     467           1 :                 zend_is_auto_global(key TSRMLS_CC);
     468             :                 zend_string_release(key);
     469           1 :                 if (Z_TYPE(PG(http_globals)[TRACK_VARS_SERVER]) != IS_UNDEF ||
     470           0 :                         (http_user_agent = zend_hash_str_find(HASH_OF(&PG(http_globals)[TRACK_VARS_SERVER]), "HTTP_USER_AGENT", sizeof("HTTP_USER_AGENT")-1)) == NULL
     471             :                 ) {
     472           1 :                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "HTTP_USER_AGENT variable is not set, cannot determine user agent name");
     473           1 :                         RETURN_FALSE;
     474             :                 }
     475           0 :                 agent_name = Z_STRVAL_P(http_user_agent);
     476           0 :                 agent_name_len = Z_STRLEN_P(http_user_agent);
     477             :         }
     478             : 
     479          40 :         lookup_browser_name = estrndup(agent_name, agent_name_len);
     480          40 :         php_strtolower(lookup_browser_name, agent_name_len);
     481             : 
     482          40 :         if ((agent = zend_hash_str_find(bdata->htab, lookup_browser_name, agent_name_len)) == NULL) {
     483          40 :                 ZVAL_UNDEF(&found_browser_entry);
     484          40 :                 zend_hash_apply_with_arguments(bdata->htab TSRMLS_CC, browser_reg_compare, 3, lookup_browser_name, agent_name_len, &found_browser_entry);
     485             : 
     486          40 :                 if (Z_TYPE(found_browser_entry) != IS_UNDEF) {
     487          40 :                         agent = &found_browser_entry;
     488           0 :                 } else if ((agent = zend_hash_str_find(bdata->htab, DEFAULT_SECTION_NAME, sizeof(DEFAULT_SECTION_NAME)-1)) == NULL) {
     489           0 :                         efree(lookup_browser_name);
     490           0 :                         RETURN_FALSE;
     491             :                 }
     492             :         }
     493             : 
     494          40 :         if (return_array) {
     495          40 :                 ZVAL_NEW_ARR(return_value);
     496          40 :                 zend_array_dup(Z_ARRVAL_P(return_value), Z_ARRVAL_P(agent));
     497             :         }
     498             :         else {
     499           0 :                 object_init(return_value);
     500           0 :                 zend_hash_copy(Z_OBJPROP_P(return_value), Z_ARRVAL_P(agent), (copy_ctor_func_t) browscap_zval_copy_ctor);
     501             :         }
     502             : 
     503         140 :         while ((z_agent_name = zend_hash_str_find(Z_ARRVAL_P(agent), "parent", sizeof("parent")-1)) != NULL) {
     504          60 :                 if ((agent = zend_hash_find(bdata->htab, Z_STR_P(z_agent_name))) == NULL) {
     505           0 :                         break;
     506             :                 }
     507             : 
     508          60 :                 if (return_array) {
     509          60 :                         zend_hash_merge(Z_ARRVAL_P(return_value), Z_ARRVAL_P(agent), (copy_ctor_func_t) browscap_zval_copy_ctor, 0);
     510             :                 }
     511             :                 else {
     512           0 :                         zend_hash_merge(Z_OBJPROP_P(return_value), Z_ARRVAL_P(agent), (copy_ctor_func_t) browscap_zval_copy_ctor, 0);
     513             :                 }
     514             :         }
     515             : 
     516          40 :         efree(lookup_browser_name);
     517             : }
     518             : /* }}} */
     519             : 
     520             : /*
     521             :  * Local variables:
     522             :  * tab-width: 4
     523             :  * c-basic-offset: 4
     524             :  * End:
     525             :  * vim600: sw=4 ts=4 fdm=marker
     526             :  * vim<600: sw=4 ts=4
     527             :  */

Generated by: LCOV version 1.10

Generated at Sat, 22 Nov 2014 23:01:24 +0000 (11 hours ago)

Copyright © 2005-2014 The PHP Group
All rights reserved.