static _AIMAuthModule_findSession(AIMAuthModule *pAuthModule, const AMChar *szSession) { AIMAuth authTmp; AMAssert(pAuthModule && szSession); authTmp.szSession = szSession; set_compare(List, &pAuthModule->lstAuth, _AIMAuth_cmpSession); return find_List(&pAuthModule->lstAuth, &authTmp, sizeof(AIMAuth)); }
/* * 不加锁,根据id查找List。使用者考虑加锁的情况 */ AIMAuth * _AIMAuthModule_findId(AIMAuthModule *pAuthModule, AMInt32 iAuthId) { AIMAuth authTmp; AMAssert(pAuthModule && iAuthId); authTmp.iAuth = iAuthId; set_compare(List, &pAuthModule->lstAuth, _AIMAuth_cmpId); return find_List(&pAuthModule->lstAuth, &authTmp, sizeof(AIMAuth)); }
AMVoid IAccountModel_ClearToken(IAccountModel *pAcntModle, const AIMAccount *pAcnt) { AIMAccount *pAcntFind = AMNULL; AMChar *szSql = AMNULL, *szErrMsg = AMNULL; sqlite3 *pDB = AMNULL; AMInt32 rcSqlite = 0; AMAssert(AMNULL != pAcntModle && AMNULL != pAcnt); pAcntFind = find_List(&pAcntModle->listAcnt, (void*)pAcnt, sizeof(AIMAccount)); if(pAcntFind) { AMFree(pAcntFind->szToken); pAcntFind->szToken = AMNULL; IAccountModel_MarkDirt(pAcntModle); rcSqlite = myADB_Open(IM_ACNT_DB, &pDB, AMFALSE); if(rcSqlite) { DPRINT("IAccountModel_ClearToken: Can't open database: %s\n", sqlite3_errmsg(pDB)); sqlite3_close(pDB); return; } rcSqlite = sqlite3_exec(pDB, SQL_CREATE_ACNT_TABLE, 0, 0, &szErrMsg); if( rcSqlite != SQLITE_OK ) { DPRINT("IAccountModel_ClearToken: Can't \"CREATE TABLE _account(...);\": %s!\n", szErrMsg); sqlite3_close(pDB); sqlite3_free(szErrMsg); return; } szSql = sqlite3_mprintf(SQL_CLEAR_TOKEN, pAcnt->_iRid); if(AMNULL != szSql) { rcSqlite = sqlite3_exec(pDB, szSql, 0, 0, &szErrMsg); sqlite3_free(szSql); if( rcSqlite != SQLITE_OK ) { DPRINT("IAccountModel_ClearToken: Can't UPDATE!\n"); sqlite3_free(szErrMsg); sqlite3_close(pDB); return; } } sqlite3_close(pDB); IAccountModel_ClearDirt(pAcntModle); } }
int find_Hash(Hash H, const void *toFind){ unsigned int value; assert(H); value = hash((char *)toFind, H->length); if (find_List(H->lists[value], toFind)) return 1; return 0; }
AMInt32 IAccountModel_UpdateStamp(IAccountModel *pAcntModel, AIMAccount *pAcnt, AMInt32 iDirtFlag) { AIMAccount *pAcntFind = 0; AMAssert(0 != pAcntModel); pAcntFind = find_List(&pAcntModel->listAcnt, pAcnt, sizeof(AIMAccount)); if(AMNULL != pAcntFind) { if(0 != iDirtFlag || pAcntFind->iGroupStamp != pAcntFind->iGroupStamp || pAcntFind->iContactStamp != pAcnt->iContactStamp || pAcntFind->iBlackStamp != pAcnt->iBlackStamp || pAcntFind->iRevBlackStamp != pAcnt->iRevBlackStamp) IAccountModel_MarkDirt(pAcntModel); if(0 == (iDirtFlag&0x01)) pAcntFind->iGroupStamp = pAcnt->iGroupStamp; else pAcntFind->iGroupStamp = 0; if(0 == (iDirtFlag&0x02)) pAcntFind->iContactStamp = pAcnt->iContactStamp; else pAcntFind->iContactStamp = 0; if(0 == (iDirtFlag&0x04)) pAcntFind->iBlackStamp = pAcnt->iBlackStamp; else pAcntFind->iBlackStamp = 0; if(0 == (iDirtFlag&0x08)) pAcntFind->iRevBlackStamp = pAcnt->iRevBlackStamp; else pAcntFind->iRevBlackStamp = 0; } else { AMAssert(0); } return 0; }