ReactOS  0.4.14-dev-317-g96040ec
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 
24 
25 typedef struct {
30 
33 
39 
41 {
42  return CONTAINING_RECORD(iface, ExtensionService, IUnknown_inner);
43 }
44 
46 {
48 
49  *ppv = NULL;
50 
52  TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
53  *ppv = &This->IUnknown_inner;
54  }else if(IsEqualGUID(&IID_IAuthenticate, riid)) {
55  TRACE("(%p)->(IID_IAuthenticate %p)\n", This, ppv);
56  *ppv = &This->IAuthenticate_iface;
57  }else if(IsEqualGUID(&IID_IHttpNegotiate, riid)) {
58  TRACE("(%p)->(IID_IHttpNegotiate %p)\n", This, ppv);
59  *ppv = &This->IHttpNegotiate_iface;
60  }else if(IsEqualGUID(&IID_IExtensionServices, riid)) {
61  TRACE("(%p)->(IID_IExtensionServices %p)\n", This, ppv);
62  *ppv = &This->IExtensionServices_iface;
63  }
64 
65  if(*ppv) {
66  IUnknown_AddRef((IUnknown*)*ppv);
67  return S_OK;
68  }
69 
70  FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
71  return E_NOINTERFACE;
72 }
73 
75 {
78 
79  TRACE("(%p) ref=%d\n", This, ref);
80 
81  return ref;
82 }
83 
85 {
88 
89  TRACE("(%p) ref=%d\n", This, ref);
90 
91  if(!ref) {
92  heap_free(This->username);
93  heap_free(This->password);
94  heap_free(This->headers);
95  heap_free(This);
96  }
97 
98  return ref;
99 }
100 
101 static const IUnknownVtbl ExtServUnkVtbl = {
105 };
106 
108 {
109  return CONTAINING_RECORD(iface, ExtensionService, IAuthenticate_iface);
110 }
111 
113 {
115  return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
116 }
117 
119 {
121  return IUnknown_AddRef(This->outer_unk);
122 }
123 
125 {
127  return IUnknown_Release(This->outer_unk);
128 }
129 
131  HWND *phwnd, LPWSTR *pszUsername, LPWSTR *pszPassword)
132 {
134 
135  TRACE("(%p)->(%p %p %p)\n", This, phwnd, pszUsername, pszPassword);
136 
137  if(!phwnd || !pszUsername || !pszPassword)
138  return E_INVALIDARG;
139 
140  *phwnd = This->hwnd;
141  *pszUsername = hlink_co_strdupW(This->username);
142  *pszPassword = hlink_co_strdupW(This->password);
143 
144  return S_OK;
145 }
146 
147 static const IAuthenticateVtbl AuthenticateVtbl = {
152 };
153 
155 {
156  return CONTAINING_RECORD(iface, ExtensionService, IHttpNegotiate_iface);
157 }
158 
160 {
162  return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
163 }
164 
166 {
168  return IUnknown_AddRef(This->outer_unk);
169 }
170 
172 {
174  return IUnknown_Release(This->outer_unk);
175 }
176 
178  LPCWSTR szURL, LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
179 {
181 
182  TRACE("(%p)->(%s %s %x %p)\n", This, debugstr_w(szURL), debugstr_w(szHeaders), dwReserved,
183  pszAdditionalHeaders);
184 
185  if(!pszAdditionalHeaders)
186  return E_INVALIDARG;
187 
188  *pszAdditionalHeaders = hlink_co_strdupW(This->headers);
189  return S_OK;
190 }
191 
193  LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders)
194 {
196 
197  TRACE("(%p)->(%d %s %s %p)\n", This, dwResponseCode, debugstr_w(szResponseHeaders),
198  debugstr_w(szRequestHeaders), pszAdditionalRequestHeaders);
199 
200  *pszAdditionalRequestHeaders = NULL;
201  return S_OK;
202 }
203 
204 static const IHttpNegotiateVtbl HttpNegotiateVtbl = {
210 };
211 
213 {
214  return CONTAINING_RECORD(iface, ExtensionService, IExtensionServices_iface);
215 }
216 
218 {
220  return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
221 }
222 
224 {
226  return IUnknown_AddRef(This->outer_unk);
227 }
228 
230 {
232  return IUnknown_Release(This->outer_unk);
233 }
234 
236 {
237  int len;
238 
239  heap_free(This->headers);
240  This->headers = NULL;
241 
242  if (!pwzAdditionalHeaders)
243  return S_OK;
244 
245  len = lstrlenW(pwzAdditionalHeaders);
246 
247  if(len && pwzAdditionalHeaders[len-1] != '\n' && pwzAdditionalHeaders[len-1] != '\r') {
248  static const WCHAR endlW[] = {'\r','\n',0};
249  This->headers = heap_alloc(len*sizeof(WCHAR) + sizeof(endlW));
250  memcpy(This->headers, pwzAdditionalHeaders, len*sizeof(WCHAR));
251  memcpy(This->headers+len, endlW, sizeof(endlW));
252  }else {
253  This->headers = hlink_strdupW(pwzAdditionalHeaders);
254  }
255 
256  return S_OK;
257 }
258 
260 {
262 
263  TRACE("(%p)->(%s)\n", This, debugstr_w(pwzAdditionalHeaders));
264 
265  return ExtServ_ImplSetAdditionalHeaders(This,pwzAdditionalHeaders);
266 }
267 
269 {
270  heap_free(This->username);
271  heap_free(This->password);
272 
273  This->hwnd = phwnd;
274  This->username = hlink_strdupW(pwzUsername);
275  This->password = hlink_strdupW(pwzPassword);
276 
277  return S_OK;
278 }
279 
280 static HRESULT WINAPI ExtServ_SetAuthenticateData(IExtensionServices* iface, HWND phwnd, LPCWSTR pwzUsername, LPCWSTR pwzPassword)
281 {
283 
284  TRACE("(%p)->(%p %s %s)\n", This, phwnd, debugstr_w(pwzUsername), debugstr_w(pwzPassword));
285 
286  return ExtServ_ImplSetAuthenticateData(This, phwnd, pwzUsername, pwzPassword);
287 }
288 
289 static const IExtensionServicesVtbl ExtServVtbl = {
295 };
296 
297 /***********************************************************************
298  * HlinkCreateExtensionServices (HLINK.@)
299  */
301  HWND phwnd, LPCWSTR pszUsername, LPCWSTR pszPassword,
302  IUnknown *punkOuter, REFIID riid, void** ppv)
303 {
305  HRESULT hres = S_OK;
306 
307  TRACE("%s %p %s %s %p %s %p\n",debugstr_w(pwzAdditionalHeaders),
308  phwnd, debugstr_w(pszUsername), debugstr_w(pszPassword),
309  punkOuter, debugstr_guid(riid), ppv);
310 
311  ret = heap_alloc(sizeof(*ret));
312 
313  ret->IUnknown_inner.lpVtbl = &ExtServUnkVtbl;
314  ret->IAuthenticate_iface.lpVtbl = &AuthenticateVtbl;
315  ret->IHttpNegotiate_iface.lpVtbl = &HttpNegotiateVtbl;
316  ret->IExtensionServices_iface.lpVtbl = &ExtServVtbl;
317  ret->ref = 1;
318  ret->headers = NULL;
319  ret->hwnd = NULL;
320  ret->username = NULL;
321  ret->password = NULL;
322 
323  ExtServ_ImplSetAuthenticateData(ret, phwnd, pszUsername, pszPassword);
324  ExtServ_ImplSetAdditionalHeaders(ret, pwzAdditionalHeaders);
325 
326  if(!punkOuter) {
327  ret->outer_unk = &ret->IUnknown_inner;
328  hres = IUnknown_QueryInterface(&ret->IUnknown_inner, riid, ppv);
329  IUnknown_Release(&ret->IUnknown_inner);
330  }else if(IsEqualGUID(&IID_IUnknown, riid)) {
331  ret->outer_unk = punkOuter;
332  *ppv = &ret->IUnknown_inner;
333  }else {
334  IUnknown_Release(&ret->IUnknown_inner);
335  hres = E_INVALIDARG;
336  }
337 
338  return hres;
339 }
static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate *iface)
Definition: extserv.c:165
static ULONG WINAPI ExtServ_Release(IExtensionServices *iface)
Definition: extserv.c:229
static ULONG WINAPI Authenticate_AddRef(IAuthenticate *iface)
Definition: extserv.c:118
static const IHttpNegotiateVtbl HttpNegotiateVtbl
Definition: extserv.c:204
static const IAuthenticateVtbl AuthenticateVtbl
Definition: extserv.c:147
static HRESULT WINAPI Authenticate_QueryInterface(IAuthenticate *iface, REFIID riid, void **ppv)
Definition: extserv.c:112
IHttpNegotiate IHttpNegotiate_iface
Definition: extserv.c:28
static ULONG WINAPI ExtServUnk_AddRef(IUnknown *iface)
Definition: extserv.c:74
#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:177
LPWSTR headers
Definition: extserv.c:37
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
LPWSTR password
Definition: extserv.c:36
static ExtensionService * impl_from_IExtensionServices(IExtensionServices *iface)
Definition: extserv.c:212
LPWSTR username
Definition: extserv.c:35
static const IUnknownVtbl ExtServUnkVtbl
Definition: extserv.c:101
REFIID riid
Definition: precomp.h:44
static ExtensionService * impl_from_IUnknown(IUnknown *iface)
Definition: extserv.c:40
static ExtensionService * impl_from_IAuthenticate(IAuthenticate *iface)
Definition: extserv.c:107
REFIID LPVOID * ppv
Definition: atlbase.h:39
static HRESULT WINAPI ExtServ_SetAdditionalHeaders(IExtensionServices *iface, LPCWSTR pwzAdditionalHeaders)
Definition: extserv.c:259
static HRESULT WINAPI Authenticate_Authenticate(IAuthenticate *iface, HWND *phwnd, LPWSTR *pszUsername, LPWSTR *pszPassword)
Definition: extserv.c:130
#define lstrlenW
Definition: compat.h:407
IUnknown IUnknown_inner
Definition: extserv.c:26
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:223
IExtensionServices IExtensionServices_iface
Definition: extserv.c:29
static ULONG WINAPI Authenticate_Release(IAuthenticate *iface)
Definition: extserv.c:124
_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:171
#define FIXME(fmt,...)
Definition: debug.h:110
static HRESULT WINAPI ExtServ_SetAuthenticateData(IExtensionServices *iface, HWND phwnd, LPCWSTR pwzUsername, LPCWSTR pwzPassword)
Definition: extserv.c:280
#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:235
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:27
static ExtensionService * impl_from_IHttpNegotiate(IHttpNegotiate *iface)
Definition: extserv.c:154
static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate *iface, DWORD dwResponseCode, LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders)
Definition: extserv.c:192
static ULONG WINAPI ExtServUnk_Release(IUnknown *iface)
Definition: extserv.c:84
#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:268
__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:300
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:45
static const IExtensionServicesVtbl ExtServVtbl
Definition: extserv.c:289
#define S_OK
Definition: intsafe.h:59
#define InterlockedIncrement
Definition: armddk.h:53
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4112
IUnknown * outer_unk
Definition: extserv.c:31
unsigned int ULONG
Definition: retypes.h:1
static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate *iface, REFIID riid, void **ppv)
Definition: extserv.c:159
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:217
static BOOL heap_free(void *mem)
Definition: appwiz.h:75