/****************************************
add item to Mac cache
****************************************/
-int addMacCacheItem(char* macAddress, char* userId, char* extraId) {
+int addMacCacheItem(char* macAddress, char* userId, char* extraId, int found) {
DBT hashKey;
DBT hashVal;
hashKey.size = strlen(macAddress) + 1;
/** setup hash value **/
- /* hash value : string "<unixtime>SPACE<userId>SPACE<extraId>" */
- snprintf(hashValueStr,BUFFMAXLN,"%d %s %s",time(NULL),userId,extraId);
+ /* hash value : string "<found>SPACE<unixtime>SPACE<userId>SPACE<extraId>" */
+ snprintf(hashValueStr,BUFFMAXLN,"%d %d %s %s",
+ found,time(NULL),userId,extraId);
hashVal.data = hashValueStr;
hashVal.size = strlen(hashValueStr) + 1;
if(macHashDb->put(macHashDb, &hashKey, &hashVal, 0) == -1) {
/****************************************
query userid and extraid for mac address
-if the entry time is old, return false
+if address is found in cache, return true or false(enable addr or not).
+if not found, too old or error, return error.
****************************************/
int queryMacFromMacCache(char* macAddress, char* userId, char* extraId){
DBT hashVal;
time_t entryTime;
int ret;
+ int found;
/* set default */
entryTime=0;
userId[0]=extraId[0]='\0';
/* if null or illegal form, return */
- if(isNull(macAddress)) return FALSE;
- if(!ReFormatMacAddr(macAddress)) return FALSE;
+ if(isNull(macAddress)) return ERROR;
+ if(!ReFormatMacAddr(macAddress)) return ERROR;
/***** get hashed item matched to the indicated mac */
hashKey.data = macAddress;
ret=macHashDb->get(macHashDb, &hashKey, &hashVal, 0);
/* get is failed, return false */
- if(ret!=0) return FALSE;
+ if(ret!=0) return ERROR;
/* get is successed */
/* pick up the hash values */
- ret=sscanf(hashVal.data,"%d %s %s",&entryTime,userId,extraId);
+ ret=sscanf(hashVal.data,"%d %d %s %s",&found,&entryTime,userId,extraId);
- /* entryTime and userId should be obtained, but extraId is not */
- if(ret<=1) return FALSE;
+ /* found, entryTime should be obtained */
+ if(ret<=1) return ERROR;
/* if entry time is older than timeout, return false */
- if( entryTime + macCacheTimeout < time(NULL) ) return FALSE;
+ if( entryTime + macCacheTimeout < time(NULL) ) return ERROR;
- return TRUE;
+ /* return the mac db access result (found/not found) */
+ return found;
}
/****************************************
if(debug>1) err_msg("DEBUG:<=freeMacCache()");
}
-int AddMacCacheItem(char* macAddress, char* userId, char* extraId) {
+int AddMacCacheItem(char* macAddress, char* userId, char* extraId, int found) {
int ret;
- if(debug>1) err_msg("DEBUG:=>addMacCacheItem(%s,%s,%s)", macAddress,userId,extraId);
- ret = addMacCacheItem(macAddress,userId,extraId);
+ if(debug>1) err_msg("DEBUG:=>addMacCacheItem(%s,%s,%s,%d)", macAddress,userId,extraId,found);
+ ret = addMacCacheItem(macAddress,userId,extraId,found);
if(debug>1) err_msg("DEBUG:(%d)<=addMacCacheItem( )",ret);
return ret;
}
/* search the address in cache of MAC DB */
macFound = QueryMacFromMacCache(macAddress, userId, extraId);
- /* if not found in MAC DB cache, access MAC DB and add result to cache */
- if(!macFound){
+ /* if accessing cache of MAC DB is failed, access MAC DB */
+ if(macFound==ERROR){
macFound = QueryMacFromMngDb(macAddress, userId, extraId);
- if(macFound) AddMacCacheItem(macAddress, userId, extraId);
+
+ /* if db access is failed, set not-found and retry next time */
+ /* if db access is successed (found or not), save it to cache */
+ if(macFound==ERROR) macFound=FALSE;
+ else AddMacCacheItem(macAddress, userId, extraId, macFound);
}
/*** depending the states, add/del/renew the session ***/