diff options
author | René Schümann <white06tiger@gmail.com> | 2014-04-11 19:25:34 +0000 |
---|---|---|
committer | René Schümann <white06tiger@gmail.com> | 2014-04-11 19:25:34 +0000 |
commit | 46ceba4a74c107aa085ce199857b9fe1d9cf3f85 (patch) | |
tree | 0fbdf001386c2197354fc3f20c74c011983da3e9 /plugins/SendScreenshotPlus | |
parent | 2e96c3880c010e34363be9300ebbc7935de4a67a (diff) |
SendSS:
+ new host "Upload Pie" with support to expiring uploads: 30 minutes, 1 day or 1 week
might not be perfect because this was a quick edit...
* updated CSend's HTTP post stuff to support integer values (CSend,CSendImageShack)
git-svn-id: http://svn.miranda-ng.org/main/trunk@8959 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/SendScreenshotPlus')
-rw-r--r-- | plugins/SendScreenshotPlus/SendSS_10.vcxproj | 6 | ||||
-rw-r--r-- | plugins/SendScreenshotPlus/SendSS_12.vcxproj | 6 | ||||
-rw-r--r-- | plugins/SendScreenshotPlus/src/CSend.cpp | 28 | ||||
-rw-r--r-- | plugins/SendScreenshotPlus/src/CSend.h | 16 | ||||
-rw-r--r-- | plugins/SendScreenshotPlus/src/CSendHost_uploadpie.cpp | 104 | ||||
-rw-r--r-- | plugins/SendScreenshotPlus/src/CSendHost_uploadpie.h | 28 | ||||
-rw-r--r-- | plugins/SendScreenshotPlus/src/CSendImageShack.cpp | 4 | ||||
-rw-r--r-- | plugins/SendScreenshotPlus/src/UMainForm.cpp | 12 | ||||
-rw-r--r-- | plugins/SendScreenshotPlus/src/UMainForm.h | 17 | ||||
-rw-r--r-- | plugins/SendScreenshotPlus/src/global.h | 3 |
10 files changed, 197 insertions, 27 deletions
diff --git a/plugins/SendScreenshotPlus/SendSS_10.vcxproj b/plugins/SendScreenshotPlus/SendSS_10.vcxproj index 9194610445..c9dec0613d 100644 --- a/plugins/SendScreenshotPlus/SendSS_10.vcxproj +++ b/plugins/SendScreenshotPlus/SendSS_10.vcxproj @@ -171,7 +171,6 @@ </ResourceCompile>
</ItemDefinitionGroup>
<ItemGroup>
- <ClCompile Include="src\CSendDropbox.cpp" />
<ClCompile Include="src\stdafx.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
@@ -187,11 +186,12 @@ <ClCompile Include="src\CSendFile.cpp" />
<ClCompile Include="src\CSendFTPFile.cpp" />
<ClCompile Include="src\CSendHTTPServer.cpp" />
+ <ClCompile Include="src\CSendDropbox.cpp" />
<ClCompile Include="src\CSendImageShack.cpp" />
+ <ClCompile Include="src\CSendHost_uploadpie.cpp" />
<ClCompile Include="src\Main.cpp" />
</ItemGroup>
<ItemGroup>
- <ClInclude Include="src\CSendDropbox.h" />
<ClInclude Include="src\DevKey.h" />
<ClInclude Include="src\UAboutForm.h" />
<ClInclude Include="src\UMainForm.h" />
@@ -206,7 +206,9 @@ <ClInclude Include="src\CSendFile.h" />
<ClInclude Include="src\CSendFTPFile.h" />
<ClInclude Include="src\CSendHTTPServer.h" />
+ <ClInclude Include="src\CSendDropbox.h" />
<ClInclude Include="src\CSendImageShack.h" />
+ <ClInclude Include="src\CSendHost_uploadpie.h" />
<ClInclude Include="src\global.h" />
<ClInclude Include="src\Main.h" />
<ClInclude Include="src\version.h" />
diff --git a/plugins/SendScreenshotPlus/SendSS_12.vcxproj b/plugins/SendScreenshotPlus/SendSS_12.vcxproj index 9f401bfdb6..75c15a57a7 100644 --- a/plugins/SendScreenshotPlus/SendSS_12.vcxproj +++ b/plugins/SendScreenshotPlus/SendSS_12.vcxproj @@ -174,7 +174,6 @@ </ResourceCompile>
</ItemDefinitionGroup>
<ItemGroup>
- <ClCompile Include="src\CSendDropbox.cpp" />
<ClCompile Include="src\stdafx.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
@@ -190,11 +189,12 @@ <ClCompile Include="src\CSendFile.cpp" />
<ClCompile Include="src\CSendFTPFile.cpp" />
<ClCompile Include="src\CSendHTTPServer.cpp" />
+ <ClCompile Include="src\CSendDropbox.cpp" />
<ClCompile Include="src\CSendImageShack.cpp" />
+ <ClCompile Include="src\CSendHost_uploadpie.cpp" />
<ClCompile Include="src\Main.cpp" />
</ItemGroup>
<ItemGroup>
- <ClInclude Include="src\CSendDropbox.h" />
<ClInclude Include="src\DevKey.h" />
<ClInclude Include="src\UAboutForm.h" />
<ClInclude Include="src\UMainForm.h" />
@@ -209,7 +209,9 @@ <ClInclude Include="src\CSendFile.h" />
<ClInclude Include="src\CSendFTPFile.h" />
<ClInclude Include="src\CSendHTTPServer.h" />
+ <ClInclude Include="src\CSendDropbox.h" />
<ClInclude Include="src\CSendImageShack.h" />
+ <ClInclude Include="src\CSendHost_uploadpie.h" />
<ClInclude Include="src\global.h" />
<ClInclude Include="src\Main.h" />
<ClInclude Include="src\version.h" />
diff --git a/plugins/SendScreenshotPlus/src/CSend.cpp b/plugins/SendScreenshotPlus/src/CSend.cpp index a2b2e7e9b3..a2f8e51beb 100644 --- a/plugins/SendScreenshotPlus/src/CSend.cpp +++ b/plugins/SendScreenshotPlus/src/CSend.cpp @@ -450,6 +450,7 @@ void CSend::Exit(unsigned int Result) { /// helper functions used for HTTP uploads //--------------------------------------------------------------------------- +#define snprintf _snprintf const char* CSend::GetHTMLContent(char* str, const char* startTag, const char* endTag) { char* begin=strstr(str,startTag); if(!begin) return NULL; @@ -525,11 +526,13 @@ int CSend::HTTPFormCreate(NETLIBHTTPREQUEST* nlhr,int requestType,char* url,HTTP memset(dataPos,'-',2); dataPos+=2; memcpy(dataPos,boundary,sizeof(boundary)); dataPos+=sizeof(boundary); memcpy(dataPos,"\r\nContent-Disposition: form-data; name=\"",40); dataPos+=40; - size_t namelen=strlen(iter->name), valuelen=strlen(iter->value); - if(iter->flags&HTTPFORM_FILE){ - const char* filename =strrchr(iter->value,'\\'); - if(!filename) filename =strrchr(iter->value,'/'); - if(!filename) filename =iter->value; + size_t namelen=strlen(iter->name), valuelen; + if(!(iter->flags&HTTPFF_INT)) + valuelen=strlen(iter->value_str); + if(iter->flags&HTTPFF_FILE){ + const char* filename =strrchr(iter->value_str,'\\'); + if(!filename) filename =strrchr(iter->value_str,'/'); + if(!filename) filename =iter->value_str; else ++filename; valuelen=strlen(filename); HTTPFormAppendData(nlhr,&dataMax,&dataPos,NULL,namelen+13+valuelen+17); @@ -556,7 +559,7 @@ int CSend::HTTPFormCreate(NETLIBHTTPREQUEST* nlhr,int requestType,char* url,HTTP HTTPFormAppendData(nlhr,&dataMax,&dataPos,"\r\n\r\n",4); /// add file content size_t filesize=0; - FILE* fp=fopen(iter->value,"rb"); + FILE* fp=fopen(iter->value_str,"rb"); if(fp){ fseek(fp,0,SEEK_END); filesize=ftell(fp); fseek(fp,0,SEEK_SET); @@ -574,17 +577,24 @@ int CSend::HTTPFormCreate(NETLIBHTTPREQUEST* nlhr,int requestType,char* url,HTTP fclose(fp); dataPos+=filesize; memcpy(dataPos,"\r\n",2); dataPos+=2; - }else if(iter->flags&HTTPFORM_8BIT){ + }else if(iter->flags&HTTPFF_8BIT){ HTTPFormAppendData(nlhr,&dataMax,&dataPos,NULL,namelen+38+valuelen+2); memcpy(dataPos,iter->name,namelen); dataPos+=namelen; memcpy(dataPos,"\"\r\nContent-Transfer-Encoding: 8bit\r\n\r\n",38); dataPos+=38; - memcpy(dataPos,iter->value,valuelen); dataPos+=valuelen; + memcpy(dataPos,iter->value_str,valuelen); dataPos+=valuelen; + memcpy(dataPos,"\r\n",2); dataPos+=2; + }else if(iter->flags&HTTPFF_INT){ + HTTPFormAppendData(nlhr,&dataMax,&dataPos,NULL,namelen+5+17/*max numbers*/+2); + memcpy(dataPos,iter->name,namelen); dataPos+=namelen; + memcpy(dataPos,"\"\r\n\r\n",5); dataPos+=5; + int ret=snprintf(dataPos,17,"%Id",iter->value_int); + if(ret<17 && ret>0) dataPos+=ret; memcpy(dataPos,"\r\n",2); dataPos+=2; }else{ HTTPFormAppendData(nlhr,&dataMax,&dataPos,NULL,namelen+5+valuelen+2); memcpy(dataPos,iter->name,namelen); dataPos+=namelen; memcpy(dataPos,"\"\r\n\r\n",5); dataPos+=5; - memcpy(dataPos,iter->value,valuelen); dataPos+=valuelen; + memcpy(dataPos,iter->value_str,valuelen); dataPos+=valuelen; memcpy(dataPos,"\r\n",2); dataPos+=2; } } diff --git a/plugins/SendScreenshotPlus/src/CSend.h b/plugins/SendScreenshotPlus/src/CSend.h index fdf84d712b..16ab0f192e 100644 --- a/plugins/SendScreenshotPlus/src/CSend.h +++ b/plugins/SendScreenshotPlus/src/CSend.h @@ -102,13 +102,21 @@ class CSend { /// HTTP upload helper stuff enum HTTPFormFlags{ - HTTPFORM_TEXT=0x00, - HTTPFORM_8BIT=0x01, - HTTPFORM_FILE=0x02, + HTTPFF_TEXT =0x00, + HTTPFF_8BIT =0x01, + HTTPFF_FILE =0x02, + HTTPFF_INT =0x04, }; + #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 struct HTTPFormData{ const char* name; - const char* value; + union{ + const char* value_str; + intptr_t value_int; + }; int flags; }; static const char* GetHTMLContent(char* str, const char* startTag, const char* endTag); /// changes "str", can be successfully used only once diff --git a/plugins/SendScreenshotPlus/src/CSendHost_uploadpie.cpp b/plugins/SendScreenshotPlus/src/CSendHost_uploadpie.cpp new file mode 100644 index 0000000000..9b975b7a6e --- /dev/null +++ b/plugins/SendScreenshotPlus/src/CSendHost_uploadpie.cpp @@ -0,0 +1,104 @@ +/* + 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_UploadPie::CSendHost_UploadPie(HWND Owner, MCONTACT hContact, bool bAsync, int expire) + : m_expire(expire), CSend(Owner,hContact,bAsync) +{ + m_EnableItem=SS_DLG_DESCRIPTION|SS_DLG_AUTOSEND|SS_DLG_DELETEAFTERSSEND; + m_pszSendTyp=LPGENT("Image upload"); +} + +CSendHost_UploadPie::~CSendHost_UploadPie() +{} + +//--------------------------------------------------------------------------- +int CSendHost_UploadPie::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[]={ + {"MAX_FILE_SIZE",HTTPFORM_INT(3145728)},// ?? + {"upload",HTTPFORM_INT(1)},// ?? + {"uploadedfile",HTTPFORM_FILE(tmp)}, + {"expire",HTTPFORM_INT(1)},// 30m + //{"expire",HTTPFORM_INT(2,},// 1h + //{"expire",HTTPFORM_INT(3)},// 6h + //{"expire",HTTPFORM_INT(4)},// 1d + //{"expire",HTTPFORM_INT(5)},// 1w + //{"x",HTTPFORM_INT(130)},// ?? + //{"y",HTTPFORM_INT(17)},// ?? + }; + int error=HTTPFormCreate(&m_nlhr,REQUEST_POST,"http://uploadpie.com/",frm,sizeof(frm)/sizeof(HTTPFormData)); + mir_free(tmp); + if(error) + return !m_bAsync; + /// start upload thread + if(m_bAsync){ + mir_forkthread(&CSendHost_UploadPie::SendThread, this); + return 0; + } + SendThread(this); + return 1; +} + +void CSendHost_UploadPie::SendThread(void* obj) +{ + CSendHost_UploadPie* self=(CSendHost_UploadPie*)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->resultCode>=200 && reply->resultCode<300){ + reply->pData[reply->dataLength]='\0';/// make sure its null terminated + + OutputDebugStringA(reply->pData); + char* url=reply->pData; + do{ + char* pos; + if((url=strstr(url,"http://uploadpie.com/"))){ + for(pos=url+21; (*pos>='0'&&*pos<='9') || (*pos>='a'&&*pos<='z') || (*pos>='A'&&*pos<='Z') || *pos=='_' || *pos=='-' || *pos=='"' || *pos=='\''; ++pos){ + if(*pos=='"' || *pos=='\'') break; + } + if(*pos=='"' || *pos=='\''){ + *pos='\0'; + break; + } + ++url; + } + }while(url); + if(url){ + mir_free(self->m_URL), self->m_URL=mir_strdup(url); + self->svcSendMsgExit(url); return; + }else{/// check error mess from server + TCHAR* err=mir_a2t(reply->pData); + self->Error(_T("%s"),err); + mir_free(err); + } + }else{ + self->Error(LPGENT("Upload server did not respond timely.")); + } + CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT,0,(LPARAM)reply); + }else{ + self->Error(SS_ERR_INIT, self->m_pszSendTyp); + } + self->Exit(ACKRESULT_FAILED); +} diff --git a/plugins/SendScreenshotPlus/src/CSendHost_uploadpie.h b/plugins/SendScreenshotPlus/src/CSendHost_uploadpie.h new file mode 100644 index 0000000000..24ebd2d882 --- /dev/null +++ b/plugins/SendScreenshotPlus/src/CSendHost_uploadpie.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_UPLOADPIE_H +#define _CSEND_HOST_UPLOADPIE_H +class CSendHost_UploadPie : public CSend { + public: + CSendHost_UploadPie(HWND Owner, MCONTACT hContact, bool bAsync, int expire); + ~CSendHost_UploadPie(); + int Send(); + protected: + int m_expire; + NETLIBHTTPREQUEST m_nlhr; + static void SendThread(void* obj); +}; +#endif diff --git a/plugins/SendScreenshotPlus/src/CSendImageShack.cpp b/plugins/SendScreenshotPlus/src/CSendImageShack.cpp index f6141651c2..9f5d5dce46 100644 --- a/plugins/SendScreenshotPlus/src/CSendImageShack.cpp +++ b/plugins/SendScreenshotPlus/src/CSendImageShack.cpp @@ -49,10 +49,10 @@ int CSendImageShack::Send() { ZeroMemory(&m_nlhr, sizeof(m_nlhr)); char* tmp; tmp=mir_t2a(m_pszFile); HTTPFormData frm[]={ - {"fileupload",tmp,HTTPFORM_FILE}, + {"fileupload",HTTPFORM_FILE(tmp)}, //{"rembar","yes"},// no info bar on thumb {"public","no"}, - {"key",DEVKEY_IMAGESHACK,HTTPFORM_8BIT}, + {"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); diff --git a/plugins/SendScreenshotPlus/src/UMainForm.cpp b/plugins/SendScreenshotPlus/src/UMainForm.cpp index 71051af96d..f387dc2287 100644 --- a/plugins/SendScreenshotPlus/src/UMainForm.cpp +++ b/plugins/SendScreenshotPlus/src/UMainForm.cpp @@ -281,6 +281,9 @@ void TfrmMain::wmInitdialog(WPARAM wParam, LPARAM lParam) { m_opt_cboxSendBy = SS_IMAGESHACK; } ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("ImageShack")), SS_IMAGESHACK); + 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_SelectItemData (hCtrl, -1, m_opt_cboxSendBy); //use Workaround for MS bug ComboBox_SelectItemData } //init footer options @@ -803,6 +806,15 @@ void TfrmMain::cboxSendByChange() { case SS_IMAGESHACK: //"ImageShack" m_cSend = new CSendImageShack(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); + break; + case SS_UPLOADPIE_1D: //"Upload Pie (1 day)" + m_cSend = new CSendHost_UploadPie(m_hWnd, m_hContact, true,4); + break; + case SS_UPLOADPIE_1W: //"Upload Pie (1 week)" + m_cSend = new CSendHost_UploadPie(m_hWnd, m_hContact, true,5); + 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 5aa35e484e..ea4b61e15e 100644 --- a/plugins/SendScreenshotPlus/src/UMainForm.h +++ b/plugins/SendScreenshotPlus/src/UMainForm.h @@ -29,13 +29,16 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef UMainFormH #define UMainFormH -#define SS_JUSTSAVE 0 -#define SS_FILESEND 1 -#define SS_EMAIL 2 -#define SS_HTTPSERVER 3 -#define SS_FTPFILE 4 -#define SS_DROPBOX 5 -#define SS_IMAGESHACK 6 +#define SS_JUSTSAVE 0 +#define SS_FILESEND 1 +#define SS_EMAIL 2 +#define SS_HTTPSERVER 3 +#define SS_FTPFILE 4 +#define SS_DROPBOX 5 +#define SS_IMAGESHACK 6 +#define SS_UPLOADPIE_30M 7 +#define SS_UPLOADPIE_1D 8 +#define SS_UPLOADPIE_1W 9 // 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 37d08e61c1..c15bd3b71e 100644 --- a/plugins/SendScreenshotPlus/src/global.h +++ b/plugins/SendScreenshotPlus/src/global.h @@ -86,12 +86,13 @@ using namespace std; #include "version.h" #include "main.h" #include "CSend.h" -#include "CSendDropbox.h" #include "CSendEmail.h" #include "CSendFile.h" #include "CSendFTPFile.h" #include "CSendHTTPServer.h" +#include "CSendDropbox.h" #include "CSendImageShack.h" +#include "CSendHost_uploadpie.h" #include "DevKey.h" #include "UMainForm.h" #include "UAboutForm.h" |