ReactOS  0.4.14-dev-50-g13bb5e2
protocol.c File Reference
#include "urlmon_main.h"
#include "wine/debug.h"
Include dependency graph for protocol.c:

Go to the source code of this file.

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (urlmon)
 
static HRESULT report_progress (Protocol *protocol, ULONG status_code, LPCWSTR status_text)
 
static HRESULT report_result (Protocol *protocol, HRESULT hres)
 
static void report_data (Protocol *protocol)
 
static void all_data_read (Protocol *protocol)
 
static HRESULT start_downloading (Protocol *protocol)
 
HRESULT protocol_syncbinding (Protocol *protocol)
 
static void request_complete (Protocol *protocol, INTERNET_ASYNC_RESULT *ar)
 
static void WINAPI internet_status_callback (HINTERNET internet, DWORD_PTR context, DWORD internet_status, LPVOID status_info, DWORD status_info_len)
 
static HRESULT write_post_stream (Protocol *protocol)
 
static HINTERNET create_internet_session (IInternetBindInfo *bind_info)
 
HINTERNET get_internet_session (IInternetBindInfo *bind_info)
 
void update_user_agent (WCHAR *user_agent)
 
HRESULT protocol_start (Protocol *protocol, IInternetProtocol *prot, IUri *uri, IInternetProtocolSink *protocol_sink, IInternetBindInfo *bind_info)
 
HRESULT protocol_continue (Protocol *protocol, PROTOCOLDATA *data)
 
HRESULT protocol_read (Protocol *protocol, void *buf, ULONG size, ULONG *read_ret)
 
HRESULT protocol_lock_request (Protocol *protocol)
 
HRESULT protocol_unlock_request (Protocol *protocol)
 
HRESULT protocol_abort (Protocol *protocol, HRESULT reason)
 
void protocol_close_connection (Protocol *protocol)
 

Variables

static HINTERNET internet_session
 

Function Documentation

◆ all_data_read()

static void all_data_read ( Protocol protocol)
static

Definition at line 65 of file protocol.c.

66 {
67  protocol->flags |= FLAG_ALL_DATA_READ;
68 
71 }
#define FLAG_ALL_DATA_READ
Definition: urlmon_main.h:154
static void report_data(Protocol *protocol)
Definition: protocol.c:41
static HRESULT report_result(Protocol *protocol, HRESULT hres)
Definition: protocol.c:31
#define S_OK
Definition: intsafe.h:59

Referenced by protocol_continue(), and protocol_read().

◆ create_internet_session()

static HINTERNET create_internet_session ( IInternetBindInfo bind_info)
static

Definition at line 264 of file protocol.c.

265 {
266  LPWSTR global_user_agent = NULL;
268  ULONG size = 0;
269  HINTERNET ret;
270  HRESULT hres;
271 
272  hres = IInternetBindInfo_GetBindString(bind_info, BINDSTRING_USER_AGENT, &user_agent, 1, &size);
273  if(hres != S_OK || !size)
274  global_user_agent = get_useragent();
275 
276  ret = InternetOpenW(user_agent ? user_agent : global_user_agent, 0, NULL, NULL, INTERNET_FLAG_ASYNC);
277  heap_free(global_user_agent);
279  if(!ret) {
280  WARN("InternetOpen failed: %d\n", GetLastError());
281  return NULL;
282  }
283 
285  return ret;
286 }
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:422
LPWSTR get_useragent(void)
Definition: session.c:609
#define WARN(fmt,...)
Definition: debug.h:111
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
static LPOLESTR
Definition: stg_prop.c:27
smooth NULL
Definition: ftsmooth.c:416
static IInternetBindInfo bind_info
Definition: protocol.c:284
GLsizeiptr size
Definition: glext.h:5919
HRESULT hres
Definition: protocol.c:465
INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackW(HINTERNET hInternet, INTERNET_STATUS_CALLBACK lpfnIntCB)
Definition: internet.c:2098
LONG HRESULT
Definition: typedefs.h:77
static void WINAPI internet_status_callback(HINTERNET internet, DWORD_PTR context, DWORD internet_status, LPVOID status_info, DWORD status_info_len)
Definition: protocol.c:158
static LPWSTR user_agent
Definition: session.c:520
#define INTERNET_FLAG_ASYNC
Definition: wininet.h:64
int ret
#define S_OK
Definition: intsafe.h:59
unsigned int ULONG
Definition: retypes.h:1
WCHAR * LPWSTR
Definition: xmlstorage.h:184
HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType, LPCWSTR lpszProxy, LPCWSTR lpszProxyBypass, DWORD dwFlags)
Definition: internet.c:1002
static BOOL heap_free(void *mem)
Definition: appwiz.h:75

