summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--protocols/Tox/src/common.h3
-rw-r--r--protocols/Tox/src/tox_contacts.cpp50
-rw-r--r--protocols/Tox/src/tox_events.cpp2
-rw-r--r--protocols/Tox/src/tox_options.cpp6
-rw-r--r--protocols/Tox/src/tox_proto.cpp84
-rw-r--r--protocols/Tox/src/tox_proto.h9
6 files changed, 72 insertions, 82 deletions
diff --git a/protocols/Tox/src/common.h b/protocols/Tox/src/common.h
index d9bc42d4ce..8833a1f517 100644
--- a/protocols/Tox/src/common.h
+++ b/protocols/Tox/src/common.h
@@ -29,6 +29,7 @@
extern HINSTANCE g_hInstance;
-#define TOX_SETTING_ID "ToxID"
+#define TOX_SETTINGS_ID "ToxID"
+#define TOX_SETTINGS_DEFAULT_GROUP "DefaultGroup"
#endif //_COMMON_H_ \ No newline at end of file
diff --git a/protocols/Tox/src/tox_contacts.cpp b/protocols/Tox/src/tox_contacts.cpp
index 3ae3cf9f21..c0c9335d63 100644
--- a/protocols/Tox/src/tox_contacts.cpp
+++ b/protocols/Tox/src/tox_contacts.cpp
@@ -50,7 +50,7 @@ MCONTACT CToxProto::FindContact(const char *clientId)
for (hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName))
{
- ptrA contactId(getStringA(hContact, TOX_SETTING_ID));
+ ptrA contactId(getStringA(hContact, TOX_SETTINGS_ID));
if (lstrcmpiA(contactId, clientId) == 0)
break;
}
@@ -60,22 +60,28 @@ MCONTACT CToxProto::FindContact(const char *clientId)
return hContact;
}
-MCONTACT CToxProto::AddContact(const char *clientId, bool isHidden)
+MCONTACT CToxProto::AddContact(const char *clientId, bool isTemporary)
{
MCONTACT hContact = FindContact(clientId);
if (!hContact)
{
- hContact = (MCONTACT)::CallService(MS_DB_CONTACT_ADD, 0, 0);
+ hContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0);
CallService(MS_PROTO_ADDTOCONTACT, hContact, (LPARAM)m_szModuleName);
- /*db_set_b(hContact, "CList", "NotOnList", 1);
-
- if (isHidden)
+ if (isTemporary)
{
- db_set_b(hContact, "CList", "Hidden", 1);
- }*/
+ db_set_b(hContact, "CList", "NotOnList", 1);
+ db_set_b(hContact, "CList", "Auth", 1);
+ }
- setString(hContact, TOX_SETTING_ID, clientId);
+ setString(hContact, TOX_SETTINGS_ID, clientId);
+
+ DBVARIANT dbv;
+ if (!getTString(TOX_SETTINGS_DEFAULT_GROUP, &dbv))
+ {
+ db_set_ts(hContact, "CList", "Group", dbv.ptszVal);
+ db_free(&dbv);
+ }
}
return hContact;
@@ -108,30 +114,4 @@ void CToxProto::LoadContactList()
}
}
}
-}
-
-void __cdecl CToxProto::SearchByUidAsync(void* arg)
-{
- ptrW userId((wchar_t*)arg);
-
- //MCONTACT hContact = GetContactByUserId(userId);
- //if (hContact)
- //{
- // ShowNotification(TranslateT("Contact already in your contact list"), 0, hContact);
- // ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)TOX_SEARCH_BYUID, 0);
- // return;
- //}
-
- //// there will be placed code
- //// that will search for contact by userId
- // ...
- // ...
- //// and call
- PROTOSEARCHRESULT psr = {0};
- psr.cbSize = sizeof(psr);
- //// get user id [and nick]
- //psr.id = userId;
- //psr.nick = nick;
-
- ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)TOX_SEARCH_BYUID, (LPARAM)&psr);
} \ No newline at end of file
diff --git a/protocols/Tox/src/tox_events.cpp b/protocols/Tox/src/tox_events.cpp
index 6007530666..8283e80c6a 100644
--- a/protocols/Tox/src/tox_events.cpp
+++ b/protocols/Tox/src/tox_events.cpp
@@ -45,7 +45,7 @@ INT_PTR CToxProto::OnContactDeleted(WPARAM wParam, LPARAM)
MCONTACT hContact = (MCONTACT)wParam;
if (hContact)
{
- std::string toxId(getStringA(hContact, TOX_SETTING_ID));
+ std::string toxId(getStringA(hContact, TOX_SETTINGS_ID));
std::vector<uint8_t> clientId = HexStringToData(toxId);
uint32_t number = tox_get_friend_number(tox, clientId.data());
diff --git a/protocols/Tox/src/tox_options.cpp b/protocols/Tox/src/tox_options.cpp
index 7f5fd47824..f4eb2e6e5d 100644
--- a/protocols/Tox/src/tox_options.cpp
+++ b/protocols/Tox/src/tox_options.cpp
@@ -24,7 +24,7 @@ INT_PTR CALLBACK CToxProto::MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam,
}
SetDlgItemTextA(hwnd, IDC_DATAPATH, dataPath);
- ptrW groupName(proto->getWStringA(NULL, "DefaultGroup"));
+ ptrW groupName(proto->getTStringA(TOX_SETTINGS_DEFAULT_GROUP));
SetDlgItemText(hwnd, IDC_GROUP, groupName);
SendDlgItemMessage(hwnd, IDC_GROUP, EM_LIMITTEXT, 64, 0);
@@ -116,11 +116,11 @@ INT_PTR CALLBACK CToxProto::MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam,
GetDlgItemText(hwnd, IDC_GROUP, groupName, SIZEOF(groupName));
if (lstrlen(groupName) > 0)
{
- proto->setWString(NULL, "DefaultGroup", groupName);
+ proto->setWString(NULL, TOX_SETTINGS_DEFAULT_GROUP, groupName);
Clist_CreateGroup(0, groupName);
}
else
- proto->delSetting(NULL, "DefaultGroup");
+ proto->delSetting(NULL, TOX_SETTINGS_DEFAULT_GROUP);
return TRUE;
}
diff --git a/protocols/Tox/src/tox_proto.cpp b/protocols/Tox/src/tox_proto.cpp
index 87e0149f41..a5e32c810f 100644
--- a/protocols/Tox/src/tox_proto.cpp
+++ b/protocols/Tox/src/tox_proto.cpp
@@ -38,11 +38,30 @@ CToxProto::~CToxProto()
tox_kill(tox);
}
-MCONTACT __cdecl CToxProto::AddToList(int flags, PROTOSEARCHRESULT* psr)
+DWORD_PTR __cdecl CToxProto::GetCaps(int type, MCONTACT hContact)
{
-// MCONTACT hContact = AddContact(psr->id, psr->nick);
+ switch (type)
+ {
+ case PFLAGNUM_1:
+ return PF1_IM | PF1_AUTHREQ | PF1_BASICSEARCH;
+ case PFLAGNUM_2:
+ return PF2_ONLINE | PF2_SHORTAWAY | PF2_LIGHTDND;
+ case PFLAGNUM_4:
+ return PF4_IMSENDUTF | PF4_NOAUTHDENYREASON | PF4_FORCEAUTH | PF4_FORCEADDED;
+ case PFLAG_UNIQUEIDTEXT:
+ return (INT_PTR)"Tox ID";
+ case PFLAG_UNIQUEIDSETTING:
+ return (DWORD_PTR)TOX_SETTINGS_ID;
+ case PFLAG_MAXLENOFMESSAGE:
+ return TOX_MAX_MESSAGE_LENGTH;
+ }
- return NULL;
+ return 0;
+}
+
+MCONTACT __cdecl CToxProto::AddToList(int flags, PROTOSEARCHRESULT* psr)
+{
+ return AddContact(_T2A(psr->id));
}
MCONTACT __cdecl CToxProto::AddToListByEvent(int flags, int iContact, HANDLE hDbEvent) { return 0; }
@@ -55,7 +74,7 @@ int __cdecl CToxProto::Authorize(HANDLE hDbEvent)
if (hContact == INVALID_CONTACT_ID)
return 1;
- std::string toxId = getStringA(hContact, TOX_SETTING_ID);
+ std::string toxId = getStringA(hContact, TOX_SETTINGS_ID);
std::vector<uint8_t> clientId = HexStringToData(toxId);
if (tox_add_friend_norequest(tox, &clientId[0]) >= 0)
@@ -69,45 +88,42 @@ int __cdecl CToxProto::Authorize(HANDLE hDbEvent)
int __cdecl CToxProto::AuthDeny(HANDLE hDbEvent, const PROTOCHAR* szReason) { return 0; }
int __cdecl CToxProto::AuthRecv(MCONTACT hContact, PROTORECVEVENT*) { return 0; }
-int __cdecl CToxProto::AuthRequest(MCONTACT hContact, const PROTOCHAR* szMessage) { return 0; }
-HANDLE __cdecl CToxProto::ChangeInfo(int iInfoType, void* pInfoData) { return 0; }
+int __cdecl CToxProto::AuthRequest(MCONTACT hContact, const PROTOCHAR* szMessage)
+{
+ std::string toxId = getStringA(hContact, TOX_SETTINGS_ID);
+ std::vector<uint8_t> clientId = HexStringToData(toxId);
-HANDLE __cdecl CToxProto::FileAllow(MCONTACT hContact, HANDLE hTransfer, const PROTOCHAR* szPath) { return 0; }
-int __cdecl CToxProto::FileCancel(MCONTACT hContact, HANDLE hTransfer) { return 0; }
-int __cdecl CToxProto::FileDeny(MCONTACT hContact, HANDLE hTransfer, const PROTOCHAR* szReason) { return 0; }
-int __cdecl CToxProto::FileResume(HANDLE hTransfer, int* action, const PROTOCHAR** szFilename) { return 0; }
+ ptrA reason(mir_utf8encodeW(szMessage));
-DWORD_PTR __cdecl CToxProto::GetCaps(int type, MCONTACT hContact)
-{
- switch(type)
+ int32_t friendnumber = tox_add_friend(tox, &clientId[0], (uint8_t*)(char*)reason, strlen(reason));
+ if (friendnumber >= 0)
{
- case PFLAGNUM_1:
- return PF1_IM | PF1_AUTHREQ | PF1_BASICSEARCH;
- case PFLAGNUM_2:
- return PF2_ONLINE | PF2_SHORTAWAY | PF2_LIGHTDND;
- case PFLAGNUM_4:
- return PF4_IMSENDUTF | PF4_NOAUTHDENYREASON;
- case PFLAG_UNIQUEIDTEXT:
- return (INT_PTR)"Tox ID";
- case PFLAG_UNIQUEIDSETTING:
- return (DWORD_PTR)TOX_SETTING_ID;
- case PFLAG_MAXLENOFMESSAGE:
- return TOX_MAX_MESSAGE_LENGTH;
+ clientId.resize(TOX_CLIENT_ID_SIZE);
+ tox_get_client_id(tox, friendnumber, &clientId[0]);
+ std::string toxId = DataToHexString(clientId);
+
+ setString(hContact, TOX_SETTINGS_ID, toxId.c_str());
+
+ db_unset(hContact, "CList", "NotOnList");
+ db_unset(hContact, "CList", "Auth");
+
+ return 0;
}
- return 0;
+ return 1;
}
-int __cdecl CToxProto::GetInfo(MCONTACT hContact, int infoType) { return 0; }
-HANDLE __cdecl CToxProto::SearchBasic(const PROTOCHAR* id)
-{
- //if ( !IsOnline()) return 0;
+HANDLE __cdecl CToxProto::ChangeInfo(int iInfoType, void* pInfoData) { return 0; }
- this->ForkThread(&CToxProto::SearchByUidAsync, (void*)id);
+HANDLE __cdecl CToxProto::FileAllow(MCONTACT hContact, HANDLE hTransfer, const PROTOCHAR* szPath) { return 0; }
+int __cdecl CToxProto::FileCancel(MCONTACT hContact, HANDLE hTransfer) { return 0; }
+int __cdecl CToxProto::FileDeny(MCONTACT hContact, HANDLE hTransfer, const PROTOCHAR* szReason) { return 0; }
+int __cdecl CToxProto::FileResume(HANDLE hTransfer, int* action, const PROTOCHAR** szFilename) { return 0; }
- return (HANDLE)TOX_SEARCH_BYUID;
-}
+int __cdecl CToxProto::GetInfo(MCONTACT hContact, int infoType) { return 0; }
+
+HANDLE __cdecl CToxProto::SearchBasic(const PROTOCHAR* id) { return 0; }
HANDLE __cdecl CToxProto::SearchByEmail(const PROTOCHAR* email) { return 0; }
HANDLE __cdecl CToxProto::SearchByName(const PROTOCHAR* nick, const PROTOCHAR* firstName, const PROTOCHAR* lastName) { return 0; }
@@ -132,7 +148,7 @@ int __cdecl CToxProto::SendMsg(MCONTACT hContact, int flags, const char* msg)
return 1;
}
- std::string toxId(getStringA(hContact, TOX_SETTING_ID));
+ std::string toxId(getStringA(hContact, TOX_SETTINGS_ID));
std::vector<uint8_t> clientId = HexStringToData(toxId);
uint32_t number = tox_get_friend_number(tox, clientId.data());
diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h
index 8c31e30d64..c61555c408 100644
--- a/protocols/Tox/src/tox_proto.h
+++ b/protocols/Tox/src/tox_proto.h
@@ -3,8 +3,6 @@
#include "common.h"
-#define TOX_SEARCH_BYUID 1001
-
struct CToxProto : public PROTO<CToxProto>
{
public:
@@ -113,14 +111,12 @@ private:
void SetAllContactsStatus(WORD status);
bool IsProtoContact(MCONTACT hContact);
MCONTACT FindContact(const char *clientId);
- MCONTACT AddContact(const char *clientId, bool isHidden = false);
+ MCONTACT AddContact(const char *clientId, bool isTemporary = false);
MCONTACT GetContactFromAuthEvent(HANDLE hEvent);
void LoadContactList();
- void __cdecl SearchByUidAsync(void* arg);
-
//services
@@ -138,9 +134,6 @@ private:
int LoadToxData(const char *path);
int SaveToxData(const char *path);
- static void fraddr_to_str(uint8_t *id_bin, char *id_str);
- static void get_id(Tox *m, char *data);
-
// dialogs
static INT_PTR CALLBACK MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
};