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: 183 228 80.3 %
Date: 2016-09-18 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-2016 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             : #define BROWSCAP_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(browscap, v)
      48             : 
      49             : #define DEFAULT_SECTION_NAME "Default Browser Capability Settings"
      50             : 
      51             : /* OBJECTS_FIXME: This whole extension needs going through. The use of objects looks pretty broken here */
      52             : 
      53           0 : static void browscap_entry_dtor_request(zval *zvalue) /* {{{ */
      54             : {
      55           0 :         if (Z_TYPE_P(zvalue) == IS_ARRAY) {
      56           0 :                 zend_hash_destroy(Z_ARRVAL_P(zvalue));
      57           0 :                 efree(Z_ARR_P(zvalue));
      58           0 :         } else if (Z_TYPE_P(zvalue) == IS_STRING) {
      59           0 :                 zend_string_release(Z_STR_P(zvalue));
      60             :         }
      61           0 : }
      62             : /* }}} */
      63             : 
      64      178696 : static void browscap_entry_dtor_persistent(zval *zvalue) /* {{{ */ {
      65      178696 :         if (Z_TYPE_P(zvalue) == IS_ARRAY) {
      66       28782 :                 zend_hash_destroy(Z_ARRVAL_P(zvalue));
      67       28782 :                 free(Z_ARR_P(zvalue));
      68      149914 :         } else if (Z_TYPE_P(zvalue) == IS_STRING) {
      69      149914 :                 zend_string_release(Z_STR_P(zvalue));
      70             :         }
      71      178696 : }
      72             : /* }}} */
      73             : 
      74       28782 : static void convert_browscap_pattern(zval *pattern, int persistent) /* {{{ */
      75             : {
      76       28782 :         size_t i, j=0;
      77             :         char *t;
      78             :         zend_string *res;
      79             :         char *lc_pattern;
      80             : 
      81       57564 :         res = zend_string_safe_alloc(Z_STRLEN_P(pattern), 2, 4, persistent);
      82       28782 :         t = ZSTR_VAL(res);
      83             : 
      84       28782 :         lc_pattern = zend_str_tolower_dup(Z_STRVAL_P(pattern), Z_STRLEN_P(pattern));
      85             : 
      86       28782 :         t[j++] = '~';
      87       28782 :         t[j++] = '^';
      88             : 
      89     1042767 :         for (i=0; i<Z_STRLEN_P(pattern); i++, j++) {
      90     1013985 :                 switch (lc_pattern[i]) {
      91             :                         case '?':
      92        8028 :                                 t[j] = '.';
      93        8028 :                                 break;
      94             :                         case '*':
      95       62352 :                                 t[j++] = '.';
      96       62352 :                                 t[j] = '*';
      97       62352 :                                 break;
      98             :                         case '.':
      99       43920 :                                 t[j++] = '\\';
     100       43920 :                                 t[j] = '.';
     101       43920 :                                 break;
     102             :                         case '\\':
     103         117 :                                 t[j++] = '\\';
     104         117 :                                 t[j] = '\\';
     105         117 :                                 break;
     106             :                         case '(':
     107       19278 :                                 t[j++] = '\\';
     108       19278 :                                 t[j] = '(';
     109       19278 :                                 break;
     110             :                         case ')':
     111       19044 :                                 t[j++] = '\\';
     112       19044 :                                 t[j] = ')';
     113       19044 :                                 break;
     114             :                         case '~':
     115           9 :                                 t[j++] = '\\';
     116           9 :                                 t[j] = '~';
     117           9 :                                 break;
     118             :                         case '+':
     119          18 :                                 t[j++] = '\\';
     120          18 :                                 t[j] = '+';
     121          18 :                                 break;
     122             :                         default:
     123      861219 :                                 t[j] = lc_pattern[i];
     124             :                                 break;
     125             :                 }
     126             :         }
     127             : 
     128       28782 :         t[j++] = '$';
     129       28782 :         t[j++] = '~';
     130             : 
     131       28782 :         t[j]=0;
     132       28782 :         ZSTR_LEN(res) = j;
     133       28782 :         Z_STR_P(pattern) = res;
     134       28782 :         efree(lc_pattern);
     135       28782 : }
     136             : /* }}} */
     137             : 
     138      119673 : static void php_browscap_parser_cb(zval *arg1, zval *arg2, zval *arg3, int callback_type, void *arg) /* {{{ */
     139             : {
     140      119673 :         browser_data *bdata = arg;
     141      119673 :         int persistent = bdata->htab->u.flags & HASH_FLAG_PERSISTENT;
     142             : 
     143      119673 :         if (!arg1) {
     144           0 :                 return;
     145             :         }
     146             : 
     147      119673 :         switch (callback_type) {
     148             :                 case ZEND_INI_PARSER_ENTRY:
     149      181782 :                         if (Z_TYPE(bdata->current_section) != IS_UNDEF && arg2) {
     150             :                                 zval new_property;
     151             :                                 zend_string *new_key;
     152             : 
     153             :                                 /* parent entry can not be same as current section -> causes infinite loop! */
     154      148401 :                                 if (!strcasecmp(Z_STRVAL_P(arg1), "parent") &&
     155       28755 :                                         bdata->current_section_name != NULL &&
     156       28755 :                                         !strcasecmp(bdata->current_section_name, Z_STRVAL_P(arg2))
     157             :                                 ) {
     158           0 :                                         zend_error(E_CORE_ERROR, "Invalid browscap ini file: "
     159             :                                                 "'Parent' value cannot be same as the section name: %s "
     160             :                                                 "(in file %s)", bdata->current_section_name, INI_STR("browscap"));
     161           0 :                                         return;
     162             :                                 }
     163             : 
     164             :                                 /* Set proper value for true/false settings */
     165      321039 :                                 if ((Z_STRLEN_P(arg2) == 2 && !strncasecmp(Z_STRVAL_P(arg2), "on", sizeof("on") - 1)) ||
     166       94473 :                                         (Z_STRLEN_P(arg2) == 3 && !strncasecmp(Z_STRVAL_P(arg2), "yes", sizeof("yes") - 1)) ||
     167      114138 :                                         (Z_STRLEN_P(arg2) == 4 && !strncasecmp(Z_STRVAL_P(arg2), "true", sizeof("true") - 1))
     168             :                                 ) {
     169       43074 :                                         ZVAL_NEW_STR(&new_property, zend_string_init("1", sizeof("1")-1, persistent));
     170      295443 :                                 } else if (
     171       70560 :                                         (Z_STRLEN_P(arg2) == 2 && !strncasecmp(Z_STRVAL_P(arg2), "no", sizeof("no") - 1)) ||
     172       72936 :                                         (Z_STRLEN_P(arg2) == 3 && !strncasecmp(Z_STRVAL_P(arg2), "off", sizeof("off") - 1)) ||
     173       71064 :                                         (Z_STRLEN_P(arg2) == 4 && !strncasecmp(Z_STRVAL_P(arg2), "none", sizeof("none") - 1)) ||
     174       80244 :                                         (Z_STRLEN_P(arg2) == 5 && !strncasecmp(Z_STRVAL_P(arg2), "false", sizeof("false") - 1))
     175             :                                 ) {
     176             :                                         // TODO: USE ZSTR_EMPTY_ALLOC()?
     177        1278 :                                         ZVAL_NEW_STR(&new_property, zend_string_init("", sizeof("")-1, persistent));
     178             :                                 } else { /* Other than true/false setting */
     179      137430 :                                         ZVAL_STR(&new_property, zend_string_dup(Z_STR_P(arg2), persistent));
     180             :                                 }
     181      181782 :                                 new_key = zend_string_dup(Z_STR_P(arg1), persistent);
     182       90891 :                                 zend_str_tolower(ZSTR_VAL(new_key), ZSTR_LEN(new_key));
     183       90891 :                                 zend_hash_update(Z_ARRVAL(bdata->current_section), new_key, &new_property);
     184             :                                 zend_string_release(new_key);
     185             :                         }
     186       90891 :                         break;
     187             :                 case ZEND_INI_PARSER_SECTION: {
     188             :                                 zval processed;
     189             :                                 zval unprocessed;
     190             : 
     191             :                                 /*printf("'%s' (%d)\n",$1.value.str.val,$1.value.str.len + 1);*/
     192       28782 :                                 if (persistent) {
     193       28782 :                                         ZVAL_NEW_PERSISTENT_ARR(&bdata->current_section);
     194             :                                 } else {
     195           0 :                                         ZVAL_NEW_ARR(&bdata->current_section);
     196             :                                 }
     197       28782 :                                 zend_hash_init(Z_ARRVAL(bdata->current_section), 0, NULL,
     198             :                                                 (dtor_func_t) (persistent?browscap_entry_dtor_persistent
     199             :                                                                                                  :browscap_entry_dtor_request),
     200             :                                                 persistent);
     201       28782 :                                 if (bdata->current_section_name) {
     202       28773 :                                         pefree(bdata->current_section_name, persistent);
     203             :                                 }
     204       28782 :                                 bdata->current_section_name = pestrndup(Z_STRVAL_P(arg1),
     205             :                                                 Z_STRLEN_P(arg1), persistent);
     206             : 
     207       28782 :                                 zend_hash_update(bdata->htab, Z_STR_P(arg1), &bdata->current_section);
     208             : 
     209       28782 :                                 ZVAL_STR(&processed, Z_STR_P(arg1));
     210       57564 :                                 ZVAL_STR(&unprocessed, zend_string_dup(Z_STR_P(arg1), persistent));
     211             : 
     212       28782 :                                 convert_browscap_pattern(&processed, persistent);
     213       28782 :                                 zend_hash_str_update(Z_ARRVAL(bdata->current_section), "browser_name_regex", sizeof("browser_name_regex")-1, &processed);
     214       28782 :                                 zend_hash_str_update(Z_ARRVAL(bdata->current_section), "browser_name_pattern", sizeof("browser_name_pattern")-1, &unprocessed);
     215             :                         }
     216             :                         break;
     217             :         }
     218             : }
     219             : /* }}} */
     220             : 
     221           9 : static int browscap_read_file(char *filename, browser_data *browdata, int persistent) /* {{{ */
     222             : {
     223             :         zend_file_handle fh;
     224             : 
     225           9 :         if (filename == NULL || filename[0] == '\0') {
     226           0 :                 return FAILURE;
     227             :         }
     228             : 
     229           9 :         browdata->htab = pemalloc(sizeof *browdata->htab, persistent);
     230           9 :         if (browdata->htab == NULL) {
     231           0 :                 return FAILURE;
     232             :         }
     233             : 
     234           9 :         zend_hash_init_ex(browdata->htab, 0, NULL,
     235             :                         (dtor_func_t) (persistent?browscap_entry_dtor_persistent
     236             :                                                                          :browscap_entry_dtor_request),
     237             :                         persistent, 0);
     238             : 
     239           9 :         memset(&fh, 0, sizeof(fh));
     240           9 :         fh.handle.fp = VCWD_FOPEN(filename, "r");
     241           9 :         fh.opened_path = NULL;
     242           9 :         fh.free_filename = 0;
     243           9 :         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           9 :         fh.filename = filename;
     251           9 :         fh.type = ZEND_HANDLE_FP;
     252           9 :         browdata->current_section_name = NULL;
     253           9 :         zend_parse_ini_file(&fh, 1, ZEND_INI_SCANNER_RAW,
     254             :                         (zend_ini_parser_cb_t) php_browscap_parser_cb, browdata);
     255           9 :         if (browdata->current_section_name != NULL) {
     256           9 :                 pefree(browdata->current_section_name, persistent);
     257           9 :                 browdata->current_section_name = NULL;
     258             :         }
     259             : 
     260           9 :         return SUCCESS;
     261             : }
     262             : /* }}} */
     263             : 
     264             : #ifdef ZTS
     265             : static void browscap_globals_ctor(zend_browscap_globals *browscap_globals) /* {{{ */
     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       23963 : static void browscap_bdata_dtor(browser_data *bdata, int persistent) /* {{{ */
     276             : {
     277       23963 :         if (bdata->htab != NULL) {
     278           9 :                 zend_hash_destroy(bdata->htab);
     279           9 :                 pefree(bdata->htab, persistent);
     280           9 :                 bdata->htab = NULL;
     281             :         }
     282       23963 :         bdata->filename[0] = '\0';
     283             :         /* current_section_* are only used during parsing */
     284       23963 : }
     285             : /* }}} */
     286             : 
     287             : /* {{{ PHP_INI_MH
     288             :  */
     289       23922 : PHP_INI_MH(OnChangeBrowscap)
     290             : {
     291       23922 :         if (stage == PHP_INI_STAGE_STARTUP) {
     292             :                 /* value handled in browscap.c's MINIT */
     293       23922 :                 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);
     298             :                 }
     299           0 :                 if (VCWD_REALPATH(ZSTR_VAL(new_value), bdata->filename) == NULL) {
     300           0 :                         return FAILURE;
     301             :                 }
     302           0 :                 return SUCCESS;
     303             :         }
     304             : 
     305           0 :         return FAILURE;
     306             : }
     307             : /* }}} */
     308             : 
     309       23922 : PHP_MINIT_FUNCTION(browscap) /* {{{ */
     310             : {
     311       23922 :         char *browscap = INI_STR("browscap");
     312             : 
     313             : #ifdef ZTS
     314             :         ts_allocate_id(&browscap_globals_id, sizeof(browser_data), (ts_allocate_ctor) browscap_globals_ctor, NULL);
     315             : #endif
     316             :         /* ctor call not really needed for non-ZTS */
     317             : 
     318       23922 :         if (browscap && browscap[0]) {
     319           9 :                 if (browscap_read_file(browscap, &global_bdata, 1) == FAILURE) {
     320           0 :                         return FAILURE;
     321             :                 }
     322             :         }
     323             : 
     324       23922 :         return SUCCESS;
     325             : }
     326             : /* }}} */
     327             : 
     328       23919 : PHP_RSHUTDOWN_FUNCTION(browscap) /* {{{ */
     329             : {
     330       23919 :         browser_data *bdata = &BROWSCAP_G(activation_bdata);
     331       23919 :         if (bdata->filename[0] != '\0') {
     332           0 :                 browscap_bdata_dtor(bdata, 0);
     333             :         }
     334             : 
     335       23919 :         return SUCCESS;
     336             : }
     337             : /* }}} */
     338             : 
     339       23963 : PHP_MSHUTDOWN_FUNCTION(browscap) /* {{{ */
     340             : {
     341       23963 :         browscap_bdata_dtor(&global_bdata, 1);
     342             : 
     343       23963 :         return SUCCESS;
     344             : }
     345             : /* }}} */
     346             : 
     347      134190 : static int browser_reg_compare(zval *browser, int num_args, va_list args, zend_hash_key *key) /* {{{ */
     348             : {
     349             :         zval *browser_regex, *previous_match;
     350             :         pcre *re;
     351             :         int re_options;
     352             :         pcre_extra *re_extra;
     353      134190 :         char *lookup_browser_name = va_arg(args, char *);
     354      134190 :         int lookup_browser_length = va_arg(args, int);
     355      134190 :         zval *found_browser_entry = va_arg(args, zval *);
     356             : 
     357             :         /* See if we have an exact match, if so, we're done... */
     358      134190 :         if (Z_TYPE_P(found_browser_entry) == IS_ARRAY) {
     359       26441 :                 if ((previous_match = zend_hash_str_find(Z_ARRVAL_P(found_browser_entry), "browser_name_pattern", sizeof("browser_name_pattern")-1)) == NULL) {
     360           0 :                         return 0;
     361             :                 }
     362       26441 :                 else if (!strcasecmp(Z_STRVAL_P(previous_match), lookup_browser_name)) {
     363        1519 :                         return 0;
     364             :                 }
     365             :         }
     366             : 
     367      132671 :         if ((browser_regex = zend_hash_str_find(Z_ARRVAL_P(browser), "browser_name_regex", sizeof("browser_name_regex")-1)) == NULL) {
     368           0 :                 return 0;
     369             :         }
     370             : 
     371      132671 :         re = pcre_get_compiled_regex(Z_STR_P(browser_regex), &re_extra, &re_options);
     372      132671 :         if (re == NULL) {
     373           0 :                 return 0;
     374             :         }
     375             : 
     376      132671 :         if (pcre_exec(re, re_extra, lookup_browser_name, lookup_browser_length, 0, re_options, NULL, 0) == 0) {
     377             :                 /* If we've found a possible browser, we need to do a comparison of the
     378             :                    number of characters changed in the user agent being checked versus
     379             :                    the previous match found and the current match. */
     380          93 :                 if (Z_TYPE_P(found_browser_entry) == IS_ARRAY) {
     381          51 :                         size_t i, prev_len = 0, curr_len = 0;
     382          51 :                         zval *current_match = zend_hash_str_find(Z_ARRVAL_P(browser), "browser_name_pattern", sizeof("browser_name_pattern")-1);
     383             : 
     384          51 :                         if (!current_match) {
     385           0 :                                 return 0;
     386             :                         }
     387             : 
     388        2709 :                         for (i = 0; i < Z_STRLEN_P(previous_match); i++) {
     389        2658 :                                 switch (Z_STRVAL_P(previous_match)[i]) {
     390             :                                         case '?':
     391             :                                         case '*':
     392             :                                                 /* do nothing, ignore these characters in the count */
     393         208 :                                         break;
     394             : 
     395             :                                         default:
     396        2450 :                                                 ++prev_len;
     397             :                                 }
     398             :                         }
     399             : 
     400        1058 :                         for (i = 0; i < Z_STRLEN_P(current_match); i++) {
     401        1007 :                                 switch (Z_STRVAL_P(current_match)[i]) {
     402             :                                         case '?':
     403             :                                         case '*':
     404             :                                                 /* do nothing, ignore these characters in the count */
     405         110 :                                         break;
     406             : 
     407             :                                         default:
     408         897 :                                                 ++curr_len;
     409             :                                 }
     410             :                         }
     411             : 
     412             :                         /* Pick which browser pattern replaces the least amount of
     413             :                            characters when compared to the original user agent string... */
     414          51 :                         if (prev_len < curr_len) {
     415           8 :                                 ZVAL_COPY_VALUE(found_browser_entry, browser);
     416             :                         }
     417             :                 }
     418             :                 else {
     419          42 :                         ZVAL_COPY_VALUE(found_browser_entry, browser);
     420             :                 }
     421             :         }
     422             : 
     423      132671 :         return 0;
     424             : }
     425             : /* }}} */
     426             : 
     427         940 : static void browscap_zval_copy_ctor(zval *p) /* {{{ */
     428             : {
     429             :         zval_copy_ctor(p);
     430         940 : }
     431             : /* }}} */
     432             : 
     433             : /* {{{ proto mixed get_browser([string browser_name [, bool return_array]])
     434             :    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. */
     435          44 : PHP_FUNCTION(get_browser)
     436             : {
     437          44 :         char *agent_name = NULL;
     438          44 :         size_t agent_name_len = 0;
     439          44 :         zend_bool return_array = 0;
     440             :         zval *agent, *z_agent_name, *http_user_agent;
     441             :         zval found_browser_entry;
     442             :         char *lookup_browser_name;
     443             :         browser_data *bdata;
     444             : 
     445          44 :         if (BROWSCAP_G(activation_bdata).filename[0] != '\0') {
     446           0 :                 bdata = &BROWSCAP_G(activation_bdata);
     447           0 :                 if (bdata->htab == NULL) { /* not initialized yet */
     448           0 :                         if (browscap_read_file(bdata->filename, bdata, 0) == FAILURE) {
     449           0 :                                 RETURN_FALSE;
     450             :                         }
     451             :                 }
     452             :         } else {
     453          44 :                 if (!global_bdata.htab) {
     454           0 :                         php_error_docref(NULL, E_WARNING, "browscap ini directive not set");
     455           0 :                         RETURN_FALSE;
     456             :                 }
     457          44 :                 bdata = &global_bdata;
     458             :         }
     459             : 
     460          44 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s!b", &agent_name, &agent_name_len, &return_array) == FAILURE) {
     461           1 :                 return;
     462             :         }
     463             : 
     464          43 :         if (agent_name == NULL) {
     465           4 :                 if ((Z_TYPE(PG(http_globals)[TRACK_VARS_SERVER]) == IS_ARRAY || zend_is_auto_global_str(ZEND_STRL("_SERVER"))) && 
     466           2 :                         (http_user_agent = zend_hash_str_find(Z_ARRVAL_P(&PG(http_globals)[TRACK_VARS_SERVER]), "HTTP_USER_AGENT", sizeof("HTTP_USER_AGENT")-1)) == NULL
     467             :                 ) {
     468           1 :                         php_error_docref(NULL, E_WARNING, "HTTP_USER_AGENT variable is not set, cannot determine user agent name");
     469           1 :                         RETURN_FALSE;
     470             :                 }
     471           1 :                 agent_name = Z_STRVAL_P(http_user_agent);
     472           1 :                 agent_name_len = Z_STRLEN_P(http_user_agent);
     473             :         }
     474             : 
     475          42 :         lookup_browser_name = estrndup(agent_name, agent_name_len);
     476          42 :         php_strtolower(lookup_browser_name, agent_name_len);
     477             : 
     478          42 :         if ((agent = zend_hash_str_find(bdata->htab, lookup_browser_name, agent_name_len)) == NULL) {
     479          42 :                 ZVAL_UNDEF(&found_browser_entry);
     480          42 :                 zend_hash_apply_with_arguments(bdata->htab, browser_reg_compare, 3, lookup_browser_name, agent_name_len, &found_browser_entry);
     481             : 
     482          42 :                 if (Z_TYPE(found_browser_entry) != IS_UNDEF) {
     483          42 :                         agent = &found_browser_entry;
     484           0 :                 } else if ((agent = zend_hash_str_find(bdata->htab, DEFAULT_SECTION_NAME, sizeof(DEFAULT_SECTION_NAME)-1)) == NULL) {
     485           0 :                         efree(lookup_browser_name);
     486           0 :                         RETURN_FALSE;
     487             :                 }
     488             :         }
     489             : 
     490          42 :         if (return_array) {
     491          42 :                 RETVAL_ARR(zend_array_dup(Z_ARRVAL_P(agent)));
     492             :         }
     493             :         else {
     494           0 :                 object_init(return_value);
     495           0 :                 zend_hash_copy(Z_OBJPROP_P(return_value), Z_ARRVAL_P(agent), (copy_ctor_func_t) browscap_zval_copy_ctor);
     496             :         }
     497             : 
     498         146 :         while ((z_agent_name = zend_hash_str_find(Z_ARRVAL_P(agent), "parent", sizeof("parent")-1)) != NULL) {
     499          62 :                 if ((agent = zend_hash_find(bdata->htab, Z_STR_P(z_agent_name))) == NULL) {
     500           0 :                         break;
     501             :                 }
     502             : 
     503          62 :                 if (return_array) {
     504          62 :                         zend_hash_merge(Z_ARRVAL_P(return_value), Z_ARRVAL_P(agent), (copy_ctor_func_t) browscap_zval_copy_ctor, 0);
     505             :                 }
     506             :                 else {
     507           0 :                         zend_hash_merge(Z_OBJPROP_P(return_value), Z_ARRVAL_P(agent), (copy_ctor_func_t) browscap_zval_copy_ctor, 0);
     508             :                 }
     509             :         }
     510             : 
     511          42 :         efree(lookup_browser_name);
     512             : }
     513             : /* }}} */
     514             : 
     515             : /*
     516             :  * Local variables:
     517             :  * tab-width: 4
     518             :  * c-basic-offset: 4
     519             :  * End:
     520             :  * vim600: sw=4 ts=4 fdm=marker
     521             :  * vim<600: sw=4 ts=4
     522             :  */

Generated by: LCOV version 1.10

Generated at Sun, 18 Sep 2016 08:20:16 +0000 (9 days ago)

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