static HRESULT FtpProtocol_start_downloading(Protocol *prot) { FtpProtocol *This = ASYNCPROTOCOL_THIS(prot); DWORD size; BOOL res; res = FtpGetFileSize(This->base.request, &size); if(res) This->base.content_length = size; else WARN("FtpGetFileSize failed: %d\n", GetLastError()); return S_OK; }
static void HttpProtocol_close_connection(Protocol *prot) { HttpProtocol *This = ASYNCPROTOCOL_THIS(prot); if(This->http_negotiate) { IHttpNegotiate_Release(This->http_negotiate); This->http_negotiate = 0; } if(This->full_header) { if(This->full_header != wszHeaders) heap_free(This->full_header); This->full_header = 0; } }
static HRESULT FtpProtocol_open_request(Protocol *prot, IUri *uri, DWORD request_flags, HINTERNET internet_session, IInternetBindInfo *bind_info) { FtpProtocol *This = ASYNCPROTOCOL_THIS(prot); BSTR url; HRESULT hres; hres = IUri_GetAbsoluteUri(uri, &url); if(FAILED(hres)) return hres; This->base.request = InternetOpenUrlW(internet_session, url, NULL, 0, request_flags|INTERNET_FLAG_EXISTING_CONNECT|INTERNET_FLAG_PASSIVE, (DWORD_PTR)&This->base); SysFreeString(url); if (!This->base.request && GetLastError() != ERROR_IO_PENDING) { WARN("InternetOpenUrl failed: %d\n", GetLastError()); return INET_E_RESOURCE_NOT_FOUND; } return S_OK; }
static HRESULT HttpProtocol_open_request(Protocol *prot, LPCWSTR url, DWORD request_flags, HINTERNET internet_session, IInternetBindInfo *bind_info) { HttpProtocol *This = ASYNCPROTOCOL_THIS(prot); LPWSTR addl_header = NULL, post_cookie = NULL, optional = NULL; IServiceProvider *service_provider = NULL; IHttpNegotiate2 *http_negotiate2 = NULL; LPWSTR host, user, pass, path; LPOLESTR accept_mimes[257]; URL_COMPONENTSW url_comp; BYTE security_id[512]; DWORD len = 0; ULONG num; BOOL res, b; HRESULT hres; static const WCHAR wszBindVerb[BINDVERB_CUSTOM][5] = {{'G','E','T',0}, {'P','O','S','T',0}, {'P','U','T',0}}; memset(&url_comp, 0, sizeof(url_comp)); url_comp.dwStructSize = sizeof(url_comp); url_comp.dwSchemeLength = url_comp.dwHostNameLength = url_comp.dwUrlPathLength = url_comp.dwExtraInfoLength = url_comp.dwUserNameLength = url_comp.dwPasswordLength = 1; if (!InternetCrackUrlW(url, 0, 0, &url_comp)) return MK_E_SYNTAX; if(!url_comp.nPort) url_comp.nPort = This->https ? INTERNET_DEFAULT_HTTPS_PORT : INTERNET_DEFAULT_HTTP_PORT; host = heap_strndupW(url_comp.lpszHostName, url_comp.dwHostNameLength); user = heap_strndupW(url_comp.lpszUserName, url_comp.dwUserNameLength); pass = heap_strndupW(url_comp.lpszPassword, url_comp.dwPasswordLength); This->base.connection = InternetConnectW(internet_session, host, url_comp.nPort, user, pass, INTERNET_SERVICE_HTTP, This->https ? INTERNET_FLAG_SECURE : 0, (DWORD_PTR)&This->base); heap_free(pass); heap_free(user); heap_free(host); if(!This->base.connection) { WARN("InternetConnect failed: %d\n", GetLastError()); return INET_E_CANNOT_CONNECT; } num = sizeof(accept_mimes)/sizeof(accept_mimes[0])-1; hres = IInternetBindInfo_GetBindString(bind_info, BINDSTRING_ACCEPT_MIMES, accept_mimes, num, &num); if(hres != S_OK) { WARN("GetBindString BINDSTRING_ACCEPT_MIMES failed: %08x\n", hres); return INET_E_NO_VALID_MEDIA; } accept_mimes[num] = 0; path = heap_alloc((url_comp.dwUrlPathLength+url_comp.dwExtraInfoLength+1)*sizeof(WCHAR)); if(url_comp.dwUrlPathLength) memcpy(path, url_comp.lpszUrlPath, url_comp.dwUrlPathLength*sizeof(WCHAR)); if(url_comp.dwExtraInfoLength) memcpy(path+url_comp.dwUrlPathLength, url_comp.lpszExtraInfo, url_comp.dwExtraInfoLength*sizeof(WCHAR)); path[url_comp.dwUrlPathLength+url_comp.dwExtraInfoLength] = 0; if(This->https) request_flags |= INTERNET_FLAG_SECURE; This->base.request = HttpOpenRequestW(This->base.connection, This->base.bind_info.dwBindVerb < BINDVERB_CUSTOM ? wszBindVerb[This->base.bind_info.dwBindVerb] : This->base.bind_info.szCustomVerb, path, NULL, NULL, (LPCWSTR *)accept_mimes, request_flags, (DWORD_PTR)&This->base); heap_free(path); while(num--) CoTaskMemFree(accept_mimes[num]); if (!This->base.request) { WARN("HttpOpenRequest failed: %d\n", GetLastError()); return INET_E_RESOURCE_NOT_FOUND; } hres = IInternetProtocolSink_QueryInterface(This->base.protocol_sink, &IID_IServiceProvider, (void **)&service_provider); if (hres != S_OK) { WARN("IInternetProtocolSink_QueryInterface IID_IServiceProvider failed: %08x\n", hres); return hres; } hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate, &IID_IHttpNegotiate, (void **)&This->http_negotiate); if (hres != S_OK) { WARN("IServiceProvider_QueryService IID_IHttpNegotiate failed: %08x\n", hres); return hres; } hres = IHttpNegotiate_BeginningTransaction(This->http_negotiate, url, wszHeaders, 0, &addl_header); if(hres != S_OK) { WARN("IHttpNegotiate_BeginningTransaction failed: %08x\n", hres); IServiceProvider_Release(service_provider); return hres; } if(addl_header) { int len_addl_header = strlenW(addl_header); This->full_header = heap_alloc(len_addl_header*sizeof(WCHAR)+sizeof(wszHeaders)); lstrcpyW(This->full_header, addl_header); lstrcpyW(&This->full_header[len_addl_header], wszHeaders); CoTaskMemFree(addl_header); }else { This->full_header = (LPWSTR)wszHeaders; } hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate2, &IID_IHttpNegotiate2, (void **)&http_negotiate2); IServiceProvider_Release(service_provider); if(hres != S_OK) { WARN("IServiceProvider_QueryService IID_IHttpNegotiate2 failed: %08x\n", hres); /* No goto done as per native */ }else { len = sizeof(security_id)/sizeof(security_id[0]); hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, security_id, &len, 0); IHttpNegotiate2_Release(http_negotiate2); if (hres != S_OK) WARN("IHttpNegotiate2_GetRootSecurityId failed: %08x\n", hres); } /* FIXME: Handle security_id. Native calls undocumented function IsHostInProxyBypassList. */ if(This->base.bind_info.dwBindVerb == BINDVERB_POST) { num = 0; hres = IInternetBindInfo_GetBindString(bind_info, BINDSTRING_POST_COOKIE, &post_cookie, 1, &num); if(hres == S_OK && num) { if(!InternetSetOptionW(This->base.request, INTERNET_OPTION_SECONDARY_CACHE_KEY, post_cookie, lstrlenW(post_cookie))) WARN("InternetSetOption INTERNET_OPTION_SECONDARY_CACHE_KEY failed: %d\n", GetLastError()); CoTaskMemFree(post_cookie); } } if(This->base.bind_info.dwBindVerb != BINDVERB_GET) { /* Native does not use GlobalLock/GlobalUnlock, so we won't either */ if (This->base.bind_info.stgmedData.tymed != TYMED_HGLOBAL) WARN("Expected This->base.bind_info.stgmedData.tymed to be TYMED_HGLOBAL, not %d\n", This->base.bind_info.stgmedData.tymed); else optional = (LPWSTR)This->base.bind_info.stgmedData.u.hGlobal; } b = TRUE; res = InternetSetOptionW(This->base.request, INTERNET_OPTION_HTTP_DECODING, &b, sizeof(b)); if(!res) WARN("InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %08x\n", GetLastError()); res = HttpSendRequestW(This->base.request, This->full_header, lstrlenW(This->full_header), optional, optional ? This->base.bind_info.cbstgmedData : 0); if(!res && GetLastError() != ERROR_IO_PENDING) { WARN("HttpSendRequest failed: %d\n", GetLastError()); return INET_E_DOWNLOAD_FAILURE; } return S_OK; }
static HRESULT HttpProtocol_start_downloading(Protocol *prot) { HttpProtocol *This = ASYNCPROTOCOL_THIS(prot); LPWSTR content_type, content_length, ranges; DWORD len = sizeof(DWORD); DWORD status_code; BOOL res; HRESULT hres; static const WCHAR wszDefaultContentType[] = {'t','e','x','t','/','h','t','m','l',0}; if(!This->http_negotiate) { WARN("Expected IHttpNegotiate pointer to be non-NULL\n"); return S_OK; } res = HttpQueryInfoW(This->base.request, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status_code, &len, NULL); if(res) { LPWSTR response_headers = query_http_info(This, HTTP_QUERY_RAW_HEADERS_CRLF); if(response_headers) { hres = IHttpNegotiate_OnResponse(This->http_negotiate, status_code, response_headers, NULL, NULL); heap_free(response_headers); if (hres != S_OK) { WARN("IHttpNegotiate_OnResponse failed: %08x\n", hres); return S_OK; } } }else { WARN("HttpQueryInfo failed: %d\n", GetLastError()); } ranges = query_http_info(This, HTTP_QUERY_ACCEPT_RANGES); if(ranges) { IInternetProtocolSink_ReportProgress(This->base.protocol_sink, BINDSTATUS_ACCEPTRANGES, NULL); heap_free(ranges); } content_type = query_http_info(This, HTTP_QUERY_CONTENT_TYPE); if(content_type) { /* remove the charset, if present */ LPWSTR p = strchrW(content_type, ';'); if (p) *p = '\0'; IInternetProtocolSink_ReportProgress(This->base.protocol_sink, (This->base.bindf & BINDF_FROMURLMON) ? BINDSTATUS_MIMETYPEAVAILABLE : BINDSTATUS_RAWMIMETYPE, content_type); heap_free(content_type); }else { WARN("HttpQueryInfo failed: %d\n", GetLastError()); IInternetProtocolSink_ReportProgress(This->base.protocol_sink, (This->base.bindf & BINDF_FROMURLMON) ? BINDSTATUS_MIMETYPEAVAILABLE : BINDSTATUS_RAWMIMETYPE, wszDefaultContentType); } content_length = query_http_info(This, HTTP_QUERY_CONTENT_LENGTH); if(content_length) { This->base.content_length = atoiW(content_length); heap_free(content_length); } return S_OK; }