OSDN Git Service

removed flag for log option
[opengatem/opengatem.git] / mdsrc / managementdb.c
index 68c1257..80828ed 100644 (file)
@@ -29,7 +29,7 @@ Email: watanaby@is.saga-u.ac.jp
 #include <mysql.h>
 
 static MYSQL mysql;
-static int saveLogToMngDb=0;
+static int isSessionTableFoundInMngDb=TRUE;
 
 /******************************************
 initialize management db
@@ -42,7 +42,6 @@ int initMngDb(void){
   char *password = GetConfValue("MySqlDb/Password");
   char *database = GetConfValue("MySqlDb/Database");
   my_bool reconnect;
-  char *confStr;
 
 /* initialize mysql */
   mysql_library_init(-1,NULL,NULL);
@@ -64,13 +63,9 @@ int initMngDb(void){
   reconnect = TRUE;
   mysql_options(&mysql, MYSQL_OPT_RECONNECT, &reconnect);
 
-  /* read logmode flag from conf file and hold in a variable */
-  confStr = GetConfValue("SaveLogToMngDb");
-  if(isNull(confStr)) saveLogToMngDb = 0;  /* no conf means no-log */
-  else                saveLogToMngDb = strtol(confStr, NULL, 2);
-
-  /* adjust relation of logmode in conf and logtable in mngdb */
-  AdjustLogModeAndLogTable();
+  /* check existence of session table in management db(not work db) */
+  /* if it is FALSE, writing/reading log is skipped */
+  isSessionTableFoundInMngDb = IsTableFoundInMngDb("sessionmd");
   
   return TRUE;
 }
@@ -137,8 +132,8 @@ int putOpenToMngDb(char* macAddress){
   char queryStr[BUFFMAXLN];
   struct utsname uts;
 
-  /* if session log table is not used, return */
-  if(!saveLogToMngDb) return FALSE;
+  /* if session log table is not found, return */
+  if(!isSessionTableFoundInMngDb) return FALSE;
   
   /* get domain name */
   uname(&uts);
@@ -167,8 +162,8 @@ int putCloseToMngDb(char* macAddress){
 
   char queryStr[BUFFMAXLN];
 
-  /* if session log table is not used, return */
-  if(!saveLogToMngDb) return FALSE;
+  /* if session log table is not found, return */
+  if(!isSessionTableFoundInMngDb) return FALSE;
 
   /* prepare query string */
   snprintf(queryStr, BUFFMAXLN, 
@@ -193,8 +188,8 @@ int delOldSessionLogInMngDb(void){
 
   char* queryStr="delete from sessionmd where closeTime>0 and closeTime<adddate(now(),interval -1 month)";
 
-  /* if session log table is not used, return */
-  if(!saveLogToMngDb) return FALSE;
+  /* if session log table is not found, return */
+  if(!isSessionTableFoundInMngDb) return FALSE;
   
   /* send SQL query */
   if (mysql_query(&mysql, queryStr)){
@@ -330,45 +325,6 @@ int isTableFoundInMngDb(char* table){
   return found;
 }
 
-/******************************************
-set closeTime to unclosed sessions in mngdb
-return value: 1=success, 0=error
-******************************************/
-int updateCloseTimeToUnclosedSessionInMngDb(void){
-  
-  char* queryStr="update sessionmd set closeTime=now() where closeTime=0";
-
-  /* send SQL query */
-  if (mysql_query(&mysql, queryStr)){
-     err_msg("ERR at %s#%d: mysql query: %s",__FILE__,__LINE__,
-            mysql_error(&mysql));
-     return FALSE;
-  }
-
-  return TRUE;
-}
-
-/**********************************************************
-adjust the relation of logmode(SaveLogToMngDb) in conf file 
-and logtable(sessionmd) in management db 
-***********************************************************/
-void adjustLogModeAndLogTable(void){
-
-  /* check the existence of table sessionmd in management.db */
-  int isSessionTableFoundInMngDb = IsTableFoundInMngDb("sessionmd");
-
-  /* if logmode=off and session table exists, cleanup all sessions */
-  if(!saveLogToMngDb && isSessionTableFoundInMngDb){
-    UpdateCloseTimeToUnclosedSessionInMngDb();
-  }
-
-  /* if logmode=on and session table does not exist, write error */
-  if(saveLogToMngDb && !isSessionTableFoundInMngDb){
-     err_msg("ERR at %s#%d: please create mysql table. sample script is found in archive",
-            __FILE__,__LINE__);
-  }
-}
-
 
 /********************************************
  routines for debugging 
@@ -444,16 +400,3 @@ int IsTableFoundInMngDb(char* table){
   return ret;
 }
 
-int UpdateCloseTimeToUnclosedSessionInMngDb(void){
-  int ret;
-  if(debug>1) err_msg("DEBUG:=>updateCloseTimeToUnclosedSessionInMngDb()");
-  ret = updateCloseTimeToUnclosedSessionInMngDb();
-  if(debug>1) err_msg("DEBUG:(%d)<=updateCloseTimeToUnclosedSessionInMngDb()", ret);
-  return ret;
-}
-
-void AdjustLogModeAndLogTable(void){
-  if(debug>1) err_msg("DEBUG:=>adjustLogModeAndLogTable()");
-  adjustLogModeAndLogTable();
-  if(debug>1) err_msg("DEBUG:<=adjustLogModeAndLogTable()");
-}