diff -urN thttpd-2.21-5/Makefile.in thttpd-2.21-6/Makefile.in --- thttpd-2.21-5/Makefile.in Thu Nov 22 14:43:09 2001 +++ thttpd-2.21-6/Makefile.in Thu Nov 22 14:43:09 2001 @@ -46,7 +46,7 @@ # You shouldn't need to edit anything below here. -CC = @CC@ +CC = @CC@ -Wall CCOPT = @V_CCOPT@ DEFS = @DEFS@ INCLS = -I. diff -urN thttpd-2.21-5/config.h thttpd-2.21-6/config.h --- thttpd-2.21-5/config.h Thu Nov 22 14:43:09 2001 +++ thttpd-2.21-6/config.h Thu Nov 22 14:43:09 2001 @@ -220,6 +220,13 @@ #define VHOST_MYSQL /* CONFIGURE: +** Interval for reloading the table from the mysql db +*/ + +#define VHOST_RELOAD_TIME 600 + + +/* CONFIGURE: ** Define special logging of requests through unix domain sockets */ diff -urN thttpd-2.21-5/libhttpd.c thttpd-2.21-6/libhttpd.c --- thttpd-2.21-5/libhttpd.c Thu Nov 22 14:43:09 2001 +++ thttpd-2.21-6/libhttpd.c Thu Nov 22 14:43:09 2001 @@ -720,17 +720,31 @@ add_response( hc, buf ); } if ( partial_content ) - { + { +#ifdef VHOST_MYSQL + (void) my_snprintf( buf, sizeof(buf), + "Content-Range: bytes %ld-%ld/%d\r\nContent-Length: %ld\r\n", + (long) hc->init_byte_loc, (long) hc->end_byte_loc, length, + (long) ( hc->end_byte_loc - hc->init_byte_loc + 1 +hc->ban+hc->ban_u) ); +#else (void) my_snprintf( buf, sizeof(buf), "Content-Range: bytes %ld-%ld/%d\r\nContent-Length: %ld\r\n", (long) hc->init_byte_loc, (long) hc->end_byte_loc, length, - (long) ( hc->end_byte_loc - hc->init_byte_loc + 1 +hc->ban+hc->ban_u) ); + (long) ( hc->end_byte_loc - hc->init_byte_loc + 1 ) ); + +#endif add_response( hc, buf ); } else if ( length >= 0 ) - { + { +#ifdef VHOST_MYSQL (void) my_snprintf( buf, sizeof(buf), - "Content-Length: %d\r\n", length +hc->ban+hc->ban_u ); + "Content-Length: %d\r\n", length +hc->ban+hc->ban_u ); +#else + (void) my_snprintf( buf, sizeof(buf), + "Content-Length: %d\r\n", length ); + +#endif add_response( hc, buf ); } if ( extraheads[0] != '\0' ) @@ -1349,7 +1363,7 @@ char* cp2; #endif /* VHOST_DIRLEVELS */ #ifdef VHOST_MYSQL - int tmp,j,j0,day; + int tmp,j,j0; time_t tm0; struct tm *stt0; char *ext; @@ -3868,7 +3882,7 @@ generate packet to be sent to the counter */ memset(log_outp,0,512); - snprintf(log_outp,512,"%s|%s|%s|%s|",hc->hostname,httpd_ntoa( &hc->client_addr ),hc->origfilename,hc->referer); + snprintf(log_outp,512,"%s|%s|/%s|%ld|%s|",hc->hostname,httpd_ntoa( &hc->client_addr ),hc->origfilename,hc->fsize,hc->referer); if ((write(UDSfd, log_outp,strlen(log_outp)) < 0) && (errno != EAGAIN)) { if (connect(UDSfd, (struct sockaddr *) &UDSaddr, sizeof(UDSaddr)) < 0) diff -urN thttpd-2.21-5/mmc.c thttpd-2.21-6/mmc.c --- thttpd-2.21-5/mmc.c Sat Apr 14 00:02:15 2001 +++ thttpd-2.21-6/mmc.c Thu Nov 22 14:43:09 2001 @@ -32,6 +32,7 @@ #include #include #include +#include #ifdef HAVE_MMAP #include diff -urN thttpd-2.21-5/thttpd.c thttpd-2.21-6/thttpd.c --- thttpd-2.21-5/thttpd.c Thu Nov 22 14:43:09 2001 +++ thttpd-2.21-6/thttpd.c Thu Nov 22 14:43:09 2001 @@ -167,6 +167,52 @@ static void logstats( struct timeval* nowP ); static void thttpd_logstats( long secs ); +#ifdef VHOST_MYSQL +static void reload_vhost(ClientData client_data, struct timeval* nowP); +#endif + + + +#ifdef VHOST_MYSQL +void reload_vhost(ClientData client_data, struct timeval* nowP) +{ + /* + we don't fscken care about the function parameters :) + */ + struct node *vh_list0; + struct banner *bn_list0; + int vh_list_len0,bn_list_len0; + + /* + we do it transactionally + e.g. connect do db load everything, and if it's ok - switch to the new + sets and free the old ones. + */ + syslog(LOG_ERR,"Reloading vhost\n"); + vh_list0=vh_init_struct(&vh_list_len0); + if (vh_list0==NULL) return; + bn_list0=init_banners_list(&bn_list_len0); + if (bn_list0==NULL) + { + /* + XXX: This could crash the server, but I prefer not to make + a memory leak here... and vh_init_struct guarantees that if vh_list0!=NULL, + then it was allocated. + */ + free_vh_list(vh_list0,vh_list_len0); + return; + }; + syslog(LOG_ERR,"Vhosts reloaded\n"); + free_vh_list(vh_list,vh_list_len); + vh_list=vh_list0; + vh_list_len=vh_list_len0; + free_bn_list(bn_list,bn_list_len); + bn_list=bn_list0; + bn_list_len=bn_list_len0; + syslog(LOG_ERR,"Switched vhosts/banners\n"); + +} +#endif static void handle_term( int sig ) @@ -181,9 +227,10 @@ static void handle_hup( int sig ) { - FILE* logfp; + #ifndef ADVCOUNTER - if ( no_log ) + FILE* logfp; + if ( no_log ) return; /* Re-open the log file. */ @@ -235,7 +282,7 @@ struct timeval tv; #ifdef ADVCOUNTER - long int flg; + long int flg=0; #endif argv0 = argv[0]; @@ -300,6 +347,8 @@ } else logfp = (FILE*) 0; +#else + logfp = (FILE*) 0; #endif /* Figure out uid/gid from user. */ @@ -423,7 +472,6 @@ if (vh_list==NULL) exit(1); bn_list=init_banners_list(&bn_list_len); if (bn_list==NULL) exit(1); - #endif #ifdef ADVCOUNTER UDSfd = socket(AF_UNIX,SOCK_DGRAM,0); @@ -493,6 +541,14 @@ exit( 1 ); } #endif /* STATS_TIME */ +#ifdef VHOST_MYSQL + /* Set up vhost reload timer */ + if (tmr_create((struct timeval*) 0,reload_vhost,JunkClientData,VHOST_RELOAD_TIME*1000L,1)==NULL) + { + (void) fprintf( stderr, "error creating timer\n"); + exit(1); + }; +#endif start_time = stats_time = time( (time_t*) 0 ); stats_connections = stats_bytes = 0L; stats_simultaneous = 0; @@ -566,7 +622,7 @@ (void) gettimeofday( &tv, (struct timezone*) 0 ); while ( ( ! terminate ) || numconnects > 0 ) { - /* Do the fd watch. */ + /* Do the fd watch. */ num_ready = fdwatch( tmr_mstimeout( &tv ) ); if ( num_ready < 0 ) { @@ -584,7 +640,7 @@ } /* Is it a new connection? */ - if ( hs != (httpd_server*) 0 && hs->listen6_fd != -1 && + if ( hs != (httpd_server*) 0 && hs->listen6_fd != -1 && fdwatch_check_fd( hs->listen6_fd ) ) { if ( handle_newconnect( &tv, hs->listen6_fd ) ) @@ -594,7 +650,7 @@ */ continue; } - if ( hs != (httpd_server*) 0 && hs->listen4_fd != -1 && + if ( hs != (httpd_server*) 0 && hs->listen4_fd != -1 && fdwatch_check_fd( hs->listen4_fd ) ) { if ( handle_newconnect( &tv, hs->listen4_fd ) ) @@ -1043,7 +1099,7 @@ } if ( aiv4 == (struct addrinfo*) 0 ) - *gotv4P = 0; + *gotv4P = 0; else { if ( sa4_len < aiv4->ai_addrlen ) @@ -1058,7 +1114,7 @@ *gotv4P = 1; } if ( aiv6 == (struct addrinfo*) 0 ) - *gotv6P = 0; + *gotv6P = 0; else { if ( sa6_len < aiv6->ai_addrlen ) @@ -1869,9 +1925,11 @@ c->idle_send_timer = (Timer*) 0; if ( c->conn_state != CNST_FREE ) { - syslog( LOG_INFO, +#ifndef VHOST_MYSQL + syslog( LOG_INFO, "%.80s connection timed out sending", - httpd_ntoa( &c->hc->client_addr ) ); + httpd_ntoa( &c->hc->client_addr ) ); +#endif clear_connection( c, nowP ); } } diff -urN thttpd-2.21-5/timers.c thttpd-2.21-6/timers.c --- thttpd-2.21-5/timers.c Fri Apr 13 08:37:49 2001 +++ thttpd-2.21-6/timers.c Thu Nov 22 14:43:09 2001 @@ -188,7 +188,6 @@ /* Add the new timer to the proper active list. */ l_add( t ); ++active_count; - return t; } diff -urN thttpd-2.21-5/vhost.c thttpd-2.21-6/vhost.c --- thttpd-2.21-5/vhost.c Thu Nov 22 14:43:09 2001 +++ thttpd-2.21-6/vhost.c Thu Nov 22 14:43:09 2001 @@ -1,5 +1,4 @@ - #include #include #include @@ -72,6 +71,7 @@ row=mysql_fetch_row(result); } (*n)--; + mysql_free_result(result); mysql_close(conn); return tmp; } @@ -181,11 +181,58 @@ } (*n)--; + mysql_free_result(result); mysql_close(conn); return tmp; } +void free_vh_list(struct node *tmp, int len) +{ + /* + simple feeing of the list (not exactly list :) some kind + of array) + */ + + int i; + + for (i=0;i