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"
21 #include "wine/debug.h"
22 #include "wine/unicode.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(hlink
);
26 #define DEFINE_THIS(cls,ifc,iface) ((cls*)((BYTE*)(iface)-offsetof(cls,lp ## ifc ## Vtbl)))
29 const IUnknownVtbl
*lpIUnknownVtbl
;
30 const IAuthenticateVtbl
*lpIAuthenticateVtbl
;
31 const IHttpNegotiateVtbl
*lpIHttpNegotiateVtbl
;
42 #define EXTSERVUNK(x) ((IUnknown*) &(x)->lpIUnknownVtbl)
43 #define AUTHENTICATE(x) ((IAuthenticate*) &(x)->lpIAuthenticateVtbl)
44 #define HTTPNEGOTIATE(x) ((IHttpNegotiate*) &(x)->lpIHttpNegotiateVtbl)
46 #define EXTSERVUNK_THIS(iface) DEFINE_THIS(ExtensionService, IUnknown, iface)
48 static HRESULT WINAPI
ExtServUnk_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ppv
)
50 ExtensionService
*This
= EXTSERVUNK_THIS(iface
);
54 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
55 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
56 *ppv
= EXTSERVUNK(This
);
57 }else if(IsEqualGUID(&IID_IAuthenticate
, riid
)) {
58 TRACE("(%p)->(IID_IAuthenticate %p)\n", This
, ppv
);
59 *ppv
= AUTHENTICATE(This
);
60 }else if(IsEqualGUID(&IID_IHttpNegotiate
, riid
)) {
61 TRACE("(%p)->(IID_IHttpNegotiate %p)\n", This
, ppv
);
62 *ppv
= HTTPNEGOTIATE(This
);
66 IUnknown_AddRef(EXTSERVUNK(This
));
70 FIXME("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
74 static ULONG WINAPI
ExtServUnk_AddRef(IUnknown
*iface
)
76 ExtensionService
*This
= EXTSERVUNK_THIS(iface
);
77 LONG ref
= InterlockedIncrement(&This
->ref
);
79 TRACE("(%p) ref=%d\n", This
, ref
);
84 static ULONG WINAPI
ExtServUnk_Release(IUnknown
*iface
)
86 ExtensionService
*This
= EXTSERVUNK_THIS(iface
);
87 LONG ref
= InterlockedDecrement(&This
->ref
);
89 TRACE("(%p) ref=%d\n", This
, ref
);
92 heap_free(This
->username
);
93 heap_free(This
->password
);
94 heap_free(This
->headers
);
101 #undef EXTSERVUNK_THIS
103 static const IUnknownVtbl ExtServUnkVtbl
= {
104 ExtServUnk_QueryInterface
,
109 #define AUTHENTICATE_THIS(iface) DEFINE_THIS(ExtensionService, IAuthenticate, iface)
111 static HRESULT WINAPI
Authenticate_QueryInterface(IAuthenticate
*iface
, REFIID riid
, void **ppv
)
113 ExtensionService
*This
= AUTHENTICATE_THIS(iface
);
114 return IUnknown_QueryInterface(This
->outer
, riid
, ppv
);
117 static ULONG WINAPI
Authenticate_AddRef(IAuthenticate
*iface
)
119 ExtensionService
*This
= AUTHENTICATE_THIS(iface
);
120 return IUnknown_AddRef(This
->outer
);
123 static ULONG WINAPI
Authenticate_Release(IAuthenticate
*iface
)
125 ExtensionService
*This
= AUTHENTICATE_THIS(iface
);
126 return IUnknown_Release(This
->outer
);
129 static HRESULT WINAPI
Authenticate_Authenticate(IAuthenticate
*iface
,
130 HWND
*phwnd
, LPWSTR
*pszUsername
, LPWSTR
*pszPassword
)
132 ExtensionService
*This
= AUTHENTICATE_THIS(iface
);
134 TRACE("(%p)->(%p %p %p)\n", This
, phwnd
, pszUsername
, pszPassword
);
136 if(!phwnd
|| !pszUsername
|| !pszPassword
)
140 *pszUsername
= hlink_co_strdupW(This
->username
);
141 *pszPassword
= hlink_co_strdupW(This
->password
);
146 #undef AUTHENTICATE_THIS
148 static const IAuthenticateVtbl AuthenticateVtbl
= {
149 Authenticate_QueryInterface
,
151 Authenticate_Release
,
152 Authenticate_Authenticate
155 #define HTTPNEGOTIATE_THIS(iface) DEFINE_THIS(ExtensionService, IHttpNegotiate, iface)
157 static HRESULT WINAPI
HttpNegotiate_QueryInterface(IHttpNegotiate
*iface
, REFIID riid
, void **ppv
)
159 ExtensionService
*This
= HTTPNEGOTIATE_THIS(iface
);
160 return IUnknown_QueryInterface(This
->outer
, riid
, ppv
);
163 static ULONG WINAPI
HttpNegotiate_AddRef(IHttpNegotiate
*iface
)
165 ExtensionService
*This
= HTTPNEGOTIATE_THIS(iface
);
166 return IUnknown_AddRef(This
->outer
);
169 static ULONG WINAPI
HttpNegotiate_Release(IHttpNegotiate
*iface
)
171 ExtensionService
*This
= HTTPNEGOTIATE_THIS(iface
);
172 return IUnknown_Release(This
->outer
);
175 static HRESULT WINAPI
HttpNegotiate_BeginningTransaction(IHttpNegotiate
*iface
,
176 LPCWSTR szURL
, LPCWSTR szHeaders
, DWORD dwReserved
, LPWSTR
*pszAdditionalHeaders
)
178 ExtensionService
*This
= HTTPNEGOTIATE_THIS(iface
);
180 TRACE("(%p)->(%s %s %x %p)\n", This
, debugstr_w(szURL
), debugstr_w(szHeaders
), dwReserved
,
181 pszAdditionalHeaders
);
183 if(!pszAdditionalHeaders
)
186 *pszAdditionalHeaders
= hlink_co_strdupW(This
->headers
);
190 static HRESULT WINAPI
HttpNegotiate_OnResponse(IHttpNegotiate
*iface
, DWORD dwResponseCode
,
191 LPCWSTR szResponseHeaders
, LPCWSTR szRequestHeaders
, LPWSTR
*pszAdditionalRequestHeaders
)
193 ExtensionService
*This
= HTTPNEGOTIATE_THIS(iface
);
195 TRACE("(%p)->(%d %s %s %p)\n", This
, dwResponseCode
, debugstr_w(szResponseHeaders
),
196 debugstr_w(szRequestHeaders
), pszAdditionalRequestHeaders
);
198 *pszAdditionalRequestHeaders
= NULL
;
202 #undef HTTPNEGOTIATE_THIS
204 static const IHttpNegotiateVtbl HttpNegotiateVtbl
= {
205 HttpNegotiate_QueryInterface
,
206 HttpNegotiate_AddRef
,
207 HttpNegotiate_Release
,
208 HttpNegotiate_BeginningTransaction
,
209 HttpNegotiate_OnResponse
212 HRESULT WINAPI
HlinkCreateExtensionServices(LPCWSTR pwzAdditionalHeaders
,
213 HWND phwnd
, LPCWSTR pszUsername
, LPCWSTR pszPassword
,
214 IUnknown
*punkOuter
, REFIID riid
, void** ppv
)
216 ExtensionService
*ret
;
220 TRACE("%s %p %s %s %p %s %p\n",debugstr_w(pwzAdditionalHeaders
),
221 phwnd
, debugstr_w(pszUsername
), debugstr_w(pszPassword
),
222 punkOuter
, debugstr_guid(riid
), ppv
);
224 ret
= heap_alloc(sizeof(*ret
));
226 ret
->lpIUnknownVtbl
= &ExtServUnkVtbl
;
227 ret
->lpIAuthenticateVtbl
= &AuthenticateVtbl
;
228 ret
->lpIHttpNegotiateVtbl
= &HttpNegotiateVtbl
;
231 ret
->username
= hlink_strdupW(pszUsername
);
232 ret
->password
= hlink_strdupW(pszPassword
);
234 if(pwzAdditionalHeaders
)
235 len
= strlenW(pwzAdditionalHeaders
);
237 if(len
&& pwzAdditionalHeaders
[len
-1] != '\n' && pwzAdditionalHeaders
[len
-1] != '\r') {
238 static const WCHAR endlW
[] = {'\r','\n',0};
239 ret
->headers
= heap_alloc(len
*sizeof(WCHAR
) + sizeof(endlW
));
240 memcpy(ret
->headers
, pwzAdditionalHeaders
, len
*sizeof(WCHAR
));
241 memcpy(ret
->headers
+len
, endlW
, sizeof(endlW
));
243 ret
->headers
= hlink_strdupW(pwzAdditionalHeaders
);
247 ret
->outer
= EXTSERVUNK(ret
);
248 hres
= IUnknown_QueryInterface(EXTSERVUNK(ret
), riid
, ppv
);
249 IUnknown_Release(EXTSERVUNK(ret
));
250 }else if(IsEqualGUID(&IID_IUnknown
, riid
)) {
251 ret
->outer
= punkOuter
;
252 *ppv
= EXTSERVUNK(ret
);
254 IUnknown_Release(EXTSERVUNK(ret
));