ReactOS 0.4.15-dev-7705-g2320c37
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 BackgroundCopyFileImplimpl_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)->(%d)\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:127
LONG ref
Definition: filesystem.c:120
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: debug.h:111
#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:132

◆ 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:2364

◆ BackgroundCopyFile_Release()

static ULONG WINAPI BackgroundCopyFile_Release ( IBackgroundCopyFile2 iface)
static

Definition at line 74 of file file.c.

76{
79
80 TRACE("(%p)->(%d)\n", file, ref);
81
82 if (ref == 0)
83 {
84 IBackgroundCopyJob3_Release(&file->owner->IBackgroundCopyJob3_iface);
85 HeapFree(GetProcessHeap(), 0, file->info.LocalName);
86 HeapFree(GetProcessHeap(), 0, file->info.RemoteName);
88 }
89
90 return ref;
91}
#define InterlockedDecrement
Definition: armddk.h:52
#define GetProcessHeap()
Definition: compat.h:736
#define HeapFree(x, y, z)
Definition: compat.h:735

◆ 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 = HeapAlloc(GetProcessHeap(), 0, sizeof *This);
171 if (!This)
172 return E_OUTOFMEMORY;
173
174 This->info.RemoteName = strdupW(remoteName);
175 if (!This->info.RemoteName)
176 {
178 return E_OUTOFMEMORY;
179 }
180
181 This->info.LocalName = strdupW(localName);
182 if (!This->info.LocalName)
183 {
184 HeapFree(GetProcessHeap(), 0, This->info.RemoteName);
186 return E_OUTOFMEMORY;
187 }
188
189 This->IBackgroundCopyFile2_iface.lpVtbl = &BackgroundCopyFile2Vtbl;
190 This->ref = 1;
191
192 This->fileProgress.BytesTotal = BG_SIZE_UNKNOWN;
193 This->fileProgress.BytesTransferred = 0;
194 This->fileProgress.Completed = FALSE;
195 This->owner = owner;
196 This->read_size = 0;
197 This->tempFileName[0] = 0;
198 IBackgroundCopyJob3_AddRef(&owner->IBackgroundCopyJob3_iface);
199
200 *file = This;
201 return S_OK;
202}
static WCHAR * strdupW(const WCHAR *src)
Definition: main.c:92
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define FALSE
Definition: types.h:117
#define HeapAlloc
Definition: compat.h:733
static const IBackgroundCopyFile2Vtbl BackgroundCopyFile2Vtbl
Definition: file.c:150
IBackgroundCopyJob3 IBackgroundCopyJob3_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 204 of file file.c.

205{
206 switch (code)
207 {
208 case 200: return S_OK;
209 case 400: return BG_E_HTTP_ERROR_400;
210 case 401: return BG_E_HTTP_ERROR_401;
211 case 404: return BG_E_HTTP_ERROR_404;
212 case 407: return BG_E_HTTP_ERROR_407;
213 case 414: return BG_E_HTTP_ERROR_414;
214 case 501: return BG_E_HTTP_ERROR_501;
215 case 503: return BG_E_HTTP_ERROR_503;
216 case 504: return BG_E_HTTP_ERROR_504;
217 case 505: return BG_E_HTTP_ERROR_505;
218 default:
219 FIXME("unhandled response code %u\n", code);
220 return S_OK;
221 }
222}
#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 477 of file file.c.

