ReactOS 0.4.17-dev-966-gf06eace
file.c File Reference
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "winuser.h"
#include "winreg.h"
#include "winhttp.h"
#include "qmgr.h"
#include "wine/debug.h"
Include dependency graph for file.c:

Go to the source code of this file.

Macros

#define COBJMACROS
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (qmgr)
 
static BackgroundCopyFileImpl * impl_from_IBackgroundCopyFile2 (IBackgroundCopyFile2 *iface)
 
static HRESULT WINAPI BackgroundCopyFile_QueryInterface (IBackgroundCopyFile2 *iface, REFIID riid, void **obj)
 
static ULONG WINAPI BackgroundCopyFile_AddRef (IBackgroundCopyFile2 *iface)
 
static ULONG WINAPI BackgroundCopyFile_Release (IBackgroundCopyFile2 *iface)
 
static HRESULT WINAPI BackgroundCopyFile_GetRemoteName (IBackgroundCopyFile2 *iface, LPWSTR *pVal)
 
static HRESULT WINAPI BackgroundCopyFile_GetLocalName (IBackgroundCopyFile2 *iface, LPWSTR *pVal)
 
static HRESULT WINAPI BackgroundCopyFile_GetProgress (IBackgroundCopyFile2 *iface, BG_FILE_PROGRESS *pVal)
 
static HRESULT WINAPI BackgroundCopyFile_GetFileRanges (IBackgroundCopyFile2 *iface, DWORD *RangeCount, BG_FILE_RANGE **Ranges)
 
static HRESULT WINAPI BackgroundCopyFile_SetRemoteName (IBackgroundCopyFile2 *iface, LPCWSTR Val)
 
HRESULT BackgroundCopyFileConstructor (BackgroundCopyJobImpl *owner, LPCWSTR remoteName, LPCWSTR localName, BackgroundCopyFileImpl **file)
 
static HRESULT hresult_from_http_response (DWORD code)
 
static void CALLBACK progress_callback_http (HINTERNET handle, DWORD_PTR context, DWORD status, LPVOID buf, DWORD buflen)
 
static DWORD wait_for_completion (BackgroundCopyJobImpl *job)
 
static UINT target_from_index (UINT index)
 
static UINT scheme_from_index (UINT index)
 
static BOOL set_request_credentials (HINTERNET req, BackgroundCopyJobImpl *job)
 
static BOOL transfer_file_http (BackgroundCopyFileImpl *file, URL_COMPONENTSW *uc, const WCHAR *tmpfile)
 
static DWORD CALLBACK progress_callback_local (LARGE_INTEGER totalSize, LARGE_INTEGER totalTransferred, LARGE_INTEGER streamSize, LARGE_INTEGER streamTransferred, DWORD streamNum, DWORD reason, HANDLE srcFile, HANDLE dstFile, LPVOID obj)
 
static BOOL transfer_file_local (BackgroundCopyFileImpl *file, const WCHAR *tmpname)
 
BOOL processFile (BackgroundCopyFileImpl *file, BackgroundCopyJobImpl *job)
 

Variables

static const IBackgroundCopyFile2Vtbl BackgroundCopyFile2Vtbl
 

Macro Definition Documentation

◆ COBJMACROS

#define COBJMACROS

Definition at line 28 of file file.c.

Function Documentation

◆ BackgroundCopyFile_AddRef()

static ULONG WINAPI BackgroundCopyFile_AddRef ( IBackgroundCopyFile2 *  iface)
static

Definition at line 65 of file file.c.

67{
70 TRACE("(%p)->(%ld)\n", file, ref);
71 return ref;
72}
#define InterlockedIncrement
Definition: armddk.h:53
static BackgroundCopyFileImpl * impl_from_IBackgroundCopyFile2(IBackgroundCopyFile2 *iface)
Definition: file.c:34
#define TRACE(s)
Definition: solgame.cpp:4
Definition: fci.c:123
LONG ref
Definition: filesystem.c:114
Definition: send.c:48
uint32_t ULONG
Definition: typedefs.h:59

◆ BackgroundCopyFile_GetFileRanges()

static HRESULT WINAPI BackgroundCopyFile_GetFileRanges ( IBackgroundCopyFile2 *  iface,
DWORD *  RangeCount,
BG_FILE_RANGE **  Ranges 
)
static

Definition at line 131 of file file.c.

135{
137 FIXME("(%p)->(%p %p)\n", file, RangeCount, Ranges);
138 return E_NOTIMPL;
139}
#define FIXME(fmt,...)
Definition: precomp.h:53
#define E_NOTIMPL
Definition: ddrawi.h:99

