diff options
Diffstat (limited to 'protocols/Tox/src')
| -rw-r--r-- | protocols/Tox/src/common.h | 2 | ||||
| -rw-r--r-- | protocols/Tox/src/tox_contacts.cpp | 2 | ||||
| -rw-r--r-- | protocols/Tox/src/tox_dns.h | 24 | ||||
| -rw-r--r-- | protocols/Tox/src/tox_proto.cpp | 66 | ||||
| -rw-r--r-- | protocols/Tox/src/tox_proto.h | 2 | ||||
| -rw-r--r-- | protocols/Tox/src/tox_search.cpp | 164 | 
6 files changed, 151 insertions, 109 deletions
diff --git a/protocols/Tox/src/common.h b/protocols/Tox/src/common.h index 9ee450e5c2..240b8817d7 100644 --- a/protocols/Tox/src/common.h +++ b/protocols/Tox/src/common.h @@ -3,6 +3,7 @@  #include <winsock2.h>
  #include <windows.h>
 +#include <windns.h>
  #include <time.h>
  #include <string>
 @@ -30,6 +31,7 @@  #include <m_message.h>
  #include <tox.h>
 +#include <toxdns.h>
  #include "version.h"
  #include "resource.h"
 diff --git a/protocols/Tox/src/tox_contacts.cpp b/protocols/Tox/src/tox_contacts.cpp index a62c685021..26159350ae 100644 --- a/protocols/Tox/src/tox_contacts.cpp +++ b/protocols/Tox/src/tox_contacts.cpp @@ -31,7 +31,7 @@ MCONTACT CToxProto::GetContactFromAuthEvent(HANDLE hEvent)  {
  	DWORD body[3];
  	DBEVENTINFO dbei = { sizeof(DBEVENTINFO) };
 -	dbei.cbBlob = sizeof(DWORD)* 2;
 +	dbei.cbBlob = sizeof(DWORD)*2;
  	dbei.pBlob = (PBYTE)&body;
  	if (db_event_get(hEvent, &dbei))
 diff --git a/protocols/Tox/src/tox_dns.h b/protocols/Tox/src/tox_dns.h new file mode 100644 index 0000000000..1629141680 --- /dev/null +++ b/protocols/Tox/src/tox_dns.h @@ -0,0 +1,24 @@ +#ifndef _TOX_DNS_H_
 +#define _TOX_DNS_H_
 +
 +struct dns_server {
 +	char *domain;
 +	uint8_t key[32];
 +} dns_servers[] = {
 +	{
 +		"toxme.se",
 +		{
 +			0x5D, 0x72, 0xC5, 0x17, 0xDF, 0x6A, 0xEC, 0x54, 0xF1, 0xE9, 0x77, 0xA6, 0xB6, 0xF2, 0x59, 0x14,
 +			0xEA, 0x4C, 0xF7, 0x27, 0x7A, 0x85, 0x02, 0x7C, 0xD9, 0xF5, 0x19, 0x6D, 0xF1, 0x7E, 0x0B, 0x13
 +		}
 +	},
 +	{
 +		"utox.org",
 +		{
 +			0xD3, 0x15, 0x4F, 0x65, 0xD2, 0x8A, 0x5B, 0x41, 0xA0, 0x5D, 0x4A, 0xC7, 0xE4, 0xB3, 0x9C, 0x6B,
 +			0x1C, 0x23, 0x3C, 0xC8, 0x57, 0xFB, 0x36, 0x5C, 0x56, 0xE8, 0x39, 0x27, 0x37, 0x46, 0x2A, 0x12
 +		}
 +	},
 +};
 +
 +#endif //_TOX_DNS_H_
\ No newline at end of file diff --git a/protocols/Tox/src/tox_proto.cpp b/protocols/Tox/src/tox_proto.cpp index 83163a9670..4bd9ca4efc 100644 --- a/protocols/Tox/src/tox_proto.cpp +++ b/protocols/Tox/src/tox_proto.cpp @@ -157,72 +157,6 @@ HANDLE __cdecl CToxProto::ChangeInfo(int iInfoType, void* pInfoData) { return 0;  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; }
 -
 -HWND __cdecl CToxProto::SearchAdvanced(HWND owner)
 -{
 -	if (!IsOnline())
 -	{
 -		// we cannot add someone to friend list while tox is offline
 -		return NULL;
 -	}
 -
 -	std::smatch match;
 -	std::regex regex("^\\s*([A-Fa-f0-9]{76})\\s*$");
 -
 -	char text[TOX_FRIEND_ADDRESS_SIZE * 2 + 1];
 -	GetDlgItemTextA(owner, IDC_SEARCH, text, SIZEOF(text));
 -
 -	const std::string query = text;
 -	if (std::regex_search(query, match, regex))
 -	{
 -		std::string address = match[1];
 -		std::vector<uint8_t> id = HexStringToData(address);
 -		MCONTACT hContact = FindContact(id);
 -		if (!hContact)
 -		{
 -			PROTOSEARCHRESULT psr = { sizeof(psr) };
 -			psr.flags = PSR_TCHAR;
 -			psr.id = mir_a2t(query.c_str());
 -
 -			ADDCONTACTSTRUCT acs = { HANDLE_SEARCHRESULT };
 -			acs.szProto = m_szModuleName;
 -			acs.psr = &psr;
 -
 -			CallService(MS_ADDCONTACT_SHOW, (WPARAM)owner, (LPARAM)&acs);
 -		}
 -		else
 -		{
 -			ShowNotification(TranslateT("Contact already in your contact list"), 0, hContact);
 -		}
 -		ForkThread(&CToxProto::SearchByIdAsync, mir_strdup(query.c_str()));
 -	}
 -	else
 -	{
 -		regex = "^\\s*([^ @/:;()\"']+)(@toxme.se)?\\s*$";
 -		if (std::regex_search(query, match, regex))
 -		{
 -			std::string query = match[1];
 -			ForkThread(&CToxProto::SearchByNameAsync, mir_strdup(query.c_str()));
 -		}
 -	}
 -	return (HWND)1;
 -}
 -
 -HWND __cdecl CToxProto::CreateExtendedSearchUI(HWND owner)
 -{
 -	return CreateDialogParam(
 -		g_hInstance,
 -		MAKEINTRESOURCE(IDD_SEARCH),
 -		owner,
 -		SearchDlgProc,
 -		(LPARAM)this);
 -}
 -
  int __cdecl CToxProto::RecvContacts(MCONTACT hContact, PROTORECVEVENT*) { return 0; }
  int __cdecl CToxProto::RecvFile(MCONTACT hContact, PROTOFILEEVENT *pre)
 diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h index 96e0bd662c..6c7b26ed34 100644 --- a/protocols/Tox/src/tox_proto.h +++ b/protocols/Tox/src/tox_proto.h @@ -173,7 +173,7 @@ private:  	static void OnConnectionStatusChanged(Tox *tox, const int number, const uint8_t status, void *arg);
  	// contacts search
 -	void __cdecl SearchByIdAsync(void* arg);
 +	void __cdecl SearchFailedAsync(void* arg);
  	void __cdecl SearchByNameAsync(void* arg);
  	static INT_PTR CALLBACK SearchDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
 diff --git a/protocols/Tox/src/tox_search.cpp b/protocols/Tox/src/tox_search.cpp index 82dcbd5be7..88726cadb8 100644 --- a/protocols/Tox/src/tox_search.cpp +++ b/protocols/Tox/src/tox_search.cpp @@ -1,58 +1,71 @@  #include "common.h"
 +#include "tox_dns.h"
 -void CToxProto::SearchByIdAsync(void*)
 +void CToxProto::SearchFailedAsync(void*)
  {
  	ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_FAILED, (HWND)1, 0);
  }
  void CToxProto::SearchByNameAsync(void* arg)
  {
 -	NETLIBHTTPREQUEST request = { sizeof(NETLIBHTTPREQUEST) };
 -	request.requestType = REQUEST_POST;
 -	request.szUrl = "https://toxme.se/api";
 -	request.flags = NLHRF_HTTP11 | NLHRF_SSL | NLHRF_NODUMP;
 +	char *query = (char*)arg;
 +	char *name = strtok(query, "@");
 +	char *domain = strtok(NULL, "");
 -	request.headers = (NETLIBHTTPHEADER*)mir_alloc(sizeof(NETLIBHTTPHEADER)* 2);
 -	request.headers[0].szName = "Content-Type";
 -	request.headers[0].szValue = "text/plain; charset=utf-8";
 -	request.headersCount = 1;
 -
 -	std::string query = "{\"action\":3,\"name\":\"";
 -	query += (char*)arg;
 -	query += "\"}";
 -
 -	request.dataLength = query.length();
 -	request.pData = (char*)query.c_str();
 -
 -	NETLIBHTTPREQUEST* response = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)hNetlib, (LPARAM)&request);
 -
 -	if (response)
 +	int i = 0;
 +	static int j = 0;
 +	while (i < 2)
  	{
 -		std::smatch match;
 -		std::regex regex("\"public_key\": \"(.+?)\"");
 -
 -		const std::string content = response->pData;
 -
 -		if (std::regex_search(content, match, regex))
 +		struct dns_server *server = &dns_servers[j % SIZEOF(dns_servers)];
 +		if (domain == NULL || strcmp(domain, server->domain) == 0)
  		{
 -			std::string toxId = match[1];
 -
 -			PROTOSEARCHRESULT psr = { sizeof(PROTOSEARCHRESULT) };
 -			psr.flags = PSR_TCHAR;
 -			psr.id = mir_a2t(toxId.c_str());
 -
 -			ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)1, (LPARAM)&psr);
 -			ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)1, 0);
 -
 -			CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)response);
 -			return;
 +			void *dns = tox_dns3_new(server->key);
 +
 +			uint8_t dnsString[256];
 +			uint32_t requestId = 0;
 +			int length = tox_generate_dns3_string(dns, dnsString, sizeof(dnsString), &requestId, (uint8_t*)name, strlen(name));
 +			if (length != TOX_ERROR)
 +			{
 +				dnsString[length] = 0;
 +
 +				char dnsQuery[512];
 +				mir_snprintf(dnsQuery, 512, "_%s._tox.%s", dnsString, server->domain);
 +
 +				bool success = false;
 +				DNS_RECORDA *record = NULL;
 +				DnsQuery_A(dnsQuery, DNS_TYPE_TEXT, 0, NULL, (PDNS_RECORD*)&record, NULL);
 +				while (record)
 +				{
 +					DNS_TXT_DATAA *txt = &record->Data.Txt;
 +					if (record->wType == DNS_TYPE_TEXT && txt->dwStringCount)
 +					{
 +						char *recordId = &txt->pStringArray[0][10];
 +						std::vector<uint8_t> address(TOX_FRIEND_ADDRESS_SIZE);
 +						if (tox_decrypt_dns3_TXT(dns, &address[0], (uint8_t*)recordId, strlen(recordId), requestId) != TOX_ERROR)
 +						{
 +							std::string id = DataToHexString(address);
 +
 +							PROTOSEARCHRESULT psr = { sizeof(PROTOSEARCHRESULT) };
 +							psr.flags = PSR_TCHAR;
 +							psr.id = mir_a2t(id.c_str());
 +							psr.nick = mir_a2t(name);
 +
 +							TCHAR email[MAX_PATH];
 +							mir_sntprintf(email, SIZEOF(email), _T("%s@%s"), _A2T(name), _A2T(server->domain));
 +							psr.email = mir_tstrdup(email);
 +
 +							ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)1, (LPARAM)&psr);
 +						}
 +					}
 +					record = record->pNext;
 +				}
 +			}
 +			tox_dns3_kill(dns);
  		}
 +		i++; j++;
  	}
 -	CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)response);
 -	mir_free(request.headers);
 -
 -	ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_FAILED, (HANDLE)1, 0);
 +	ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)1, 0);
  	mir_free(arg);
  }
 @@ -76,4 +89,73 @@ INT_PTR CToxProto::SearchDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa  	}
  	return FALSE;
 +}
 +
 +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; }
 +
 +HWND __cdecl CToxProto::SearchAdvanced(HWND owner)
 +{
 +	if (!IsOnline())
 +	{
 +		// we cannot add someone to friend list while tox is offline
 +		return NULL;
 +	}
 +
 +	std::smatch match;
 +	std::regex regex("^\\s*([A-Fa-f0-9]{76})\\s*$");
 +
 +	char text[TOX_FRIEND_ADDRESS_SIZE * 2 + 1];
 +	GetDlgItemTextA(owner, IDC_SEARCH, text, SIZEOF(text));
 +
 +	const std::string query = text;
 +	if (std::regex_search(query, match, regex))
 +	{
 +		std::string address = match[1];
 +		std::vector<uint8_t> id = HexStringToData(address);
 +		MCONTACT hContact = FindContact(id);
 +		if (!hContact)
 +		{
 +			PROTOSEARCHRESULT psr = { sizeof(psr) };
 +			psr.flags = PSR_TCHAR;
 +			psr.id = mir_a2t(query.c_str());
 +
 +			ADDCONTACTSTRUCT acs = { HANDLE_SEARCHRESULT };
 +			acs.szProto = m_szModuleName;
 +			acs.psr = &psr;
 +
 +			CallService(MS_ADDCONTACT_SHOW, (WPARAM)owner, (LPARAM)&acs);
 +		}
 +		else
 +		{
 +			ShowNotification(TranslateT("Contact already in your contact list"), 0, hContact);
 +		}
 +		ForkThread(&CToxProto::SearchFailedAsync, NULL);
 +	}
 +	else
 +	{
 +		regex = "^\\s*(([^ @/:;()\"']+)(@[A-Za-z]+.[A-Za-z]{2,6})?)\\s*$";
 +		if (std::regex_search(query, match, regex))
 +		{
 +			ForkThread(&CToxProto::SearchByNameAsync, mir_strdup(match[1].str().c_str()));
 +		}
 +		else
 +		{
 +			ForkThread(&CToxProto::SearchFailedAsync, NULL);
 +		}
 +	}
 +	return (HWND)1;
 +}
 +
 +HWND __cdecl CToxProto::CreateExtendedSearchUI(HWND owner)
 +{
 +	return CreateDialogParam(
 +		g_hInstance,
 +		MAKEINTRESOURCE(IDD_SEARCH),
 +		owner,
 +		SearchDlgProc,
 +		(LPARAM)this);
  }
\ No newline at end of file  | 
