AMVoid IAccount_SetNameType(AIMAccount *pAcnt, const AMChar *szName, AMUInt32 uiNameLen, AIM_ACCOUNT_TYPE eType) { AMAssert(0 != pAcnt); AMAssert(0 != szName && eType>=0 && eType <= 8); if(pAcnt->szName) { AMFree(pAcnt->szName); pAcnt->szName = 0; } pAcnt->szName = AMMalloc(uiNameLen + 1); AMAssert(0 != pAcnt->szName); AMMemset(pAcnt->szName, 0, uiNameLen + 1); AMMemcpy(pAcnt->szName, szName, uiNameLen); pAcnt->eType = eType; if(pAcnt->szID) { AMFree(pAcnt->szID); pAcnt->szID = 0; } pAcnt->szID = AMMalloc(uiNameLen + ID_HEAD_LEN + 1); AMAssert(0 != pAcnt->szID); AMMemset(pAcnt->szID, 0, uiNameLen + ID_HEAD_LEN + 1); AMStrcpy(pAcnt->szID, szID_Head[eType]); AMMemcpy(pAcnt->szID + ID_HEAD_LEN, szName, uiNameLen); }
IMnetRetCode AIMAuthModule_onNtfNeedAuth(IMnetHandle hIMnetHandle, EventContent* pEventContent) { IAIM *pIM = (IAIM *)IMnetGetReference(hIMnetHandle); ImNtfNeedAuthCode *pNeedAuth = (ImNtfNeedAuthCode *)pEventContent; AMInt32 iRetCode = eAIM_RESULT_OK, iImgLen = 0, iAuthId = 0; AMChar *szSessin = AMNULL, *szImgData = AMNULL; AIM_NTF_NEED_AUTH ntfNeedAuth; DPRINT("%s >>>>>> Entering\n", __FUNCTION__); iRetCode = _AIMAuth_getAuthImg(&szSessin, &szImgData, &iImgLen); _AIMAuthModule_addAuth(pIM->hAuthModule, szSessin, pNeedAuth->szPacket, pNeedAuth->uiPacketLen, &iAuthId); AMMemset(&ntfNeedAuth, 0, sizeof(ntfNeedAuth)); ntfNeedAuth.iAuthId = iAuthId; ntfNeedAuth.iRetCode = iRetCode; if(eAIM_RESULT_OK == iRetCode) { ntfNeedAuth.pvData = szImgData; ntfNeedAuth.iDataLen = iImgLen; pNeedAuth->szPacket = AMNULL; } _AIMAuth_notify(pIM, OnNtfNeedAuth, &ntfNeedAuth); if(ntfNeedAuth.pvData) AMFree(ntfNeedAuth.pvData); DPRINT("%s >>>>>> id: %d, code: %d, session: %s, imgLen: %d\n", __FUNCTION__, ntfNeedAuth.iAuthId, ntfNeedAuth.iRetCode, szSessin, iImgLen); return eIMnetSkip; }
AMTaskMgr* AMTaskMgrCreate(AMInt32 concurNum) { AMInt32 index = 0; if(concurNum < 0) concurNum = AMASYNCTASK_DEFAULT_EXECUTE_COUNT; else if(concurNum > AMASYNCTASK_MAX_EXECUTE_COUNT) concurNum = AMASYNCTASK_MAX_EXECUTE_COUNT; _AMTaskMgrInit(); AMThreadMutexLock(&gMutex); for(;index < AMASYNCTASK_SUPPORTED_MAXMGR; index++) { if(gTaskMgr[index] == AMNULL) { _AMTaskMgr* _taskMgr = (_AMTaskMgr*)AMMalloc(sizeof(_AMTaskMgr)); if(_taskMgr == AMNULL) { AMThreadMutexUnlock(&gMutex); return AMNULL; } gTaskMgrCount++; AMMemset(_taskMgr, 0 , sizeof(_AMTaskMgr)); _taskMgr->mId = index; _taskMgr->mConcurNum = concurNum; AMThreadMutexCreate(&_taskMgr->mMutex); AMThreadMutexUnlock(&gMutex); return (AMTaskMgr*)_taskMgr; } } AMThreadMutexUnlock(&gMutex); return AMNULL; }
AMChar * BuildSigXMLFromStruct(AIM_SIGNATURE *pSigStruct, const AMChar *szSig)//只是把5个sig造好,没有追加后面的loop/st/ci等设置 { AMChar * szResultXML = AMNULL; AMInt32 iLen = 0, iPos = 0, i=0; AMAssert(pSigStruct); iLen = sizeof(XML_SIG_TEMPHEAD) + sizeof(XML_SIG_TEMPTAIL) + 3*MAX_INT_NUMBER_LEN; iLen += szSig?AMStrlen(szSig):0 + 11; for(i=0; i< MAX_SIG_COUNT-1; i++) iLen += pSigStruct->szSignature[i]?AMStrlen(pSigStruct->szSignature[i]):0 + 11;//11 for "<Sig></Sig>" szResultXML = (AMChar*)AMMalloc(iLen); if(!szResultXML) return AMNULL; AMMemset(szResultXML, 0, iLen); AMMemcpy(szResultXML, HeadTag(XML_TAG_SIGOP), sizeof(HeadTag(XML_TAG_SIGOP))-1); AMStrcat(szResultXML, HeadTag(XML_TAG_SIG)); if(szSig) AMStrcat(szResultXML, szSig); AMStrcat(szResultXML, TailTag(XML_TAG_SIG)); for(i=0; i< MAX_SIG_COUNT-1; i++) { AMStrcat(szResultXML, HeadTag(XML_TAG_SIG)); AMStrcat(szResultXML, pSigStruct->szSignature[i]); AMStrcat(szResultXML, TailTag(XML_TAG_SIG)); } return szResultXML; }
IAIMessage* IAIMessage_Create() { IAIMessage *pRet = 0; pRet = (IAIMessage*)AMMalloc(sizeof(IAIMessage)); AMAssert(0 != pRet); AMMemset(pRet, 0, sizeof(IAIMessage)); return pRet; }
static AMVoid _AMTaskMgrInit() { if(gMutex != AMNULL) return; AMThreadMutexCreate(&gMutex); gTaskMgrCount = 0; AMMemset(gTaskMgr, 0, sizeof(gTaskMgr)); }
AIMAccount * IAccount_Create() { AIMAccount *pRet = AMMalloc(sizeof(AIMAccount)); AMAssert(0 != pRet); AMMemset(pRet, 0, sizeof(AIMAccount)); return pRet; }
/* * 外面传入szSession\szRawPacket, 赋值(不拷贝)给AIMAuth */ AIMAuth *_AIMAuth_create(const AMChar *szSession, const AMChar *szRawPacket, AMUInt32 uiLen) { AIMAuth *pAuth = AMNULL; pAuth = (AIMAuth *)AMMalloc(sizeof(AIMAuth)); if(!pAuth) return AMNULL; AMMemset(pAuth, 0, sizeof(AIMAuth)); pAuth->szSession = szSession; pAuth->szRawPacket = szRawPacket; pAuth->uiPacketLen = uiLen; pAuth->iStatus = eAUTH_SESSION; return pAuth; }
AIM_RESULT OnRspGetProfile(AMVoid *pvArg, AIM_RSP_GET_PROFILE *pRspGetProfile) { IAIM *pIM = (IAIM*)(((AMPVoid*)pvArg)[1]); IAIMessage *pMsg = 0; AMInt32 iContentLen = 0, i = 0, iPos = 0, iLen = 0;; pMsg = IAIMessage_Create(); pMsg->bUnread = AMTRUE; pMsg->eType = (AIM_MSG_TYPE)GET_PEER_UDB_PROFILE; IAIMessage_SetCntID(pMsg, pRspGetProfile->szContactId, AMStrlen(pRspGetProfile->szContactId)); iContentLen = pRspGetProfile->iTotalLen + 4 + AMStrlen(pRspGetProfile->szContactId) + sizeof(UID_KEYWROD_ID); iContentLen += pRspGetProfile->iCount*2; pMsg->szContent = (AMChar *)AMMalloc(iContentLen); if(AMNULL == pMsg->szContent) { IAIMessage_Destroy(pMsg); return eAIM_RESULT_NOT_READY; } AMMemset(pMsg->szContent, 0, iContentLen); for(i=0; i<pRspGetProfile->iCount; i++) { if(AMNULL != pRspGetProfile->pszValues[i]) { iLen = AMStrlen(pRspGetProfile->pszKeys[i]); AMMemcpy(pMsg->szContent+iPos, pRspGetProfile->pszKeys[i], iLen); iPos += iLen; pMsg->szContent[iPos++] = '\1'; iLen = AMStrlen(pRspGetProfile->pszValues[i]); AMMemcpy(pMsg->szContent+iPos, pRspGetProfile->pszValues[i], iLen); iPos += iLen; pMsg->szContent[iPos++] = '\1'; } } AMMemcpy(pMsg->szContent+iPos, UID_KEYWROD_ID, sizeof(UID_KEYWROD_ID)-1);//加上"uid\1'contactId'" iPos += sizeof(UID_KEYWROD_ID)-1; pMsg->szContent[iPos++] = '\1'; AMStrcat(pMsg->szContent+iPos, pRspGetProfile->szContactId);//不需要尾巴了 DPRINT("IASessionModel_OnPeerVerifyConfig.................%s\n", pMsg->szContent); Adapter_OnIncomingSysMsg(pIM->pSesModel, pMsg, pvArg); IAIMessage_Destroy(pMsg); return eAIM_RESULT_OK; }
AMInt32 AIMAuthModule_updateCode(AMHandle hAuthModule, AMInt32 iAuthId) { AIMAuthModule *pAuthModule = (AIMAuthModule *)hAuthModule; AIMAuth tmpAuth, *pAuthFind = AMNULL; AMInt32 iRetCode = eAIM_RESULT_OK, iImgLen = 0; AMChar *szSessin = AMNULL, *szImgData = AMNULL; AIM_NTF_NEED_AUTH ntfNeedAuth; AMAssert(pAuthModule && iAuthId); iRetCode = _AIMAuth_getAuthImg(&szSessin, &szImgData, &iImgLen); DPRINT("%s >>>>>> session: %s, imgLen: %d\n", __FUNCTION__, szSessin, iImgLen); if(eAIM_RESULT_OK == iRetCode) { tmpAuth.iAuth = iAuthId; AMThreadMutexLock(&pAuthModule->mtxAuth); set_compare(List, &pAuthModule->lstAuth, _AIMAuth_cmpId); pAuthFind = _AIMAuthModule_findId(pAuthModule, iAuthId); if(pAuthFind) _AIMAuth_setSession(pAuthFind, szSessin); else iRetCode = eAIM_RESULT_NOT_READY; AMThreadMutexUnlock(&pAuthModule->mtxAuth); } AMMemset(&ntfNeedAuth, 0, sizeof(ntfNeedAuth)); ntfNeedAuth.iAuthId = iAuthId; ntfNeedAuth.iRetCode = iRetCode; if(eAIM_RESULT_OK == iRetCode) { ntfNeedAuth.pvData = szImgData; ntfNeedAuth.iDataLen = iImgLen; } if(eAIM_RESULT_NOT_READY != iRetCode) _AIMAuth_notify(pAuthModule->pIM, OnNtfNeedAuth, &ntfNeedAuth); if(ntfNeedAuth.pvData) AMFree(ntfNeedAuth.pvData); return eAIM_RESULT_OK; }
AIM_RESULT OnRspGetDegree(AMVoid *pvArg, AIM_RSP_GET_DEGREE *pRspGetDegree) { IAIM *pIM = (IAIM*)(((AMPVoid*)pvArg)[1]); IAIMessage *pMsg = AMNULL; AMChar *pBuf = AMNULL; AMInt32 iLen = 0; AMAssert(AMNULL != pIM && AMNULL != pRspGetDegree); DPRINT("IASessionModel_OnGetDegree.........................Entering!\n"); pMsg = IAIMessage_Create(); if(pRspGetDegree->szContactId) IAIMessage_SetCntID(pMsg, pRspGetDegree->szContactId, AMStrlen(pRspGetDegree->szContactId)); if(0 == pRspGetDegree->iRetCode)//成功 { pMsg->eType = (AIM_MSG_TYPE)GET_DEGREE_OK; pBuf = (AMChar *)AMMalloc(MAX_INT_NUMBER_LEN*3); if(AMNULL == pBuf) { IAIMessage_Destroy(pMsg); return eAIM_RESULT_MALLOC_ERROR; } AMMemset(pBuf, 0, MAX_INT_NUMBER_LEN*3); iLen += _AIMItoa(pRspGetDegree->iUserLevel, pBuf); pBuf[iLen++] = ','; iLen += _AIMItoa(pRspGetDegree->iTotalDegree, pBuf+iLen); pBuf[iLen++] = ','; iLen += _AIMItoa(pRspGetDegree->iNeedDegree, pBuf+iLen); pMsg->szContent = pBuf; } else//失败 { DPRINT("IASessionModel_OnGetDegree.......................Fail!\n"); pMsg->eType = (AIM_MSG_TYPE)GET_DEGREE_FAIL; } DPRINT("IASessionModel_OnGetDegree.......................%s\n", pMsg->szContent); Adapter_OnIncomingSysMsg(pIM->pSesModel, pMsg, pvArg); IAIMessage_Destroy(pMsg); DPRINT("IASessionModel_OnGetDegree.........................OK!\n"); return eAIM_RESULT_OK; }
IAGroup * IAGroup_CreateProc(AMBool bLight) { IAGroup *pGrp = AMMalloc(sizeof(IAGroup)); AMAssert(0 != pGrp); AMMemset(pGrp, 0, sizeof(IAGroup)); if(!bLight) { construct(List, &pGrp->lChildCnt, sizeof(IAContact), NOFREE); set_compare(List, &pGrp->lChildCnt, IAContact_CmpPinyin); construct(List, &pGrp->lChildGrp, sizeof(IAGroup), NOFREE); set_compare(List, &pGrp->lChildGrp, IAGroup_CmpPinyin); } return pGrp; }
static AMChar *_genSession() { AMInt32 iGMTime = AMGetUpTime(AMNULL); AMChar *szSession = AMNULL; AMInt32 iUsed = 0, i = 0; szSession = (AMChar *)AMMalloc(LEN_SESSION + 1); if(!szSession) return AMNULL; AMMemset(szSession, 0, LEN_SESSION + 1); AMStrcpy(szSession, SESSION_PREFIX_AIM); iUsed = sizeof(SESSION_PREFIX_AIM) + _AIMItoa(iGMTime, szSession + sizeof(SESSION_PREFIX_AIM) - 1) -1; for(i=iUsed; i<LEN_SESSION; i++) szSession[i] = '0'; return szSession; }
IASession * IASession_Create(const AMChar *szContactID, IASessionModel *pSesModel) { IASession *pRet = 0; AMUInt32 ui = 0, uiLen = 0; AMAssert(0 != szContactID); pRet = (IASession*)AMMalloc(sizeof(IASession)); AMMemset(pRet, 0, sizeof(IASession)); uiLen = AMStrlen(szContactID); AMAssert(8 < uiLen); pRet->szContactID = (AMChar *)AMMalloc(uiLen + 1); for(ui = 0; ui < uiLen; ui++) pRet->szContactID[ui] = szContactID[ui]; pRet->szContactID[uiLen] = 0; pRet->pSesModel = pSesModel; return pRet; }
AMTask* AMTaskMgrRun(AMTaskMgr* taskMgr, AMTaskProc proc, AMPVoid procArg, AMTaskArgFree procFree) { _AMTaskMgr* _taskMgr = (_AMTaskMgr*)taskMgr; if(_taskMgr == AMNULL || proc == AMNULL) return AMNULL; else { _AMTask* newTask = AMNULL; AMThreadMutexLock(&_taskMgr->mMutex); //Create a new _AMTask. newTask = (_AMTask*)AMMalloc(sizeof(_AMTask)); if(newTask == AMNULL) { AMThreadMutexUnlock(&_taskMgr->mMutex); return AMNULL; } AMMemset(newTask, 0, sizeof(_AMTask)); newTask->mProc = proc; newTask->mProcArg = procArg; newTask->mProcFree = procFree; newTask->mId = _taskMgr->mNextTaskId++; newTask->mTaskMgr = _taskMgr; if(_taskMgr->mTasks == AMNULL) _taskMgr->mTasks = newTask; else { _AMTask* taskNode = _taskMgr->mTasks; while(taskNode->mNext != AMNULL) { taskNode = taskNode->mNext; } taskNode->mNext = newTask; } AMThreadMutexUnlock(&_taskMgr->mMutex); _AMRunTask(_taskMgr, AMFALSE); return (AMTask*)newTask; } }
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; }
IAccountModel* IAccountModel_Create() { if(0 == pSingleAcntModel) { DPRINT("IAccountModel_Create.................AcntModle Creating\n"); pSingleAcntModel = (IAccountModel *)AMMalloc(sizeof(IAccountModel)); AMAssert(0 != pSingleAcntModel); AMMemset(pSingleAcntModel, 0, sizeof(IAccountModel)); construct(List, &(pSingleAcntModel->listAcnt), sizeof(AIMAccount), FREEOBJ); set_compare(List, &(pSingleAcntModel->listAcnt), IAccount_cmpID); set_dealloc(List, &(pSingleAcntModel->listAcnt), IAccount_Destroy); IAccountModel_Restore(pSingleAcntModel); DPRINT("IAccountModel_Create.................AcntModle Created\n"); } pSingleAcntModel->iRefCount++; DPRINT("IAccountModel_Create.................Add Reference %d\n", pSingleAcntModel->iRefCount); return pSingleAcntModel; }
AMInt32 AIMAuthModule_create(IAIM *pIM, AMHandle *phAuthModule) { AIMAuthModule *pAuthModule = (AIMAuthModule *)AMMalloc(sizeof(AIMAuthModule)); if(!pAuthModule) return eAIM_RESULT_MALLOC_ERROR; AMMemset(pAuthModule, 0, sizeof(AIMAuthModule)); if(AMThreadMutexCreate(&pAuthModule->mtxAuth)) { AMFree(pAuthModule); return eAIM_RESULT_MALLOC_ERROR; } pAuthModule->pIM = pIM; construct(List, &pAuthModule->lstAuth, sizeof(AIMAuth), FREEOBJ); set_dealloc(List, &pAuthModule->lstAuth, _AIMAuth_destroy); *phAuthModule = pAuthModule; return eAIM_RESULT_OK; }
//这个方法是AMLooperRemoveHandler的辅助方法, 其它不能调用. void _AMLooperRemoveHandlerMsg(struct AMHandler* handler, List* list) { //AMLogForDebug("AMLooper", "_AMLooperRemoveHandlerMsg"); ListIter* message_iter; message_iter = create_ListIter(list); if(!head_ListIter(message_iter)) { do { struct AMMessage* msg = (struct AMMessage*)retrieve_ListIter(message_iter); if(msg->handler == handler || handler == NULL) { ListIter temp_message_iter; AMMemset(&temp_message_iter, 0, sizeof(ListIter)); copy_ListIter(&temp_message_iter, message_iter); if(!next_ListIter(message_iter)) { if(msg->cleanUp) msg->cleanUp(msg); //free(msg); extract_ListIter(&temp_message_iter); continue; } else { if(msg->cleanUp) msg->cleanUp(msg); //free(msg); extract_ListIter(&temp_message_iter); break; } } }while(!next_ListIter(message_iter)); } destroy_ListIter(message_iter); }
AMInt32 SigXML2SigStruct(const AMChar *szSigXML, AMHandle hSig) { int i = 0; AMChar *szBegin = AMNULL, *szEnd = AMNULL; AIM_SIGNATURE *pSig = (AIM_SIGNATURE*)hSig; AMAssert(0 != szSigXML && AMNULL != pSig); AMMemset(pSig, 0, sizeof(AIM_SIGNATURE)); szBegin = AMStrstr(szSigXML, HeadTag(XML_TAG_SIG)); i=0; while(AMNULL != szBegin && i<MAX_SIG_COUNT) { szBegin += sizeof(HeadTag(XML_TAG_SIG)) -1; szEnd = AMStrstr(szBegin, TailTag(XML_TAG_SIG)); if(AMNULL != szEnd) { if(szEnd-szBegin < MAX_SIG_LEN) { AMMemcpy(pSig->szSignature[i], szBegin, szEnd-szBegin); } szBegin = AMStrstr(szEnd, HeadTag(XML_TAG_SIG)); } else break; i++; } if(AMNULL == szEnd) szEnd = szSigXML; szBegin = AMStrstr(szEnd, HeadTag(XML_TAG_LOOP)); if(AMNULL != szBegin) pSig->iLoop = AMAtoi(szBegin + sizeof(HeadTag(XML_TAG_LOOP))-1); else szBegin = szSigXML; szBegin = AMStrstr(szBegin, HeadTag(XML_TAG_T)); if(AMNULL != szBegin) pSig->iT = AMAtoi(szBegin + sizeof(HeadTag(XML_TAG_T))-1); else szBegin = szSigXML; szBegin = AMStrstr(szBegin, HeadTag(XML_TAG_CI)); if(AMNULL != szBegin) pSig->iCI = AMAtoi(szBegin + sizeof(HeadTag(XML_TAG_CI))-1); else szBegin = szSigXML; szBegin = AMStrstr(szBegin, HeadTag(XML_TAG_ST)); if(AMNULL != szBegin) pSig->iST = AMAtoi(szBegin + sizeof(HeadTag(XML_TAG_ST))-1); else szBegin = szSigXML; szBegin = AMStrstr(szBegin, HeadTag(XML_TAG_RET)); if(AMNULL != szBegin) pSig->iRet = AMAtoi(szBegin + sizeof(HeadTag(XML_TAG_RET))-1); else szBegin = szSigXML; szBegin = AMStrstr(szBegin, HeadTag(XML_TAG_FLAG)); if(AMNULL != szBegin) pSig->iFlag = AMAtoi(szBegin + sizeof(HeadTag(XML_TAG_FLAG))-1); else szBegin = szSigXML; szBegin = AMStrstr(szBegin, HeadTag(XML_TAG_EMP)); if(AMNULL != szBegin) pSig->iEmp = AMAtoi(szBegin + sizeof(HeadTag(XML_TAG_EMP))-1); return 0; }
//本函数具有所有潜规则! 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; }
AIM_RESULT OnNtfUpdateContact(AMVoid *pArg, AIM_NTF_UPDATE_CONTACT *pNtfUpdateContact) { AIM_CONTACT_UPDATE_DATA *pPresent = 0; AMInt32 i=0; IAIM *pIM = (IAIM*)(((AMPVoid*)pArg)[1]); pPresent = (AIM_CONTACT_UPDATE_DATA*)AMMalloc(sizeof(AIM_CONTACT_UPDATE_DATA) * pNtfUpdateContact->iCount); AMMemset(pPresent, 0, sizeof(AIM_CONTACT_UPDATE_DATA) * pNtfUpdateContact->iCount); switch(pNtfUpdateContact->eType) { case eAIM_CONTACT_PRESENCE_FIRST: DPRINT("OnNtfUpdateContact..........................Presence First!\n"); for(i=0; i<pNtfUpdateContact->iCount; i++) { pPresent[i].ucType = eAIM_CONTACT_PRESENCE; IAIMContact_GetPresence(pNtfUpdateContact->phContacts[i], (AIM_PRESENCE*)&pPresent[i].ucStatus); } break; case eAIM_CONTACT_PRESENCE: DPRINT("OnNtfUpdateContact..........................Presence!\n"); for(i=0; i<pNtfUpdateContact->iCount; i++) { pPresent[i].iFlag = 1; pPresent[i].ucType = eAIM_CONTACT_PRESENCE; IAIMContact_GetPresence(pNtfUpdateContact->phContacts[i], (AIM_PRESENCE*)&pPresent[i].ucStatus); } break; case eAIM_CONTACT_SIGNATURE: DPRINT("OnNtfUpdateContact..........................Signature!\n"); for(i=0; i<pNtfUpdateContact->iCount; i++) { pPresent[i].iFlag = 1; pPresent[i].ucType = eAIM_CONTACT_SIGNATURE; IAIMContact_GetSignature(pNtfUpdateContact->phContacts[i], (const AMChar **)&pPresent[i].szSignature); } break; case eAIM_CONTACT_PORTRAIT: DPRINT("OnNtfUpdateContact..........................Portrait!\n"); #ifdef ALIM_SUPPORT_PORTRAIT_NOTIFY // notify the event for(i=0; i<pNtfUpdateContact->iCount; i++) { pPresent[i].iFlag = 1; pPresent[i].ucType = eAIM_CONTACT_PORTRAIT; } #else // get the portrait data. IAIMContact_GetID(pNtfUpdateContact->phContacts [0], (const AMChar **)&pPresent[0].szID); IAIM_GetPortrait(pIM, pPresent[0].szID); pNtfUpdateContact->iCount = 0;//如果是头像事件,则不向上发送了 #endif default: pNtfUpdateContact->iCount = 0; } for(i=0; i<pNtfUpdateContact->iCount; i++) { IAIMContact_GetID(pNtfUpdateContact->phContacts [i], (const AMChar **)&pPresent[i].szID); } if(pNtfUpdateContact->iCount) { JavaPreListener(pArg, pPresent, pNtfUpdateContact->iCount); } AMFree(pPresent); return eAIM_RESULT_OK; }