]> granicus.if.org Git - php/commitdiff
Fix for
authorAndrey Hristov <andrey@php.net>
Wed, 22 Sep 2010 15:14:04 +0000 (15:14 +0000)
committerAndrey Hristov <andrey@php.net>
Wed, 22 Sep 2010 15:14:04 +0000 (15:14 +0000)
Request #48082 mysql_connect does not work with named pipes

ext/mysqlnd/mysqlnd.c
ext/mysqlnd/mysqlnd_net.c

index 90324d5e09083ca89333e7991d06ff0340ad5c12..36e6bcb028335de7dd8d298d741e2d85f53f0c67 100644 (file)
@@ -556,6 +556,7 @@ MYSQLND_METHOD(mysqlnd_conn, connect)(MYSQLND * conn,
        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 @@ MYSQLND_METHOD(mysqlnd_conn, connect)(MYSQLND * conn,
                        }
                        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 @@ MYSQLND_METHOD(mysqlnd_conn, connect)(MYSQLND * conn,
                        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 @@ MYSQLND_METHOD(mysqlnd_conn, connect)(MYSQLND * conn,
                        }
                } 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 */
index 3d25362f82cba0b952010fde9970d75fd1c6726d..c4c361bb5d890f3505f27e9fa5504f681d5a7727 100644 (file)
@@ -113,23 +113,30 @@ MYSQLND_METHOD(mysqlnd_net, connect)(MYSQLND_NET * net, const char * const schem
        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);
+               }
 
-       DBG_INF_FMT("calling php_stream_xport_create");
-       net->stream = php_stream_xport_create(scheme, scheme_len, streams_options, streams_flags,
-                                                                                 hashed_details, (net->options.timeout_connect) ? &tv : NULL,
-                                                                                 NULL /*ctx*/, errstr, errcode);
+               if (net->options.timeout_connect) {
+                       tv.tv_sec = net->options.timeout_connect;
+                       tv.tv_usec = 0;
+               }
 
+               DBG_INF_FMT("calling php_stream_xport_create");
+               net->stream = php_stream_xport_create(scheme, scheme_len, streams_options, streams_flags,
+                                                                                         hashed_details, (net->options.timeout_connect) ? &tv : NULL,
+                                                                                         NULL /*ctx*/, errstr, errcode);
+       }
        if (*errstr || !net->stream) {
                if (hashed_details) {
                        efree(hashed_details); /* allocated by spprintf */