forked from meganz/sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnet.cpp
More file actions
726 lines (611 loc) · 24.8 KB
/
net.cpp
File metadata and controls
726 lines (611 loc) · 24.8 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
/**
* @file win32/net.cpp
* @brief Win32 network access layer (using WinHTTP)
*
* (c) 2013-2014 by Mega Limited, Auckland, New Zealand
*
* This file is part of the MEGA SDK - Client Access Engine.
*
* Applications using the MEGA API must present a valid application key
* and comply with the the rules set forth in the Terms of Service.
*
* The MEGA SDK 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.
*
* @copyright Simplified (2-clause) BSD License.
*
* You should have received a copy of the license along with this
* program.
*/
// FIXME: Work around WinHTTP's inability to POST additional data
// after having read from the HTTP connection
#include "meganet.h"
#include <winhttp.h>
namespace mega {
extern PGTC pGTC;
WinHttpIO::WinHttpIO()
{
InitializeCriticalSection(&csHTTP);
EnterCriticalSection(&csHTTP);
hWakeupEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
waiter = NULL;
}
WinHttpIO::~WinHttpIO()
{
WinHttpCloseHandle(hSession);
LeaveCriticalSection(&csHTTP);
}
void WinHttpIO::setuseragent(string* useragent)
{
string wuseragent;
wuseragent.resize((useragent->size() + 1) * sizeof(wchar_t));
wuseragent.resize(sizeof(wchar_t)
* (MultiByteToWideChar(CP_UTF8, 0, useragent->c_str(),
-1, (wchar_t*)wuseragent.data(),
int(wuseragent.size() / sizeof(wchar_t) + 1))
- 1));
// create the session handle using the default settings.
hSession = WinHttpOpen((LPCWSTR)wuseragent.data(),
WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
WINHTTP_NO_PROXY_NAME,
WINHTTP_NO_PROXY_BYPASS,
WINHTTP_FLAG_ASYNC);
DWORD protocols = WINHTTP_FLAG_SECURE_PROTOCOL_TLS1 |
WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_1 |
WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2;
WinHttpSetOption(hSession, WINHTTP_OPTION_SECURE_PROTOCOLS, &protocols, sizeof (protocols));
}
void WinHttpIO::setproxy(Proxy* proxy)
{
Proxy* autoProxy = NULL;
proxyUsername.clear();
proxyPassword.clear();
if (proxy->getProxyType() == Proxy::AUTO)
{
autoProxy = getautoproxy();
proxy = autoProxy;
}
if (proxy->getProxyType() == Proxy::NONE)
{
WINHTTP_PROXY_INFO proxyInfo;
proxyInfo.dwAccessType = WINHTTP_ACCESS_TYPE_NO_PROXY;
proxyInfo.lpszProxy = WINHTTP_NO_PROXY_NAME;
proxyInfo.lpszProxyBypass = WINHTTP_NO_PROXY_BYPASS;
WinHttpSetOption(hSession, WINHTTP_OPTION_PROXY, &proxyInfo, sizeof(proxyInfo));
LOG_info << "Proxy disabled";
}
else if (proxy->getProxyType() == Proxy::CUSTOM)
{
string proxyURL = proxy->getProxyURL();
proxyURL.append("", 1);
WINHTTP_PROXY_INFO proxyInfo;
proxyInfo.dwAccessType = WINHTTP_ACCESS_TYPE_NAMED_PROXY;
proxyInfo.lpszProxy = (LPWSTR)proxyURL.data();
proxyInfo.lpszProxyBypass = WINHTTP_NO_PROXY_BYPASS;
WinHttpSetOption(hSession, WINHTTP_OPTION_PROXY, &proxyInfo, sizeof(proxyInfo));
LOG_info << "Proxy enabled";
if (proxy->credentialsNeeded())
{
proxyUsername = proxy->getUsername();
if (proxyUsername.size())
{
proxyUsername.append("", 1);
}
proxyPassword = proxy->getPassword();
if(proxyPassword.size())
{
proxyPassword.append("", 1);
}
LOG_info << "Proxy requires authentication";
}
}
delete autoProxy;
}
// trigger wakeup
void WinHttpIO::httpevent()
{
SetEvent(hWakeupEvent);
}
// (WinHTTP unfortunately uses threads, hence the need for a mutex)
void WinHttpIO::lock()
{
EnterCriticalSection(&csHTTP);
}
void WinHttpIO::unlock()
{
LeaveCriticalSection(&csHTTP);
}
// ensure wakeup from WinHttpIO events
void WinHttpIO::addevents(Waiter* cwaiter, int flags)
{
waiter = (WinWaiter*)cwaiter;
waiter->addhandle(hWakeupEvent, flags);
waiter->pcsHTTP = &csHTTP;
}
// handle WinHTTP callbacks (which can be in a worker thread context)
VOID CALLBACK WinHttpIO::asynccallback(HINTERNET hInternet, DWORD_PTR dwContext,
DWORD dwInternetStatus,
LPVOID lpvStatusInformation,
DWORD dwStatusInformationLength)
{
WinHttpContext* httpctx = (WinHttpContext*)dwContext;
WinHttpIO* httpio = (WinHttpIO*)httpctx->httpio;
if (dwInternetStatus == WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING)
{
LOG_verbose << "Closing request";
assert(!httpctx->req);
if (httpctx->gzip)
{
inflateEnd(&httpctx->z);
}
delete httpctx;
return;
}
httpio->lock();
HttpReq* req = httpctx->req;
// request cancellations that occured after asynccallback() was entered are caught here
if (!req)
{
LOG_verbose << "Request cancelled";
httpio->unlock();
return;
}
switch (dwInternetStatus)
{
case WINHTTP_CALLBACK_STATUS_DATA_AVAILABLE:
{
DWORD size = *(DWORD*)lpvStatusInformation;
if (!size)
{
if (req->binary)
{
LOG_debug << req->logname << "[received " << (req->buf ? req->buflen : req->in.size()) << " bytes of raw data]";
}
else
{
if(req->in.size() < 2048)
{
LOG_debug << req->logname << "Received: " << req->in.c_str();
}
else
{
LOG_debug << req->logname << "Received: " << req->in.substr(0,2048).c_str();
}
}
LOG_debug << "Request finished with HTTP status: " << req->httpstatus;
req->status = (req->httpstatus == 200
&& (req->contentlength < 0
|| req->contentlength == (req->buf ? req->bufpos : (int)req->in.size())))
? REQ_SUCCESS : REQ_FAILURE;
if (req->status == REQ_SUCCESS)
{
httpio->lastdata = Waiter::ds;
req->lastdata = Waiter::ds;
}
httpio->success = true;
}
else
{
LOG_verbose << "Data available. Remaining: " << size << " bytes";
char* ptr;
if (httpctx->gzip)
{
m_off_t zprevsize = httpctx->zin.size();
httpctx->zin.resize(size_t(zprevsize + size));
ptr = (char*)httpctx->zin.data() + zprevsize;
}
else
{
ptr = (char*)req->reserveput((unsigned*)&size);
req->bufpos += size;
}
if (!WinHttpReadData(hInternet, ptr, size, NULL))
{
LOG_err << "Unable to get more data. Code: " << GetLastError();
httpio->cancel(req);
}
}
httpio->httpevent();
break;
}
case WINHTTP_CALLBACK_STATUS_READ_COMPLETE:
LOG_verbose << "Read complete";
if (dwStatusInformationLength)
{
LOG_verbose << dwStatusInformationLength << " bytes received";
if (req->httpio)
{
req->httpio->lastdata = Waiter::ds;
req->lastdata = Waiter::ds;
}
if (httpctx->gzip)
{
httpctx->z.next_in = (Bytef*)lpvStatusInformation;
httpctx->z.avail_in = dwStatusInformationLength;
req->bufpos += httpctx->z.avail_out;
int t = inflate(&httpctx->z, Z_SYNC_FLUSH);
req->bufpos -= httpctx->z.avail_out;
if ((char*)lpvStatusInformation + dwStatusInformationLength ==
httpctx->zin.data() + httpctx->zin.size())
{
httpctx->zin.clear();
}
if (t != Z_OK && (t != Z_STREAM_END || httpctx->z.avail_out))
{
LOG_err << "GZIP error";
httpio->cancel(req);
}
}
else
{
// data was copied direct to buf or to req->in.
assert(req->buf && (byte*)lpvStatusInformation >= req->buf && (byte*)lpvStatusInformation + dwStatusInformationLength <= req->buf + req->buflen ||
!req->buf && (char*)lpvStatusInformation >= req->in.data() && (char*)lpvStatusInformation + dwStatusInformationLength <= req->in.data() + req->in.size());
}
if (!WinHttpQueryDataAvailable(httpctx->hRequest, NULL))
{
LOG_err << "Error on WinHttpQueryDataAvailable. Code: " << GetLastError();
httpio->cancel(req);
httpio->httpevent();
}
}
break;
case WINHTTP_CALLBACK_STATUS_HEADERS_AVAILABLE:
{
DWORD statusCode;
DWORD statusCodeSize = sizeof(statusCode);
if (!WinHttpQueryHeaders(httpctx->hRequest,
WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER,
WINHTTP_HEADER_NAME_BY_INDEX,
&statusCode,
&statusCodeSize,
WINHTTP_NO_HEADER_INDEX))
{
LOG_err << "Error getting headers. Code: " << GetLastError();
httpio->cancel(req);
httpio->httpevent();
}
else
{
LOG_verbose << "Headers available";
req->httpstatus = statusCode;
if (req->httpio)
{
req->httpio->lastdata = Waiter::ds;
req->lastdata = Waiter::ds;
}
if (!req->buf)
{
DWORD timeLeft;
DWORD timeLeftSize = sizeof(timeLeft);
if (WinHttpQueryHeaders(httpctx->hRequest,
WINHTTP_QUERY_CUSTOM | WINHTTP_QUERY_FLAG_NUMBER,
L"X-MEGA-Time-Left",
&timeLeft,
&timeLeftSize,
WINHTTP_NO_HEADER_INDEX))
{
LOG_verbose << "Seconds left until more bandwidth quota: " << timeLeft;
req->timeleft = timeLeft;
}
// check for gzip content encoding
WCHAR contentEncoding[16];
DWORD contentEncodingSize = sizeof(contentEncoding);
httpctx->gzip = WinHttpQueryHeaders(httpctx->hRequest,
WINHTTP_QUERY_CONTENT_ENCODING,
WINHTTP_HEADER_NAME_BY_INDEX,
&contentEncoding,
&contentEncodingSize,
WINHTTP_NO_HEADER_INDEX)
&& !wcscmp(contentEncoding, L"gzip");
// obtain original content length - always present if gzip is in use
DWORD contentLength;
DWORD contentLengthSize = sizeof(contentLength);
if (WinHttpQueryHeaders(httpctx->hRequest,
WINHTTP_QUERY_CUSTOM | WINHTTP_QUERY_FLAG_NUMBER,
L"Original-Content-Length",
&contentLength,
&contentLengthSize,
WINHTTP_NO_HEADER_INDEX))
{
LOG_verbose << "Content-Length: " << contentLength;
req->setcontentlength(contentLength);
if (httpctx->gzip)
{
LOG_verbose << "Using GZIP";
httpctx->z.zalloc = Z_NULL;
httpctx->z.zfree = Z_NULL;
httpctx->z.opaque = Z_NULL;
httpctx->z.avail_in = 0;
httpctx->z.next_in = Z_NULL;
inflateInit2(&httpctx->z, MAX_WBITS+16);
req->in.resize(contentLength);
httpctx->z.avail_out = contentLength;
httpctx->z.next_out = (unsigned char*)req->in.data();
}
else
{
LOG_verbose << "Not using GZIP";
}
}
else if (httpctx->gzip)
{
LOG_err << "Content is gzipped but length is missing";
httpio->cancel(req);
httpio->httpevent();
break;
}
else
{
// not zipped and no original size - check for Content-Length instead, plain data arriving (eg. keep-alive)
if (WinHttpQueryHeaders(httpctx->hRequest,
WINHTTP_QUERY_CUSTOM | WINHTTP_QUERY_FLAG_NUMBER,
L"Content-Length",
&contentLength,
&contentLengthSize,
WINHTTP_NO_HEADER_INDEX))
{
LOG_verbose << "Content-Length: " << contentLength;
req->setcontentlength(contentLength);
}
else
{
LOG_verbose << "Content-Length not available";
}
}
}
if (!WinHttpQueryDataAvailable(httpctx->hRequest, NULL))
{
LOG_err << "Unable to query data. Code: " << GetLastError();
httpio->cancel(req);
httpio->httpevent();
}
else if (httpio->waiter && httpio->noinetds)
{
httpio->inetstatus(true);
}
}
break;
}
case WINHTTP_CALLBACK_STATUS_REQUEST_ERROR:
{
DWORD e = GetLastError();
LOG_err << "Request error. Code: " << e;
if (httpio->waiter && e != ERROR_WINHTTP_TIMEOUT)
{
httpio->inetstatus(false);
}
}
// fall through
case WINHTTP_CALLBACK_STATUS_SECURE_FAILURE:
if (dwInternetStatus == WINHTTP_CALLBACK_STATUS_SECURE_FAILURE)
{
LOG_err << "Security check failed. Code: " << (*(DWORD*)lpvStatusInformation);
}
httpio->cancel(req);
httpio->httpevent();
break;
case WINHTTP_CALLBACK_STATUS_SENDING_REQUEST:
{
if (MegaClient::disablepkp || !req->protect)
{
break;
}
PCCERT_CONTEXT cert;
DWORD len = sizeof cert;
if (WinHttpQueryOption(httpctx->hRequest, WINHTTP_OPTION_SERVER_CERT_CONTEXT, &cert, &len))
{
CRYPT_BIT_BLOB* pkey = &cert->pCertInfo->SubjectPublicKeyInfo.PublicKey;
// this is an SSL connection: verify public key to prevent MITM attacks
if (pkey->cbData != 270
|| (memcmp(pkey->pbData, "\x30\x82\x01\x0a\x02\x82\x01\x01\x00" APISSLMODULUS1
"\x02" APISSLEXPONENTSIZE APISSLEXPONENT, 270)
&& memcmp(pkey->pbData, "\x30\x82\x01\x0a\x02\x82\x01\x01\x00" APISSLMODULUS2
"\x02" APISSLEXPONENTSIZE APISSLEXPONENT, 270)))
{
LOG_err << "Invalid public key. Possible MITM attack!!";
req->sslcheckfailed = true;
CertFreeCertificateContext(cert);
httpio->cancel(req);
httpio->httpevent();
break;
}
CertFreeCertificateContext(cert);
}
break;
}
case WINHTTP_CALLBACK_STATUS_SENDREQUEST_COMPLETE:
case WINHTTP_CALLBACK_STATUS_WRITE_COMPLETE:
if (httpctx->postpos < httpctx->postlen)
{
LOG_verbose << "Chunk written";
unsigned pos = httpctx->postpos;
unsigned t = httpctx->postlen - pos;
if (t > HTTP_POST_CHUNK_SIZE)
{
t = HTTP_POST_CHUNK_SIZE;
}
httpctx->postpos += t;
if (!WinHttpWriteData(httpctx->hRequest, (LPVOID)(httpctx->postdata + pos), t, NULL))
{
LOG_err << "Error writing data. Code: " << GetLastError();
req->httpio->cancel(req);
}
httpio->httpevent();
}
else
{
LOG_verbose << "Request written";
if (!WinHttpReceiveResponse(httpctx->hRequest, NULL))
{
LOG_err << "Error receiving response. Code: " << GetLastError();
httpio->cancel(req);
httpio->httpevent();
}
httpctx->postdata = NULL;
}
}
httpio->unlock();
}
// POST request to URL
void WinHttpIO::post(HttpReq* req, const char* data, unsigned len)
{
if (SimpleLogger::logCurrentLevel >= logDebug)
{
string safeurl = req->posturl;
size_t sid = safeurl.find("sid=");
if (sid != string::npos)
{
sid += 4;
size_t end = safeurl.find("&", sid);
if (end == string::npos)
{
end = safeurl.size();
}
memset((char *)safeurl.data() + sid, 'X', end - sid);
}
LOG_debug << "POST target URL: " << safeurl;
}
if (req->binary)
{
LOG_debug << req->logname << "[sending " << (data ? len : req->out->size()) << " bytes of raw data]";
}
else
{
LOG_debug << req->logname << "Sending: " << *req->out;
}
WinHttpContext* httpctx;
WCHAR szURL[8192];
WCHAR szHost[256];
URL_COMPONENTS urlComp = { sizeof urlComp };
urlComp.lpszHostName = szHost;
urlComp.dwHostNameLength = sizeof szHost / sizeof *szHost;
urlComp.dwUrlPathLength = (DWORD)-1;
urlComp.dwSchemeLength = (DWORD)-1;
httpctx = new WinHttpContext;
httpctx->httpio = this;
httpctx->req = req;
httpctx->gzip = false;
req->httpiohandle = (void*)httpctx;
if (MultiByteToWideChar(CP_UTF8, 0, req->posturl.c_str(), -1, szURL,
sizeof szURL / sizeof *szURL)
&& WinHttpCrackUrl(szURL, 0, 0, &urlComp))
{
if ((httpctx->hConnect = WinHttpConnect(hSession, szHost, urlComp.nPort, 0)))
{
httpctx->hRequest = WinHttpOpenRequest(httpctx->hConnect, L"POST",
urlComp.lpszUrlPath, NULL,
WINHTTP_NO_REFERER,
WINHTTP_DEFAULT_ACCEPT_TYPES,
(urlComp.nScheme == INTERNET_SCHEME_HTTPS)
? WINHTTP_FLAG_SECURE
: 0);
if (httpctx->hRequest)
{
if (proxyUsername.size())
{
LOG_verbose << "Setting proxy credentials";
WinHttpSetCredentials(httpctx->hRequest, WINHTTP_AUTH_TARGET_PROXY,
WINHTTP_AUTH_SCHEME_BASIC,
(LPWSTR)proxyUsername.data(), (LPWSTR)proxyPassword.data(), NULL);
}
WinHttpSetTimeouts(httpctx->hRequest, 58000, 58000, 0, 0);
WinHttpSetStatusCallback(httpctx->hRequest, asynccallback,
WINHTTP_CALLBACK_FLAG_DATA_AVAILABLE
| WINHTTP_CALLBACK_FLAG_READ_COMPLETE
| WINHTTP_CALLBACK_FLAG_HEADERS_AVAILABLE
| WINHTTP_CALLBACK_FLAG_REQUEST_ERROR
| WINHTTP_CALLBACK_FLAG_SECURE_FAILURE
| WINHTTP_CALLBACK_FLAG_SENDREQUEST_COMPLETE
| WINHTTP_CALLBACK_FLAG_SEND_REQUEST
| WINHTTP_CALLBACK_FLAG_WRITE_COMPLETE
| WINHTTP_CALLBACK_FLAG_HANDLES,
0);
LPCWSTR pwszHeaders = req->type == REQ_JSON || !req->buf
? L"Content-Type: application/json\r\nAccept-Encoding: gzip"
: L"Content-Type: application/octet-stream";
httpctx->postlen = int(data ? len : req->out->size());
httpctx->postdata = data ? data : req->out->data();
if (urlComp.nPort == 80)
{
LOG_verbose << "HTTP connection";
// HTTP connection: send a chunk of data immediately
httpctx->postpos = (httpctx->postlen < HTTP_POST_CHUNK_SIZE)
? httpctx->postlen
: HTTP_POST_CHUNK_SIZE;
}
else
{
LOG_verbose << "HTTPS connection";
// HTTPS connection: ignore certificate errors, send no data yet
DWORD flags = SECURITY_FLAG_IGNORE_CERT_CN_INVALID
| SECURITY_FLAG_IGNORE_CERT_DATE_INVALID
| SECURITY_FLAG_IGNORE_UNKNOWN_CA;
WinHttpSetOption(httpctx->hRequest, WINHTTP_OPTION_SECURITY_FLAGS, &flags, sizeof flags);
httpctx->postpos = 0;
}
if (WinHttpSendRequest(httpctx->hRequest, pwszHeaders,
DWORD(wcslen(pwszHeaders)),
(LPVOID)httpctx->postdata,
httpctx->postpos,
httpctx->postlen,
(DWORD_PTR)httpctx))
{
LOG_verbose << "Request sent";
req->status = REQ_INFLIGHT;
return;
}
LOG_err << "Error sending request: " << req->posturl << " Code: " << GetLastError();
}
else
{
LOG_err << "Error opening request: " << req->posturl << " Code: " << GetLastError();
}
}
else
{
LOG_err << "Error connecting to " << req->posturl << " Code: " << GetLastError();
httpctx->hRequest = NULL;
}
}
else
{
LOG_err << "Error parsing POST URL: " << req->posturl << " Code: " << GetLastError();
httpctx->hRequest = NULL;
httpctx->hConnect = NULL;
}
LOG_err << "Request failed";
req->status = REQ_FAILURE;
}
// cancel pending HTTP request
void WinHttpIO::cancel(HttpReq* req)
{
WinHttpContext* httpctx;
if ((httpctx = (WinHttpContext*)req->httpiohandle))
{
httpctx->req = NULL;
req->httpstatus = 0;
req->status = REQ_FAILURE;
req->httpiohandle = NULL;
if (httpctx->hConnect)
{
WinHttpCloseHandle(httpctx->hConnect);
}
if (httpctx->hRequest)
{
WinHttpCloseHandle(httpctx->hRequest);
}
}
}
// supply progress information on POST data
m_off_t WinHttpIO::postpos(void* handle)
{
return ((WinHttpContext*)handle)->postpos;
}
// process events
bool WinHttpIO::doio()
{
return false;
}
} // namespace