diff options
Diffstat (limited to 'plugins/SendScreenshotPlus/src/CSendHost_ImageShack.cpp')
-rw-r--r-- | plugins/SendScreenshotPlus/src/CSendHost_ImageShack.cpp | 100 |
1 files changed, 53 insertions, 47 deletions
diff --git a/plugins/SendScreenshotPlus/src/CSendHost_ImageShack.cpp b/plugins/SendScreenshotPlus/src/CSendHost_ImageShack.cpp index a0f03d11eb..a1bdcc4fa1 100644 --- a/plugins/SendScreenshotPlus/src/CSendHost_ImageShack.cpp +++ b/plugins/SendScreenshotPlus/src/CSendHost_ImageShack.cpp @@ -31,36 +31,39 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. //--------------------------------------------------------------------------- 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"); + : CSend(Owner, hContact, bAsync) +{ + m_EnableItem = SS_DLG_DESCRIPTION | SS_DLG_AUTOSEND | SS_DLG_DELETEAFTERSSEND; + m_pszSendTyp = LPGENT("Image upload"); } -CSendHost_ImageShack::~CSendHost_ImageShack(){ +CSendHost_ImageShack::~CSendHost_ImageShack() +{ }; //--------------------------------------------------------------------------- -int CSendHost_ImageShack::Send() { - if(!g_hNetlibUser){ /// check Netlib +int CSendHost_ImageShack::Send() +{ + 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[]={ -// {"Referer",HTTPFORM_HEADER("http://www.imageshack.us/upload_api.php")}, - {"fileupload",HTTPFORM_FILE(tmp)}, + 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)}, + { "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)); + int error = HTTPFormCreate(&m_nlhr, REQUEST_POST, "http://imageshack.us/upload_api.php", 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_ImageShack::SendThreadWrapper, this); return 0; } @@ -68,52 +71,55 @@ int CSendHost_ImageShack::Send() { return 1; } -void CSendHost_ImageShack::SendThread() { +void CSendHost_ImageShack::SendThread() +{ /// send DATA and wait for m_nlreply - NETLIBHTTPREQUEST* reply=(NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)g_hNetlibUser, (LPARAM)&m_nlhr); + NETLIBHTTPREQUEST* reply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)g_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); + 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); + 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); + 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 + } + 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); + err = mir_a2t(reply->pData); } - Error(_T("%s"),err); + 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); + 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) { +void CSendHost_ImageShack::SendThreadWrapper(void * Obj) +{ reinterpret_cast<CSendHost_ImageShack*>(Obj)->SendThread(); } |