---------------------
PatchSet 6729 
Date: 2008/01/29 09:02:00
Author: arthur-tumanyan
Branch: shaga
Tag: shaga-31-01-2008 
Log:
*** empty log message ***

Members: 
	configure.in:1.172->1.172.2.1 
	src/Makefile.am:1.136->1.136.2.1 
	src/ShagaAccess.h:1.1->1.1.2.1 
	src/ShagaConfig.h:1.1->1.1.2.1 
	src/ShagaProtos.h:1.1->1.1.2.1 
	src/access_log.cc:1.51->1.51.2.1 
	src/cf.data.pre:1.169->1.169.2.1 
	src/cf_gen_defines:1.4->1.4.36.1 
	src/main.cc:1.92->1.92.2.1 
	src/shaga.cc:1.1->1.1.2.1 
	src/shaga.h:1.1->1.1.2.1 
	src/structs.h:1.124->1.124.2.1 

Index: squid3/configure.in
===================================================================
RCS file: /cvsroot/squid-sf//squid3/configure.in,v
retrieving revision 1.172
retrieving revision 1.172.2.1
diff -u -r1.172 -r1.172.2.1
--- squid3/configure.in	18 Jan 2008 10:14:07 -0000	1.172
+++ squid3/configure.in	29 Jan 2008 09:02:00 -0000	1.172.2.1
@@ -1,7 +1,7 @@
 
 dnl  Configuration input file for Squid
 dnl
-dnl  $Id: configure.in,v 1.172 2008/01/18 10:14:07 squidadm Exp $
+dnl  $Id: configure.in,v 1.172.2.1 2008/01/29 09:02:00 arthur-tumanyan Exp $
 dnl
 dnl
 dnl
@@ -11,7 +11,7 @@
 AC_CONFIG_AUX_DIR(cfgaux)
 AC_CONFIG_SRCDIR([src/main.cc])
 AM_INIT_AUTOMAKE([tar-ustar])
-AC_REVISION($Revision: 1.172 $)dnl
+AC_REVISION($Revision: 1.172.2.1 $)dnl
 AC_PREFIX_DEFAULT(/usr/local/squid)
 AM_MAINTAINER_MODE
 
@@ -853,6 +853,19 @@
 fi
 AM_CONDITIONAL(ENABLE_HTCP, [test x$USE_HTCP = xtrue])
 
+dnl  Shaga support is disabled by default
+AM_CONDITIONAL(ENABLE_SHAGA, false)
+AC_ARG_ENABLE(shaga,
+[  --enable-shaga          Enable ShagaEngine support(Mysql logging feature)],
+[ if test "$enableval" != "no"; then
+    echo "ShagaEngine support enabled"
+    AC_DEFINE(USE_SHAGA, 1, [Define this to include code for ShagaEngine.])
+    AM_CONDITIONAL(ENABLE_SHAGA, true)
+	SHAGALIB="-L/usr/local/lib/mysql -lmysqlclient -lz -lcrypt -lm"	
+fi
+])
+AC_SUBST(SHAGALIB)
+
 dnl SSL is not enabled by default.
 AM_CONDITIONAL(ENABLE_SSL, false)
 
Index: squid3/src/Makefile.am
===================================================================
RCS file: /cvsroot/squid-sf//squid3/src/Makefile.am,v
retrieving revision 1.136
retrieving revision 1.136.2.1
diff -u -r1.136 -r1.136.2.1
--- squid3/src/Makefile.am	14 Jan 2008 13:51:53 -0000	1.136
+++ squid3/src/Makefile.am	29 Jan 2008 09:02:01 -0000	1.136.2.1
@@ -1,7 +1,7 @@
 #
 #  Makefile for the Squid Object Cache server
 #
-#  $Id: Makefile.am,v 1.136 2008/01/14 13:51:53 squidadm Exp $
+#  $Id: Makefile.am,v 1.136.2.1 2008/01/29 09:02:01 arthur-tumanyan Exp $
 #
 #  Uncomment and customize the following to suit your needs:
 #
@@ -121,6 +121,12 @@
 UNLINKD = 
 endif
 
