diff options
author | Sergey Bolhovskoy <elzorfox@ya.ru> | 2014-10-06 09:48:49 +0000 |
---|---|---|
committer | Sergey Bolhovskoy <elzorfox@ya.ru> | 2014-10-06 09:48:49 +0000 |
commit | 3897e7500fd9c3a01d4141f9c037ee9432c8eaab (patch) | |
tree | b4d2168370f4206f64c509b792db5735f093eccb | |
parent | 7af885608ecb5da860d81d692bf15aa26fdb7b8e (diff) |
VKontakte:
fix for filter on search result
upload files support part 2 (audio and documents)
version bump
git-svn-id: http://svn.miranda-ng.org/main/trunk@10704 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | protocols/VKontakte/src/misc.cpp | 2 | ||||
-rw-r--r-- | protocols/VKontakte/src/version.h | 2 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_files.cpp | 128 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_proto.cpp | 3 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_queue.cpp | 2 |
5 files changed, 98 insertions, 39 deletions
diff --git a/protocols/VKontakte/src/misc.cpp b/protocols/VKontakte/src/misc.cpp index 5b417a1971..8d2b866d07 100644 --- a/protocols/VKontakte/src/misc.cpp +++ b/protocols/VKontakte/src/misc.cpp @@ -488,5 +488,5 @@ bool tlstrstr(TCHAR* _s1, TCHAR* _s2) mir_sntprintf(s2, SIZEOF(s2), _T("%s"), _s2);
CharLowerBuff(s1, SIZEOF(s1));
CharLowerBuff(s2, SIZEOF(s2));
- return (_tcsstr(s1, s2) == NULL);
+ return (_tcsstr(s1, s2) != NULL);
}
\ No newline at end of file diff --git a/protocols/VKontakte/src/version.h b/protocols/VKontakte/src/version.h index 1acb8c28fb..74e50ca380 100644 --- a/protocols/VKontakte/src/version.h +++ b/protocols/VKontakte/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0
#define __MINOR_VERSION 1
#define __RELEASE_NUM 0
-#define __BUILD_NUM 19
+#define __BUILD_NUM 20
#include <stdver.h>
diff --git a/protocols/VKontakte/src/vk_files.cpp b/protocols/VKontakte/src/vk_files.cpp index 804c612e8b..1a372d9b4d 100644 --- a/protocols/VKontakte/src/vk_files.cpp +++ b/protocols/VKontakte/src/vk_files.cpp @@ -43,16 +43,14 @@ FileUploadParam::VKFileType FileUploadParam::GetType() if (filetype != typeInvalid)
return filetype;
- TCHAR img[] = L"jpg jpeg png bmp";
- TCHAR audio[] = L"mp3";
+ TCHAR img[] = L".jpg .jpeg .png .bmp";
+ TCHAR audio[] = L".mp3";
TCHAR DRIVE[3], DIR[256], FNAME[256], EXT[256];
_tsplitpath(FileName, DRIVE, DIR, FNAME, EXT);
- CMStringA fn(mir_utf8encodeT(FNAME));
- fn.AppendChar('.');
- fn.AppendFormat("%s", mir_utf8encodeT(EXT));
-
+ CMStringA fn;
+ fn.AppendFormat("%s%s", mir_utf8encodeT(FNAME), mir_utf8encodeT(EXT));
fname = mir_strdup(fn.GetBuffer());
if (tlstrstr(img, EXT)){
@@ -71,7 +69,6 @@ FileUploadParam::VKFileType FileUploadParam::GetType() return filetype;
}
-
HANDLE CVkProto::SendFile(MCONTACT hContact, const PROTOCHAR *desc, PROTOCHAR **files)
{
debugLogA("CVkProto::SendFile");
@@ -90,30 +87,32 @@ void CVkProto::SendFileFiled(FileUploadParam *fup, TCHAR *reason) void CVkProto::SendFileThread(void *p)
{
FileUploadParam *fup = (FileUploadParam *)p;
- debugLogA("CVkProto::SendFileThread");
+ debugLog(L"CVkProto::SendFileThread %d %s", fup->GetType(), fup->fileName());
if (!fup->IsAccess()){
SendFileFiled(fup, L"FileIsNotAccess");
return;
}
+
AsyncHttpRequest *pReq;
switch (fup->GetType()){
case FileUploadParam::typeImg:
pReq = new AsyncHttpRequest(this, REQUEST_GET, "/method/photos.getMessagesUploadServer.json", true, &CVkProto::OnReciveUploadServer)
<< VER_API;
- pReq->pUserInfo = p;
- Push(pReq);
break;
case FileUploadParam::typeAudio:
- // Audio
- SendFileFiled(fup, L"FileTypeIsNotSupported");
+ pReq = new AsyncHttpRequest(this, REQUEST_GET, "/method/audio.getUploadServer.json", true, &CVkProto::OnReciveUploadServer)
+ << VER_API;
break;
case FileUploadParam::typeDoc:
- // Doc
- SendFileFiled(fup, L"FileTypeIsNotSupported");
+ pReq = new AsyncHttpRequest(this, REQUEST_GET, "/method/docs.getUploadServer.json", true, &CVkProto::OnReciveUploadServer)
+ << VER_API;
break;
default:
- SendFileFiled(fup);
+ SendFileFiled(fup, L"FileTypeNotSupported");
+ return;
}
+ pReq->pUserInfo = p;
+ Push(pReq);
}
void CVkProto::OnReciveUploadServer(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
@@ -155,13 +154,15 @@ void CVkProto::OnReciveUploadServer(NETLIBHTTPREQUEST *reply, AsyncHttpRequest * CMStringA boundary, header;
CMStringA NamePart = fup->atrName();
CMStringA FNamePart = fup->fileName();
- srand(time(NULL));
+ // Boundary
+ srand(time(NULL));
int iboundary = rand();
boundary.AppendFormat("Miranda%dNG%d", iboundary, time(NULL));
+ // Header
header.AppendFormat("multipart/form-data; boundary=%s", boundary.GetBuffer());
pUploadReq->AddHeader("Content-Type", header.GetBuffer());
-
+ // Content-Disposition {
CMStringA DataBegin = "--";
DataBegin += boundary;
DataBegin += "\r\n";
@@ -170,25 +171,28 @@ void CVkProto::OnReciveUploadServer(NETLIBHTTPREQUEST *reply, AsyncHttpRequest * DataBegin += "\"; filename=\"";
DataBegin += FNamePart;
DataBegin += "\";\r\n\r\n";
-
+ // } Content-Disposition
CMStringA DataEnd = "\r\n--";
DataEnd += boundary;
DataEnd += "--\r\n";
-
+ // Body size
size_t dataLength = szFileLen + DataBegin.GetLength() + DataEnd.GetLength();
-
+ // Body {
char* pData = (char *)mir_alloc(dataLength);
memcpy(pData, (void *)DataBegin.GetBuffer(), DataBegin.GetLength());
pUploadReq->pData = pData;
+
pData += DataBegin.GetLength();
fread(pData, 1, szFileLen, pFile);
+ fclose(pFile);
+
pData += szFileLen;
memcpy(pData, (void *)DataEnd.GetBuffer(), DataEnd.GetLength());
+ // } Body
+
pUploadReq-> dataLength = dataLength;
pUploadReq->pUserInfo = pReq->pUserInfo;
- debugLogA("CVkProto::OnReciveUploadServer \n<%d>", dataLength);
Push(pUploadReq);
- fclose(pFile);
}
void CVkProto::OnReciveUpload(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
@@ -203,16 +207,53 @@ void CVkProto::OnReciveUpload(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) JSONROOT pRoot;
JSONNODE *pResponse = CheckJsonResponse(pReq, reply, pRoot);
-
+
CMString server = json_as_string(json_get(pRoot, "server"));
- CMString photo = json_as_string(json_get(pRoot, "photo"));
CMString hash = json_as_string(json_get(pRoot, "hash"));
+ CMString upload;
- AsyncHttpRequest *pUploadReq = new AsyncHttpRequest(this, REQUEST_GET, "/method/photos.saveMessagesPhoto.json", true, &CVkProto::OnReciveUploadFile)
- << TCHAR_PARAM("server", server)
- << TCHAR_PARAM("photo", photo)
- << TCHAR_PARAM("hash", hash)
- << VER_API;
+ AsyncHttpRequest *pUploadReq;
+
+ switch (fup->GetType()){
+ case FileUploadParam::typeImg:
+ upload = json_as_string(json_get(pRoot, "photo"));
+ if (upload == L"[]"){
+ SendFileFiled(fup, L"NotUpload Photo");
+ }
+ pUploadReq = new AsyncHttpRequest(this, REQUEST_GET, "/method/photos.saveMessagesPhoto.json", true, &CVkProto::OnReciveUploadFile)
+ << TCHAR_PARAM("server", server)
+ << TCHAR_PARAM("photo", upload)
+ << TCHAR_PARAM("hash", hash)
+ << VER_API;
+ break;
+ case FileUploadParam::typeAudio:
+ upload = json_as_string(json_get(pRoot, "audio"));
+ if (upload == L"[]"){
+ SendFileFiled(fup, L"NotUpload Audio");
+ return;
+ }
+ pUploadReq = new AsyncHttpRequest(this, REQUEST_GET, "/method/audio.save.json", true, &CVkProto::OnReciveUploadFile)
+ << TCHAR_PARAM("server", server)
+ << TCHAR_PARAM("audio", upload)
+ << TCHAR_PARAM("hash", hash)
+ << VER_API;
+ break;
+ case FileUploadParam::typeDoc:
+ upload = json_as_string(json_get(pRoot, "file"));
+ if (upload.IsEmpty()){
+ SendFileFiled(fup, L"NotUpload Doc");
+ return;
+ }
+ pUploadReq = new AsyncHttpRequest(this, REQUEST_GET, "/method/docs.save.json", true, &CVkProto::OnReciveUploadFile)
+ << CHAR_PARAM("title", fup->fileName())
+ << TCHAR_PARAM("file", upload)
+ << VER_API;
+ break;
+ default:
+ SendFileFiled(fup);
+ return;
+ }
+
pUploadReq->pUserInfo = pReq->pUserInfo;
Push(pUploadReq);
}
@@ -221,7 +262,7 @@ void CVkProto::OnReciveUploadFile(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pR {
FileUploadParam *fup = (FileUploadParam *)pReq->pUserInfo;
- debugLogA("CVkProto::OnReciveUploadPhoto %d", reply->resultCode);
+ debugLogA("CVkProto::OnReciveUploadFile %d", reply->resultCode);
if (reply->resultCode != 200){
SendFileFiled(fup);
return;
@@ -234,13 +275,30 @@ void CVkProto::OnReciveUploadFile(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pR return;
}
- int id = json_as_int(json_get(json_at(pResponse,0), "id"));
- int owner_id = json_as_int(json_get(json_at(pResponse, 0), "owner_id"));
+ int id = json_as_int(json_get(fup->GetType() == FileUploadParam::typeAudio ? pResponse: json_at(pResponse, 0), "id"));
+ int owner_id = json_as_int(json_get(fup->GetType() == FileUploadParam::typeAudio ? pResponse : json_at(pResponse, 0), "owner_id"));
+ if ((id == 0) || (owner_id == 0)){
+ SendFileFiled(fup);
+ return;
+ }
+
CMString Attachment;
- Attachment.AppendFormat(L"photo%d_%d", owner_id, id);
-
- debugLog(L"CVkProto::OnReciveUploadPhoto Att %s", Attachment.GetBuffer());
+ switch (fup->GetType()){
+ case FileUploadParam::typeImg:
+ Attachment.AppendFormat(L"photo%d_%d", owner_id, id);
+ break;
+ case FileUploadParam::typeAudio:
+ Attachment.AppendFormat(L"audio%d_%d", owner_id, id);
+ break;
+ case FileUploadParam::typeDoc:
+ Attachment.AppendFormat(L"doc%d_%d", owner_id, id);
+ break;
+ default:
+ SendFileFiled(fup);
+ return;
+ }
+
LONG userID = getDword(fup->hContact, "ID", -1);
if (userID == -1){
SendFileFiled(fup);
diff --git a/protocols/VKontakte/src/vk_proto.cpp b/protocols/VKontakte/src/vk_proto.cpp index 3d59c48847..d7d46d6f40 100644 --- a/protocols/VKontakte/src/vk_proto.cpp +++ b/protocols/VKontakte/src/vk_proto.cpp @@ -374,7 +374,8 @@ void CVkProto::OnSendMessage(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) JSONNODE *pResponse = CheckJsonResponse(pReq, reply, pRoot);
if (pResponse != NULL) {
UINT mid = json_as_int(pResponse);
- m_sendIds.insert((HANDLE)mid);
+ if (param->iMsgID != -1)
+ m_sendIds.insert((HANDLE)mid);
if (mid>getDword(param->hContact, "lastmsgid", 0))
setDword(param->hContact, "lastmsgid", mid);
if (m_bMarkReadOnReply)
diff --git a/protocols/VKontakte/src/vk_queue.cpp b/protocols/VKontakte/src/vk_queue.cpp index 74341beb55..08caa1684a 100644 --- a/protocols/VKontakte/src/vk_queue.cpp +++ b/protocols/VKontakte/src/vk_queue.cpp @@ -97,7 +97,7 @@ void CVkProto::WorkerThread(void*) extern char szBlankUrl[];
Push(new AsyncHttpRequest(this, REQUEST_GET, "/oauth/authorize", false, &CVkProto::OnOAuthAuthorize)
<< INT_PARAM("client_id", VK_APP_ID)
- << CHAR_PARAM("scope", "friends,photos,audio,video,wall,messages,offline,status")
+ << CHAR_PARAM("scope", "friends,photos,audio,docs,video,wall,messages,offline,status")
<< CHAR_PARAM("redirect_uri", szBlankUrl)
<< CHAR_PARAM("display", "mobile")
<< CHAR_PARAM("response_type", "token")
|