From 545ca2edec49b7aed688bec052cc6609f68b39ed Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Mon, 13 Jun 2016 19:11:23 +0000 Subject: Tox: toxme.io used for search instead of toxdns git-svn-id: http://svn.miranda-ng.org/main/trunk@16971 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Tox/src/tox_search.cpp | 41 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'protocols/Tox/src/tox_search.cpp') diff --git a/protocols/Tox/src/tox_search.cpp b/protocols/Tox/src/tox_search.cpp index 6c99ad123c..197f1baaa3 100644 --- a/protocols/Tox/src/tox_search.cpp +++ b/protocols/Tox/src/tox_search.cpp @@ -57,6 +57,30 @@ ToxHexAddress ResolveToxAddressFromDns(const char *dnsQuery) return address; } +ToxHexAddress ResolveToxAddressFromToxme(HANDLE hNetlib, const char *query) +{ + ToxHexAddress address = ToxHexAddress::Empty(); + + HttpRequest request(REQUEST_POST, "https://toxme.io/api"); + JSONNode root(JSON_NODE); + root + << JSONNode("action", 3) + << JSONNode("name", query); + json_string data = root.write(); + request.SetData(data.c_str(), data.length()); + + NLHR_PTR response(request.Send(hNetlib)); + if (response->resultCode != HTTP_CODE_OK || !response->pData) + return ToxHexAddress::Empty(); + + root = JSONNode::parse(response->pData); + if (root.empty()) + return ToxHexAddress::Empty(); + + json_string id = root.at("tox_id").as_string(); + return ToxHexAddress(id.c_str()); +} + void CToxProto::SearchByNameAsync(void *arg) { Thread_SetName("TOX: SearchByNameAsync"); @@ -65,7 +89,7 @@ void CToxProto::SearchByNameAsync(void *arg) char *name = strtok(query, "@"); char *domain = strtok(NULL, ""); - int resolved = 0; + /*int resolved = 0; if (IsFileExists((TCHAR*)VARST(_T(TOX_INI_PATH)))) { @@ -139,6 +163,21 @@ void CToxProto::SearchByNameAsync(void *arg) ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)1, (LPARAM)&psr); } + }*/ + + ToxHexAddress address = ResolveToxAddressFromToxme(m_hNetlibUser, query); + if (!address.IsEmpty()) + { + PROTOSEARCHRESULT psr = { sizeof(PROTOSEARCHRESULT) }; + psr.flags = PSR_UTF8; + psr.id.a = mir_strdup(address); + psr.nick.a = mir_strdup(name); + + char email[MAX_PATH]; + mir_snprintf(email, "%s@toxme.io", name); + psr.email.a = mir_strdup(email); + + ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)1, (LPARAM)&psr); } ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)1, 0); -- cgit v1.2.3