478{
479 static const WCHAR prefix[] = {'B','I','T', 0};
480 WCHAR tmpDir[MAX_PATH], tmpName[MAX_PATH];
483 BOOL ret;
484
485 if (!GetTempPathW(MAX_PATH, tmpDir))
486 {
487 ERR("Couldn't create temp file name: %d\n", GetLastError());
488 /* Guessing on what state this should give us */
489 transitionJobState(job, BG_JOB_STATE_QUEUED, BG_JOB_STATE_TRANSIENT_ERROR);
490 return FALSE;
491 }
492
493 if (!GetTempFileNameW(tmpDir, prefix, 0, tmpName))
494 {
495 ERR("Couldn't create temp file: %d\n", GetLastError());
496 /* Guessing on what state this should give us */
497 transitionJobState(job, BG_JOB_STATE_QUEUED, BG_JOB_STATE_TRANSIENT_ERROR);
498 return FALSE;
499 }
500
502 file->fileProgress.BytesTotal = BG_SIZE_UNKNOWN;
503 file->fileProgress.BytesTransferred = 0;
504 file->fileProgress.Completed = FALSE;
506
507 TRACE("Transferring: %s -> %s -> %s\n",
508 debugstr_w(file->info.RemoteName),
509 debugstr_w(tmpName),
510 debugstr_w(file->info.LocalName));
511
512 uc.dwStructSize = sizeof(uc);
513 uc.nScheme = 0;
514 uc.lpszScheme = NULL;
515 uc.dwSchemeLength = 0;
516 uc.lpszUserName = NULL;
517 uc.dwUserNameLength = 0;
518 uc.lpszPassword = NULL;
519 uc.dwPasswordLength = 0;
520 uc.lpszHostName = host;
522 uc.nPort = 0;
523 uc.lpszUrlPath = NULL;
524 uc.dwUrlPathLength = ~0u;
525 uc.lpszExtraInfo = NULL;
526 uc.dwExtraInfoLength = 0;
527 ret = WinHttpCrackUrl(file->info.RemoteName, 0, 0, &uc);
528 if (!ret)
529 {
530 TRACE("WinHttpCrackUrl failed, trying local file copy\n");
531 if (!transfer_file_local(file, tmpName)) WARN("local transfer failed\n");
532 }
533 else if (!transfer_file_http(file, &uc, tmpName)) WARN("HTTP transfer failed\n");
534
535 if (transitionJobState(job, BG_JOB_STATE_CONNECTING, BG_JOB_STATE_QUEUED) ||
536 transitionJobState(job, BG_JOB_STATE_TRANSFERRING, BG_JOB_STATE_QUEUED))
537 {
538 lstrcpyW(file->tempFileName, tmpName);
539
541 file->fileProgress.Completed = TRUE;
542 job->jobProgress.FilesTransferred++;
544
545 return TRUE;
546 }
547 else
548 {
549 DeleteFileW(tmpName);
550 return FALSE;
551 }
552}
#define ARRAY_SIZE(A)
Definition: main.h:33
#define WARN(fmt,...)
Definition: debug.h:112
#define ERR(fmt,...)
Definition: debug.h:110
#define TRUE
Definition: types.h:120
#define MAX_PATH
Definition: compat.h:34
#define lstrcpyW
Definition: compat.h:749
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
DWORD WINAPI GetTempPathW(IN DWORD count, OUT LPWSTR path)
Definition: path.c:2080
static BOOL transfer_file_local(BackgroundCopyFileImpl *file, const WCHAR *tmpname)
Definition: file.c:453
static BOOL transfer_file_http(BackgroundCopyFileImpl *file, URL_COMPONENTSW *uc, const WCHAR *tmpfile)
Definition: file.c:367
BOOL transitionJobState(BackgroundCopyJobImpl *job, BG_JOB_STATE from, BG_JOB_STATE to)
Definition: job.c:30
BOOL WINAPI WinHttpCrackUrl(LPCWSTR url, DWORD len, DWORD flags, LPURL_COMPONENTSW uc)
Definition: url.c:179
UINT WINAPI GetTempFileNameW(IN LPCWSTR lpPathName, IN LPCWSTR lpPrefixString, IN UINT uUnique, OUT LPWSTR lpTempFileName)
Definition: filename.c:84
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:77
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
int ret
char * host
Definition: whois.c:55
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
__wchar_t WCHAR
Definition: xmlstorage.h:180

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 224 of file file.c.

