+ 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;
+}