From 1e800c7b944e79e85268290510322bf888d637c3 Mon Sep 17 00:00:00 2001 From: Hans Leidekker Date: Fri, 12 Jun 2015 15:05:59 +0200 Subject: [PATCH] qmgr: Implement IBackgroundCopyJobHttpOptions::SetCustomHeaders and IBackgroundCopyJobHttpOptions::GetCustomHeaders. --- dlls/qmgr/file.c | 2 +- dlls/qmgr/job.c | 51 ++++++++++++++++++++++++++++++++++++++++++++---- dlls/qmgr/qmgr.h | 14 +++++++++++++ 3 files changed, 62 insertions(+), 5 deletions(-) diff --git a/dlls/qmgr/file.c b/dlls/qmgr/file.c index 3c92bb018c2..55e93aa36ef 100644 --- a/dlls/qmgr/file.c +++ b/dlls/qmgr/file.c @@ -340,7 +340,7 @@ static BOOL transfer_file_http(BackgroundCopyFileImpl *file, URL_COMPONENTSW *uc if (!(con = WinHttpConnect(ses, uc->lpszHostName, uc->nPort, 0))) goto done; if (!(req = WinHttpOpenRequest(con, NULL, uc->lpszUrlPath, NULL, NULL, NULL, flags))) goto done; - if (!(WinHttpSendRequest(req, NULL, 0, NULL, 0, 0, (DWORD_PTR)file))) goto done; + if (!(WinHttpSendRequest(req, job->http_options.headers, ~0u, NULL, 0, 0, (DWORD_PTR)file))) goto done; if (wait_for_completion(job) || job->error.code) goto done; if (!(WinHttpReceiveResponse(req, NULL))) goto done; diff --git a/dlls/qmgr/job.c b/dlls/qmgr/job.c index 8ee6498e7a6..9595616721f 100644 --- a/dlls/qmgr/job.c +++ b/dlls/qmgr/job.c @@ -976,16 +976,59 @@ static HRESULT WINAPI http_options_SetCustomHeaders( IBackgroundCopyJobHttpOptions *iface, LPCWSTR RequestHeaders) { - FIXME("\n"); - return E_NOTIMPL; + BackgroundCopyJobImpl *job = impl_from_IBackgroundCopyJobHttpOptions(iface); + + TRACE("(%p)->(%s)\n", iface, debugstr_w(RequestHeaders)); + + EnterCriticalSection(&job->cs); + + if (RequestHeaders) + { + WCHAR *headers = strdupW(RequestHeaders); + if (!headers) + { + LeaveCriticalSection(&job->cs); + return E_OUTOFMEMORY; + } + HeapFree(GetProcessHeap(), 0, job->http_options.headers); + job->http_options.headers = headers; + } + else + { + HeapFree(GetProcessHeap(), 0, job->http_options.headers); + job->http_options.headers = NULL; + } + + LeaveCriticalSection(&job->cs); + return S_OK; } static HRESULT WINAPI http_options_GetCustomHeaders( IBackgroundCopyJobHttpOptions *iface, LPWSTR *pRequestHeaders) { - FIXME("\n"); - return E_NOTIMPL; + BackgroundCopyJobImpl *job = impl_from_IBackgroundCopyJobHttpOptions(iface); + + TRACE("(%p)->(%p)\n", iface, pRequestHeaders); + + EnterCriticalSection(&job->cs); + + if (job->http_options.headers) + { + WCHAR *headers = co_strdupW(job->http_options.headers); + if (!headers) + { + LeaveCriticalSection(&job->cs); + return E_OUTOFMEMORY; + } + *pRequestHeaders = headers; + LeaveCriticalSection(&job->cs); + return S_OK; + } + + *pRequestHeaders = NULL; + LeaveCriticalSection(&job->cs); + return S_FALSE; } static HRESULT WINAPI http_options_SetSecurityFlags( diff --git a/dlls/qmgr/qmgr.h b/dlls/qmgr/qmgr.h index 4b9d2fb3fbc..268fabc50cf 100644 --- a/dlls/qmgr/qmgr.h +++ b/dlls/qmgr/qmgr.h @@ -115,6 +115,20 @@ void processJob(BackgroundCopyJobImpl *job) DECLSPEC_HIDDEN; BOOL processFile(BackgroundCopyFileImpl *file, BackgroundCopyJobImpl *job) DECLSPEC_HIDDEN; /* Little helper functions */ +static inline WCHAR *strdupW(const WCHAR *src) +{ + WCHAR *dst = HeapAlloc(GetProcessHeap(), 0, (strlenW(src) + 1) * sizeof(WCHAR)); + if (dst) strcpyW(dst, src); + return dst; +} + +static inline WCHAR *co_strdupW(const WCHAR *src) +{ + WCHAR *dst = CoTaskMemAlloc((strlenW(src) + 1) * sizeof(WCHAR)); + if (dst) strcpyW(dst, src); + return dst; +} + static inline HRESULT return_strval(const WCHAR *str, WCHAR **ret) { int len;