Ticket #158 (new enhancement)

Opened 3 years ago

Last modified 14 months ago

Add support for host/ip connects in mod_mysql_vhost

Reported by: neonman <jonas@…> Owned by: jan
Priority: normal Milestone:
Component: mod_mysql_vhost Version:
Severity: normal Keywords: mod_mysql_vhost
Cc: Blocked By:
Need User Feedback: Blocking:

Description

This patch adds support for the mysql-vhost.host config option which makes mod_mysql_vhost able to connect to a remote mysqld to fetch vhost info, only connections through sockets were possible before

The code may not be of the highest standards (read: I usually don't code C), but maby it will help someone anyways.

--- lighttpd-1.3.14/src/mod_mysql_vhost.c   2005-04-20 18:24:45.000000000 +0200
+++ lighttpd-1.3.14.new/src/mod_mysql_vhost.c   2005-06-15 15:35:53.000000000 +0200
@@ -36,6 +36,7 @@
    buffer  *myuser;
    buffer  *mypass;
    buffer  *mysock;
+   buffer  *myhost;

    buffer  *mysql_pre;
    buffer  *mysql_post;
@@ -94,6 +95,7 @@
            buffer_free(s->myuser);
            buffer_free(s->mypass);
            buffer_free(s->mysock);
+           buffer_free(s->myhost);
            buffer_free(s->mysql_pre);
            buffer_free(s->mysql_post);

@@ -169,6 +171,7 @@
        { "mysql-vhost.user",   NULL, T_CONFIG_STRING,  T_CONFIG_SCOPE_SERVER },
        { "mysql-vhost.pass",   NULL, T_CONFIG_STRING,  T_CONFIG_SCOPE_SERVER },
        { "mysql-vhost.sock",   NULL, T_CONFIG_STRING,  T_CONFIG_SCOPE_SERVER },
+       { "mysql-vhost.host",   NULL, T_CONFIG_STRING,  T_CONFIG_SCOPE_SERVER },    
        { "mysql-vhost.sql",    NULL, T_CONFIG_STRING,  T_CONFIG_SCOPE_SERVER },
                 { NULL,            NULL, T_CONFIG_UNSET,   T_CONFIG_SCOPE_UNSET }
         };
@@ -185,6 +188,7 @@
        s->myuser = buffer_init();
        s->mypass = buffer_init();
        s->mysock = buffer_init();
+       s->myhost = buffer_init();
        sel = buffer_init();
 #ifdef HAVE_MYSQL
        s->mysql = NULL;
@@ -197,7 +201,8 @@
        cv[1].destination = s->myuser;
        cv[2].destination = s->mypass;
        cv[3].destination = s->mysock;
-       cv[4].destination = sel;
+       cv[4].destination = s->myhost;
+       cv[5].destination = sel;

        p->config_storage[i] = s;

@@ -216,11 +221,13 @@
            buffer_copy_string_buffer(s->mysql_pre, sel);
        }

-       /* all have to be set */
-       if (!(buffer_is_empty(s->myuser) ||
+       /* user, pass, db and EITHER sock or host has to be set (Will default to socket if both is set) */
+       if (!((buffer_is_empty(s->myuser) ||
              buffer_is_empty(s->mypass) ||
-             buffer_is_empty(s->mydb) ||
-             buffer_is_empty(s->mysock))) {
+              buffer_is_empty(s->mydb)) ||
+                (buffer_is_empty(s->mysock) &&
+                    buffer_is_empty(s->myhost)))) {
+              
 #ifdef HAVE_MYSQL
            int fd;

@@ -230,12 +237,21 @@
                return HANDLER_ERROR;
            }

-           if (!mysql_real_connect(s->mysql, NULL, s->myuser->ptr, s->mypass->ptr, 
-                       s->mydb->ptr, 0, s->mysock->ptr, 0)) {
-               log_error_write(srv, __FILE__, __LINE__, "s", mysql_error(s->mysql));
-               
-               return HANDLER_ERROR;
-           }
+            if (!buffer_is_empty(s->myhost)) {
+               if (!mysql_real_connect(s->mysql, s->myhost->ptr, s->myuser->ptr, s->mypass->ptr, 
+                           s->mydb->ptr, 0, NULL, 0)) {
+                   log_error_write(srv, __FILE__, __LINE__, "s", mysql_error(s->mysql));
+                   
+                   return HANDLER_ERROR;
+               }
+            } else {
+               if (!mysql_real_connect(s->mysql, NULL, s->myuser->ptr, s->mypass->ptr, 
+                           s->mydb->ptr, 0, s->mysock->ptr, 0)) {
+                   log_error_write(srv, __FILE__, __LINE__, "s", mysql_error(s->mysql));
+                   
+                   return HANDLER_ERROR;
+               }
+            }

            /* set close_on_exec for mysql the hard way */
            /* Note: this only works as it is done during startup, */

Attachments

lighttpd-1.3.14-20050612-1303.mod_mysql_vhost.socks_or_host.patch (3.0 kB) - added by neonman <jonas@…> 3 years ago.
The patch

Change History

Changed 3 years ago by neonman <jonas@…>

The patch

Add/Change #158 (Add support for host/ip connects in mod_mysql_vhost)

Author



Change Properties
<Author field>
Action
as new
 
Note: See TracTickets for help on using tickets.