Diff for /embedaddon/lighttpd/src/mod_mysql_vhost.c between versions 1.1.1.1 and 1.1.1.2

version 1.1.1.1, 2013/10/14 10:32:47 version 1.1.1.2, 2014/06/15 20:20:06
Line 127  static void* mod_mysql_vhost_connection_data(server *s Line 127  static void* mod_mysql_vhost_connection_data(server *s
         UNUSED(srv);          UNUSED(srv);
   
 #ifdef DEBUG  #ifdef DEBUG
        log_error_write(srv, __FILE__, __LINE__, "ss",        log_error_write(srv, __FILE__, __LINE__, "ss",
                 "mod_mysql_connection_data", c ? "old" : "NEW");                  "mod_mysql_connection_data", c ? "old" : "NEW");
 #endif  #endif
   
Line 173  SERVER_FUNC(mod_mysql_vhost_set_defaults) { Line 173  SERVER_FUNC(mod_mysql_vhost_set_defaults) {
   
         char *qmark;          char *qmark;
         size_t i = 0;          size_t i = 0;
           buffer *sel;
   
         config_values_t cv[] = {          config_values_t cv[] = {
                { "mysql-vhost.db",     NULL, T_CONFIG_STRING,  T_CONFIG_SCOPE_SERVER },                { "mysql-vhost.db",       NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_SERVER },
                { "mysql-vhost.user",   NULL, T_CONFIG_STRING,  T_CONFIG_SCOPE_SERVER },                { "mysql-vhost.user",     NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_SERVER },
                { "mysql-vhost.pass",   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.sock",     NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_SERVER },
                { "mysql-vhost.sql",    NULL, T_CONFIG_STRING,  T_CONFIG_SCOPE_SERVER },                { "mysql-vhost.sql",      NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_SERVER },
                { "mysql-vhost.hostname", NULL, T_CONFIG_STRING,T_CONFIG_SCOPE_SERVER },                { "mysql-vhost.hostname", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_SERVER },
                { "mysql-vhost.port",   NULL, T_CONFIG_SHORT,   T_CONFIG_SCOPE_SERVER },                { "mysql-vhost.port",     NULL, T_CONFIG_SHORT,  T_CONFIG_SCOPE_SERVER },
                { NULL,                 NULL, T_CONFIG_UNSET,   T_CONFIG_SCOPE_UNSET }                { NULL,                   NULL, T_CONFIG_UNSET,  T_CONFIG_SCOPE_UNSET }
        };        };
   
        p->config_storage = calloc(1, srv->config_context->used * sizeof(specific_config *));        p->config_storage = calloc(1, srv->config_context->used * sizeof(plugin_config *));
         sel = buffer_init();
   
         for (i = 0; i < srv->config_context->used; i++) {          for (i = 0; i < srv->config_context->used; i++) {
                 plugin_config *s;                  plugin_config *s;
                 buffer *sel;  
   
   
                 s = calloc(1, sizeof(plugin_config));                  s = calloc(1, sizeof(plugin_config));
                 s->mydb = buffer_init();                  s->mydb = buffer_init();
                 s->myuser = buffer_init();                  s->myuser = buffer_init();
                 s->mypass = buffer_init();                  s->mypass = buffer_init();
                 s->mysock = buffer_init();                  s->mysock = buffer_init();
                 s->hostname = buffer_init();                  s->hostname = buffer_init();
                s->port   = 0;               /* default port for mysql */                s->port = 0;               /* default port for mysql */
                sel = buffer_init(); 
                 s->mysql = NULL;                  s->mysql = NULL;
   
                 s->mysql_pre = buffer_init();                  s->mysql_pre = buffer_init();
Line 209  SERVER_FUNC(mod_mysql_vhost_set_defaults) { Line 208  SERVER_FUNC(mod_mysql_vhost_set_defaults) {
                 cv[1].destination = s->myuser;                  cv[1].destination = s->myuser;
                 cv[2].destination = s->mypass;                  cv[2].destination = s->mypass;
                 cv[3].destination = s->mysock;                  cv[3].destination = s->mysock;
                   buffer_reset(sel);
                 cv[4].destination = sel;                  cv[4].destination = sel;
                 cv[5].destination = s->hostname;                  cv[5].destination = s->hostname;
                 cv[6].destination = &(s->port);                  cv[6].destination = &(s->port);
   
                 p->config_storage[i] = s;                  p->config_storage[i] = s;
   
                if (config_insert_values_global(srv,                if (config_insert_values_global(srv,
                         ((data_config *)srv->config_context->data[i])->value,                          ((data_config *)srv->config_context->data[i])->value,
                         cv)) return HANDLER_ERROR;                          cv)) return HANDLER_ERROR;
   
Line 249  SERVER_FUNC(mod_mysql_vhost_set_defaults) { Line 249  SERVER_FUNC(mod_mysql_vhost_set_defaults) {
                         if (NULL == (s->mysql = mysql_init(NULL))) {                          if (NULL == (s->mysql = mysql_init(NULL))) {
                                 log_error_write(srv, __FILE__, __LINE__, "s", "mysql_init() failed, exiting...");                                  log_error_write(srv, __FILE__, __LINE__, "s", "mysql_init() failed, exiting...");
   
                                   buffer_free(sel);
                                 return HANDLER_ERROR;                                  return HANDLER_ERROR;
                         }                          }
   
Line 260  SERVER_FUNC(mod_mysql_vhost_set_defaults) { Line 261  SERVER_FUNC(mod_mysql_vhost_set_defaults) {
 #define FOO(x) (s->x->used ? s->x->ptr : NULL)  #define FOO(x) (s->x->used ? s->x->ptr : NULL)
   
 #if MYSQL_VERSION_ID >= 40100  #if MYSQL_VERSION_ID >= 40100
                        /* CLIENT_MULTI_STATEMENTS first appeared in 4.1 */                         /* CLIENT_MULTI_STATEMENTS first appeared in 4.1 */ 
                         if (!mysql_real_connect(s->mysql, FOO(hostname), FOO(myuser), FOO(mypass),                          if (!mysql_real_connect(s->mysql, FOO(hostname), FOO(myuser), FOO(mypass),
                                                 FOO(mydb), s->port, FOO(mysock), CLIENT_MULTI_STATEMENTS)) {                                                  FOO(mydb), s->port, FOO(mysock), CLIENT_MULTI_STATEMENTS)) {
 #else  #else
Line 269  SERVER_FUNC(mod_mysql_vhost_set_defaults) { Line 270  SERVER_FUNC(mod_mysql_vhost_set_defaults) {
 #endif  #endif
                                 log_error_write(srv, __FILE__, __LINE__, "s", mysql_error(s->mysql));                                  log_error_write(srv, __FILE__, __LINE__, "s", mysql_error(s->mysql));
   
                                   buffer_free(sel);
                                 return HANDLER_ERROR;                                  return HANDLER_ERROR;
                         }                          }
 #undef FOO  #undef FOO
   
#if 0                        fd_close_on_exec(s->mysql->net.fd);
                        /* set close_on_exec for mysql the hard way */ 
                        /* Note: this only works as it is done during startup, */ 
                        /* otherwise we cannot be sure that mysql is fd i-1 */ 
                        { int fd; 
                        if (-1 != (fd = open("/dev/null", 0))) { 
                                close(fd); 
#ifdef FD_CLOEXEC 
                                fcntl(fd-1, F_SETFD, FD_CLOEXEC); 
#endif 
                        } } 
#else 
#ifdef FD_CLOEXEC 
                        fcntl(s->mysql->net.fd, F_SETFD, FD_CLOEXEC); 
#endif 
#endif 
                 }                  }
         }          }
   
           buffer_free(sel);
         return HANDLER_GO_ON;          return HANDLER_GO_ON;
 }  }
   
Line 351  CONNECTION_FUNC(mod_mysql_vhost_handle_docroot) { Line 339  CONNECTION_FUNC(mod_mysql_vhost_handle_docroot) {
         mod_mysql_vhost_patch_connection(srv, con, p);          mod_mysql_vhost_patch_connection(srv, con, p);
   
         if (!p->conf.mysql) return HANDLER_GO_ON;          if (!p->conf.mysql) return HANDLER_GO_ON;
           if (0 == p->conf.mysql_pre->used) return HANDLER_GO_ON;
   
         /* sets up connection data if not done yet */          /* sets up connection data if not done yet */
         c = mod_mysql_vhost_connection_data(srv, con, p_d);          c = mod_mysql_vhost_connection_data(srv, con, p_d);
   
         /* check if cached this connection */          /* check if cached this connection */
         if (c->server_name->used && /* con->uri.authority->used && */          if (c->server_name->used && /* con->uri.authority->used && */
            buffer_is_equal(c->server_name, con->uri.authority)) goto GO_ON;            buffer_is_equal(c->server_name, con->uri.authority)) goto GO_ON;
   
         /* build and run SQL query */          /* build and run SQL query */
         buffer_copy_string_buffer(p->tmp_buf, p->conf.mysql_pre);          buffer_copy_string_buffer(p->tmp_buf, p->conf.mysql_pre);
         if (p->conf.mysql_post->used) {          if (p->conf.mysql_post->used) {
                buffer_append_string_buffer(p->tmp_buf, con->uri.authority);                /* escape the uri.authority */
                 unsigned long to_len;
 
                 /* 'to' has to be 'from_len * 2 + 1' */
                 buffer_prepare_append(p->tmp_buf, (con->uri.authority->used - 1) * 2 + 1);
 
                 to_len = mysql_real_escape_string(p->conf.mysql,
                                 p->tmp_buf->ptr + p->tmp_buf->used - 1,
                                 con->uri.authority->ptr, con->uri.authority->used - 1);
                 p->tmp_buf->used += to_len;
 
                 buffer_append_string_buffer(p->tmp_buf, p->conf.mysql_post);                  buffer_append_string_buffer(p->tmp_buf, p->conf.mysql_post);
         }          }
        if (mysql_query(p->conf.mysql, p->tmp_buf->ptr)) {        if (mysql_real_query(p->conf.mysql, p->tmp_buf->ptr, p->tmp_buf->used - 1)) {
                 log_error_write(srv, __FILE__, __LINE__, "s", mysql_error(p->conf.mysql));                  log_error_write(srv, __FILE__, __LINE__, "s", mysql_error(p->conf.mysql));
                 goto ERR500;                  goto ERR500;
         }          }
Line 389  CONNECTION_FUNC(mod_mysql_vhost_handle_docroot) { Line 388  CONNECTION_FUNC(mod_mysql_vhost_handle_docroot) {
                 log_error_write(srv, __FILE__, __LINE__, "sb", strerror(errno), p->tmp_buf);                  log_error_write(srv, __FILE__, __LINE__, "sb", strerror(errno), p->tmp_buf);
                 goto ERR500;                  goto ERR500;
         }          }
        if (!S_ISDIR(sce->st.st_mode)) {        if (!S_ISDIR(sce->st.st_mode)) {
                 log_error_write(srv, __FILE__, __LINE__, "sb", "Not a directory", p->tmp_buf);                  log_error_write(srv, __FILE__, __LINE__, "sb", "Not a directory", p->tmp_buf);
                 goto ERR500;                  goto ERR500;
         }          }
Line 416  CONNECTION_FUNC(mod_mysql_vhost_handle_docroot) { Line 415  CONNECTION_FUNC(mod_mysql_vhost_handle_docroot) {
 #endif  #endif
   
         /* fix virtual server and docroot */          /* fix virtual server and docroot */
GO_ON:  buffer_copy_string_buffer(con->server_name, c->server_name);GO_ON:
         buffer_copy_string_buffer(con->server_name, c->server_name);
         buffer_copy_string_buffer(con->physical.doc_root, c->document_root);          buffer_copy_string_buffer(con->physical.doc_root, c->document_root);
   
 #ifdef DEBUG  #ifdef DEBUG
Line 427  GO_ON: buffer_copy_string_buffer(con->server_name, c-> Line 427  GO_ON: buffer_copy_string_buffer(con->server_name, c->
 #endif  #endif
         return HANDLER_GO_ON;          return HANDLER_GO_ON;
   
ERR500: if (result) mysql_free_result(result);ERR500:
         if (result) mysql_free_result(result);
 #if MYSQL_VERSION_ID >= 40100  #if MYSQL_VERSION_ID >= 40100
         while (mysql_next_result(p->conf.mysql) == 0);          while (mysql_next_result(p->conf.mysql) == 0);
 #endif  #endif

Removed from v.1.1.1.1  
changed lines
  Added in v.1.1.1.2


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>