+if ENABLE_SHAGA
+SHAGASOURCE = shaga.cc shaga.h ShagaConfig.h ShagaAccess.h ShagaProtos.h
+else
+SHAGASOURCE = 
+endif
+
 if ENABLE_PINGER
 PINGER = pinger
 else
@@ -197,12 +203,13 @@
 
 AM_CFLAGS = @SQUID_CFLAGS@
 AM_CXXFLAGS = @SQUID_CXXFLAGS@
-
+MYSQL_INC_DIR = /usr/local/include/mysql
+MYSQL_LIB_DIR = /usr/local/lib/mysql
 EXTRA_LIBRARIES = libAIO.a libBlocking.a libDiskDaemon.a libDiskThreads.a ICAP/libicap.a
 noinst_LIBRARIES = @DISK_LIBS@ @ICAP_LIBS@
 noinst_LTLIBRARIES = libsquid.la libauth.la
 
-INCLUDES        = -I. -I$(srcdir) -I$(top_builddir)/include -I$(top_srcdir)/include -I$(top_srcdir)/lib/libTrie/include
+INCLUDES        = -I. -I$(srcdir) -I$(top_builddir)/include -I$(top_srcdir)/include -I$(top_srcdir)/lib/libTrie/include -I$(MYSQL_INC_DIR) -I$(MYSQL_LIB_DIR)
 INCLUDES	+= @SQUID_CPPUNIT_INC@
 
 EXTRA_PROGRAMS = \
@@ -452,6 +459,7 @@
 	CompletionDispatcher.cc \
 	CompletionDispatcher.h \
 	$(squid_COMMSOURCES) \
+	$(SHAGASOURCE) \
 	CommRead.h \
 	ConfigOption.cc \
 	ConfigParser.cc \
@@ -673,6 +681,7 @@
 	-lmiscutil \
 	@XTRA_LIBS@ \
 	@EPOLL_LIBS@ \
+	@SHAGALIB@ \
 	@MINGW_LIBS@ 
 squid_DEPENDENCIES = $(top_builddir)/lib/libmiscutil.a \
 	@STORE_OBJS@ \
@@ -894,6 +903,7 @@
 	tools.cc \
 	typedefs.h \
 	$(UNLINKDSOURCE) \
+	$(SHAGASOURCE) \
 	URLScheme.cc \
 	urn.cc \
 	useragent.cc \
@@ -917,6 +927,7 @@
 	@SSLLIB@ \
 	-lmiscutil \
 	@XTRA_LIBS@ \
+	@SHAGALIB@ \
 	@EPOLL_LIBS@ \
 	@MINGW_LIBS@ 
 ufsdump_DEPENDENCIES = $(top_builddir)/lib/libmiscutil.a \
@@ -1339,6 +1350,7 @@
 	$(DELAY_POOL_SOURCE) \
 	disk.cc \
 	$(DNSSOURCE) \
+	$(SHAGASOURCE) \
 	event.cc \
 	errorpage.cc \
 	$(ESI_SOURCE) \
@@ -1521,6 +1533,7 @@
 	gopher.cc \
 	helper.cc \
 	$(HTCPSOURCE) \
+	$(SHAGASOURCE) \
 	http.cc \
 	HttpBody.cc \
 	HttpHeader.cc \
@@ -1675,6 +1688,7 @@
 	gopher.cc \
 	helper.cc \
 	$(HTCPSOURCE) \
+	$(SHAGASOURCE) \
 	http.cc \
 	HttpBody.cc \
 	HttpHeader.cc \
@@ -1840,6 +1854,7 @@
 	$(DELAY_POOL_SOURCE) \
 	disk.cc \
 	$(DNSSOURCE) \
+	$(SHAGASOURCE) \
 	event.cc \
 	errorpage.cc \
 	$(ESI_SOURCE) \
@@ -2000,6 +2015,7 @@
 	$(DELAY_POOL_SOURCE) \
 	disk.cc \
 	$(DNSSOURCE) \
+	$(SHAGASOURCE) \
 	event.cc \
 	errorpage.cc \
 	$(ESI_SOURCE) \
