|
| 1 | +/* |
| 2 | + +----------------------------------------------------------------------+ |
| 3 | + | PHP Version 5 | |
| 4 | + +----------------------------------------------------------------------+ |
| 5 | + | Copyright (c) 1997-2011 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(default_mod) == NULL) { \ |
| 26 | + php_error_docref(NULL TSRMLS_CC, E_CORE_ERROR, "Called default SessionHandler but session.save_handler is user"); \ |
| 27 | + RETURN_FALSE; \ |
| 28 | + } |
| 29 | + |
| 30 | +#define PS_SANITY_CHECK_IS_OPEN \ |
| 31 | + PS_SANITY_CHECK; \ |
| 32 | + if (!PS(mod_user_is_open)) { \ |
| 33 | + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Parent session handler is not open"); \ |
| 34 | + RETURN_FALSE; \ |
| 35 | + } |
| 36 | + |
| 37 | +/* {{{ proto bool SessionHandler::open(string save_path, string session_name) |
| 38 | + Wraps the old open handler */ |
| 39 | +PHP_METHOD(SessionHandler, open) |
| 40 | +{ |
| 41 | + char *save_path = NULL, *session_name = NULL; |
| 42 | + int save_path_len, session_name_len; |
| 43 | + |
| 44 | + PS_SANITY_CHECK; |
| 45 | + |
| 46 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &save_path, &save_path_len, &session_name, &session_name_len) == FAILURE) { |
| 47 | + return; |
| 48 | + } |
| 49 | + |
| 50 | + PS(mod_user_is_open) = 1; |
| 51 | + RETVAL_LONG(PS(default_mod)->s_open(&PS(mod_data), save_path, session_name TSRMLS_CC)); |
| 52 | +} |
| 53 | +/* }}} */ |
| 54 | + |
| 55 | +/* {{{ proto bool SessionHandler::close() |
| 56 | + Wraps the old close handler */ |
| 57 | +PHP_METHOD(SessionHandler, close) |
| 58 | +{ |
| 59 | + PS_SANITY_CHECK_IS_OPEN; |
| 60 | + |
| 61 | + // don't return on failure, since not closing the default handler |
| 62 | + // could result in memory leaks or other nasties |
| 63 | + zend_parse_parameters_none(); |
| 64 | + |
| 65 | + PS(mod_user_is_open) = 0; |
| 66 | + RETVAL_LONG(PS(default_mod)->s_close(&PS(mod_data) TSRMLS_CC)); |
| 67 | +} |
| 68 | +/* }}} */ |
| 69 | + |
| 70 | +/* {{{ proto bool SessionHandler::read(string id) |
| 71 | + Wraps the old read handler */ |
| 72 | +PHP_METHOD(SessionHandler, read) |
| 73 | +{ |
| 74 | + char *key, *val; |
| 75 | + int key_len, val_len; |
| 76 | + |
| 77 | + PS_SANITY_CHECK_IS_OPEN; |
| 78 | + |
| 79 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &key, &key_len) == FAILURE) { |
| 80 | + return; |
| 81 | + } |
| 82 | + |
| 83 | + if (PS(default_mod)->s_read(&PS(mod_data), key, &val, &val_len TSRMLS_CC) == FAILURE) { |
| 84 | + RETVAL_FALSE; |
| 85 | + return; |
| 86 | + } |
| 87 | + |
| 88 | + RETVAL_STRINGL(val, val_len, 1); |
| 89 | + efree(val); |
| 90 | + return; |
| 91 | +} |
| 92 | +/* }}} */ |
| 93 | + |
| 94 | +/* {{{ proto bool SessionHandler::write(string id, string data) |
| 95 | + Wraps the old write handler */ |
| 96 | +PHP_METHOD(SessionHandler, write) |
| 97 | +{ |
| 98 | + char *key, *val; |
| 99 | + int key_len, val_len; |
| 100 | + |
| 101 | + PS_SANITY_CHECK_IS_OPEN; |
| 102 | + |
| 103 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &key, &key_len, &val, &val_len) == FAILURE) { |
| 104 | + return; |
| 105 | + } |
| 106 | + |
| 107 | + RETVAL_LONG(PS(default_mod)->s_write(&PS(mod_data), key, val, val_len TSRMLS_CC)); |
| 108 | +} |
| 109 | +/* }}} */ |
| 110 | + |
| 111 | +/* {{{ proto bool SessionHandler::destroy(string id) |
| 112 | + Wraps the old destroy handler */ |
| 113 | +PHP_METHOD(SessionHandler, destroy) |
| 114 | +{ |
| 115 | + char *key; |
| 116 | + int key_len; |
| 117 | + |
| 118 | + PS_SANITY_CHECK_IS_OPEN; |
| 119 | + |
| 120 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &key, &key_len) == FAILURE) { |
| 121 | + return; |
| 122 | + } |
| 123 | + |
| 124 | + PS(mod_user_is_open) = 0; |
| 125 | + RETVAL_LONG(PS(default_mod)->s_destroy(&PS(mod_data), key TSRMLS_CC)); |
| 126 | +} |
| 127 | +/* }}} */ |
| 128 | + |
| 129 | +/* {{{ proto bool SessionHandler::gc(int maxlifetime) |
| 130 | + Wraps the old gc handler */ |
| 131 | +PHP_METHOD(SessionHandler, gc) |
| 132 | +{ |
| 133 | + long maxlifetime; |
| 134 | + int nrdels; |
| 135 | + |
| 136 | + PS_SANITY_CHECK; |
| 137 | + |
| 138 | + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &maxlifetime) == FAILURE) { |
| 139 | + return; |
| 140 | + } |
| 141 | + |
| 142 | + RETVAL_LONG(PS(default_mod)->s_gc(&PS(mod_data), maxlifetime, &nrdels TSRMLS_CC)); |
| 143 | +} |
| 144 | +/* }}} */ |
0 commit comments