Referenced by get_internet_session().

◆ get_internet_session()

HINTERNET get_internet_session ( IInternetBindInfo bind_info)

Definition at line 290 of file protocol.c.

291 {
292  HINTERNET new_session;
293 
294  if(internet_session)
295  return internet_session;
296 
297  if(!bind_info)
298  return NULL;
299 
300  new_session = create_internet_session(bind_info);
301  if(new_session && InterlockedCompareExchangePointer((void**)&internet_session, new_session, NULL))
302  InternetCloseHandle(new_session);
303 
304  return internet_session;
305 }
static HINTERNET internet_session
Definition: protocol.c:288
BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
Definition: internet.c:1437
#define InterlockedCompareExchangePointer
Definition: interlocked.h:129
smooth NULL
Definition: ftsmooth.c:416
static IInternetBindInfo bind_info
Definition: protocol.c:284
static HINTERNET create_internet_session(IInternetBindInfo *bind_info)
Definition: protocol.c:264

Referenced by process_detach(), and protocol_start().

◆ internet_status_callback()

static void WINAPI internet_status_callback ( HINTERNET  internet,
DWORD_PTR  context,
DWORD  internet_status,
LPVOID  status_info,
DWORD  status_info_len 
)
static

Definition at line 158 of file protocol.c.

160 {
162 
163  switch(internet_status) {
165  TRACE("%p INTERNET_STATUS_RESOLVING_NAME\n", protocol);
166  report_progress(protocol, BINDSTATUS_FINDINGRESOURCE, (LPWSTR)status_info);
167  break;
168 
170  WCHAR *info;
171 
172  TRACE("%p INTERNET_STATUS_CONNECTING_TO_SERVER %s\n", protocol, (const char*)status_info);
173 
174  info = heap_strdupAtoW(status_info);
175  if(!info)
176  return;
177 
178  report_progress(protocol, BINDSTATUS_CONNECTING, info);
179  heap_free(info);
180  break;
181  }
182 
184  TRACE("%p INTERNET_STATUS_SENDING_REQUEST\n", protocol);
185  report_progress(protocol, BINDSTATUS_SENDINGREQUEST, (LPWSTR)status_info);
186  break;
187 
189  TRACE("%p INTERNET_STATUS_REDIRECT\n", protocol);
190  report_progress(protocol, BINDSTATUS_REDIRECTING, (LPWSTR)status_info);
191  break;
192 
194  request_complete(protocol, status_info);
195  break;
196 
198  TRACE("%p INTERNET_STATUS_HANDLE_CREATED\n", protocol);
199  IInternetProtocol_AddRef(protocol->protocol);
200  break;
201 
203  TRACE("%p INTERNET_STATUS_HANDLE_CLOSING\n", protocol);
204 
205  if(*(HINTERNET *)status_info == protocol->request) {
206  protocol->request = NULL;
207  if(protocol->protocol_sink) {
208  IInternetProtocolSink_Release(protocol->protocol_sink);
209  protocol->protocol_sink = NULL;
210  }
211 
212  if(protocol->bind_info.cbSize) {
213  ReleaseBindInfo(&protocol->bind_info);
214  memset(&protocol->bind_info, 0, sizeof(protocol->bind_info));
215  }
216  }else if(*(HINTERNET *)status_info == protocol->connection) {
217  protocol->connection = NULL;
218  }
219 
220  IInternetProtocol_Release(protocol->protocol);
221  break;
222 
223  default:
224  WARN("Unhandled Internet status callback %d\n", internet_status);
225  }
226 }
#define INTERNET_STATUS_HANDLE_CLOSING
Definition: wininet.h:896
Definition: http.c:6587
void WINAPI ReleaseBindInfo(BINDINFO *pbindinfo)
Definition: urlmon_main.c:572
#define WARN(fmt,...)
Definition: debug.h:111
#define INTERNET_STATUS_CONNECTING_TO_SERVER
Definition: wininet.h:885
static void request_complete(Protocol *protocol, INTERNET_ASYNC_RESULT *ar)
Definition: protocol.c:124
struct _test_info info[]
Definition: SetCursorPos.c:19
smooth NULL
Definition: ftsmooth.c:416
static WCHAR * heap_strdupAtoW(const char *str)
Definition: appwiz.h:80
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define INTERNET_STATUS_REDIRECT
Definition: wininet.h:899
#define INTERNET_STATUS_SENDING_REQUEST
Definition: wininet.h:887
#define INTERNET_STATUS_RESOLVING_NAME
Definition: wininet.h:883
#define INTERNET_STATUS_REQUEST_COMPLETE
Definition: wininet.h:898
#define INTERNET_STATUS_HANDLE_CREATED
Definition: wininet.h:895
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define memset(x, y, z)
Definition: compat.h:39
static BOOL heap_free(void *mem)
Definition: appwiz.h:75
static HRESULT report_progress(Protocol *protocol, ULONG status_code, LPCWSTR status_text)
Definition: protocol.c:26