◆ BackgroundCopyFile_GetLocalName()

static HRESULT WINAPI BackgroundCopyFile_GetLocalName ( IBackgroundCopyFile2 *  iface,
LPWSTR *  pVal 
)
static

Definition at line 105 of file file.c.

108{
110
111 TRACE("(%p)->(%p)\n", file, pVal);
112
113 return return_strval(file->info.LocalName, pVal);
114}
static HRESULT return_strval(const WCHAR *str, WCHAR **ret)
Definition: qmgr.h:125

◆ BackgroundCopyFile_GetProgress()

static HRESULT WINAPI BackgroundCopyFile_GetProgress ( IBackgroundCopyFile2 *  iface,
BG_FILE_PROGRESS *  pVal 
)
static

Definition at line 116 of file file.c.

119{
121
122 TRACE("(%p)->(%p)\n", file, pVal);
123
124 EnterCriticalSection(&file->owner->cs);
125 *pVal = file->fileProgress;
126 LeaveCriticalSection(&file->owner->cs);
127
128 return S_OK;
129}
#define S_OK
Definition: intsafe.h:52
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)

◆ BackgroundCopyFile_GetRemoteName()

static HRESULT WINAPI BackgroundCopyFile_GetRemoteName ( IBackgroundCopyFile2 *  iface,
LPWSTR *  pVal 
)
static

Definition at line 94 of file file.c.

97{
99
100 TRACE("(%p)->(%p)\n", file, pVal);
101
102 return return_strval(file->info.RemoteName, pVal);
103}

◆ BackgroundCopyFile_QueryInterface()

static HRESULT WINAPI BackgroundCopyFile_QueryInterface ( IBackgroundCopyFile2 *  iface,
REFIID  riid,
void **  obj 
)
static

Definition at line 40 of file file.c.

44{
46
47 TRACE("(%p)->(%s %p)\n", file, debugstr_guid(riid), obj);
48
50 IsEqualGUID(riid, &IID_IBackgroundCopyFile) ||
51 IsEqualGUID(riid, &IID_IBackgroundCopyFile2))
52 {
53 *obj = iface;
54 }
55 else
56 {
57 *obj = NULL;
58 return E_NOINTERFACE;
59 }
60
61 IBackgroundCopyFile2_AddRef(iface);
62 return S_OK;
63}
const GUID IID_IUnknown
#define NULL
Definition: types.h:112
REFIID riid
Definition: atlbase.h:39
#define debugstr_guid
Definition: kernel32.h:35
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define E_NOINTERFACE
Definition: winerror.h:3479

◆ BackgroundCopyFile_Release()

static ULONG WINAPI BackgroundCopyFile_Release ( IBackgroundCopyFile2 *  iface)
static

Definition at line 74 of file file.c.

76{
79
80 TRACE("(%p)->(%ld)\n", file, ref);
81
82 if (ref == 0)
83 {
84 IBackgroundCopyJob4_Release(&file->owner->IBackgroundCopyJob4_iface);
85 free(file->info.LocalName);
86 free(file->info.RemoteName);
87 free(file);
88 }
89
90 return ref;
91}
#define InterlockedDecrement
Definition: armddk.h:52
#define free
Definition: debug_ros.c:5

◆ BackgroundCopyFile_SetRemoteName()

static HRESULT WINAPI BackgroundCopyFile_SetRemoteName ( IBackgroundCopyFile2 *  iface,
LPCWSTR  Val 
)
static

Definition at line 141 of file file.c.

144{
146 FIXME("(%p)->(%s)\n", file, debugstr_w(Val));
147 return E_NOTIMPL;
148}
#define debugstr_w
Definition: kernel32.h:32

◆ BackgroundCopyFileConstructor()

HRESULT BackgroundCopyFileConstructor ( BackgroundCopyJobImpl *  owner,
LPCWSTR  remoteName,
LPCWSTR  localName,
BackgroundCopyFileImpl **  file 
)

Definition at line 162 of file file.c.

