Skip to content

Commit

Permalink
Expose oci_unregister_taf_callback()
Browse files Browse the repository at this point in the history
  • Loading branch information
cjbj committed Jul 26, 2017
1 parent 3fd7d81 commit de65a22
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 23 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ PHP NEWS
. Fixed bug #74968 (PHP crashes when calling mysqli_result::fetch_object with
an abstract class). (Anatol)

- OCI8:
. Expose oci_unregister_taf_callback() (Tianfang Yang)

- SimpleXML:
. Fixed bug #74950 (nullpointer deref in simplexml_element_getDocNamespaces).
(Laruence)
Expand Down
8 changes: 7 additions & 1 deletion ext/oci8/oci8.c
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_oci_register_taf_callback, 0, 0, 1)
ZEND_ARG_INFO(0, connection_resource)
ZEND_ARG_INFO(0, function_name)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_oci_unregister_taf_callback, 0, 0, 1)
ZEND_ARG_INFO(0, connection_resource)
ZEND_END_ARG_INFO()
/* }}} */

/* {{{ LOB Method arginfo */
Expand Down Expand Up @@ -707,6 +711,7 @@ PHP_FUNCTION(oci_collection_size);
PHP_FUNCTION(oci_collection_max);
PHP_FUNCTION(oci_collection_trim);
PHP_FUNCTION(oci_register_taf_callback);
PHP_FUNCTION(oci_unregister_taf_callback);
/* }}} */

/* {{{ extension definition structures
Expand Down Expand Up @@ -790,6 +795,7 @@ static const zend_function_entry php_oci_functions[] = {
PHP_FE(oci_collection_trim, arginfo_oci_collection_trim)
PHP_FE(oci_new_collection, arginfo_oci_new_collection)
PHP_FE(oci_register_taf_callback, arginfo_oci_register_taf_callback)
PHP_FE(oci_unregister_taf_callback, arginfo_oci_unregister_taf_callback)

PHP_FALIAS(oci_free_cursor, oci_free_statement, arginfo_oci_free_statement)
PHP_FALIAS(ocifreecursor, oci_free_statement, arginfo_oci_free_statement)
Expand Down Expand Up @@ -2702,7 +2708,7 @@ static int php_oci_persistent_helper(zval *zv)

/* Remove TAF callback function as it's bound to current request */
if (connection->used_this_request && !Z_ISUNDEF(connection->taf_callback) && !Z_ISNULL(connection->taf_callback)) {
php_oci_disable_taf_callback(connection);
php_oci_unregister_taf_callback(connection);
}

