summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--protocols/Tox/src/tox_contacts.cpp138
-rw-r--r--protocols/Tox/src/tox_core.cpp15
-rw-r--r--protocols/Tox/src/tox_network.cpp4
-rw-r--r--protocols/Tox/src/tox_options.cpp4
4 files changed, 90 insertions, 71 deletions
diff --git a/protocols/Tox/src/tox_contacts.cpp b/protocols/Tox/src/tox_contacts.cpp
index fc1727aaac..5678869b52 100644
--- a/protocols/Tox/src/tox_contacts.cpp
+++ b/protocols/Tox/src/tox_contacts.cpp
@@ -39,6 +39,9 @@ MCONTACT CToxProto::GetContactFromAuthEvent(MEVENT hEvent)
MCONTACT CToxProto::GetContact(const int friendNumber)
{
+ if (!toxThread)
+ return NULL;
+
uint8_t data[TOX_PUBLIC_KEY_SIZE];
TOX_ERR_FRIEND_GET_PUBLIC_KEY error;
if (!tox_friend_get_public_key(toxThread->Tox(), friendNumber, data, &error))
@@ -79,32 +82,33 @@ ToxHexAddress CToxProto::GetContactPublicKey(const int friendNumber)
MCONTACT CToxProto::AddContact(const char *address, const char *nick, const char *dnsId, bool isTemporary)
{
MCONTACT hContact = GetContact(address);
- if (!hContact)
- {
- hContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0);
- Proto_AddToContact(hContact, m_szModuleName);
-
- setString(hContact, TOX_SETTINGS_ID, address);
+ if (hContact)
+ return hContact;
- if (mir_strlen(nick))
- setTString(hContact, "Nick", ptrT(mir_utf8decodeT(nick)));
+ hContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0);
+ Proto_AddToContact(hContact, m_szModuleName);
- if (mir_strlen(dnsId))
- setTString(hContact, TOX_SETTINGS_DNS, ptrT(mir_utf8decodeT(dnsId)));
+ setString(hContact, TOX_SETTINGS_ID, address);
- DBVARIANT dbv;
- if (!getTString(TOX_SETTINGS_GROUP, &dbv))
- {
- db_set_ts(hContact, "CList", "Group", dbv.ptszVal);
- db_free(&dbv);
- }
+ if (mir_strlen(nick))
+ setTString(hContact, "Nick", ptrT(mir_utf8decodeT(nick)));
- setByte(hContact, "Auth", 1);
- setByte(hContact, "Grant", 1);
+ if (mir_strlen(dnsId))
+ setTString(hContact, TOX_SETTINGS_DNS, ptrT(mir_utf8decodeT(dnsId)));
- if (isTemporary)
- db_set_b(hContact, "CList", "NotOnList", 1);
+ DBVARIANT dbv;
+ if (!getTString(TOX_SETTINGS_GROUP, &dbv))
+ {
+ db_set_ts(hContact, "CList", "Group", dbv.ptszVal);
+ db_free(&dbv);
}
+
+ setByte(hContact, "Auth", 1);
+ setByte(hContact, "Grant", 1);
+
+ if (isTemporary)
+ db_set_b(hContact, "CList", "NotOnList", 1);
+
return hContact;
}
@@ -322,63 +326,63 @@ void CToxProto::OnConnectionStatusChanged(Tox*, uint32_t friendNumber, TOX_CONNE
CToxProto *proto = (CToxProto*)arg;
MCONTACT hContact = proto->GetContact(friendNumber);
- if (hContact)
+ if (!hContact)
+ return;
+
+ if (status != TOX_CONNECTION_NONE)
{
- if (status != TOX_CONNECTION_NONE)
- {
- proto->delSetting(hContact, "Auth");
- proto->delSetting(hContact, "Grant");
+ proto->delSetting(hContact, "Auth");
+ proto->delSetting(hContact, "Grant");
- // resume incoming transfers
- proto->ResumeIncomingTransfers(friendNumber);
+ // resume incoming transfers
+ proto->ResumeIncomingTransfers(friendNumber);
- // update avatar
- ptrT avatarPath(proto->GetAvatarFilePath());
- if (IsFileExists(avatarPath))
+ // update avatar
+ ptrT avatarPath(proto->GetAvatarFilePath());
+ if (IsFileExists(avatarPath))
+ {
+ FILE *hFile = _tfopen(avatarPath, L"rb");
+ if (!hFile)
{
- FILE *hFile = _tfopen(avatarPath, L"rb");
- if (!hFile)
- {
- Netlib_Logf(proto->m_hNetlibUser, __FUNCTION__": failed to open avatar file");
- return;
- }
+ Netlib_Logf(proto->m_hNetlibUser, __FUNCTION__": failed to open avatar file");
+ return;
+ }
- fseek(hFile, 0, SEEK_END);
- size_t length = ftell(hFile);
- rewind(hFile);
+ fseek(hFile, 0, SEEK_END);
+ size_t length = ftell(hFile);
+ rewind(hFile);
- uint8_t hash[TOX_HASH_LENGTH];
- DBVARIANT dbv;
- if (!db_get(NULL, proto->m_szModuleName, TOX_SETTINGS_AVATAR_HASH, &dbv))
- {
- memcpy(hash, dbv.pbVal, TOX_HASH_LENGTH);
- db_free(&dbv);
- }
-
- TOX_ERR_FILE_SEND error;
- uint32_t fileNumber = tox_file_send(proto->toxThread->Tox(), friendNumber, TOX_FILE_KIND_AVATAR, length, hash, NULL, 0, &error);
- if (error != TOX_ERR_FILE_SEND_OK)
- {
- Netlib_Logf(proto->m_hNetlibUser, __FUNCTION__": failed to set new avatar");
- fclose(hFile);
- return;
- }
+ uint8_t hash[TOX_HASH_LENGTH];
+ DBVARIANT dbv;
+ if (!db_get(NULL, proto->m_szModuleName, TOX_SETTINGS_AVATAR_HASH, &dbv))
+ {
+ memcpy(hash, dbv.pbVal, TOX_HASH_LENGTH);
+ db_free(&dbv);
+ }
- AvatarTransferParam *transfer = new AvatarTransferParam(friendNumber, fileNumber, NULL, length);
- transfer->pfts.flags |= PFTS_SENDING;
- memcpy(transfer->hash, hash, TOX_HASH_LENGTH);
- transfer->pfts.hContact = hContact;
- transfer->hFile = hFile;
- proto->transfers.Add(transfer);
+ TOX_ERR_FILE_SEND error;
+ uint32_t fileNumber = tox_file_send(proto->toxThread->Tox(), friendNumber, TOX_FILE_KIND_AVATAR, length, hash, NULL, 0, &error);
+ if (error != TOX_ERR_FILE_SEND_OK)
+ {
+ Netlib_Logf(proto->m_hNetlibUser, __FUNCTION__": failed to set new avatar");
+ fclose(hFile);
+ return;
}
- else
- tox_file_send(proto->toxThread->Tox(), friendNumber, TOX_FILE_KIND_AVATAR, 0, NULL, NULL, 0, NULL);
+
+ AvatarTransferParam *transfer = new AvatarTransferParam(friendNumber, fileNumber, NULL, length);
+ transfer->pfts.flags |= PFTS_SENDING;
+ memcpy(transfer->hash, hash, TOX_HASH_LENGTH);
+ transfer->pfts.hContact = hContact;
+ transfer->hFile = hFile;
+ proto->transfers.Add(transfer);
}
else
- {
- proto->SetContactStatus(hContact, ID_STATUS_OFFLINE);
- proto->setDword(hContact, "LastEventDateTS", time(NULL));
- }
+ tox_file_send(proto->toxThread->Tox(), friendNumber, TOX_FILE_KIND_AVATAR, 0, NULL, NULL, 0, NULL);
+ }
+ else
+ {
+ proto->SetContactStatus(hContact, ID_STATUS_OFFLINE);
+ proto->setDword(hContact, "LastEventDateTS", time(NULL));
}
}
diff --git a/protocols/Tox/src/tox_core.cpp b/protocols/Tox/src/tox_core.cpp
index 838edd6a1a..0188265f18 100644
--- a/protocols/Tox/src/tox_core.cpp
+++ b/protocols/Tox/src/tox_core.cpp
@@ -109,4 +109,19 @@ void CToxProto::UninitToxCore(CToxThread *toxThread)
CancelAllTransfers(toxThread);
SaveToxProfile(toxThread);
+
+ tox_callback_friend_request(toxThread->Tox(), OnFriendRequest, NULL);
+ tox_callback_friend_message(toxThread->Tox(), OnFriendMessage, NULL);
+ tox_callback_friend_read_receipt(toxThread->Tox(), OnReadReceipt, NULL);
+ tox_callback_friend_typing(toxThread->Tox(), OnTypingChanged, NULL);
+ //
+ tox_callback_friend_name(toxThread->Tox(), OnFriendNameChange, NULL);
+ tox_callback_friend_status_message(toxThread->Tox(), OnStatusMessageChanged, NULL);
+ tox_callback_friend_status(toxThread->Tox(), OnUserStatusChanged, NULL);
+ tox_callback_friend_connection_status(toxThread->Tox(), OnConnectionStatusChanged, NULL);
+ // transfers
+ tox_callback_file_recv_control(toxThread->Tox(), OnFileRequest, NULL);
+ tox_callback_file_recv(toxThread->Tox(), OnFriendFile, NULL);
+ tox_callback_file_recv_chunk(toxThread->Tox(), OnDataReceiving, NULL);
+ tox_callback_file_chunk_request(toxThread->Tox(), OnFileSendData, NULL);
} \ No newline at end of file
diff --git a/protocols/Tox/src/tox_network.cpp b/protocols/Tox/src/tox_network.cpp
index 13182139f1..bf5e54ccc2 100644
--- a/protocols/Tox/src/tox_network.cpp
+++ b/protocols/Tox/src/tox_network.cpp
@@ -289,10 +289,10 @@ void CToxProto::PollingThread(void*)
toxThread.Iterate();
}
- this->toxThread = NULL;
-
toxThread.Disconnect();
UninitToxCore(&toxThread);
+ this->toxThread = NULL;
+
debugLogA(__FUNCTION__": leaving");
} \ No newline at end of file
diff --git a/protocols/Tox/src/tox_options.cpp b/protocols/Tox/src/tox_options.cpp
index f65f575c50..651cecf377 100644
--- a/protocols/Tox/src/tox_options.cpp
+++ b/protocols/Tox/src/tox_options.cpp
@@ -650,9 +650,9 @@ int CToxProto::OnOptionsInit(WPARAM wParam, LPARAM)
odp.pDialog = CToxOptionsMain::CreateOptionsPage(this);
Options_AddPage(wParam, &odp);
- odp.ptszTab = LPGENT("Multimedia");
+ /*odp.ptszTab = LPGENT("Multimedia");
odp.pDialog = CToxOptionsMultimedia::CreateOptionsPage(this);
- Options_AddPage(wParam, &odp);
+ Options_AddPage(wParam, &odp);*/
odp.ptszTab = LPGENT("Nodes");
odp.pDialog = CToxOptionsNodeList::CreateOptionsPage(this);