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/session - mod_user_class.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 39 65 60.0 %
Date: 2019-10-17 Functions: 7 9 77.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 7                                                        |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1997-2018 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: Arpad Ray <arpad@php.net>                                    |
      16             :    +----------------------------------------------------------------------+
      17             :  */
      18             : 
      19             : /* $Id$ */
      20             : 
      21             : #include "php.h"
      22             : #include "php_session.h"
      23             : 
      24             : #define PS_SANITY_CHECK                                         \
      25             :         if (PS(session_status) != php_session_active) { \
      26             :                 php_error_docref(NULL, E_WARNING, "Session is not active"); \
      27             :                 RETURN_FALSE; \
      28             :         } \
      29             :         if (PS(default_mod) == NULL) {                          \
      30             :                 php_error_docref(NULL, E_CORE_ERROR, "Cannot call default session handler"); \
      31             :                 RETURN_FALSE;                                           \
      32             :         }
      33             : 
      34             : #define PS_SANITY_CHECK_IS_OPEN                         \
      35             :         PS_SANITY_CHECK; \
      36             :         if (!PS(mod_user_is_open)) {                    \
      37             :                 php_error_docref(NULL, E_WARNING, "Parent session handler is not open");      \
      38             :                 RETURN_FALSE;                                           \
      39             :         }
      40             : 
      41             : /* {{{ proto bool SessionHandler::open(string save_path, string session_name)
      42             :    Wraps the old open handler */
      43          30 : PHP_METHOD(SessionHandler, open)
      44             : {
      45          30 :         char *save_path = NULL, *session_name = NULL;
      46             :         size_t save_path_len, session_name_len;
      47             :         int ret;
      48             : 
      49          36 :         PS_SANITY_CHECK;
      50             : 
      51          25 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &save_path, &save_path_len, &session_name, &session_name_len) == FAILURE) {
      52           1 :                 return;
      53             :         }
      54             : 
      55          24 :         PS(mod_user_is_open) = 1;
      56             : 
      57          24 :         zend_try {
      58          24 :                 ret = PS(default_mod)->s_open(&PS(mod_data), save_path, session_name);
      59           0 :         } zend_catch {
      60           0 :                 PS(session_status) = php_session_none;
      61           0 :                 zend_bailout();
      62          24 :         } zend_end_try();
      63             : 
      64          24 :         RETVAL_BOOL(SUCCESS == ret);
      65             : }
      66             : /* }}} */
      67             : 
      68             : /* {{{ proto bool SessionHandler::close()
      69             :    Wraps the old close handler */
      70          26 : PHP_METHOD(SessionHandler, close)
      71             : {
      72             :         int ret;
      73             : 
      74          26 :         PS_SANITY_CHECK_IS_OPEN;
      75             : 
      76             :         // don't return on failure, since not closing the default handler
      77             :         // could result in memory leaks or other nasties
      78          24 :         zend_parse_parameters_none();
      79             : 
      80          24 :         PS(mod_user_is_open) = 0;
      81             : 
      82          24 :         zend_try {
      83          24 :                 ret = PS(default_mod)->s_close(&PS(mod_data));
      84           0 :         } zend_catch {
      85           0 :                 PS(session_status) = php_session_none;
      86           0 :                 zend_bailout();
      87          24 :         } zend_end_try();
      88             : 
      89          24 :         RETVAL_BOOL(SUCCESS == ret);
      90             : }
      91             : /* }}} */
      92             : 
      93             : /* {{{ proto bool SessionHandler::read(string id)
      94             :    Wraps the old read handler */
      95          27 : PHP_METHOD(SessionHandler, read)
      96             : {
      97             :         zend_string *val;
      98             :         zend_string *key;
      99             : 
     100          27 :         PS_SANITY_CHECK_IS_OPEN;
     101             : 
     102          24 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &key) == FAILURE) {
     103           0 :                 return;
     104             :         }
     105             : 
     106          24 :         if (PS(default_mod)->s_read(&PS(mod_data), key, &val, PS(gc_maxlifetime)) == FAILURE) {
     107           0 :                 RETURN_FALSE;
     108             :         }
     109             : 
     110          24 :         RETURN_STR(val);
     111             : }
     112             : /* }}} */
     113             : 
     114             : /* {{{ proto bool SessionHandler::write(string id, string data)
     115             :    Wraps the old write handler */
     116          24 : PHP_METHOD(SessionHandler, write)
     117             : {
     118             :         zend_string *key, *val;
     119             : 
     120          24 :         PS_SANITY_CHECK_IS_OPEN;
     121             : 
     122          23 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS", &key, &val) == FAILURE) {
     123           0 :                 return;
     124             :         }
     125             : 
     126          23 :         RETURN_BOOL(SUCCESS == PS(default_mod)->s_write(&PS(mod_data), key, val, PS(gc_maxlifetime)));
     127             : }
     128             : /* }}} */
     129             : 
     130             : /* {{{ proto bool SessionHandler::destroy(string id)
     131             :    Wraps the old destroy handler */
     132           1 : PHP_METHOD(SessionHandler, destroy)
     133             : {
     134             :         zend_string *key;
     135             : 
     136           1 :         PS_SANITY_CHECK_IS_OPEN;
     137             : 
     138           1 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &key) == FAILURE) {
     139           0 :                 return;
     140             :         }
     141             : 
     142           1 :         RETURN_BOOL(SUCCESS == PS(default_mod)->s_destroy(&PS(mod_data), key));
     143             : }
     144             : /* }}} */
     145             : 
     146             : /* {{{ proto bool SessionHandler::gc(int maxlifetime)
     147             :    Wraps the old gc handler */
     148           1 : PHP_METHOD(SessionHandler, gc)
     149             : {
     150             :         zend_long maxlifetime;
     151           1 :         zend_long nrdels = -1;
     152             : 
     153           1 :         PS_SANITY_CHECK_IS_OPEN;
     154             : 
     155           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &maxlifetime) == FAILURE) {
     156           0 :                 return;
     157             :         }
     158             : 
     159           0 :         if (PS(default_mod)->s_gc(&PS(mod_data), maxlifetime, &nrdels) == FAILURE) {
     160           0 :                 RETURN_FALSE;
     161             :         }
     162           0 :         RETURN_LONG(nrdels);
     163             : }
     164             : /* }}} */
     165             : 
     166             : /* {{{ proto char SessionHandler::create_sid()
     167             :    Wraps the old create_sid handler */
     168          19 : PHP_METHOD(SessionHandler, create_sid)
     169             : {
     170             :         zend_string *id;
     171             : 
     172          19 :         PS_SANITY_CHECK;
     173             : 
     174          18 :         if (zend_parse_parameters_none() == FAILURE) {
     175           0 :             return;
     176             :         }
     177             : 
     178          18 :         id = PS(default_mod)->s_create_sid(&PS(mod_data));
     179             : 
     180          18 :         RETURN_STR(id);
     181             : }
     182             : /* }}} */
     183             : 
     184             : /* {{{ proto char SessionUpdateTimestampHandler::validateId(string id)
     185             :    Simply return TRUE */
     186           0 : PHP_METHOD(SessionHandler, validateId)
     187             : {
     188             :         zend_string *key;
     189             : 
     190           0 :         PS_SANITY_CHECK_IS_OPEN;
     191             : 
     192           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &key) == FAILURE) {
     193           0 :                 return;
     194             :         }
     195             : 
     196             :         /* Legacy save handler may not support validate_sid API. Return TRUE. */
     197           0 :         RETURN_TRUE;
     198             : }
     199             : /* }}} */
     200             : 
     201             : /* {{{ proto bool SessionUpdateTimestampHandler::updateTimestamp(string id, string data)
     202             :    Simply call update_timestamp */
     203           0 : PHP_METHOD(SessionHandler, updateTimestamp)
     204             : {
     205             :         zend_string *key, *val;
     206             : 
     207           0 :         PS_SANITY_CHECK_IS_OPEN;
     208             : 
     209           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS", &key, &val) == FAILURE) {
     210           0 :                 return;
     211             :         }
     212             : 
     213             :         /* Legacy save handler may not support update_timestamp API. Just write. */
     214           0 :         RETVAL_BOOL(SUCCESS == PS(default_mod)->s_write(&PS(mod_data), key, val, PS(gc_maxlifetime)));
     215             : }
     216             : /* }}} */

Generated by: LCOV version 1.10

Generated at Thu, 17 Oct 2019 23:21:25 +0000 (2 days ago)

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