summaryrefslogtreecommitdiff
path: root/protocols/Tox/src/tox_search.cpp
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2014-08-30 11:37:47 +0000
committerAlexander Lantsev <aunsane@gmail.com>2014-08-30 11:37:47 +0000
commitce49c84f3a26f016f9232d2bffdc830d7fd6169f (patch)
treec6bbdab7b5a42f65461a5d495d962c4ff69b9e97 /protocols/Tox/src/tox_search.cpp
parentbeaf93e92827b7bcc77c9f6b2a0c7097d355151c (diff)
Tox:
- switch to offline when connection is lost - file transfer support - code refactoring - project reordering - version bump git-svn-id: http://svn.miranda-ng.org/main/trunk@10340 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Tox/src/tox_search.cpp')
-rw-r--r--protocols/Tox/src/tox_search.cpp79
1 files changed, 79 insertions, 0 deletions
diff --git a/protocols/Tox/src/tox_search.cpp b/protocols/Tox/src/tox_search.cpp
new file mode 100644
index 0000000000..82dcbd5be7
--- /dev/null
+++ b/protocols/Tox/src/tox_search.cpp
@@ -0,0 +1,79 @@
+#include "common.h"
+
+void CToxProto::SearchByIdAsync(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;
+
+ 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)
+ {
+ std::smatch match;
+ std::regex regex("\"public_key\": \"(.+?)\"");
+
+ const std::string content = response->pData;
+
+ if (std::regex_search(content, match, regex))
+ {
+ 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;
+ }
+ }
+
+ CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)response);
+ mir_free(request.headers);
+
+ ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_FAILED, (HANDLE)1, 0);
+ mir_free(arg);
+}
+
+INT_PTR CToxProto::SearchDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ CToxProto *proto = (CToxProto*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
+
+ switch (uMsg)
+ {
+ case WM_INITDIALOG:
+ TranslateDialogDefault(hwnd);
+ {
+ proto = (CToxProto*)lParam;
+ SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam);
+
+ //ShowWindow(GetDlgItem(GetParent(hwnd), 1408/*IDC_BYCUSTOM*/), SW_HIDE);
+ //ShowWindow(GetDlgItem(GetParent(hwnd), 1402/*IDC_ADVANCEDGROUP*/), SW_HIDE);
+ SetDlgItemText(GetParent(hwnd), 1408/*IDC_BYCUSTOM*/, TranslateT("Query"));
+ }
+ return TRUE;
+ }
+
+ return FALSE;
+} \ No newline at end of file