Changeset 480
- Timestamp:
- 07/28/2005 08:55:55 PM (3 years ago)
- Files:
-
- 1 modified
-
branches/lighttpd-1.3.x/src/mod_mysql_vhost.c (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/lighttpd-1.3.x/src/mod_mysql_vhost.c
r1 r480 29 29 */ 30 30 31 #ifdef HAVE_MYSQL 31 32 typedef struct { 32 #ifdef HAVE_MYSQL33 33 MYSQL *mysql; 34 #endif 34 35 35 buffer *mydb; 36 36 buffer *myuser; 37 37 buffer *mypass; 38 38 buffer *mysock; 39 40 buffer *hostname; 41 unsigned short port; 39 42 40 43 buffer *mysql_pre; … … 88 91 for (i = 0; i < srv->config_context->used; i++) { 89 92 plugin_config *s = p->config_storage[i]; 90 #ifdef HAVE_MYSQL 93 91 94 mysql_close(s->mysql); 92 #endif 95 93 96 buffer_free(s->mydb); 94 97 buffer_free(s->myuser); … … 166 169 167 170 config_values_t cv[] = { 168 { "mysql-vhost.db", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_SERVER }, 171 { "mysql-vhost.db", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_SERVER }, 169 172 { "mysql-vhost.user", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_SERVER }, 170 { "mysql-vhost.pass", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_SERVER }, 171 { "mysql-vhost.sock", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_SERVER }, 172 { "mysql-vhost.sql", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_SERVER }, 173 { "mysql-vhost.pass", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_SERVER }, 174 { "mysql-vhost.sock", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_SERVER }, 175 { "mysql-vhost.sql", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_SERVER }, 176 { "mysql-vhost.hostname", NULL, T_CONFIG_STRING,T_CONFIG_SCOPE_SERVER }, 177 { "mysql-vhost.port", NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_SERVER }, 173 178 { NULL, NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET } 174 179 }; … … 186 191 s->mypass = buffer_init(); 187 192 s->mysock = buffer_init(); 193 s->hostname = buffer_init(); 194 s->port = 0; /* default port for mysql */ 188 195 sel = buffer_init(); 189 #ifdef HAVE_MYSQL190 196 s->mysql = NULL; 191 #endif192 197 193 198 s->mysql_pre = buffer_init(); … … 199 204 cv[3].destination = s->mysock; 200 205 cv[4].destination = sel; 206 cv[5].destination = s->hostname; 207 cv[6].destination = &(s->port); 201 208 202 209 p->config_storage[i] = s; … … 217 224 } 218 225 226 /* required: 227 * - username 228 * - database 229 * 230 * optional: 231 * - password, default: empty 232 * - socket, default: mysql default 233 * - hostname, if set overrides socket 234 * - port, default: 3306 235 */ 236 219 237 /* all have to be set */ 220 238 if (!(buffer_is_empty(s->myuser) || 221 buffer_is_empty(s->mypass) || 222 buffer_is_empty(s->mydb) || 223 buffer_is_empty(s->mysock))) { 224 #ifdef HAVE_MYSQL 239 buffer_is_empty(s->mydb))) { 240 225 241 int fd; 226 242 … … 230 246 return HANDLER_ERROR; 231 247 } 248 #define FOO(x) (s->x->used ? s->x->ptr : NULL) 232 249 233 if (!mysql_real_connect(s->mysql, NULL, s->myuser->ptr, s->mypass->ptr,234 s->mydb->ptr, 0, s->mysock->ptr, 0)) {250 if (!mysql_real_connect(s->mysql, FOO(hostname), FOO(myuser), FOO(mypass), 251 FOO(mydb), s->port, FOO(mysock), 0)) { 235 252 log_error_write(srv, __FILE__, __LINE__, "s", mysql_error(s->mysql)); 236 253 237 254 return HANDLER_ERROR; 238 255 } 239 256 #undef FOO 240 257 /* set close_on_exec for mysql the hard way */ 241 258 /* Note: this only works as it is done during startup, */ … … 245 262 fcntl(fd-1, F_SETFD, FD_CLOEXEC); 246 263 } 247 #endif248 264 } 249 265 } … … 280 296 } 281 297 282 #ifdef HAVE_MYSQL283 298 if (s->mysql) { 284 299 PATCH(mysql); 285 300 } 286 #endif287 301 } 288 302 … … 298 312 PATCH(mysql_pre); 299 313 PATCH(mysql_post); 300 #ifdef HAVE_MYSQL301 314 PATCH(mysql); 302 #endif303 315 304 316 return 0; … … 309 321 /* handle document root request */ 310 322 CONNECTION_FUNC(mod_mysql_vhost_handle_docroot) { 311 #ifdef HAVE_MYSQL312 323 plugin_data *p = p_d; 313 324 plugin_connection_data *c; … … 400 411 con->http_status = 500; /* Internal Error */ 401 412 return HANDLER_FINISHED; 402 #else403 UNUSED(srv);404 UNUSED(con);405 UNUSED(p_d);406 407 return HANDLER_ERROR;408 #endif409 413 } 410 414 … … 423 427 return 0; 424 428 } 425 429 #else 430 /* we don't have mysql support, this plugin does nothing */ 431 int mod_mysql_vhost_plugin_init(plugin *p) { 432 p->version = LIGHTTPD_VERSION_ID; 433 p->name = buffer_init_string("mysql_vhost"); 434 435 return 0; 436 } 437 #endif

