| 581 | } |
| 582 | |
| 583 | static std::variant<HINTERNET, FtpWebOperationError> open_url(HINTERNET win_inet_handle, const std::wstring &url, const FtpOperationParams ¶ms) { |
| 584 | const auto url_handle = |
| 585 | InternetOpenUrl(win_inet_handle, url.c_str(), nullptr, 0, INTERNET_FLAG_PASSIVE | INTERNET_FLAG_RELOAD | INTERNET_FLAG_PRAGMA_NOCACHE, 0); |
| 586 | if (url_handle == nullptr) |
| 587 | return FtpWebOperationError{FtpWebOperationErrorType::url_cannot_be_opened, -1}; |
| 588 | |
| 589 | if (!params.anonymous) { |
| 590 | InternetSetOption(url_handle, INTERNET_OPTION_PROXY_USERNAME, const_cast<wchar_t *>(params.proxy_username.c_str()), |
| 591 | static_cast<DWORD>(params.proxy_username.length() + 1)); |
| 592 | InternetSetOption(url_handle, INTERNET_OPTION_PROXY_PASSWORD, const_cast<wchar_t *>(params.proxy_password.c_str()), |
| 593 | static_cast<DWORD>(params.proxy_password.length() + 1)); |
| 594 | InternetSetOption(url_handle, INTERNET_OPTION_PROXY_SETTINGS_CHANGED, nullptr, 0); |
| 595 | } |
| 596 | HttpSendRequest(url_handle, nullptr, 0, nullptr, 0); |
| 597 | |
| 598 | DWORD code = 0; |
| 599 | DWORD dummy = 0; |
| 600 | DWORD size = sizeof(DWORD); |
| 601 | |
| 602 | if (!HttpQueryInfo(url_handle, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &code, &size, &dummy)) |
| 603 | return FtpWebOperationError{FtpWebOperationErrorType::querying_status_code_failed, -1}; |
| 604 | |
| 605 | if (code != HTTP_STATUS_OK) { |
| 606 | if (code == HTTP_STATUS_PROXY_AUTH_REQ) |
| 607 | return FtpWebOperationError{FtpWebOperationErrorType::proxy_authorization_required, static_cast<int>(code)}; |
| 608 | |
| 609 | return FtpWebOperationError{FtpWebOperationErrorType::http_error, static_cast<int>(code)}; |
| 610 | } |
| 611 | return url_handle; |
| 612 | } |
| 613 | |
| 614 | static std::variant<HINTERNET, FtpWebOperationError> ftp_web_proxy_login(const FtpOperationParams ¶ms) { |
| 615 | std::wstring proxy_final_string = params.proxy_address + L":" + std::to_wstring(params.proxy_port); |
no test coverage detected