diff -ruN ./0.3/Makefile ./0.4/Makefile --- ./0.3/Makefile Fri May 10 17:41:33 2002 +++ ./0.4/Makefile Fri May 10 19:19:38 2002 @@ -1,4 +1,4 @@ -OPT=-O3 -g #-DDMALLOC +OPT=-O3 -g -Wall #-DDMALLOC #LDOPT=-ldmalloc -DDMALLOC NAME=jikos_cheetah diff -ruN ./0.3/connection.c ./0.4/connection.c --- ./0.3/connection.c Fri May 10 17:34:21 2002 +++ ./0.4/connection.c Fri May 10 19:15:17 2002 @@ -21,13 +21,11 @@ return 0; } -char *decode_hexa_octets(char *s1) +void decode_hexa_octets(char *s1, char *s2) { int i,a,q; - char hexa[3],*s2; + char hexa[3]; - fprintf(stderr,"S1: %s\n",s1); - s2=(char *)malloc(sizeof(char)*strlen(s1)); a=0;i=0; while(i<=strlen(s1)){ if(s1[i]!='%'){ @@ -43,7 +41,6 @@ i += 3; } } - return(s2); } @@ -149,7 +146,6 @@ i++; } ret[i] = '\0'; - fprintf(stderr,"hashed: %s\n",ret); return (char *)(strdup(ret)); } @@ -159,23 +155,21 @@ int i = 0; int li = 0; int x,q,len, got_valid_cookie, no_more_cookies; - int S_num, N_num; + int S_num=0, N_num=0; char line[1024]; char c_server_id[MAX_SERVER_ID_LENGTH], tmp_S[MAX_STRING_ARG_LENGTH]; char tmp_N[9]; - char **endptr; - char *decoded; + char decoded[1024]; char *c, *line_ptr, *tmp_ptr; - long tmp_server_id,N; + long tmp_server_id,N=0; ASSERT (connection != NULL); ASSERT (connection->request_text != NULL); -/* decoded = decode_hexa_octets(connection->request_text); + decode_hexa_octets(connection->request_text, decoded); strcpy(connection->request_text, decoded); connection->request_text_size = strlen(decoded); - free(decoded); -*/ + got_valid_cookie = 0; connection->do_set_cookie = 0; @@ -250,9 +244,6 @@ connection->S_num = S_num; connection->N = (int) N; connection->N_num = N_num; - fprintf(stderr,"ID: %d S%d: %s, N%d: %d\n", connection->server_id, - connection->S_num,connection->S, - connection->N_num,connection->N); } else if (strncmp (&connection->request_text[i], "Cookie: ", 8) == 0) { /* Take from "Cookie: " to the end */ @@ -296,36 +287,35 @@ tmp_N[q] = '\0'; N = strtol(tmp_N, NULL, 10); if(*line_ptr == 'V' && N == connection->server_id){ - if (tmp_ptr = strchr(line_ptr,'=')){ + if ( (tmp_ptr = strchr(line_ptr,'=')) ){ tmp_ptr++; while (isspace(*tmp_ptr)) tmp_ptr++; if(!strcmp(tmp_ptr,"YES")){ - fprintf(stderr,"V cookie for %d found\n",N); items[N]->first_visit_flag = 1; } } } else if (N != connection->server_id){ - fprintf(stderr,"%d != %d\n", N, connection->server_id); BAIL_OUT; } if (*line_ptr == 'S' && N == connection->server_id) { - if (tmp_ptr = strchr(line_ptr,'=')){ + if ( (tmp_ptr = strchr(line_ptr,'=')) ){ tmp_ptr++; while(isspace(*tmp_ptr)) tmp_ptr++; /* now there is string identifier in tmp_ptr */ if (!strcmp(tmp_ptr, items[N]->identifier)){ if (!strcmp(items[N]->ip_addr, - connection->ip_addr)) - if (time(NULL) - items[N]->last_request < + connection->ip_addr)){ + if (time(NULL) - items[N]->last_request < SESSION_TIMEOUT){ - items[N]->last_request = time(NULL); - if (items[N]->request_count++ < 0) - items[N]->request_count--; - } else { - fprintf(stderr,"session timed out\n"); - BAIL_OUT; + items[N]->last_request = time(NULL); + if (items[N]->request_count++ < 0) + items[N]->request_count--; + } else { + fprintf(stderr,"session timed out\n"); + BAIL_OUT; + } } } else { fprintf(stderr,"wrong cookie identifier. Got %s expected %s\n", tmp_ptr, items[N]->identifier); @@ -333,7 +323,6 @@ } } } - fprintf(stderr, "D: %s\n",connection->reply_filename); /* else if (N != connection->server_id) BAIL_OUT;*/ } /* is valid cookie */ @@ -355,9 +344,8 @@ if (!got_valid_cookie) { N = connection->server_id; if (items[N]->id == 0){ - int w; - fprintf(stderr,"NO VALID COOKIE, CREATING SERVER_ID: %d\n",N); + fprintf(stderr,"NO VALID COOKIE, CREATING SERVER_ID: %ld\n",N); connection->do_set_cookie = 1; connection->set_cookie = get_identifier(connection->server_id,time(NULL)); items[N]->id = connection->server_id; diff -ruN ./0.3/connection.h ./0.4/connection.h --- ./0.3/connection.h Fri May 10 17:10:19 2002 +++ ./0.4/connection.h Fri May 10 18:19:03 2002 @@ -9,6 +9,7 @@ #include #include #include +#include #include "macros.h" #include "configuration.h" @@ -16,7 +17,7 @@ #include "rmd160.h" #define MAX_REQUEST_PROCESSING_TIME 30 -/*#define MAX_SERVER_ID 16386*/ +#define MAX_SERVER_ID 16386 #define MAX_SERVER_ID 16 #define MAX_SERVER_ID_LENGTH 5 #define MAX_STRING_ARG_LENGTH 256 diff -ruN ./0.3/errors.c ./0.4/errors.c --- ./0.3/errors.c Fri May 10 03:26:35 2002 +++ ./0.4/errors.c Fri May 10 18:23:13 2002 @@ -20,7 +20,6 @@ char * error_make_page_dup (int err) { int _404_len = -1; - char * error_string; char * new_string; size_t new_size; diff -ruN ./0.3/errors.h ./0.4/errors.h --- ./0.3/errors.h Fri May 10 03:26:38 2002 +++ ./0.4/errors.h Fri May 10 18:23:04 2002 @@ -2,6 +2,7 @@ #define __ERRORS_H__ #include +#include #define RESPONSE_STRING "HTTP/1.0 %03i %s\r\n" diff -ruN ./0.3/jikos_cheetah.c ./0.4/jikos_cheetah.c --- ./0.3/jikos_cheetah.c Fri May 10 17:31:59 2002 +++ ./0.4/jikos_cheetah.c Fri May 10 19:11:29 2002 @@ -5,6 +5,9 @@ struct timeval tv; +extern sig_atomic_t terminate; +/*extern void free_item_struct();*/ + int socket_ready_to_read (int socket) { @@ -21,13 +24,6 @@ return FD_ISSET (socket, &readfds); } -void sig(int num){ -#ifdef DMALLOC - dmalloc_shutdown(); -#endif - exit(1); -} - jikos_cheetah_ptr jikos_cheetah_new (void) { jikos_cheetah_ptr new_jikos_cheetah; @@ -39,8 +35,6 @@ 0, FD_SETSIZE * sizeof(void *)); signal(SIGPIPE, SIG_IGN); - signal(SIGSEGV, sig); - signal(SIGINT, sig); new_jikos_cheetah->server_socket = server_new(); return new_jikos_cheetah; } @@ -54,16 +48,18 @@ time_t curr_time; struct sockaddr_in cli_addr; int clilen; + int ret; connection_ptr this_connection; - if (socket_ready_to_read (jikos_cheetah->server_socket)) { + if ((ret = socket_ready_to_read (jikos_cheetah->server_socket)) > 0) { clilen = sizeof(cli_addr); if ((new_socket = accept (jikos_cheetah->server_socket, (struct sockaddr *)&cli_addr, - &clilen)) < 0) + &clilen)) < 0){ perror ("accept"); - + return; + } /* fprintf(stderr,"1: %s\n",inet_ntoa(cli_addr.sin_addr));*/ fcntl (new_socket, F_SETFL, O_NONBLOCK|O_ASYNC); @@ -79,6 +75,7 @@ (char *)inet_ntoa(cli_addr.sin_addr); max_fd=MAX(max_fd,new_socket); } + else if (ret == -1) return; for (i=3; i<=max_fd; i++) { diff -ruN ./0.3/jikos_cheetah.h ./0.4/jikos_cheetah.h --- ./0.3/jikos_cheetah.h Fri May 10 03:35:30 2002 +++ ./0.4/jikos_cheetah.h Fri May 10 18:54:44 2002 @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include diff -ruN ./0.3/main.c ./0.4/main.c --- ./0.3/main.c Fri May 10 17:35:18 2002 +++ ./0.4/main.c Fri May 10 19:04:23 2002 @@ -2,6 +2,20 @@ #include "jikos_cheetah.h" item_struct *items[MAX_SERVER_ID+1]; +sig_atomic_t terminate = 0; + +void free_item_struct() +{ + int i; + + for (i = 0; iidentifier) free(items[i]->identifier); + if(items[i]->ip_addr) free(items[i]->ip_addr); + + free(items[i]); + } + +} void init_item_struct() { @@ -19,17 +33,37 @@ } } +void sig(int dummy){ + fprintf(stderr,"Exit signalled\n"); + terminate = 1; +} + int main (int argc, char **argv) { jikos_cheetah_ptr web_server; + struct sigaction *s1, *s2; + web_server = jikos_cheetah_new (); init_item_struct(); - for ( ; ; ) jikos_cheetah_step (web_server); + s1 = (struct sigaction *)malloc(sizeof(struct sigaction)); + s2 = (struct sigaction *)malloc(sizeof(struct sigaction)); + s1->sa_handler = sig; sigaction(SIGTERM, s1, s2); + s1->sa_handler = sig; sigaction(SIGINT, s1, s2); + free(s1); free(s2); + while (!terminate) jikos_cheetah_step (web_server); + + fprintf(stderr,"Shutting down\n"); jikos_cheetah_free (web_server); + free_item_struct(); +#ifdef DMALLOC + fprintf(stderr,"Flushing DMALLOC stats\n"); + dmalloc_shutdown(); +#endif + return 0; } diff -ruN ./0.3/run.sh ./0.4/run.sh --- ./0.3/run.sh Fri May 10 17:41:48 2002 +++ ./0.4/run.sh Fri May 10 18:10:06 2002 @@ -1,7 +1,9 @@ #!/bin/bash +export DMALLOC_OPTIONS="log-stats,log-non-free,log-unknown,log-bad-space,check-fence,check-heap,check-lists,check-blank,catch-signals,log-trans,free-blank,error-abort,alloc-blank,heap-check-map,catch-null,error-dump,log=.dmalloc.log" echo DMAL: $DMALLOC_OPTIONS export EF_PROTECT_FREE=1 ulimit -c unlimited ./jikos_cheetah +