2007-11-21 11:35:00 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2007 Jacek Caban for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "hlink_private.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(hlink);
|
|
|
|
|
|
|
|
typedef struct {
|
2012-03-19 00:29:07 +01:00
|
|
|
IUnknown IUnknown_inner;
|
2011-01-05 00:36:48 +01:00
|
|
|
IAuthenticate IAuthenticate_iface;
|
|
|
|
IHttpNegotiate IHttpNegotiate_iface;
|
|
|
|
IExtensionServices IExtensionServices_iface;
|
2007-11-21 11:35:00 +01:00
|
|
|
|
2012-03-19 00:29:07 +01:00
|
|
|
IUnknown *outer_unk;
|
2007-11-21 11:35:00 +01:00
|
|
|
LONG ref;
|
|
|
|
|
|
|
|
HWND hwnd;
|
|
|
|
LPWSTR username;
|
|
|
|
LPWSTR password;
|
2007-12-06 13:17:30 +01:00
|
|
|
LPWSTR headers;
|
2007-11-21 11:35:00 +01:00
|
|
|
} ExtensionService;
|
|
|
|
|
2011-01-05 00:36:48 +01:00
|
|
|
static inline ExtensionService *impl_from_IUnknown(IUnknown *iface)
|
|
|
|
{
|
2012-03-19 00:29:07 +01:00
|
|
|
return CONTAINING_RECORD(iface, ExtensionService, IUnknown_inner);
|
2011-01-05 00:36:48 +01:00
|
|
|
}
|
2007-11-21 11:35:00 +01:00
|
|
|
|
|
|
|
static HRESULT WINAPI ExtServUnk_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
2011-01-05 00:36:48 +01:00
|
|
|
ExtensionService *This = impl_from_IUnknown(iface);
|
2007-11-21 11:35:00 +01:00
|
|
|
|
|
|
|
*ppv = NULL;
|
|
|
|
|
|
|
|
if(IsEqualGUID(&IID_IUnknown, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
|
2012-03-19 00:29:07 +01:00
|
|
|
*ppv = &This->IUnknown_inner;
|
2007-11-21 11:35:00 +01:00
|
|
|
}else if(IsEqualGUID(&IID_IAuthenticate, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IAuthenticate %p)\n", This, ppv);
|
2011-01-05 00:36:48 +01:00
|
|
|
*ppv = &This->IAuthenticate_iface;
|
2007-12-06 13:17:30 +01:00
|
|
|
}else if(IsEqualGUID(&IID_IHttpNegotiate, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IHttpNegotiate %p)\n", This, ppv);
|
2011-01-05 00:36:48 +01:00
|
|
|
*ppv = &This->IHttpNegotiate_iface;
|
2008-04-28 20:44:16 +02:00
|
|
|
}else if(IsEqualGUID(&IID_IExtensionServices, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IExtensionServices %p)\n", This, ppv);
|
2011-01-05 00:36:48 +01:00
|
|
|
*ppv = &This->IExtensionServices_iface;
|
2007-11-21 11:35:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(*ppv) {
|
2008-01-29 00:19:22 +01:00
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
2007-11-21 11:35:00 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ExtServUnk_AddRef(IUnknown *iface)
|
|
|
|
{
|
2011-01-05 00:36:48 +01:00
|
|
|
ExtensionService *This = impl_from_IUnknown(iface);
|
2007-11-21 11:35:00 +01:00
|
|
|
LONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
2022-02-10 08:43:37 +01:00
|
|
|
TRACE("(%p) ref=%ld\n", This, ref);
|
2007-11-21 11:35:00 +01:00
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ExtServUnk_Release(IUnknown *iface)
|
|
|
|
{
|
2011-01-05 00:36:48 +01:00
|
|
|
ExtensionService *This = impl_from_IUnknown(iface);
|
2007-11-21 11:35:00 +01:00
|
|
|
LONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
2022-02-10 08:43:37 +01:00
|
|
|
TRACE("(%p) ref=%ld\n", This, ref);
|
2007-11-21 11:35:00 +01:00
|
|
|
|
|
|
|
if(!ref) {
|
2007-12-09 16:29:51 +01:00
|
|
|
heap_free(This->username);
|
|
|
|
heap_free(This->password);
|
2007-12-26 12:02:48 +01:00
|
|
|
heap_free(This->headers);
|
2007-12-09 16:29:51 +01:00
|
|
|
heap_free(This);
|
2007-11-21 11:35:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IUnknownVtbl ExtServUnkVtbl = {
|
|
|
|
ExtServUnk_QueryInterface,
|
|
|
|
ExtServUnk_AddRef,
|
|
|
|
ExtServUnk_Release
|
|
|
|
};
|
|
|
|
|
2011-01-05 00:36:48 +01:00
|
|
|
static inline ExtensionService *impl_from_IAuthenticate(IAuthenticate *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, ExtensionService, IAuthenticate_iface);
|
|
|
|
}
|
2007-11-21 11:35:00 +01:00
|
|
|
|
|
|
|
static HRESULT WINAPI Authenticate_QueryInterface(IAuthenticate *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
2011-01-05 00:36:48 +01:00
|
|
|
ExtensionService *This = impl_from_IAuthenticate(iface);
|
2012-03-19 00:29:07 +01:00
|
|
|
return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
|
2007-11-21 11:35:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI Authenticate_AddRef(IAuthenticate *iface)
|
|
|
|
{
|
2011-01-05 00:36:48 +01:00
|
|
|
ExtensionService *This = impl_from_IAuthenticate(iface);
|
2012-03-19 00:29:07 +01:00
|
|
|
return IUnknown_AddRef(This->outer_unk);
|
2007-11-21 11:35:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI Authenticate_Release(IAuthenticate *iface)
|
|
|
|
{
|
2011-01-05 00:36:48 +01:00
|
|
|
ExtensionService *This = impl_from_IAuthenticate(iface);
|
2012-03-19 00:29:07 +01:00
|
|
|
return IUnknown_Release(This->outer_unk);
|
2007-11-21 11:35:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Authenticate_Authenticate(IAuthenticate *iface,
|
|
|
|
HWND *phwnd, LPWSTR *pszUsername, LPWSTR *pszPassword)
|
|
|
|
{
|
2011-01-05 00:36:48 +01:00
|
|
|
ExtensionService *This = impl_from_IAuthenticate(iface);
|
2007-11-21 11:35:00 +01:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p %p %p)\n", This, phwnd, pszUsername, pszPassword);
|
|
|
|
|
|
|
|
if(!phwnd || !pszUsername || !pszPassword)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
*phwnd = This->hwnd;
|
|
|
|
*pszUsername = hlink_co_strdupW(This->username);
|
|
|
|
*pszPassword = hlink_co_strdupW(This->password);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IAuthenticateVtbl AuthenticateVtbl = {
|
|
|
|
Authenticate_QueryInterface,
|
|
|
|
Authenticate_AddRef,
|
|
|
|
Authenticate_Release,
|
|
|
|
Authenticate_Authenticate
|
|
|
|
};
|
|
|
|
|
2011-01-05 00:36:48 +01:00
|
|
|
static inline ExtensionService *impl_from_IHttpNegotiate(IHttpNegotiate *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, ExtensionService, IHttpNegotiate_iface);
|
|
|
|
}
|
2007-12-06 13:17:30 +01:00
|
|
|
|
|
|
|
static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
2011-01-05 00:36:48 +01:00
|
|
|
ExtensionService *This = impl_from_IHttpNegotiate(iface);
|
2012-03-19 00:29:07 +01:00
|
|
|
return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
|
2007-12-06 13:17:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate *iface)
|
|
|
|
{
|
2011-01-05 00:36:48 +01:00
|
|
|
ExtensionService *This = impl_from_IHttpNegotiate(iface);
|
2012-03-19 00:29:07 +01:00
|
|
|
return IUnknown_AddRef(This->outer_unk);
|
2007-12-06 13:17:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate *iface)
|
|
|
|
{
|
2011-01-05 00:36:48 +01:00
|
|
|
ExtensionService *This = impl_from_IHttpNegotiate(iface);
|
2012-03-19 00:29:07 +01:00
|
|
|
return IUnknown_Release(This->outer_unk);
|
2007-12-06 13:17:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate *iface,
|
|
|
|
LPCWSTR szURL, LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
|
|
|
|
{
|
2011-01-05 00:36:48 +01:00
|
|
|
ExtensionService *This = impl_from_IHttpNegotiate(iface);
|
2007-12-06 13:17:30 +01:00
|
|
|
|
2022-02-10 08:43:37 +01:00
|
|
|
TRACE("(%p)->(%s %s %lx %p)\n", This, debugstr_w(szURL), debugstr_w(szHeaders), dwReserved,
|
2007-12-06 13:17:30 +01:00
|
|
|
pszAdditionalHeaders);
|
|
|
|
|
|
|
|
if(!pszAdditionalHeaders)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
*pszAdditionalHeaders = hlink_co_strdupW(This->headers);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate *iface, DWORD dwResponseCode,
|
|
|
|
LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders)
|
|
|
|
{
|
2011-01-05 00:36:48 +01:00
|
|
|
ExtensionService *This = impl_from_IHttpNegotiate(iface);
|
2007-12-06 13:17:30 +01:00
|
|
|
|
2022-02-10 08:43:37 +01:00
|
|
|
TRACE("(%p)->(%ld %s %s %p)\n", This, dwResponseCode, debugstr_w(szResponseHeaders),
|
2007-12-06 13:17:30 +01:00
|
|
|
debugstr_w(szRequestHeaders), pszAdditionalRequestHeaders);
|
|
|
|
|
|
|
|
*pszAdditionalRequestHeaders = NULL;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IHttpNegotiateVtbl HttpNegotiateVtbl = {
|
|
|
|
HttpNegotiate_QueryInterface,
|
|
|
|
HttpNegotiate_AddRef,
|
|
|
|
HttpNegotiate_Release,
|
|
|
|
HttpNegotiate_BeginningTransaction,
|
|
|
|
HttpNegotiate_OnResponse
|
|
|
|
};
|
|
|
|
|
2011-01-05 00:36:48 +01:00
|
|
|
static inline ExtensionService *impl_from_IExtensionServices(IExtensionServices *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, ExtensionService, IExtensionServices_iface);
|
|
|
|
}
|
2008-04-28 20:44:16 +02:00
|
|
|
|
|
|
|
static HRESULT WINAPI ExtServ_QueryInterface(IExtensionServices *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
2011-01-05 00:36:48 +01:00
|
|
|
ExtensionService *This = impl_from_IExtensionServices(iface);
|
2012-03-19 00:29:07 +01:00
|
|
|
return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
|
2008-04-28 20:44:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ExtServ_AddRef(IExtensionServices *iface)
|
|
|
|
{
|
2011-01-05 00:36:48 +01:00
|
|
|
ExtensionService *This = impl_from_IExtensionServices(iface);
|
2012-03-19 00:29:07 +01:00
|
|
|
return IUnknown_AddRef(This->outer_unk);
|
2008-04-28 20:44:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ExtServ_Release(IExtensionServices *iface)
|
|
|
|
{
|
2011-01-05 00:36:48 +01:00
|
|
|
ExtensionService *This = impl_from_IExtensionServices(iface);
|
2012-03-19 00:29:07 +01:00
|
|
|
return IUnknown_Release(This->outer_unk);
|
2008-04-28 20:44:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT ExtServ_ImplSetAdditionalHeaders(ExtensionService* This, LPCWSTR pwzAdditionalHeaders)
|
|
|
|
{
|
2013-03-23 18:53:14 +01:00
|
|
|
int len;
|
2008-04-28 20:44:16 +02:00
|
|
|
|
|
|
|
heap_free(This->headers);
|
|
|
|
This->headers = NULL;
|
|
|
|
|
|
|
|
if (!pwzAdditionalHeaders)
|
|
|
|
return S_OK;
|
|
|
|
|
2019-06-05 08:37:02 +02:00
|
|
|
len = lstrlenW(pwzAdditionalHeaders);
|
2008-04-28 20:44:16 +02:00
|
|
|
|
|
|
|
if(len && pwzAdditionalHeaders[len-1] != '\n' && pwzAdditionalHeaders[len-1] != '\r') {
|
2020-10-03 20:28:12 +02:00
|
|
|
This->headers = heap_alloc(len*sizeof(WCHAR) + sizeof(L"\r\n"));
|
2008-04-28 20:44:16 +02:00
|
|
|
memcpy(This->headers, pwzAdditionalHeaders, len*sizeof(WCHAR));
|
2020-10-03 20:28:12 +02:00
|
|
|
memcpy(This->headers+len, L"\r\n", sizeof(L"\r\n"));
|
2008-04-28 20:44:16 +02:00
|
|
|
}else {
|
|
|
|
This->headers = hlink_strdupW(pwzAdditionalHeaders);
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ExtServ_SetAdditionalHeaders(IExtensionServices* iface, LPCWSTR pwzAdditionalHeaders)
|
|
|
|
{
|
2011-01-05 00:36:48 +01:00
|
|
|
ExtensionService *This = impl_from_IExtensionServices(iface);
|
2008-04-28 20:44:16 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%s)\n", This, debugstr_w(pwzAdditionalHeaders));
|
|
|
|
|
|
|
|
return ExtServ_ImplSetAdditionalHeaders(This,pwzAdditionalHeaders);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT ExtServ_ImplSetAuthenticateData(ExtensionService* This, HWND phwnd, LPCWSTR pwzUsername, LPCWSTR pwzPassword)
|
|
|
|
{
|
|
|
|
heap_free(This->username);
|
|
|
|
heap_free(This->password);
|
|
|
|
|
|
|
|
This->hwnd = phwnd;
|
|
|
|
This->username = hlink_strdupW(pwzUsername);
|
|
|
|
This->password = hlink_strdupW(pwzPassword);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ExtServ_SetAuthenticateData(IExtensionServices* iface, HWND phwnd, LPCWSTR pwzUsername, LPCWSTR pwzPassword)
|
|
|
|
{
|
2011-01-05 00:36:48 +01:00
|
|
|
ExtensionService *This = impl_from_IExtensionServices(iface);
|
2008-04-28 20:44:16 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p %s %s)\n", This, phwnd, debugstr_w(pwzUsername), debugstr_w(pwzPassword));
|
|
|
|
|
|
|
|
return ExtServ_ImplSetAuthenticateData(This, phwnd, pwzUsername, pwzPassword);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IExtensionServicesVtbl ExtServVtbl = {
|
|
|
|
ExtServ_QueryInterface,
|
|
|
|
ExtServ_AddRef,
|
|
|
|
ExtServ_Release,
|
|
|
|
ExtServ_SetAdditionalHeaders,
|
|
|
|
ExtServ_SetAuthenticateData
|
|
|
|
};
|
|
|
|
|
2008-01-29 00:22:54 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* HlinkCreateExtensionServices (HLINK.@)
|
|
|
|
*/
|
2007-11-21 11:35:00 +01:00
|
|
|
HRESULT WINAPI HlinkCreateExtensionServices(LPCWSTR pwzAdditionalHeaders,
|
|
|
|
HWND phwnd, LPCWSTR pszUsername, LPCWSTR pszPassword,
|
|
|
|
IUnknown *punkOuter, REFIID riid, void** ppv)
|
|
|
|
{
|
|
|
|
ExtensionService *ret;
|
|
|
|
HRESULT hres = S_OK;
|
|
|
|
|
|
|
|
TRACE("%s %p %s %s %p %s %p\n",debugstr_w(pwzAdditionalHeaders),
|
|
|
|
phwnd, debugstr_w(pszUsername), debugstr_w(pszPassword),
|
|
|
|
punkOuter, debugstr_guid(riid), ppv);
|
|
|
|
|
2007-12-09 16:29:51 +01:00
|
|
|
ret = heap_alloc(sizeof(*ret));
|
2007-11-21 11:35:00 +01:00
|
|
|
|
2012-03-19 00:29:07 +01:00
|
|
|
ret->IUnknown_inner.lpVtbl = &ExtServUnkVtbl;
|
2011-01-05 00:36:48 +01:00
|
|
|
ret->IAuthenticate_iface.lpVtbl = &AuthenticateVtbl;
|
|
|
|
ret->IHttpNegotiate_iface.lpVtbl = &HttpNegotiateVtbl;
|
|
|
|
ret->IExtensionServices_iface.lpVtbl = &ExtServVtbl;
|
2007-11-21 11:35:00 +01:00
|
|
|
ret->ref = 1;
|
2008-04-28 20:44:16 +02:00
|
|
|
ret->headers = NULL;
|
|
|
|
ret->hwnd = NULL;
|
|
|
|
ret->username = NULL;
|
|
|
|
ret->password = NULL;
|
2007-12-06 13:17:30 +01:00
|
|
|
|
2008-04-28 20:44:16 +02:00
|
|
|
ExtServ_ImplSetAuthenticateData(ret, phwnd, pszUsername, pszPassword);
|
|
|
|
ExtServ_ImplSetAdditionalHeaders(ret, pwzAdditionalHeaders);
|
2007-11-21 11:35:00 +01:00
|
|
|
|
|
|
|
if(!punkOuter) {
|
2012-03-19 00:29:07 +01:00
|
|
|
ret->outer_unk = &ret->IUnknown_inner;
|
|
|
|
hres = IUnknown_QueryInterface(&ret->IUnknown_inner, riid, ppv);
|
|
|
|
IUnknown_Release(&ret->IUnknown_inner);
|
2007-11-21 11:35:00 +01:00
|
|
|
}else if(IsEqualGUID(&IID_IUnknown, riid)) {
|
2012-03-19 00:29:07 +01:00
|
|
|
ret->outer_unk = punkOuter;
|
|
|
|
*ppv = &ret->IUnknown_inner;
|
2007-11-21 11:35:00 +01:00
|
|
|
}else {
|
2012-03-19 00:29:07 +01:00
|
|
|
IUnknown_Release(&ret->IUnknown_inner);
|
2007-11-21 11:35:00 +01:00
|
|
|
hres = E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hres;
|
|
|
|
}
|