Referenced by create_internet_session().

◆ protocol_abort()

HRESULT protocol_abort ( Protocol protocol,
HRESULT  reason 
)

Definition at line 518 of file protocol.c.

519 {
520  if(!protocol->protocol_sink)
521  return S_OK;
522 
523  /* NOTE: IE10 returns S_OK here */
524  if(protocol->flags & FLAG_RESULT_REPORTED)
525  return INET_E_RESULT_DISPATCHED;
526 
528  return S_OK;
529 }
static HRESULT report_result(Protocol *protocol, HRESULT hres)
Definition: protocol.c:31
static WCHAR reason[MAX_STRING_RESOURCE_LEN]
Definition: object.c:1904
#define FLAG_RESULT_REPORTED
Definition: urlmon_main.h:156
#define S_OK
Definition: intsafe.h:59

Referenced by FtpProtocol_Abort(), GopherProtocol_Abort(), HttpProtocol_Abort(), and HttpProtocol_on_error().

◆ protocol_close_connection()

void protocol_close_connection ( Protocol protocol)

Definition at line 531 of file protocol.c.

532 {
533  protocol->vtbl->close_connection(protocol);
534 
535  if(protocol->request)
536  InternetCloseHandle(protocol->request);
537 
538  if(protocol->connection)
539  InternetCloseHandle(protocol->connection);
540 
541  if(protocol->post_stream) {
542  IStream_Release(protocol->post_stream);
543  protocol->post_stream = NULL;
544  }
545 
546  protocol->flags = 0;
547 }
BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
Definition: internet.c:1437
smooth NULL
Definition: ftsmooth.c:416

Referenced by FtpProtocol_Terminate(), FtpProtocolUnk_Release(), GopherProtocol_Terminate(), HttpProtocol_on_error(), HttpProtocol_Terminate(), HttpProtocolUnk_Release(), protocol_start(), and start_downloading().

◆ protocol_continue()

HRESULT protocol_continue ( Protocol protocol,
PROTOCOLDATA *  data 
)

Definition at line 355 of file protocol.c.

