1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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);
}
|