Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenextserv.c
Go to the documentation of this file.
00001 /* 00002 * Copyright 2007 Jacek Caban for CodeWeavers 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Lesser General Public 00006 * License as published by the Free Software Foundation; either 00007 * version 2.1 of the License, or (at your option) any later version. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Lesser General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public 00015 * License along with this library; if not, write to the Free Software 00016 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 00017 */ 00018 00019 #include "hlink_private.h" 00020 00021 #include "wine/debug.h" 00022 #include "wine/unicode.h" 00023 00024 WINE_DEFAULT_DEBUG_CHANNEL(hlink); 00025 00026 typedef struct { 00027 IUnknown IUnknown_inner; 00028 IAuthenticate IAuthenticate_iface; 00029 IHttpNegotiate IHttpNegotiate_iface; 00030 IExtensionServices IExtensionServices_iface; 00031 00032 IUnknown *outer_unk; 00033 LONG ref; 00034 00035 HWND hwnd; 00036 LPWSTR username; 00037 LPWSTR password; 00038 LPWSTR headers; 00039 } ExtensionService; 00040 00041 static inline ExtensionService *impl_from_IUnknown(IUnknown *iface) 00042 { 00043 return CONTAINING_RECORD(iface, ExtensionService, IUnknown_inner); 00044 } 00045 00046 static HRESULT WINAPI ExtServUnk_QueryInterface(IUnknown *iface, REFIID riid, void **ppv) 00047 { 00048 ExtensionService *This = impl_from_IUnknown(iface); 00049 00050 *ppv = NULL; 00051 00052 if(IsEqualGUID(&IID_IUnknown, riid)) { 00053 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv); 00054 *ppv = &This->IUnknown_inner; 00055 }else if(IsEqualGUID(&IID_IAuthenticate, riid)) { 00056 TRACE("(%p)->(IID_IAuthenticate %p)\n", This, ppv); 00057 *ppv = &This->IAuthenticate_iface; 00058 }else if(IsEqualGUID(&IID_IHttpNegotiate, riid)) { 00059 TRACE("(%p)->(IID_IHttpNegotiate %p)\n", This, ppv); 00060 *ppv = &This->IHttpNegotiate_iface; 00061 }else if(IsEqualGUID(&IID_IExtensionServices, riid)) { 00062 TRACE("(%p)->(IID_IExtensionServices %p)\n", This, ppv); 00063 *ppv = &This->IExtensionServices_iface; 00064 } 00065 00066 if(*ppv) { 00067 IUnknown_AddRef((IUnknown*)*ppv); 00068 return S_OK; 00069 } 00070 00071 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv); 00072 return E_NOINTERFACE; 00073 } 00074 00075 static ULONG WINAPI ExtServUnk_AddRef(IUnknown *iface) 00076 { 00077 ExtensionService *This = impl_from_IUnknown(iface); 00078 LONG ref = InterlockedIncrement(&This->ref); 00079 00080 TRACE("(%p) ref=%d\n", This, ref); 00081 00082 return ref; 00083 } 00084 00085 static ULONG WINAPI ExtServUnk_Release(IUnknown *iface) 00086 { 00087 ExtensionService *This = impl_from_IUnknown(iface); 00088 LONG ref = InterlockedDecrement(&This->ref); 00089 00090 TRACE("(%p) ref=%d\n", This, ref); 00091 00092 if(!ref) { 00093 heap_free(This->username); 00094 heap_free(This->password); 00095 heap_free(This->headers); 00096 heap_free(This); 00097 } 00098 00099 return ref; 00100 } 00101 00102 static const IUnknownVtbl ExtServUnkVtbl = { 00103 ExtServUnk_QueryInterface, 00104 ExtServUnk_AddRef, 00105 ExtServUnk_Release 00106 }; 00107 00108 static inline ExtensionService *impl_from_IAuthenticate(IAuthenticate *iface) 00109 { 00110 return CONTAINING_RECORD(iface, ExtensionService, IAuthenticate_iface); 00111 } 00112 00113 static HRESULT WINAPI Authenticate_QueryInterface(IAuthenticate *iface, REFIID riid, void **ppv) 00114 { 00115 ExtensionService *This = impl_from_IAuthenticate(iface); 00116 return IUnknown_QueryInterface(This->outer_unk, riid, ppv); 00117 } 00118 00119 static ULONG WINAPI Authenticate_AddRef(IAuthenticate *iface) 00120 { 00121 ExtensionService *This = impl_from_IAuthenticate(iface); 00122 return IUnknown_AddRef(This->outer_unk); 00123 } 00124 00125 static ULONG WINAPI Authenticate_Release(IAuthenticate *iface) 00126 { 00127 ExtensionService *This = impl_from_IAuthenticate(iface); 00128 return IUnknown_Release(This->outer_unk); 00129 } 00130 00131 static HRESULT WINAPI Authenticate_Authenticate(IAuthenticate *iface, 00132 HWND *phwnd, LPWSTR *pszUsername, LPWSTR *pszPassword) 00133 { 00134 ExtensionService *This = impl_from_IAuthenticate(iface); 00135 00136 TRACE("(%p)->(%p %p %p)\n", This, phwnd, pszUsername, pszPassword); 00137 00138 if(!phwnd || !pszUsername || !pszPassword) 00139 return E_INVALIDARG; 00140 00141 *phwnd = This->hwnd; 00142 *pszUsername = hlink_co_strdupW(This->username); 00143 *pszPassword = hlink_co_strdupW(This->password); 00144 00145 return S_OK; 00146 } 00147 00148 static const IAuthenticateVtbl AuthenticateVtbl = { 00149 Authenticate_QueryInterface, 00150 Authenticate_AddRef, 00151 Authenticate_Release, 00152 Authenticate_Authenticate 00153 }; 00154 00155 static inline ExtensionService *impl_from_IHttpNegotiate(IHttpNegotiate *iface) 00156 { 00157 return CONTAINING_RECORD(iface, ExtensionService, IHttpNegotiate_iface); 00158 } 00159 00160 static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate *iface, REFIID riid, void **ppv) 00161 { 00162 ExtensionService *This = impl_from_IHttpNegotiate(iface); 00163 return IUnknown_QueryInterface(This->outer_unk, riid, ppv); 00164 } 00165 00166 static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate *iface) 00167 { 00168 ExtensionService *This = impl_from_IHttpNegotiate(iface); 00169 return IUnknown_AddRef(This->outer_unk); 00170 } 00171 00172 static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate *iface) 00173 { 00174 ExtensionService *This = impl_from_IHttpNegotiate(iface); 00175 return IUnknown_Release(This->outer_unk); 00176 } 00177 00178 static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate *iface, 00179 LPCWSTR szURL, LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders) 00180 { 00181 ExtensionService *This = impl_from_IHttpNegotiate(iface); 00182 00183 TRACE("(%p)->(%s %s %x %p)\n", This, debugstr_w(szURL), debugstr_w(szHeaders), dwReserved, 00184 pszAdditionalHeaders); 00185 00186 if(!pszAdditionalHeaders) 00187 return E_INVALIDARG; 00188 00189 *pszAdditionalHeaders = hlink_co_strdupW(This->headers); 00190 return S_OK; 00191 } 00192 00193 static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate *iface, DWORD dwResponseCode, 00194 LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders) 00195 { 00196 ExtensionService *This = impl_from_IHttpNegotiate(iface); 00197 00198 TRACE("(%p)->(%d %s %s %p)\n", This, dwResponseCode, debugstr_w(szResponseHeaders), 00199 debugstr_w(szRequestHeaders), pszAdditionalRequestHeaders); 00200 00201 *pszAdditionalRequestHeaders = NULL; 00202 return S_OK; 00203 } 00204 00205 static const IHttpNegotiateVtbl HttpNegotiateVtbl = { 00206 HttpNegotiate_QueryInterface, 00207 HttpNegotiate_AddRef, 00208 HttpNegotiate_Release, 00209 HttpNegotiate_BeginningTransaction, 00210 HttpNegotiate_OnResponse 00211 }; 00212 00213 static inline ExtensionService *impl_from_IExtensionServices(IExtensionServices *iface) 00214 { 00215 return CONTAINING_RECORD(iface, ExtensionService, IExtensionServices_iface); 00216 } 00217 00218 static HRESULT WINAPI ExtServ_QueryInterface(IExtensionServices *iface, REFIID riid, void **ppv) 00219 { 00220 ExtensionService *This = impl_from_IExtensionServices(iface); 00221 return IUnknown_QueryInterface(This->outer_unk, riid, ppv); 00222 } 00223 00224 static ULONG WINAPI ExtServ_AddRef(IExtensionServices *iface) 00225 { 00226 ExtensionService *This = impl_from_IExtensionServices(iface); 00227 return IUnknown_AddRef(This->outer_unk); 00228 } 00229 00230 static ULONG WINAPI ExtServ_Release(IExtensionServices *iface) 00231 { 00232 ExtensionService *This = impl_from_IExtensionServices(iface); 00233 return IUnknown_Release(This->outer_unk); 00234 } 00235 00236 static HRESULT ExtServ_ImplSetAdditionalHeaders(ExtensionService* This, LPCWSTR pwzAdditionalHeaders) 00237 { 00238 int len = 0; 00239 00240 heap_free(This->headers); 00241 This->headers = NULL; 00242 00243 if (!pwzAdditionalHeaders) 00244 return S_OK; 00245 00246 len = strlenW(pwzAdditionalHeaders); 00247 00248 if(len && pwzAdditionalHeaders[len-1] != '\n' && pwzAdditionalHeaders[len-1] != '\r') { 00249 static const WCHAR endlW[] = {'\r','\n',0}; 00250 This->headers = heap_alloc(len*sizeof(WCHAR) + sizeof(endlW)); 00251 memcpy(This->headers, pwzAdditionalHeaders, len*sizeof(WCHAR)); 00252 memcpy(This->headers+len, endlW, sizeof(endlW)); 00253 }else { 00254 This->headers = hlink_strdupW(pwzAdditionalHeaders); 00255 } 00256 00257 return S_OK; 00258 } 00259 00260 static HRESULT WINAPI ExtServ_SetAdditionalHeaders(IExtensionServices* iface, LPCWSTR pwzAdditionalHeaders) 00261 { 00262 ExtensionService *This = impl_from_IExtensionServices(iface); 00263 00264 TRACE("(%p)->(%s)\n", This, debugstr_w(pwzAdditionalHeaders)); 00265 00266 return ExtServ_ImplSetAdditionalHeaders(This,pwzAdditionalHeaders); 00267 } 00268 00269 static HRESULT ExtServ_ImplSetAuthenticateData(ExtensionService* This, HWND phwnd, LPCWSTR pwzUsername, LPCWSTR pwzPassword) 00270 { 00271 heap_free(This->username); 00272 heap_free(This->password); 00273 00274 This->hwnd = phwnd; 00275 This->username = hlink_strdupW(pwzUsername); 00276 This->password = hlink_strdupW(pwzPassword); 00277 00278 return S_OK; 00279 } 00280 00281 static HRESULT WINAPI ExtServ_SetAuthenticateData(IExtensionServices* iface, HWND phwnd, LPCWSTR pwzUsername, LPCWSTR pwzPassword) 00282 { 00283 ExtensionService *This = impl_from_IExtensionServices(iface); 00284 00285 TRACE("(%p)->(%p %s %s)\n", This, phwnd, debugstr_w(pwzUsername), debugstr_w(pwzPassword)); 00286 00287 return ExtServ_ImplSetAuthenticateData(This, phwnd, pwzUsername, pwzPassword); 00288 } 00289 00290 static const IExtensionServicesVtbl ExtServVtbl = { 00291 ExtServ_QueryInterface, 00292 ExtServ_AddRef, 00293 ExtServ_Release, 00294 ExtServ_SetAdditionalHeaders, 00295 ExtServ_SetAuthenticateData 00296 }; 00297 00298 /*********************************************************************** 00299 * HlinkCreateExtensionServices (HLINK.@) 00300 */ 00301 HRESULT WINAPI HlinkCreateExtensionServices(LPCWSTR pwzAdditionalHeaders, 00302 HWND phwnd, LPCWSTR pszUsername, LPCWSTR pszPassword, 00303 IUnknown *punkOuter, REFIID riid, void** ppv) 00304 { 00305 ExtensionService *ret; 00306 HRESULT hres = S_OK; 00307 00308 TRACE("%s %p %s %s %p %s %p\n",debugstr_w(pwzAdditionalHeaders), 00309 phwnd, debugstr_w(pszUsername), debugstr_w(pszPassword), 00310 punkOuter, debugstr_guid(riid), ppv); 00311 00312 ret = heap_alloc(sizeof(*ret)); 00313 00314 ret->IUnknown_inner.lpVtbl = &ExtServUnkVtbl; 00315 ret->IAuthenticate_iface.lpVtbl = &AuthenticateVtbl; 00316 ret->IHttpNegotiate_iface.lpVtbl = &HttpNegotiateVtbl; 00317 ret->IExtensionServices_iface.lpVtbl = &ExtServVtbl; 00318 ret->ref = 1; 00319 ret->headers = NULL; 00320 ret->hwnd = NULL; 00321 ret->username = NULL; 00322 ret->password = NULL; 00323 00324 ExtServ_ImplSetAuthenticateData(ret, phwnd, pszUsername, pszPassword); 00325 ExtServ_ImplSetAdditionalHeaders(ret, pwzAdditionalHeaders); 00326 00327 if(!punkOuter) { 00328 ret->outer_unk = &ret->IUnknown_inner; 00329 hres = IUnknown_QueryInterface(&ret->IUnknown_inner, riid, ppv); 00330 IUnknown_Release(&ret->IUnknown_inner); 00331 }else if(IsEqualGUID(&IID_IUnknown, riid)) { 00332 ret->outer_unk = punkOuter; 00333 *ppv = &ret->IUnknown_inner; 00334 }else { 00335 IUnknown_Release(&ret->IUnknown_inner); 00336 hres = E_INVALIDARG; 00337 } 00338 00339 return hres; 00340 } Generated on Thu May 24 2012 04:24:23 for ReactOS by
1.7.6.1
|