void CDropbox::SendToContact(MCONTACT hContact, const TCHAR *data) { if (hContact == GetDefaultContact()) { char *message = mir_utf8encodeT(data); AddEventToDb(hContact, EVENTTYPE_MESSAGE, DBEF_UTF, (DWORD)mir_strlen(message), (PBYTE)message); return; } const char *szProto = GetContactProto(hContact); if (db_get_b(hContact, szProto, "ChatRoom", 0) == TRUE) { ptrT tszChatRoom(db_get_tsa(hContact, szProto, "ChatRoomID")); GCDEST gcd = { szProto, tszChatRoom, GC_EVENT_SENDMESSAGE }; GCEVENT gce = { sizeof(gce), &gcd }; gce.bIsMe = TRUE; gce.dwFlags = GCEF_ADDTOLOG; gce.ptszText = mir_tstrdup(data); gce.time = time(NULL); CallServiceSync(MS_GC_EVENT, WINDOW_VISIBLE, (LPARAM)&gce); mir_free((void*)gce.ptszText); return; } char *message = mir_utf8encodeT(data); if (CallContactService(hContact, PSS_MESSAGE, 0, (LPARAM)message) != ACKRESULT_FAILED) AddEventToDb(hContact, EVENTTYPE_MESSAGE, DBEF_UTF | DBEF_SENT, (DWORD)mir_strlen(message), (PBYTE)message); }
int CSkypeProto::RecvContacts(MCONTACT hContact, PROTORECVEVENT* pre) { PROTOSEARCHRESULT **isrList = (PROTOSEARCHRESULT**)pre->szMessage; DWORD cbBlob = 0; BYTE *pBlob; BYTE *pCurBlob; int i; int nCount = *((LPARAM*)pre->lParam); char* szMessageId = ((char*)pre->lParam + sizeof(LPARAM)); //if (GetMessageFromDb(hContact, szMessageId, pre->timestamp)) return 0; for (i = 0; i < nCount; i++) cbBlob += int(/*mir_tstrlen(isrList[i]->nick.t)*/0 + 2 + mir_tstrlen(isrList[i]->id.t) + mir_strlen(szMessageId)); pBlob = (PBYTE)mir_calloc(cbBlob); for (i = 0, pCurBlob = pBlob; i < nCount; i++) { //mir_strcpy((char*)pCurBlob, _T2A(isrList[i]->nick.t)); pCurBlob += mir_strlen((PCHAR)pCurBlob) + 1; mir_strcpy((char*)pCurBlob, _T2A(isrList[i]->id.t)); pCurBlob += mir_strlen((char*)pCurBlob) + 1; } //memcpy(pCurBlob + 1, szMessageId, mir_strlen(szMessageId)); AddEventToDb(hContact, EVENTTYPE_CONTACTS, pre->timestamp, (pre->flags & PREF_CREATEREAD) ? DBEF_READ : 0, cbBlob, pBlob); mir_free(pBlob); return 0; }
MEVENT CSkypeProto::AddDbEvent(WORD type, MCONTACT hContact, DWORD timestamp, DWORD flags, const char *content, const char *uid) { if (MEVENT hDbEvent = GetMessageFromDb(hContact, uid, timestamp)) return hDbEvent; size_t messageLength = mir_strlen(content) + 1; size_t messageIdLength = mir_strlen(uid); size_t cbBlob = messageLength + messageIdLength; PBYTE pBlob = (PBYTE)mir_alloc(cbBlob); memcpy(pBlob, content, messageLength); memcpy(pBlob + messageLength, uid, messageIdLength); return AddEventToDb(hContact, type, timestamp, flags, (DWORD)cbBlob, pBlob); }