php-src/ext/session/mod_user.c

238 lines
5.1 KiB
C
Raw Normal View History

1999-09-17 05:40:59 +00:00
/*
+----------------------------------------------------------------------+
2004-01-08 08:18:22 +00:00
| PHP Version 5 |
1999-09-17 05:40:59 +00:00
+----------------------------------------------------------------------+
2014-01-03 03:08:10 +00:00
| Copyright (c) 1997-2014 The PHP Group |
1999-09-17 05:40:59 +00:00
+----------------------------------------------------------------------+
2006-01-01 12:51:34 +00:00
| This source file is subject to version 3.01 of the PHP license, |
1999-09-17 05:40:59 +00:00
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
2006-01-01 12:51:34 +00:00
| http://www.php.net/license/3_01.txt |
1999-09-17 05:40:59 +00:00
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
2002-02-28 08:29:35 +00:00
| Author: Sascha Schumann <sascha@schumann.cx> |
1999-09-17 05:40:59 +00:00
+----------------------------------------------------------------------+
*/
2001-06-06 14:32:27 +00:00
/* $Id$ */
1999-09-17 05:40:59 +00:00
#include "php.h"
#include "php_session.h"
#include "mod_user.h"
ps_module ps_mod_user = {
PS_MOD_SID(user)
1999-09-17 05:40:59 +00:00
};
2014-08-19 06:07:31 +00:00
#define SESS_ZVAL_INT(val, a) \
2009-05-18 16:10:09 +00:00
{ \
2014-08-19 06:07:31 +00:00
ZVAL_INT(a, val); \
1999-09-17 05:40:59 +00:00
}
2009-05-18 16:10:09 +00:00
#define SESS_ZVAL_STRING(vl, a) \
{ \
char *__vl = vl; \
SESS_ZVAL_STRINGN(__vl, strlen(__vl), a); \
1999-09-17 05:40:59 +00:00
}
2009-05-18 16:10:09 +00:00
#define SESS_ZVAL_STRINGN(vl, ln, a) \
{ \
2014-03-28 10:46:25 +00:00
ZVAL_STRINGL(a, vl, ln); \
1999-09-17 05:40:59 +00:00
}
2014-03-28 10:46:25 +00:00
#define SESS_ZVAL_STR(vl, a) \
{ \
ZVAL_STR(a, STR_COPY(vl)); \
}
static void ps_call_handler(zval *func, int argc, zval *argv, zval *retval TSRMLS_DC)
1999-09-17 05:40:59 +00:00
{
int i;
2014-03-29 12:17:59 +00:00
if (call_user_function(EG(function_table), NULL, func, retval, argc, argv TSRMLS_CC) == FAILURE) {
zval_ptr_dtor(retval);
ZVAL_UNDEF(retval);
} else if (Z_ISUNDEF_P(retval)) {
2014-03-29 12:17:59 +00:00
ZVAL_NULL(retval);
}
2000-02-11 13:41:30 +00:00
for (i = 0; i < argc; i++) {
zval_ptr_dtor(&argv[i]);
1999-09-17 05:40:59 +00:00
}
}
#define STDVARS \
2014-03-28 10:46:25 +00:00
zval retval; \
int ret = FAILURE
#define PSF(a) PS(mod_user_names).name.ps_##a
1999-09-17 05:40:59 +00:00
#define FINISH \
if (Z_TYPE(retval) != IS_UNDEF) { \
if (Z_TYPE(retval) == IS_TRUE) { \
ret = SUCCESS; \
} else if (Z_TYPE(retval) == IS_FALSE) { \
ret = FAILURE; \
2014-08-19 06:07:31 +00:00
} else if ((Z_TYPE(retval) == IS_INT) && (Z_IVAL(retval) == -1)) { \
/* BC for clever users - Deprecate me */ \
ret = FAILURE; \
2014-08-19 06:07:31 +00:00
} else if ((Z_TYPE(retval) == IS_INT) && (Z_IVAL(retval) == 0)) { \
/* BC for clever users - Deprecate me */ \
ret = SUCCESS; \
} else { \
if (!EG(exception)) { \
php_error_docref(NULL TSRMLS_CC, E_WARNING, \
"Session callback expects true/false return value"); \
} \
ret = FAILURE; \
zval_ptr_dtor(&retval); \
} \
} \
1999-09-17 05:40:59 +00:00
return ret
PS_OPEN_FUNC(user)
{
2014-03-28 10:46:25 +00:00
zval args[2];
STDVARS;
if (Z_ISUNDEF(PSF(open))) {
php_error_docref(NULL TSRMLS_CC, E_WARNING,
"user session functions not defined");
return FAILURE;
}
2009-05-18 16:10:09 +00:00
2014-03-28 10:46:25 +00:00
SESS_ZVAL_STRING((char*)save_path, &args[0]);
SESS_ZVAL_STRING((char*)session_name, &args[1]);
2009-05-18 16:10:09 +00:00
2014-03-28 10:46:25 +00:00
ps_call_handler(&PSF(open), 2, args, &retval TSRMLS_CC);
PS(mod_user_implemented) = 1;
2009-05-18 16:10:09 +00:00
1999-09-17 05:40:59 +00:00
FINISH;
}
PS_CLOSE_FUNC(user)
{
zend_bool bailout = 0;
STDVARS;
1999-09-17 05:40:59 +00:00
if (!PS(mod_user_implemented)) {
/* already closed */
return SUCCESS;
}
1999-09-17 05:40:59 +00:00
zend_try {
2014-03-28 10:46:25 +00:00
ps_call_handler(&PSF(close), 0, NULL, &retval TSRMLS_CC);
} zend_catch {
bailout = 1;
} zend_end_try();
2012-08-14 17:25:31 +00:00
PS(mod_user_implemented) = 0;
if (bailout) {
if (!Z_ISUNDEF(retval)) {
zval_ptr_dtor(&retval);
}
zend_bailout();
}
1999-09-17 05:40:59 +00:00
FINISH;
}
PS_READ_FUNC(user)
{
2014-03-28 10:46:25 +00:00
zval args[1];
1999-09-17 05:40:59 +00:00
STDVARS;
2014-03-28 10:46:25 +00:00
SESS_ZVAL_STR(key, &args[0]);
1999-09-17 05:40:59 +00:00
2014-03-28 10:46:25 +00:00
ps_call_handler(&PSF(read), 1, args, &retval TSRMLS_CC);
2009-05-18 16:10:09 +00:00
if (!Z_ISUNDEF(retval)) {
2014-03-28 10:46:25 +00:00
if (Z_TYPE(retval) == IS_STRING) {
*val = STR_COPY(Z_STR(retval));
1999-09-17 05:40:59 +00:00
ret = SUCCESS;
}
zval_ptr_dtor(&retval);
1999-09-17 05:40:59 +00:00
}
return ret;
}
PS_WRITE_FUNC(user)
{
2014-03-28 10:46:25 +00:00
zval args[2];
1999-09-17 05:40:59 +00:00
STDVARS;
2009-05-18 16:10:09 +00:00
2014-03-28 10:46:25 +00:00
SESS_ZVAL_STR(key, &args[0]);
SESS_ZVAL_STR(val, &args[1]);
1999-09-17 05:40:59 +00:00
2014-03-28 10:46:25 +00:00
ps_call_handler(&PSF(write), 2, args, &retval TSRMLS_CC);
1999-09-17 05:40:59 +00:00
FINISH;
}
PS_DESTROY_FUNC(user)
{
2014-03-28 10:46:25 +00:00
zval args[1];
1999-09-17 05:40:59 +00:00
STDVARS;
2014-03-28 10:46:25 +00:00
SESS_ZVAL_STR(key, &args[0]);
1999-09-17 05:40:59 +00:00
2014-03-28 10:46:25 +00:00
ps_call_handler(&PSF(destroy), 1, args, &retval TSRMLS_CC);
1999-09-17 05:40:59 +00:00
FINISH;
}
PS_GC_FUNC(user)
{
2014-03-28 10:46:25 +00:00
zval args[1];
1999-09-17 05:40:59 +00:00
STDVARS;
2014-08-19 06:07:31 +00:00
SESS_ZVAL_INT(maxlifetime, &args[0]);
1999-09-17 05:40:59 +00:00
2014-03-28 10:46:25 +00:00
ps_call_handler(&PSF(gc), 1, args, &retval TSRMLS_CC);
1999-09-17 05:40:59 +00:00
FINISH;
}
2001-06-06 14:32:27 +00:00
PS_CREATE_SID_FUNC(user)
{
/* maintain backwards compatibility */
if (!Z_ISUNDEF(PSF(create_sid))) {
2014-03-28 10:46:25 +00:00
zend_string *id = NULL;
zval retval;
2014-03-28 10:46:25 +00:00
ps_call_handler(&PSF(create_sid), 0, NULL, &retval TSRMLS_CC);
if (!Z_ISUNDEF(retval)) {
2014-03-28 10:46:25 +00:00
if (Z_TYPE(retval) == IS_STRING) {
id = STR_COPY(Z_STR(retval));
}
zval_ptr_dtor(&retval);
2014-03-28 10:46:25 +00:00
} else {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "No session id returned by function");
return NULL;
}
if (!id) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Session id must be a string");
return NULL;
}
return id;
}
/* function as defined by PS_MOD */
2014-03-28 10:46:25 +00:00
return php_session_create_id(mod_data TSRMLS_CC);
}
2001-06-06 14:32:27 +00:00
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: sw=4 ts=4 fdm=marker
* vim<600: sw=4 ts=4
2001-06-06 14:32:27 +00:00
*/