summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2014-08-12 19:29:57 +0000
committerAlexander Lantsev <aunsane@gmail.com>2014-08-12 19:29:57 +0000
commit79f5521815e208cb694bbc814ee88429e20328b6 (patch)
tree62f552526e0626aa55285684f0fe12081a91349c /protocols
parent4e5548a98703325099017bf6bf04b2fb5edefbd4 (diff)
Tox: getting friend request
git-svn-id: http://svn.miranda-ng.org/main/trunk@10170 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r--protocols/Tox/src/tox_contacts.cpp20
-rw-r--r--protocols/Tox/src/tox_events.cpp6
-rw-r--r--protocols/Tox/src/tox_proto.cpp25
-rw-r--r--protocols/Tox/src/tox_proto.h3
-rw-r--r--protocols/Tox/src/tox_utils.cpp61
5 files changed, 77 insertions, 38 deletions
diff --git a/protocols/Tox/src/tox_contacts.cpp b/protocols/Tox/src/tox_contacts.cpp
index 788105b0d4..1fd99bc36e 100644
--- a/protocols/Tox/src/tox_contacts.cpp
+++ b/protocols/Tox/src/tox_contacts.cpp
@@ -17,6 +17,26 @@ void CToxProto::SetAllContactsStatus(WORD status)
}
}
+MCONTACT CToxProto::GetContactFromAuthEvent(HANDLE hEvent)
+{
+ DWORD body[3];
+ DBEVENTINFO dbei = { sizeof(DBEVENTINFO) };
+ dbei.cbBlob = sizeof(DWORD)* 2;
+ dbei.pBlob = (PBYTE)&body;
+
+ if (::db_event_get(hEvent, &dbei))
+ return INVALID_CONTACT_ID;
+
+ if (dbei.eventType != EVENTTYPE_AUTHREQUEST)
+ return INVALID_CONTACT_ID;
+
+ if (strcmp(dbei.szModule, m_szModuleName) != 0)
+ return INVALID_CONTACT_ID;
+
+ return DbGetAuthEventContact(&dbei);
+}
+
+
bool CToxProto::IsProtoContact(MCONTACT hContact)
{
return lstrcmpiA(GetContactProto(hContact), m_szModuleName) == 0;
diff --git a/protocols/Tox/src/tox_events.cpp b/protocols/Tox/src/tox_events.cpp
index c34e8078fb..ebc189aeba 100644
--- a/protocols/Tox/src/tox_events.cpp
+++ b/protocols/Tox/src/tox_events.cpp
@@ -42,6 +42,12 @@ int CToxProto::OnOptionsInit(void *obj, WPARAM wParam, LPARAM lParam)
void CToxProto::OnFriendRequest(Tox *tox, const uint8_t *userId, const uint8_t *message, const uint16_t messageSize, void *arg)
{
+ CToxProto *proto = (CToxProto*)arg;
+
+ std::vector<uint8_t> clientId(userId, userId + TOX_CLIENT_ID_SIZE);
+ std::string toxId = proto->DataToHexString(clientId);
+
+ proto->RaiseAuthRequestEvent(time(NULL), toxId.c_str(), (char*)message);
}
void CToxProto::OnFriendMessage(Tox *tox, const int friendnumber, const uint8_t *message, const uint16_t messageSize, void *arg)
diff --git a/protocols/Tox/src/tox_proto.cpp b/protocols/Tox/src/tox_proto.cpp
index ee4c60b917..9029c54a16 100644
--- a/protocols/Tox/src/tox_proto.cpp
+++ b/protocols/Tox/src/tox_proto.cpp
@@ -47,7 +47,26 @@ MCONTACT __cdecl CToxProto::AddToList(int flags, PROTOSEARCHRESULT* psr)
MCONTACT __cdecl CToxProto::AddToListByEvent(int flags, int iContact, HANDLE hDbEvent) { return 0; }
-int __cdecl CToxProto::Authorize(HANDLE hDbEvent) { return 0; }
+int __cdecl CToxProto::Authorize(HANDLE hDbEvent)
+{
+ if (this->IsOnline() && hDbEvent)
+ {
+ MCONTACT hContact = GetContactFromAuthEvent(hDbEvent);
+ if (hContact == INVALID_CONTACT_ID)
+ return 1;
+
+ std::string toxId = getStringA(hContact, TOX_SETTING_ID);
+ std::vector<uint8_t> clientId = HexStringToData(toxId);
+
+ if (tox_add_friend_norequest(tox, &clientId[0]) >= 0)
+ {
+ return 0;
+ }
+ }
+
+ return 1;
+}
+
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; }
@@ -64,11 +83,11 @@ DWORD_PTR __cdecl CToxProto::GetCaps(int type, MCONTACT hContact)
switch(type)
{
case PFLAGNUM_1:
- return PF1_IM | PF1_AUTHREQ | PF1_BASICSEARCH | PF1_ADDSEARCHRES;
+ return PF1_IM | PF1_AUTHREQ;
case PFLAGNUM_2:
return PF2_ONLINE | PF2_SHORTAWAY | PF2_LIGHTDND;
case PFLAGNUM_4:
- return PF4_IMSENDUTF | PF4_SUPPORTTYPING;
+ return PF4_IMSENDUTF | PF4_NOAUTHDENYREASON;
case PFLAG_UNIQUEIDTEXT:
return (INT_PTR)"Tox ID";
case PFLAG_UNIQUEIDSETTING:
diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h
index 53c1c3bf7d..f8db0371db 100644
--- a/protocols/Tox/src/tox_proto.h
+++ b/protocols/Tox/src/tox_proto.h
@@ -113,6 +113,8 @@ private:
MCONTACT FindContact(const char *clientId);
MCONTACT AddContact(const char *clientId, bool isHidden = false);
+ MCONTACT GetContactFromAuthEvent(HANDLE hEvent);
+
void LoadContactList();
void __cdecl SearchByUidAsync(void* arg);
@@ -126,6 +128,7 @@ private:
int ToxToMirandaStatus(TOX_USERSTATUS userstatus);
HANDLE AddDbEvent(MCONTACT hContact, WORD type, DWORD timestamp, DWORD flags, DWORD cbBlob, PBYTE pBlob);
+ void RaiseAuthRequestEvent(DWORD timestamp, const char* toxId, const char* reason);
std::vector<uint8_t> HexStringToData(std::string hex);
std::string DataToHexString(std::vector<uint8_t>);
diff --git a/protocols/Tox/src/tox_utils.cpp b/protocols/Tox/src/tox_utils.cpp
index 4876b7e9fd..95743b9412 100644
--- a/protocols/Tox/src/tox_utils.cpp
+++ b/protocols/Tox/src/tox_utils.cpp
@@ -55,6 +55,32 @@ HANDLE CToxProto::AddDbEvent(MCONTACT hContact, WORD type, DWORD timestamp, DWOR
return db_event_add(hContact, &dbei);
}
+void CToxProto::RaiseAuthRequestEvent(DWORD timestamp, const char* toxId, const char* reason)
+{
+ MCONTACT hContact = this->AddContact(toxId);
+
+ /*blob is: 0(DWORD), hContact(DWORD), nick(ASCIIZ), firstName(ASCIIZ), lastName(ASCIIZ), sid(ASCIIZ), reason(ASCIIZ)*/
+ DWORD cbBlob = (DWORD)
+ (sizeof(DWORD) * 2 +
+ strlen(toxId) +
+ strlen(reason) +
+ 5);
+
+ PBYTE pBlob, pCurBlob;
+ pCurBlob = pBlob = (PBYTE)mir_calloc(cbBlob);
+
+ *((PDWORD)pCurBlob) = 0;
+ pCurBlob += sizeof(DWORD);
+ *((PDWORD)pCurBlob) = (DWORD)hContact;
+ pCurBlob += sizeof(DWORD);
+ pCurBlob += 3;
+ strcpy((char *)pCurBlob, toxId);
+ pCurBlob += strlen(toxId) + 1;
+ strcpy((char *)pCurBlob, reason);
+
+ AddDbEvent(hContact, EVENTTYPE_AUTHREQUEST, timestamp, DBEF_UTF, cbBlob, pBlob);
+}
+
std::vector<uint8_t> CToxProto::HexStringToData(std::string hex)
{
std::stringstream ss;
@@ -153,38 +179,3 @@ int CToxProto::SaveToxData(const char *path)
return res;
}
-
-#define FRADDR_TOSTR_CHUNK_LEN 8
-
-void CToxProto::fraddr_to_str(uint8_t *id_bin, char *id_str)
-{
- uint32_t i, delta = 0, pos_extra, sum_extra = 0;
-
- for (i = 0; i < TOX_FRIEND_ADDRESS_SIZE; i++) {
- sprintf(&id_str[2 * i + delta], "%02hhX", id_bin[i]);
-
- if ((i + 1) == TOX_CLIENT_ID_SIZE)
- pos_extra = 2 * (i + 1) + delta;
-
- if (i >= TOX_CLIENT_ID_SIZE)
- sum_extra |= id_bin[i];
-
- if (!((i + 1) % FRADDR_TOSTR_CHUNK_LEN)) {
- id_str[2 * (i + 1) + delta] = ' ';
- delta++;
- }
- }
-
- id_str[2 * i + delta] = 0;
-
- if (!sum_extra)
- id_str[pos_extra] = 0;
-}
-
-void CToxProto::get_id(Tox *m, char *data)
-{
- int offset = strlen(data);
- uint8_t address[TOX_FRIEND_ADDRESS_SIZE];
- tox_get_address(m, address);
- fraddr_to_str(address, data + offset);
-}