[PHP-CVS] svn: /php/php-src/trunk/ext/mysqlnd/ mysqlnd.c

2011-05-04 Thread Andrey Hristov
andrey   Wed, 04 May 2011 10:35:04 +

Revision: http://svn.php.net/viewvc?view=revisionrevision=310757

Log:
fix valgrind warning

Changed paths:
U   php/php-src/trunk/ext/mysqlnd/mysqlnd.c

Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd.c
===
--- php/php-src/trunk/ext/mysqlnd/mysqlnd.c 2011-05-04 08:44:14 UTC (rev 
310756)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd.c 2011-05-04 10:35:04 UTC (rev 
310757)
@@ -506,12 +506,13 @@
size_t plugin_data_len;

plugin_data_len = greet_packet-auth_plugin_data_len;
-   plugin_data = mnd_emalloc(plugin_data_len);
+   plugin_data = mnd_emalloc(plugin_data_len + 1);
if (!plugin_data) {
ret = FAIL;
goto end;
}
memcpy(plugin_data, greet_packet-auth_plugin_data, 
plugin_data_len);
+   plugin_data[plugin_data_len] = '\0';

requested_protocol = mnd_pestrdup(greet_packet-auth_protocol? 
greet_packet-auth_protocol: mysql_native_password, FALSE);
if (!requested_protocol) {

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[PHP-CVS] svn: /php/php-src/trunk/ext/mysqlnd/ mysqlnd.c mysqlnd_net.c mysqlnd_ps.c mysqlnd_result.c

2011-03-18 Thread Andrey Hristov
andrey   Fri, 18 Mar 2011 12:33:17 +

Revision: http://svn.php.net/viewvc?view=revisionrevision=309381

Log:
less trace info

Changed paths:
U   php/php-src/trunk/ext/mysqlnd/mysqlnd.c
U   php/php-src/trunk/ext/mysqlnd/mysqlnd_net.c
U   php/php-src/trunk/ext/mysqlnd/mysqlnd_ps.c
U   php/php-src/trunk/ext/mysqlnd/mysqlnd_result.c

Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd.c
===
--- php/php-src/trunk/ext/mysqlnd/mysqlnd.c	2011-03-18 12:05:16 UTC (rev 309380)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd.c	2011-03-18 12:33:17 UTC (rev 309381)
@@ -138,47 +138,38 @@
 	DBG_INF(Freeing memory of members);

 	if (conn-host) {
-		DBG_INF(Freeing host);
 		mnd_pefree(conn-host, pers);
 		conn-host = NULL;
 	}
 	if (conn-user) {
-		DBG_INF(Freeing user);
 		mnd_pefree(conn-user, pers);
 		conn-user = NULL;
 	}
 	if (conn-passwd) {
-		DBG_INF(Freeing passwd);
 		mnd_pefree(conn-passwd, pers);
 		conn-passwd = NULL;
 	}
 	if (conn-connect_or_select_db) {
-		DBG_INF(Freeing connect_or_select_db);
 		mnd_pefree(conn-connect_or_select_db, pers);
 		conn-connect_or_select_db = NULL;
 	}
 	if (conn-unix_socket) {
-		DBG_INF(Freeing unix_socket);
 		mnd_pefree(conn-unix_socket, pers);
 		conn-unix_socket = NULL;
 	}
 	if (conn-scheme) {
-		DBG_INF(Freeing scheme);
 		mnd_pefree(conn-scheme, pers);
 		conn-scheme = NULL;
 	}
 	if (conn-server_version) {
-		DBG_INF(Freeing server_version);
 		mnd_pefree(conn-server_version, pers);
 		conn-server_version = NULL;
 	}
 	if (conn-host_info) {
-		DBG_INF(Freeing host_info);
 		mnd_pefree(conn-host_info, pers);
 		conn-host_info = NULL;
 	}
 	if (conn-auth_plugin_data) {
-		DBG_INF(Freeing auth_plugin_data);
 		mnd_pefree(conn-auth_plugin_data, pers);
 		conn-auth_plugin_data = NULL;
 	}
@@ -205,13 +196,11 @@
 	conn-m-free_options(conn TSRMLS_CC);

 	if (conn-net) {
-		DBG_INF(Freeing net);
 		mysqlnd_net_free(conn-net TSRMLS_CC);
 		conn-net = NULL;
 	}

 	if (conn-protocol) {
-		DBG_INF(Freeing protocol);
 		mysqlnd_protocol_free(conn-protocol TSRMLS_CC);
 		conn-protocol = NULL;
 	}
@@ -2168,12 +2157,10 @@
 #endif
 #ifdef MYSQLND_STRING_TO_INT_CONVERSION
 		case MYSQLND_OPT_INT_AND_FLOAT_NATIVE:
-			DBG_INF(MYSQLND_OPT_INT_AND_FLOAT_NATIVE);
 			conn-options.int_and_float_native = *(unsigned int*) value;
 			break;
 #endif
 		case MYSQL_OPT_LOCAL_INFILE:
-			DBG_INF(MYSQL_OPT_LOCAL_INFILE);
 			if (!value || (*(unsigned int*) value) ? 1 : 0) {
 conn-options.flags |= CLIENT_LOCAL_FILES;
 			} else {
@@ -2184,8 +2171,6 @@
 		{
 			char ** new_init_commands;
 			char * new_command;
-			DBG_INF(MYSQL_INIT_COMMAND);
-			DBG_INF_FMT(command=%s, value);
 			/* when num_commands is 0, then realloc will be effectively a malloc call, internally */
 			/* Don't assign to conn-options.init_commands because in case of OOM we will lose the pointer and leak */
 			new_init_commands = mnd_perealloc(conn-options.init_commands, sizeof(char *) * (conn-options.num_commands + 1), conn-persistent);
@@ -2212,7 +2197,6 @@
 		case MYSQL_SET_CHARSET_NAME:
 		{
 			char * new_charset_name = mnd_pestrdup(value, conn-persistent);
-			DBG_INF(MYSQL_SET_CHARSET_NAME);
 			if (!new_charset_name) {
 goto oom;
 			}
@@ -2251,7 +2235,6 @@
 		case MYSQLND_OPT_AUTH_PROTOCOL:
 		{
 			char * new_auth_protocol = value? mnd_pestrdup(value, conn-persistent) : NULL;
-			DBG_INF(MYSQLND_OPT_AUTH_PROTOCOL);
 			if (value  !new_auth_protocol) {
 goto oom;
 			}
@@ -2294,8 +2277,7 @@

 	/* Nothing to store for UPSERT/LOAD DATA */
 	if (conn-last_query_type != QUERY_SELECT || CONN_GET_STATE(conn) != CONN_FETCHING_DATA) {
-		SET_CLIENT_ERROR(conn-error_info, CR_COMMANDS_OUT_OF_SYNC, UNKNOWN_SQLSTATE,
-		 mysqlnd_out_of_sync);
+		SET_CLIENT_ERROR(conn-error_info, CR_COMMANDS_OUT_OF_SYNC, UNKNOWN_SQLSTATE, mysqlnd_out_of_sync);
 		DBG_ERR(Command out of sync);
 		DBG_RETURN(NULL);
 	}
@@ -2330,8 +2312,7 @@

 	/* Nothing to store for UPSERT/LOAD DATA*/
 	if (conn-last_query_type != QUERY_SELECT || CONN_GET_STATE(conn) != CONN_FETCHING_DATA) {
-		SET_CLIENT_ERROR(conn-error_info, CR_COMMANDS_OUT_OF_SYNC, UNKNOWN_SQLSTATE,
-		 mysqlnd_out_of_sync);
+		SET_CLIENT_ERROR(conn-error_info, CR_COMMANDS_OUT_OF_SYNC, UNKNOWN_SQLSTATE, mysqlnd_out_of_sync);
 		DBG_ERR(Command out of sync);
 		DBG_RETURN(NULL);
 	}
@@ -2355,7 +2336,6 @@
    TSRMLS_DC ZEND_FILE_LINE_DC)
 {
 	DBG_ENTER(mysqlnd_conn::get_connection_stats);
-	DBG_INF_FMT(conn=%llu, conn-thread_id);
 	mysqlnd_fill_stats_hash(conn-stats, mysqlnd_stats_values_names, return_value TSRMLS_CC ZEND_FILE_LINE_CC);
 	DBG_VOID_RETURN;
 }

Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd_net.c
===
--- php/php-src/trunk/ext/mysqlnd/mysqlnd_net.c	2011-03-18 12:05:16 UTC (rev 309380)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd_net.c	2011-03-18 12:33:17 UTC (rev 309381)
@@ -68,7 +68,7 

[PHP-CVS] svn: /php/php-src/trunk/ext/mysqlnd/ mysqlnd.c mysqlnd_alloc.c mysqlnd_alloc.h mysqlnd_debug.c mysqlnd_net.c mysqlnd_ps.c mysqlnd_ps_codec.c

2011-03-18 Thread Andrey Hristov
andrey   Fri, 18 Mar 2011 14:56:20 +

Revision: http://svn.php.net/viewvc?view=revisionrevision=309388

Log:
add a proxy for sppintf and vspprintf

Changed paths:
U   php/php-src/trunk/ext/mysqlnd/mysqlnd.c
U   php/php-src/trunk/ext/mysqlnd/mysqlnd_alloc.c
U   php/php-src/trunk/ext/mysqlnd/mysqlnd_alloc.h
U   php/php-src/trunk/ext/mysqlnd/mysqlnd_debug.c
U   php/php-src/trunk/ext/mysqlnd/mysqlnd_net.c
U   php/php-src/trunk/ext/mysqlnd/mysqlnd_ps.c
U   php/php-src/trunk/ext/mysqlnd/mysqlnd_ps_codec.c

Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd.c
===
--- php/php-src/trunk/ext/mysqlnd/mysqlnd.c	2011-03-18 14:54:02 UTC (rev 309387)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd.c	2011-03-18 14:56:20 UTC (rev 309388)
@@ -524,11 +524,11 @@
 			{
 char * plugin_name = NULL;

-spprintf(plugin_name, 0, auth_plugin_%s, requested_protocol);
+mnd_sprintf(plugin_name, 0, auth_plugin_%s, requested_protocol);

 DBG_INF_FMT(looking for %s auth plugin, plugin_name);
 auth_plugin = mysqlnd_plugin_find(plugin_name);
-efree(plugin_name);
+mnd_sprintf_free(plugin_name);

 if (!auth_plugin) {
 	php_error_docref(NULL TSRMLS_CC, E_WARNING, The server requested authentication method unknown to the client [%s], requested_protocol);
@@ -695,7 +695,7 @@
 			if (!socket_or_pipe) {
 socket_or_pipe = /tmp/mysql.sock;
 			}
-			transport_len = spprintf(transport, 0, unix://%s, socket_or_pipe);
+			transport_len = mnd_sprintf(transport, 0, unix://%s, socket_or_pipe);
 			unix_socket = TRUE;
 #else
 		if (host_len == sizeof(.) - 1  host[0] == '.') {
@@ -703,14 +703,14 @@
 			if (!socket_or_pipe) {
 socket_or_pipe = .\\pipe\\MySQL;
 			}
-			transport_len = spprintf(transport, 0, pipe://%s, socket_or_pipe);
+			transport_len = mnd_sprintf(transport, 0, pipe://%s, socket_or_pipe);
 			named_pipe = TRUE;
 #endif
 		} else {
 			if (!port) {
 port = 3306;
 			}
-			transport_len = spprintf(transport, 0, tcp://%s:%u, host, port);
+			transport_len = mnd_sprintf(transport, 0, tcp://%s:%u, host, port);
 		}
 		if (!transport) {
 			SET_OOM_ERROR(conn-error_info);
@@ -719,7 +719,7 @@
 		DBG_INF_FMT(transport=%s, transport);
 		conn-scheme = mnd_pestrndup(transport, transport_len, conn-persistent);
 		conn-scheme_len = transport_len;
-		efree(transport); /* allocated by spprintf */
+		mnd_sprintf_free(transport);
 		transport = NULL;
 		if (!conn-scheme) {
 			goto err; /* OOM */
@@ -833,13 +833,13 @@
 			conn-host_len = strlen(conn-host);
 			{
 char *p;
-spprintf(p, 0, %s via TCP/IP, conn-host);
+mnd_sprintf(p, 0, %s via TCP/IP, conn-host);
 if (!p) {
 	SET_OOM_ERROR(conn-error_info);
 	goto err; /* OOM */
 }
 conn-host_info =  mnd_pestrdup(p, conn-persistent);
-efree(p); /* allocated by spprintf */
+mnd_sprintf_free(p);
 if (!conn-host_info) {
 	SET_OOM_ERROR(conn-error_info);
 	goto err; /* OOM */
@@ -851,13 +851,13 @@
 conn-host_info		= mnd_pestrdup(Localhost via UNIX socket, conn-persistent);
 			} else if (named_pipe) {
 char *p;
-spprintf(p, 0, %s via named pipe, conn-unix_socket);
+mnd_sprintf(p, 0, %s via named pipe, conn-unix_socket);
 if (!p) {
 	SET_OOM_ERROR(conn-error_info);
 	goto err; /* OOM */
 }
 conn-host_info =  mnd_pestrdup(p, conn-persistent);
-efree(p); /* allocated by spprintf */
+mnd_sprintf_free(p);
 if (!conn-host_info) {
 	SET_OOM_ERROR(conn-error_info);
 	goto err; /* OOM */
@@ -1317,13 +1317,13 @@

 	if (par1) {
 		if (achtung_wild) {
-			show_query_len = spprintf(show_query, 0, query, par1, achtung_wild);
+			show_query_len = mnd_sprintf(show_query, 0, query, par1, achtung_wild);
 		} else {
-			show_query_len = spprintf(show_query, 0, query, par1);
+			show_query_len = mnd_sprintf(show_query, 0, query, par1);
 		}
 	} else {
 		if (achtung_wild) {
-			show_query_len = spprintf(show_query, 0, query, achtung_wild);
+			show_query_len = mnd_sprintf(show_query, 0, query, achtung_wild);
 		} else {
 			show_query_len = strlen(show_query = (char *)query);
 		}
@@ -1333,7 +1333,7 @@
 		result = conn-m-store_result(conn TSRMLS_CC);
 	}
 	if (show_query != query) {
-		efree(show_query); /* allocated by spprintf */
+		mnd_sprintf_free(show_query);
 	}
 	DBG_RETURN(result);
 }
@@ -1547,7 +1547,7 @@
 		DBG_RETURN(FAIL);
 	}

-	query_len = spprintf(query, 0, SET NAMES %s, csname);
+	query_len = mnd_sprintf(query, 0, SET NAMES %s, csname);

 	if (FAIL == conn-m-query(conn, query, query_len TSRMLS_CC)) {
 		php_error_docref(NULL TSRMLS_CC, E_WARNING, Error executing query);
@@ -1556,7 +1556,7 @@
 	} else {
 		conn-charset = charset;
 	}
-	efree(query); /* allocated by spprintf */
+	mnd_sprintf_free(query);

 	DBG_INF(ret == PASS? PASS:FAIL);
 	DBG_RETURN(ret);
@@ -2033,11 +2033,11 @@
 			{
 char * plugin_name = NULL;

-

[PHP-CVS] svn: /php/php-src/trunk/ext/mysqlnd/ mysqlnd.c

2011-01-31 Thread Andrey Hristov
andrey   Mon, 31 Jan 2011 13:29:18 +

Revision: http://svn.php.net/viewvc?view=revisionrevision=307882

Log:
Don't lose this data anymore. It worked without the fix,
but it with it is just correct (trunk only).

Changed paths:
U   php/php-src/trunk/ext/mysqlnd/mysqlnd.c

Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd.c
===
--- php/php-src/trunk/ext/mysqlnd/mysqlnd.c 2011-01-31 13:00:27 UTC (rev 
307881)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd.c 2011-01-31 13:29:18 UTC (rev 
307882)
@@ -588,10 +588,10 @@
free(scrambled_data);

DBG_INF_FMT(switch_to_auth_protocol=%s, 
switch_to_auth_protocol? switch_to_auth_protocol:n/a);
-   if (requested_protocol) {
+   if (requested_protocol  
switch_to_auth_protocol) {
mnd_efree(requested_protocol);
+   requested_protocol = 
switch_to_auth_protocol;
}
-   requested_protocol = switch_to_auth_protocol;

if (plugin_data) {
mnd_efree(plugin_data);
@@ -606,6 +606,7 @@
}

if (ret == PASS) {
+   DBG_INF_FMT(saving requested_protocol=%s, 
requested_protocol);
conn-m-set_client_option(conn, 
MYSQLND_OPT_AUTH_PROTOCOL, requested_protocol TSRMLS_CC);
}


-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[PHP-CVS] svn: /php/php-src/trunk/ext/mysqlnd/ mysqlnd.c

2011-01-28 Thread Andrey Hristov
andrey   Fri, 28 Jan 2011 17:33:14 +

Revision: http://svn.php.net/viewvc?view=revisionrevision=307827

Log:
clear error before doing anything, because we can get
trapped by previous error :
php -r '$link = mysqli_init();
var_dump($link-real_connect(127.0.0.1, unknown, unknown));
var_dump($link-real_connect(127.0.0.1, known, password));'

shows the problem. The second connect did not work, as it should be.

Changed paths:
U   php/php-src/trunk/ext/mysqlnd/mysqlnd.c

Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd.c
===
--- php/php-src/trunk/ext/mysqlnd/mysqlnd.c 2011-01-28 17:11:32 UTC (rev 
307826)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd.c 2011-01-28 17:33:14 UTC (rev 
307827)
@@ -641,6 +641,9 @@

DBG_ENTER(mysqlnd_conn::connect);

+   SET_EMPTY_ERROR(conn-error_info);
+   SET_ERROR_AFF_ROWS(conn);
+
DBG_INF_FMT(host=%s user=%s db=%s port=%u flags=%u persistent=%u 
state=%u,
host?host:, user?user:, db?db:, port, 
mysql_flags,
conn? conn-persistent:0, conn? 
CONN_GET_STATE(conn):-1);

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[PHP-CVS] svn: /php/php-src/trunk/ext/mysqlnd/ mysqlnd.c mysqlnd_auth.c mysqlnd_priv.h

2011-01-24 Thread Andrey Hristov
andrey   Mon, 24 Jan 2011 13:58:18 +

Revision: http://svn.php.net/viewvc?view=revisionrevision=307711

Log:
small cleanups

Changed paths:
U   php/php-src/trunk/ext/mysqlnd/mysqlnd.c
U   php/php-src/trunk/ext/mysqlnd/mysqlnd_auth.c
U   php/php-src/trunk/ext/mysqlnd/mysqlnd_priv.h

Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd.c
===
--- php/php-src/trunk/ext/mysqlnd/mysqlnd.c 2011-01-24 12:34:47 UTC (rev 
307710)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd.c 2011-01-24 13:58:18 UTC (rev 
307711)
@@ -577,7 +577,7 @@

   plugin_data, plugin_data_len, options, mysql_flags 
TSRMLS_CC);


-   ret = mysqlnd_auth_handshake(conn, user, 
passwd, db, db_len, passwd_len, options, mysql_flags, greet_packet-charset_no,
+   ret = mysqlnd_auth_handshake(conn, user, 
passwd, passwd_len, db, db_len, options, mysql_flags, greet_packet-charset_no,

first_call,

requested_protocol,

scrambled_data, scrambled_data_len,
@@ -2084,7 +2084,7 @@

   plugin_data, plugin_data_len, 0, 
conn-server_capabilities TSRMLS_CC);


-   ret = mysqlnd_auth_change_user(conn, user, 
strlen(user), passwd, db, strlen(db), passwd_len, silent,
+   ret = mysqlnd_auth_change_user(conn, user, 
strlen(user), passwd, passwd_len, db, strlen(db), silent,

   first_call,

   requested_protocol,

   scrambled_data, scrambled_data_len,

Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd_auth.c
===
--- php/php-src/trunk/ext/mysqlnd/mysqlnd_auth.c2011-01-24 12:34:47 UTC 
(rev 307710)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd_auth.c2011-01-24 13:58:18 UTC 
(rev 307711)
@@ -34,9 +34,9 @@
 mysqlnd_auth_handshake(MYSQLND * conn,
  const char * const 
user,
  const char * const 
passwd,
+ const size_t 
passwd_len,
  const char * const db,
  const size_t db_len,
- const size_t 
passwd_len,
  const MYSQLND_OPTIONS 
* const options,
  unsigned long 
mysql_flags,
  unsigned int 
server_charset_no,
@@ -158,9 +158,9 @@
const char * 
const user,
const size_t 
user_len,
const char * 
const passwd,
+   const size_t 
passwd_len,
const char * 
const db,
const size_t 
db_len,
-   const size_t 
passwd_len,
const zend_bool 
silent,
zend_bool 
use_full_blown_auth_packet,
const char * 
const auth_protocol,
@@ -172,14 +172,7 @@
size_t * 
switch_to_auth_protocol_data_len
TSRMLS_DC)
 {
-   /*
- User could be max 16 * 3 (utf8), pass is 20 usually, db is up to 64*3
- Stack space is not that expensive, so use a bit more to be protected 
against
- buffer overflows.
-   */
enum_func_status ret = FAIL;
-   char buffer[MYSQLND_MAX_ALLOWED_USER_LEN + 1 + SCRAMBLE_LENGTH + 
MYSQLND_MAX_ALLOWED_DB_LEN + 1 + 2 /* charset*/ ];
-   char *p = buffer;
const MYSQLND_CHARSET 

[PHP-CVS] svn: /php/php-src/trunk/ext/mysqlnd/ mysqlnd.c mysqlnd_statistics.c

2011-01-19 Thread Andrey Hristov
andrey   Wed, 19 Jan 2011 17:51:02 +

Revision: http://svn.php.net/viewvc?view=revisionrevision=307592

Log:
fix ZTS build

Changed paths:
U   php/php-src/trunk/ext/mysqlnd/mysqlnd.c
U   php/php-src/trunk/ext/mysqlnd/mysqlnd_statistics.c

Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd.c
===
--- php/php-src/trunk/ext/mysqlnd/mysqlnd.c 2011-01-19 17:17:52 UTC (rev 
307591)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd.c 2011-01-19 17:51:02 UTC (rev 
307592)
@@ -2307,7 +2307,7 @@
conn-net = mysqlnd_net_init(conn-persistent TSRMLS_CC);
conn-protocol = mysqlnd_protocol_init(conn-persistent TSRMLS_CC);

-   DBG_RETURN(conn-net  conn-protocol? PASS:FAIL);
+   DBG_RETURN(conn-stats  conn-net  conn-protocol? PASS:FAIL);
 }
 /* }}} */


Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd_statistics.c
===
--- php/php-src/trunk/ext/mysqlnd/mysqlnd_statistics.c  2011-01-19 17:17:52 UTC 
(rev 307591)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd_statistics.c  2011-01-19 17:51:02 UTC 
(rev 307592)
@@ -246,7 +246,6 @@
 {
*stats = calloc(1, sizeof(MYSQLND_STATS));
if (*stats == NULL) {
-   DBG_ENTER(mysqlnd_stats_init failed to calloc stats context);
return;
}
(*stats)-values = calloc(statistic_count, sizeof(uint64_t));
@@ -256,7 +255,6 @@
 #ifdef ZTS
(*stats)-LOCK_access = tsrm_mutex_alloc();
 #endif
-
 }
 /* }}} */


-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[PHP-CVS] svn: /php/php-src/trunk/ext/mysqlnd/ mysqlnd.c mysqlnd_auth.c mysqlnd_priv.h mysqlnd_structs.h mysqlnd_wireprotocol.c mysqlnd_wireprotocol.h

2011-01-14 Thread Andrey Hristov
andrey   Fri, 14 Jan 2011 20:04:17 +

Revision: http://svn.php.net/viewvc?view=revisionrevision=307493

Log:
Update on the mysqlnd auth plugins, changed the plugin
structure and where they load themselves.
0xFE packets (method switch) needs to be done, additional
wire-level packet to be created to be parsed and the packet
doesn't fit the PACKET_OK structure anymore.

Changed paths:
U   php/php-src/trunk/ext/mysqlnd/mysqlnd.c
U   php/php-src/trunk/ext/mysqlnd/mysqlnd_auth.c
U   php/php-src/trunk/ext/mysqlnd/mysqlnd_priv.h
U   php/php-src/trunk/ext/mysqlnd/mysqlnd_structs.h
U   php/php-src/trunk/ext/mysqlnd/mysqlnd_wireprotocol.c
U   php/php-src/trunk/ext/mysqlnd/mysqlnd_wireprotocol.h

Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd.c
===
--- php/php-src/trunk/ext/mysqlnd/mysqlnd.c	2011-01-14 20:02:49 UTC (rev 307492)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd.c	2011-01-14 20:04:17 UTC (rev 307493)
@@ -177,10 +177,10 @@
 		mnd_pefree(conn-host_info, pers);
 		conn-host_info = NULL;
 	}
-	if (conn-scramble) {
-		DBG_INF(Freeing scramble);
-		mnd_pefree(conn-scramble, pers);
-		conn-scramble = NULL;
+	if (conn-auth_plugin_data) {
+		DBG_INF(Freeing auth_plugin_data);
+		mnd_pefree(conn-auth_plugin_data, pers);
+		conn-auth_plugin_data = NULL;
 	}
 	if (conn-last_message) {
 		mnd_pefree(conn-last_message, pers);
@@ -524,15 +524,15 @@
 			auth_plugin = mysqlnd_plugin_find(plugin_name);
 			efree(plugin_name);
 			if (!auth_plugin) {
-php_error_docref(NULL TSRMLS_CC, E_WARNING, Server requested authentication method uknown to the client [%s], requested_protocol);
-SET_CLIENT_ERROR(conn-error_info, CR_NOT_IMPLEMENTED, UNKNOWN_SQLSTATE, Server requested authentication method uknown to the client);
+php_error_docref(NULL TSRMLS_CC, E_WARNING, The server requested authentication method uknown to the client [%s], requested_protocol);
+SET_CLIENT_ERROR(conn-error_info, CR_NOT_IMPLEMENTED, UNKNOWN_SQLSTATE, The server requested authentication method uknown to the client);
 break;
 			}

 			DBG_INF(plugin found);

-			ret = auth_plugin-methods.auth_handshake(conn, user, passwd, db, db_len, passwd_len, greet_packet, options, mysql_flags,
-	  switch_to_auth_protocol TSRMLS_CC);
+			ret = mysqlnd_auth_handshake(conn, user, passwd, db, db_len, passwd_len, greet_packet, options, mysql_flags,
+		 auth_plugin, switch_to_auth_protocol TSRMLS_CC);
 			DBG_INF_FMT(switch_to_auth_protocol=%s, switch_to_auth_protocol? switch_to_auth_protocol:n/a);
 		} while (ret == FAIL  switch_to_auth_protocol != NULL);

@@ -1942,6 +1942,7 @@
 		db = ;
 	}

+
 	{
 		char * switch_to_auth_protocol = NULL;
 		const char * requested_protocol = NULL;
@@ -1961,13 +1962,15 @@
 			efree(plugin_name);
 			if (!auth_plugin) {
 if (!silent) {
-	php_error_docref(NULL TSRMLS_CC, E_WARNING, Server requested authentication method uknown to the client [%s], requested_protocol);
+	php_error_docref(NULL TSRMLS_CC, E_WARNING, The server requested authentication method uknown to the client [%s], requested_protocol);
 }
-SET_CLIENT_ERROR(conn-error_info, CR_NOT_IMPLEMENTED, UNKNOWN_SQLSTATE, Server requested authentication method uknown to the client);
+SET_CLIENT_ERROR(conn-error_info, CR_NOT_IMPLEMENTED, UNKNOWN_SQLSTATE, The server requested authentication method uknown to the client);
 break;
 			}
 			DBG_INF(plugin found);
-			ret = auth_plugin-methods.auth_change_user(conn, user, strlen(user), passwd, db, strlen(db), passwd_len, silent, switch_to_auth_protocol TSRMLS_CC);
+			ret = mysqlnd_auth_change_user(conn, user, strlen(user), passwd, db, strlen(db), passwd_len, silent,
+		   auth_plugin, switch_to_auth_protocol TSRMLS_CC);
+
 			DBG_INF_FMT(switch_to_auth_protocol=%s, switch_to_auth_protocol? switch_to_auth_protocol:n/a);
 		} while (ret == FAIL  switch_to_auth_protocol != NULL);
 		if (ret == PASS) {

Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd_auth.c
===
--- php/php-src/trunk/ext/mysqlnd/mysqlnd_auth.c	2011-01-14 20:02:49 UTC (rev 307492)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd_auth.c	2011-01-14 20:04:17 UTC (rev 307493)
@@ -30,8 +30,8 @@


 /* {{{ mysqlnd_native_auth_handshake */
-static enum_func_status
-mysqlnd_native_auth_handshake(MYSQLND * conn,
+enum_func_status
+mysqlnd_auth_handshake(MYSQLND * conn,
 			  const char * const user,
 			  const char * const passwd,
 			  const char * const db,
@@ -40,6 +40,7 @@
 			  const MYSQLND_PACKET_GREET * const greet_packet,
 			  const MYSQLND_OPTIONS * const options,
 			  unsigned long mysql_flags,
+			  struct st_mysqlnd_authentication_plugin * auth_plugin,
 			  char ** switch_to_auth_protocol
 			  TSRMLS_DC)
 {
@@ -50,14 +51,6 @@

 	DBG_ENTER(mysqlnd_native_auth_handshake);

-	/* 5.5.x reports 21 

[PHP-CVS] svn: /php/php-src/trunk/ext/mysqlnd/ mysqlnd.c mysqlnd_wireprotocol.c mysqlnd_wireprotocol.h

2011-01-11 Thread Andrey Hristov
andrey   Tue, 11 Jan 2011 13:02:57 +

Revision: http://svn.php.net/viewvc?view=revisionrevision=307377

Log:
Use common code to handle initial authentication and
COM_CHANGE_USER

Changed paths:
U   php/php-src/trunk/ext/mysqlnd/mysqlnd.c
U   php/php-src/trunk/ext/mysqlnd/mysqlnd_wireprotocol.c
U   php/php-src/trunk/ext/mysqlnd/mysqlnd_wireprotocol.h

Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd.c
===
--- php/php-src/trunk/ext/mysqlnd/mysqlnd.c	2011-01-11 13:01:30 UTC (rev 307376)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd.c	2011-01-11 13:02:57 UTC (rev 307377)
@@ -427,7 +427,63 @@
 /* }}} */


-#define MYSQLND_ASSEBLED_PACKET_MAX_SIZE 3UL*1024UL*1024UL*1024UL
+#define MYSQLND_ASSEMBLED_PACKET_MAX_SIZE 3UL*1024UL*1024UL*1024UL
+/* {{{ mysqlnd_switch_to_ssl_if_needed */
+static MYSQLND_PACKET_AUTH *
+mysqlnd_switch_to_ssl_if_needed(
+			MYSQLND * conn,
+			const MYSQLND_PACKET_GREET * const greet_packet,
+			const MYSQLND_OPTIONS * const options,
+			unsigned long mysql_flags
+			TSRMLS_DC
+		)
+{
+	const MYSQLND_CHARSET * charset = NULL;
+	MYSQLND_PACKET_AUTH * auth_packet = conn-protocol-m.get_auth_packet(conn-protocol, FALSE TSRMLS_CC);
+	DBG_ENTER(mysqlnd_switch_to_ssl_if_needed);
+
+	if (!auth_packet) {
+		SET_OOM_ERROR(conn-error_info);
+		goto err;
+	}
+	auth_packet-client_flags = mysql_flags;
+	auth_packet-max_packet_size = MYSQLND_ASSEMBLED_PACKET_MAX_SIZE;
+
+	if (options-charset_name  (charset = mysqlnd_find_charset_name(options-charset_name))) {
+		auth_packet-charset_no	= charset-nr;
+	} else {
+#if MYSQLND_UNICODE
+		auth_packet-charset_no	= 200;/* utf8 - swedish collation, check mysqlnd_charset.c */
+#else
+		auth_packet-charset_no	= greet_packet-charset_no;
+#endif
+	}
+
+#ifdef MYSQLND_SSL_SUPPORTED
+	if ((greet_packet-server_capabilities  CLIENT_SSL)  (mysql_flags  CLIENT_SSL)) {
+		zend_bool verify = mysql_flags  CLIENT_SSL_VERIFY_SERVER_CERT? TRUE:FALSE;
+		DBG_INF(Switching to SSL);
+		if (!PACKET_WRITE(auth_packet, conn)) {
+			CONN_SET_STATE(conn, CONN_QUIT_SENT);
+			SET_CLIENT_ERROR(conn-error_info, CR_SERVER_GONE_ERROR, UNKNOWN_SQLSTATE, mysqlnd_server_gone);
+			goto err;
+		}
+
+		conn-net-m.set_client_option(conn-net, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, (const char *) verify TSRMLS_CC);
+
+		if (FAIL == conn-net-m.enable_ssl(conn-net TSRMLS_CC)) {
+			goto err;
+		}
+	}
+#endif
+	DBG_RETURN(auth_packet);
+err:
+	PACKET_FREE(auth_packet);
+	DBG_RETURN(NULL);
+}
+/* }}} */
+
+
 /* {{{ mysqlnd_connect_run_authentication */
 static enum_func_status
 mysqlnd_connect_run_authentication(
@@ -441,39 +497,28 @@
 			unsigned long mysql_flags
 			TSRMLS_DC)
 {
-	const MYSQLND_CHARSET * charset = NULL;
 	enum_func_status ret = FAIL;
-	MYSQLND_PACKET_AUTH * auth_packet = conn-protocol-m.get_auth_packet(conn-protocol, FALSE TSRMLS_CC);
+	MYSQLND_PACKET_AUTH * auth_packet = NULL;
 	MYSQLND_PACKET_OK * ok_packet = conn-protocol-m.get_ok_packet(conn-protocol, FALSE TSRMLS_CC);

 	DBG_ENTER(mysqlnd_connect_run_authentication);

-	if (!auth_packet || !ok_packet) {
+	if (!ok_packet) {
 		SET_OOM_ERROR(conn-error_info);
 		goto err;
 	}

-#ifdef MYSQLND_SSL_SUPPORTED
-	if ((greet_packet-server_capabilities  CLIENT_SSL)  (mysql_flags  CLIENT_SSL)) {
-		auth_packet-send_half_packet = TRUE;
+	auth_packet = mysqlnd_switch_to_ssl_if_needed(conn, greet_packet, options, mysql_flags TSRMLS_CC);
+
+	if (!auth_packet) {
+		goto err;
 	}
-#endif
+
+	auth_packet-send_auth_data = TRUE;
 	auth_packet-user		= user;
 	auth_packet-password	= passwd;
-
-	if (options-charset_name  (charset = mysqlnd_find_charset_name(options-charset_name))) {
-		auth_packet-charset_no	= charset-nr;
-	} else {
-#if MYSQLND_UNICODE
-		auth_packet-charset_no	= 200;/* utf8 - swedish collation, check mysqlnd_charset.c */
-#else
-		auth_packet-charset_no	= greet_packet-charset_no;
-#endif
-	}
 	auth_packet-db			= db;
 	auth_packet-db_len		= db_len;
-	auth_packet-max_packet_size= MYSQLND_ASSEBLED_PACKET_MAX_SIZE;
-	auth_packet-client_flags= mysql_flags;

 	conn-scramble = auth_packet-server_scramble_buf = mnd_pemalloc(SCRAMBLE_LENGTH, conn-persistent);
 	if (!conn-scramble) {
@@ -488,27 +533,6 @@
 		goto err;
 	}

-#ifdef MYSQLND_SSL_SUPPORTED
-	if (auth_packet-send_half_packet) {
-		zend_bool verify = mysql_flags  CLIENT_SSL_VERIFY_SERVER_CERT? TRUE:FALSE;
-		DBG_INF(Switching to SSL);
-
-		conn-net-m.set_client_option(conn-net, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, (const char *) verify TSRMLS_CC);
-
-		if (FAIL == conn-net-m.enable_ssl(conn-net TSRMLS_CC)) {
-			goto err;
-		}
-
-		auth_packet-send_half_packet = FALSE;
-		if (!PACKET_WRITE(auth_packet, conn)) {
-			CONN_SET_STATE(conn, CONN_QUIT_SENT);
-			SET_CLIENT_ERROR(conn-error_info, CR_SERVER_GONE_ERROR, UNKNOWN_SQLSTATE, mysqlnd_server_gone);
-			goto err;
-		}
-	}
-#endif
-
-
 	if (FAIL == PACKET_READ(ok_packet, conn) || ok_packet-field_count = 0xFE) {
 		if 

[PHP-CVS] svn: /php/php-src/trunk/ext/mysqlnd/ mysqlnd.c mysqlnd_net.c

2010-09-22 Thread Andrey Hristov
andrey   Wed, 22 Sep 2010 15:14:04 +

Revision: http://svn.php.net/viewvc?view=revisionrevision=303679

Log:
Fix for
Request #48082 mysql_connect does not work with named pipes

Bug: http://bugs.php.net/48082 (Analyzed) mysql_connect does not work with 
named pipes
  
Changed paths:
U   php/php-src/trunk/ext/mysqlnd/mysqlnd.c
U   php/php-src/trunk/ext/mysqlnd/mysqlnd_net.c

Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd.c
===
--- php/php-src/trunk/ext/mysqlnd/mysqlnd.c 2010-09-22 14:54:43 UTC (rev 
303678)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd.c 2010-09-22 15:14:04 UTC (rev 
303679)
@@ -556,6 +556,7 @@
char *errstr = NULL;
int errcode = 0, host_len;
zend_bool unix_socket = FALSE;
+   zend_bool named_pipe = FALSE;
zend_bool reconnect = FALSE;
zend_bool saved_compression = FALSE;

@@ -623,9 +624,16 @@
}
transport_len = spprintf(transport, 0, unix://%s, 
socket);
unix_socket = TRUE;
-   } else
+#else
+   if (host_len == sizeof(.) - 1  host[0] == '.') {
+   /* named pipe in socket */
+   if (!socket) {
+   socket = .\\pipe\\MySQL;
+   }
+   transport_len = spprintf(transport, 0, pipe://%s, 
socket);
+   named_pipe = TRUE;
 #endif
-   {
+   } else {
if (!port) {
port = 3306;
}
@@ -742,7 +750,7 @@
goto err; /* OOM */
}

-   if (!unix_socket) {
+   if (!unix_socket  !named_pipe) {
conn-host = mnd_pestrdup(host, conn-persistent);
if (!conn-host) {
SET_OOM_ERROR(conn-error_info);
@@ -765,7 +773,24 @@
}
} else {
conn-unix_socket   = mnd_pestrdup(socket, 
conn-persistent);
-   conn-host_info = mnd_pestrdup(Localhost via 
UNIX socket, conn-persistent);
+   if (unix_socket) {
+   conn-host_info = 
mnd_pestrdup(Localhost via UNIX socket, conn-persistent);
+   } else if (named_pipe) {
+   char *p;
+   spprintf(p, 0, %s via named pipe, 
conn-unix_socket);
+   if (!p) {
+   SET_OOM_ERROR(conn-error_info);
+   goto err; /* OOM */
+   }
+   conn-host_info =  mnd_pestrdup(p, 
conn-persistent);
+   efree(p); /* allocated by spprintf */
+   if (!conn-host_info) {
+   SET_OOM_ERROR(conn-error_info);
+   goto err; /* OOM */
+   }
+   } else {
+   php_error_docref(NULL TSRMLS_CC, E_WARNING, 
Impossible. Should be either socket or a pipe. Report a bug!);
+   }
if (!conn-unix_socket || !conn-host_info) {
SET_OOM_ERROR(conn-error_info);
goto err; /* OOM */

Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd_net.c
===
--- php/php-src/trunk/ext/mysqlnd/mysqlnd_net.c 2010-09-22 14:54:43 UTC (rev 
303678)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd_net.c 2010-09-22 15:14:04 UTC (rev 
303679)
@@ -113,23 +113,30 @@
struct timeval tv;
DBG_ENTER(mysqlnd_net::connect);

-   if (persistent) {
-   hashed_details_len = spprintf(hashed_details, 0, %p, net);
-   DBG_INF_FMT(hashed_details=%s, hashed_details);
-   }
-
net-packet_no = net-compressed_envelope_packet_no = 0;

-   if (net-options.timeout_connect) {
-   tv.tv_sec = net-options.timeout_connect;
-   tv.tv_usec = 0;
-   }
+   if (scheme_len  (sizeof(pipe://) - 1)  !memcmp(scheme, pipe://, 
sizeof(pipe://) - 1)) {
+   if (persistent) {
+   streams_options |= STREAM_OPEN_PERSISTENT;
+   }
+   streams_options |= IGNORE_URL;
+   net-stream = php_stream_open_wrapper((char*) scheme + 
sizeof(pipe://) - 1, r+, streams_options, NULL);
+   } else {
+   if (persistent) {
+   hashed_details_len = spprintf(hashed_details, 0, %p, 
net);
+   DBG_INF_FMT(hashed_details=%s, hashed_details);
+   }

-   

[PHP-CVS] svn: /php/php-src/trunk/ext/mysqlnd/ mysqlnd.c mysqlnd_statistics.c mysqlnd_statistics.h

2010-01-11 Thread Andrey Hristov
andrey   Mon, 11 Jan 2010 18:27:31 +

Revision: http://svn.php.net/viewvc?view=revisionrevision=293417

Log:
and another change to make the stats API re-usable

Changed paths:
U   php/php-src/trunk/ext/mysqlnd/mysqlnd.c
U   php/php-src/trunk/ext/mysqlnd/mysqlnd_statistics.c
U   php/php-src/trunk/ext/mysqlnd/mysqlnd_statistics.h

Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd.c
===
--- php/php-src/trunk/ext/mysqlnd/mysqlnd.c 2010-01-11 18:06:15 UTC (rev 
293416)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd.c 2010-01-11 18:27:31 UTC (rev 
293417)
@@ -2029,7 +2029,7 @@
 {
DBG_ENTER(mysqlnd_conn::get_connection_stats);
DBG_INF_FMT(conn=%llu, conn-thread_id);
-   mysqlnd_fill_stats_hash(conn-stats, return_value TSRMLS_CC 
ZEND_FILE_LINE_CC);
+   mysqlnd_fill_stats_hash(conn-stats, mysqlnd_stats_values_names, 
return_value TSRMLS_CC ZEND_FILE_LINE_CC);
DBG_VOID_RETURN;
 }
 /* }}} */

Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd_statistics.c
===
--- php/php-src/trunk/ext/mysqlnd/mysqlnd_statistics.c  2010-01-11 18:06:15 UTC 
(rev 293416)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd_statistics.c  2010-01-11 18:27:31 UTC 
(rev 293417)
@@ -190,13 +190,13 @@


 /* {{{ mysqlnd_fill_stats_hash */
-void
-mysqlnd_fill_stats_hash(const MYSQLND_STATS * const stats, zval *return_value 
TSRMLS_DC ZEND_FILE_LINE_DC)
+PHPAPI void
+mysqlnd_fill_stats_hash(const MYSQLND_STATS * const stats, const 
MYSQLND_STRING * names, zval *return_value TSRMLS_DC ZEND_FILE_LINE_DC)
 {
unsigned int i;

-   mysqlnd_array_init(return_value, STAT_LAST);
-   for (i = 0; i  STAT_LAST; i++) {
+   mysqlnd_array_init(return_value, stats-count);
+   for (i = 0; i  stats-count; i++) {
 #if PHP_MAJOR_VERSION = 6
UChar *ustr, *tstr;
int ulen, tlen;
@@ -205,15 +205,13 @@

sprintf((char *)tmp, MYSQLND_LLU_SPEC, stats-values[i]);
 #if PHP_MAJOR_VERSION = 6
-   zend_string_to_unicode(UG(utf8_conv), ustr, ulen, 
mysqlnd_stats_values_names[i].s,
-   
mysqlnd_stats_values_names[i].l + 1 TSRMLS_CC);
+   zend_string_to_unicode(UG(utf8_conv), ustr, ulen, names[i].s, 
names[i].l + 1 TSRMLS_CC);
zend_string_to_unicode(UG(utf8_conv), tstr, tlen, tmp, 
strlen(tmp) + 1 TSRMLS_CC);
add_u_assoc_unicode_ex(return_value, IS_UNICODE, ZSTR(ustr), 
ulen, tstr, 1);
efree(ustr);
efree(tstr);
 #else
-   add_assoc_string_ex(return_value, 
mysqlnd_stats_values_names[i].s,
-   
mysqlnd_stats_values_names[i].l + 1, tmp, 1);
+   add_assoc_string_ex(return_value, names[i].s, names[i].l + 1, 
tmp, 1);
 #endif
}
 }
@@ -229,7 +227,7 @@
memset(stats, 0, sizeof(stats));
stats_ptr = stats;
}
-   mysqlnd_fill_stats_hash(stats_ptr, return_value TSRMLS_CC 
ZEND_FILE_LINE_CC);
+   mysqlnd_fill_stats_hash(stats_ptr, mysqlnd_stats_values_names, 
return_value TSRMLS_CC ZEND_FILE_LINE_CC);
DBG_VOID_RETURN;
 }
 /* }}} */

Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd_statistics.h
===
--- php/php-src/trunk/ext/mysqlnd/mysqlnd_statistics.h  2010-01-11 18:06:15 UTC 
(rev 293416)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd_statistics.h  2010-01-11 18:27:31 UTC 
(rev 293417)
@@ -163,10 +163,8 @@
 MYSQLND_INC_STATISTIC_W_VALUE3(MYSQLND_G(collect_statistics), 
(conn_stats), (statistic1), (value1), (statistic2), (value2), (statistic3), 
(value3));


-void mysqlnd_fill_stats_hash(const MYSQLND_STATS * const stats, zval 
*return_value
-TSRMLS_DC 
ZEND_FILE_LINE_DC);
+PHPAPI void mysqlnd_fill_stats_hash(const MYSQLND_STATS * const stats, const 
MYSQLND_STRING * names, zval *return_value TSRMLS_DC ZEND_FILE_LINE_DC);

-
 PHPAPI void mysqlnd_stats_init(MYSQLND_STATS ** stats, size_t statistic_count);
 PHPAPI void mysqlnd_stats_end(MYSQLND_STATS * stats);


-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php