226{
229
230 TRACE("%p, %p, %x, %p, %u\n", handle, file, status, buf, buflen);
231
232 switch (status)
233 {
235 {
236 DWORD code, len, size;
237
238 size = sizeof(code);
240 NULL, &code, &size, NULL))
241 {
242 if ((job->error.code = hresult_from_http_response(code)))
243 {
245
246 job->error.context = BG_ERROR_CONTEXT_REMOTE_FILE;
247 if (job->error.file) IBackgroundCopyFile2_Release(job->error.file);
248 job->error.file = &file->IBackgroundCopyFile2_iface;
249 IBackgroundCopyFile2_AddRef(job->error.file);
250
252 transitionJobState(job, BG_JOB_STATE_TRANSFERRING, BG_JOB_STATE_ERROR);
253 }
254 else
255 {
257
258 job->error.context = 0;
259 if (job->error.file)
260 {
261 IBackgroundCopyFile2_Release(job->error.file);
262 job->error.file = NULL;
263 }
264
266 }
267 }
268 size = sizeof(len);
270 NULL, &len, &size, NULL))
271 {
272 file->fileProgress.BytesTotal = len;
273 }
274 break;
275 }
277 {
278 file->read_size = buflen;
279 break;
280 }
282 {
284 job->error.code = HRESULT_FROM_WIN32(result->dwError);
285 transitionJobState(job, BG_JOB_STATE_TRANSFERRING, BG_JOB_STATE_ERROR);
286 break;
287 }
288 default: break;
289 }
290
291 SetEvent(job->wait);
292}
static HRESULT hresult_from_http_response(DWORD code)
Definition: file.c:204
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
GLenum GLsizei len
Definition: glext.h:6722
GLuint64EXT * result
Definition: glext.h:11304
BOOL WINAPI WinHttpQueryHeaders(HINTERNET hrequest, DWORD level, LPCWSTR name, LPVOID buffer, LPDWORD buflen, LPDWORD index)
Definition: request.c:856
Definition: http.c:7252
Definition: ps.c:97
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
#define WINHTTP_QUERY_CONTENT_LENGTH
Definition: winhttp.h:303
#define WINHTTP_CALLBACK_STATUS_HEADERS_AVAILABLE
Definition: winhttp.h:396
#define WINHTTP_QUERY_STATUS_CODE
Definition: winhttp.h:317
#define WINHTTP_CALLBACK_STATUS_READ_COMPLETE
Definition: winhttp.h:398
#define WINHTTP_QUERY_FLAG_NUMBER
Definition: winhttp.h:377
#define WINHTTP_CALLBACK_STATUS_REQUEST_ERROR
Definition: winhttp.h:400

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 430 of file file.c.