356 {
357  BOOL is_start;
358  HRESULT hres;
359 
360  is_start = !data || data->pData == UlongToPtr(BINDSTATUS_DOWNLOADINGDATA);
361 
362  if(!protocol->request) {
363  WARN("Expected request to be non-NULL\n");
364  return S_OK;
365  }
366 
367  if(!protocol->protocol_sink) {
368  WARN("Expected IInternetProtocolSink pointer to be non-NULL\n");
369  return S_OK;
370  }
371 
372  if(protocol->flags & FLAG_ERROR) {
373  protocol->flags &= ~FLAG_ERROR;
374  protocol->vtbl->on_error(protocol, PtrToUlong(data->pData));
375  return S_OK;
376  }
377 
378  if(protocol->post_stream)
379  return write_post_stream(protocol);
380 
381  if(is_start) {
383  if(FAILED(hres))
384  return S_OK;
385  }
386 
387  if(!data || data->pData >= UlongToPtr(BINDSTATUS_DOWNLOADINGDATA)) {
388  if(!protocol->available_bytes) {
389  if(protocol->query_available) {
390  protocol->available_bytes = protocol->query_available;
391  }else {
392  BOOL res;
393 
394  /* InternetQueryDataAvailable may immediately fork and perform its asynchronous
395  * read, so clear the flag _before_ calling so it does not incorrectly get cleared
396  * after the status callback is called */
397  protocol->flags &= ~FLAG_REQUEST_COMPLETE;
398  res = InternetQueryDataAvailable(protocol->request, &protocol->query_available, 0, 0);
399  if(res) {
400  TRACE("available %u bytes\n", protocol->query_available);
401  if(!protocol->query_available) {
403  return S_OK;
404  }
405  protocol->available_bytes = protocol->query_available;
406  }else if(GetLastError() != ERROR_IO_PENDING) {
408  WARN("InternetQueryDataAvailable failed: %d\n", GetLastError());
409  report_result(protocol, INET_E_DATA_NOT_AVAILABLE);
410  return S_OK;
411  }
412  }
413 
415  }
416 
418  }
419 
420  return S_OK;
421 }
static void report_data(Protocol *protocol)
Definition: protocol.c:41
#define WARN(fmt,...)
Definition: debug.h:111
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define ERROR_IO_PENDING
Definition: dderror.h:15
static HRESULT write_post_stream(Protocol *protocol)
Definition: protocol.c:228
unsigned int BOOL
Definition: ntddk_ex.h:94
BOOL WINAPI InternetQueryDataAvailable(HINTERNET hFile, LPDWORD lpdwNumberOfBytesAvailable, DWORD dwFlags, DWORD_PTR dwContext)
Definition: internet.c:3845
#define UlongToPtr(u)
Definition: config.h:106
#define PtrToUlong(u)
Definition: config.h:107
#define TRACE(s)
Definition: solgame.cpp:4
HRESULT hres
Definition: protocol.c:465
LONG HRESULT
Definition: typedefs.h:77
static HRESULT report_result(Protocol *protocol, HRESULT hres)
Definition: protocol.c:31
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define S_OK
Definition: intsafe.h:59
static HRESULT start_downloading(Protocol *protocol)
Definition: protocol.c:73
GLuint res
Definition: glext.h:9613
#define FLAG_ERROR
Definition: urlmon_main.h:157
#define FLAG_REQUEST_COMPLETE
Definition: urlmon_main.h:151
static void all_data_read(Protocol *protocol)
Definition: protocol.c:65

Referenced by FtpProtocol_Continue(), GopherProtocol_Continue(), HttpProtocol_Continue(), and request_complete().

◆ protocol_lock_request()

HRESULT protocol_lock_request ( Protocol protocol)

Definition at line 498 of file protocol.c.

499 {
500  if (!InternetLockRequestFile(protocol->request, &protocol->lock))
501  WARN("InternetLockRequest failed: %d\n", GetLastError());
502 
503  return S_OK;
504 }
#define WARN(fmt,...)
Definition: debug.h:111
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL WINAPI InternetLockRequestFile(HINTERNET hInternet, HANDLE *lphLockReqHandle)
Definition: internet.c:3918
#define S_OK
Definition: intsafe.h:59

Referenced by FtpProtocol_LockRequest(), GopherProtocol_LockRequest(), and HttpProtocol_LockRequest().

◆ protocol_read()

HRESULT protocol_read ( Protocol protocol,
void buf,
ULONG  size,
ULONG read_ret 
)

Definition at line 423 of file protocol.c.

