You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

182 lines
4.0 KiB

25 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2009 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: Sascha Schumann <sascha@schumann.cx> |
  16. +----------------------------------------------------------------------+
  17. */
  18. /* $Id$ */
  19. #include "php.h"
  20. #include "php_session.h"
  21. #include "mod_user.h"
  22. ps_module ps_mod_user = {
  23. PS_MOD(user)
  24. };
  25. #define SESS_ZVAL_LONG(val, a) \
  26. { \
  27. MAKE_STD_ZVAL(a); \
  28. ZVAL_LONG(a, val); \
  29. }
  30. #define SESS_ZVAL_STRING(vl, a) \
  31. { \
  32. char *__vl = vl; \
  33. SESS_ZVAL_STRINGN(__vl, strlen(__vl), a); \
  34. }
  35. #define SESS_ZVAL_STRINGN(vl, ln, a) \
  36. { \
  37. MAKE_STD_ZVAL(a); \
  38. ZVAL_STRINGL(a, vl, ln, 1); \
  39. }
  40. static zval *ps_call_handler(zval *func, int argc, zval **argv TSRMLS_DC)
  41. {
  42. int i;
  43. zval *retval = NULL;
  44. MAKE_STD_ZVAL(retval);
  45. if (call_user_function(EG(function_table), NULL, func, retval, argc, argv TSRMLS_CC) == FAILURE) {
  46. zval_ptr_dtor(&retval);
  47. retval = NULL;
  48. }
  49. for (i = 0; i < argc; i++) {
  50. zval_ptr_dtor(&argv[i]);
  51. }
  52. return retval;
  53. }
  54. #define STDVARS1 \
  55. zval *retval; \
  56. int ret = FAILURE
  57. #define STDVARS \
  58. STDVARS1; \
  59. char *mdata = PS_GET_MOD_DATA(); \
  60. if (!mdata) { return FAILURE; }
  61. #define PSF(a) PS(mod_user_names).name.ps_##a
  62. #define FINISH \
  63. if (retval) { \
  64. convert_to_long(retval); \
  65. ret = Z_LVAL_P(retval); \
  66. zval_ptr_dtor(&retval); \
  67. } \
  68. return ret
  69. PS_OPEN_FUNC(user)
  70. {
  71. zval *args[2];
  72. static char dummy = 0;
  73. STDVARS1;
  74. SESS_ZVAL_STRING((char*)save_path, args[0]);
  75. SESS_ZVAL_STRING((char*)session_name, args[1]);
  76. retval = ps_call_handler(PSF(open), 2, args TSRMLS_CC);
  77. if (retval) {
  78. /* This is necessary to fool the session module. Yes, it's safe to
  79. * use a static. Neither mod_user nor the session module itself will
  80. * ever touch this pointer. It could be set to 0xDEADBEEF for all the
  81. * difference it makes, but for the sake of paranoia it's set to some
  82. * valid value. */
  83. PS_SET_MOD_DATA(&dummy);
  84. }
  85. FINISH;
  86. }
  87. PS_CLOSE_FUNC(user)
  88. {
  89. STDVARS1;
  90. retval = ps_call_handler(PSF(close), 0, NULL TSRMLS_CC);
  91. PS_SET_MOD_DATA(NULL);
  92. FINISH;
  93. }
  94. PS_READ_FUNC(user)
  95. {
  96. zval *args[1];
  97. STDVARS;
  98. SESS_ZVAL_STRING((char*)key, args[0]);
  99. retval = ps_call_handler(PSF(read), 1, args TSRMLS_CC);
  100. if (retval) {
  101. if (Z_TYPE_P(retval) == IS_STRING) {
  102. *val = estrndup(Z_STRVAL_P(retval), Z_STRLEN_P(retval));
  103. *vallen = Z_STRLEN_P(retval);
  104. ret = SUCCESS;
  105. }
  106. zval_ptr_dtor(&retval);
  107. }
  108. return ret;
  109. }
  110. PS_WRITE_FUNC(user)
  111. {
  112. zval *args[2];
  113. STDVARS;
  114. SESS_ZVAL_STRING((char*)key, args[0]);
  115. SESS_ZVAL_STRINGN((char*)val, vallen, args[1]);
  116. retval = ps_call_handler(PSF(write), 2, args TSRMLS_CC);
  117. FINISH;
  118. }
  119. PS_DESTROY_FUNC(user)
  120. {
  121. zval *args[1];
  122. STDVARS;
  123. SESS_ZVAL_STRING((char*)key, args[0]);
  124. retval = ps_call_handler(PSF(destroy), 1, args TSRMLS_CC);
  125. FINISH;
  126. }
  127. PS_GC_FUNC(user)
  128. {
  129. zval *args[1];
  130. STDVARS;
  131. SESS_ZVAL_LONG(maxlifetime, args[0]);
  132. retval = ps_call_handler(PSF(gc), 1, args TSRMLS_CC);
  133. FINISH;
  134. }
  135. /*
  136. * Local variables:
  137. * tab-width: 4
  138. * c-basic-offset: 4
  139. * End:
  140. * vim600: sw=4 ts=4 fdm=marker
  141. * vim<600: sw=4 ts=4
  142. */