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

Generated by: LCOV version 1.10

Generated at Wed, 20 Jul 2016 02:56:28 +0000 (3 days ago)

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