summaryrefslogtreecommitdiff
path: root/protocols/Tox/src/tox_search.cpp
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2016-06-13 19:11:23 +0000
committerAlexander Lantsev <aunsane@gmail.com>2016-06-13 19:11:23 +0000
commit545ca2edec49b7aed688bec052cc6609f68b39ed (patch)
tree20fe7b34d39959d66bbbbf3500f4ac11aa6038b6 /protocols/Tox/src/tox_search.cpp
parent96e5029af97ae86f2b41499884a46723410a357d (diff)
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
Diffstat (limited to 'protocols/Tox/src/tox_search.cpp')
-rw-r--r--protocols/Tox/src/tox_search.cpp41
1 files changed, 40 insertions, 1 deletions
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);