AIMAccount * IAccountModel_findHistoryAcnt(IAccountModel *pAcntModel, const AMChar *szAcntID) { ListIter *pItr = 0; AIMAccount *pAcnt = 0; AMAssert(0 != pAcntModel && 0 != szAcntID); if(pAcntModel->listAcnt.size <= 0) return 0; pItr = create(ListIter, &pAcntModel->listAcnt); head(ListIter, pItr); do { pAcnt = (AIMAccount *)retrieve(ListIter, pItr); if(0 == AMStrcmp(pAcnt->szID, szAcntID)//帐号相等 || (pAcnt->szPhoneNum && 0 == AMStrcmp(pAcnt->szPhoneNum, szAcntID + ID_HEAD_LEN)))//或者传进来的电话号码相等 { destroy(ListIter, pItr); return pAcnt; } } while (!next(ListIter, pItr)); destroy(ListIter, pItr); return 0; }
//i64Id=0表示标记该Session的所有未读消息为已读,i6rId>0表示只标记对应_rid的消息为已读 //传进来的Msg的跟hSession是需要一致的,否则后面的IAContactModel_DecreaseReadCnt无法处理... AIM_RESULT IAIMSession_MarkMsgRead(AMHandle hSession, AMInt64 i64MsgId) { IASession *pSes = (IASession *)hSession; AMInt32 rcSqlite = 0; AMChar *szSql = AMNULL; AMChar *szErrMsg = AMNULL; AMInt32 iUnreadCount = 0; AIM_RESULT eResult = 0; AMAssert(AMNULL != pSes); eResult = AIMSession_CountUnreadMsgs(pSes, i64MsgId, &iUnreadCount); if(eAIM_RESULT_OK != eResult) { return eAIM_RESULT_OK; } if(iUnreadCount <= 0) return eAIM_RESULT_OK; if(0 == i64MsgId) { if(0 == AMStrcmp(pSes->szContactID, SYS_SES_NAME))//系统消息 { szSql = sqlite3_mprintf(SQL_MARK_READ_SYS_MSG); } else//普通聊天消息 { szSql = sqlite3_mprintf(SQL_MARK_READ_CNT_MSG, pSes->szContactID); } } else { szSql = sqlite3_mprintf(SQL_MARK_READ_MSG_ID, i64MsgId); } if(!szSql) return eAIM_RESULT_MALLOC_ERROR; rcSqlite = sqlite3_exec(pSes->pSesModel->pDB, szSql, 0, 0, &szErrMsg); sqlite3_free(szSql); if(SQLITE_OK != rcSqlite) { DPRINT("IASession_MarkMsgRead.............can not %s for %s\n", szSql, szErrMsg); sqlite3_free(szErrMsg); return eAIM_RESULT_DB_ERROR; } if(0 != AMStrcmp(pSes->szContactID, SYS_SES_NAME)) { IAContactModel_DecreaseReadCnt(pSes->pSesModel->pReference->pCntModel, pSes->szContactID, iUnreadCount); } return eAIM_RESULT_OK; }
AMInt32 IASession_Cmp(const AMVoid *p1, const AMVoid *p2, size_t t) { IASession *pA = (IASession*)p1, *pB = (IASession*)p2; AMAssert(0 != pA && 0 != pB); AMAssert(0 != pA->szContactID && 0 != pB->szContactID); return AMStrcmp(pA->szContactID, pB->szContactID); }
AMInt32 IAGroup_CmpPinyin(const AMVoid *pG1,const AMVoid *pG2, size_t t) { IAGroup *pGA = (IAGroup*)pG1, *pGB = (IAGroup*)pG2; AMAssert(0 != pGA && 0 != pGB); AMAssert(0 != pGA->szPinyin && 0 != pGB->szPinyin); return AMStrcmp(pGA->szPinyin, pGB->szPinyin); }
AMInt32 _AIMAuth_cmpSession(const AMVoid *pvArgA, const AIMAuth *pvArgB, AMUInt32 uiSize) { AIMAuth *pAuthA = (AIMAuth *)pvArgA, *pAuthB = (AIMAuth *)pvArgB; AMAssert(pAuthA && pAuthB); return AMStrcmp(pAuthA->szSession, pAuthB->szSession); }
AMInt32 IAccount_cmpID(const AMVoid *pA, const AMVoid *pB, size_t s) { AIMAccount *pAcntA, *pAcntB; AMAssert(0 != pA && 0 != pB); pAcntA = (AIMAccount *)pA; pAcntB = (AIMAccount *)pB; AMAssert(pAcntA->szID != 0 && pAcntB->szID != 0); DPRINT("IAccount_cmpID.................%s, %s\n", pAcntA->szID, pAcntB->szID); return AMStrcmp(pAcntA->szID, pAcntB->szID); }
static AMInt32 IAccountModel_OnSelAcnt(void* pvAcntor, int iCnt, char **pszValue, char**pszName) { IAccountModel *pAcntModel = (IAccountModel *)pvAcntor; AIMAccount *pAcnt = 0; AMAssert(0 !=pAcntModel); DPRINT("IAccountModel_OnSelAcnt %s ! %s ! %s ! %s ! %s ! %s ! %s\n" , pszValue[0], pszValue[1], pszValue[2], pszValue[3], pszValue[4], pszValue[5], pszValue[6]); pAcnt = IAccount_Create(); pAcnt->_iRid = AMAtoi(pszValue[0]); if(0 != IAccount_SetID(pAcnt, pszValue[1], AMStrlen(pszValue[1]))) return -1; pAcnt->uiFlag = AMAtoi(pszValue[4]); if(pAcnt->uiFlag&01 && 0 != AMStrcmp("0", pszValue[2])) { IAccount_SetToken(pAcnt, pszValue[2], AMStrlen(pszValue[2])); } if(0 != AMStrcmp("0", pszValue[3])) { IAccount_SetPhoneNum(pAcnt, pszValue[3]); } pAcnt->ePresence = AMAtoi(pszValue[5]); pAcnt->iGroupStamp = AMAtoi(pszValue[6]); pAcnt->iContactStamp = AMAtoi(pszValue[7]); pAcnt->iBlackStamp = AMAtoi(pszValue[8]); pAcnt->iRevBlackStamp = AMAtoi(pszValue[9]); if(0 != AMStrcmp("0", pszValue[10])) { IAccount_SetSigXML(pAcnt, pszValue[10], AMStrlen(pszValue[10])); } push_front_List(&pAcntModel->listAcnt, pAcnt, sizeof(AIMAccount), DYNAMIC); return 0; }
AIM_RESULT AIMSession_CountUnreadMsgs( AMHandle hSession, AMInt64 iID, AMInt32 *pCount ) { const IASession *pSession = (const IASession *)hSession; AMInt32 iRet = 0; AMInt32 rcSqlite = 0; AMChar *szSql = AMNULL; AMChar *szErrMsg = AMNULL; AMAssert(AMNULL != pSession && AMNULL != pCount); AMAssert(AMNULL != pSession->pSesModel); AMAssert(AMNULL != pSession->pSesModel->pDB); if(0 == iID) { if(0 == AMStrcmp(pSession->szContactID, SYS_SES_NAME))//系统消息 { szSql = sqlite3_mprintf(SQL_SELECT_UNREAD_SYS_MSG_COUNT); } else//普通聊天消息 { szSql = sqlite3_mprintf(SQL_SELECT_UNREAD_CNT_MSG_COUNT, pSession->szContactID); } } else { szSql = sqlite3_mprintf(SQL_SELECT_UNREAD_COUNT_ID, iID); } if(szSql) { rcSqlite = sqlite3_exec(pSession->pSesModel->pDB, szSql, IASession_OnSelUnreadCnt, &iRet, &szErrMsg); sqlite3_free(szSql); if(SQLITE_OK != rcSqlite) { DPRINT("IASession_GetUnreadCnt.............can not %s for %s\n", szSql, szErrMsg); sqlite3_free(szErrMsg); return eAIM_RESULT_DB_ERROR; } *pCount = iRet; return eAIM_RESULT_OK; } else { return eAIM_RESULT_MALLOC_ERROR; } }
//因为需要先MarkRead,所以i64MsgId也需要跟hSession一致 AIM_RESULT AIMSession_RemoveMsg(AMHandle hSession, AMInt64 i64MsgId, AMBool bHasUnread) { IASession *pSes = (IASession *)hSession; AMInt32 rcSqlite = 0; AMChar *szSql = AMNULL; AMChar *szErrMsg = AMNULL; AMAssert(AMNULL != pSes && AMNULL != pSes->pSesModel->pDB); DPRINT("AIMSession_RemoveMsg\t\t\t Entering "I64FORMAT"\n", i64MsgId); if(bHasUnread) IAIMSession_MarkMsgRead(hSession, i64MsgId); if(i64MsgId<=0) { if(0 == AMStrcmp(pSes->szContactID, "systemSes"))//系统消息 { szSql = sqlite3_mprintf(SQL_DELETE_SYS_MSG); } else//普通聊天消息 { szSql = sqlite3_mprintf(SQL_DELETE_CNT_MSG, pSes->szContactID); } } else { szSql = sqlite3_mprintf(SQL_DELETE_MSG_ID, i64MsgId); } DPRINT("AIMSession_RemoveMsg\t\t\t SQL: %s\n", szSql); if(!szSql) return eAIM_RESULT_MALLOC_ERROR; rcSqlite = sqlite3_exec(pSes->pSesModel->pDB, szSql, 0, 0, &szErrMsg); sqlite3_free(szSql); if(SQLITE_OK != rcSqlite) { DPRINT("IASession_RemoveMsg.............can not %s for %s\n", szSql, szErrMsg); sqlite3_free(szErrMsg); return eAIM_RESULT_DB_ERROR; } return eAIM_RESULT_OK; }
AIM_RESULT OnRspGetSignature(AMVoid *pvArg, AIM_RSP_GET_SIGNATURE *rspGetSignature) { AIM_CONTACT_UPDATE_DATA *pPresent = 0; AMInt32 i=0; IAIM *pIM = (IAIM*)(((AMPVoid*)pvArg)[1]); if(!rspGetSignature->iRetCode) { pPresent = (AIM_CONTACT_UPDATE_DATA *)AMMalloc(sizeof(AIM_CONTACT_UPDATE_DATA) * rspGetSignature->iCount); AMMemset(pPresent, 0, sizeof(AIM_CONTACT_UPDATE_DATA) * rspGetSignature->iCount); for(i=0; i<rspGetSignature->iCount; i++) { pPresent[i].iFlag = 0; pPresent[i].szID = rspGetSignature->pszContactIds[i]; pPresent[i].szSignature = rspGetSignature->pszValues[i]; pPresent[i].ucType = eAIM_CONTACT_SIGNATURE; } JavaPreListener(pvArg, pPresent, rspGetSignature->iCount); AMFree(pPresent); } else { AMAssert(pIM && pIM->pAcnt); AMAssert(rspGetSignature->pszContactIds); DPRINT("OnRspGetSignature................Fail: %s\n", *(rspGetSignature->pszContactIds)); if(0 == AMStrcmp(pIM->pAcnt->szID, *(rspGetSignature->pszContactIds))) { DPRINT("OnRspGetSignature................Fail: %s\n", *(rspGetSignature->pszContactIds)); //pIM->pAcnt->bGetSigFail = AMTRUE; } else { DPRINT("OnRspGetSignature.....................Acnt %s\n", pIM->pAcnt->szID); } } return eAIM_RESULT_OK; }
//本函数具有所有潜规则! AIM_RESULT AIMSession_GetMsgs( AMHandle hSession, AMInt32 iOffset, AMInt32 iCount, AMBool bUnread , AMHandle **pphMsgArray, AMInt32 *piCount) { IASession *pSession = (IASession *)hSession; AMInt32 rcSqlite = 0; AMChar *szSql = AMNULL; AMChar *szErrMsg = AMNULL; AMPVoid pvArgs[2] = {pphMsgArray, piCount}; AMAssert(AMNULL != pSession && AMNULL != pSession->pSesModel->pDB); AMAssert(AMNULL != pphMsgArray && AMNULL != piCount); *piCount = 0; *pphMsgArray = AMNULL;//ReleaseMsgs要利用free不释放NULL的特点。 if(iCount > 0) { if(bUnread) { if(0 == AMStrcmp(pSession->szContactID, SYS_SES_NAME))//系统消息 { szSql = sqlite3_mprintf(SQL_SELECT_UNREAD_SYS_MSG, iCount, iOffset); } else//普通聊天消息 { szSql = sqlite3_mprintf(SQL_SELECT_UNREAD_CNT_MSG, pSession->szContactID, iCount, iOffset); } } else { if(0 == AMStrcmp(pSession->szContactID, SYS_SES_NAME))//系统消息 { szSql = sqlite3_mprintf(SQL_SELECT_SYS_MSG, iCount, iOffset); } else//普通聊天消息 { szSql = sqlite3_mprintf(SQL_SELECT_CNT_MSG, pSession->szContactID, iCount, iOffset); } } } else { szSql = sqlite3_mprintf(SQL_SELECT_MSG_ID, iOffset); } if(!szSql) return eAIM_RESULT_MALLOC_ERROR; DPRINT("%s >>>>>> sql: %s\n", __FUNCTION__, szSql); //iCount may be zero to select a particular message. *pphMsgArray = (AMHandle*)AMMalloc(sizeof(AMHandle) * (iCount + 1)); if(!(*pphMsgArray)) return eAIM_RESULT_MALLOC_ERROR; AMMemset(*pphMsgArray, 0, sizeof(AMHandle) * (iCount + 1)); rcSqlite = sqlite3_exec(pSession->pSesModel->pDB, szSql, AIMSession_OnSelMsgs, pvArgs, &szErrMsg); sqlite3_free(szSql); if(SQLITE_OK != rcSqlite) { DPRINT("IASession_GetHistory.............can not %s for %s\n", szSql, szErrMsg); sqlite3_free(szErrMsg); IAIMSession_ReleaseMsgs(hSession, *pphMsgArray, *piCount); return eAIM_RESULT_DB_ERROR; } if(!(*piCount)) AMFree(*pphMsgArray); return eAIM_RESULT_OK; }