@@ -2412,6 +2428,7 @@
 	Server.cc \
 	$(SNMP_SOURCE) \
 	$(SSL_SOURCE) \
+	$(SHAGASOURCE) \
 	stat.cc \
 	StatHist.cc \
 	stmem.cc \
--- /dev/null	Wed Feb  6 01:24:25 2008
+++ squid3/src/ShagaAccess.h	Wed Feb  6 01:24:25 2008
@@ -0,0 +1,41 @@
+/*
+ * AUTHOR: Arthur Tumanyan 
+ *
+ * SQUID Web Proxy Cache          http://www.squid-cache.org/
+ * ----------------------------------------------------------
+ *
+ *  Squid is the result of efforts by numerous individuals from
+ *  the Internet community; see the CONTRIBUTORS file for full
+ *  details.   Many organizations have provided support for Squid's
+ *  development; see the SPONSORS file for full details.  Squid is
+ *  Copyrighted (C) 2001 by the Regents of the University of
+ *  California; see the COPYRIGHT file for full details.  Squid
+ *  incorporates software developed and/or copyrighted by other
+ *  sources; see the CREDITS file for full details.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
+ *
+ */
+#ifndef SHAGA_ACCESS_H
+#define SHAGA_ACCESS_H
+int writeToDB(char * __time,char * username,char * ip_address,char * byte);
+struct {
+	char access_timestamp[13];
+	char access_user[8];
+	char access_ip[15];
+	char access_byte[15];
+}ShagaAccess;
+
+#endif
--- /dev/null	Wed Feb  6 01:24:25 2008
+++ squid3/src/ShagaConfig.h	Wed Feb  6 01:24:25 2008
@@ -0,0 +1,44 @@
+/*
+ * AUTHOR: Arthur Tumanyan 
+ *
+ * SQUID Web Proxy Cache          http://www.squid-cache.org/
+ * ----------------------------------------------------------
+ *
+ *  Squid is the result of efforts by numerous individuals from
+ *  the Internet community; see the CONTRIBUTORS file for full
+ *  details.   Many organizations have provided support for Squid's
+ *  development; see the SPONSORS file for full details.  Squid is
+ *  Copyrighted (C) 2001 by the Regents of the University of
+ *  California; see the COPYRIGHT file for full details.  Squid
+ *  incorporates software developed and/or copyrighted by other
+ *  sources; see the CREDITS file for full details.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
+ *
+ */
+#ifndef SHAGA_CONFIG_H
+#define SHAGA_CONFIG_H
+
+struct {
+	int enable_shaga;
+	int enable_db_config;
+	char 		*db_host;
+	u_short		db_port;
+	char		*db_name;
+	char		*db_user;
+	char		*db_pwd;
+}Shaga;
+
+#endif
--- /dev/null	Wed Feb  6 01:24:25 2008
+++ squid3/src/ShagaProtos.h	Wed Feb  6 01:24:25 2008
@@ -0,0 +1,38 @@
+/*
+ * AUTHOR: Arthur Tumanyan 
+ *
+ * SQUID Web Proxy Cache          http://www.squid-cache.org/
+ * ----------------------------------------------------------
+ *
+ *  Squid is the result of efforts by numerous individuals from
+ *  the Internet community; see the CONTRIBUTORS file for full
+ *  details.   Many organizations have provided support for Squid's
+ *  development; see the SPONSORS file for full details.  Squid is
+ *  Copyrighted (C) 2001 by the Regents of the University of
+ *  California; see the COPYRIGHT file for full details.  Squid
+ *  incorporates software developed and/or copyrighted by other
+ *  sources; see the CREDITS file for full details.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
+ *
+ */
+#ifndef SHAGA_PROTOS_H
+#define SHAGA_PROTOS_H
+int db_connect(char *dbhost,char *dbuser,char *dbpwd,char *dbname,unsigned int dbport);
+void init_shaga_support();
+void shutdown_shaga_support();
+int getExcludeHosts();
+int isExHost(char *host);
+#endif
Index: squid3/src/access_log.cc
===================================================================
RCS file: /cvsroot/squid-sf//squid3/src/access_log.cc,v
retrieving revision 1.51
retrieving revision 1.51.2.1
diff -u -r1.51 -r1.51.2.1
--- squid3/src/access_log.cc	20 Jan 2008 09:50:56 -0000	1.51
+++ squid3/src/access_log.cc	29 Jan 2008 09:02:02 -0000	1.51.2.1
@@ -1,6 +1,6 @@
 
 /*
- * $Id: access_log.cc,v 1.51 2008/01/20 09:50:56 squidadm Exp $
+ * $Id: access_log.cc,v 1.51.2.1 2008/01/29 09:02:02 arthur-tumanyan Exp $
  *
  * DEBUG: section 46    Access Log
  * AUTHOR: Duane Wessels
@@ -47,7 +47,9 @@
 #include "MemBuf.h"
 #include "SquidTime.h"
 #include "CacheManager.h"
-
+#ifdef USE_SHAGA
+#include "ShagaAccess.h"
+#endif
 static void accessLogSquid(AccessLogEntry * al, Logfile * logfile);
 static void accessLogCommon(AccessLogEntry * al, Logfile * logfile);
 static void accessLogCustom(AccessLogEntry * al, customlog * log);
@@ -1339,6 +1341,23 @@
         safe_free(ereq);
         safe_free(erep);
     }
+#if USE_SHAGA
+if(Config.Shaga.enable_shaga){
+//
+snprintf(ShagaAccess.access_timestamp,13,"%9ld.%03d",
+		 (long int)current_time.tv_sec,( (int)current_time.tv_usec / 1000));
+sscanf((user ? user : dash_str),"%s",ShagaAccess.access_user);
+sscanf(client,"%s",ShagaAccess.access_ip);
+snprintf(ShagaAccess.access_byte,15,"%ld",(long int)al->cache.size);
+//
+	writeToDB(ShagaAccess.access_timestamp,
+			ShagaAccess.access_user,
+			ShagaAccess.access_ip,
+			ShagaAccess.access_byte); /* write to db TIMESTAMP ,USER ,IP ,BYTE */
+}
+#endif
+
+
     logfilePrintf(logfile, "\n");
     safe_free(user);
 }