424 {
425  ULONG read = 0;
426  BOOL res;
427  HRESULT hres = S_FALSE;
428 
429  if(protocol->flags & FLAG_ALL_DATA_READ) {
430  *read_ret = 0;
431  return S_FALSE;
432  }
433 
434  if(!(protocol->flags & FLAG_SYNC_READ) && (!(protocol->flags & FLAG_REQUEST_COMPLETE) || !protocol->available_bytes)) {
435  *read_ret = 0;
436  return E_PENDING;
437  }
438 
439  while(read < size && protocol->available_bytes) {
440  ULONG len;
441 
442  res = InternetReadFile(protocol->request, ((BYTE *)buf)+read,
443  protocol->available_bytes > size-read ? size-read : protocol->available_bytes, &len);
444  if(!res) {
445  WARN("InternetReadFile failed: %d\n", GetLastError());
446  hres = INET_E_DOWNLOAD_FAILURE;
448  break;
449  }
450 
451  if(!len) {
453  break;
454  }
455 
456  read += len;
457  protocol->current_position += len;
458  protocol->available_bytes -= len;
459 
460  TRACE("current_position %d, available_bytes %d\n", protocol->current_position, protocol->available_bytes);
461 
462  if(!protocol->available_bytes) {
463  /* InternetQueryDataAvailable may immediately fork and perform its asynchronous
464  * read, so clear the flag _before_ calling so it does not incorrectly get cleared
465  * after the status callback is called */
466  protocol->flags &= ~FLAG_REQUEST_COMPLETE;
467  res = InternetQueryDataAvailable(protocol->request, &protocol->query_available, 0, 0);
468  if(!res) {
469  if (GetLastError() == ERROR_IO_PENDING) {
470  hres = E_PENDING;
471  }else {
472  WARN("InternetQueryDataAvailable failed: %d\n", GetLastError());
473  hres = INET_E_DATA_NOT_AVAILABLE;
475  }
476  break;
477  }
478 
479  if(!protocol->query_available) {
481  break;
482  }
483 
484  protocol->available_bytes = protocol->query_available;
485  }
486  }
487 
488  *read_ret = read;
489 
490  if (hres != E_PENDING)
492  if(FAILED(hres))
493  return hres;
494 
495  return read ? S_OK : S_FALSE;
496 }
#define FLAG_ALL_DATA_READ
Definition: urlmon_main.h:154
#define FLAG_SYNC_READ
Definition: urlmon_main.h:158
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define WARN(fmt,...)
Definition: debug.h:111
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define ERROR_IO_PENDING
Definition: dderror.h:15
unsigned int BOOL
Definition: ntddk_ex.h:94
#define S_FALSE
Definition: winerror.h:2357
BOOL WINAPI InternetQueryDataAvailable(HINTERNET hFile, LPDWORD lpdwNumberOfBytesAvailable, DWORD dwFlags, DWORD_PTR dwContext)
Definition: internet.c:3845
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919
HRESULT hres
Definition: protocol.c:465
LONG HRESULT
Definition: typedefs.h:77
static HRESULT report_result(Protocol *protocol, HRESULT hres)
Definition: protocol.c:31
GLenum GLsizei len
Definition: glext.h:6722
unsigned char BYTE
Definition: mem.h:68
#define S_OK
Definition: intsafe.h:59
BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer, DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead)
Definition: internet.c:2175
GLuint res
Definition: glext.h:9613
unsigned int ULONG
Definition: retypes.h:1
#define E_PENDING
Definition: dinput.h:172
#define FLAG_REQUEST_COMPLETE
Definition: urlmon_main.h:151
static void all_data_read(Protocol *protocol)
Definition: protocol.c:65
_CRTIMP int __cdecl read(_In_ int _FileHandle, _Out_writes_bytes_(_MaxCharCount) void *_DstBuf, _In_ unsigned int _MaxCharCount)

◆ protocol_start()

HRESULT protocol_start ( Protocol protocol,
IInternetProtocol prot,
IUri uri,
IInternetProtocolSink protocol_sink,
IInternetBindInfo bind_info 
)

Definition at line 313 of file protocol.c.

315 {
316  DWORD request_flags;
317  HRESULT hres;
318 
319  protocol->protocol = prot;
320 
321  IInternetProtocolSink_AddRef(protocol_sink);
322  protocol->protocol_sink = protocol_sink;
323 
324  memset(&protocol->bind_info, 0, sizeof(protocol->bind_info));
325  protocol->bind_info.cbSize = sizeof(BINDINFO);
326  hres = IInternetBindInfo_GetBindInfo(bind_info, &protocol->bindf, &protocol->bind_info);
327  if(hres != S_OK) {
328  WARN("GetBindInfo failed: %08x\n", hres);
329  return report_result(protocol, hres);
330  }
331 
332  if(!(protocol->bindf & BINDF_FROMURLMON))
333  report_progress(protocol, BINDSTATUS_DIRECTBIND, NULL);
334 
336  return report_result(protocol, INET_E_NO_SESSION);
337 
338  request_flags = INTERNET_FLAG_KEEP_CONNECTION;
339  if(protocol->bindf & BINDF_NOWRITECACHE)
340  request_flags |= INTERNET_FLAG_NO_CACHE_WRITE;
341  if(protocol->bindf & BINDF_NEEDFILE)
342  request_flags |= INTERNET_FLAG_NEED_FILE;
343  if(protocol->bind_info.dwOptions & BINDINFO_OPTIONS_DISABLEAUTOREDIRECTS)
344  request_flags |= INTERNET_FLAG_NO_AUTO_REDIRECT;
345 
346  hres = protocol->vtbl->open_request(protocol, uri, request_flags, internet_session, bind_info);
347  if(FAILED(hres)) {
349  return report_result(protocol, hres);
350  }
351 
352  return S_OK;
353 }
#define INTERNET_FLAG_NO_CACHE_WRITE
Definition: wininet.h:66
#define INTERNET_FLAG_NEED_FILE
Definition: wininet.h:88
const char * uri
Definition: sec_mgr.c:1594
#define WARN(fmt,...)
Definition: debug.h:111
static HINTERNET internet_session
Definition: protocol.c:288
void protocol_close_connection(Protocol *protocol)
Definition: protocol.c:531
static IInternetProtocolSink protocol_sink
Definition: protocol.c:232
smooth NULL
Definition: ftsmooth.c:416
static IInternetBindInfo bind_info
Definition: protocol.c:284
HRESULT hres
Definition: protocol.c:465
#define INTERNET_FLAG_NO_AUTO_REDIRECT
Definition: wininet.h:73
LONG HRESULT
Definition: typedefs.h:77
unsigned long DWORD
Definition: ntddk_ex.h:95
static HRESULT report_result(Protocol *protocol, HRESULT hres)
Definition: protocol.c:31
HINTERNET get_internet_session(IInternetBindInfo *bind_info)
Definition: protocol.c:290
#define S_OK
Definition: intsafe.h:59
#define memset(x, y, z)
Definition: compat.h:39
static HRESULT report_progress(Protocol *protocol, ULONG status_code, LPCWSTR status_text)
Definition: protocol.c:26
#define INTERNET_FLAG_KEEP_CONNECTION
Definition: wininet.h:72

