summaryrefslogtreecommitdiff
path: root/plugins/SendScreenshotPlus/src/CSendHost_imgur.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2015-07-29 21:18:27 +0000
committerGeorge Hazan <george.hazan@gmail.com>2015-07-29 21:18:27 +0000
commit1271802f514d41e8e06df7714d1f1e4a430b417b (patch)
tree5bd4ef52613333cba786f1246414e422a5e4c95a /plugins/SendScreenshotPlus/src/CSendHost_imgur.cpp
parent14d0ed2003485ebf19d45672b065a7dd2bf5274a (diff)
- warning fixes;
- code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@14757 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/SendScreenshotPlus/src/CSendHost_imgur.cpp')
-rw-r--r--plugins/SendScreenshotPlus/src/CSendHost_imgur.cpp81
1 files changed, 40 insertions, 41 deletions
diff --git a/plugins/SendScreenshotPlus/src/CSendHost_imgur.cpp b/plugins/SendScreenshotPlus/src/CSendHost_imgur.cpp
index 6b1b638083..d3fe40ce74 100644
--- a/plugins/SendScreenshotPlus/src/CSendHost_imgur.cpp
+++ b/plugins/SendScreenshotPlus/src/CSendHost_imgur.cpp
@@ -16,38 +16,39 @@
#include "stdafx.h"
CSendHost_Imgur::CSendHost_Imgur(HWND Owner, MCONTACT hContact, bool bAsync)
- : CSend(Owner,hContact,bAsync)
+ : CSend(Owner, hContact, bAsync)
{
- m_EnableItem=SS_DLG_DESCRIPTION|SS_DLG_AUTOSEND|SS_DLG_DELETEAFTERSSEND;
- m_pszSendTyp=LPGENT("Image upload");
+ m_EnableItem = SS_DLG_DESCRIPTION | SS_DLG_AUTOSEND | SS_DLG_DELETEAFTERSSEND;
+ m_pszSendTyp = LPGENT("Image upload");
}
CSendHost_Imgur::~CSendHost_Imgur()
-{}
+{
+}
//---------------------------------------------------------------------------
int CSendHost_Imgur::Send()
{
- if(!g_hNetlibUser){ /// check Netlib
+ if (!g_hNetlibUser) { /// check Netlib
Error(SS_ERR_INIT, m_pszSendTyp);
Exit(ACKRESULT_FAILED);
return !m_bAsync;
}
memset(&m_nlhr, 0, sizeof(m_nlhr));
- char* tmp; tmp=mir_t2a(m_pszFile);
- HTTPFormData frm[]={
- {"Authorization",HTTPFORM_HEADER("Client-ID 2a7303d78abe041")},
- {"image",HTTPFORM_FILE(tmp)},
-// {"name",""},// filename (detected if multipart / form-data)
-// {"title",""},
-// {"description",""},
+ char* tmp; tmp = mir_t2a(m_pszFile);
+ HTTPFormData frm[] = {
+ { "Authorization", HTTPFORM_HEADER("Client-ID 2a7303d78abe041") },
+ { "image", HTTPFORM_FILE(tmp) },
+ // {"name",""},// filename (detected if multipart / form-data)
+ // {"title",""},
+ // {"description",""},
};
- int error=HTTPFormCreate(&m_nlhr,REQUEST_POST,"https://api.imgur.com/3/image",frm,sizeof(frm)/sizeof(HTTPFormData));
+ int error = HTTPFormCreate(&m_nlhr, REQUEST_POST, "https://api.imgur.com/3/image", frm, sizeof(frm) / sizeof(HTTPFormData));
mir_free(tmp);
- if(error)
+ if (error)
return !m_bAsync;
/// start upload thread
- if(m_bAsync){
+ if (m_bAsync) {
mir_forkthread(&CSendHost_Imgur::SendThread, this);
return 0;
}
@@ -57,39 +58,37 @@ int CSendHost_Imgur::Send()
void CSendHost_Imgur::SendThread(void* obj)
{
- CSendHost_Imgur* self=(CSendHost_Imgur*)obj;
+ CSendHost_Imgur* self = (CSendHost_Imgur*)obj;
/// send DATA and wait for m_nlreply
- NETLIBHTTPREQUEST* reply=(NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION,(WPARAM)g_hNetlibUser,(LPARAM)&self->m_nlhr);
+ NETLIBHTTPREQUEST* reply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)g_hNetlibUser, (LPARAM)&self->m_nlhr);
self->HTTPFormDestroy(&self->m_nlhr);
- if(reply){
- if(reply->dataLength){
+ if (reply) {
+ if (reply->dataLength) {
char buf[128];
-// GetJSONInteger(reply->pData,reply->dataLength,"status",0)
- if(GetJSONBool(reply->pData,reply->dataLength,"success")){
-// GetJSONString(reply->pData,reply->dataLength,"data[id]",buf,sizeof(buf));
- GetJSONString(reply->pData,reply->dataLength,"data[link]",buf,sizeof(buf));
-// GetJSONString(reply->pData,reply->dataLength,"[data][deletehash]",buf,sizeof(buf));
- mir_free(self->m_URL), self->m_URL=mir_strdup(buf);
- char* ext=strrchr(self->m_URL,'.');
- if(ext){
- size_t thumblen=mir_strlen(self->m_URL)+2;
- mir_free(self->m_URLthumb), self->m_URLthumb=(char*)mir_alloc(thumblen);
- thumblen=ext-self->m_URL;
- memcpy(self->m_URLthumb,self->m_URL,thumblen);
- self->m_URLthumb[thumblen]='m'; // 320x320, see http://api.imgur.com/models/image
- mir_strcpy(self->m_URLthumb+thumblen+1,self->m_URL+thumblen);
+
+ if (GetJSONBool(reply->pData, reply->dataLength, "success")) {
+ GetJSONString(reply->pData, reply->dataLength, "data[link]", buf, sizeof(buf));
+
+ mir_free(self->m_URL), self->m_URL = mir_strdup(buf);
+ char* ext = strrchr(self->m_URL, '.');
+ if (ext) {
+ size_t thumblen = mir_strlen(self->m_URL) + 2;
+ mir_free(self->m_URLthumb), self->m_URLthumb = (char*)mir_alloc(thumblen);
+ thumblen = ext - self->m_URL;
+ memcpy(self->m_URLthumb, self->m_URL, thumblen);
+ self->m_URLthumb[thumblen] = 'm'; // 320x320, see http://api.imgur.com/models/image
+ mir_strcpy(self->m_URLthumb + thumblen + 1, self->m_URL + thumblen);
}
- CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT,0,(LPARAM)reply);
+ CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)reply);
self->svcSendMsgExit(self->m_URL); return;
- }else{
- self->Error(SS_ERR_RESPONSE,self->m_pszSendTyp,GetJSONInteger(reply->pData,reply->dataLength,"status",0));
}
- }else{
- self->Error(SS_ERR_RESPONSE,self->m_pszSendTyp,reply->resultCode);
+ else self->Error(SS_ERR_RESPONSE, self->m_pszSendTyp, GetJSONInteger(reply->pData, reply->dataLength, "status", 0));
}
- CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT,0,(LPARAM)reply);
- }else{
- self->Error(SS_ERR_NORESPONSE,self->m_pszSendTyp,self->m_nlhr.resultCode);
+ else self->Error(SS_ERR_RESPONSE, self->m_pszSendTyp, reply->resultCode);
+
+ CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)reply);
}
+ else self->Error(SS_ERR_NORESPONSE, self->m_pszSendTyp, self->m_nlhr.resultCode);
+
self->Exit(ACKRESULT_FAILED);
}