forked from salsita/passthruapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProtocolImpl.inl
755 lines (669 loc) · 20.7 KB
/
ProtocolImpl.inl
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
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
#ifndef PASSTHROUGHAPP_PROTOCOLIMPL_INL
#define PASSTHROUGHAPP_PROTOCOLIMPL_INL
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#ifndef PASSTHROUGHAPP_PROTOCOLIMPL_H
#error ProtocolImpl.inl requires ProtocolImpl.h to be included first
#endif
namespace PassthroughAPP
{
namespace Detail
{
template <class T>
inline HRESULT WINAPI QIPassthrough<T>::
QueryInterfacePassthroughT(void* pv, REFIID riid, LPVOID* ppv, DWORD_PTR dw)
{
ATLASSERT(pv != 0);
T* pT = static_cast<T*>(pv);
IUnknown* punkTarget = pT->GetTargetUnknown();
ATLASSERT(punkTarget != 0);
if (!punkTarget)
{
ATLTRACE(_T("Interface queried before target unknown is set"));
return E_UNEXPECTED;
}
IUnknown* punkWrapper = pT->GetUnknown();
typename T::ObjectLock lock(pT);
return QueryInterfacePassthrough(
pv, riid, ppv, dw, punkTarget, punkWrapper);
}
template <class T>
inline HRESULT WINAPI QIPassthrough<T>::
QueryInterfaceDebugT(void* pv, REFIID riid, LPVOID* ppv, DWORD_PTR dw)
{
ATLASSERT(pv != 0);
T* pT = static_cast<T*>(pv);
IUnknown* punkTarget = pT->GetTargetUnknown();
ATLASSERT(punkTarget != 0);
if (!punkTarget)
{
ATLTRACE(_T("Interface queried before target unknown is set"));
return E_UNEXPECTED;
}
typename T::ObjectLock lock(pT);
return QueryInterfaceDebug(pv, riid, ppv, dw, punkTarget);
}
inline HRESULT WINAPI QueryInterfacePassthrough(void* pv, REFIID riid,
LPVOID* ppv, DWORD_PTR dw, IUnknown* punkTarget, IUnknown* punkWrapper)
{
ATLASSERT(pv != 0);
ATLASSERT(ppv != 0);
ATLASSERT(dw != 0);
ATLASSERT(punkTarget != 0);
const PassthroughItfData& data =
*reinterpret_cast<const PassthroughItfData*>(dw);
IUnknown** ppUnk = reinterpret_cast<IUnknown**>(
static_cast<char*>(pv) + data.offsetUnk);
HRESULT hr = S_OK;
if (!*ppUnk)
{
CComPtr<IUnknown> spUnk;
hr = punkTarget->QueryInterface(riid,
reinterpret_cast<void**>(&spUnk));
ATLASSERT(FAILED(hr) || spUnk != 0);
if (SUCCEEDED(hr))
{
*ppUnk = spUnk.Detach();
// Need to QI for base interface to fill in base target pointer
if (data.piidBase)
{
ATLASSERT(punkWrapper != 0);
hr = punkWrapper->QueryInterface(*data.piidBase,
reinterpret_cast<void**>(&spUnk));
// since QI for derived interface succeeded,
// QI for base interface must succeed, too
ATLASSERT(SUCCEEDED(hr));
}
}
}
if (SUCCEEDED(hr))
{
CComPtr<IUnknown> spItf = reinterpret_cast<IUnknown*>(
static_cast<char*>(pv) + data.offsetItf);
*ppv = spItf.Detach();
}
else
{
ATLASSERT(_T("Interface not supported by target unknown"));
}
return hr;
}
inline HRESULT WINAPI QueryInterfaceDebug(void* pv, REFIID riid,
LPVOID* ppv, DWORD_PTR dw, IUnknown* punkTarget)
{
ATLASSERT(pv != 0);
ATLASSERT(ppv != 0);
ATLASSERT(punkTarget != 0);
CComPtr<IUnknown> spUnk;
HRESULT hr = punkTarget->QueryInterface(riid,
reinterpret_cast<void**>(&spUnk));
ATLASSERT(FAILED(hr) || spUnk != 0);
if (SUCCEEDED(hr))
{
ATLTRACE(_T("Unrecognized interface supported by target unknown"));
ATLASSERT(false);
}
// We don't support this interface, so return an error.
// The operations above are for debugging purposes only,
// this function is not supposed to ever return success
return E_NOINTERFACE;
}
inline HRESULT QueryServicePassthrough(REFGUID guidService,
IUnknown* punkThis, REFIID riid, void** ppv,
IServiceProvider* pClientProvider)
{
ATLASSERT(punkThis != 0);
CComPtr<IUnknown> spDummy;
HRESULT hr = pClientProvider ?
pClientProvider->QueryService(guidService, riid,
reinterpret_cast<void**>(&spDummy)) :
E_NOINTERFACE;
if (SUCCEEDED(hr))
{
hr = punkThis->QueryInterface(riid, ppv);
}
return hr;
}
} // end namespace PassthroughAPP::Detail
// ===== IInternetProtocolImpl =====
inline STDMETHODIMP IInternetProtocolImpl::SetTargetUnknown(
IUnknown* punkTarget)
{
ATLASSERT(punkTarget != 0);
if (!punkTarget)
{
return E_POINTER;
}
// This method should only be called once, and be the only source
// of target interface pointers.
ATLASSERT(m_spInternetProtocolUnk == 0);
ATLASSERT(m_spInternetProtocol == 0);
if (m_spInternetProtocolUnk || m_spInternetProtocol)
{
return E_UNEXPECTED;
}
// We expect the target unknown to implement at least IInternetProtocol
// Otherwise we reject it
HRESULT hr = punkTarget->QueryInterface(&m_spInternetProtocol);
ATLASSERT(FAILED(hr) || m_spInternetProtocol != 0);
if (FAILED(hr))
{
return hr;
}
hr = m_spInternetProtocol->QueryInterface(&m_spInternetProtocolEx);
ATLASSERT(FAILED(hr) || m_spInternetProtocolEx != 0);
if (FAILED(hr))
{
return hr;
}
ATLASSERT(m_spInternetProtocolInfo == 0);
ATLASSERT(m_spInternetPriority == 0);
ATLASSERT(m_spInternetThreadSwitch == 0);
ATLASSERT(m_spWinInetInfo == 0);
ATLASSERT(m_spWinInetHttpInfo == 0);
m_spInternetProtocolUnk = punkTarget;
return S_OK;
}
inline void IInternetProtocolImpl::ReleaseAll()
{
m_spInternetProtocolUnk.Release();
m_spInternetProtocol.Release();
m_spInternetProtocolEx.Release();
m_spInternetProtocolInfo.Release();
m_spInternetPriority.Release();
m_spInternetThreadSwitch.Release();
m_spWinInetInfo.Release();
m_spWinInetHttpInfo.Release();
m_spWinInetCacheHints.Release();
m_spWinInetCacheHints2.Release();
}
// IInternetProtocolRoot
inline STDMETHODIMP IInternetProtocolImpl::Start(
/* [in] */ LPCWSTR szUrl,
/* [in] */ IInternetProtocolSink *pOIProtSink,
/* [in] */ IInternetBindInfo *pOIBindInfo,
/* [in] */ DWORD grfPI,
/* [in] */ HANDLE_PTR dwReserved)
{
ATLASSERT(m_spInternetProtocol != 0);
return m_spInternetProtocol ?
m_spInternetProtocol->Start(szUrl, pOIProtSink, pOIBindInfo, grfPI,
dwReserved) :
E_UNEXPECTED;
}
inline STDMETHODIMP IInternetProtocolImpl::Continue(
/* [in] */ PROTOCOLDATA *pProtocolData)
{
ATLASSERT(m_spInternetProtocol != 0);
return m_spInternetProtocol ?
m_spInternetProtocol->Continue(pProtocolData) :
E_UNEXPECTED;
}
inline STDMETHODIMP IInternetProtocolImpl::Abort(
/* [in] */ HRESULT hrReason,
/* [in] */ DWORD dwOptions)
{
ATLASSERT(m_spInternetProtocol != 0);
return m_spInternetProtocol ?
m_spInternetProtocol->Abort(hrReason, dwOptions) :
E_UNEXPECTED;
}
inline STDMETHODIMP IInternetProtocolImpl::Terminate(
/* [in] */ DWORD dwOptions)
{
ATLASSERT(m_spInternetProtocol != 0);
return m_spInternetProtocol ?
m_spInternetProtocol->Terminate(dwOptions) :
E_UNEXPECTED;
}
inline STDMETHODIMP IInternetProtocolImpl::Suspend()
{
ATLASSERT(m_spInternetProtocol != 0);
return m_spInternetProtocol ?
m_spInternetProtocol->Suspend() :
E_UNEXPECTED;
}
inline STDMETHODIMP IInternetProtocolImpl::Resume()
{
ATLASSERT(m_spInternetProtocol != 0);
return m_spInternetProtocol ?
m_spInternetProtocol->Resume() :
E_UNEXPECTED;
}
// IInternetProtocol
inline STDMETHODIMP IInternetProtocolImpl::Read(
/* [in, out] */ void *pv,
/* [in] */ ULONG cb,
/* [out] */ ULONG *pcbRead)
{
ATLASSERT(m_spInternetProtocol != 0);
return m_spInternetProtocol ?
m_spInternetProtocol->Read(pv, cb, pcbRead) :
E_UNEXPECTED;
}
inline STDMETHODIMP IInternetProtocolImpl::Seek(
/* [in] */ LARGE_INTEGER dlibMove,
/* [in] */ DWORD dwOrigin,
/* [out] */ ULARGE_INTEGER *plibNewPosition)
{
ATLASSERT(m_spInternetProtocol != 0);
return m_spInternetProtocol ?
m_spInternetProtocol->Seek(dlibMove, dwOrigin, plibNewPosition) :
E_UNEXPECTED;
}
inline STDMETHODIMP IInternetProtocolImpl::LockRequest(
/* [in] */ DWORD dwOptions)
{
ATLASSERT(m_spInternetProtocol != 0);
return m_spInternetProtocol ?
m_spInternetProtocol->LockRequest(dwOptions) :
E_UNEXPECTED;
}
inline STDMETHODIMP IInternetProtocolImpl::UnlockRequest()
{
ATLASSERT(m_spInternetProtocol != 0);
return m_spInternetProtocol ?
m_spInternetProtocol->UnlockRequest() :
E_UNEXPECTED;
}
// IInternetProtocolEx
inline STDMETHODIMP IInternetProtocolImpl::StartEx(
IUri *pUri,
IInternetProtocolSink *pOIProtSink,
IInternetBindInfo *pOIBindInfo,
DWORD grfPI,
HANDLE_PTR dwReserved)
{
ATLASSERT(m_spInternetProtocolEx != 0);
return m_spInternetProtocolEx ?
m_spInternetProtocolEx->StartEx(pUri, pOIProtSink, pOIBindInfo, grfPI, dwReserved) :
E_UNEXPECTED;
}
// IInternetProtocolInfo
inline STDMETHODIMP IInternetProtocolImpl::ParseUrl(
/* [in] */ LPCWSTR pwzUrl,
/* [in] */ PARSEACTION ParseAction,
/* [in] */ DWORD dwParseFlags,
/* [out] */ LPWSTR pwzResult,
/* [in] */ DWORD cchResult,
/* [out] */ DWORD *pcchResult,
/* [in] */ DWORD dwReserved)
{
ATLASSERT(m_spInternetProtocolInfo != 0);
return m_spInternetProtocolInfo ?
m_spInternetProtocolInfo->ParseUrl(pwzUrl, ParseAction, dwParseFlags,
pwzResult, cchResult, pcchResult, dwReserved) :
E_UNEXPECTED;
}
inline STDMETHODIMP IInternetProtocolImpl::CombineUrl(
/* [in] */ LPCWSTR pwzBaseUrl,
/* [in] */ LPCWSTR pwzRelativeUrl,
/* [in] */ DWORD dwCombineFlags,
/* [out] */ LPWSTR pwzResult,
/* [in] */ DWORD cchResult,
/* [out] */ DWORD *pcchResult,
/* [in] */ DWORD dwReserved)
{
ATLASSERT(m_spInternetProtocolInfo != 0);
return m_spInternetProtocolInfo ?
m_spInternetProtocolInfo->CombineUrl(pwzBaseUrl, pwzRelativeUrl,
dwCombineFlags, pwzResult, cchResult, pcchResult, dwReserved) :
E_UNEXPECTED;
}
inline STDMETHODIMP IInternetProtocolImpl::CompareUrl(
/* [in] */ LPCWSTR pwzUrl1,
/* [in] */ LPCWSTR pwzUrl2,
/* [in] */ DWORD dwCompareFlags)
{
ATLASSERT(m_spInternetProtocolInfo != 0);
return m_spInternetProtocolInfo ?
m_spInternetProtocolInfo->CompareUrl(pwzUrl1,pwzUrl2, dwCompareFlags) :
E_UNEXPECTED;
}
inline STDMETHODIMP IInternetProtocolImpl::QueryInfo(
/* [in] */ LPCWSTR pwzUrl,
/* [in] */ QUERYOPTION QueryOption,
/* [in] */ DWORD dwQueryFlags,
/* [in, out] */ LPVOID pBuffer,
/* [in] */ DWORD cbBuffer,
/* [in, out] */ DWORD *pcbBuf,
/* [in] */ DWORD dwReserved)
{
ATLASSERT(m_spInternetProtocolInfo != 0);
return m_spInternetProtocolInfo ?
m_spInternetProtocolInfo->QueryInfo(pwzUrl, QueryOption, dwQueryFlags,
pBuffer, cbBuffer, pcbBuf, dwReserved) :
E_UNEXPECTED;
}
// IInternetPriority
inline STDMETHODIMP IInternetProtocolImpl::SetPriority(
/* [in] */ LONG nPriority)
{
ATLASSERT(m_spInternetPriority != 0);
return m_spInternetPriority ?
m_spInternetPriority->SetPriority(nPriority) :
E_UNEXPECTED;
}
inline STDMETHODIMP IInternetProtocolImpl::GetPriority(
/* [out] */ LONG *pnPriority)
{
ATLASSERT(m_spInternetPriority != 0);
return m_spInternetPriority ?
m_spInternetPriority->GetPriority(pnPriority) :
E_UNEXPECTED;
}
// IInternetThreadSwitch
inline STDMETHODIMP IInternetProtocolImpl::Prepare()
{
ATLASSERT(m_spInternetThreadSwitch != 0);
return m_spInternetThreadSwitch ?
m_spInternetThreadSwitch->Prepare() :
E_UNEXPECTED;
}
inline STDMETHODIMP IInternetProtocolImpl::Continue()
{
ATLASSERT(m_spInternetThreadSwitch != 0);
return m_spInternetThreadSwitch ?
m_spInternetThreadSwitch->Continue() :
E_UNEXPECTED;
}
// IWinInetInfo
inline STDMETHODIMP IInternetProtocolImpl::QueryOption(
/* [in] */ DWORD dwOption,
/* [in, out] */ LPVOID pBuffer,
/* [in, out] */ DWORD *pcbBuf)
{
ATLASSERT(m_spWinInetInfo != 0);
return m_spWinInetInfo ?
m_spWinInetInfo->QueryOption(dwOption, pBuffer, pcbBuf) :
E_UNEXPECTED;
}
// IWinInetHttpInfo
inline STDMETHODIMP IInternetProtocolImpl::QueryInfo(
/* [in] */ DWORD dwOption,
/* [in, out] */ LPVOID pBuffer,
/* [in, out] */ DWORD *pcbBuf,
/* [in, out] */ DWORD *pdwFlags,
/* [in, out] */ DWORD *pdwReserved)
{
ATLASSERT(m_spWinInetHttpInfo != 0);
return m_spWinInetHttpInfo ?
m_spWinInetHttpInfo->QueryInfo(dwOption, pBuffer, pcbBuf, pdwFlags,
pdwReserved) :
E_UNEXPECTED;
}
// IWinInetCacheHints
inline STDMETHODIMP IInternetProtocolImpl::SetCacheExtension(
/* [in] */ LPCWSTR pwzExt,
/* [in, out] */ LPVOID pszCacheFile,
/* [in, out] */ DWORD *pcbCacheFile,
/* [in, out] */ DWORD *pdwWinInetError,
/* [in, out] */ DWORD *pdwReserved)
{
ATLASSERT(m_spWinInetCacheHints2 != NULL);
return m_spWinInetCacheHints2 ?
m_spWinInetCacheHints2->SetCacheExtension(pwzExt, pszCacheFile, pcbCacheFile,
pdwWinInetError, pdwReserved) : E_UNEXPECTED;
}
inline STDMETHODIMP IInternetProtocolImpl::SetCacheExtension2(
/* [in] */ LPCWSTR pwzExt,
/* [out] */ WCHAR *pwzCacheFile,
/* [in, out] */ DWORD *pcchCacheFile,
/* [out] */ DWORD *pdwWinInetError,
/* [out] */ DWORD *pdwReserved)
{
ATLASSERT(m_spWinInetCacheHints2 != NULL);
return m_spWinInetCacheHints2 ?
m_spWinInetCacheHints2->SetCacheExtension2(pwzExt, pwzCacheFile, pcchCacheFile,
pdwWinInetError, pdwReserved) : E_UNEXPECTED;
}
// ===== IInternetProtocolSinkImpl =====
inline HRESULT IInternetProtocolSinkImpl::InitMembers(IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
IInternetProtocol* pTargetProtocol)
{
ATLASSERT(pOIProtSink != 0);
ATLASSERT(pOIBindInfo != 0);
ATLASSERT(pTargetProtocol != 0);
if (!pOIProtSink || !pOIBindInfo || !pTargetProtocol)
{
return E_POINTER;
}
// This method should only be called once, and be the only source
// of target interface pointers.
ATLASSERT(m_spInternetProtocolSink == 0);
ATLASSERT(m_spInternetBindInfo == 0);
ATLASSERT(m_spTargetProtocol == 0);
if (m_spInternetProtocolSink || m_spInternetBindInfo || m_spTargetProtocol)
{
return E_UNEXPECTED;
}
ATLASSERT(m_spServiceProvider == 0);
m_spInternetProtocolSink = pOIProtSink;
m_spInternetBindInfo = pOIBindInfo;
if (FAILED(m_spInternetBindInfo->QueryInterface(&m_spInternetBindInfoEx)))
m_spInternetBindInfoEx = NULL;
m_spTargetProtocol = pTargetProtocol;
return S_OK;
}
inline HRESULT IInternetProtocolSinkImpl::OnStart(LPCWSTR szUrl,
IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
DWORD grfPI, HANDLE_PTR dwReserved, IInternetProtocol* pTargetProtocol)
{
return InitMembers(pOIProtSink, pOIBindInfo, pTargetProtocol);
}
inline HRESULT IInternetProtocolSinkImpl::OnStartEx(IUri* pUri,
IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
DWORD grfPI, HANDLE_PTR dwReserved, IInternetProtocol* pTargetProtocol)
{
return InitMembers(pOIProtSink, pOIBindInfo, pTargetProtocol);
}
inline void IInternetProtocolSinkImpl::ReleaseAll()
{
m_spInternetProtocolSink.Release();
m_spServiceProvider.Release();
m_spInternetBindInfo.Release();
m_spInternetBindInfoEx.Release();
m_spUriContainer.Release();
m_spTargetProtocol.Release();
}
inline IServiceProvider* IInternetProtocolSinkImpl::GetClientServiceProvider()
{
return m_spServiceProvider;
}
inline HRESULT IInternetProtocolSinkImpl::QueryServiceFromClient(
REFGUID guidService, REFIID riid, void** ppvObject)
{
HRESULT hr = S_OK;
CComPtr<IServiceProvider> spClientProvider = m_spServiceProvider;
if (!spClientProvider)
{
hr = m_spInternetProtocolSink->QueryInterface(&spClientProvider);
ATLASSERT(SUCCEEDED(hr) && spClientProvider != 0);
}
if (SUCCEEDED(hr))
{
hr = spClientProvider->QueryService(guidService, riid, ppvObject);
}
return hr;
}
// IInternetProtocolSink
inline STDMETHODIMP IInternetProtocolSinkImpl::Switch(
/* [in] */ PROTOCOLDATA *pProtocolData)
{
ATLASSERT(m_spInternetProtocolSink != 0);
return m_spInternetProtocolSink ?
m_spInternetProtocolSink->Switch(pProtocolData) :
E_UNEXPECTED;
}
inline STDMETHODIMP IInternetProtocolSinkImpl::ReportProgress(
/* [in] */ ULONG ulStatusCode,
/* [in] */ LPCWSTR szStatusText)
{
ATLASSERT(m_spInternetProtocolSink != 0);
return m_spInternetProtocolSink ?
m_spInternetProtocolSink->ReportProgress(ulStatusCode, szStatusText) :
E_UNEXPECTED;
}
inline STDMETHODIMP IInternetProtocolSinkImpl::ReportData(
/* [in] */ DWORD grfBSCF,
/* [in] */ ULONG ulProgress,
/* [in] */ ULONG ulProgressMax)
{
ATLASSERT(m_spInternetProtocolSink != 0);
return m_spInternetProtocolSink ?
m_spInternetProtocolSink->ReportData(grfBSCF, ulProgress,
ulProgressMax) :
E_UNEXPECTED;
}
inline STDMETHODIMP IInternetProtocolSinkImpl::ReportResult(
/* [in] */ HRESULT hrResult,
/* [in] */ DWORD dwError,
/* [in] */ LPCWSTR szResult)
{
ATLASSERT(m_spInternetProtocolSink != 0);
return m_spInternetProtocolSink ?
m_spInternetProtocolSink->ReportResult(hrResult, dwError, szResult) :
E_UNEXPECTED;
}
// IServiceProvider
inline STDMETHODIMP IInternetProtocolSinkImpl::QueryService(
/* [in] */ REFGUID guidService,
/* [in] */ REFIID riid,
/* [out] */ void** ppvObject)
{
ATLASSERT(m_spServiceProvider != 0);
return m_spServiceProvider ?
m_spServiceProvider->QueryService(guidService, riid, ppvObject) :
E_UNEXPECTED;
}
// IInternetBindInfo
inline STDMETHODIMP IInternetProtocolSinkImpl::GetBindInfo(
/* [out] */ DWORD *grfBINDF,
/* [in, out] */ BINDINFO *pbindinfo)
{
ATLASSERT(m_spInternetBindInfo != 0);
return m_spInternetBindInfo ?
m_spInternetBindInfo->GetBindInfo(grfBINDF, pbindinfo) :
E_UNEXPECTED;
}
inline STDMETHODIMP IInternetProtocolSinkImpl::GetBindString(
/* [in] */ ULONG ulStringType,
/* [in, out] */ LPOLESTR *ppwzStr,
/* [in] */ ULONG cEl,
/* [in, out] */ ULONG *pcElFetched)
{
ATLASSERT(m_spInternetBindInfo != 0);
return m_spInternetBindInfo ?
m_spInternetBindInfo->GetBindString(ulStringType, ppwzStr, cEl,
pcElFetched) :
E_UNEXPECTED;
}
// IInternetBindInfoEx
inline STDMETHODIMP IInternetProtocolSinkImpl::GetBindInfoEx(
DWORD *grfBINDF,
BINDINFO *pbindinfo,
DWORD *grfBINDF2,
DWORD *pdwReserved)
{
ATLASSERT(m_spInternetBindInfoEx != 0);
return m_spInternetBindInfoEx ?
m_spInternetBindInfoEx->GetBindInfoEx(grfBINDF, pbindinfo,
grfBINDF2, pdwReserved) : E_UNEXPECTED;
}
inline STDMETHODIMP IInternetProtocolSinkImpl::GetIUri(
IUri **ppIUri
)
{
ATLASSERT(m_spUriContainer != 0);
return m_spUriContainer ?
m_spUriContainer->GetIUri(ppIUri) : E_UNEXPECTED;
}
// ===== CInternetProtocolSinkWithSP =====
template <class T, class ThreadModel>
inline HRESULT CInternetProtocolSinkWithSP<T, ThreadModel>::OnStart(
LPCWSTR szUrl, IInternetProtocolSink *pOIProtSink,
IInternetBindInfo *pOIBindInfo, DWORD grfPI, HANDLE_PTR dwReserved,
IInternetProtocol* pTargetProtocol)
{
ATLASSERT(m_spServiceProvider == 0);
if (m_spServiceProvider)
{
return E_UNEXPECTED;
}
HRESULT hr = BaseClass::OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI,
dwReserved, pTargetProtocol);
if (SUCCEEDED(hr))
{
pOIProtSink->QueryInterface(&m_spServiceProvider);
}
return hr;
}
template <class T, class ThreadModel>
inline HRESULT CInternetProtocolSinkWithSP<T, ThreadModel>::OnStartEx(
IUri* pUri, IInternetProtocolSink *pOIProtSink,
IInternetBindInfo *pOIBindInfo, DWORD grfPI, HANDLE_PTR dwReserved,
IInternetProtocol* pTargetProtocol)
{
ATLASSERT(m_spServiceProvider == 0);
if (m_spServiceProvider)
{
return E_UNEXPECTED;
}
HRESULT hr = BaseClass::OnStartEx(pUri, pOIProtSink, pOIBindInfo, grfPI,
dwReserved, pTargetProtocol);
if (SUCCEEDED(hr))
{
pOIProtSink->QueryInterface(&m_spServiceProvider);
}
return hr;
}
template <class T, class ThreadModel>
inline HRESULT CInternetProtocolSinkWithSP<T, ThreadModel>::
_InternalQueryService(REFGUID guidService, REFIID riid, void** ppvObject)
{
return E_NOINTERFACE;
}
template <class T, class ThreadModel>
inline STDMETHODIMP CInternetProtocolSinkWithSP<T, ThreadModel>::QueryService(
REFGUID guidService, REFIID riid, void** ppv)
{
T* pT = static_cast<T*>(this);
HRESULT hr = pT->_InternalQueryService(guidService, riid, ppv);
if (FAILED(hr) && m_spServiceProvider)
{
hr = m_spServiceProvider->QueryService(guidService, riid, ppv);
}
return hr;
}
// ===== CInternetProtocol =====
// IInternetProtocolRoot
template <class StartPolicy, class ThreadModel>
inline STDMETHODIMP CInternetProtocol<StartPolicy, ThreadModel>::Start(
LPCWSTR szUrl, IInternetProtocolSink *pOIProtSink,
IInternetBindInfo *pOIBindInfo, DWORD grfPI, HANDLE_PTR dwReserved)
{
ATLASSERT(m_spInternetProtocol != 0);
if (!m_spInternetProtocol)
{
return E_UNEXPECTED;
}
return StartPolicy::OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI,
dwReserved, m_spInternetProtocol);
}
// IInternetProtocolEx
template <class StartPolicy, class ThreadModel>
inline STDMETHODIMP CInternetProtocol<StartPolicy, ThreadModel>::StartEx(
IUri* pUri, IInternetProtocolSink *pOIProtSink,
IInternetBindInfo *pOIBindInfo, DWORD grfPI, HANDLE_PTR dwReserved)
{
ATLASSERT(m_spInternetProtocolEx != 0);
if (!m_spInternetProtocolEx)
{
return E_UNEXPECTED;
}
return StartPolicy::OnStartEx(pUri, pOIProtSink, pOIBindInfo, grfPI,
dwReserved, m_spInternetProtocolEx);
}
} // end namespace PassthroughAPP
#endif // PASSTHROUGHAPP_PROTOCOLIMPL_INL