From 814ff2e2b838bdefb42f2af358f358446025c8d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Sch=C3=BCmann?= Date: Sat, 28 Jun 2014 23:29:27 +0000 Subject: SendSS v0.8.6.0: + imgur.com support by user requests (anonymous upload only) (CSendHost_imgur,CSend,global.h,UMainForm) this also include basic functions for JSON parsing (currently only JSON without spaces and arrays) (CSend) SSL/HTTPS support for HTTPFormCreate (CSend) support for custom headers in HTTPFormCreate (CSend) * updated ImageShack related filenames. * very minor misc code changes and improvements (comments, error messages) git-svn-id: http://svn.miranda-ng.org/main/trunk@9606 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/SendScreenshotPlus/src/CSend.cpp | 148 ++++++++++++++++++++- plugins/SendScreenshotPlus/src/CSend.h | 13 +- .../src/CSendHost_ImageShack.cpp | 119 +++++++++++++++++ .../SendScreenshotPlus/src/CSendHost_ImageShack.h | 51 +++++++ plugins/SendScreenshotPlus/src/CSendHost_imgur.cpp | 95 +++++++++++++ plugins/SendScreenshotPlus/src/CSendHost_imgur.h | 28 ++++ .../SendScreenshotPlus/src/CSendHost_uploadpie.cpp | 6 +- plugins/SendScreenshotPlus/src/CSendImageShack.cpp | 118 ---------------- plugins/SendScreenshotPlus/src/CSendImageShack.h | 51 ------- plugins/SendScreenshotPlus/src/Main.cpp | 2 +- plugins/SendScreenshotPlus/src/UMainForm.cpp | 6 +- plugins/SendScreenshotPlus/src/UMainForm.h | 1 + plugins/SendScreenshotPlus/src/global.h | 3 +- plugins/SendScreenshotPlus/src/version.h | 4 +- 14 files changed, 463 insertions(+), 182 deletions(-) create mode 100644 plugins/SendScreenshotPlus/src/CSendHost_ImageShack.cpp create mode 100644 plugins/SendScreenshotPlus/src/CSendHost_ImageShack.h create mode 100644 plugins/SendScreenshotPlus/src/CSendHost_imgur.cpp create mode 100644 plugins/SendScreenshotPlus/src/CSendHost_imgur.h delete mode 100644 plugins/SendScreenshotPlus/src/CSendImageShack.cpp delete mode 100644 plugins/SendScreenshotPlus/src/CSendImageShack.h (limited to 'plugins/SendScreenshotPlus/src') diff --git a/plugins/SendScreenshotPlus/src/CSend.cpp b/plugins/SendScreenshotPlus/src/CSend.cpp index f0c800004e..cb18639223 100644 --- a/plugins/SendScreenshotPlus/src/CSend.cpp +++ b/plugins/SendScreenshotPlus/src/CSend.cpp @@ -462,6 +462,140 @@ const char* CSend::GetHTMLContent(char* str, const char* startTag, const char* e } return begin; } +int JSON_ParseData_(const char** jsondata,size_t jsonlen,const char** rawdata){ + const char* c=*jsondata; + const char* jsonend=*jsondata+jsonlen; + int len=0; + *rawdata=NULL; + if(c==jsonend) + return 0; + if(*c=='{'){ // scope (object) + *rawdata=c; + do{ + if(*c=='{') ++len; + else if(*c=='}') --len; + if(++c==jsonend) + return 0; + }while(len>0); + len=c-*rawdata; + if(*c==',') ++c; + }else if(*c=='"' || *c=='\''){ // string + char needle=*c; + if(++c==jsonend) + return 0; + *rawdata=c; + do{ + if(c==jsonend || (*c=='\\' && ++c==jsonend)) + return 0; + }while(*c++!=needle); + len=c-*rawdata-1; + if(*c==',') ++c; + }else{ // other + for(*rawdata=c; c=jsonend || *++c!=':') break; + /// read data + ++c; + if(!strcmp(var,needle)){ + int datalen=JSON_ParseData_(&c,jsonend-c,value); + if(!datalen) + return 0; + if(*needlechild && **value=='{'){ // we need a child value, parse child object + return JSON_Get_(*value,datalen,needlechild,value); + } + return datalen; + }else{ + JSON_ParseData_(&c,jsonend-c,value); + } + } + *value=NULL; + return 0; +} +int CSend::GetJSONString(const char* json, size_t jsonlen, const char* variable, char* value, size_t valuesize) { + if(!jsonlen || !valuesize) + return 0; + const char* rawvalue; + int rawlen=JSON_Get_(json,jsonlen,variable,&rawvalue); + if(rawlen){ + size_t out=0; + --valuesize; + /// copy & parse escape sequences + for(int in=0; in'9') break; + defvalue*=10; + defvalue+=rawvalue[offset]-'0'; + } + } + return defvalue; +} +bool CSend::GetJSONBool(const char* json, size_t jsonlen, const char* variable) { + const char* rawvalue; + int rawlen=JSON_Get_(json,jsonlen,variable,&rawvalue); + if(rawlen){ + if(rawlen==4 && !memcmp(rawvalue,"true",4)) + return true; + if(*rawvalue>'0' && *rawvalue<='9') + return true; + } + return false; +} static void HTTPFormAppendData(NETLIBHTTPREQUEST* nlhr, size_t* dataMax, char** dataPos, const char* data,size_t len){ nlhr->dataLength=(*dataPos-nlhr->pData); @@ -505,8 +639,13 @@ int CSend::HTTPFormCreate(NETLIBHTTPREQUEST* nlhr,int requestType,char* url,HTTP nlhr->cbSize =sizeof(NETLIBHTTPREQUEST); nlhr->requestType =requestType; nlhr->flags =NLHRF_HTTP11; + if(!strncmp(url,"https://",8)) nlhr->flags|=NLHRF_SSL; nlhr->szUrl =url; nlhr->headersCount =3; + for(HTTPFormData* iter=frm,* end=frm+frmNum; iter!=end; ++iter){ + if(!(iter->flags&HTTPFF_HEADER)) break; + ++nlhr->headersCount; + } nlhr->headers =(NETLIBHTTPHEADER*)mir_alloc(sizeof(NETLIBHTTPHEADER)*nlhr->headersCount); { char* contenttype=(char*)mir_alloc(sizeof(char)*(30+1+sizeof(boundary))); @@ -519,12 +658,17 @@ int CSend::HTTPFormCreate(NETLIBHTTPREQUEST* nlhr,int requestType,char* url,HTTP nlhr->headers[1].szValue =__USER_AGENT_STRING; nlhr->headers[2].szName ="Accept-Language"; nlhr->headers[2].szValue ="en-us,en;q=0.8"; -// nlhr->headers[3].szName ="Referer"; -// nlhr->headers[3].szValue ="http://www.imageshack.us/upload_api.php"; + int i=3; + for(HTTPFormData* iter=frm,* end=frm+frmNum; iter!=end; ++iter){ + if(!(iter->flags&HTTPFF_HEADER)) break; + nlhr->headers[i].szName=(char*)iter->name; + nlhr->headers[i++].szValue=(char*)iter->value_str; + } } char* dataPos=nlhr->pData; size_t dataMax=0; for(HTTPFormData* iter=frm,* end=frm+frmNum; iter!=end; ++iter){ + if(iter->flags&HTTPFF_HEADER) continue; HTTPFormAppendData(nlhr,&dataMax,&dataPos,NULL,2+sizeof(boundary)+40); memset(dataPos,'-',2); dataPos+=2; memcpy(dataPos,boundary,sizeof(boundary)); dataPos+=sizeof(boundary); diff --git a/plugins/SendScreenshotPlus/src/CSend.h b/plugins/SendScreenshotPlus/src/CSend.h index 16ab0f192e..e9e57a9199 100644 --- a/plugins/SendScreenshotPlus/src/CSend.h +++ b/plugins/SendScreenshotPlus/src/CSend.h @@ -42,8 +42,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define GC_RESULT_ERROR 202 #define GC_RESULT_NOSESSION 209 -#define SS_ERR_INIT LPGENT("Unable to initiate %s.") -#define SS_ERR_MAPI LPGENT("MAPI error (%i):\n%s.") +const TCHAR SS_ERR_INIT[] =LPGENT("Unable to initiate %s."); +const TCHAR SS_ERR_MAPI[] =LPGENT("MAPI error (%i):\n%s."); +const TCHAR SS_ERR_RESPONSE[] =LPGENT("Unknown response from %s (%i)"); +const TCHAR SS_ERR_NORESPONSE[] =LPGENT("Got no response from %s (%i)"); //--------------------------------------------------------------------------- class CSend { @@ -102,15 +104,17 @@ class CSend { /// HTTP upload helper stuff enum HTTPFormFlags{ + HTTPFF_HEADER=0x80, HTTPFF_TEXT =0x00, HTTPFF_8BIT =0x01, HTTPFF_FILE =0x02, HTTPFF_INT =0x04, }; + #define HTTPFORM_HEADER(str) str,HTTPFF_HEADER #define HTTPFORM_TEXT(str) str,HTTPFF_TEXT #define HTTPFORM_8BIT(str) str,HTTPFF_8BIT #define HTTPFORM_FILE(str) str,HTTPFF_FILE - #define HTTPFORM_INT(int) (const char*)int,HTTPFF_INT + #define HTTPFORM_INT(int) (const char*)(int),HTTPFF_INT struct HTTPFormData{ const char* name; union{ @@ -120,6 +124,9 @@ class CSend { int flags; }; static const char* GetHTMLContent(char* str, const char* startTag, const char* endTag); /// changes "str", can be successfully used only once + static int GetJSONString(const char* json, size_t jsonlen, const char* variable, char* value, size_t valuesize); + static int GetJSONInteger(const char* json, size_t jsonlen, const char* variable,int defvalue); + static bool GetJSONBool(const char* json, size_t jsonlen, const char* variable); void HTTPFormDestroy(NETLIBHTTPREQUEST* nlhr); /// use to free data inside "nlhr" created by HTTPFormCreate int HTTPFormCreate(NETLIBHTTPREQUEST* nlhr,int requestType,char* url,HTTPFormData* frm,size_t frmNum); /// returns "0" on success, Exit() will be called on failure (stop processing) }; diff --git a/plugins/SendScreenshotPlus/src/CSendHost_ImageShack.cpp b/plugins/SendScreenshotPlus/src/CSendHost_ImageShack.cpp new file mode 100644 index 0000000000..b4dc0dde92 --- /dev/null +++ b/plugins/SendScreenshotPlus/src/CSendHost_ImageShack.cpp @@ -0,0 +1,119 @@ +/* + +Miranda NG: the free IM client for Microsoft* Windows* + +Copyright (c) 2012-14 Miranda NG project (http://miranda-ng.org), +Copyright (c) 2000-09 Miranda ICQ/IM project, + +This file is part of Send Screenshot Plus, a Miranda IM plugin. +Copyright (c) 2010 Ing.U.Horn + +Parts of this file based on original sorce code +(c) 2004-2006 Sérgio Vieira Rolanski (portet from Borland C++) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +//--------------------------------------------------------------------------- +#include "global.h" + +//--------------------------------------------------------------------------- +CSendHost_ImageShack::CSendHost_ImageShack(HWND Owner, MCONTACT hContact, bool bAsync) +: CSend(Owner, hContact, bAsync) { + m_EnableItem = SS_DLG_DESCRIPTION | SS_DLG_AUTOSEND | SS_DLG_DELETEAFTERSSEND; + m_pszSendTyp = LPGENT("Image upload"); +} + +CSendHost_ImageShack::~CSendHost_ImageShack(){ +}; + +//--------------------------------------------------------------------------- +int CSendHost_ImageShack::Send() { + if(!hNetlibUser){ /// check Netlib + Error(SS_ERR_INIT, m_pszSendTyp); + Exit(ACKRESULT_FAILED); + return !m_bAsync; + } + ZeroMemory(&m_nlhr, sizeof(m_nlhr)); + char* tmp; tmp=mir_t2a(m_pszFile); + HTTPFormData frm[]={ +// {"Referer",HTTPFORM_HEADER("http://www.imageshack.us/upload_api.php")}, + {"fileupload",HTTPFORM_FILE(tmp)}, + //{"rembar","yes"},// no info bar on thumb + {"public","no"}, + {"key",HTTPFORM_8BIT(DEVKEY_IMAGESHACK)}, + }; + int error=HTTPFormCreate(&m_nlhr,REQUEST_POST,"http://imageshack.us/upload_api.php",frm,sizeof(frm)/sizeof(HTTPFormData)); + mir_free(tmp); + if(error) + return !m_bAsync; + /// start upload thread + if(m_bAsync){ + mir_forkthread(&CSendHost_ImageShack::SendThreadWrapper, this); + return 0; + } + SendThread(); + return 1; +} + +void CSendHost_ImageShack::SendThread() { + /// send DATA and wait for m_nlreply + NETLIBHTTPREQUEST* reply=(NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)hNetlibUser, (LPARAM)&m_nlhr); + HTTPFormDestroy(&m_nlhr); + if(reply){ + if(reply->resultCode>=200 && reply->resultCode<300 && reply->dataLength){ + reply->pData[reply->dataLength-1]='\0';/// make sure its null terminated + const char* url=NULL; + url=GetHTMLContent(reply->pData,"",""); + if(url && *url){ + mir_free(m_URL), m_URL=mir_strdup(url); + mir_free(m_URLthumb), m_URLthumb=mir_strdup(m_URL); + size_t extlen; + char* pos=strrchr(m_URLthumb,'.'); + if(pos && (extlen=mir_strlen(pos))>2){ + char* tmp=mir_strdup(pos); + memcpy(pos,".th",3); + memcpy(pos+3,tmp,extlen-3); + mir_stradd(m_URLthumb,tmp+extlen-3); + mir_free(tmp); + }else{ + mir_freeAndNil(m_URLthumb); + } + CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT,0,(LPARAM)reply); + svcSendMsgExit(url); return; + }else{/// check error mess from server + url=GetHTMLContent(reply->pData,""); + TCHAR* err=NULL; + if(url) err=mir_a2t(url); + if (!err || !*err){/// fallback to server response mess + mir_free(err); + err=mir_a2t(reply->pData); + } + Error(_T("%s"),err); + mir_free(err); + } + }else{ + Error(SS_ERR_RESPONSE,m_pszSendTyp,reply->resultCode); + } + CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT,0,(LPARAM)reply); + }else{ + Error(SS_ERR_NORESPONSE,m_pszSendTyp,m_nlhr.resultCode); + } + Exit(ACKRESULT_FAILED); +} + +void CSendHost_ImageShack::SendThreadWrapper(void * Obj) { + reinterpret_cast(Obj)->SendThread(); +} diff --git a/plugins/SendScreenshotPlus/src/CSendHost_ImageShack.h b/plugins/SendScreenshotPlus/src/CSendHost_ImageShack.h new file mode 100644 index 0000000000..30e1fdaa21 --- /dev/null +++ b/plugins/SendScreenshotPlus/src/CSendHost_ImageShack.h @@ -0,0 +1,51 @@ +/* + +Miranda NG: the free IM client for Microsoft* Windows* + +Copyright (c) 2012-14 Miranda NG project (http://miranda-ng.org), +Copyright (c) 2000-09 Miranda ICQ/IM project, + +This file is part of Send Screenshot Plus, a Miranda IM plugin. +Copyright (c) 2010 Ing.U.Horn + +Parts of this file based on original sorce code +(c) 2004-2006 Sérgio Vieira Rolanski (portet from Borland C++) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#ifndef _CSEND_IMAGESHACK_H +#define _CSEND_IMAGESHACK_H + +//--------------------------------------------------------------------------- +class CSendHost_ImageShack : public CSend { + public: + // Deklaration Standardkonstruktor/Standarddestructor + CSendHost_ImageShack(HWND Owner, MCONTACT hContact, bool bAsync); + ~CSendHost_ImageShack(); + + int Send(); + + protected: + NETLIBHTTPREQUEST m_nlhr; + + void SendThread(); + static void SendThreadWrapper(void * Obj); + +}; + +//--------------------------------------------------------------------------- + +#endif diff --git a/plugins/SendScreenshotPlus/src/CSendHost_imgur.cpp b/plugins/SendScreenshotPlus/src/CSendHost_imgur.cpp new file mode 100644 index 0000000000..1a4063e710 --- /dev/null +++ b/plugins/SendScreenshotPlus/src/CSendHost_imgur.cpp @@ -0,0 +1,95 @@ +/* + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + + Copyright (C) 2014 Miranda NG project (http://miranda-ng.org) + + Everyone is permitted to copy and distribute verbatim or modified + copies of this license document, and changing it is allowed as long + as the name is changed. + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. You just DO WHAT THE FUCK YOU WANT TO. +*/ +#include "global.h" + +CSendHost_Imgur::CSendHost_Imgur(HWND Owner, MCONTACT hContact, bool bAsync) + : CSend(Owner,hContact,bAsync) +{ + 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(!hNetlibUser){ /// check Netlib + Error(SS_ERR_INIT, m_pszSendTyp); + Exit(ACKRESULT_FAILED); + return !m_bAsync; + } + ZeroMemory(&m_nlhr, 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",""}, + }; + int error=HTTPFormCreate(&m_nlhr,REQUEST_POST,"https://api.imgur.com/3/image",frm,sizeof(frm)/sizeof(HTTPFormData)); + mir_free(tmp); + if(error) + return !m_bAsync; + /// start upload thread + if(m_bAsync){ + mir_forkthread(&CSendHost_Imgur::SendThread, this); + return 0; + } + SendThread(this); + return 1; +} + +void CSendHost_Imgur::SendThread(void* obj) +{ + CSendHost_Imgur* self=(CSendHost_Imgur*)obj; + /// send DATA and wait for m_nlreply + NETLIBHTTPREQUEST* reply=(NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION,(WPARAM)hNetlibUser,(LPARAM)&self->m_nlhr); + self->HTTPFormDestroy(&self->m_nlhr); + 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=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 + strcpy(self->m_URLthumb+thumblen+1,self->m_URL+thumblen); + } + 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); + } + CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT,0,(LPARAM)reply); + }else{ + self->Error(SS_ERR_NORESPONSE,self->m_pszSendTyp,self->m_nlhr.resultCode); + } + self->Exit(ACKRESULT_FAILED); +} diff --git a/plugins/SendScreenshotPlus/src/CSendHost_imgur.h b/plugins/SendScreenshotPlus/src/CSendHost_imgur.h new file mode 100644 index 0000000000..84223ec9f4 --- /dev/null +++ b/plugins/SendScreenshotPlus/src/CSendHost_imgur.h @@ -0,0 +1,28 @@ +/* + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + + Copyright (C) 2014 Miranda NG project (http://miranda-ng.org) + + Everyone is permitted to copy and distribute verbatim or modified + copies of this license document, and changing it is allowed as long + as the name is changed. + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. You just DO WHAT THE FUCK YOU WANT TO. +*/ +#ifndef _CSEND_HOST_IMGUR_H +#define _CSEND_HOST_IMGUR_H +class CSendHost_Imgur : public CSend { +// API: http://api.imgur.com/endpoints/image + public: + CSendHost_Imgur(HWND Owner, MCONTACT hContact, bool bAsync); + ~CSendHost_Imgur(); + int Send(); + protected: + NETLIBHTTPREQUEST m_nlhr; + static void SendThread(void* obj); +}; +#endif diff --git a/plugins/SendScreenshotPlus/src/CSendHost_uploadpie.cpp b/plugins/SendScreenshotPlus/src/CSendHost_uploadpie.cpp index 6a2c7fe48a..73830c7052 100644 --- a/plugins/SendScreenshotPlus/src/CSendHost_uploadpie.cpp +++ b/plugins/SendScreenshotPlus/src/CSendHost_uploadpie.cpp @@ -63,7 +63,7 @@ int CSendHost_UploadPie::Send() void CSendHost_UploadPie::SendThread(void* obj) { CSendHost_UploadPie* self=(CSendHost_UploadPie*)obj; - //send DATA and wait for m_nlreply + /// send DATA and wait for m_nlreply NETLIBHTTPREQUEST* reply=(NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION,(WPARAM)hNetlibUser,(LPARAM)&self->m_nlhr); self->HTTPFormDestroy(&self->m_nlhr); if(reply){ @@ -96,11 +96,11 @@ void CSendHost_UploadPie::SendThread(void* obj) mir_free(werr); } }else{ - self->Error(LPGENT("Upload server did not respond timely.")); + self->Error(SS_ERR_RESPONSE,self->m_pszSendTyp,reply->resultCode); } CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT,0,(LPARAM)reply); }else{ - self->Error(SS_ERR_INIT, self->m_pszSendTyp); + self->Error(SS_ERR_NORESPONSE,self->m_pszSendTyp,self->m_nlhr.resultCode); } self->Exit(ACKRESULT_FAILED); } diff --git a/plugins/SendScreenshotPlus/src/CSendImageShack.cpp b/plugins/SendScreenshotPlus/src/CSendImageShack.cpp deleted file mode 100644 index 9bd0ef0e0f..0000000000 --- a/plugins/SendScreenshotPlus/src/CSendImageShack.cpp +++ /dev/null @@ -1,118 +0,0 @@ -/* - -Miranda NG: the free IM client for Microsoft* Windows* - -Copyright (c) 2012-14 Miranda NG project (http://miranda-ng.org), -Copyright (c) 2000-09 Miranda ICQ/IM project, - -This file is part of Send Screenshot Plus, a Miranda IM plugin. -Copyright (c) 2010 Ing.U.Horn - -Parts of this file based on original sorce code -(c) 2004-2006 Sérgio Vieira Rolanski (portet from Borland C++) - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - -//--------------------------------------------------------------------------- -#include "global.h" - -//--------------------------------------------------------------------------- -CSendImageShack::CSendImageShack(HWND Owner, MCONTACT hContact, bool bAsync) -: CSend(Owner, hContact, bAsync) { - m_EnableItem = SS_DLG_DESCRIPTION | SS_DLG_AUTOSEND | SS_DLG_DELETEAFTERSSEND; - m_pszSendTyp = LPGENT("Image upload"); -} - -CSendImageShack::~CSendImageShack(){ -}; - -//--------------------------------------------------------------------------- -int CSendImageShack::Send() { - if(!hNetlibUser){ /// check Netlib - Error(SS_ERR_INIT, m_pszSendTyp); - Exit(ACKRESULT_FAILED); - return !m_bAsync; - } - ZeroMemory(&m_nlhr, sizeof(m_nlhr)); - char* tmp; tmp=mir_t2a(m_pszFile); - HTTPFormData frm[]={ - {"fileupload",HTTPFORM_FILE(tmp)}, - //{"rembar","yes"},// no info bar on thumb - {"public","no"}, - {"key",HTTPFORM_8BIT(DEVKEY_IMAGESHACK)}, - }; - int error=HTTPFormCreate(&m_nlhr,REQUEST_POST,"http://imageshack.us/upload_api.php",frm,sizeof(frm)/sizeof(HTTPFormData)); - mir_free(tmp); - if(error) - return !m_bAsync; - /// start upload thread - if(m_bAsync){ - mir_forkthread(&CSendImageShack::SendThreadWrapper, this); - return 0; - } - SendThread(); - return 1; -} - -void CSendImageShack::SendThread() { - //send DATA and wait for m_nlreply - NETLIBHTTPREQUEST* reply=(NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)hNetlibUser, (LPARAM)&m_nlhr); - HTTPFormDestroy(&m_nlhr); - if(reply){ - if(reply->resultCode>=200 && reply->resultCode<300 && reply->dataLength){ - reply->pData[reply->dataLength-1]='\0';/// make sure its null terminated - const char* url=NULL; - url=GetHTMLContent(reply->pData,"",""); - if(url && *url){ - mir_free(m_URL), m_URL=mir_strdup(url); - mir_free(m_URLthumb), m_URLthumb=mir_strdup(m_URL); - size_t extlen; - char* pos=strrchr(m_URLthumb,'.'); - if(pos && (extlen=mir_strlen(pos))>2){ - char* tmp=mir_strdup(pos); - memcpy(pos,".th",3); - memcpy(pos+3,tmp,extlen-3); - mir_stradd(m_URLthumb,tmp+extlen-3); - mir_free(tmp); - }else{ - mir_freeAndNil(m_URLthumb); - } - CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT,0,(LPARAM)reply); - svcSendMsgExit(url); return; - }else{/// check error mess from server - url=GetHTMLContent(reply->pData,""); - TCHAR* err=NULL; - if(url) err=mir_a2t(url); - if (!err || !*err){/// fallback to server response mess - mir_free(err); - err=mir_a2t(reply->pData); - } - Error(_T("%s"),err); - mir_free(err); - } - }else{ - Error(LPGENT("Upload server did not respond timely.")); - } - CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT,0,(LPARAM)reply); - }else{ - Error(SS_ERR_INIT, m_pszSendTyp); - } - Exit(ACKRESULT_FAILED); -} - -void CSendImageShack::SendThreadWrapper(void * Obj) { - reinterpret_cast(Obj)->SendThread(); -} diff --git a/plugins/SendScreenshotPlus/src/CSendImageShack.h b/plugins/SendScreenshotPlus/src/CSendImageShack.h deleted file mode 100644 index f32e1cd0b0..0000000000 --- a/plugins/SendScreenshotPlus/src/CSendImageShack.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - -Miranda NG: the free IM client for Microsoft* Windows* - -Copyright (c) 2012-14 Miranda NG project (http://miranda-ng.org), -Copyright (c) 2000-09 Miranda ICQ/IM project, - -This file is part of Send Screenshot Plus, a Miranda IM plugin. -Copyright (c) 2010 Ing.U.Horn - -Parts of this file based on original sorce code -(c) 2004-2006 Sérgio Vieira Rolanski (portet from Borland C++) - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - -#ifndef _CSEND_IMAGESHACK_H -#define _CSEND_IMAGESHACK_H - -//--------------------------------------------------------------------------- -class CSendImageShack : public CSend { - public: - // Deklaration Standardkonstruktor/Standarddestructor - CSendImageShack(HWND Owner, MCONTACT hContact, bool bAsync); - ~CSendImageShack(); - - int Send(); - - protected: - NETLIBHTTPREQUEST m_nlhr; - - void SendThread(); - static void SendThreadWrapper(void * Obj); - -}; - -//--------------------------------------------------------------------------- - -#endif diff --git a/plugins/SendScreenshotPlus/src/Main.cpp b/plugins/SendScreenshotPlus/src/Main.cpp index 58f5f8819e..fc69925c58 100644 --- a/plugins/SendScreenshotPlus/src/Main.cpp +++ b/plugins/SendScreenshotPlus/src/Main.cpp @@ -275,7 +275,7 @@ INT_PTR service_EditBitmap(WPARAM wParam, LPARAM lParam) { // lParam = (HANDLE)contact (can be null) INT_PTR service_Send2ImageShack(WPARAM wParam, LPARAM lParam) { char* result = NULL; - CSendImageShack* cSend = new CSendImageShack(NULL, lParam, false); + CSendHost_ImageShack* cSend = new CSendHost_ImageShack(NULL, lParam, false); cSend->m_bDeleteAfterSend = false; cSend->SetFile((char*)wParam); if (lParam != NULL) { diff --git a/plugins/SendScreenshotPlus/src/UMainForm.cpp b/plugins/SendScreenshotPlus/src/UMainForm.cpp index 6abf446e60..859fd0a9cc 100644 --- a/plugins/SendScreenshotPlus/src/UMainForm.cpp +++ b/plugins/SendScreenshotPlus/src/UMainForm.cpp @@ -315,6 +315,7 @@ void TfrmMain::wmInitdialog(WPARAM wParam, LPARAM lParam) { ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("Upload Pie (30m)")), SS_UPLOADPIE_30M); ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("Upload Pie (1d)")), SS_UPLOADPIE_1D); ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("Upload Pie (1w)")), SS_UPLOADPIE_1W); + ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("imgur")), SS_IMGUR); ComboBox_SelectItemData (hCtrl, -1, m_opt_cboxSendBy); //use Workaround for MS bug ComboBox_SelectItemData } /// init footer options @@ -832,7 +833,7 @@ void TfrmMain::cboxSendByChange() { m_cSend = new CSendDropbox(m_hWnd, m_hContact, false); break; case SS_IMAGESHACK: //"ImageShack" - m_cSend = new CSendImageShack(m_hWnd, m_hContact, true); + m_cSend = new CSendHost_ImageShack(m_hWnd, m_hContact, true); break; case SS_UPLOADPIE_30M: //"Upload Pie (30 minutes)" m_cSend = new CSendHost_UploadPie(m_hWnd, m_hContact, true,1); @@ -843,6 +844,9 @@ void TfrmMain::cboxSendByChange() { case SS_UPLOADPIE_1W: //"Upload Pie (1 week)" m_cSend = new CSendHost_UploadPie(m_hWnd, m_hContact, true,5); break; + case SS_IMGUR: + m_cSend = new CSendHost_Imgur(m_hWnd, m_hContact, true); + break; default: //SS_JUSTSAVE - "Just save it " m_cSend = NULL; break; diff --git a/plugins/SendScreenshotPlus/src/UMainForm.h b/plugins/SendScreenshotPlus/src/UMainForm.h index c5906b2f1d..b6ba02ddd3 100644 --- a/plugins/SendScreenshotPlus/src/UMainForm.h +++ b/plugins/SendScreenshotPlus/src/UMainForm.h @@ -39,6 +39,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define SS_UPLOADPIE_30M 7 #define SS_UPLOADPIE_1D 8 #define SS_UPLOADPIE_1W 9 +#define SS_IMGUR 10 // Used for our own cheap TrackMouseEvent #define BUTTON_POLLDELAY 50 diff --git a/plugins/SendScreenshotPlus/src/global.h b/plugins/SendScreenshotPlus/src/global.h index d0914b4a00..9c822d3f98 100644 --- a/plugins/SendScreenshotPlus/src/global.h +++ b/plugins/SendScreenshotPlus/src/global.h @@ -90,8 +90,9 @@ using namespace std; #include "CSendFTPFile.h" #include "CSendHTTPServer.h" #include "CSendDropbox.h" -#include "CSendImageShack.h" +#include "CSendHost_ImageShack.h" #include "CSendHost_uploadpie.h" +#include "CSendHost_imgur.h" #include "DevKey.h" #include "UMainForm.h" #include "UAboutForm.h" diff --git a/plugins/SendScreenshotPlus/src/version.h b/plugins/SendScreenshotPlus/src/version.h index 34c726289c..eaf9ca7683 100644 --- a/plugins/SendScreenshotPlus/src/version.h +++ b/plugins/SendScreenshotPlus/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 8 -#define __RELEASE_NUM 5 -#define __BUILD_NUM 2 +#define __RELEASE_NUM 6 +#define __BUILD_NUM 0 #include -- cgit v1.2.3