summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorSergey Bolhovskoy <elzorfox@ya.ru>2014-09-17 10:30:51 +0000
committerSergey Bolhovskoy <elzorfox@ya.ru>2014-09-17 10:30:51 +0000
commitf2f109ef851c68b7f9ff53a179a7e75311cd2d1a (patch)
treefac94a12dca7ad8aacf09ccadd0615f95bb30b01 /protocols
parent5172bf214fcba35685070a0ab9ce9e212084823a (diff)
VKontakte: Add search by name support
git-svn-id: http://svn.miranda-ng.org/main/trunk@10492 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r--protocols/VKontakte/src/vk_proto.cpp5
-rw-r--r--protocols/VKontakte/src/vk_proto.h3
-rw-r--r--protocols/VKontakte/src/vk_search.cpp31
3 files changed, 30 insertions, 9 deletions
diff --git a/protocols/VKontakte/src/vk_proto.cpp b/protocols/VKontakte/src/vk_proto.cpp
index 5afa14dedf..e8f01b8897 100644
--- a/protocols/VKontakte/src/vk_proto.cpp
+++ b/protocols/VKontakte/src/vk_proto.cpp
@@ -345,7 +345,10 @@ HANDLE CVkProto::SearchByEmail(const PROTOCHAR* email)
HANDLE CVkProto::SearchByName(const PROTOCHAR* nick, const PROTOCHAR* firstName, const PROTOCHAR* lastName)
{
- return 0;
+ TCHAR arg[200];
+ mir_sntprintf(arg, SIZEOF(arg), _T("%s %s %s"), nick, firstName, lastName);
+ ForkThread(&CVkProto::SearchByStringThread, (void *)arg);
+ return (HANDLE)1;
}
MCONTACT CVkProto::AddToList(int flags, PROTOSEARCHRESULT* psr)
diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h
index 43608c2ee1..750034ccc6 100644
--- a/protocols/VKontakte/src/vk_proto.h
+++ b/protocols/VKontakte/src/vk_proto.h
@@ -205,7 +205,8 @@ struct CVkProto : public PROTO<CVkProto>
//==== Search ========================================================================
void __cdecl SearchBasicThread(void* id);
- void OnSearchBasic(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
+ void __cdecl SearchByStringThread(void* id);
+ void OnSearch(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
//==== Misc ==========================================================================
diff --git a/protocols/VKontakte/src/vk_search.cpp b/protocols/VKontakte/src/vk_search.cpp
index 158d949d8b..a6337407a3 100644
--- a/protocols/VKontakte/src/vk_search.cpp
+++ b/protocols/VKontakte/src/vk_search.cpp
@@ -20,15 +20,24 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
void CVkProto::SearchBasicThread(void* id)
{
debugLogA("CVkProto::OnSearchBasicThread");
- Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/users.get.json", true, &CVkProto::OnSearchBasic)
- << TCHAR_PARAM("user_ids", (TCHAR *) id)
+ Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/users.get.json", true, &CVkProto::OnSearch)
+ << TCHAR_PARAM("user_ids", (TCHAR *)id)
<< VER_API);
}
-void CVkProto::OnSearchBasic(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
+void __cdecl CVkProto::SearchByStringThread(void* str)
{
- debugLogA("CVkProto::OnSearchBasic %d", reply->resultCode);
+ debugLogA("CVkProto::OnSearchBasicThread");
+ Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/users.search.json", true, &CVkProto::OnSearch)
+ << TCHAR_PARAM("q", (TCHAR *)str)
+ << INT_PARAM("count", 200)
+ << VER_API);
+}
+
+void CVkProto::OnSearch(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
+{
+ debugLogA("CVkProto::OnSearch %d", reply->resultCode);
if (reply->resultCode != 200){
ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)1, 0);
return;
@@ -41,11 +50,19 @@ void CVkProto::OnSearchBasic(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
return;
}
- for (size_t i = 0;; i++) {
+ int iCount = json_as_int(json_get(pResponse, "count"));
+ JSONNODE *pItems = json_get(pResponse, "items");
+ if (!pItems){
+ pItems = pResponse;
+ iCount = 1;
+ }
+
+
+ for (size_t i = 0; i<iCount; i++) {
PROTOSEARCHRESULT psr = { sizeof(psr) };
psr.flags = PSR_TCHAR;
- JSONNODE *pRecord = json_at(pResponse, i);
+ JSONNODE *pRecord = json_at(pItems, i);
if (pRecord == NULL)
break;
@@ -62,4 +79,4 @@ void CVkProto::OnSearchBasic(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
}
ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)1, 0);
-} \ No newline at end of file
+}