165{
167
168 TRACE("(%s, %s, %p)\n", debugstr_w(remoteName), debugstr_w(localName), file);
169
170 This = calloc(1, sizeof(*This));
171 if (!This)
172 return E_OUTOFMEMORY;
173
174 This->info.RemoteName = wcsdup(remoteName);
175 if (!This->info.RemoteName)
176 {
177 free(This);
178 return E_OUTOFMEMORY;
179 }
180
181 This->info.LocalName = wcsdup(localName);
182 if (!This->info.LocalName)
183 {
184 free(This->info.RemoteName);
185 free(This);
186 return E_OUTOFMEMORY;
187 }
188
189 This->IBackgroundCopyFile2_iface.lpVtbl = &BackgroundCopyFile2Vtbl;
190 This->ref = 1;
191 This->fileProgress.BytesTotal = BG_SIZE_UNKNOWN;
192 This->owner = owner;
193 IBackgroundCopyJob4_AddRef(&owner->IBackgroundCopyJob4_iface);
194
195 *file = This;
196 return S_OK;
197}
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
static wchar_t * wcsdup(const wchar_t *str)
Definition: string.h:94
static const IBackgroundCopyFile2Vtbl BackgroundCopyFile2Vtbl
Definition: file.c:150
#define calloc
Definition: rosglue.h:14
IBackgroundCopyJob4 IBackgroundCopyJob4_iface
Definition: qmgr.h:38

Referenced by BackgroundCopyJob_AddFileSet().

◆ hresult_from_http_response()

static HRESULT hresult_from_http_response ( DWORD  code)
static

Definition at line 199 of file file.c.

200{
201 switch (code)
202 {
203 case 200: return S_OK;
204 case 400: return BG_E_HTTP_ERROR_400;
205 case 401: return BG_E_HTTP_ERROR_401;
206 case 404: return BG_E_HTTP_ERROR_404;
207 case 407: return BG_E_HTTP_ERROR_407;
208 case 414: return BG_E_HTTP_ERROR_414;
209 case 501: return BG_E_HTTP_ERROR_501;
210 case 503: return BG_E_HTTP_ERROR_503;
211 case 504: return BG_E_HTTP_ERROR_504;
212 case 505: return BG_E_HTTP_ERROR_505;
213 default:
214 FIXME("unhandled response code %lu\n", code);
215 return S_OK;
216 }
217}
#define BG_E_HTTP_ERROR_501
Definition: bitsmsg.h:33
#define BG_E_HTTP_ERROR_404
Definition: bitsmsg.h:30
#define BG_E_HTTP_ERROR_400
Definition: bitsmsg.h:28
#define BG_E_HTTP_ERROR_505
Definition: bitsmsg.h:36
#define BG_E_HTTP_ERROR_407
Definition: bitsmsg.h:31
#define BG_E_HTTP_ERROR_401
Definition: bitsmsg.h:29
#define BG_E_HTTP_ERROR_503
Definition: bitsmsg.h:34
#define BG_E_HTTP_ERROR_414
Definition: bitsmsg.h:32
#define BG_E_HTTP_ERROR_504
Definition: bitsmsg.h:35
Definition: inflate.c:139

Referenced by progress_callback_http().

◆ impl_from_IBackgroundCopyFile2()

◆ processFile()

BOOL processFile ( BackgroundCopyFileImpl *  file,
BackgroundCopyJobImpl *  job 
)

Definition at line 471 of file file.c.