Referenced by do_test_about_protocol(), ProtocolEmul_Start(), ProtocolEmul_StartEx(), test_res_protocol(), and test_res_url().

◆ protocol_syncbinding()

HRESULT protocol_syncbinding ( Protocol protocol)

Definition at line 101 of file protocol.c.

102 {
103  BOOL res;
104  HRESULT hres;
105 
106  protocol->flags |= FLAG_SYNC_READ;
107 
109  if(FAILED(hres))
110  return hres;
111 
112  res = InternetQueryDataAvailable(protocol->request, &protocol->query_available, 0, 0);
113  if(res)
114  protocol->available_bytes = protocol->query_available;
115  else
116  WARN("InternetQueryDataAvailable failed: %u\n", GetLastError());
117 
119  IInternetProtocolSink_ReportData(protocol->protocol_sink, BSCF_LASTDATANOTIFICATION|BSCF_DATAFULLYAVAILABLE,
120  protocol->available_bytes, protocol->content_length);
121  return S_OK;
122 }
#define FLAG_SYNC_READ
Definition: urlmon_main.h:158
#define WARN(fmt,...)
Definition: debug.h:111
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
unsigned int BOOL
Definition: ntddk_ex.h:94
BOOL WINAPI InternetQueryDataAvailable(HINTERNET hFile, LPDWORD lpdwNumberOfBytesAvailable, DWORD dwFlags, DWORD_PTR dwContext)
Definition: internet.c:3845
HRESULT hres
Definition: protocol.c:465
#define FLAG_FIRST_DATA_REPORTED
Definition: urlmon_main.h:153
LONG HRESULT
Definition: typedefs.h:77
#define S_OK
Definition: intsafe.h:59
static HRESULT start_downloading(Protocol *protocol)
Definition: protocol.c:73
GLuint res
Definition: glext.h:9613
#define FLAG_LAST_DATA_REPORTED
Definition: urlmon_main.h:155

Referenced by HttpProtocol_open_request().

◆ protocol_unlock_request()

HRESULT protocol_unlock_request ( Protocol protocol)

Definition at line 506 of file protocol.c.

507 {
508  if(!protocol->lock)
509  return S_OK;
510 
512  WARN("InternetUnlockRequest failed: %d\n", GetLastError());
513  protocol->lock = 0;
514 
515  return S_OK;
516 }
#define WARN(fmt,...)
Definition: debug.h:111
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL WINAPI InternetUnlockRequestFile(HANDLE hLockHandle)
Definition: internet.c:3947
#define S_OK
Definition: intsafe.h:59

Referenced by FtpProtocol_UnlockRequest(), GopherProtocol_UnlockRequest(), and HttpProtocol_UnlockRequest().

◆ report_data()

static void report_data ( Protocol protocol)
static

Definition at line 41 of file protocol.c.

