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: 2015-08-29 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-2015 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 :         int 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           7 :         zend_file_handle fh = {{0}};
     220             : 
     221           7 :         if (filename == NULL || filename[0] == '\0') {
     222           0 :                 return FAILURE;
     223             :         }
     224             : 
     225          14 :         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 :         fh.handle.fp = VCWD_FOPEN(filename, "r");
     236           7 :         fh.opened_path = NULL;
     237           7 :         fh.free_filename = 0;
     238           7 :         if (!fh.handle.fp) {
     239           0 :                 zend_hash_destroy(browdata->htab);
     240           0 :                 pefree(browdata->htab, persistent);
     241           0 :                 browdata->htab = NULL;
     242           0 :                 zend_error(E_CORE_WARNING, "Cannot open '%s' for reading", filename);
     243           0 :                 return FAILURE;
     244             :         }
     245           7 :         fh.filename = filename;
     246           7 :         fh.type = ZEND_HANDLE_FP;
     247           7 :         browdata->current_section_name = NULL;
     248           7 :         zend_parse_ini_file(&fh, 1, ZEND_INI_SCANNER_RAW,
     249             :                         (zend_ini_parser_cb_t) php_browscap_parser_cb, browdata);
     250           7 :         if (browdata->current_section_name != NULL) {
     251           7 :                 pefree(browdata->current_section_name, persistent);
     252           7 :                 browdata->current_section_name = NULL;
     253             :         }
     254             : 
     255           7 :         return SUCCESS;
     256             : }
     257             : /* }}} */
     258             : 
     259             : #ifdef ZTS
     260             : static void browscap_globals_ctor(zend_browscap_globals *browscap_globals) /* {{{ */
     261             : {
     262             :         browscap_globals->activation_bdata.htab = NULL;
     263             :         ZVAL_UNDEF(&browscap_globals->activation_bdata.current_section);
     264             :         browscap_globals->activation_bdata.current_section_name = NULL;
     265             :         browscap_globals->activation_bdata.filename[0] = '\0';
     266             : }
     267             : /* }}} */
     268             : #endif
     269             : 
     270       21327 : static void browscap_bdata_dtor(browser_data *bdata, int persistent) /* {{{ */
     271             : {
     272       21327 :         if (bdata->htab != NULL) {
     273           7 :                 zend_hash_destroy(bdata->htab);
     274           7 :                 pefree(bdata->htab, persistent);
     275           7 :                 bdata->htab = NULL;
     276             :         }
     277       21327 :         bdata->filename[0] = '\0';
     278             :         /* current_section_* are only used during parsing */
     279       21327 : }
     280             : /* }}} */
     281             : 
     282             : /* {{{ PHP_INI_MH
     283             :  */
     284       21291 : PHP_INI_MH(OnChangeBrowscap)
     285             : {
     286       21291 :         if (stage == PHP_INI_STAGE_STARTUP) {
     287             :                 /* value handled in browscap.c's MINIT */
     288       21291 :                 return SUCCESS;
     289           0 :         } else if (stage == PHP_INI_STAGE_ACTIVATE) {
     290           0 :                 browser_data *bdata = &BROWSCAP_G(activation_bdata);
     291           0 :                 if (bdata->filename[0] != '\0') {
     292           0 :                         browscap_bdata_dtor(bdata, 0);
     293             :                 }
     294           0 :                 if (VCWD_REALPATH(ZSTR_VAL(new_value), bdata->filename) == NULL) {
     295           0 :                         return FAILURE;
     296             :                 }
     297           0 :                 return SUCCESS;
     298             :         }
     299             : 
     300           0 :         return FAILURE;
     301             : }
     302             : /* }}} */
     303             : 
     304       21291 : PHP_MINIT_FUNCTION(browscap) /* {{{ */
     305             : {
     306       21291 :         char *browscap = INI_STR("browscap");
     307             : 
     308             : #ifdef ZTS
     309             :         ts_allocate_id(&browscap_globals_id, sizeof(browser_data), (ts_allocate_ctor) browscap_globals_ctor, NULL);
     310             : #endif
     311             :         /* ctor call not really needed for non-ZTS */
     312             : 
     313       21291 :         if (browscap && browscap[0]) {
     314           7 :                 if (browscap_read_file(browscap, &global_bdata, 1) == FAILURE) {
     315           0 :                         return FAILURE;
     316             :                 }
     317             :         }
     318             : 
     319       21291 :         return SUCCESS;
     320             : }
     321             : /* }}} */
     322             : 
     323       21286 : PHP_RSHUTDOWN_FUNCTION(browscap) /* {{{ */
     324             : {
     325       21286 :         browser_data *bdata = &BROWSCAP_G(activation_bdata);
     326       21286 :         if (bdata->filename[0] != '\0') {
     327           0 :                 browscap_bdata_dtor(bdata, 0);
     328             :         }
     329             : 
     330       21286 :         return SUCCESS;
     331             : }
     332             : /* }}} */
     333             : 
     334       21327 : PHP_MSHUTDOWN_FUNCTION(browscap) /* {{{ */
     335             : {
     336       21327 :         browscap_bdata_dtor(&global_bdata, 1);
     337             : 
     338       21327 :         return SUCCESS;
     339             : }
     340             : /* }}} */
     341             : 
     342      130995 : static int browser_reg_compare(zval *browser, int num_args, va_list args, zend_hash_key *key) /* {{{ */
     343             : {
     344             :         zval *browser_regex, *previous_match;
     345             :         pcre *re;
     346             :         int re_options;
     347             :         pcre_extra *re_extra;
     348      130995 :         char *lookup_browser_name = va_arg(args, char *);
     349      130995 :         int lookup_browser_length = va_arg(args, int);
     350      130995 :         zval *found_browser_entry = va_arg(args, zval *);
     351             : 
     352             :         /* See if we have an exact match, if so, we're done... */
     353      130995 :         if (Z_TYPE_P(found_browser_entry) == IS_ARRAY) {
     354       24916 :                 if ((previous_match = zend_hash_str_find(Z_ARRVAL_P(found_browser_entry), "browser_name_pattern", sizeof("browser_name_pattern")-1)) == NULL) {
     355           0 :                         return 0;
     356             :                 }
     357       24916 :                 else if (!strcasecmp(Z_STRVAL_P(previous_match), lookup_browser_name)) {
     358           0 :                         return 0;
     359             :                 }
     360             :         }
     361             : 
     362      130995 :         if ((browser_regex = zend_hash_str_find(Z_ARRVAL_P(browser), "browser_name_regex", sizeof("browser_name_regex")-1)) == NULL) {
     363           0 :                 return 0;
     364             :         }
     365             : 
     366      130995 :         re = pcre_get_compiled_regex(Z_STR_P(browser_regex), &re_extra, &re_options);
     367      130995 :         if (re == NULL) {
     368           0 :                 return 0;
     369             :         }
     370             : 
     371      130995 :         if (pcre_exec(re, re_extra, lookup_browser_name, lookup_browser_length, 0, re_options, NULL, 0) == 0) {
     372             :                 /* If we've found a possible browser, we need to do a comparison of the
     373             :                    number of characters changed in the user agent being checked versus
     374             :                    the previous match found and the current match. */
     375          91 :                 if (Z_TYPE_P(found_browser_entry) == IS_ARRAY) {
     376          50 :                         size_t i, prev_len = 0, curr_len = 0;
     377          50 :                         zval *current_match = zend_hash_str_find(Z_ARRVAL_P(browser), "browser_name_pattern", sizeof("browser_name_pattern")-1);
     378             : 
     379          50 :                         if (!current_match) {
     380           0 :                                 return 0;
     381             :                         }
     382             : 
     383        2640 :                         for (i = 0; i < Z_STRLEN_P(previous_match); i++) {
     384        2590 :                                 switch (Z_STRVAL_P(previous_match)[i]) {
     385             :                                         case '?':
     386             :                                         case '*':
     387             :                                                 /* do nothing, ignore these characters in the count */
     388         201 :                                         break;
     389             : 
     390             :                                         default:
     391        2389 :                                                 ++prev_len;
     392             :                                 }
     393             :                         }
     394             : 
     395         948 :                         for (i = 0; i < Z_STRLEN_P(current_match); i++) {
     396         898 :                                 switch (Z_STRVAL_P(current_match)[i]) {
     397             :                                         case '?':
     398             :                                         case '*':
     399             :                                                 /* do nothing, ignore these characters in the count */
     400         110 :                                         break;
     401             : 
     402             :                                         default:
     403         788 :                                                 ++curr_len;
     404             :                                 }
     405             :                         }
     406             : 
     407             :                         /* Pick which browser pattern replaces the least amount of
     408             :                            characters when compared to the original user agent string... */
     409          50 :                         if (prev_len < curr_len) {
     410           7 :                                 ZVAL_COPY_VALUE(found_browser_entry, browser);
     411             :                         }
     412             :                 }
     413             :                 else {
     414          41 :                         ZVAL_COPY_VALUE(found_browser_entry, browser);
     415             :                 }
     416             :         }
     417             : 
     418      130995 :         return 0;
     419             : }
     420             : /* }}} */
     421             : 
     422         911 : static void browscap_zval_copy_ctor(zval *p) /* {{{ */
     423             : {
     424             :         zval_copy_ctor(p);
     425         911 : }
     426             : /* }}} */
     427             : 
     428             : /* {{{ proto mixed get_browser([string browser_name [, bool return_array]])
     429             :    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. */
     430          43 : PHP_FUNCTION(get_browser)
     431             : {
     432          43 :         char *agent_name = NULL;
     433          43 :         size_t agent_name_len = 0;
     434          43 :         zend_bool return_array = 0;
     435             :         zval *agent, *z_agent_name, *http_user_agent;
     436             :         zval found_browser_entry;
     437             :         char *lookup_browser_name;
     438             :         browser_data *bdata;
     439             : 
     440          43 :         if (BROWSCAP_G(activation_bdata).filename[0] != '\0') {
     441           0 :                 bdata = &BROWSCAP_G(activation_bdata);
     442           0 :                 if (bdata->htab == NULL) { /* not initialized yet */
     443           0 :                         if (browscap_read_file(bdata->filename, bdata, 0) == FAILURE) {
     444           0 :                                 RETURN_FALSE;
     445             :                         }
     446             :                 }
     447             :         } else {
     448          43 :                 if (!global_bdata.htab) {
     449           0 :                         php_error_docref(NULL, E_WARNING, "browscap ini directive not set");
     450           0 :                         RETURN_FALSE;
     451             :                 }
     452          43 :                 bdata = &global_bdata;
     453             :         }
     454             : 
     455          43 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s!b", &agent_name, &agent_name_len, &return_array) == FAILURE) {
     456           1 :                 return;
     457             :         }
     458             : 
     459          42 :         if (agent_name == NULL) {
     460           4 :                 if ((Z_TYPE(PG(http_globals)[TRACK_VARS_SERVER]) == IS_ARRAY || zend_is_auto_global_str(ZEND_STRL("_SERVER"))) && 
     461           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
     462             :                 ) {
     463           1 :                         php_error_docref(NULL, E_WARNING, "HTTP_USER_AGENT variable is not set, cannot determine user agent name");
     464           1 :                         RETURN_FALSE;
     465             :                 }
     466           1 :                 agent_name = Z_STRVAL_P(http_user_agent);
     467           1 :                 agent_name_len = Z_STRLEN_P(http_user_agent);
     468             :         }
     469             : 
     470          41 :         lookup_browser_name = estrndup(agent_name, agent_name_len);
     471          41 :         php_strtolower(lookup_browser_name, agent_name_len);
     472             : 
     473          41 :         if ((agent = zend_hash_str_find(bdata->htab, lookup_browser_name, agent_name_len)) == NULL) {
     474          41 :                 ZVAL_UNDEF(&found_browser_entry);
     475          41 :                 zend_hash_apply_with_arguments(bdata->htab, browser_reg_compare, 3, lookup_browser_name, agent_name_len, &found_browser_entry);
     476             : 
     477          41 :                 if (Z_TYPE(found_browser_entry) != IS_UNDEF) {
     478          41 :                         agent = &found_browser_entry;
     479           0 :                 } else if ((agent = zend_hash_str_find(bdata->htab, DEFAULT_SECTION_NAME, sizeof(DEFAULT_SECTION_NAME)-1)) == NULL) {
     480           0 :                         efree(lookup_browser_name);
     481           0 :                         RETURN_FALSE;
     482             :                 }
     483             :         }
     484             : 
     485          41 :         if (return_array) {
     486          41 :                 RETVAL_ARR(zend_array_dup(Z_ARRVAL_P(agent)));
     487             :         }
     488             :         else {
     489           0 :                 object_init(return_value);
     490           0 :                 zend_hash_copy(Z_OBJPROP_P(return_value), Z_ARRVAL_P(agent), (copy_ctor_func_t) browscap_zval_copy_ctor);
     491             :         }
     492             : 
     493         142 :         while ((z_agent_name = zend_hash_str_find(Z_ARRVAL_P(agent), "parent", sizeof("parent")-1)) != NULL) {
     494          60 :                 if ((agent = zend_hash_find(bdata->htab, Z_STR_P(z_agent_name))) == NULL) {
     495           0 :                         break;
     496             :                 }
     497             : 
     498          60 :                 if (return_array) {
     499          60 :                         zend_hash_merge(Z_ARRVAL_P(return_value), Z_ARRVAL_P(agent), (copy_ctor_func_t) browscap_zval_copy_ctor, 0);
     500             :                 }
     501             :                 else {
     502           0 :                         zend_hash_merge(Z_OBJPROP_P(return_value), Z_ARRVAL_P(agent), (copy_ctor_func_t) browscap_zval_copy_ctor, 0);
     503             :                 }
     504             :         }
     505             : 
     506          41 :         efree(lookup_browser_name);
     507             : }
     508             : /* }}} */
     509             : 
     510             : /*
     511             :  * Local variables:
     512             :  * tab-width: 4
     513             :  * c-basic-offset: 4
     514             :  * End:
     515             :  * vim600: sw=4 ts=4 fdm=marker
     516             :  * vim<600: sw=4 ts=4
     517             :  */

Generated by: LCOV version 1.10

Generated at Sat, 29 Aug 2015 10:22:24 +0000 (2 days ago)

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