472{
473 WCHAR tmpDir[MAX_PATH], tmpName[MAX_PATH];
476 BOOL ret;
477
478 if (!GetTempPathW(MAX_PATH, tmpDir))
479 {
480 ERR("Couldn't create temp file name: %ld\n", GetLastError());
481 /* Guessing on what state this should give us */
482 transitionJobState(job, BG_JOB_STATE_QUEUED, BG_JOB_STATE_TRANSIENT_ERROR);
483 return FALSE;
484 }
485
486 if (!GetTempFileNameW(tmpDir, L"BIT", 0, tmpName))
487 {
488 ERR("Couldn't create temp file: %ld\n", GetLastError());
489 /* Guessing on what state this should give us */
490 transitionJobState(job, BG_JOB_STATE_QUEUED, BG_JOB_STATE_TRANSIENT_ERROR);
491 return FALSE;
492 }
493
495 file->fileProgress.BytesTotal = BG_SIZE_UNKNOWN;
496 file->fileProgress.BytesTransferred = 0;
497 file->fileProgress.Completed = FALSE;
499
500 TRACE("Transferring: %s -> %s -> %s\n",
501 debugstr_w(file->info.RemoteName),
502 debugstr_w(tmpName),
503 debugstr_w(file->info.LocalName));
504
505 uc.dwStructSize = sizeof(uc);
506 uc.nScheme = 0;
507 uc.lpszScheme = NULL;
508 uc.dwSchemeLength = 0;
509 uc.lpszUserName = NULL;
510 uc.dwUserNameLength = 0;
511 uc.lpszPassword = NULL;
512 uc.dwPasswordLength = 0;
513 uc.lpszHostName = host;
515 uc.nPort = 0;
516 uc.lpszUrlPath = NULL;
517 uc.dwUrlPathLength = ~0u;
518 uc.lpszExtraInfo = NULL;
519 uc.dwExtraInfoLength = 0;
520 ret = WinHttpCrackUrl(file->info.RemoteName, 0, 0, &uc);
521 if (!ret)
522 {
523 TRACE("WinHttpCrackUrl failed, trying local file copy\n");
524 if (!transfer_file_local(file, tmpName)) WARN("local transfer failed\n");
525 }
526 else if (!transfer_file_http(file, &uc, tmpName)) WARN("HTTP transfer failed\n");
527
528 if (transitionJobState(job, BG_JOB_STATE_CONNECTING, BG_JOB_STATE_QUEUED) ||
529 transitionJobState(job, BG_JOB_STATE_TRANSFERRING, BG_JOB_STATE_QUEUED))
530 {
531 lstrcpyW(file->tempFileName, tmpName);
532
534 file->fileProgress.Completed = TRUE;
535 job->jobProgress.FilesTransferred++;
537
538 return TRUE;
539 }
540 else
541 {
542 DeleteFileW(tmpName);
543 return FALSE;
544 }
545}
#define ARRAY_SIZE(A)
Definition: main.h:20
#define WARN(fmt,...)
Definition: precomp.h:61
#define ERR(fmt,...)
Definition: precomp.h:57
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define MAX_PATH
Definition: compat.h:34
#define lstrcpyW
Definition: compat.h:749
UINT WINAPI DECLSPEC_HOTPATCH GetTempFileNameW(LPCWSTR path, LPCWSTR prefix, UINT unique, LPWSTR buffer)
Definition: file.c:2355
DWORD WINAPI DECLSPEC_HOTPATCH GetTempPathW(DWORD count, LPWSTR path)
Definition: file.c:2438
BOOL WINAPI DECLSPEC_HOTPATCH DeleteFileW(LPCWSTR path)
Definition: file.c:1003
static BOOL transfer_file_local(BackgroundCopyFileImpl *file, const WCHAR *tmpname)
Definition: file.c:448
static BOOL transfer_file_http(BackgroundCopyFileImpl *file, URL_COMPONENTSW *uc, const WCHAR *tmpfile)
Definition: file.c:362
BOOL transitionJobState(BackgroundCopyJobImpl *job, BG_JOB_STATE from, BG_JOB_STATE to)
Definition: job.c:30
BOOL WINAPI WinHttpCrackUrl(const WCHAR *url, DWORD len, DWORD flags, URL_COMPONENTSW *uc)
Definition: url.c:173
return ret
Definition: mutex.c:147
#define L(x)
Definition: resources.c:13
unsigned int BOOL
Definition: ntddk_ex.h:94
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
Definition: glfuncs.h:240
static HANDLE job
Definition: process.c:79
short WCHAR
Definition: pedump.c:58
DWORD dwStructSize
Definition: wininet.h:211
DWORD dwUrlPathLength
Definition: wininet.h:223
DWORD dwExtraInfoLength
Definition: wininet.h:225
LPWSTR lpszPassword
Definition: wininet.h:220
LPWSTR lpszHostName
Definition: wininet.h:215
DWORD dwUserNameLength
Definition: wininet.h:219
DWORD dwHostNameLength
Definition: wininet.h:216
INTERNET_SCHEME nScheme
Definition: wininet.h:214
LPWSTR lpszScheme
Definition: wininet.h:212
LPWSTR lpszUserName
Definition: wininet.h:218
LPWSTR lpszUrlPath
Definition: wininet.h:222
LPWSTR lpszExtraInfo
Definition: wininet.h:224
DWORD dwPasswordLength
Definition: wininet.h:221
INTERNET_PORT nPort
Definition: wininet.h:217
DWORD dwSchemeLength
Definition: wininet.h:213
Definition: txthost.c:37
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

Referenced by processJob().

◆ progress_callback_http()

static void CALLBACK progress_callback_http ( HINTERNET  handle,
DWORD_PTR  context,
DWORD  status,
LPVOID  buf,
DWORD  buflen 
)
static

Definition at line 219 of file file.c.

