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
|
/*
Copyright (C) 2012-23 Miranda NG team (https://miranda-ng.org)
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 version 2
of the License.
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, see <http://www.gnu.org/licenses/>.
*/
#include "stdafx.h"
// create an object for sending
IcqFileTransfer::IcqFileTransfer(MCONTACT hContact, const wchar_t *pwszFileName) :
m_wszFileName(pwszFileName)
{
pfts.flags = PFTS_UNICODE | PFTS_SENDING;
pfts.hContact = hContact;
pfts.szCurrentFile.w = m_wszFileName.GetBuffer();
const wchar_t *p = wcsrchr(pfts.szCurrentFile.w, '\\');
if (pwszFileName != nullptr)
p++;
else
p = pfts.szCurrentFile.w;
m_wszShortName = p;
}
IcqFileTransfer::~IcqFileTransfer()
{
if (m_fileId >= 0)
_close(m_fileId);
}
void IcqFileTransfer::FillHeaders(AsyncHttpRequest *pReq)
{
pReq->AddHeader("Content-Type", "application/octet-stream");
pReq->AddHeader("Content-Disposition", CMStringA(FORMAT, "attachment; filename=\"%s\"", T2Utf(m_wszShortName).get()));
uint32_t dwPortion = pfts.currentFileSize - pfts.currentFileProgress;
if (dwPortion > 1000000)
dwPortion = 1000000;
pReq->AddHeader("Content-Range", CMStringA(FORMAT, "bytes %lld-%lld/%lld", pfts.currentFileProgress, pfts.currentFileProgress + dwPortion - 1, pfts.currentFileSize));
pReq->AddHeader("Content-Length", CMStringA(FORMAT, "%d", dwPortion));
pReq->dataLength = dwPortion;
pReq->pData = (char *)mir_alloc(dwPortion);
_lseek(m_fileId, pfts.currentFileProgress, SEEK_SET);
_read(m_fileId, pReq->pData, dwPortion);
pfts.currentFileProgress += dwPortion;
pfts.totalProgress += dwPortion;
}
|