42 {
43  DWORD bscf;
44 
45  if((protocol->flags & FLAG_LAST_DATA_REPORTED) || !protocol->protocol_sink)
46  return;
47 
48  if(protocol->flags & FLAG_FIRST_DATA_REPORTED) {
49  bscf = BSCF_INTERMEDIATEDATANOTIFICATION;
50  }else {
52  bscf = BSCF_FIRSTDATANOTIFICATION;
53  }
54 
55  if(protocol->flags & FLAG_ALL_DATA_READ && !(protocol->flags & FLAG_LAST_DATA_REPORTED)) {
57  bscf |= BSCF_LASTDATANOTIFICATION;
58  }
59 
60  IInternetProtocolSink_ReportData(protocol->protocol_sink, bscf,
61  protocol->current_position+protocol->available_bytes,
62  protocol->content_length);
63 }
#define FLAG_ALL_DATA_READ
Definition: urlmon_main.h:154
#define FLAG_FIRST_DATA_REPORTED
Definition: urlmon_main.h:153
unsigned long DWORD
Definition: ntddk_ex.h:95
#define FLAG_LAST_DATA_REPORTED
Definition: urlmon_main.h:155

Referenced by all_data_read(), and protocol_continue().

◆ report_progress()

static HRESULT report_progress ( Protocol protocol,
ULONG  status_code,
LPCWSTR  status_text 
)
inlinestatic

Definition at line 26 of file protocol.c.

27 {
28  return IInternetProtocolSink_ReportProgress(protocol->protocol_sink, status_code, status_text);
29 }

Referenced by internet_status_callback(), protocol_start(), and start_downloading().

◆ report_result()

static HRESULT report_result ( Protocol protocol,
HRESULT  hres 
)
inlinestatic

Definition at line 31 of file protocol.c.

32 {
33  if (!(protocol->flags & FLAG_RESULT_REPORTED) && protocol->protocol_sink) {
35  IInternetProtocolSink_ReportResult(protocol->protocol_sink, hres, 0, NULL);
36  }
37 
38  return hres;
39 }
smooth NULL
Definition: ftsmooth.c:416
HRESULT hres
Definition: protocol.c:465
#define FLAG_RESULT_REPORTED
Definition: urlmon_main.h:156

Referenced by all_data_read(), protocol_abort(), protocol_continue(), protocol_read(), protocol_start(), start_downloading(), and write_post_stream().

◆ request_complete()

static void request_complete ( Protocol protocol,
INTERNET_ASYNC_RESULT ar 
)
static

Definition at line 124 of file protocol.c.

125 {
126  PROTOCOLDATA data;
127 
128  TRACE("(%p)->(%p)\n", protocol, ar);
129 
130  /* PROTOCOLDATA same as native */
131  memset(&data, 0, sizeof(data));
132  data.dwState = 0xf1000000;
133 
134  if(ar->dwResult) {
136 
137  if(!protocol->request) {
138  TRACE("setting request handle %p\n", (HINTERNET)ar->dwResult);
139  protocol->request = (HINTERNET)ar->dwResult;
140  }
141 
143  data.pData = UlongToPtr(BINDSTATUS_ENDDOWNLOADCOMPONENTS);
144  else
145  data.pData = UlongToPtr(BINDSTATUS_DOWNLOADINGDATA);
146 
147  }else {
148  protocol->flags |= FLAG_ERROR;
149  data.pData = UlongToPtr(ar->dwError);
150  }
151 
152  if (protocol->bindf & BINDF_FROMURLMON)
153  IInternetProtocolSink_Switch(protocol->protocol_sink, &data);
154  else
156 }
LPVOID HINTERNET
Definition: winhttp.h:32
#define UlongToPtr(u)
Definition: config.h:106
#define TRACE(s)
Definition: solgame.cpp:4
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
DWORD_PTR dwResult
Definition: wininet.h:155
HRESULT protocol_continue(Protocol *protocol, PROTOCOLDATA *data)
Definition: protocol.c:355
#define FLAG_FIRST_CONTINUE_COMPLETE
Definition: urlmon_main.h:152
#define FLAG_ERROR
Definition: urlmon_main.h:157
#define memset(x, y, z)
Definition: compat.h:39
#define FLAG_REQUEST_COMPLETE
Definition: urlmon_main.h:151

Referenced by internet_status_callback().

◆ start_downloading()

static HRESULT start_downloading ( Protocol protocol)
static

Definition at line 73 of file protocol.c.

