-
Notifications
You must be signed in to change notification settings - Fork 8k
oci8 - Implementation of Oracle TAF Callback (PHP7) #2459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9e28a67
Merge remote-tracking branch 'refs/remotes/php/master'
KoenigsKind 822b4f8
oci8 - Implementation of Oracle TAF Callback
KoenigsKind bc8cb6d
Syntax changes
KoenigsKind 6a06678
zval instead of char* and modified config.m4
KoenigsKind 283cc0d
Implemented second state to prevent double callback registration
KoenigsKind 8d240df
Swapped return value
KoenigsKind File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| /* | ||
| +----------------------------------------------------------------------+ | ||
| | PHP Version 5 | | ||
| +----------------------------------------------------------------------+ | ||
| | Copyright (c) 1997-2016 The PHP Group | | ||
| +----------------------------------------------------------------------+ | ||
| | This source file is subject to version 3.01 of the PHP license, | | ||
| | that is bundled with this package in the file LICENSE, and is | | ||
| | available through the world-wide-web at the following url: | | ||
| | http://www.php.net/license/3_01.txt | | ||
| | 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 | | ||
| | [email protected] so we can mail you a copy immediately. | | ||
| +----------------------------------------------------------------------+ | ||
| | Authors: Stig Sæther Bakken <[email protected]> | | ||
| | Thies C. Arntzen <[email protected]> | | ||
| | | | ||
| | Collection support by Andy Sautins <[email protected]> | | ||
| | Temporary LOB support by David Benson <[email protected]> | | ||
| | ZTS per process OCIPLogon by Harald Radi <[email protected]> | | ||
| | | | ||
| | Redesigned by: Antony Dovgal <[email protected]> | | ||
| | Andi Gutmans <[email protected]> | | ||
| | Wez Furlong <[email protected]> | | ||
| +----------------------------------------------------------------------+ | ||
| */ | ||
|
|
||
|
|
||
|
|
||
| #ifdef HAVE_CONFIG_H | ||
| #include "config.h" | ||
| #endif | ||
|
|
||
| #include "php.h" | ||
| #include "ext/standard/info.h" | ||
| #include "php_ini.h" | ||
|
|
||
| #if HAVE_OCI8 | ||
|
|
||
| #include "php_oci8.h" | ||
| #include "php_oci8_int.h" | ||
|
|
||
| /* {{{ 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) | ||
| { | ||
| /* Create zval */ | ||
| zval retval, params[3]; | ||
|
|
||
| /* 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)) { | ||
| return 0; | ||
| } | ||
|
|
||
| /* Initialize zval */ | ||
| ZVAL_RES(¶ms[0], fo_ctx->id); | ||
| ZVAL_LONG(¶ms[1], fo_event); | ||
| ZVAL_LONG(¶ms[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?"); | ||
| } | ||
|
|
||
| /* Set return value */ | ||
| if (Z_TYPE(retval) == IS_LONG) { | ||
| returnValue = (sb4) Z_LVAL(retval); | ||
| } | ||
|
|
||
| /* Setting params[0] to null so ressource isn't destroyed on zval_dtor */ | ||
| ZVAL_NULL(¶ms[0]); | ||
|
|
||
| /* Cleanup */ | ||
| zval_dtor(&retval); | ||
| zval_dtor(¶ms[0]); | ||
| zval_dtor(¶ms[1]); | ||
| zval_dtor(¶ms[2]); | ||
|
|
||
| return returnValue; | ||
| } | ||
| /* }}} */ | ||
|
|
||
| /* {{{ php_oci_disable_taf_callback() | ||
| Disables the userspace callback function for Oracle TAF, | ||
| while keeping the OCI callback alive */ | ||
| int php_oci_disable_taf_callback(php_oci_connection *connection) | ||
| { | ||
| return php_oci_register_taf_callback(connection, NULL); | ||
| } | ||
| /* }}} */ | ||
|
|
||
| /* {{{ php_oci_register_taf_callback() | ||
| Register a callback function for Oracle TAF */ | ||
| int php_oci_register_taf_callback(php_oci_connection *connection, zval *callback) | ||
| { | ||
| sword errstatus; | ||
| int registered = 0; | ||
|
|
||
| /* temporary failover callback structure */ | ||
| OCIFocbkStruct failover; | ||
|
|
||
| if (!callback) { | ||
| /* Disable callback */ | ||
| if (Z_ISUNDEF(connection->taf_callback) || Z_ISNULL(connection->taf_callback)) { | ||
| return 0; // Nothing to disable | ||
| } | ||
|
|
||
| registered = 1; | ||
| zval_ptr_dtor(&connection->taf_callback); | ||
| ZVAL_NULL(&connection->taf_callback); | ||
| } else { | ||
| if (!Z_ISUNDEF(connection->taf_callback)) { | ||
| registered = 1; | ||
| if (!Z_ISNULL(connection->taf_callback)) { | ||
| zval_ptr_dtor(&connection->taf_callback); | ||
| ZVAL_NULL(&connection->taf_callback); | ||
| } | ||
| } | ||
|
|
||
| /* Set userspace callback function */ | ||
| ZVAL_COPY(&connection->taf_callback, callback); | ||
| } | ||
|
|
||
| /* OCI callback function already registered */ | ||
| if (registered) { | ||
| return 0; | ||
| } | ||
|
|
||
| /* set context */ | ||
| failover.fo_ctx = connection; | ||
|
|
||
| /* set callback function */ | ||
| failover.callback_function = &callback_fn; | ||
|
|
||
| /* do the registration */ | ||
| PHP_OCI_CALL_RETURN(errstatus, OCIAttrSet, (connection->server, (ub4) OCI_HTYPE_SERVER, (void *) &failover, (ub4) 0, (ub4) OCI_ATTR_FOCBK, connection->err)); | ||
|
|
||
| if (errstatus != OCI_SUCCESS) { | ||
| zval_ptr_dtor(&connection->taf_callback); | ||
| ZVAL_UNDEF(&connection->taf_callback); | ||
| connection->errcode = php_oci_error(connection->err, errstatus); | ||
| return 1; | ||
| } | ||
|
|
||
| /* successful conclusion */ | ||
| return 0; | ||
| } | ||
| /* }}} */ | ||
|
|
||
| #endif /* HAVE_OCI8 */ | ||
|
|
||
| /* | ||
| * Local variables: | ||
| * tab-width: 4 | ||
| * c-basic-offset: 4 | ||
| * End: | ||
| * vim600: noet sw=4 ts=4 fdm=marker | ||
| * vim<600: noet sw=4 ts=4 | ||
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we return bool instead of int here to align with other oci8 functions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took a look at the other functions, do you mean to still return an int, but to return 1 on success and 0 on failure?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My mistake. I was looking at the wrong prototype. For php_oci functions, it should return an int and return 0 on success and 1 on failure. Sorry I misled you.