X-Git-Url: http://git.sourceforge.jp/view?a=blobdiff_plain;ds=sidebyside;f=mngsrc%2Fmanagementdb.c;fp=mngsrc%2Fmanagementdb.c;h=103787aac084f2a906189056f80fabab20a73c25;hb=8da4f192a4aeba5ac0b592859af2df8d979d43a7;hp=3ac08aef0a87e3e8c8c0cd57797f291fde26944d;hpb=65cc8326dc55b0d7fdddd275da32cd989436b25e;p=opengatem%2Fopengatem.git diff --git a/mngsrc/managementdb.c b/mngsrc/managementdb.c index 3ac08ae..103787a 100644 --- a/mngsrc/managementdb.c +++ b/mngsrc/managementdb.c @@ -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; +}