Index: squid3/src/cf.data.pre
===================================================================
RCS file: /cvsroot/squid-sf//squid3/src/cf.data.pre,v
retrieving revision 1.169
retrieving revision 1.169.2.1
diff -u -r1.169 -r1.169.2.1
--- squid3/src/cf.data.pre	20 Jan 2008 11:51:46 -0000	1.169
+++ squid3/src/cf.data.pre	29 Jan 2008 09:02:03 -0000	1.169.2.1
@@ -1,6 +1,6 @@
 
 #
-# $Id: cf.data.pre,v 1.169 2008/01/20 11:51:46 squidadm Exp $
+# $Id: cf.data.pre,v 1.169.2.1 2008/01/29 09:02:03 arthur-tumanyan Exp $
 #
 # SQUID Web Proxy Cache		http://www.squid-cache.org/
 # ----------------------------------------------------------
@@ -5521,4 +5521,59 @@
 	rounded to 1000.
 DOC_END
 
+NAME: enable_shaga_engine
+COMMENT: on|off
+IFDEF: USE_SHAGA
+TYPE: onoff
+LOC: Config.Shaga.enable_shaga
+DEFAULT: on
+DOC_START
+	When this set to on,squid will write some entries from access.log file into database
+DOC_END
+
+NAME: shaga_db_host
+COMMENT: mysql server ip address
+IFDEF: USE_SHAGA
+TYPE: string
+LOC: Config.Shaga.db_host
+DEFAULT: 10.0.0.1
+DOC_START
+DOC_END
+
+NAME: shaga_db_port
+COMMENT: listening port of mysql server
+IFDEF: USE_SHAGA
+TYPE: ushort
+LOC: Config.Shaga.db_port
+DEFAULT: 3306
+DOC_START
+DOC_END
+
+NAME: shaga_db_name
+COMMENT: shaga database name
+IFDEF: USE_SHAGA
+TYPE: string
+LOC: Config.Shaga.db_name
+DEFAULT: shaga
+DOC_START
+DOC_END
+
+NAME: shaga_db_user
+COMMENT: shaga database user
+IFDEF: USE_SHAGA
+TYPE: string
+LOC: Config.Shaga.db_user
+DEFAULT: shaga
+DOC_START
+DOC_END
+
+NAME: shaga_db_pwd
+COMMENT: shaga database password
+IFDEF: USE_SHAGA
+TYPE: string
+LOC: Config.Shaga.db_pwd
+DEFAULT: shaga
+DOC_START
+DOC_END
+
 EOF