434{
437 ULONG64 diff;
438
440 diff = (file->fileProgress.BytesTotal == BG_SIZE_UNKNOWN
441 ? totalTransferred.QuadPart
442 : totalTransferred.QuadPart - file->fileProgress.BytesTransferred);
443 file->fileProgress.BytesTotal = totalSize.QuadPart;
444 file->fileProgress.BytesTransferred = totalTransferred.QuadPart;
445 job->jobProgress.BytesTransferred += diff;
447
448 return (job->state == BG_JOB_STATE_TRANSFERRING
451}
unsigned __int64 ULONG64
Definition: imports.h:198
LONGLONG QuadPart
Definition: typedefs.h:114
#define PROGRESS_CANCEL
Definition: winbase.h:147
#define PROGRESS_CONTINUE
Definition: winbase.h:146

Referenced by transfer_file_local().

◆ scheme_from_index()

static UINT scheme_from_index ( UINT  index)
static

Definition at line 331 of file file.c.

332{
333 switch (index)
334 {
335 case 0: return WINHTTP_AUTH_SCHEME_BASIC;
336 case 1: return WINHTTP_AUTH_SCHEME_NTLM;
337 case 2: return WINHTTP_AUTH_SCHEME_PASSPORT;
338 case 3: return WINHTTP_AUTH_SCHEME_DIGEST;
339 case 4: return WINHTTP_AUTH_SCHEME_NEGOTIATE;
340 default:
341 ERR("unhandled index %u\n", index);
342 break;
343 }
344 return 0;
345}
GLuint index
Definition: glext.h:6031
#define WINHTTP_AUTH_SCHEME_BASIC
Definition: winhttp.h:452
#define WINHTTP_AUTH_SCHEME_PASSPORT
Definition: winhttp.h:454
#define WINHTTP_AUTH_SCHEME_NEGOTIATE
Definition: winhttp.h:456
#define WINHTTP_AUTH_SCHEME_DIGEST
Definition: winhttp.h:455
#define WINHTTP_AUTH_SCHEME_NTLM
Definition: winhttp.h:453

Referenced by set_request_credentials().

◆ set_request_credentials()

static BOOL set_request_credentials ( HINTERNET  req,
BackgroundCopyJobImpl job 
)
static

Definition at line 347 of file file.c.

348{
349 UINT i, j;
350
351 for (i = 0; i < BG_AUTH_TARGET_PROXY; i++)
352 {
354 for (j = 0; j < BG_AUTH_SCHEME_PASSPORT; j++)
355 {
357 const WCHAR *username = job->http_options.creds[i][j].Credentials.Basic.UserName;
358 const WCHAR *password = job->http_options.creds[i][j].Credentials.Basic.Password;
359
360 if (!username) continue;
362 }
363 }
364 return TRUE;
365}
static UINT scheme_from_index(UINT index)
Definition: file.c:331
static UINT target_from_index(UINT index)
Definition: file.c:318
GLenum target
Definition: glext.h:7315
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
static WCHAR password[]
Definition: url.c:33
static WCHAR username[]
Definition: url.c:32
unsigned int UINT
Definition: ndis.h:50
BOOL WINAPI WinHttpSetCredentials(HINTERNET hrequest, DWORD target, DWORD scheme, LPCWSTR username, LPCWSTR password, LPVOID params)
Definition: request.c:2442
DWORD scheme

Referenced by transfer_file_http().

◆ target_from_index()

static UINT target_from_index ( UINT  index)
static

Definition at line 318 of file file.c.

319{
320 switch (index)
321 {
322 case 0: return WINHTTP_AUTH_TARGET_SERVER;
323 case 1: return WINHTTP_AUTH_TARGET_PROXY;
324 default:
325 ERR("unhandled index %u\n", index);
326 break;
327 }
328 return 0;
329}
#define WINHTTP_AUTH_TARGET_SERVER
Definition: winhttp.h:458
#define WINHTTP_AUTH_TARGET_PROXY
Definition: winhttp.h:459

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 367 of file file.c.

369{
372 HINTERNET ses, con = NULL, req = NULL;
374 char buf[4096];
375 BOOL ret = FALSE;
376 DWORD written;
377
378 transitionJobState(job, BG_JOB_STATE_QUEUED, BG_JOB_STATE_CONNECTING);
379
380 if (!(ses = WinHttpOpen(NULL, 0, NULL, NULL, WINHTTP_FLAG_ASYNC))) return FALSE;
382 if (!WinHttpSetOption(ses, WINHTTP_OPTION_CONTEXT_VALUE, &file, sizeof(file))) goto done;
383
384 if (!(con = WinHttpConnect(ses, uc->lpszHostName, uc->nPort, 0))) goto done;
385 if (!(req = WinHttpOpenRequest(con, NULL, uc->lpszUrlPath, NULL, NULL, NULL, flags))) goto done;
386 if (!set_request_credentials(req, job)) goto done;
387
388 if (!(WinHttpSendRequest(req, job->http_options.headers, ~0u, NULL, 0, 0, (DWORD_PTR)file))) goto done;
389 if (wait_for_completion(job) || FAILED(job->error.code)) goto done;
390
391 if (!(WinHttpReceiveResponse(req, NULL))) goto done;
392 if (wait_for_completion(job) || FAILED(job->error.code)) goto done;
393
394 transitionJobState(job, BG_JOB_STATE_CONNECTING, BG_JOB_STATE_TRANSFERRING);
395
397 if (handle == INVALID_HANDLE_VALUE) goto done;
398
399 for (;;)
400 {
401 file->read_size = 0;
402 if (!(ret = WinHttpReadData(req, buf, sizeof(buf), NULL))) break;
403 if (wait_for_completion(job) || FAILED(job->error.code))
404 {
405 ret = FALSE;
406 break;
407 }
408 if (!file->read_size) break;
409 if (!(ret = WriteFile(handle, buf, file->read_size, &written, NULL))) break;
410
412 file->fileProgress.BytesTransferred += file->read_size;
413 job->jobProgress.BytesTransferred += file->read_size;
415 }
416
418
419done:
423 if (!ret && !transitionJobState(job, BG_JOB_STATE_CONNECTING, BG_JOB_STATE_ERROR))
424 transitionJobState(job, BG_JOB_STATE_TRANSFERRING, BG_JOB_STATE_ERROR);
425
426 SetEvent(job->done);
427 return ret;
428}
#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 WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
static void CALLBACK progress_callback_http(HINTERNET handle, DWORD_PTR context, DWORD status, LPVOID buf, DWORD buflen)
Definition: file.c:224
static DWORD wait_for_completion(BackgroundCopyJobImpl *job)
Definition: file.c:294
static BOOL set_request_credentials(HINTERNET req, BackgroundCopyJobImpl *job)
Definition: file.c:347
HINTERNET WINAPI WinHttpOpen(LPCWSTR agent, DWORD access, LPCWSTR proxy, LPCWSTR bypass, DWORD flags)
Definition: session.c:250
HINTERNET WINAPI WinHttpConnect(HINTERNET hsession, LPCWSTR server, INTERNET_PORT port, DWORD reserved)
Definition: session.c:541
BOOL WINAPI WinHttpCloseHandle(HINTERNET handle)
Definition: session.c:1195
HINTERNET WINAPI WinHttpOpenRequest(HINTERNET hconnect, LPCWSTR verb, LPCWSTR object, LPCWSTR version, LPCWSTR referrer, LPCWSTR *types, DWORD flags)
Definition: session.c:1117
BOOL WINAPI WinHttpSetOption(HINTERNET handle, DWORD option, LPVOID buffer, DWORD buflen)
Definition: session.c:1312
WINHTTP_STATUS_CALLBACK WINAPI WinHttpSetStatusCallback(HINTERNET handle, WINHTTP_STATUS_CALLBACK callback, DWORD flags, DWORD_PTR reserved)
Definition: session.c:2056
GLbitfield flags
Definition: glext.h:7161
_Check_return_ _CRTIMP FILE *__cdecl tmpfile(void)
Definition: file.c:3914
#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, LPVOID buffer, DWORD to_read, LPDWORD read)
Definition: request.c:3053
BOOL WINAPI WinHttpSendRequest(HINTERNET hrequest, LPCWSTR headers, DWORD headers_len, LPVOID optional, DWORD optional_len, DWORD total_len, DWORD_PTR context)
Definition: request.c:2350
BOOL WINAPI WinHttpReceiveResponse(HINTERNET hrequest, LPVOID reserved)
Definition: request.c:2924
uint32_t DWORD_PTR
Definition: typedefs.h:65
#define WINHTTP_OPTION_CONTEXT_VALUE
Definition: winhttp.h:112
#define WINHTTP_CALLBACK_FLAG_ALL_COMPLETIONS
Definition: winhttp.h:418
#define WINHTTP_FLAG_ASYNC
Definition: winhttp.h:51
#define WINHTTP_FLAG_SECURE
Definition: winhttp.h:60
#define INTERNET_SCHEME_HTTPS
Definition: winhttp.h:43

Referenced by processFile().

◆ transfer_file_local()

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

Definition at line 453 of file file.c.

454{
455 static const WCHAR fileW[] = {'f','i','l','e',':','/','/',0};
457 const WCHAR *ptr;
458 BOOL ret;
459
460 transitionJobState(job, BG_JOB_STATE_QUEUED, BG_JOB_STATE_TRANSFERRING);
461
462 if (lstrlenW(file->info.RemoteName) > 7 && !_wcsnicmp(file->info.RemoteName, fileW, 7))
463 ptr = file->info.RemoteName + 7;
464 else
465 ptr = file->info.RemoteName;
466
467 if (!(ret = CopyFileExW(ptr, tmpname, progress_callback_local, file, NULL, 0)))
468 {
469 WARN("Local file copy failed: error %u\n", GetLastError());
470 transitionJobState(job, BG_JOB_STATE_TRANSFERRING, BG_JOB_STATE_ERROR);
471 }
472
473 SetEvent(job->done);
474 return ret;
475}
#define lstrlenW
Definition: compat.h:750
BOOL WINAPI CopyFileExW(IN LPCWSTR lpExistingFileName, IN LPCWSTR lpNewFileName, IN LPPROGRESS_ROUTINE lpProgressRoutine OPTIONAL, IN LPVOID lpData OPTIONAL, IN LPBOOL pbCancel OPTIONAL, IN DWORD dwCopyFlags)
Definition: copy.c:318
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:430
static const WCHAR fileW[]
Definition: url.c:111
static PVOID ptr
Definition: dispmode.c:27
_Check_return_ _CRTIMP int __cdecl _wcsnicmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)

Referenced by processFile().

◆ wait_for_completion()

static DWORD wait_for_completion ( BackgroundCopyJobImpl job)
static

Definition at line 294 of file file.c.

295{
296 HANDLE handles[2] = {job->wait, job->cancel};
298
300 {
301 case WAIT_OBJECT_0:
302 break;
303
304 case WAIT_OBJECT_0 + 1:
306 transitionJobState(job, BG_JOB_STATE_TRANSFERRING, BG_JOB_STATE_CANCELLED);
307 break;
308
309 default:
311 transitionJobState(job, BG_JOB_STATE_TRANSFERRING, BG_JOB_STATE_ERROR);
312 break;
313 }
314
315 return error;
316}
#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:62
#define WAIT_OBJECT_0
Definition: winbase.h:406
#define ERROR_CANCELLED
Definition: winerror.h:726

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().