74 {
75  HRESULT hres;
76 
77  hres = protocol->vtbl->start_downloading(protocol);
78  if(FAILED(hres)) {
79  if(hres == INET_E_REDIRECT_FAILED)
80  return S_OK;
83  return hres;
84  }
85 
86  if(protocol->bindf & BINDF_NEEDFILE) {
88  DWORD buflen = sizeof(cache_file);
89 
91  report_progress(protocol, BINDSTATUS_CACHEFILENAMEAVAILABLE, cache_file);
92  }else {
93  FIXME("Could not get cache file\n");
94  }
95  }
96 
98  return S_OK;
99 }
void protocol_close_connection(Protocol *protocol)
Definition: protocol.c:531
#define FIXME(fmt,...)
Definition: debug.h:110
static const WCHAR * cache_file
Definition: protocol.c:102
HRESULT hres
Definition: protocol.c:465
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
static HRESULT report_result(Protocol *protocol, HRESULT hres)
Definition: protocol.c:31
#define FLAG_FIRST_CONTINUE_COMPLETE
Definition: urlmon_main.h:152
#define S_OK
Definition: intsafe.h:59
BOOL WINAPI InternetQueryOptionW(HINTERNET hInternet, DWORD dwOption, LPVOID lpBuffer, LPDWORD lpdwBufferLength)
Definition: internet.c:2576
#define INTERNET_OPTION_DATAFILE_NAME
Definition: wininet.h:727
static HRESULT report_progress(Protocol *protocol, ULONG status_code, LPCWSTR status_text)
Definition: protocol.c:26

Referenced by protocol_continue(), and protocol_syncbinding().

◆ update_user_agent()

void update_user_agent ( WCHAR user_agent)

Definition at line 307 of file protocol.c.

308 {
309  if(internet_session)
311 }
WINE_UNICODE_INLINE unsigned int strlenW(const WCHAR *str)
Definition: unicode.h:212
BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption, LPVOID lpBuffer, DWORD dwBufferLength)
Definition: internet.c:2716
static HINTERNET internet_session
Definition: protocol.c:288
static LPWSTR user_agent
Definition: session.c:520
#define INTERNET_OPTION_USER_AGENT
Definition: wininet.h:735

Referenced by UrlMkSetSessionOption().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( urlmon  )

◆ write_post_stream()

static HRESULT write_post_stream ( Protocol protocol)
static

Definition at line 228 of file protocol.c.

229 {
230  BYTE buf[0x20000];
231  DWORD written;
232  ULONG size;
233  BOOL res;
234  HRESULT hres;
235 
236  protocol->flags &= ~FLAG_REQUEST_COMPLETE;
237 
238  while(1) {
239  size = 0;
240  hres = IStream_Read(protocol->post_stream, buf, sizeof(buf), &size);
241  if(FAILED(hres) || !size)
242  break;
243  res = InternetWriteFile(protocol->request, buf, size, &written);
244  if(!res) {
245  FIXME("InternetWriteFile failed: %u\n", GetLastError());
246  hres = E_FAIL;
247  break;
248  }
249  }
250 
251  if(SUCCEEDED(hres)) {
252  IStream_Release(protocol->post_stream);
253  protocol->post_stream = NULL;
254 
255  hres = protocol->vtbl->end_request(protocol);
256  }
257 
258  if(FAILED(hres))
259  return report_result(protocol, hres);
260 
261  return S_OK;
262 }
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define E_FAIL
Definition: ddrawi.h:102
unsigned int BOOL
Definition: ntddk_ex.h:94
#define FIXME(fmt,...)
Definition: debug.h:110
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI InternetWriteFile(HINTERNET hFile, LPCVOID lpBuffer, DWORD dwNumOfBytesToWrite, LPDWORD lpdwNumOfBytesWritten)
Definition: internet.c:2135
GLsizeiptr size
Definition: glext.h:5919
HRESULT hres
Definition: protocol.c:465
LONG HRESULT
Definition: typedefs.h:77
unsigned long DWORD
Definition: ntddk_ex.h:95
static HRESULT report_result(Protocol *protocol, HRESULT hres)
Definition: protocol.c:31
unsigned char BYTE
Definition: mem.h:68
#define S_OK
Definition: intsafe.h:59
GLuint res
Definition: glext.h:9613
unsigned int ULONG
Definition: retypes.h:1
#define FLAG_REQUEST_COMPLETE
Definition: urlmon_main.h:151
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by protocol_continue().

Variable Documentation

◆ internet_session