Index: squid3/src/cf_gen_defines
===================================================================
RCS file: /cvsroot/squid-sf//squid3/src/cf_gen_defines,v
retrieving revision 1.4
retrieving revision 1.4.36.1
diff -u -r1.4 -r1.4.36.1
--- squid3/src/cf_gen_defines	2 Jul 2006 17:50:45 -0000	1.4
+++ squid3/src/cf_gen_defines	29 Jan 2008 09:02:04 -0000	1.4.36.1
@@ -20,6 +20,7 @@
 	define["USE_WCCP"]="--enable-wccp"
 	define["USE_WCCPv2"]="--enable-wccpv2"
 	define["ESI"]="--enable-esi"
+	define["USE_SHAGA"]="--enable-shaga"
 }
 /^IFDEF:/ {
 	if (define[$2] != "")
Index: squid3/src/main.cc
===================================================================
RCS file: /cvsroot/squid-sf//squid3/src/main.cc,v
retrieving revision 1.92
retrieving revision 1.92.2.1
diff -u -r1.92 -r1.92.2.1
--- squid3/src/main.cc	29 Dec 2007 18:50:34 -0000	1.92
+++ squid3/src/main.cc	29 Jan 2008 09:02:04 -0000	1.92.2.1
@@ -1,6 +1,6 @@
 
 /*
- * $Id: main.cc,v 1.92 2007/12/29 18:50:34 squidadm Exp $
+ * $Id: main.cc,v 1.92.2.1 2008/01/29 09:02:04 arthur-tumanyan Exp $
  *
  * DEBUG: section 1     Startup and Main Loop
  * AUTHOR: Harvest Derived
@@ -73,6 +73,9 @@
 #include "forward.h"
 #include "MemPool.h"
 #include "ICMPSquid.h"
+#ifdef USE_SHAGA
+#include "ShagaProtos.h"
+#endif
 
 #if USE_WIN32_SERVICE
 
@@ -667,6 +670,14 @@
     wccp2Init();
 #endif
 
+#ifdef USE_SHAGA
+if(Config.Shaga.enable_shaga){
+	
+	shutdown_shaga_support();
+	init_shaga_support();
+
+}else _db_print("ShagaEngine is disabled\n");
+#endif
     serverConnectionsOpen();
 
     neighbors_init();
@@ -986,6 +997,14 @@
 
 #endif
 
+#ifdef USE_SHAGA
+if(Config.Shaga.enable_shaga){
+
+	init_shaga_support();
+
+}else _db_print("ShagaEngine is disabled\n");
+#endif
+
     serverConnectionsOpen();
 
     neighbors_init();
@@ -1626,6 +1645,12 @@
     wccp2ConnectionClose();
 #endif
 
+#ifdef USE_SHAGA
+if(Config.Shaga.enable_shaga){
+	shutdown_shaga_support();
+}
+#endif
+
     releaseServerSockets();
     commCloseAllSockets();
 #if DELAY_POOLS
--- /dev/null	Wed Feb  6 01:24:25 2008
+++ squid3/src/shaga.cc	Wed Feb  6 01:24:25 2008
@@ -0,0 +1,182 @@
+/*
+ * AUTHOR: Arthur Tumanyan 
+ *
+ * SQUID Web Proxy Cache          http://www.squid-cache.org/
+ * ----------------------------------------------------------
+ *
+ *  Squid is the result of efforts by numerous individuals from
+ *  the Internet community; see the CONTRIBUTORS file for full
+ *  details.   Many organizations have provided support for Squid's
+ *  development; see the SPONSORS file for full details.  Squid is
+ *  Copyrighted (C) 2001 by the Regents of the University of
+ *  California; see the COPYRIGHT file for full details.  Squid
+ *  incorporates software developed and/or copyrighted by other
+ *  sources; see the CREDITS file for full details.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
+ *
+ */
+
+#include "squid.h"
+#include "shaga.h"
+//
+int db_connect(char *dbhost,char *dbuser,char *dbpwd,char *dbname,unsigned int dbport){ 
+
+    mysql_init(&mysql);
+    connection = mysql_real_connect(&mysql,dbhost,dbuser,dbpwd,dbname,dbport,NULL,0);
+    /* check for connection error */
+    if(connection == NULL) {
+        /* log the error message */
+     snprintf(MYSQL_ERR,LINE_MAXLEN,"%s\n",(char *)mysql_error(&mysql)); 
+	_db_print(MYSQL_ERR);
+       /* log this */ 
+
+        return 1;
+    }
+
+  return 0; 
+}
+void init_shaga_support(){
+
+if ( db_connect(Config.Shaga.db_host,
+		Config.Shaga.db_user,
+		Config.Shaga.db_pwd,
+		Config.Shaga.db_name,
+		Config.Shaga.db_port) != 0)
+ {
+        snprintf(MYSQL_ERR,LINE_MAXLEN,"Cannot connect to database %s on %s\n", 
+                                            Config.Shaga.db_name,Config.Shaga.db_host);
+	/* log this*/if(!already_logged){	
+	_db_print(MYSQL_ERR);
+	already_logged = 1;
+ }
+	_db_print("ShagaEngine can not start\n");
+	_db_print("Fix all errors\n");
+	shaga_force = 1;
+}else {
+	exclude = (0 == getExcludeHosts()) ? 1 : 0;
+	_db_print("ShagaEngine is started\n");
+	snprintf(TMP_MSG,LINE_MAXLEN,"Exclude hosts detected %d\n",hc);
+	_db_print(TMP_MSG);
+
+}
+}
+
+//
+int writeToDB(char * __time,char * username,char * ip_address,char * byte){
+	
+  long int my_stamp = atol(__time);	
+  time_t my_stamp2 = (time_t)my_stamp;
+
+	thistime = localtime(&my_stamp2);
+	strftime(timestr,25,"%F %T",thistime);
+	int retval;
+	
+	snprintf(TMP_QUERY,LINE_MAXLEN,
+		 "INSERT DELAYED INTO %s(`date`,`user`,`ip_addr`,`bytes`) VALUES(\'%s\',\'%s\',\'%s\',\'%s\')",
+		TMP_TABLE,(char *) timestr,username,(char *)ip_address,(char *)byte);
+if(shaga_force == 0){
+if(exclude == 1 && ( 0 == isExHost(ip_address) ) ){	
+	state = mysql_real_query(&mysql,TMP_QUERY,strlen(TMP_QUERY));
+	
+} /* IP address is from exclude hosts pool */
+	} /* connection failed */
+
+	//
+	if(state) {
+		snprintf(MYSQL_ERR,LINE_MAXLEN,"%s\n",(char *)mysql_error(&mysql));
+	 /* log this */	
+if(!already_logged){	
+	_db_print(MYSQL_ERR);
+	already_logged = 1;
+ }
+		return 1; 
+	}
+	int affected = (int)mysql_affected_rows(&mysql);
+	if(affected > 0){
+		retval = 0;
+	}else{ 
+		snprintf(MYSQL_ERR,LINE_MAXLEN,"%s\n",(char *)mysql_error(&mysql));
+	/* log this */	
+	if(!already_logged) {
+		 _db_print(MYSQL_ERR); 
+		already_logged = 1;
+	}
+		retval = 1;
+	}
+
+	return retval;
+}
+//
+
+void shutdown_shaga_support(){
+	if (shaga_force == 0)_db_print("ShagaEngine is shutting down\n");
+	if(connection != NULL) mysql_close(&mysql);
+}
+
+int getExcludeHosts(){
+        //
+        snprintf(TMP_QUERY,LINE_MAXLEN,"%s",
+                 "SELECT `hosts` FROM `ecl_hosts`");
+        state = mysql_real_query(&mysql,TMP_QUERY,strlen(TMP_QUERY));
+        //
+        if(state)
+        {
+            snprintf(MYSQL_ERR,LINE_MAXLEN,"%s\n",(char *)mysql_error(&mysql));
+	_db_print(MYSQL_ERR);
+        /* log about failure */    
+	return 1;
+        }
+        result = mysql_store_result(&mysql);
+        if (result)  // there are rows
+        { 
+	int c = 0;
+            while((row = mysql_fetch_row(result)))
+            {
+                sscanf(row[0],"%s",excludeHosts[c].host);
+		
+		c++;
+}
+            mysql_free_result(result);
+	hc = c;
+            //
+        }else
+        {
+
+ snprintf(MYSQL_ERR,LINE_MAXLEN,"Error getting records: %s\n",(char *) mysql_error(&mysql));
+	_db_print(MYSQL_ERR);
+       /* log about failure */ 
+        }
+	return 0;
+}
+
+int isExHost(char *host){
+
+int i,ret = 0;
+
+if(strlen(host) < 7) return 0;
+    for(i = 0;i < hc;i++)
+    { 
+	if(strncmp(host,excludeHosts[i].host,15) == 0)
+        {
+                ret = 1;
+            break;
+        }//strcmp
+    }//for
+    return ret;
+}
+//
+//
+
--- /dev/null	Wed Feb  6 01:24:25 2008
+++ squid3/src/shaga.h	Wed Feb  6 01:24:25 2008
@@ -0,0 +1,65 @@
+/*
+ * AUTHOR: Arthur Tumanyan 
+ *
+ * SQUID Web Proxy Cache          http://www.squid-cache.org/
+ * ----------------------------------------------------------
+ *
+ *  Squid is the result of efforts by numerous individuals from
+ *  the Internet community; see the CONTRIBUTORS file for full
+ *  details.   Many organizations have provided support for Squid's
+ *  development; see the SPONSORS file for full details.  Squid is
+ *  Copyrighted (C) 2001 by the Regents of the University of
+ *  California; see the COPYRIGHT file for full details.  Squid
+ *  incorporates software developed and/or copyrighted by other
+ *  sources; see the CREDITS file for full details.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
+ *
+ */
+
+#include <mysql.h>
+
+#ifndef SHAGA_LIB_H
+#define SHAGA_LIB_H
+
+#define LINE_MAXLEN 512
+#define TMP_TABLE "tmp_traff"
+#define MAX_USER_COUNT 9999
+//
+#include "ShagaProtos.h"
+
+int state;
+int hc = 0;
+char TMP_QUERY[LINE_MAXLEN];
+char MYSQL_ERR[LINE_MAXLEN];
+char TMP_MSG[LINE_MAXLEN];
+int exclude;
+int u_count; /* users count */
+char timestr[25];
+struct tm *thistime;
+
+struct {
+	char host[16];
+}excludeHosts[MAX_USER_COUNT];
+//
+int shaga_force = 0;
+int already_logged = 0;
+//
+MYSQL_RES *result;
+MYSQL_ROW row;
+MYSQL *connection, mysql;
+//
+//
+#endif
Index: squid3/src/structs.h
===================================================================
RCS file: /cvsroot/squid-sf//squid3/src/structs.h,v
retrieving revision 1.124
retrieving revision 1.124.2.1
diff -u -r1.124 -r1.124.2.1
--- squid3/src/structs.h	19 Jan 2008 07:50:42 -0000	1.124
+++ squid3/src/structs.h	29 Jan 2008 09:02:04 -0000	1.124.2.1
@@ -1,6 +1,6 @@
 
 /*
- * $Id: structs.h,v 1.124 2008/01/19 07:50:42 squidadm Exp $
+ * $Id: structs.h,v 1.124.2.1 2008/01/29 09:02:04 arthur-tumanyan Exp $
  *
  *
  * SQUID Web Proxy Cache          http://www.squid-cache.org/
@@ -192,6 +192,10 @@
 struct _SquidConfig
 {
 
+
+#ifdef USE_SHAGA
+#include "ShagaConfig.h"
+#endif
     struct
     {
         /* These should be for the Store::Root instance.
