ReactOS  0.4.13-dev-698-g77671f0
extserv.c
Go to the documentation of this file.
1 /*
2  * Copyright 2007 Jacek Caban for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18 
19 #include "hlink_private.h"
20 
21 #include "wine/debug.h"
22 #include "wine/unicode.h"
23 
25 
26 typedef struct {
31 
34 
40 
42 {
43  return CONTAINING_RECORD(iface, ExtensionService, IUnknown_inner);
44 }
45 
47 {
49 
50  *ppv = NULL;
51 
53  TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
54  *ppv = &This->IUnknown_inner;
55  }else if(IsEqualGUID(&IID_IAuthenticate, riid)) {
56  TRACE("(%p)->(IID_IAuthenticate %p)\n", This, ppv);
57  *ppv = &This->IAuthenticate_iface;
58  }else if(IsEqualGUID(&IID_IHttpNegotiate, riid)) {
59  TRACE("(%p)->(IID_IHttpNegotiate %p)\n", This, ppv);
60  *ppv = &This->IHttpNegotiate_iface;
61  }else if(IsEqualGUID(&IID_IExtensionServices, riid)) {
62  TRACE("(%p)->(IID_IExtensionServices %p)\n", This, ppv);
63  *ppv = &This->IExtensionServices_iface;
64  }
65 
66  if(*ppv) {
67  IUnknown_AddRef((IUnknown*)*ppv);
68  return S_OK;
69  }
70 
71  FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
72  return E_NOINTERFACE;
73 }
74 
76 {
79 
80  TRACE("(%p) ref=%d\n", This, ref);
81 
82  return ref;
83 }
84 
86 {
89 
90  TRACE("(%p) ref=%d\n", This, ref);
91 
92  if(!ref) {
93  heap_free(This->username);
94  heap_free(This->password);
95  heap_free(This->headers);
96  heap_free(This);
97  }
98 
99  return ref;
100 }
101 
102 static const IUnknownVtbl ExtServUnkVtbl = {
106 };
107 
109 {
110  return CONTAINING_RECORD(iface, ExtensionService, IAuthenticate_iface);
111 }
112 
114 {
116  return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
117 }
118 
120 {
122  return IUnknown_AddRef(This->outer_unk);
123 }
124 
126 {
128  return IUnknown_Release(This->outer_unk);
129 }
130 
132  HWND *phwnd, LPWSTR *pszUsername, LPWSTR *pszPassword)
133 {
135 
136  TRACE("(%p)->(%p %p %p)\n", This, phwnd, pszUsername, pszPassword);
137 
138  if(!phwnd || !pszUsername || !pszPassword)
139  return E_INVALIDARG;
140 
141  *phwnd = This->hwnd;
142  *pszUsername = hlink_co_strdupW(This->username);
143  *pszPassword = hlink_co_strdupW(This->password);
144 
145  return S_OK;
146 }
147 
148 static const IAuthenticateVtbl AuthenticateVtbl = {
153 };
154 
156 {
157  return CONTAINING_RECORD(iface, ExtensionService, IHttpNegotiate_iface);
158 }
159 
161 {
163  return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
164 }
165 
167 {
169  return IUnknown_AddRef(This->outer_unk);
170 }
171 
173 {
175  return IUnknown_Release(This->outer_unk);
176 }
177 
179  LPCWSTR szURL, LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
180 {
182 
183  TRACE("(%p)->(%s %s %x %p)\n", This, debugstr_w(szURL), debugstr_w(szHeaders), dwReserved,
184  pszAdditionalHeaders);
185 
186  if(!pszAdditionalHeaders)
187  return E_INVALIDARG;
188 
189  *pszAdditionalHeaders = hlink_co_strdupW(This->headers);
190  return S_OK;
191 }
192 
194  LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders)
195 {
197 
198  TRACE("(%p)->(%d %s %s %p)\n", This, dwResponseCode, debugstr_w(szResponseHeaders),
199  debugstr_w(szRequestHeaders), pszAdditionalRequestHeaders);
200 
201  *pszAdditionalRequestHeaders = NULL;
202  return S_OK;
203 }
204 
205 static const IHttpNegotiateVtbl HttpNegotiateVtbl = {
211 };
212 
214 {
215  return CONTAINING_RECORD(iface, ExtensionService, IExtensionServices_iface);
216 }
217 
219 {
221  return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
222 }
223 
225 {
227  return IUnknown_AddRef(This->outer_unk);
228 }
229 
231 {
233  return IUnknown_Release(This->outer_unk);
234 }
235 
237 {
238  int len;
239 
240  heap_free(This->headers);
241  This->headers = NULL;
242 
243  if (!pwzAdditionalHeaders)
244  return S_OK;
245 
246  len = strlenW(pwzAdditionalHeaders);
247 
248  if(len && pwzAdditionalHeaders[len-1] != '\n' && pwzAdditionalHeaders[len-1] != '\r') {
249  static const WCHAR endlW[] = {'\r','\n',0};
250  This->headers = heap_alloc(len*sizeof(WCHAR) + sizeof(endlW));
251  memcpy(This->headers, pwzAdditionalHeaders, len*sizeof(WCHAR));
252  memcpy(This->headers+len, endlW, sizeof(endlW));
253  }else {
254  This->headers = hlink_strdupW(pwzAdditionalHeaders);
255  }
256 
257  return S_OK;
258 }
259 
261 {
263 
264  TRACE("(%p)->(%s)\n", This, debugstr_w(pwzAdditionalHeaders));
265 
266  return ExtServ_ImplSetAdditionalHeaders(This,pwzAdditionalHeaders);
267 }
268 
270 {
271  heap_free(This->username);
272  heap_free(This->password);
273 
274  This->hwnd = phwnd;
275  This->username = hlink_strdupW(pwzUsername);
276  This->password = hlink_strdupW(pwzPassword);
277 
278  return S_OK;
279 }
280 
281 static HRESULT WINAPI ExtServ_SetAuthenticateData(IExtensionServices* iface, HWND phwnd, LPCWSTR pwzUsername, LPCWSTR pwzPassword)
282 {
284 
285  TRACE("(%p)->(%p %s %s)\n", This, phwnd, debugstr_w(pwzUsername), debugstr_w(pwzPassword));
286 
287  return ExtServ_ImplSetAuthenticateData(This, phwnd, pwzUsername, pwzPassword);
288 }
289 
290 static const IExtensionServicesVtbl ExtServVtbl = {
296 };
297 
298 /***********************************************************************
299  * HlinkCreateExtensionServices (HLINK.@)
300  */
302  HWND phwnd, LPCWSTR pszUsername, LPCWSTR pszPassword,
303  IUnknown *punkOuter, REFIID riid, void** ppv)
304 {
306  HRESULT hres = S_OK;
307 
308  TRACE("%s %p %s %s %p %s %p\n",debugstr_w(pwzAdditionalHeaders),
309  phwnd, debugstr_w(pszUsername), debugstr_w(pszPassword),
310  punkOuter, debugstr_guid(riid), ppv);
311 
312  ret = heap_alloc(sizeof(*ret));
313 
314  ret->IUnknown_inner.lpVtbl = &ExtServUnkVtbl;
315  ret->IAuthenticate_iface.lpVtbl = &AuthenticateVtbl;
316  ret->IHttpNegotiate_iface.lpVtbl = &HttpNegotiateVtbl;
317  ret->IExtensionServices_iface.lpVtbl = &ExtServVtbl;
318  ret->ref = 1;
319  ret->headers = NULL;
320  ret->hwnd = NULL;
321  ret->username = NULL;
322  ret->password = NULL;
323 
324  ExtServ_ImplSetAuthenticateData(ret, phwnd, pszUsername, pszPassword);
325  ExtServ_ImplSetAdditionalHeaders(ret, pwzAdditionalHeaders);
326 
327  if(!punkOuter) {
328  ret->outer_unk = &ret->IUnknown_inner;
329  hres = IUnknown_QueryInterface(&ret->IUnknown_inner, riid, ppv);
330  IUnknown_Release(&ret->IUnknown_inner);
331  }else if(IsEqualGUID(&IID_IUnknown, riid)) {
332  ret->outer_unk = punkOuter;
333  *ppv = &ret->IUnknown_inner;
334  }else {
335  IUnknown_Release(&ret->IUnknown_inner);
336  hres = E_INVALIDARG;
337  }
338 
339  return hres;
340 }
static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate *iface)
Definition: extserv.c:166
static ULONG WINAPI ExtServ_Release(IExtensionServices *iface)
Definition: extserv.c:230
static ULONG WINAPI Authenticate_AddRef(IAuthenticate *iface)
Definition: extserv.c:119
static const IHttpNegotiateVtbl HttpNegotiateVtbl
Definition: extserv.c:205
static const IAuthenticateVtbl AuthenticateVtbl
Definition: extserv.c:148
static HRESULT WINAPI Authenticate_QueryInterface(IAuthenticate *iface, REFIID riid, void **ppv)
Definition: extserv.c:113
IHttpNegotiate IHttpNegotiate_iface
Definition: extserv.c:29
static ULONG WINAPI ExtServUnk_AddRef(IUnknown *iface)
Definition: extserv.c:75
#define REFIID
Definition: guiddef.h:118
#define E_NOINTERFACE
Definition: winerror.h:2364
static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate *iface, LPCWSTR szURL, LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
Definition: extserv.c:178
LPWSTR headers
Definition: extserv.c:38
WINE_UNICODE_INLINE unsigned int strlenW(const WCHAR *str)
Definition: unicode.h:212
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
LPWSTR password
Definition: extserv.c:37
static ExtensionService * impl_from_IExtensionServices(IExtensionServices *iface)
Definition: extserv.c:213
LPWSTR username
Definition: extserv.c:36
static const IUnknownVtbl ExtServUnkVtbl
Definition: extserv.c:102
REFIID riid
Definition: precomp.h:44
static ExtensionService * impl_from_IUnknown(IUnknown *iface)
Definition: extserv.c:41
static ExtensionService * impl_from_IAuthenticate(IAuthenticate *iface)
Definition: extserv.c:108
REFIID LPVOID * ppv
Definition: atlbase.h:39
static HRESULT WINAPI ExtServ_SetAdditionalHeaders(IExtensionServices *iface, LPCWSTR pwzAdditionalHeaders)
Definition: extserv.c:260
static HRESULT WINAPI Authenticate_Authenticate(IAuthenticate *iface, HWND *phwnd, LPWSTR *pszUsername, LPWSTR *pszPassword)
Definition: extserv.c:131
IUnknown IUnknown_inner
Definition: extserv.c:27
Definition: send.c:47
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
static ULONG WINAPI ExtServ_AddRef(IExtensionServices *iface)
Definition: extserv.c:224
IExtensionServices IExtensionServices_iface
Definition: extserv.c:30
static ULONG WINAPI Authenticate_Release(IAuthenticate *iface)
Definition: extserv.c:125
_In_ HANDLE _In_ DWORD _In_ DWORD _Inout_opt_ LPOVERLAPPED _In_opt_ LPTRANSMIT_FILE_BUFFERS _In_ DWORD dwReserved
Definition: mswsock.h:90
long LONG
Definition: pedump.c:60
#define debugstr_w
Definition: kernel32.h:32
GLenum GLint ref
Definition: glext.h:6028
static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate *iface)
Definition: extserv.c:172
#define FIXME(fmt,...)
Definition: debug.h:110
static HRESULT WINAPI ExtServ_SetAuthenticateData(IExtensionServices *iface, HWND phwnd, LPCWSTR pwzUsername, LPCWSTR pwzPassword)
Definition: extserv.c:281
#define E_INVALIDARG
Definition: ddrawi.h:101
smooth NULL
Definition: ftsmooth.c:416
#define debugstr_guid
Definition: kernel32.h:35
static HRESULT ExtServ_ImplSetAdditionalHeaders(ExtensionService *This, LPCWSTR pwzAdditionalHeaders)
Definition: extserv.c:236
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
IAuthenticate IAuthenticate_iface
Definition: extserv.c:28
static ExtensionService * impl_from_IHttpNegotiate(IHttpNegotiate *iface)
Definition: extserv.c:155
static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate *iface, DWORD dwResponseCode, LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders)
Definition: extserv.c:193
static ULONG WINAPI ExtServUnk_Release(IUnknown *iface)
Definition: extserv.c:85
#define TRACE(s)
Definition: solgame.cpp:4
HRESULT hres
Definition: protocol.c:465
static HRESULT ExtServ_ImplSetAuthenticateData(ExtensionService *This, HWND phwnd, LPCWSTR pwzUsername, LPCWSTR pwzPassword)
Definition: extserv.c:269
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
const GUID IID_IUnknown
#define WINAPI
Definition: msvc.h:8
HRESULT WINAPI HlinkCreateExtensionServices(LPCWSTR pwzAdditionalHeaders, HWND phwnd, LPCWSTR pszUsername, LPCWSTR pszPassword, IUnknown *punkOuter, REFIID riid, void **ppv)
Definition: extserv.c:301
unsigned long DWORD
Definition: ntddk_ex.h:95
int ret
#define InterlockedDecrement
Definition: armddk.h:52
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLsizei len
Definition: glext.h:6722
static HRESULT WINAPI ExtServUnk_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
Definition: extserv.c:46
static const IExtensionServicesVtbl ExtServVtbl
Definition: extserv.c:290
#define S_OK
Definition: intsafe.h:59
#define InterlockedIncrement
Definition: armddk.h:53
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4021
IUnknown * outer_unk
Definition: extserv.c:32
unsigned int ULONG
Definition: retypes.h:1
static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate *iface, REFIID riid, void **ppv)
Definition: extserv.c:160
WCHAR * LPWSTR
Definition: xmlstorage.h:184
WINE_DEFAULT_DEBUG_CHANNEL(hlink)
static HRESULT WINAPI ExtServ_QueryInterface(IExtensionServices *iface, REFIID riid, void **ppv)
Definition: extserv.c:218
static BOOL heap_free(void *mem)
Definition: appwiz.h:75