diff options
author | René Schümann <white06tiger@gmail.com> | 2014-06-28 23:29:27 +0000 |
---|---|---|
committer | René Schümann <white06tiger@gmail.com> | 2014-06-28 23:29:27 +0000 |
commit | 814ff2e2b838bdefb42f2af358f358446025c8d0 (patch) | |
tree | 78ff09fb8b3748f4a308491d9c4ac2e11dc9610b /plugins/SendScreenshotPlus/src/CSendHost_ImageShack.cpp | |
parent | c6e1bedfc18495b3e083069f8d03c2218f6f6b78 (diff) |
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
Diffstat (limited to 'plugins/SendScreenshotPlus/src/CSendHost_ImageShack.cpp')
-rw-r--r-- | plugins/SendScreenshotPlus/src/CSendHost_ImageShack.cpp | 119 |
1 files changed, 119 insertions, 0 deletions
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,"<image_link>","</image_link>"); + 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,"<error ","</error>"); + 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<CSendHost_ImageShack*>(Obj)->SendThread(); +} |