diff options
author | Sergey Bolhovskoy <elzorfox@ya.ru> | 2014-10-07 04:47:23 +0000 |
---|---|---|
committer | Sergey Bolhovskoy <elzorfox@ya.ru> | 2014-10-07 04:47:23 +0000 |
commit | 00714f1a92044866135cd75e599ff3fac75fe33f (patch) | |
tree | da70b71498faa719e6a0f9650d8114e9e117e7e8 /protocols | |
parent | 251e7759f31dbf3c8a199766b5d341342af77992 (diff) |
VKontakte:
rename FileUploadParam => CVkFileUploadParam
add processing file upload errors
git-svn-id: http://svn.miranda-ng.org/main/trunk@10722 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/VKontakte/src/misc.cpp | 15 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk.h | 8 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_files.cpp | 80 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_proto.cpp | 2 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_proto.h | 15 |
5 files changed, 85 insertions, 35 deletions
diff --git a/protocols/VKontakte/src/misc.cpp b/protocols/VKontakte/src/misc.cpp index 50ffe7a86b..9d299a31cc 100644 --- a/protocols/VKontakte/src/misc.cpp +++ b/protocols/VKontakte/src/misc.cpp @@ -100,6 +100,8 @@ bool CVkProto::CheckJsonResult(AsyncHttpRequest *pReq, NETLIBHTTPREQUEST *reply, int iErrorCode = json_as_int(pErrorCode);
debugLogA("CVkProto::CheckJsonResult %d", iErrorCode);
+ CVkFileUploadParam * fup = (CVkFileUploadParam *)pReq->pUserInfo;
+ CVkSendMsgParam *param = (CVkSendMsgParam*)pReq->pUserInfo;
switch (iErrorCode){
case VKERR_AUTHORIZATION_FAILED:
ConnectionFailed(LOGINERR_WRONGPASSWORD);
@@ -107,6 +109,17 @@ bool CVkProto::CheckJsonResult(AsyncHttpRequest *pReq, NETLIBHTTPREQUEST *reply, case VKERR_CAPTCHA_NEEDED:
ApplyCaptcha(pReq, pError);
break;
+ case VKERR_COULD_NOT_SAVE_FILE:
+ case VKERR_INVALID_ALBUM_ID:
+ case VKERR_INVALID_SERVER:
+ case VKERR_INVALID_HASH:
+ case VKERR_INVALID_AUDIO:
+ case VKERR_AUDIO_DEL_COPYRIGHT:
+ case VKERR_INVALID_FILENAME:
+ case VKERR_INVALID_FILESIZE:
+ if (fup)
+ fup->iErrorCode = iErrorCode;
+ break;
case VKERR_UNKNOWN:
case VKERR_TOO_MANY_REQ_PER_SEC:
case VKERR_FLOOD_CONTROL:
@@ -125,7 +138,6 @@ bool CVkProto::CheckJsonResult(AsyncHttpRequest *pReq, NETLIBHTTPREQUEST *reply, case VKERR_HIMSELF_AS_FRIEND:
case VKERR_YOU_ON_BLACKLIST:
case VKERR_USER_ON_BLACKLIST:
- CVkSendMsgParam *param = (CVkSendMsgParam*)pReq->pUserInfo;
if (param)
param->iCount = iErrorCode;
break;
@@ -141,7 +153,6 @@ void CVkProto::OnReceiveSmth(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) debugLogA("CVkProto::OnReceiveSmth %s", json_as_string(pResponse));
}
-
/////////////////////////////////////////////////////////////////////////////////////////
static IconItem iconList[] =
diff --git a/protocols/VKontakte/src/vk.h b/protocols/VKontakte/src/vk.h index f85659968c..9477be3d1c 100644 --- a/protocols/VKontakte/src/vk.h +++ b/protocols/VKontakte/src/vk.h @@ -50,6 +50,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #define VKERR_FLOOD_CONTROL 9 // Flood control
#define VKERR_INTERNAL_SERVER_ERR 10 // Internal server error
#define VKERR_CAPTCHA_NEEDED 14 // Captcha needed
+#define VKERR_COULD_NOT_SAVE_FILE 105 // Couldn't save file
+#define VKERR_INVALID_ALBUM_ID 114 // Invalid album id
+#define VKERR_INVALID_SERVER 118 // Invalid server
+#define VKERR_INVALID_HASH 121 // Invalid hash
+#define VKERR_INVALID_AUDIO 123 // Invalid audio
+#define VKERR_AUDIO_DEL_COPYRIGHT 270 // The audio file was removed by the copyright holder and cannot be reuploaded.
+#define VKERR_INVALID_FILENAME 301 // Invalid filename
+#define VKERR_INVALID_FILESIZE 302 // Invalid filesize
#define VKERR_HIMSELF_AS_FRIEND 174 // Cannot add user himself as friend
#define VKERR_YOU_ON_BLACKLIST 175 // Cannot add this user to friends as they have put you on their blacklist
#define VKERR_USER_ON_BLACKLIST 176 // Cannot add this user to friends as you put him on blacklist
diff --git a/protocols/VKontakte/src/vk_files.cpp b/protocols/VKontakte/src/vk_files.cpp index 1a372d9b4d..8d19508bb4 100644 --- a/protocols/VKontakte/src/vk_files.cpp +++ b/protocols/VKontakte/src/vk_files.cpp @@ -23,14 +23,14 @@ int CVkProto::FileDeny(MCONTACT hContact, HANDLE hTransfer, const PROTOCHAR *rea int CVkProto::FileResume(HANDLE hTransfer, int *action, const PROTOCHAR **filename) { return 1; }
int CVkProto::RecvFile(MCONTACT hContact, PROTORECVFILET *) { return 1; }
-FileUploadParam::FileUploadParam(MCONTACT _hContact, const PROTOCHAR* _desc, PROTOCHAR** _files):
-hContact(_hContact), filetype(typeInvalid), atr(NULL), fname(NULL)
+CVkFileUploadParam::CVkFileUploadParam(MCONTACT _hContact, const PROTOCHAR* _desc, PROTOCHAR** _files) :
+hContact(_hContact), filetype(typeInvalid), atr(NULL), fname(NULL), iErrorCode(0)
{
Desc = mir_tstrdup(_desc);
FileName = mir_tstrdup(_files[0]);
}
-FileUploadParam::~FileUploadParam()
+CVkFileUploadParam::~CVkFileUploadParam()
{
mir_free(Desc);
mir_free(FileName);
@@ -38,7 +38,7 @@ FileUploadParam::~FileUploadParam() mir_free(fname);
}
-FileUploadParam::VKFileType FileUploadParam::GetType()
+CVkFileUploadParam::VKFileType CVkFileUploadParam::GetType()
{
if (filetype != typeInvalid)
return filetype;
@@ -54,15 +54,15 @@ FileUploadParam::VKFileType FileUploadParam::GetType() fname = mir_strdup(fn.GetBuffer());
if (tlstrstr(img, EXT)){
- filetype = FileUploadParam::typeImg;
+ filetype = CVkFileUploadParam::typeImg;
atr = mir_strdup("photo");
}
else if (tlstrstr(audio, EXT)){
- filetype = FileUploadParam::typeAudio;
+ filetype = CVkFileUploadParam::typeAudio;
atr = mir_strdup("file");
}
else{
- filetype = FileUploadParam::typeDoc;
+ filetype = CVkFileUploadParam::typeDoc;
atr = mir_strdup("file");
}
@@ -72,21 +72,51 @@ FileUploadParam::VKFileType FileUploadParam::GetType() HANDLE CVkProto::SendFile(MCONTACT hContact, const PROTOCHAR *desc, PROTOCHAR **files)
{
debugLogA("CVkProto::SendFile");
- FileUploadParam *fup = new FileUploadParam(hContact, desc, files);
+ CVkFileUploadParam *fup = new CVkFileUploadParam(hContact, desc, files);
ForkThread(&CVkProto::SendFileThread, (void *)fup);
return (HANDLE)fup;
}
-void CVkProto::SendFileFiled(FileUploadParam *fup, TCHAR *reason)
+void CVkProto::SendFileFiled(CVkFileUploadParam *fup, TCHAR *reason)
{
- debugLog(L"CVkProto::SendFileFiled <%s>", reason);
+ debugLog(L"CVkProto::SendFileFiled <%s> Error code <%d>", reason, fup->iErrorCode);
ProtoBroadcastAck(fup->hContact, ACKTYPE_FILE, ACKRESULT_FAILED, (HANDLE)fup, 0);
+ CMString tszError;
+ switch (fup->iErrorCode){
+ case VKERR_COULD_NOT_SAVE_FILE:
+ tszError = TranslateT("Couldn't save file");
+ break;
+ case VKERR_INVALID_ALBUM_ID:
+ tszError = TranslateT("Invalid album id");
+ break;
+ case VKERR_INVALID_SERVER:
+ tszError = TranslateT("Invalid server");
+ break;
+ case VKERR_INVALID_HASH:
+ tszError = TranslateT("Invalid hash");
+ break;
+ case VKERR_INVALID_AUDIO:
+ tszError = TranslateT("Invalid audio");
+ break;
+ case VKERR_AUDIO_DEL_COPYRIGHT:
+ tszError = TranslateT("The audio file was removed by the copyright holder and cannot be reuploaded");
+ break;
+ case VKERR_INVALID_FILENAME:
+ tszError = TranslateT("Invalid filename");
+ break;
+ case VKERR_INVALID_FILESIZE:
+ tszError = TranslateT("Invalid filesize");
+ break;
+ default:
+ tszError = TranslateT("Unknown error occurred");
+ }
+ MsgPopup(NULL, tszError.GetBuffer(), TranslateT("File upload error"), true);
delete fup;
}
void CVkProto::SendFileThread(void *p)
{
- FileUploadParam *fup = (FileUploadParam *)p;
+ CVkFileUploadParam *fup = (CVkFileUploadParam *)p;
debugLog(L"CVkProto::SendFileThread %d %s", fup->GetType(), fup->fileName());
if (!fup->IsAccess()){
SendFileFiled(fup, L"FileIsNotAccess");
@@ -95,15 +125,15 @@ void CVkProto::SendFileThread(void *p) AsyncHttpRequest *pReq;
switch (fup->GetType()){
- case FileUploadParam::typeImg:
+ case CVkFileUploadParam::typeImg:
pReq = new AsyncHttpRequest(this, REQUEST_GET, "/method/photos.getMessagesUploadServer.json", true, &CVkProto::OnReciveUploadServer)
<< VER_API;
break;
- case FileUploadParam::typeAudio:
+ case CVkFileUploadParam::typeAudio:
pReq = new AsyncHttpRequest(this, REQUEST_GET, "/method/audio.getUploadServer.json", true, &CVkProto::OnReciveUploadServer)
<< VER_API;
break;
- case FileUploadParam::typeDoc:
+ case CVkFileUploadParam::typeDoc:
pReq = new AsyncHttpRequest(this, REQUEST_GET, "/method/docs.getUploadServer.json", true, &CVkProto::OnReciveUploadServer)
<< VER_API;
break;
@@ -117,7 +147,7 @@ void CVkProto::SendFileThread(void *p) void CVkProto::OnReciveUploadServer(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
{
- FileUploadParam *fup = (FileUploadParam *)pReq->pUserInfo;
+ CVkFileUploadParam *fup = (CVkFileUploadParam *)pReq->pUserInfo;
debugLogA("CVkProto::OnReciveUploadServer %d", reply->resultCode);
if (reply->resultCode != 200){
@@ -197,7 +227,7 @@ void CVkProto::OnReciveUploadServer(NETLIBHTTPREQUEST *reply, AsyncHttpRequest * void CVkProto::OnReciveUpload(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
{
- FileUploadParam *fup = (FileUploadParam *)pReq->pUserInfo;
+ CVkFileUploadParam *fup = (CVkFileUploadParam *)pReq->pUserInfo;
debugLogA("CVkProto::OnReciveUploadServer %d", reply->resultCode);
if (reply->resultCode != 200){
@@ -215,7 +245,7 @@ void CVkProto::OnReciveUpload(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) AsyncHttpRequest *pUploadReq;
switch (fup->GetType()){
- case FileUploadParam::typeImg:
+ case CVkFileUploadParam::typeImg:
upload = json_as_string(json_get(pRoot, "photo"));
if (upload == L"[]"){
SendFileFiled(fup, L"NotUpload Photo");
@@ -226,7 +256,7 @@ void CVkProto::OnReciveUpload(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) << TCHAR_PARAM("hash", hash)
<< VER_API;
break;
- case FileUploadParam::typeAudio:
+ case CVkFileUploadParam::typeAudio:
upload = json_as_string(json_get(pRoot, "audio"));
if (upload == L"[]"){
SendFileFiled(fup, L"NotUpload Audio");
@@ -238,7 +268,7 @@ void CVkProto::OnReciveUpload(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) << TCHAR_PARAM("hash", hash)
<< VER_API;
break;
- case FileUploadParam::typeDoc:
+ case CVkFileUploadParam::typeDoc:
upload = json_as_string(json_get(pRoot, "file"));
if (upload.IsEmpty()){
SendFileFiled(fup, L"NotUpload Doc");
@@ -260,7 +290,7 @@ void CVkProto::OnReciveUpload(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) void CVkProto::OnReciveUploadFile(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
{
- FileUploadParam *fup = (FileUploadParam *)pReq->pUserInfo;
+ CVkFileUploadParam *fup = (CVkFileUploadParam *)pReq->pUserInfo;
debugLogA("CVkProto::OnReciveUploadFile %d", reply->resultCode);
if (reply->resultCode != 200){
@@ -275,8 +305,8 @@ void CVkProto::OnReciveUploadFile(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pR return;
}
- 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"));
+ int id = json_as_int(json_get(fup->GetType() == CVkFileUploadParam::typeAudio ? pResponse : json_at(pResponse, 0), "id"));
+ int owner_id = json_as_int(json_get(fup->GetType() == CVkFileUploadParam::typeAudio ? pResponse : json_at(pResponse, 0), "owner_id"));
if ((id == 0) || (owner_id == 0)){
SendFileFiled(fup);
return;
@@ -285,13 +315,13 @@ void CVkProto::OnReciveUploadFile(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pR CMString Attachment;
switch (fup->GetType()){
- case FileUploadParam::typeImg:
+ case CVkFileUploadParam::typeImg:
Attachment.AppendFormat(L"photo%d_%d", owner_id, id);
break;
- case FileUploadParam::typeAudio:
+ case CVkFileUploadParam::typeAudio:
Attachment.AppendFormat(L"audio%d_%d", owner_id, id);
break;
- case FileUploadParam::typeDoc:
+ case CVkFileUploadParam::typeDoc:
Attachment.AppendFormat(L"doc%d_%d", owner_id, id);
break;
default:
diff --git a/protocols/VKontakte/src/vk_proto.cpp b/protocols/VKontakte/src/vk_proto.cpp index d7d46d6f40..830e1f6cb1 100644 --- a/protocols/VKontakte/src/vk_proto.cpp +++ b/protocols/VKontakte/src/vk_proto.cpp @@ -385,7 +385,7 @@ void CVkProto::OnSendMessage(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) }
if (param->iMsgID == -1){
- FileUploadParam *fup = (FileUploadParam *)param->iCount;
+ CVkFileUploadParam *fup = (CVkFileUploadParam *)param->iCount;
ProtoBroadcastAck(fup->hContact, ACKTYPE_FILE, iResult, (HANDLE)fup, 0);
delete fup;
}
diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h index 0298598752..84796e4188 100644 --- a/protocols/VKontakte/src/vk_proto.h +++ b/protocols/VKontakte/src/vk_proto.h @@ -131,7 +131,7 @@ struct CVkChatInfo : public MZeroedObject CVkChatUser* GetUserById(LPCTSTR);
};
-struct FileUploadParam {
+struct CVkFileUploadParam {
enum VKFileType {typeInvalid, typeImg, typeAudio, typeDoc, typeNotSupported};
TCHAR* FileName;
TCHAR* Desc;
@@ -139,13 +139,14 @@ struct FileUploadParam { char* fname;
MCONTACT hContact;
VKFileType filetype;
+ int iErrorCode;
- FileUploadParam(MCONTACT _hContact, const PROTOCHAR* _desc, PROTOCHAR** _files);
- ~FileUploadParam();
+ CVkFileUploadParam(MCONTACT _hContact, const PROTOCHAR* _desc, PROTOCHAR** _files);
+ ~CVkFileUploadParam();
VKFileType GetType();
- __forceinline bool FileUploadParam::IsAccess() {return ::_taccess(FileName, 0)==0; }
- __forceinline char* FileUploadParam::atrName() { return atr; }
- __forceinline char* FileUploadParam::fileName() { return fname; }
+ __forceinline bool IsAccess() { return ::_taccess(FileName, 0) == 0; }
+ __forceinline char* atrName() { return atr; }
+ __forceinline char* fileName() { return fname; }
};
struct CVkProto : public PROTO<CVkProto>
@@ -246,7 +247,7 @@ struct CVkProto : public PROTO<CVkProto> //==== Files Upload ==================================================================
void __cdecl SendFileThread(void *p);
- void SendFileFiled(FileUploadParam *fup, TCHAR* reason=NULL);
+ void SendFileFiled(CVkFileUploadParam *fup, TCHAR* reason = NULL);
void OnReciveUploadServer(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void OnReciveUpload(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void OnReciveUploadFile(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
|