diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2016-06-13 19:11:23 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2016-06-13 19:11:23 +0000 |
commit | 545ca2edec49b7aed688bec052cc6609f68b39ed (patch) | |
tree | 20fe7b34d39959d66bbbbf3500f4ac11aa6038b6 /protocols | |
parent | 96e5029af97ae86f2b41499884a46723410a357d (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')
-rw-r--r-- | protocols/Tox/src/http_request.h | 96 | ||||
-rw-r--r-- | protocols/Tox/src/tox_search.cpp | 41 |
2 files changed, 67 insertions, 70 deletions
diff --git a/protocols/Tox/src/http_request.h b/protocols/Tox/src/http_request.h index e52de2c179..1ffa523775 100644 --- a/protocols/Tox/src/http_request.h +++ b/protocols/Tox/src/http_request.h @@ -41,75 +41,6 @@ private: protected:
enum HttpRequestUrlFormat { FORMAT };
- void AddHeader(LPCSTR szName, LPCSTR szValue)
- {
- headers = (NETLIBHTTPHEADER*)mir_realloc(headers, sizeof(NETLIBHTTPHEADER) * (headersCount + 1));
- headers[headersCount].szName = mir_strdup(szName);
- headers[headersCount].szValue = mir_strdup(szValue);
- headersCount++;
- }
-
- void AddBasicAuthHeader(LPCSTR szLogin, LPCSTR szPassword)
- {
- char cPair[128];
- mir_snprintf(
- cPair,
- _countof(cPair),
- "%s:%s",
- szLogin,
- szPassword);
-
- char *ePair = (char *)mir_base64_encode((BYTE*)cPair, (UINT)mir_strlen(cPair));
-
- char value[128];
- mir_snprintf(
- value,
- _countof(value),
- "Basic %s",
- ePair);
-
- mir_free(ePair);
-
- headers = (NETLIBHTTPHEADER*)mir_realloc(headers, sizeof(NETLIBHTTPHEADER)*(headersCount + 1));
- headers[headersCount].szName = mir_strdup("Authorization");
- headers[headersCount].szValue = mir_strdup(value);
- headersCount++;
- }
-
- void AddBearerAuthHeader(LPCSTR szValue)
- {
- char value[128];
- mir_snprintf(
- value,
- _countof(value),
- "Bearer %s",
- szValue);
-
- headers = (NETLIBHTTPHEADER*)mir_realloc(headers, sizeof(NETLIBHTTPHEADER)*(headersCount + 1));
- headers[headersCount].szName = mir_strdup("Authorization");
- headers[headersCount].szValue = mir_strdup(value);
- headersCount++;
- }
-
- void AddUrlParameter(const char *urlFormat, ...)
- {
- va_list urlArgs;
- va_start(urlArgs, urlFormat);
- m_szUrl += m_szUrl.Find('?') == -1 ? '?' : '&';
- m_szUrl.AppendFormatV(urlFormat, urlArgs);
- va_end(urlArgs);
- }
-
- void SetData(const char *data, size_t size)
- {
- if (pData != NULL)
- mir_free(pData);
-
- dataLength = (int)size;
- pData = (char*)mir_alloc(size);
- memcpy(pData, data, size);
- }
-
public:
HttpRequest(int type, LPCSTR url)
{
@@ -140,6 +71,33 @@ public: mir_free(pData);
}
+ void AddHeader(LPCSTR szName, LPCSTR szValue)
+ {
+ headers = (NETLIBHTTPHEADER*)mir_realloc(headers, sizeof(NETLIBHTTPHEADER) * (headersCount + 1));
+ headers[headersCount].szName = mir_strdup(szName);
+ headers[headersCount].szValue = mir_strdup(szValue);
+ headersCount++;
+ }
+
+ void AddUrlParameter(const char *urlFormat, ...)
+ {
+ va_list urlArgs;
+ va_start(urlArgs, urlFormat);
+ m_szUrl += m_szUrl.Find('?') == -1 ? '?' : '&';
+ m_szUrl.AppendFormatV(urlFormat, urlArgs);
+ va_end(urlArgs);
+ }
+
+ void SetData(const char *data, size_t size)
+ {
+ if (pData != NULL)
+ mir_free(pData);
+
+ dataLength = (int)size;
+ pData = (char*)mir_alloc(size);
+ memcpy(pData, data, size);
+ }
+
NETLIBHTTPREQUEST* Send(HANDLE hNetlibConnection)
{
m_szUrl.Replace('\\', '/');
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);
|