221{
224
225 TRACE("%p, %p, %lx, %p, %lu\n", handle, file, status, buf, buflen);
226
227 switch (status)
228 {
230 {
231 DWORD code, len, size;
232
233 size = sizeof(code);
235 NULL, &code, &size, NULL))
236 {
237 if ((job->error.code = hresult_from_http_response(code)))
238 {
240
241 job->error.context = BG_ERROR_CONTEXT_REMOTE_FILE;
242 if (job->error.file) IBackgroundCopyFile2_Release(job->error.file);
243 job->error.file = &file->IBackgroundCopyFile2_iface;
244 IBackgroundCopyFile2_AddRef(job->error.file);
245
247 transitionJobState(job, BG_JOB_STATE_TRANSFERRING, BG_JOB_STATE_ERROR);
248 }
249 else
250 {
252
253 job->error.context = 0;
254 if (job->error.file)
255 {
256 IBackgroundCopyFile2_Release(job->error.file);
257 job->error.file = NULL;
258 }
259
261 }
262 }
263 size = sizeof(len);
265 NULL, &len, &size, NULL))
266 {
267 file->fileProgress.BytesTotal = len;
268 }
269 break;
270 }
272 {
273 file->read_size = buflen;
274 break;
275 }
277 {
279 job->error.code = HRESULT_FROM_WIN32(result->dwError);
280 transitionJobState(job, BG_JOB_STATE_TRANSFERRING, BG_JOB_STATE_ERROR);
281 break;
282 }
283 default: break;
284 }
285
286 SetEvent(job->wait);
287}
static HRESULT hresult_from_http_response(DWORD code)
Definition: file.c:199
unsigned long DWORD
Definition: ntddk_ex.h:95
GLsizeiptr size
Definition: glext.h:5919
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLuint64EXT * result
Definition: glext.h:11304
GLenum GLsizei len
Definition: glext.h:6722
BOOL WINAPI WinHttpQueryHeaders(HINTERNET hrequest, DWORD level, const WCHAR *name, void *buffer, DWORD *buflen, DWORD *index)
Definition: request.c:814
Definition: http.c:7252
Definition: ps.c:97
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:669
static HRESULT HRESULT_FROM_WIN32(unsigned int x)
Definition: winerror.h:210
#define WINHTTP_QUERY_CONTENT_LENGTH
Definition: winhttp.h:365
#define WINHTTP_CALLBACK_STATUS_HEADERS_AVAILABLE
Definition: winhttp.h:459
#define WINHTTP_QUERY_STATUS_CODE
Definition: winhttp.h:379
#define WINHTTP_CALLBACK_STATUS_READ_COMPLETE
Definition: winhttp.h:461
#define WINHTTP_QUERY_FLAG_NUMBER
Definition: winhttp.h:439
#define WINHTTP_CALLBACK_STATUS_REQUEST_ERROR
Definition: winhttp.h:463

Referenced by transfer_file_http().

◆ progress_callback_local()

static DWORD CALLBACK progress_callback_local ( LARGE_INTEGER  totalSize,
LARGE_INTEGER  totalTransferred,
LARGE_INTEGER  streamSize,
LARGE_INTEGER  streamTransferred,
DWORD  streamNum,
DWORD  reason,
HANDLE  srcFile,
HANDLE  dstFile,
LPVOID  obj 
)
static

Definition at line 425 of file file.c.