if (!connection->used_this_request && OCI_G(persistent_timeout) != -1) {
Expand Down
25 changes: 13 additions & 12 deletions ext/oci8/oci8_failover.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,29 +40,30 @@
#include "php_oci8.h"
#include "php_oci8_int.h"

/* {{{ callback_fn()
/* {{{ callback_fn()
OCI TAF callback function, calling userspace function */
sb4 callback_fn(OCISvcCtx *svchp, OCIEnv *envhp, php_oci_connection *fo_ctx, ub4 fo_type, ub4 fo_event)
sb4 callback_fn(void *svchp, void *envhp, void *fo_ctx, ub4 fo_type, ub4 fo_event)
{
/* Create zval */
zval retval, params[3];
php_oci_connection *connection = (php_oci_connection*)fo_ctx;

/* Default return value */
sb4 returnValue = 0;

/* Check if userspace callback function was disabled */
if (Z_ISUNDEF(fo_ctx->taf_callback) || Z_ISNULL(fo_ctx->taf_callback)) {
/* Check if userspace callback function was unregistered */
if (Z_ISUNDEF(connection->taf_callback) || Z_ISNULL(connection->taf_callback)) {
return 0;
}

/* Initialize zval */
ZVAL_RES(&params[0], fo_ctx->id);
ZVAL_RES(&params[0], connection->id);
ZVAL_LONG(&params[1], fo_event);
ZVAL_LONG(&params[2], fo_type);

/* Call user function (if possible) */
if (call_user_function(EG(function_table), NULL, &fo_ctx->taf_callback, &retval, 3, params) == FAILURE) {
php_error_docref(NULL, E_WARNING, "Unable to call taf callback function, is it defined?");
if (call_user_function(EG(function_table), NULL, &connection->taf_callback, &retval, 3, params) == FAILURE) {
php_error_docref(NULL, E_WARNING, "Unable to call Oracle TAF callback function");
}

/* Set return value */
Expand All @@ -83,10 +84,10 @@ sb4 callback_fn(OCISvcCtx *svchp, OCIEnv *envhp, php_oci_connection *fo_ctx, ub4
}
/* }}} */

/* {{{ php_oci_disable_taf_callback()
Disables the userspace callback function for Oracle TAF,
/* {{{ php_oci_unregister_taf_callback()
Unregister the userspace callback function for Oracle TAF,
while keeping the OCI callback alive */
int php_oci_disable_taf_callback(php_oci_connection *connection)
int php_oci_unregister_taf_callback(php_oci_connection *connection)
{
return php_oci_register_taf_callback(connection, NULL);
}
Expand All @@ -103,9 +104,9 @@ int php_oci_register_taf_callback(php_oci_connection *connection, zval *callback
OCIFocbkStruct failover;

if (!callback) {
/* Disable callback */
/* Unregister callback */
if (Z_ISUNDEF(connection->taf_callback) || Z_ISNULL(connection->taf_callback)) {
return 0; // Nothing to disable
return 0; // Nothing to unregister
}

registered = 1;
Expand Down
25 changes: 23 additions & 2 deletions ext/oci8/oci8_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,27 @@ PHP_FUNCTION(oci_register_taf_callback)
}
/* }}} */

/* {{{ proto bool oci_unregister_taf_callback( resource connection )
* Unregister a callback function for Oracle Transparent Application Failover (TAF) */
PHP_FUNCTION(oci_unregister_taf_callback)
{
zval *z_connection;
php_oci_connection *connection;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &z_connection) == FAILURE) {
return;
}

PHP_OCI_ZVAL_TO_CONNECTION(z_connection, connection);

if (php_oci_unregister_taf_callback(connection) == 0) {
RETURN_TRUE;
} else {
RETURN_FALSE;
}
}
/* }}} */

/* {{{ proto bool oci_define_by_name(resource stmt, string name, mixed &var [, int type])
Define a PHP variable to an Oracle column by name */
/* if you want to define a LOB/CLOB etc make sure you allocate it via OCINewDescriptor BEFORE defining!!! */
Expand Down Expand Up @@ -1587,8 +1608,8 @@ PHP_FUNCTION(oci_close)
RefCount value by 1 */
zend_list_close(connection->id);

/* Disable Oracle TAF */
php_oci_disable_taf_callback(connection);
/* Unregister Oracle TAF */
php_oci_unregister_taf_callback(connection);

/* ZVAL_NULL(z_connection); */

Expand Down
22 changes: 19 additions & 3 deletions ext/oci8/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ Interoperability Support" (ID 207303.1) for details.
<time>12:00:00</time>

<version>
<release>2.1.6</release>
<api>2.1.6</api>
<release>2.1.7</release>
<api>2.1.7</api>
</version>
<stability>
<release>stable</release>
Expand All @@ -60,7 +60,7 @@ Interoperability Support" (ID 207303.1) for details.
<license uri="http://www.php.net/license">PHP</license>
<notes>
This version is for PHP 7 only.
Fixed bug #74625 (Integer overflow in oci_bind_array_by_name). (Ingmar Runge)
Added oci_unregister_taf_callback()
</notes>
<contents>
<dir name="/">
Expand Down Expand Up @@ -470,6 +470,22 @@ Fixed bug #74625 (Integer overflow in oci_bind_array_by_name). (Ingmar Runge)
</extsrcrelease>
<changelog>

<release>
<version>
<release>2.1.6</release>
<api>2.1.6</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<license uri="http://www.php.net/license">PHP</license>
<notes>
This version is for PHP 7 only.
Fixed bug #74625 (Integer overflow in oci_bind_array_by_name). (Ingmar Runge)
</notes>
</release>

<release>
<version>
<release>2.1.5</release>
Expand Down
2 changes: 1 addition & 1 deletion ext/oci8/php_oci8.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
*/
#undef PHP_OCI8_VERSION
#endif
#define PHP_OCI8_VERSION "2.1.6"
#define PHP_OCI8_VERSION "2.1.7"

extern zend_module_entry oci8_module_entry;
#define phpext_oci8_ptr &oci8_module_entry
Expand Down
2 changes: 1 addition & 1 deletion ext/oci8/php_oci8_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ ZEND_END_MODULE_GLOBALS(oci) /* }}} */
/* {{{ transparent failover related prototypes */

int php_oci_register_taf_callback(php_oci_connection *connection, zval *callback);
int php_oci_disable_taf_callback(php_oci_connection *connection);
int php_oci_unregister_taf_callback(php_oci_connection *connection);

/* }}} */

Expand Down
6 changes: 3 additions & 3 deletions ext/oci8/tests/driver_name.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ function get_attr($conn)
?>
--EXPECT--
**Test 1.1 - Default values for the attribute **************
The value of DRIVER_NAME is PHP OCI8 : 2.1.6
The value of DRIVER_NAME is PHP OCI8 : 2.1.7

***Test 1.2 - Get the values from different connections **************
Testing with oci_pconnect()
The value of DRIVER_NAME is PHP OCI8 : 2.1.6
The value of DRIVER_NAME is PHP OCI8 : 2.1.7
Testing with oci_new_connect()
The value of DRIVER_NAME is PHP OCI8 : 2.1.6
The value of DRIVER_NAME is PHP OCI8 : 2.1.7
Done

0 comments on commit de65a22

Please sign in to comment.