Merge pull request #9 from microsoft/adjust_design2_add_preferred_new
Adjust design2 add preferred new without cache change
This commit is contained in:
Коммит
2e5c33fdaf
22
Notes.txt
22
Notes.txt
|
@ -9,7 +9,23 @@ connection, and use the new one afterward.
|
||||||
+---------------------------+
|
+---------------------------+
|
||||||
OPTION DESCRIPTION
|
OPTION DESCRIPTION
|
||||||
------------------ ----------------------------------------------------------
|
------------------ ----------------------------------------------------------
|
||||||
mysqlnd_azure.enabled This option is to control enable or disable mysqlnd_rd.
|
mysqlnd_azure.enableRedirect This option is to control enable or disable redirection feature of mysqlnd_azure.
|
||||||
If this is set to 0, it will not use redirection.
|
If this is set to off, it will not use redirection.
|
||||||
(Default: 0)
|
|
||||||
|
|
||||||
|
Available option values:
|
||||||
|
(Default: preferred)
|
||||||
|
---------------|------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
off(0) | - It will not use redirection.
|
||||||
|
---------------|------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
on(1) | - If ssl is off, no connection will be made, return error:
|
||||||
|
| "mysqlnd_azure.enableRedirect is on, but SSL option is not set in connection string. Redirection is only possible with SSL."
|
||||||
|
| - If on server side redirection is not available, abort the first connection and return error:
|
||||||
|
| "Connection aborted because redirection is not enabled on the MySQL server or the network package doesn't meet meet redirection protocol."
|
||||||
|
| - If server supports redirection, but the redirected connection failed for any reason, also abort the first proxy connection.
|
||||||
|
| Return the error of the redirected connection.
|
||||||
|
---------------|------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
preferred(2) | - it will use redirection if possible.
|
||||||
|
| - If connection does not use SSL, or server does not support redirection, or redirected connection fails
|
||||||
|
| to connect for any non-fatal reason while the proxy connection is still a valid one, it will fallback
|
||||||
|
| to the first proxy connection.
|
||||||
|
---------------|------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
60
README.md
60
README.md
|
@ -3,6 +3,51 @@ The source code here is a PHP extension implemented using mysqlnd plugin API (ht
|
||||||
|
|
||||||
**Important notice: There is a limitation that for Azure MySQL, redirection is only possible when the connection is configured with SSL, and it will only support TLS 1.2 with FIPS approved cipher for redirection.**
|
**Important notice: There is a limitation that for Azure MySQL, redirection is only possible when the connection is configured with SSL, and it will only support TLS 1.2 with FIPS approved cipher for redirection.**
|
||||||
|
|
||||||
|
## Option Usage
|
||||||
|
**Before 1.1.0**, the option is with name **mysqlnd_azure.enabled**. Valid values are on/off, and the option "on" supports fallback logic. The detailed usage of the option enableRedirect is as follows:
|
||||||
|
|
||||||
|
(Version before 1.1.0. Config name: **mysqlnd_azure.enabled**. Valid value: on/off. Default value: off)
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td>off(0)</td>
|
||||||
|
<td> - It will not use redirection. </td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>on(1)</td>
|
||||||
|
<td> - It will use redirection if possible (Connection is with SSL and Server supports/needs redirection).</br>
|
||||||
|
- If connection does not use SSL, or server does not support redirection, or redirected connection fails to connect for any non-fatal reason while the proxy connection is still a valid one, it will fallback to the first proxy connection.
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
**Since 1.1.0**, the logic changes as follows:
|
||||||
|
- The option mysqlnd_azure.enabled is renamed to **mysqlnd_azure.enableRedirect**, option "on" enforces redirection, and there is a new option value "preferred" provided which becomes the default option.
|
||||||
|
- The detailed usage of the option enableRedirect is as follows:
|
||||||
|
|
||||||
|
(Version 1.1.0. Config name: **mysqlnd_azure.enableRedirect**. Valid value: on/off/preferred. Default value: preferred)
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td>off(0)</td>
|
||||||
|
<td> - It will not use redirection. </td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>on(1)</td>
|
||||||
|
<td> - If SSL is off, no connection will be made, return error:
|
||||||
|
<i>"mysqlnd_azure.enableRedirect is on, but SSL option is not set in connection string. Redirection is only possible with SSL."</i></br>
|
||||||
|
- If on server side redirection is not supported, abort the first connection and return error: <i>"Connection aborted because redirection is not enabled on the MySQL server or the network package doesn't meet meet redirection protocol."</i></br>
|
||||||
|
- If server supports redirection, but the redirected connection failed for any reason, also abort the first proxy connection. Return the error of the redirected connection.
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
preferred(2)
|
||||||
|
</td>
|
||||||
|
<td> - It will use redirection if possible.</br>
|
||||||
|
- If connection does not use SSL, or server does not support redirection, or redirected connection fails to connect for any non-fatal reason while the proxy connection is still a valid one, it will fallback to the first proxy connection.
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
## Name and Extension Version
|
## Name and Extension Version
|
||||||
Extension name: **mysqlnd_azure**
|
Extension name: **mysqlnd_azure**
|
||||||
|
|
||||||
|
@ -15,6 +60,12 @@ Valid version:
|
||||||
- 1.0.3RC Change: fix the crash problem when working with PDO interface with flag PDO::ATTR_PERSISTENT=>false.
|
- 1.0.3RC Change: fix the crash problem when working with PDO interface with flag PDO::ATTR_PERSISTENT=>false.
|
||||||
This version is marked as beta, so please use *pecl install mysqlnd_azure-1.0.3RC* to install when using pecl.
|
This version is marked as beta, so please use *pecl install mysqlnd_azure-1.0.3RC* to install when using pecl.
|
||||||
- 1.0.3 Change: Remove the use of is_using_redirect flag. More strict validation and new test cases with php built-in web server.
|
- 1.0.3 Change: Remove the use of is_using_redirect flag. More strict validation and new test cases with php built-in web server.
|
||||||
|
- 1.1.0 Change:
|
||||||
|
1. Rename option mysqlnd_azure.enabled to mysqlnd_azure.enableRedirect, and add a new option value "preferred".
|
||||||
|
2. When enableRedirect is "preferred", it will use redirection if possible. If connection does not use SSL, or server does not support redirection, or redirected connection fails to connect for any non-fatal reason while the proxy connection is still a valid one, it will fallback to the first proxy connection.
|
||||||
|
3. When enableRedirect is "on", SSL is off, no connection will be made, return error "mysqlnd_azure.enableRedirect is on, but SSL option is not set in connection string. Redirection is only possible with SSL."
|
||||||
|
4. When enableRedirect is "on", but on server side redirection is not supported, abort the first connection and return error "Connection aborted because redirection is not enabled on the MySQL server or the network package doesn't meet meet redirection protocol."
|
||||||
|
5. When enableRedirect is "on" and server supports redirection, but the redirected connection failed for any reason, also abort the first proxy connection. Return the error of the redirected connection.
|
||||||
|
|
||||||
Following is a brief guide of how to install using pecl or build and test the extension from source.
|
Following is a brief guide of how to install using pecl or build and test the extension from source.
|
||||||
|
|
||||||
|
@ -93,7 +144,8 @@ Then you can run **make install** to put the .so to your php so library. However
|
||||||
- put mysqlnd_azure.so under extension_dir.
|
- put mysqlnd_azure.so under extension_dir.
|
||||||
- under directory for additional .ini files, you will find the ini files for the common used modules, e.g. 10-mysqlnd.ini for mysqlnd, 20-mysqli.ini for mysqli. Create a new ini file for mysqlnd_azure here. **Make sure the alphabet order of the name is after that of mysqnld**, since the modules are loaded according to the name order of the ini files. E.g. if mysqlnd ini is with name 10-mysqlnd.ini,then name the ini as 20-mysqlnd-azure.ini. In the ini file, add the following two lines:
|
- under directory for additional .ini files, you will find the ini files for the common used modules, e.g. 10-mysqlnd.ini for mysqlnd, 20-mysqli.ini for mysqli. Create a new ini file for mysqlnd_azure here. **Make sure the alphabet order of the name is after that of mysqnld**, since the modules are loaded according to the name order of the ini files. E.g. if mysqlnd ini is with name 10-mysqlnd.ini,then name the ini as 20-mysqlnd-azure.ini. In the ini file, add the following two lines:
|
||||||
- extension=mysqlnd_azure
|
- extension=mysqlnd_azure
|
||||||
- mysqlnd_azure.enabled = on ; you can also set this to off to disable redirection
|
- mysqlnd_azure.enableRedirect = on/off/preferred
|
||||||
|
- **Notice:** since 1.1.0, if this value is set to on, the connection must be configured with SSL, and it requires server support redirection. Otherwise, the connection will fail. Please check the Option Usage section for detailed information.
|
||||||
|
|
||||||
|
|
||||||
## Step to build on Windows
|
## Step to build on Windows
|
||||||
|
@ -139,15 +191,17 @@ After this, the code directory should look like C:\php-sdk\phpdev\vc15\x64\php-s
|
||||||
- extension=mysqlnd_azure
|
- extension=mysqlnd_azure
|
||||||
- Under the Module Settings section add:
|
- Under the Module Settings section add:
|
||||||
- [mysqlnd_azure]
|
- [mysqlnd_azure]
|
||||||
- mysqlnd_azure.enabled = on
|
- mysqlnd_azure.enableRedirect = on/off/preferred
|
||||||
|
- **Notice:** since 1.1.0, if this value is set to on, the connection must be configured with SSL, and it requires server support redirection. Otherwise, the connection will fail. Please check the Option Usage section for detailed information.
|
||||||
|
|
||||||
|
|
||||||
## Test
|
## Test
|
||||||
* Currently redirection is only possible when the connection is via ssl, and it need that the redirection feature switch is enabled on server side. Following is a snippet to test connection with redirection:
|
* Currently redirection is only possible when the connection is via ssl, and it need that the redirection feature switch is enabled on server side. Following is a snippet to test connection with redirection:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
echo "mysqlnd_azure.enabled: ", ini_get("mysqlnd_azure.enabled") == true?"On":"Off", "\n";
|
echo "mysqlnd_azure.enableRedirect: ", ini_get("mysqlnd_azure.enableRedirect"), "\n";
|
||||||
$db = mysqli_init();
|
$db = mysqli_init();
|
||||||
|
//The connection must be configured with SSL for redirection test
|
||||||
$link = mysqli_real_connect ($db, 'your-hostname-with-redirection-enabled', 'user@host', 'password', "db", 3306, NULL, MYSQLI_CLIENT_SSL);
|
$link = mysqli_real_connect ($db, 'your-hostname-with-redirection-enabled', 'user@host', 'password', "db", 3306, NULL, MYSQLI_CLIENT_SSL);
|
||||||
if (!$link) {
|
if (!$link) {
|
||||||
die ('Connect error (' . mysqli_connect_errno() . '): ' . mysqli_connect_error() . "\n");
|
die ('Connect error (' . mysqli_connect_errno() . '): ' . mysqli_connect_error() . "\n");
|
||||||
|
|
899
mysqlnd_azure.c
899
mysqlnd_azure.c
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -36,6 +36,8 @@ typedef struct st_mysqlnd_azure_redirect_info {
|
||||||
#define MAX_REDIRECT_HOST_LEN 128
|
#define MAX_REDIRECT_HOST_LEN 128
|
||||||
#define MAX_REDIRECT_USER_LEN 128
|
#define MAX_REDIRECT_USER_LEN 128
|
||||||
|
|
||||||
|
#define MYSQLND_AZURE_ENFORCE_REDIRECT_ERROR_NO CR_NOT_IMPLEMENTED
|
||||||
|
|
||||||
void mysqlnd_azure_minit_register_hooks();
|
void mysqlnd_azure_minit_register_hooks();
|
||||||
|
|
||||||
enum_func_status mysqlnd_azure_add_redirect_cache(const char* user, const char* host, int port, const char* redirect_user, const char* redirect_host, int redirect_port);
|
enum_func_status mysqlnd_azure_add_redirect_cache(const char* user, const char* host, int port, const char* redirect_user, const char* redirect_host, int redirect_port);
|
||||||
|
|
42
package.xml
42
package.xml
|
@ -16,11 +16,11 @@
|
||||||
<email>Qianqian.Bu@microsoft.com</email>
|
<email>Qianqian.Bu@microsoft.com</email>
|
||||||
<active>yes</active>
|
<active>yes</active>
|
||||||
</lead>
|
</lead>
|
||||||
<date>2020-02-10</date>
|
<date>2020-02-14</date>
|
||||||
<time>15:00:13</time>
|
<time>15:00:13</time>
|
||||||
<version>
|
<version>
|
||||||
<release>1.0.3</release>
|
<release>1.1.0</release>
|
||||||
<api>1.0.3</api>
|
<api>1.1.0</api>
|
||||||
</version>
|
</version>
|
||||||
<stability>
|
<stability>
|
||||||
<release>stable</release>
|
<release>stable</release>
|
||||||
|
@ -28,7 +28,13 @@
|
||||||
</stability>
|
</stability>
|
||||||
<license uri="http://www.php.net/license">PHP License</license>
|
<license uri="http://www.php.net/license">PHP License</license>
|
||||||
<notes>
|
<notes>
|
||||||
- Remove the use of is_using_redirect flag. More strict validation and test cases with php built-in web server.
|
- 1. Rename option mysqlnd_azure.enabled to mysqlnd_azure.enableRedirect.
|
||||||
|
- 2. Add a new option choice "preferred".
|
||||||
|
- 3. When enableRedirect is "on", ssl is off, no connection will be made, return error "mysqlnd_azure.enableRedirect is on, but SSL option is not set in connection string. Redirection is only possible with SSL."
|
||||||
|
- 4. When enableRedirect is "on", but on server side redirection is not available, abort the first connection and return error "Connection aborted because redirection is not enabled on the MySQL server or the network package doesn't meet meet redirection protocol."
|
||||||
|
- 5. When enableRedirect is "on" and server supports redirection, but the redirected connection failed for any reason, also abort the first proxy connection. Return the error of the redirected connection.
|
||||||
|
- 6. When enableRedirect is "preferred", it will use redirection if possible.
|
||||||
|
If connection does not use SSL, or server does not support redirection, or redirected connection fails to connect for any non-fatal reason while the proxy connection is still a valid one, it will fallback to the first proxy connection.
|
||||||
</notes>
|
</notes>
|
||||||
<contents>
|
<contents>
|
||||||
<dir name="/">
|
<dir name="/">
|
||||||
|
@ -39,11 +45,13 @@
|
||||||
<file md5sum="81379d753b8268922e3e3dd8c11c803c" name="redirect_cache.c" role="src" />
|
<file md5sum="81379d753b8268922e3e3dd8c11c803c" name="redirect_cache.c" role="src" />
|
||||||
<file md5sum="f6ce2d3ccfaa1d8e53196f9df9043b35" name="mysqlnd_azure.h" role="src" />
|
<file md5sum="f6ce2d3ccfaa1d8e53196f9df9043b35" name="mysqlnd_azure.h" role="src" />
|
||||||
<file md5sum="207e117afe26f28a75d83776e88d7ee0" name="php_mysqlnd_azure.h" role="src" />
|
<file md5sum="207e117afe26f28a75d83776e88d7ee0" name="php_mysqlnd_azure.h" role="src" />
|
||||||
<file md5sum="1d60dd2a72d2d9a325e68070b7fd0fbf" name="tests/mysqli_azure_redirection_enabled.phpt" role="test" />
|
<file md5sum="1d60dd2a72d2d9a325e68070b7fd0fbf" name="tests/mysqli_azure_redirection_on.phpt" role="test" />
|
||||||
<file md5sum="a678a17b08f337292c0471b26be405f5" name="tests/mysqli_azure_redirection_disabled.phpt" role="test" />
|
<file md5sum="a678a17b08f337292c0471b26be405f5" name="tests/mysqli_azure_redirection_off.phpt" role="test" />
|
||||||
|
<file md5sum="a678a17b08f337292c0471b26be405f5" name="tests/mysqli_azure_redirection_preferred.phpt" role="test" />
|
||||||
|
<file md5sum="a678a17b08f337292c0471b26be405f5" name="tests/mysqli_azure_option_test.phpt" role="test" />
|
||||||
<file md5sum="271878ad9afcd0f4304529ff9522e034" name="tests/connect.inc" role="test" />
|
<file md5sum="271878ad9afcd0f4304529ff9522e034" name="tests/connect.inc" role="test" />
|
||||||
<file md5sum="d621e9a3ad808225480ee11b361338ad" name="tests/skipif.inc" role="test" />
|
<file md5sum="d621e9a3ad808225480ee11b361338ad" name="tests/skipif.inc" role="test" />
|
||||||
<file md5sum="841204de228db4ea0150bf7289956163" name="tests/skipifconnectfailure.inc" role="test" />
|
<file md5sum="841204de228db4ea0150bf7289956163" name="tests/skipif_mysqli.inc" role="test" />
|
||||||
<file md5sum="c5ac2a622a1ad2ecbb1a80fddb1ea774" name="tests/server.inc" role="test" />
|
<file md5sum="c5ac2a622a1ad2ecbb1a80fddb1ea774" name="tests/server.inc" role="test" />
|
||||||
<file md5sum="ee9b26d984fe6024f9ee9d6c162b3a1d" name="tests/skipif_pdo.inc" role="test" />
|
<file md5sum="ee9b26d984fe6024f9ee9d6c162b3a1d" name="tests/skipif_pdo.inc" role="test" />
|
||||||
<file md5sum="9ecaa780d20d362faeae7df543a0d38f" name="tests/skipif_server.inc" role="test" />
|
<file md5sum="9ecaa780d20d362faeae7df543a0d38f" name="tests/skipif_server.inc" role="test" />
|
||||||
|
@ -72,6 +80,26 @@
|
||||||
<providesextension>mysqlnd_azure</providesextension>
|
<providesextension>mysqlnd_azure</providesextension>
|
||||||
<extsrcrelease />
|
<extsrcrelease />
|
||||||
<changelog>
|
<changelog>
|
||||||
|
<release>
|
||||||
|
<version>
|
||||||
|
<release>1.1.0</release>
|
||||||
|
<api>1.1.0</api>
|
||||||
|
</version>
|
||||||
|
<stability>
|
||||||
|
<release>beta</release>
|
||||||
|
<api>beta</api>
|
||||||
|
</stability>
|
||||||
|
<date>2020-02-15</date>
|
||||||
|
<license uri="http://www.php.net/license">PHP License</license>
|
||||||
|
<notes>
|
||||||
|
- 1. Rename option mysqlnd_azure.enabled to mysqlnd_azure.enableRedirect, and add a new option value "preferred".
|
||||||
|
- 2. When enableRedirect is "on", ssl is off, no connection will be made, return error "mysqlnd_azure.enableRedirect is on, but SSL option is not set in connection string. Redirection is only possible with SSL."
|
||||||
|
- 3. When enableRedirect is "on", but on server side redirection is not available, abort the first connection and return error "Connection aborted because redirection is not enabled on the MySQL server or the network package doesn't meet meet redirection protocol."
|
||||||
|
- 4. When enableRedirect is "on" and server supports redirection, but the redirected connection failed for any reason, also abort the first proxy connection. Return the error of the redirected connection.
|
||||||
|
- 5. A new option for mysqlnd_azure.enableRedirect is introduced with name "preferred". When enableRedirect is "preferred", it will use redirection if possible.
|
||||||
|
If connection does not use SSL, or server does not support redirection, or redirected connection fails to connect for any non-fatal reason while the proxy connection is still a valid one, it will fallback to the first proxy connection.
|
||||||
|
</notes>
|
||||||
|
</release>
|
||||||
<release>
|
<release>
|
||||||
<version>
|
<version>
|
||||||
<release>1.0.3</release>
|
<release>1.0.3</release>
|
||||||
|
|
|
@ -28,13 +28,45 @@
|
||||||
|
|
||||||
ZEND_DECLARE_MODULE_GLOBALS(mysqlnd_azure)
|
ZEND_DECLARE_MODULE_GLOBALS(mysqlnd_azure)
|
||||||
|
|
||||||
|
/* {{{ OnUpdateEnableRedirect */
|
||||||
|
static ZEND_INI_MH(OnUpdateEnableRedirect)
|
||||||
|
{
|
||||||
|
if (STRING_EQUALS(new_value,"preferred")
|
||||||
|
|| STRING_EQUALS(new_value, "2")) {
|
||||||
|
|
||||||
|
MYSQLND_AZURE_G(enableRedirect) = REDIRECT_PREFERRED;
|
||||||
|
|
||||||
|
} else if (STRING_EQUALS(new_value, "on")
|
||||||
|
|| STRING_EQUALS(new_value, "yes")
|
||||||
|
|| STRING_EQUALS(new_value, "true")
|
||||||
|
|| STRING_EQUALS(new_value, "1")) {
|
||||||
|
|
||||||
|
MYSQLND_AZURE_G(enableRedirect) = REDIRECT_ON;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
MYSQLND_AZURE_G(enableRedirect) = REDIRECT_OFF;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return SUCCESS;
|
||||||
|
|
||||||
|
}
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
|
/* {{{ PHP_INI */
|
||||||
|
PHP_INI_BEGIN()
|
||||||
|
STD_PHP_INI_ENTRY("mysqlnd_azure.enableRedirect", "preferred", PHP_INI_ALL, OnUpdateEnableRedirect, enableRedirect, zend_mysqlnd_azure_globals, mysqlnd_azure_globals)
|
||||||
|
PHP_INI_END()
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ PHP_GINIT_FUNCTION */
|
/* {{{ PHP_GINIT_FUNCTION */
|
||||||
static PHP_GINIT_FUNCTION(mysqlnd_azure)
|
static PHP_GINIT_FUNCTION(mysqlnd_azure)
|
||||||
{
|
{
|
||||||
#if defined(COMPILE_DL_MYSQLND_AZURE) && defined(ZTS)
|
#if defined(COMPILE_DL_MYSQLND_AZURE) && defined(ZTS)
|
||||||
ZEND_TSRMLS_CACHE_UPDATE();
|
ZEND_TSRMLS_CACHE_UPDATE();
|
||||||
#endif
|
#endif
|
||||||
mysqlnd_azure_globals->enabled = 0;
|
mysqlnd_azure_globals->enableRedirect = REDIRECT_PREFERRED;
|
||||||
mysqlnd_azure_globals->redirectCache = NULL;
|
mysqlnd_azure_globals->redirectCache = NULL;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
@ -50,17 +82,6 @@ static PHP_GSHUTDOWN_FUNCTION(mysqlnd_azure)
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ PHP_INI */
|
|
||||||
/*
|
|
||||||
It is handy to allow users to disable any mysqlnd plugin globally - not only for debugging :-)
|
|
||||||
Because we register our plugin in MINIT changes to mysqlnd_ed.enabled shall be bound to
|
|
||||||
INI_SYSTEM (and PHP restarts).
|
|
||||||
*/
|
|
||||||
PHP_INI_BEGIN()
|
|
||||||
STD_PHP_INI_ENTRY("mysqlnd_azure.enabled", "0", PHP_INI_ALL, OnUpdateBool, enabled, zend_mysqlnd_azure_globals, mysqlnd_azure_globals)
|
|
||||||
PHP_INI_END()
|
|
||||||
/* }}} */
|
|
||||||
|
|
||||||
/* {{{ PHP_MINIT_FUNCTION
|
/* {{{ PHP_MINIT_FUNCTION
|
||||||
*/
|
*/
|
||||||
static PHP_MINIT_FUNCTION(mysqlnd_azure)
|
static PHP_MINIT_FUNCTION(mysqlnd_azure)
|
||||||
|
@ -87,8 +108,8 @@ static PHP_MSHUTDOWN_FUNCTION(mysqlnd_azure)
|
||||||
PHP_MINFO_FUNCTION(mysqlnd_azure)
|
PHP_MINFO_FUNCTION(mysqlnd_azure)
|
||||||
{
|
{
|
||||||
php_info_print_table_start();
|
php_info_print_table_start();
|
||||||
php_info_print_table_header(2, "mysqlnd_azure", "enabled");
|
php_info_print_table_header(2, "mysqlnd_azure", "enableRedirect");
|
||||||
php_info_print_table_row(2, "enabled", MYSQLND_AZURE_G(enabled)? "Yes":"No");
|
php_info_print_table_row(2, "enableRedirect", MYSQLND_AZURE_G(enableRedirect) == REDIRECT_OFF ? "off" : (MYSQLND_AZURE_G(enableRedirect) == REDIRECT_ON ? "on" : "preferred"));
|
||||||
php_info_print_table_end();
|
php_info_print_table_end();
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
@ -103,14 +124,14 @@ zend_module_entry mysqlnd_azure_module_entry = {
|
||||||
STANDARD_MODULE_HEADER_EX,
|
STANDARD_MODULE_HEADER_EX,
|
||||||
NULL,
|
NULL,
|
||||||
mysqlnd_azure_deps,
|
mysqlnd_azure_deps,
|
||||||
EXT_MYSQLND_AZURE_NAME,
|
PHP_MYSQLND_AZURE_NAME,
|
||||||
NULL,
|
NULL,
|
||||||
PHP_MINIT(mysqlnd_azure),
|
PHP_MINIT(mysqlnd_azure),
|
||||||
PHP_MSHUTDOWN(mysqlnd_azure),
|
PHP_MSHUTDOWN(mysqlnd_azure),
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
PHP_MINFO(mysqlnd_azure),
|
PHP_MINFO(mysqlnd_azure),
|
||||||
EXT_MYSQLND_AZURE_VERSION,
|
PHP_MYSQLND_AZURE_VERSION,
|
||||||
PHP_MODULE_GLOBALS(mysqlnd_azure),
|
PHP_MODULE_GLOBALS(mysqlnd_azure),
|
||||||
PHP_GINIT(mysqlnd_azure),
|
PHP_GINIT(mysqlnd_azure),
|
||||||
PHP_GSHUTDOWN(mysqlnd_azure),
|
PHP_GSHUTDOWN(mysqlnd_azure),
|
||||||
|
|
|
@ -28,12 +28,20 @@
|
||||||
extern zend_module_entry mysqlnd_azure_module_entry;
|
extern zend_module_entry mysqlnd_azure_module_entry;
|
||||||
#define phpext_mysqlnd_azure_ptr &mysqlnd_azure_module_entry
|
#define phpext_mysqlnd_azure_ptr &mysqlnd_azure_module_entry
|
||||||
|
|
||||||
#define EXT_MYSQLND_AZURE_NAME "mysqlnd_azure"
|
#define PHP_MYSQLND_AZURE_NAME "mysqlnd_azure"
|
||||||
#define EXT_MYSQLND_AZURE_VERSION "1.0.3"
|
#define PHP_MYSQLND_AZURE_VERSION "1.1.0"
|
||||||
|
|
||||||
|
#define STRING_EQUALS(z_str,str) (ZSTR_LEN((z_str)) == strlen((str)) && strcasecmp((str), ZSTR_VAL((z_str))) == 0)
|
||||||
|
|
||||||
|
typedef enum _mysqlnd_azure_redirect_mode {
|
||||||
|
REDIRECT_OFF = 0, /* completely disabled */
|
||||||
|
REDIRECT_ON = 1, /* enabled without fallback, block if redirection fail */
|
||||||
|
REDIRECT_PREFERRED = 2 /* enabled with fallback */
|
||||||
|
} mysqlnd_azure_redirect_mode;
|
||||||
|
|
||||||
ZEND_BEGIN_MODULE_GLOBALS(mysqlnd_azure)
|
ZEND_BEGIN_MODULE_GLOBALS(mysqlnd_azure)
|
||||||
zend_bool enabled;
|
mysqlnd_azure_redirect_mode enableRedirect;
|
||||||
HashTable* redirectCache;
|
HashTable* redirectCache;
|
||||||
ZEND_END_MODULE_GLOBALS(mysqlnd_azure)
|
ZEND_END_MODULE_GLOBALS(mysqlnd_azure)
|
||||||
|
|
||||||
PHPAPI ZEND_EXTERN_MODULE_GLOBALS(mysqlnd_azure)
|
PHPAPI ZEND_EXTERN_MODULE_GLOBALS(mysqlnd_azure)
|
||||||
|
|
|
@ -0,0 +1,133 @@
|
||||||
|
--TEST--
|
||||||
|
Azure redirection option test for mysqlnd_azure.enableRedirect
|
||||||
|
--SKIPIF--
|
||||||
|
<?php
|
||||||
|
require_once('skipif.inc');
|
||||||
|
?>
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
require_once("connect.inc");
|
||||||
|
|
||||||
|
function ini_set_test($value) {
|
||||||
|
global $host, $user, $passwd, $db, $port;
|
||||||
|
|
||||||
|
ini_set("mysqlnd_azure.enableRedirect", $value);
|
||||||
|
echo ini_get("mysqlnd_azure.enableRedirect"), "\n";
|
||||||
|
$link = mysqli_init();
|
||||||
|
$ret = @mysqli_real_connect($link, $host, $user, $passwd, $db, $port, NULL, NULL);
|
||||||
|
if(!$ret)
|
||||||
|
echo error_get_last()["message"], "\n";
|
||||||
|
|
||||||
|
if($ret) {
|
||||||
|
if(substr($link->host_info, 0, strlen($host)) == $host)
|
||||||
|
echo "equal\n";
|
||||||
|
else
|
||||||
|
echo "not equal\n";
|
||||||
|
$link->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
$link = mysqli_init();
|
||||||
|
$ret = @mysqli_real_connect($link, $host, $user, $passwd, $db, $port, NULL, MYSQLI_CLIENT_SSL);
|
||||||
|
$last_message = "";
|
||||||
|
if($ret)
|
||||||
|
$last_message = $link->info;
|
||||||
|
|
||||||
|
//Server supports redirection
|
||||||
|
if(strlen($last_message) > 27 && strcmp(substr($last_message, 0, strlen("Location:")), "Location:")==0) {
|
||||||
|
$config = ini_get("mysqlnd_azure.enableRedirect");
|
||||||
|
if(substr($link->host_info, 0, strlen($host)) == $host && (strcasecmp($config, "preferred")==0 || strcasecmp($config, "2")==0))
|
||||||
|
echo "FAIL\n";
|
||||||
|
else
|
||||||
|
echo "PASS\n";
|
||||||
|
}
|
||||||
|
else if($ret && is_object($link)) {
|
||||||
|
if(substr($link->host_info, 0, strlen($host)) == $host)
|
||||||
|
echo "PASS\n";
|
||||||
|
else
|
||||||
|
echo "FAIL\n";
|
||||||
|
}
|
||||||
|
else if(!$ret) { //Server does not support redirection and redirect on
|
||||||
|
$lastError = error_get_last()["message"];
|
||||||
|
if (strpos($lastError, "Connection aborted because redirection is not enabled on the MySQL server or the network package doesn't meet meet redirection protocol.") !== false)
|
||||||
|
echo "PASS\n";
|
||||||
|
else
|
||||||
|
echo "FAIL\n";
|
||||||
|
}
|
||||||
|
if($ret) $link->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
ini_set_test("on");
|
||||||
|
ini_set_test("On");
|
||||||
|
ini_set_test("yes");
|
||||||
|
ini_set_test("Yes");
|
||||||
|
ini_set_test("true");
|
||||||
|
ini_set_test("True");
|
||||||
|
ini_set_test("1");
|
||||||
|
ini_set_test(1);
|
||||||
|
|
||||||
|
ini_set_test("preferred");
|
||||||
|
ini_set_test("Preferred");
|
||||||
|
ini_set_test("2");
|
||||||
|
ini_set_test(2);
|
||||||
|
|
||||||
|
ini_set_test("off");
|
||||||
|
ini_set_test("Off");
|
||||||
|
ini_set_test("0");
|
||||||
|
ini_set_test(0);
|
||||||
|
ini_set_test("otherValue");
|
||||||
|
|
||||||
|
echo "Done\n";
|
||||||
|
?>
|
||||||
|
--EXPECTF--
|
||||||
|
on
|
||||||
|
mysqli_real_connect(): (HY000/2054): mysqlnd_azure.enableRedirect is on, but SSL option is not set in connection string. Redirection is only possible with SSL.
|
||||||
|
PASS
|
||||||
|
On
|
||||||
|
mysqli_real_connect(): (HY000/2054): mysqlnd_azure.enableRedirect is on, but SSL option is not set in connection string. Redirection is only possible with SSL.
|
||||||
|
PASS
|
||||||
|
yes
|
||||||
|
mysqli_real_connect(): (HY000/2054): mysqlnd_azure.enableRedirect is on, but SSL option is not set in connection string. Redirection is only possible with SSL.
|
||||||
|
PASS
|
||||||
|
Yes
|
||||||
|
mysqli_real_connect(): (HY000/2054): mysqlnd_azure.enableRedirect is on, but SSL option is not set in connection string. Redirection is only possible with SSL.
|
||||||
|
PASS
|
||||||
|
true
|
||||||
|
mysqli_real_connect(): (HY000/2054): mysqlnd_azure.enableRedirect is on, but SSL option is not set in connection string. Redirection is only possible with SSL.
|
||||||
|
PASS
|
||||||
|
True
|
||||||
|
mysqli_real_connect(): (HY000/2054): mysqlnd_azure.enableRedirect is on, but SSL option is not set in connection string. Redirection is only possible with SSL.
|
||||||
|
PASS
|
||||||
|
1
|
||||||
|
mysqli_real_connect(): (HY000/2054): mysqlnd_azure.enableRedirect is on, but SSL option is not set in connection string. Redirection is only possible with SSL.
|
||||||
|
PASS
|
||||||
|
1
|
||||||
|
mysqli_real_connect(): (HY000/2054): mysqlnd_azure.enableRedirect is on, but SSL option is not set in connection string. Redirection is only possible with SSL.
|
||||||
|
PASS
|
||||||
|
preferred
|
||||||
|
equal
|
||||||
|
PASS
|
||||||
|
Preferred
|
||||||
|
equal
|
||||||
|
PASS
|
||||||
|
2
|
||||||
|
equal
|
||||||
|
PASS
|
||||||
|
2
|
||||||
|
equal
|
||||||
|
PASS
|
||||||
|
off
|
||||||
|
equal
|
||||||
|
PASS
|
||||||
|
Off
|
||||||
|
equal
|
||||||
|
PASS
|
||||||
|
0
|
||||||
|
equal
|
||||||
|
PASS
|
||||||
|
0
|
||||||
|
equal
|
||||||
|
PASS
|
||||||
|
otherValue
|
||||||
|
equal
|
||||||
|
PASS
|
||||||
|
Done
|
|
@ -1,38 +0,0 @@
|
||||||
--TEST--
|
|
||||||
Azure redirection test for servers with mysqlnd_azure.enabled=0
|
|
||||||
--INI--
|
|
||||||
mysqlnd_azure.enabled=0
|
|
||||||
--SKIPIF--
|
|
||||||
<?php
|
|
||||||
require_once('skipif.inc');
|
|
||||||
require_once('skipifconnectfailure.inc');
|
|
||||||
?>
|
|
||||||
--FILE--
|
|
||||||
<?php
|
|
||||||
require_once("connect.inc");
|
|
||||||
|
|
||||||
if (($tmp = ini_get("mysqlnd_azure.enabled")) != false)
|
|
||||||
printf("[001] mysqlnd_azure.enabled not set to false, got '%s'\n", $tmp);
|
|
||||||
|
|
||||||
$link = mysqli_init();
|
|
||||||
$ret = mysqli_real_connect($link, $host, $user, $passwd, $db, $port, NULL, MYSQLI_CLIENT_SSL);
|
|
||||||
if (!$ret || !is_object($link))
|
|
||||||
{
|
|
||||||
printf("[002] Cannot connect to the server with ssl using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n - [%d] %s",
|
|
||||||
$host, $user, $db, $port, $socket, mysqli_connect_errno(), mysqli_connect_error());
|
|
||||||
die();
|
|
||||||
}
|
|
||||||
echo $link->host_info."\n";
|
|
||||||
echo $link->info."\n";
|
|
||||||
if(substr($link->host_info, 0, strlen($host)) == $host)
|
|
||||||
echo "1\n";
|
|
||||||
else
|
|
||||||
echo "0\n";
|
|
||||||
mysqli_close($link);
|
|
||||||
echo "Done\n";
|
|
||||||
?>
|
|
||||||
--EXPECTF--
|
|
||||||
%s
|
|
||||||
Location: mysql://%s.%s:%d/user=%s@%s
|
|
||||||
1
|
|
||||||
Done
|
|
|
@ -1,38 +0,0 @@
|
||||||
--TEST--
|
|
||||||
Azure redirection test for servers when mysqlnd_azure.enabled
|
|
||||||
--INI--
|
|
||||||
mysqlnd_azure.enabled=1
|
|
||||||
--SKIPIF--
|
|
||||||
<?php
|
|
||||||
require_once('skipif.inc');
|
|
||||||
require_once('skipifconnectfailure.inc');
|
|
||||||
?>
|
|
||||||
--FILE--
|
|
||||||
<?php
|
|
||||||
require_once("connect.inc");
|
|
||||||
|
|
||||||
if (($tmp = ini_get("mysqlnd_azure.enabled")) != true)
|
|
||||||
printf("[001] mysqlnd_azure.enabled not set to true, got '%s'\n", $tmp);
|
|
||||||
|
|
||||||
$link = mysqli_init();
|
|
||||||
$ret = mysqli_real_connect($link, $host, $user, $passwd, $db, $port, NULL, MYSQLI_CLIENT_SSL);
|
|
||||||
if (!$ret || !is_object($link))
|
|
||||||
{
|
|
||||||
printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n - [%d] %s with ssl",
|
|
||||||
$host, $user, $db, $port, $socket, mysqli_connect_errno(), mysqli_connect_error());
|
|
||||||
die();
|
|
||||||
}
|
|
||||||
echo $link->host_info."\n";
|
|
||||||
echo $link->info."\n";
|
|
||||||
if(substr($link->host_info, 0, strlen($host)) == $host)
|
|
||||||
echo "1\n";
|
|
||||||
else
|
|
||||||
echo "0\n";
|
|
||||||
mysqli_close($link);
|
|
||||||
echo "Done\n";
|
|
||||||
?>
|
|
||||||
--EXPECTF--
|
|
||||||
%s.%s
|
|
||||||
Location: mysql://%s.%s:%d/user=%s@%s
|
|
||||||
0
|
|
||||||
Done
|
|
|
@ -0,0 +1,72 @@
|
||||||
|
--TEST--
|
||||||
|
Azure redirection test for servers when mysqlnd_azure.enableRedirect="off"
|
||||||
|
--INI--
|
||||||
|
mysqlnd_azure.enableRedirect="off"
|
||||||
|
--SKIPIF--
|
||||||
|
<?php
|
||||||
|
require_once('skipif.inc');
|
||||||
|
?>
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
require_once("connect.inc");
|
||||||
|
|
||||||
|
//Step 1: check option setting
|
||||||
|
$tmp = ini_get("mysqlnd_azure.enableRedirect");
|
||||||
|
echo $tmp."\n";
|
||||||
|
if (strcmp($tmp, "off")!=0)
|
||||||
|
{
|
||||||
|
printf("[001] mysqlnd_azure.enableRedirect not set to off, got '%s'\n", $tmp);
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Step 2: check connection result when use SSL
|
||||||
|
$link = mysqli_init();
|
||||||
|
$ret = @mysqli_real_connect($link, $host, $user, $passwd, $db, $port, NULL, MYSQLI_CLIENT_SSL);
|
||||||
|
if (!$ret || !is_object($link))
|
||||||
|
{
|
||||||
|
printf("[002] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n - [%d] %s with ssl\n",
|
||||||
|
$host, $user, $db, $port, $socket, mysqli_connect_errno(), mysqli_connect_error());
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
echo $link->host_info."\n";
|
||||||
|
$last_message = $link->info;
|
||||||
|
|
||||||
|
//Server supports redirection
|
||||||
|
if(strlen($last_message) > 27 && strcmp(substr($last_message, 0, strlen("Location:")), "Location:")==0) {
|
||||||
|
if(substr($link->host_info, 0, strlen($host)) == $host)
|
||||||
|
echo "[003] pass\n";
|
||||||
|
else
|
||||||
|
echo "[003] fail\n";
|
||||||
|
}
|
||||||
|
else { //Server does not support redirection, use the proxy connection
|
||||||
|
if(substr($link->host_info, 0, strlen($host)) == $host)
|
||||||
|
echo "[003] pass\n";
|
||||||
|
else
|
||||||
|
echo "[003] fail\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
mysqli_close($link);
|
||||||
|
|
||||||
|
//Step 3: check connection result when not use SSL
|
||||||
|
$link = mysqli_init();
|
||||||
|
$ret = @mysqli_real_connect($link, $host, $user, $passwd, $db, $port, NULL, NULL);
|
||||||
|
if (!$ret || !is_object($link))
|
||||||
|
{
|
||||||
|
printf("[004] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n - [%d] %s without ssl\n",
|
||||||
|
$host, $user, $db, $port, $socket, mysqli_connect_errno(), mysqli_connect_error());
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(substr($link->host_info, 0, strlen($host)) == $host)
|
||||||
|
echo "[004] pass\n";
|
||||||
|
else
|
||||||
|
echo "[004] fail\n";
|
||||||
|
|
||||||
|
echo "Done\n";
|
||||||
|
?>
|
||||||
|
--EXPECTF--
|
||||||
|
off
|
||||||
|
%s
|
||||||
|
[003] pass
|
||||||
|
[004] pass
|
||||||
|
Done
|
|
@ -0,0 +1,68 @@
|
||||||
|
--TEST--
|
||||||
|
Azure redirection test for servers when mysqlnd_azure.enableRedirect="on"
|
||||||
|
--INI--
|
||||||
|
mysqlnd_azure.enableRedirect="on"
|
||||||
|
--SKIPIF--
|
||||||
|
<?php
|
||||||
|
require_once('skipif.inc');
|
||||||
|
?>
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
require_once("connect.inc");
|
||||||
|
|
||||||
|
//Step 1: check option setting
|
||||||
|
$tmp = ini_get("mysqlnd_azure.enableRedirect");
|
||||||
|
echo $tmp."\n";
|
||||||
|
if (strcmp($tmp, "on")!=0)
|
||||||
|
{
|
||||||
|
printf("[001] mysqlnd_azure.enableRedirect not set to on, got '%s'\n", $tmp);
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Step 2: check connection result when use SSL
|
||||||
|
$link = mysqli_init();
|
||||||
|
$ret = @mysqli_real_connect($link, $host, $user, $passwd, $db, $port, NULL, MYSQLI_CLIENT_SSL);
|
||||||
|
|
||||||
|
$last_message = "";
|
||||||
|
if($ret)
|
||||||
|
$last_message = $link->info;
|
||||||
|
|
||||||
|
//Server supports redirection
|
||||||
|
if(strlen($last_message) > 27 && strcmp(substr($last_message, 0, strlen("Location:")), "Location:")==0) {
|
||||||
|
if(substr($link->host_info, 0, strlen($host)) == $host)
|
||||||
|
echo "[003] fail\n";
|
||||||
|
else
|
||||||
|
echo "[003] pass\n";
|
||||||
|
}
|
||||||
|
else { //Server does not support redirection
|
||||||
|
$lastError = error_get_last()["message"];
|
||||||
|
if (strpos($lastError, "Connection aborted because redirection is not enabled on the MySQL server or the network package doesn't meet meet redirection protocol.") !== false)
|
||||||
|
echo "[003] pass\n";
|
||||||
|
else
|
||||||
|
echo "[003] fail\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
mysqli_close($link);
|
||||||
|
|
||||||
|
//Step 3: check connection result when not use SSL
|
||||||
|
$link = mysqli_init();
|
||||||
|
$ret = @mysqli_real_connect($link, $host, $user, $passwd, $db, $port, NULL, NULL);
|
||||||
|
if ($ret)
|
||||||
|
{
|
||||||
|
printf("[004] When enableRedirect=on, connect without SSL expects failure, got pass\n");
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
|
||||||
|
$lastError = error_get_last()["message"];
|
||||||
|
if (strpos($lastError, "mysqlnd_azure.enableRedirect is on, but SSL option is not set in connection string. Redirection is only possible with SSL.") !== false)
|
||||||
|
echo "[004] pass\n";
|
||||||
|
else
|
||||||
|
echo "[004] fail\n";
|
||||||
|
|
||||||
|
echo "Done\n";
|
||||||
|
?>
|
||||||
|
--EXPECTF--
|
||||||
|
on
|
||||||
|
[003] pass
|
||||||
|
[004] pass
|
||||||
|
Done
|
|
@ -0,0 +1,72 @@
|
||||||
|
--TEST--
|
||||||
|
Azure redirection test for servers when mysqlnd_azure.enableRedirect="preferred"
|
||||||
|
--INI--
|
||||||
|
mysqlnd_azure.enableRedirect="preferred"
|
||||||
|
--SKIPIF--
|
||||||
|
<?php
|
||||||
|
require_once('skipif.inc');
|
||||||
|
?>
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
require_once("connect.inc");
|
||||||
|
|
||||||
|
//Step 1: check option setting
|
||||||
|
$tmp = ini_get("mysqlnd_azure.enableRedirect");
|
||||||
|
echo $tmp."\n";
|
||||||
|
if (strcmp($tmp, "preferred")!=0)
|
||||||
|
{
|
||||||
|
printf("[001] mysqlnd_azure.enableRedirect not set to preferred, got '%s'\n", $tmp);
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Step 2: check connection result when use SSL
|
||||||
|
$link = mysqli_init();
|
||||||
|
$ret = @mysqli_real_connect($link, $host, $user, $passwd, $db, $port, NULL, MYSQLI_CLIENT_SSL);
|
||||||
|
if (!$ret || !is_object($link))
|
||||||
|
{
|
||||||
|
printf("[002] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n - [%d] %s with ssl\n",
|
||||||
|
$host, $user, $db, $port, $socket, mysqli_connect_errno(), mysqli_connect_error());
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
echo $link->host_info."\n";
|
||||||
|
$last_message = $link->info;
|
||||||
|
|
||||||
|
//Server supports redirection
|
||||||
|
if(strlen($last_message) > 27 && strcmp(substr($last_message, 0, strlen("Location:")), "Location:")==0) {
|
||||||
|
if(substr($link->host_info, 0, strlen($host)) == $host)
|
||||||
|
echo "[003] fail\n";
|
||||||
|
else
|
||||||
|
echo "[003] pass\n";
|
||||||
|
}
|
||||||
|
else { //Server does not support redirection, use the proxy connection
|
||||||
|
if(substr($link->host_info, 0, strlen($host)) == $host)
|
||||||
|
echo "[003] pass\n";
|
||||||
|
else
|
||||||
|
echo "[003] fail\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
mysqli_close($link);
|
||||||
|
|
||||||
|
//Step 3: check connection result when not use SSL
|
||||||
|
$link = mysqli_init();
|
||||||
|
$ret = @mysqli_real_connect($link, $host, $user, $passwd, $db, $port, NULL, NULL);
|
||||||
|
if (!$ret || !is_object($link))
|
||||||
|
{
|
||||||
|
printf("[004] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n - [%d] %s without ssl\n",
|
||||||
|
$host, $user, $db, $port, $socket, mysqli_connect_errno(), mysqli_connect_error());
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(substr($link->host_info, 0, strlen($host)) == $host)
|
||||||
|
echo "[004] pass\n";
|
||||||
|
else
|
||||||
|
echo "[004] fail\n";
|
||||||
|
|
||||||
|
echo "Done\n";
|
||||||
|
?>
|
||||||
|
--EXPECTF--
|
||||||
|
preferred
|
||||||
|
%s
|
||||||
|
[003] pass
|
||||||
|
[004] pass
|
||||||
|
Done
|
|
@ -4,7 +4,7 @@ Test redirection in web server with baisc functionality - mysqli
|
||||||
<?php
|
<?php
|
||||||
require_once('skipif_server.inc');
|
require_once('skipif_server.inc');
|
||||||
require_once('skipif.inc');
|
require_once('skipif.inc');
|
||||||
require_once('skipifconnectfailure.inc');
|
require_once('skipif_mysqli.inc');
|
||||||
?>
|
?>
|
||||||
--CONFLICTS--
|
--CONFLICTS--
|
||||||
server
|
server
|
||||||
|
@ -33,23 +33,31 @@ fclose($fp);
|
||||||
--EXPECTF--
|
--EXPECTF--
|
||||||
*** Testing mysqli in web server: basic functionality ***
|
*** Testing mysqli in web server: basic functionality ***
|
||||||
step1: redirect enabled, non-persistent connection
|
step1: redirect enabled, non-persistent connection
|
||||||
mysqlnd_azure.enabled: On
|
mysqlnd_azure.enableRedirect: preferred
|
||||||
%s
|
%s
|
||||||
Location: mysql://%s:%d/user=%s
|
Location: mysql://%s:%d/user=%s
|
||||||
0
|
0
|
||||||
step2: redirect enabled, persistent connection
|
step2: redirect enabled, persistent connection
|
||||||
mysqlnd_azure.enabled: On
|
mysqlnd_azure.enableRedirect: preferred
|
||||||
%s
|
%s
|
||||||
Location: mysql://%s:%d/user=%s
|
Location: mysql://%s:%d/user=%s
|
||||||
0
|
0
|
||||||
step3: redirect disabled, non-persistent connection
|
step3: redirect disabled, non-persistent connection
|
||||||
mysqlnd_azure.enabled: Off
|
mysqlnd_azure.enableRedirect: off
|
||||||
%s
|
%s
|
||||||
Location: mysql://%s:%d/user=%s
|
Location: mysql://%s:%d/user=%s
|
||||||
1
|
1
|
||||||
step4: redirect disabled, persistent connection
|
step4: redirect disabled, persistent connection
|
||||||
mysqlnd_azure.enabled: Off
|
mysqlnd_azure.enableRedirect: off
|
||||||
%s
|
%s
|
||||||
|
|
||||||
|
0
|
||||||
|
step5: redirect enforced, non-ssl connection
|
||||||
|
mysqlnd_azure.enableRedirect: on
|
||||||
|
mysqli_real_connect(): (HY000/2054): mysqlnd_azure.enableRedirect is on, but SSL option is not set in connection string. Redirection is only possible with SSL.
|
||||||
|
step6: redirect enforced, ssl connection
|
||||||
|
mysqlnd_azure.enableRedirect: on
|
||||||
|
%s
|
||||||
|
Location: mysql://%s:%d/user=%s
|
||||||
0
|
0
|
||||||
===DONE===
|
===DONE===
|
|
@ -1,11 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
require_once("connect.inc");
|
require_once("connect.inc");
|
||||||
|
|
||||||
ini_set("mysqlnd_azure.enabled", "on");
|
ini_set("mysqlnd_azure.enableRedirect", "preferred");
|
||||||
|
|
||||||
echo "step1: redirect enabled, non-persistent connection \n";
|
echo "step1: redirect enabled, non-persistent connection \n";
|
||||||
{
|
{
|
||||||
echo "mysqlnd_azure.enabled: ", ini_get("mysqlnd_azure.enabled") == true?"On":"Off", "\n";
|
echo "mysqlnd_azure.enableRedirect: ", ini_get("mysqlnd_azure.enableRedirect"), "\n";
|
||||||
$link = mysqli_init();
|
$link = mysqli_init();
|
||||||
$ret = mysqli_real_connect($link, $host, $user, $passwd, $db, $port, NULL, MYSQLI_CLIENT_SSL);
|
$ret = mysqli_real_connect($link, $host, $user, $passwd, $db, $port, NULL, MYSQLI_CLIENT_SSL);
|
||||||
if (!$ret || !is_object($link))
|
if (!$ret || !is_object($link))
|
||||||
|
@ -25,7 +25,7 @@ echo "step1: redirect enabled, non-persistent connection \n";
|
||||||
|
|
||||||
echo "step2: redirect enabled, persistent connection \n";
|
echo "step2: redirect enabled, persistent connection \n";
|
||||||
{
|
{
|
||||||
echo "mysqlnd_azure.enabled: ", ini_get("mysqlnd_azure.enabled") == true?"On":"Off", "\n";
|
echo "mysqlnd_azure.enableRedirect: ", ini_get("mysqlnd_azure.enableRedirect"), "\n";
|
||||||
$link = mysqli_init();
|
$link = mysqli_init();
|
||||||
$ret = mysqli_real_connect($link, "p:".$host, $user, $passwd, $db, $port, NULL, MYSQLI_CLIENT_SSL);
|
$ret = mysqli_real_connect($link, "p:".$host, $user, $passwd, $db, $port, NULL, MYSQLI_CLIENT_SSL);
|
||||||
if (!$ret || !is_object($link))
|
if (!$ret || !is_object($link))
|
||||||
|
@ -43,11 +43,11 @@ echo "step2: redirect enabled, persistent connection \n";
|
||||||
mysqli_close($link);
|
mysqli_close($link);
|
||||||
}
|
}
|
||||||
|
|
||||||
ini_set("mysqlnd_azure.enabled", 0);
|
ini_set("mysqlnd_azure.enableRedirect", "off");
|
||||||
|
|
||||||
echo "step3: redirect disabled, non-persistent connection \n";
|
echo "step3: redirect disabled, non-persistent connection \n";
|
||||||
{
|
{
|
||||||
echo "mysqlnd_azure.enabled: ", ini_get("mysqlnd_azure.enabled") == true?"On":"Off", "\n";
|
echo "mysqlnd_azure.enableRedirect: ", ini_get("mysqlnd_azure.enableRedirect"), "\n";
|
||||||
$link = mysqli_init();
|
$link = mysqli_init();
|
||||||
$ret = mysqli_real_connect($link, $host, $user, $passwd, $db, $port, NULL, MYSQLI_CLIENT_SSL);
|
$ret = mysqli_real_connect($link, $host, $user, $passwd, $db, $port, NULL, MYSQLI_CLIENT_SSL);
|
||||||
if (!$ret || !is_object($link))
|
if (!$ret || !is_object($link))
|
||||||
|
@ -67,7 +67,7 @@ echo "step3: redirect disabled, non-persistent connection \n";
|
||||||
|
|
||||||
echo "step4: redirect disabled, persistent connection \n";
|
echo "step4: redirect disabled, persistent connection \n";
|
||||||
{
|
{
|
||||||
echo "mysqlnd_azure.enabled: ", ini_get("mysqlnd_azure.enabled") == true?"On":"Off", "\n";
|
echo "mysqlnd_azure.enableRedirect: ", ini_get("mysqlnd_azure.enableRedirect"), "\n";
|
||||||
$link = mysqli_init();
|
$link = mysqli_init();
|
||||||
$ret = mysqli_real_connect($link, "p:".$host, $user, $passwd, $db, $port, NULL, MYSQLI_CLIENT_SSL);
|
$ret = mysqli_real_connect($link, "p:".$host, $user, $passwd, $db, $port, NULL, MYSQLI_CLIENT_SSL);
|
||||||
if (!$ret || !is_object($link))
|
if (!$ret || !is_object($link))
|
||||||
|
@ -85,4 +85,40 @@ echo "step4: redirect disabled, persistent connection \n";
|
||||||
mysqli_close($link);
|
mysqli_close($link);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ini_set("mysqlnd_azure.enableRedirect", "on");
|
||||||
|
|
||||||
|
echo "step5: redirect enforced, non-ssl connection \n";
|
||||||
|
{
|
||||||
|
echo "mysqlnd_azure.enableRedirect: ", ini_get("mysqlnd_azure.enableRedirect"), "\n";
|
||||||
|
$link = mysqli_init();
|
||||||
|
$ret = @mysqli_real_connect($link, $host, $user, $passwd, $db, $port, NULL, NULL);
|
||||||
|
if ($ret)
|
||||||
|
{
|
||||||
|
printf("[001] when enableRedirect=on, Connection without SSL should fail.\n");
|
||||||
|
mysqli_close($link);
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
echo error_get_last()["message"], "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "step6: redirect enforced, ssl connection \n";
|
||||||
|
{
|
||||||
|
echo "mysqlnd_azure.enableRedirect: ", ini_get("mysqlnd_azure.enableRedirect"), "\n";
|
||||||
|
$link = mysqli_init();
|
||||||
|
$ret = mysqli_real_connect($link, $host, $user, $passwd, $db, $port, NULL, MYSQLI_CLIENT_SSL);
|
||||||
|
if (!$ret || !is_object($link))
|
||||||
|
{
|
||||||
|
printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n - [%d] %s with ssl",
|
||||||
|
$host, $user, $db, $port, $socket, mysqli_connect_errno(), mysqli_connect_error());
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
echo $link->host_info."\n";
|
||||||
|
echo $link->info."\n";
|
||||||
|
if(substr($link->host_info, 0, strlen($host)) == $host)
|
||||||
|
echo "1\n";
|
||||||
|
else
|
||||||
|
echo "0\n";
|
||||||
|
mysqli_close($link);
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -32,19 +32,19 @@ fclose($fp);
|
||||||
--EXPECTF--
|
--EXPECTF--
|
||||||
*** Testing pdo_mysql in web server: basic functionality ***
|
*** Testing pdo_mysql in web server: basic functionality ***
|
||||||
step1: redirect enabled, non-persistent connection
|
step1: redirect enabled, non-persistent connection
|
||||||
mysqlnd_azure.enabled: On
|
mysqlnd_azure.enableRedirect: preferred
|
||||||
%s
|
%s
|
||||||
0
|
0
|
||||||
step2: redirect enabled, persistent connection
|
step2: redirect enabled, persistent connection
|
||||||
mysqlnd_azure.enabled: On
|
mysqlnd_azure.enableRedirect: preferred
|
||||||
%s
|
%s
|
||||||
0
|
0
|
||||||
step3: redirect disabled, non-persistent connection
|
step3: redirect disabled, non-persistent connection
|
||||||
mysqlnd_azure.enabled: Off
|
mysqlnd_azure.enableRedirect: off
|
||||||
%s
|
%s
|
||||||
1
|
1
|
||||||
step4: redirect disabled, persistent connection
|
step4: redirect disabled, persistent connection
|
||||||
mysqlnd_azure.enabled: Off
|
mysqlnd_azure.enableRedirect: off
|
||||||
%s
|
%s
|
||||||
0
|
0
|
||||||
===DONE===
|
===DONE===
|
|
@ -1,11 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
require_once("connect.inc");
|
require_once("connect.inc");
|
||||||
|
|
||||||
ini_set("mysqlnd_azure.enabled", "on");
|
ini_set("mysqlnd_azure.enableRedirect", "preferred");
|
||||||
|
|
||||||
echo "step1: redirect enabled, non-persistent connection \n";
|
echo "step1: redirect enabled, non-persistent connection \n";
|
||||||
{
|
{
|
||||||
echo "mysqlnd_azure.enabled: ", ini_get("mysqlnd_azure.enabled") == true?"On":"Off", "\n";
|
echo "mysqlnd_azure.enableRedirect: ", ini_get("mysqlnd_azure.enableRedirect"), "\n";
|
||||||
$conn = NULL;
|
$conn = NULL;
|
||||||
try {
|
try {
|
||||||
$conn = new PDO($pdo_dsn, $user, $passwd,
|
$conn = new PDO($pdo_dsn, $user, $passwd,
|
||||||
|
@ -27,7 +27,7 @@ echo "step1: redirect enabled, non-persistent connection \n";
|
||||||
|
|
||||||
echo "step2: redirect enabled, persistent connection \n";
|
echo "step2: redirect enabled, persistent connection \n";
|
||||||
{
|
{
|
||||||
echo "mysqlnd_azure.enabled: ", ini_get("mysqlnd_azure.enabled") == true?"On":"Off", "\n";
|
echo "mysqlnd_azure.enableRedirect: ", ini_get("mysqlnd_azure.enableRedirect"), "\n";
|
||||||
$conn = NULL;
|
$conn = NULL;
|
||||||
try {
|
try {
|
||||||
$conn = new PDO($pdo_dsn, $user, $passwd,
|
$conn = new PDO($pdo_dsn, $user, $passwd,
|
||||||
|
@ -47,11 +47,11 @@ echo "step2: redirect enabled, persistent connection \n";
|
||||||
$conn = NULL;
|
$conn = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ini_set("mysqlnd_azure.enabled", 0);
|
ini_set("mysqlnd_azure.enableRedirect", "off");
|
||||||
|
|
||||||
echo "step3: redirect disabled, non-persistent connection \n";
|
echo "step3: redirect disabled, non-persistent connection \n";
|
||||||
{
|
{
|
||||||
echo "mysqlnd_azure.enabled: ", ini_get("mysqlnd_azure.enabled") == true?"On":"Off", "\n";
|
echo "mysqlnd_azure.enableRedirect: ", ini_get("mysqlnd_azure.enableRedirect"), "\n";
|
||||||
$conn = NULL;
|
$conn = NULL;
|
||||||
try {
|
try {
|
||||||
$conn = new PDO($pdo_dsn, $user, $passwd,
|
$conn = new PDO($pdo_dsn, $user, $passwd,
|
||||||
|
@ -73,7 +73,7 @@ echo "step3: redirect disabled, non-persistent connection \n";
|
||||||
|
|
||||||
echo "step4: redirect disabled, persistent connection \n";
|
echo "step4: redirect disabled, persistent connection \n";
|
||||||
{
|
{
|
||||||
echo "mysqlnd_azure.enabled: ", ini_get("mysqlnd_azure.enabled") == true?"On":"Off", "\n";
|
echo "mysqlnd_azure.enableRedirect: ", ini_get("mysqlnd_azure.enableRedirect"), "\n";
|
||||||
$conn = NULL;
|
$conn = NULL;
|
||||||
try {
|
try {
|
||||||
$conn = new PDO($pdo_dsn, $user, $passwd,
|
$conn = new PDO($pdo_dsn, $user, $passwd,
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
if(!link)
|
if(!link)
|
||||||
die("skip mysqli_init failed");
|
die("skip mysqli_init failed");
|
||||||
|
|
||||||
|
ini_set("mysqlnd_azure.enableRedirect", "preferred");
|
||||||
$ret = mysqli_real_connect($link, $host, $user, $passwd, $db, $port, NULL, MYSQLI_CLIENT_SSL);
|
$ret = mysqli_real_connect($link, $host, $user, $passwd, $db, $port, NULL, MYSQLI_CLIENT_SSL);
|
||||||
if (!$ret)
|
if (!$ret)
|
||||||
die(sprintf("skip Can't connect to MySQL Server with ssl - [%d] %s", mysqli_connect_errno(), mysqli_connect_error()));
|
die(sprintf("skip Can't connect to MySQL Server with ssl - [%d] %s", mysqli_connect_errno(), mysqli_connect_error()));
|
|
@ -20,7 +20,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
include_once('connect.inc');
|
include_once('connect.inc');
|
||||||
ini_set("mysqlnd_azure.enabled", "on");
|
ini_set("mysqlnd_azure.enableRedirect", "preferred");
|
||||||
$conn = NULL;
|
$conn = NULL;
|
||||||
try {
|
try {
|
||||||
$conn = new PDO($pdo_dsn, $user, $passwd,
|
$conn = new PDO($pdo_dsn, $user, $passwd,
|
||||||
|
|
Загрузка…
Ссылка в новой задаче