20
20
#include "config.h"
21
21
#endif
22
22
#include "php_soap.h"
23
- #if defined(HAVE_PHP_SESSION ) && !defined(COMPILE_DL_SESSION )
24
23
#include "ext/session/php_session.h"
25
- #endif
26
24
#include "soap_arginfo.h"
27
25
#include "zend_exceptions.h"
28
26
#include "zend_interfaces.h"
29
27
#include "ext/standard/php_incomplete_class.h"
30
28
29
+ /* We only have session support if PHP was configured with session support
30
+ * or if the session module could be loaded dynamically, which will only
31
+ * work if soap is loaded dynamically as well. */
32
+ #if defined(HAVE_PHP_SESSION ) || defined(COMPILE_DL_SOAP )
33
+ # define SOAP_HAS_SESSION_SUPPORT
34
+ #endif
35
+
31
36
typedef struct _soapHeader {
32
37
sdlFunctionPtr function ;
33
38
zval function_name ;
@@ -298,6 +303,7 @@ PHP_MINFO_FUNCTION(soap);
298
303
static const zend_module_dep soap_deps [] = {
299
304
ZEND_MOD_REQUIRED ("date" )
300
305
ZEND_MOD_REQUIRED ("libxml" )
306
+ ZEND_MOD_OPTIONAL ("session" )
301
307
ZEND_MOD_END
302
308
};
303
309
@@ -995,6 +1001,12 @@ PHP_METHOD(SoapServer, setPersistence)
995
1001
if (service -> type == SOAP_CLASS ) {
996
1002
if (value == SOAP_PERSISTENCE_SESSION ||
997
1003
value == SOAP_PERSISTENCE_REQUEST ) {
1004
+ if (value == SOAP_PERSISTENCE_SESSION && !zend_hash_str_exists (& module_registry , "session" , sizeof ("session" )- 1 )) {
1005
+ SOAP_SERVER_END_CODE ();
1006
+ zend_throw_error (NULL , "SoapServer::setPersistence(): Session persistence cannot be enabled because the session module is not enabled" );
1007
+ RETURN_THROWS ();
1008
+ }
1009
+
998
1010
service -> soap_class .persistence = value ;
999
1011
} else {
1000
1012
zend_argument_value_error (
@@ -1406,22 +1418,18 @@ PHP_METHOD(SoapServer, handle)
1406
1418
soap_obj = & service -> soap_object ;
1407
1419
function_table = & ((Z_OBJCE_P (soap_obj ))-> function_table );
1408
1420
} else if (service -> type == SOAP_CLASS ) {
1409
- #if defined( HAVE_PHP_SESSION ) && !defined( COMPILE_DL_SESSION )
1410
- /* If persistent then set soap_obj from from the previous created session (if available) */
1421
+ /* If persistent then set soap_obj from the previous created session (if available) */
1422
+ #ifdef SOAP_HAS_SESSION_SUPPORT
1411
1423
if (service -> soap_class .persistence == SOAP_PERSISTENCE_SESSION ) {
1412
- zval * session_vars , * tmp_soap_p ;
1413
-
1414
- if (PS (session_status ) != php_session_active &&
1415
- PS (session_status ) != php_session_disabled ) {
1424
+ php_session_status session_status = php_get_session_status ();
1425
+ if (session_status != php_session_active &&
1426
+ session_status != php_session_disabled ) {
1416
1427
php_session_start ();
1417
1428
}
1418
1429
1419
1430
/* Find the soap object and assign */
1420
- session_vars = & PS (http_session_vars );
1421
- ZVAL_DEREF (session_vars );
1422
- if (Z_TYPE_P (session_vars ) == IS_ARRAY &&
1423
- (tmp_soap_p = zend_hash_str_find (Z_ARRVAL_P (session_vars ), "_bogus_session_name" , sizeof ("_bogus_session_name" )- 1 )) != NULL &&
1424
- Z_TYPE_P (tmp_soap_p ) == IS_OBJECT ) {
1431
+ zval * tmp_soap_p = php_get_session_var_str ("_bogus_session_name" , sizeof ("_bogus_session_name" )- 1 );
1432
+ if (tmp_soap_p != NULL && Z_TYPE_P (tmp_soap_p ) == IS_OBJECT ) {
1425
1433
if (EXPECTED (Z_OBJCE_P (tmp_soap_p ) == service -> soap_class .ce )) {
1426
1434
soap_obj = tmp_soap_p ;
1427
1435
} else if (Z_OBJCE_P (tmp_soap_p ) == php_ce_incomplete_class ) {
@@ -1431,9 +1439,9 @@ PHP_METHOD(SoapServer, handle)
1431
1439
}
1432
1440
}
1433
1441
#endif
1442
+
1434
1443
/* If new session or something weird happned */
1435
1444
if (soap_obj == NULL ) {
1436
-
1437
1445
object_init_ex (& tmp_soap , service -> soap_class .ce );
1438
1446
1439
1447
/* Call constructor */
@@ -1448,25 +1456,23 @@ PHP_METHOD(SoapServer, handle)
1448
1456
goto fail ;
1449
1457
}
1450
1458
}
1451
- #if defined( HAVE_PHP_SESSION ) && !defined( COMPILE_DL_SESSION )
1459
+
1452
1460
/* If session then update session hash with new object */
1461
+ #ifdef SOAP_HAS_SESSION_SUPPORT
1453
1462
if (service -> soap_class .persistence == SOAP_PERSISTENCE_SESSION ) {
1454
- zval * session_vars = & PS (http_session_vars ), * tmp_soap_p ;
1455
-
1456
- ZVAL_DEREF (session_vars );
1457
- if (Z_TYPE_P (session_vars ) == IS_ARRAY &&
1458
- (tmp_soap_p = zend_hash_str_update (Z_ARRVAL_P (session_vars ), "_bogus_session_name" , sizeof ("_bogus_session_name" )- 1 , & tmp_soap )) != NULL ) {
1463
+ zend_string * session_var_name = ZSTR_INIT_LITERAL ("_bogus_session_name" , false);
1464
+ zval * tmp_soap_p = php_set_session_var (session_var_name , & tmp_soap , NULL );
1465
+ if (tmp_soap_p != NULL ) {
1459
1466
soap_obj = tmp_soap_p ;
1460
1467
} else {
1461
1468
soap_obj = & tmp_soap ;
1462
1469
}
1463
- } else {
1470
+ zend_string_release_ex (session_var_name , false);
1471
+ } else
1472
+ #endif
1473
+ {
1464
1474
soap_obj = & tmp_soap ;
1465
1475
}
1466
- #else
1467
- soap_obj = & tmp_soap ;
1468
- #endif
1469
-
1470
1476
}
1471
1477
function_table = & ((Z_OBJCE_P (soap_obj ))-> function_table );
1472
1478
} else {
@@ -1534,15 +1540,10 @@ PHP_METHOD(SoapServer, handle)
1534
1540
if (service -> type == SOAP_CLASS || service -> type == SOAP_OBJECT ) {
1535
1541
call_status = call_user_function (NULL , soap_obj , & function_name , & retval , num_params , params );
1536
1542
if (service -> type == SOAP_CLASS ) {
1537
- #if defined(HAVE_PHP_SESSION ) && !defined(COMPILE_DL_SESSION )
1538
1543
if (service -> soap_class .persistence != SOAP_PERSISTENCE_SESSION ) {
1539
1544
zval_ptr_dtor (soap_obj );
1540
1545
soap_obj = NULL ;
1541
1546
}
1542
- #else
1543
- zval_ptr_dtor (soap_obj );
1544
- soap_obj = NULL ;
1545
- #endif
1546
1547
}
1547
1548
} else {
1548
1549
call_status = call_user_function (EG (function_table ), NULL , & function_name , & retval , num_params , params );
@@ -1557,11 +1558,7 @@ PHP_METHOD(SoapServer, handle)
1557
1558
php_output_discard ();
1558
1559
_soap_server_exception (service , function , ZEND_THIS );
1559
1560
if (service -> type == SOAP_CLASS ) {
1560
- #if defined(HAVE_PHP_SESSION ) && !defined(COMPILE_DL_SESSION )
1561
1561
if (soap_obj && service -> soap_class .persistence != SOAP_PERSISTENCE_SESSION ) {
1562
- #else
1563
- if (soap_obj ) {
1564
- #endif
1565
1562
zval_ptr_dtor (soap_obj );
1566
1563
}
1567
1564
}
@@ -1597,11 +1594,7 @@ PHP_METHOD(SoapServer, handle)
1597
1594
php_output_discard ();
1598
1595
_soap_server_exception (service , function , ZEND_THIS );
1599
1596
if (service -> type == SOAP_CLASS ) {
1600
- #if defined(HAVE_PHP_SESSION ) && !defined(COMPILE_DL_SESSION )
1601
1597
if (soap_obj && service -> soap_class .persistence != SOAP_PERSISTENCE_SESSION ) {
1602
- #else
1603
- if (soap_obj ) {
1604
- #endif
1605
1598
zval_ptr_dtor (soap_obj );
1606
1599
}
1607
1600
}
0 commit comments