#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
//#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#define SIZE 1000
//int maxtextbuffer = sizeof(char)*250;
//#define SIZE sizeof(char)*250
#define SIZE 255

int main() {
	FILE* fp;
	int count = 0; 
	int detected = 0;
	char buf[SIZE];
	if( ( fp = fopen( "/var/log/httpd/access_log", "r" ) ) == NULL ) {
		fprintf( stderr, "Error opening file.\n" );
		exit( 1 );
	}
//70.166.30.6 - - [02/Mar/2009:07:26:34 -0800] "GET /lsquote/0.2.1/lsquote.pl HTTP/1.0" 200 26533
//70.166.30.4 - - [02/Mar/2009:09:14:42 -0800] "GET /lsbench/lsbench-beta0.3.2/lsbench-beta0.3.2.tar.bz2 HTTP/1.1" 200 935365
//64.1.215.162 - - [25/Feb/2009:07:36:55 -0800] "GET /lsbench/lsbench-beta0.3.2/Makefile-threading-cmd-no-gfx HTTP/1.0" 200 808
        while( fgets(buf, sizeof(buf), fp) != NULL)
        {
		count = 0;
		while (buf[count] != 'G'){
				count++;
			}

			if (buf[count+13] == 'l'){
				//printf("l found\n");
				if (buf[count+14] == 's'){
					if (buf[count+15] == 'b'){ 
						if (buf[count+16] == 'e'){ 
							if (buf[count+17] == 'n'){
								//printf("lsben found\n"); 
								if (buf[count+25] == '0'){
								//printf("lsbench-beta0 found\n"); 
									//if (buf[count+26] == '.'){ 
										if (buf[count+27] == '3'){ 
											//printf("lsbench-beta0.3 found\n");
											//if (buf[count+28] == '.'){ 
												if (buf[count+29] == '2'){ 
													//printf("lsbench-beta0.3.2 found\n");
													if (buf[count+49] == 't'){ 
														if (buf[count+50] == 'a'){
															//printf("lsbench-beta0.3.2.t found\n");
															//printf("buf: %s\n", buf);
															detected++;
														}
			//}
				//}
					}
						}
							}
								}
									}
										}
											}
												}
													}
														







	}
	//printf( "NUMBER OF CORES: %d\n", coresdetected );

	fclose( fp );




        if( ( fp = fopen( "/var/log/httpd/access_log.1", "r" ) ) == NULL ) {
                //fprintf( stderr, "Error opening file.\n" );
                //exit( 1 );
        }

        while( fgets(buf, sizeof(buf), fp) != NULL)
        {
                count = 0;
                while (buf[count] != 'G'){
                                count++;
                        }  
                                   
                        if (buf[count+13] == 'l'){
                                //printf("l found\n");
                                if (buf[count+14] == 's'){
                                        if (buf[count+15] == 'b'){
                                                if (buf[count+16] == 'e'){
                                                        if (buf[count+17] == 'n'){
                                                                //printf("lsben found\n");
                                                                if (buf[count+25] == '0'){
                                                                //printf("lsbench-beta0 found\n");
                                                                        //if (buf[count+26] == '.'){
                                                                                if (buf[count+27] == '3'){
                                                                                        //printf("lsbench-beta0.3 found\n");
                                                                                        //if (buf[count+28] == '.'){
                                                                                                if (buf[count+29] == '2'){
                                                                                                        //printf("lsbench-beta0.3.2 found\n");
                                                                                                        if (buf[count+49] == 't'){
                                                                                                                if (buf[count+50] == 'a'){
                                                                                                                        //printf("lsbench-beta0.3$
                                                                                                                        //printf("buf: %s\n", buf$
                                                                                                                        detected++;
                                                                                                                }
                        //}
                                //}
                                        }
                                                }
                                                        }
                                                                }
                                                                        }
                                                                                }
                                                                                        } 
                                                                                                }
                                                                                                        }







        }
        //printf( "NUMBER OF CORES: %d\n", coresdetected );

        fclose( fp );





//<span style="color: rgb(2, 2, 255); font-size: 18;">Project status:</span>
printf( "Content-type: text/html\n\n");
printf( "<html>");
//printf( "</title></head>");
printf( "<body bgcolor=\"#FFFFFF\" text=\"#000000\" link=\"#FF0000\"link=\"#800000\">");
//printf( "<span style=\"color: rgb(2, 2, 255) font-size: 12\">");
printf( "<font size=\"-3\">");
printf("%d", detected);
printf( "</font>");
//printf( "</span>");
printf( "</body></html>");






	//printf("Downloaded: %d\n", detected);
	return 0;
	//return (coresdetected);
}
