OSDN Git Service

added splash mode
[opengatem/opengatem.git] / mngsrc / managementdb.c
index 3ac08ae..103787a 100644 (file)
@@ -324,7 +324,7 @@ int putMacModifyLogToMngDb(char* userId, char* extraId, char* macAddr, char modi
 /******************************************
  The count of mac address modification in last 24 hours
 ******************************************/
-int countMacModifyPerDayInMngDb(char* userId, char* extraId){
+int countMacModifyPerDayInMngDb(char* userId, char* extraId, char* macAddress){
 
   MYSQL_RES *res=NULL;
   MYSQL_ROW row;
@@ -333,12 +333,21 @@ int countMacModifyPerDayInMngDb(char* userId, char* extraId){
   int count=10000;
 
   /* prepare query string */
-  snprintf(queryStr, BUFFMAXLN, 
+  /* count for one macAddress if not null, elsecount for one userID)*/
+  if(!isNull(macAddress)){
+    snprintf(queryStr, BUFFMAXLN, 
+          "select count(*) from macmodify "
+          " where macAddress='%s' and "
+          " modifyDate > adddate(now(), interval -1 day) ",
+          macAddress);
+  }else{
+    snprintf(queryStr, BUFFMAXLN, 
           "select count(*) from macmodify "
           " where userId='%s' and extraId='%s' and "
           " modifyDate > adddate(now(), interval -1 day) ",
           userId, extraId);
-
+  }
+  
   /* send SQL query */
   if (mysql_query(&mysql, queryStr)){
     err_msg("ERR at %s#%d: mysql query: %s",__FILE__,__LINE__,
@@ -713,7 +722,72 @@ int renameMailAddressInMngDb(char* macAddr, char* mailStr){
   return TRUE;
 }
 
+/********************************************
+Register or Update MacAddress which is unlinked to user
+********************************************/
+int regOrUpNobodyMacAddr(char* macAddress){
 
+  int modified=FALSE;
+
+  /* macAddress in inactive status cannot be modified */
+  if(IsMacAddrStatusInactiveInMngDb(macAddress)) return FALSE;
+  
+  /* if mac is already registered, update it */
+  if(IsMacAddrFoundInMngDb(macAddress)){
+    if(RenewMacAddrInMngDb(macAddress)){
+      PutMacModifyLogToMngDb("?", "", macAddress, 'E'); /*(userId,extraId,.)*/
+      modified=TRUE;
+    }
+  }
+
+  /* if mac is not yet registered, register it */ 
+  else{
+    if(RegistMacAddrToMngDb(macAddress,"?","?","","")){ /*(dev,user,ext,mail) */
+       PutMacModifyLogToMngDb("?","", macAddress, 'R'); /* (userId,extraId,.) */
+      modified=TRUE;
+    }
+  }
+  return modified;
+}
+
+/******************************************
+ Is the macAddr  in INACTIVE('I') status
+******************************************/
+int isMacAddrStatusInactiveInMngDb(char* macAddr){
+
+  MYSQL_RES *res=NULL;
+  MYSQL_ROW row;
+  char queryStr[BUFFMAXLN];
+  int ret;
+
+  /* prepare query string */
+  snprintf(queryStr, BUFFMAXLN, 
+          "select * from macaddrs "
+          " where macAddress='%s' and status='I'",
+          macAddr);
+  
+  /* send SQL query */
+  if (mysql_query(&mysql, queryStr)){
+    err_msg("ERR at %s#%d: mysql query: %s",__FILE__,__LINE__,
+           mysql_error(&mysql));
+    return FALSE;
+  }
+  
+  /* store result */
+  res = mysql_store_result(&mysql);
+
+  /* output table name */
+  row = mysql_fetch_row(res);
+  
+  /* if found, return true */
+  if(row!=NULL) ret=TRUE;
+
+  /* if not found, return false */
+  else ret=FALSE;
+
+  mysql_free_result(res);
+  return ret;
+}
 
 /********************************************
  routines for debugging output
@@ -787,11 +861,11 @@ int GetNicVendorFromMngDb(char* macAddress, char* vendor, int bufferLength){
 }
 
 
-int CountMacModifyPerDayInMngDb(char* userId, char* extraId){
+int CountMacModifyPerDayInMngDb(char* userId, char* extraId, char* macAddress){
   int ret;
-  if(debug>1) err_msg("DEBUG:=>countMacModifyPerDayInMngDb(%s,%s)",
-                     userId,extraId);
-  ret=countMacModifyPerDayInMngDb(userId,extraId);
+  if(debug>1) err_msg("DEBUG:=>countMacModifyPerDayInMngDb(%s,%s,%s)",
+                     userId,extraId,macAddress);
+  ret=countMacModifyPerDayInMngDb(userId,extraId,macAddress);
   if(debug>1) err_msg("DEBUG:(%d)<=countMacModifyPerDayInMngDb( )",ret);
   return ret;
 }
@@ -872,3 +946,20 @@ int RenameMailAddressInMngDb(char* macAddr, char* mailStr){
   if(debug>1) err_msg("DEBUG:(%d)<=renameMailAddressInMngDb()",ret);
   return ret;
 }
+
+int RegOrUpNobodyMacAddr(char* macAddress){
+  int ret;
+  if(debug>1) err_msg("DEBUG:=>regOrUpNobodyMacAddr(%s)",macAddress);
+  ret=regOrUpNobodyMacAddr(macAddress);
+  if(debug>1) err_msg("DEBUG:(%d)<=regOrUpNobodyMacAddr()",ret);
+  return ret;
+}
+
+
+int IsMacAddrStatusInactiveInMngDb(char* macAddress){
+    int ret;
+  if(debug>1) err_msg("DEBUG:=>isMacAddrStatusInactiveInMngDb(%s)",macAddress);
+  ret=isMacAddrStatusInactiveInMngDb(macAddress);
+  if(debug>1) err_msg("DEBUG:(%d)<=isMacAddrStatusInactiveInMngDb()",ret);
+  return ret;
+}