429{
432 ULONG64 diff;
433
435 diff = (file->fileProgress.BytesTotal == BG_SIZE_UNKNOWN
436 ? totalTransferred.QuadPart
437 : totalTransferred.QuadPart - file->fileProgress.BytesTransferred);
438 file->fileProgress.BytesTotal = totalSize.QuadPart;
439 file->fileProgress.BytesTransferred = totalTransferred.QuadPart;
440 job->jobProgress.BytesTransferred += diff;
442
443 return (job->state == BG_JOB_STATE_TRANSFERRING
446}
unsigned __int64 ULONG64
Definition: imports.h:198
LONGLONG QuadPart
Definition: typedefs.h:114
#define PROGRESS_CANCEL
Definition: winbase.h:150
#define PROGRESS_CONTINUE
Definition: winbase.h:149

Referenced by transfer_file_local().

◆ scheme_from_index()

static UINT scheme_from_index ( UINT  index)
static

Definition at line 326 of file file.c.

327{
328 switch (index)
329 {
330 case 0: return WINHTTP_AUTH_SCHEME_BASIC;
331 case 1: return WINHTTP_AUTH_SCHEME_NTLM;
332 case 2: return WINHTTP_AUTH_SCHEME_PASSPORT;
333 case 3: return WINHTTP_AUTH_SCHEME_DIGEST;
334 case 4: return WINHTTP_AUTH_SCHEME_NEGOTIATE;
335 default:
336 ERR("unhandled index %u\n", index);
337 break;
338 }
339 return 0;
340}
GLuint index
Definition: glext.h:6031
#define WINHTTP_AUTH_SCHEME_BASIC
Definition: winhttp.h:524
#define WINHTTP_AUTH_SCHEME_PASSPORT
Definition: winhttp.h:526
#define WINHTTP_AUTH_SCHEME_NEGOTIATE
Definition: winhttp.h:528
#define WINHTTP_AUTH_SCHEME_DIGEST
Definition: winhttp.h:527
#define WINHTTP_AUTH_SCHEME_NTLM
Definition: winhttp.h:525

Referenced by set_request_credentials().

◆ set_request_credentials()

static BOOL set_request_credentials ( HINTERNET  req,
BackgroundCopyJobImpl *  job 
)
static

Definition at line 342 of file file.c.

343{
344 UINT i, j;
345
346 for (i = 0; i < BG_AUTH_TARGET_PROXY; i++)
347 {
349 for (j = 0; j < BG_AUTH_SCHEME_PASSPORT; j++)
350 {
352 const WCHAR *username = job->http_options.creds[i][j].Credentials.Basic.UserName;
353 const WCHAR *password = job->http_options.creds[i][j].Credentials.Basic.Password;
354
355 if (!username) continue;
357 }
358 }
359 return TRUE;
360}
static UCHAR password[]
Definition: bcrypt.c:520
static UINT scheme_from_index(UINT index)
Definition: file.c:326
static UINT target_from_index(UINT index)
Definition: file.c:313
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
unsigned int UINT
Definition: sysinfo.c:13
static WCHAR username[]
Definition: url.c:32
BOOL WINAPI WinHttpSetCredentials(HINTERNET hrequest, DWORD target, DWORD scheme, const WCHAR *username, const WCHAR *password, void *params)
Definition: request.c:2493
DWORD scheme
Definition: tools.h:99

Referenced by transfer_file_http().

◆ target_from_index()

static UINT target_from_index ( UINT  index)
static

Definition at line 313 of file file.c.

314{
315 switch (index)
316 {
317 case 0: return WINHTTP_AUTH_TARGET_SERVER;
318 case 1: return WINHTTP_AUTH_TARGET_PROXY;
319 default:
320 ERR("unhandled index %u\n", index);
321 break;
322 }
323 return 0;
324}
#define WINHTTP_AUTH_TARGET_SERVER
Definition: winhttp.h:530
#define WINHTTP_AUTH_TARGET_PROXY
Definition: winhttp.h:531

Referenced by set_request_credentials().

◆ transfer_file_http()

static BOOL transfer_file_http ( BackgroundCopyFileImpl *  file,
URL_COMPONENTSW *  uc,
const WCHAR *  tmpfile 
)
static

Definition at line 362 of file file.c.

364{
367 HINTERNET ses, con = NULL, req = NULL;
369 char buf[4096];
370 BOOL ret = FALSE;
371 DWORD written;
372
373 transitionJobState(job, BG_JOB_STATE_QUEUED, BG_JOB_STATE_CONNECTING);
374
375 if (!(ses = WinHttpOpen(NULL, 0, NULL, NULL, WINHTTP_FLAG_ASYNC))) return FALSE;
377 if (!WinHttpSetOption(ses, WINHTTP_OPTION_CONTEXT_VALUE, &file, sizeof(file))) goto done;
378
379 if (!(con = WinHttpConnect(ses, uc->lpszHostName, uc->nPort, 0))) goto done;
380 if (!(req = WinHttpOpenRequest(con, NULL, uc->lpszUrlPath, NULL, NULL, NULL, flags))) goto done;
381 if (!set_request_credentials(req, job)) goto done;
382
383 if (!(WinHttpSendRequest(req, job->http_options.headers, ~0u, NULL, 0, 0, (DWORD_PTR)file))) goto done;
384 if (wait_for_completion(job) || FAILED(job->error.code)) goto done;
385
386 if (!(WinHttpReceiveResponse(req, NULL))) goto done;
387 if (wait_for_completion(job) || FAILED(job->error.code)) goto done;
388
389 transitionJobState(job, BG_JOB_STATE_CONNECTING, BG_JOB_STATE_TRANSFERRING);
390
392 if (handle == INVALID_HANDLE_VALUE) goto done;
393
394 for (;;)
395 {
396 file->read_size = 0;
397 if (!(ret = WinHttpReadData(req, buf, sizeof(buf), NULL))) break;
398 if (wait_for_completion(job) || FAILED(job->error.code))
399 {
400 ret = FALSE;
401 break;
402 }
403 if (!file->read_size) break;
404 if (!(ret = WriteFile(handle, buf, file->read_size, &written, NULL))) break;
405
407 file->fileProgress.BytesTransferred += file->read_size;
408 job->jobProgress.BytesTransferred += file->read_size;
410 }
411
413
414done:
418 if (!ret && !transitionJobState(job, BG_JOB_STATE_CONNECTING, BG_JOB_STATE_ERROR))
419 transitionJobState(job, BG_JOB_STATE_TRANSFERRING, BG_JOB_STATE_ERROR);
420
421 SetEvent(job->done);
422 return ret;
423}
#define CloseHandle
Definition: compat.h:739
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define CreateFileW
Definition: compat.h:741
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
BOOL WINAPI DECLSPEC_HOTPATCH WriteFile(HANDLE file, LPCVOID buffer, DWORD count, LPDWORD result, LPOVERLAPPED overlapped)
Definition: file.c:3896
FILE *CDECL tmpfile(void)
Definition: file.c:5199
static void CALLBACK progress_callback_http(HINTERNET handle, DWORD_PTR context, DWORD status, LPVOID buf, DWORD buflen)
Definition: file.c:219
static DWORD wait_for_completion(BackgroundCopyJobImpl *job)
Definition: file.c:289
static BOOL set_request_credentials(HINTERNET req, BackgroundCopyJobImpl *job)
Definition: file.c:342
HINTERNET WINAPI WinHttpOpenRequest(HINTERNET hconnect, const WCHAR *verb, const WCHAR *object, const WCHAR *version, const WCHAR *referrer, const WCHAR **types, DWORD flags)
Definition: session.c:1277
HINTERNET WINAPI WinHttpOpen(LPCWSTR agent, DWORD access, LPCWSTR proxy, LPCWSTR bypass, DWORD flags)
Definition: session.c:304
HINTERNET WINAPI WinHttpConnect(HINTERNET hsession, const WCHAR *server, INTERNET_PORT port, DWORD reserved)
Definition: session.c:594
BOOL WINAPI WinHttpSetOption(HINTERNET handle, DWORD option, void *buffer, DWORD buflen)
Definition: session.c:1479
BOOL WINAPI WinHttpCloseHandle(HINTERNET handle)
Definition: session.c:1358
WINHTTP_STATUS_CALLBACK WINAPI WinHttpSetStatusCallback(HINTERNET handle, WINHTTP_STATUS_CALLBACK callback, DWORD flags, DWORD_PTR reserved)
Definition: session.c:2435
GLbitfield flags
Definition: glext.h:7161
#define FAILED(hr)
Definition: intsafe.h:51
#define CREATE_ALWAYS
Definition: disk.h:72
#define GENERIC_WRITE
Definition: nt_native.h:90
BOOL WINAPI WinHttpReadData(HINTERNET hrequest, void *buffer, DWORD to_read, DWORD *read)
Definition: request.c:3252
BOOL WINAPI WinHttpSendRequest(HINTERNET hrequest, const WCHAR *headers, DWORD headers_len, void *optional, DWORD optional_len, DWORD total_len, DWORD_PTR context)
Definition: request.c:2397
BOOL WINAPI WinHttpReceiveResponse(HINTERNET hrequest, LPVOID reserved)
Definition: request.c:3068
uint32_t DWORD_PTR
Definition: typedefs.h:65
#define WINHTTP_OPTION_CONTEXT_VALUE
Definition: winhttp.h:121
#define WINHTTP_CALLBACK_FLAG_ALL_COMPLETIONS
Definition: winhttp.h:487
#define WINHTTP_FLAG_ASYNC
Definition: winhttp.h:58
#define WINHTTP_FLAG_SECURE
Definition: winhttp.h:67
#define INTERNET_SCHEME_HTTPS
Definition: winhttp.h:48

Referenced by processFile().

◆ transfer_file_local()

static BOOL transfer_file_local ( BackgroundCopyFileImpl *  file,
const WCHAR *  tmpname 
)
static

Definition at line 448 of file file.c.

449{
451 const WCHAR *ptr;
452 BOOL ret;
453
454 transitionJobState(job, BG_JOB_STATE_QUEUED, BG_JOB_STATE_TRANSFERRING);
455
456 if (lstrlenW(file->info.RemoteName) > 7 && !wcsnicmp(file->info.RemoteName, L"file://", 7))
457 ptr = file->info.RemoteName + 7;
458 else
459 ptr = file->info.RemoteName;
460
461 if (!(ret = CopyFileExW(ptr, tmpname, progress_callback_local, file, NULL, 0)))
462 {
463 WARN("Local file copy failed: error %lu\n", GetLastError());
464 transitionJobState(job, BG_JOB_STATE_TRANSFERRING, BG_JOB_STATE_ERROR);
465 }
466
467 SetEvent(job->done);
468 return ret;
469}
#define wcsnicmp
Definition: compat.h:14
#define lstrlenW
Definition: compat.h:750
BOOL WINAPI CopyFileExW(const WCHAR *source, const WCHAR *dest, LPPROGRESS_ROUTINE progress, void *param, BOOL *cancel_ptr, DWORD flags)
Definition: file.c:609
static DWORD CALLBACK progress_callback_local(LARGE_INTEGER totalSize, LARGE_INTEGER totalTransferred, LARGE_INTEGER streamSize, LARGE_INTEGER streamTransferred, DWORD streamNum, DWORD reason, HANDLE srcFile, HANDLE dstFile, LPVOID obj)
Definition: file.c:425
static PVOID ptr
Definition: dispmode.c:27

Referenced by processFile().

◆ wait_for_completion()

static DWORD wait_for_completion ( BackgroundCopyJobImpl *  job)
static

Definition at line 289 of file file.c.

290{
291 HANDLE handles[2] = {job->wait, job->cancel};
293
295 {
296 case WAIT_OBJECT_0:
297 break;
298
299 case WAIT_OBJECT_0 + 1:
301 transitionJobState(job, BG_JOB_STATE_TRANSFERRING, BG_JOB_STATE_CANCELLED);
302 break;
303
304 default:
306 transitionJobState(job, BG_JOB_STATE_TRANSFERRING, BG_JOB_STATE_ERROR);
307 break;
308 }
309
310 return error;
311}
#define ERROR_SUCCESS
Definition: deptool.c:10
#define INFINITE
Definition: serial.h:102
#define error(str)
Definition: mkdosfs.c:1605
DWORD WINAPI WaitForMultipleObjects(IN DWORD nCount, IN CONST HANDLE *lpHandles, IN BOOL bWaitAll, IN DWORD dwMilliseconds)
Definition: synch.c:151
static EFI_HANDLE * handles
Definition: uefidisk.c:66
#define WAIT_OBJECT_0
Definition: winbase.h:383
#define ERROR_CANCELLED
Definition: winerror.h:1055

Referenced by transfer_file_http().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( qmgr  )

Variable Documentation

◆ BackgroundCopyFile2Vtbl

const IBackgroundCopyFile2Vtbl BackgroundCopyFile2Vtbl
static
Initial value:
=
{
}
static ULONG WINAPI BackgroundCopyFile_Release(IBackgroundCopyFile2 *iface)
Definition: file.c:74
static HRESULT WINAPI BackgroundCopyFile_GetProgress(IBackgroundCopyFile2 *iface, BG_FILE_PROGRESS *pVal)
Definition: file.c:116
static HRESULT WINAPI BackgroundCopyFile_GetFileRanges(IBackgroundCopyFile2 *iface, DWORD *RangeCount, BG_FILE_RANGE **Ranges)
Definition: file.c:131
static ULONG WINAPI BackgroundCopyFile_AddRef(IBackgroundCopyFile2 *iface)
Definition: file.c:65
static HRESULT WINAPI BackgroundCopyFile_GetRemoteName(IBackgroundCopyFile2 *iface, LPWSTR *pVal)
Definition: file.c:94
static HRESULT WINAPI BackgroundCopyFile_QueryInterface(IBackgroundCopyFile2 *iface, REFIID riid, void **obj)
Definition: file.c:40
static HRESULT WINAPI BackgroundCopyFile_SetRemoteName(IBackgroundCopyFile2 *iface, LPCWSTR Val)
Definition: file.c:141
static HRESULT WINAPI BackgroundCopyFile_GetLocalName(IBackgroundCopyFile2 *iface, LPWSTR *pVal)
Definition: file.c:105

Definition at line 150 of file file.c.

Referenced by BackgroundCopyFileConstructor().