2 * Copyright 2007 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "hlink_private.h"
22 IUnknown IUnknown_inner
;
23 IAuthenticate IAuthenticate_iface
;
24 IHttpNegotiate IHttpNegotiate_iface
;
25 IExtensionServices IExtensionServices_iface
;
36 static inline ExtensionService
*impl_from_IUnknown(IUnknown
*iface
)
38 return CONTAINING_RECORD(iface
, ExtensionService
, IUnknown_inner
);
41 static HRESULT WINAPI
ExtServUnk_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ppv
)
43 ExtensionService
*This
= impl_from_IUnknown(iface
);
47 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
48 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
49 *ppv
= &This
->IUnknown_inner
;
50 }else if(IsEqualGUID(&IID_IAuthenticate
, riid
)) {
51 TRACE("(%p)->(IID_IAuthenticate %p)\n", This
, ppv
);
52 *ppv
= &This
->IAuthenticate_iface
;
53 }else if(IsEqualGUID(&IID_IHttpNegotiate
, riid
)) {
54 TRACE("(%p)->(IID_IHttpNegotiate %p)\n", This
, ppv
);
55 *ppv
= &This
->IHttpNegotiate_iface
;
56 }else if(IsEqualGUID(&IID_IExtensionServices
, riid
)) {
57 TRACE("(%p)->(IID_IExtensionServices %p)\n", This
, ppv
);
58 *ppv
= &This
->IExtensionServices_iface
;
62 IUnknown_AddRef((IUnknown
*)*ppv
);
66 FIXME("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
70 static ULONG WINAPI
ExtServUnk_AddRef(IUnknown
*iface
)
72 ExtensionService
*This
= impl_from_IUnknown(iface
);
73 LONG ref
= InterlockedIncrement(&This
->ref
);
75 TRACE("(%p) ref=%d\n", This
, ref
);
80 static ULONG WINAPI
ExtServUnk_Release(IUnknown
*iface
)
82 ExtensionService
*This
= impl_from_IUnknown(iface
);
83 LONG ref
= InterlockedDecrement(&This
->ref
);
85 TRACE("(%p) ref=%d\n", This
, ref
);
88 heap_free(This
->username
);
89 heap_free(This
->password
);
90 heap_free(This
->headers
);
97 static const IUnknownVtbl ExtServUnkVtbl
= {
98 ExtServUnk_QueryInterface
,
103 static inline ExtensionService
*impl_from_IAuthenticate(IAuthenticate
*iface
)
105 return CONTAINING_RECORD(iface
, ExtensionService
, IAuthenticate_iface
);
108 static HRESULT WINAPI
Authenticate_QueryInterface(IAuthenticate
*iface
, REFIID riid
, void **ppv
)
110 ExtensionService
*This
= impl_from_IAuthenticate(iface
);
111 return IUnknown_QueryInterface(This
->outer_unk
, riid
, ppv
);
114 static ULONG WINAPI
Authenticate_AddRef(IAuthenticate
*iface
)
116 ExtensionService
*This
= impl_from_IAuthenticate(iface
);
117 return IUnknown_AddRef(This
->outer_unk
);
120 static ULONG WINAPI
Authenticate_Release(IAuthenticate
*iface
)
122 ExtensionService
*This
= impl_from_IAuthenticate(iface
);
123 return IUnknown_Release(This
->outer_unk
);
126 static HRESULT WINAPI
Authenticate_Authenticate(IAuthenticate
*iface
,
127 HWND
*phwnd
, LPWSTR
*pszUsername
, LPWSTR
*pszPassword
)
129 ExtensionService
*This
= impl_from_IAuthenticate(iface
);
131 TRACE("(%p)->(%p %p %p)\n", This
, phwnd
, pszUsername
, pszPassword
);
133 if(!phwnd
|| !pszUsername
|| !pszPassword
)
137 *pszUsername
= hlink_co_strdupW(This
->username
);
138 *pszPassword
= hlink_co_strdupW(This
->password
);
143 static const IAuthenticateVtbl AuthenticateVtbl
= {
144 Authenticate_QueryInterface
,
146 Authenticate_Release
,
147 Authenticate_Authenticate
150 static inline ExtensionService
*impl_from_IHttpNegotiate(IHttpNegotiate
*iface
)
152 return CONTAINING_RECORD(iface
, ExtensionService
, IHttpNegotiate_iface
);
155 static HRESULT WINAPI
HttpNegotiate_QueryInterface(IHttpNegotiate
*iface
, REFIID riid
, void **ppv
)
157 ExtensionService
*This
= impl_from_IHttpNegotiate(iface
);
158 return IUnknown_QueryInterface(This
->outer_unk
, riid
, ppv
);
161 static ULONG WINAPI
HttpNegotiate_AddRef(IHttpNegotiate
*iface
)
163 ExtensionService
*This
= impl_from_IHttpNegotiate(iface
);
164 return IUnknown_AddRef(This
->outer_unk
);
167 static ULONG WINAPI
HttpNegotiate_Release(IHttpNegotiate
*iface
)
169 ExtensionService
*This
= impl_from_IHttpNegotiate(iface
);
170 return IUnknown_Release(This
->outer_unk
);
173 static HRESULT WINAPI
HttpNegotiate_BeginningTransaction(IHttpNegotiate
*iface
,
174 LPCWSTR szURL
, LPCWSTR szHeaders
, DWORD dwReserved
, LPWSTR
*pszAdditionalHeaders
)
176 ExtensionService
*This
= impl_from_IHttpNegotiate(iface
);
178 TRACE("(%p)->(%s %s %x %p)\n", This
, debugstr_w(szURL
), debugstr_w(szHeaders
), dwReserved
,
179 pszAdditionalHeaders
);
181 if(!pszAdditionalHeaders
)
184 *pszAdditionalHeaders
= hlink_co_strdupW(This
->headers
);
188 static HRESULT WINAPI
HttpNegotiate_OnResponse(IHttpNegotiate
*iface
, DWORD dwResponseCode
,
189 LPCWSTR szResponseHeaders
, LPCWSTR szRequestHeaders
, LPWSTR
*pszAdditionalRequestHeaders
)
191 ExtensionService
*This
= impl_from_IHttpNegotiate(iface
);
193 TRACE("(%p)->(%d %s %s %p)\n", This
, dwResponseCode
, debugstr_w(szResponseHeaders
),
194 debugstr_w(szRequestHeaders
), pszAdditionalRequestHeaders
);
196 *pszAdditionalRequestHeaders
= NULL
;
200 static const IHttpNegotiateVtbl HttpNegotiateVtbl
= {
201 HttpNegotiate_QueryInterface
,
202 HttpNegotiate_AddRef
,
203 HttpNegotiate_Release
,
204 HttpNegotiate_BeginningTransaction
,
205 HttpNegotiate_OnResponse
208 static inline ExtensionService
*impl_from_IExtensionServices(IExtensionServices
*iface
)
210 return CONTAINING_RECORD(iface
, ExtensionService
, IExtensionServices_iface
);
213 static HRESULT WINAPI
ExtServ_QueryInterface(IExtensionServices
*iface
, REFIID riid
, void **ppv
)
215 ExtensionService
*This
= impl_from_IExtensionServices(iface
);
216 return IUnknown_QueryInterface(This
->outer_unk
, riid
, ppv
);
219 static ULONG WINAPI
ExtServ_AddRef(IExtensionServices
*iface
)
221 ExtensionService
*This
= impl_from_IExtensionServices(iface
);
222 return IUnknown_AddRef(This
->outer_unk
);
225 static ULONG WINAPI
ExtServ_Release(IExtensionServices
*iface
)
227 ExtensionService
*This
= impl_from_IExtensionServices(iface
);
228 return IUnknown_Release(This
->outer_unk
);
231 static HRESULT
ExtServ_ImplSetAdditionalHeaders(ExtensionService
* This
, LPCWSTR pwzAdditionalHeaders
)
235 heap_free(This
->headers
);
236 This
->headers
= NULL
;
238 if (!pwzAdditionalHeaders
)
241 len
= strlenW(pwzAdditionalHeaders
);
243 if(len
&& pwzAdditionalHeaders
[len
-1] != '\n' && pwzAdditionalHeaders
[len
-1] != '\r') {
244 static const WCHAR endlW
[] = {'\r','\n',0};
245 This
->headers
= heap_alloc(len
*sizeof(WCHAR
) + sizeof(endlW
));
246 memcpy(This
->headers
, pwzAdditionalHeaders
, len
*sizeof(WCHAR
));
247 memcpy(This
->headers
+len
, endlW
, sizeof(endlW
));
249 This
->headers
= hlink_strdupW(pwzAdditionalHeaders
);
255 static HRESULT WINAPI
ExtServ_SetAdditionalHeaders(IExtensionServices
* iface
, LPCWSTR pwzAdditionalHeaders
)
257 ExtensionService
*This
= impl_from_IExtensionServices(iface
);
259 TRACE("(%p)->(%s)\n", This
, debugstr_w(pwzAdditionalHeaders
));
261 return ExtServ_ImplSetAdditionalHeaders(This
,pwzAdditionalHeaders
);
264 static HRESULT
ExtServ_ImplSetAuthenticateData(ExtensionService
* This
, HWND phwnd
, LPCWSTR pwzUsername
, LPCWSTR pwzPassword
)
266 heap_free(This
->username
);
267 heap_free(This
->password
);
270 This
->username
= hlink_strdupW(pwzUsername
);
271 This
->password
= hlink_strdupW(pwzPassword
);
276 static HRESULT WINAPI
ExtServ_SetAuthenticateData(IExtensionServices
* iface
, HWND phwnd
, LPCWSTR pwzUsername
, LPCWSTR pwzPassword
)
278 ExtensionService
*This
= impl_from_IExtensionServices(iface
);
280 TRACE("(%p)->(%p %s %s)\n", This
, phwnd
, debugstr_w(pwzUsername
), debugstr_w(pwzPassword
));
282 return ExtServ_ImplSetAuthenticateData(This
, phwnd
, pwzUsername
, pwzPassword
);
285 static const IExtensionServicesVtbl ExtServVtbl
= {
286 ExtServ_QueryInterface
,
289 ExtServ_SetAdditionalHeaders
,
290 ExtServ_SetAuthenticateData
293 /***********************************************************************
294 * HlinkCreateExtensionServices (HLINK.@)
296 HRESULT WINAPI
HlinkCreateExtensionServices(LPCWSTR pwzAdditionalHeaders
,
297 HWND phwnd
, LPCWSTR pszUsername
, LPCWSTR pszPassword
,
298 IUnknown
*punkOuter
, REFIID riid
, void** ppv
)
300 ExtensionService
*ret
;
303 TRACE("%s %p %s %s %p %s %p\n",debugstr_w(pwzAdditionalHeaders
),
304 phwnd
, debugstr_w(pszUsername
), debugstr_w(pszPassword
),
305 punkOuter
, debugstr_guid(riid
), ppv
);
307 ret
= heap_alloc(sizeof(*ret
));
309 ret
->IUnknown_inner
.lpVtbl
= &ExtServUnkVtbl
;
310 ret
->IAuthenticate_iface
.lpVtbl
= &AuthenticateVtbl
;
311 ret
->IHttpNegotiate_iface
.lpVtbl
= &HttpNegotiateVtbl
;
312 ret
->IExtensionServices_iface
.lpVtbl
= &ExtServVtbl
;
316 ret
->username
= NULL
;
317 ret
->password
= NULL
;
319 ExtServ_ImplSetAuthenticateData(ret
, phwnd
, pszUsername
, pszPassword
);
320 ExtServ_ImplSetAdditionalHeaders(ret
, pwzAdditionalHeaders
);
323 ret
->outer_unk
= &ret
->IUnknown_inner
;
324 hres
= IUnknown_QueryInterface(&ret
->IUnknown_inner
, riid
, ppv
);
325 IUnknown_Release(&ret
->IUnknown_inner
);
326 }else if(IsEqualGUID(&IID_IUnknown
, riid
)) {
327 ret
->outer_unk
= punkOuter
;
328 *ppv
= &ret
->IUnknown_inner
;
330 IUnknown_Release(&ret
->IUnknown_inner
);