@@ -3678,7 +3678,7 @@ SKIF_Util_GetHotKeyStateSVCTemp (void)
36783678
36793679DWORD
36803680WINAPI
3681- SKIF_Util_GetWebUri (skif_get_web_uri_t * get)
3681+ SKIF_Util_GetWebUri (skif_get_web_uri_t * get, std::string* response_body )
36823682{
36833683 static SKIF_RegistrySettings& _registry = SKIF_RegistrySettings::GetInstance ( );
36843684
@@ -3715,15 +3715,16 @@ SKIF_Util_GetWebUri (skif_get_web_uri_t* get)
37153715 return 0 ;
37163716 };
37173717
3718- PLOG_VERBOSE << " Method : " << std::wstring (get->method );
3719- PLOG_VERBOSE << " Target : " << ((get->https ) ? " https://" : " http://" ) << get->wszHostName << get->wszHostPath ;
3720- PLOG_VERBOSE_IF (get->wszExtraInfo [0 ] != L' \0 ' ) << " Fragment: " << get->wszExtraInfo ;
3721- PLOG_VERBOSE_IF (! get->header .empty ()) << " Header : " << get->header ;
3722- PLOG_VERBOSE_IF (! get->body .empty ()) << " Body : " << get->body ;
3718+ PLOG_VERBOSE << " Method: " << std::wstring (get->method );
3719+ PLOG_VERBOSE << " Target: " << ((get->https ) ? " https://" : " http://" ) << get->wszHostName << get->wszHostPath ;
3720+ PLOG_VERBOSE_IF ( get->wszExtraInfo [0 ] != L' \0 ' ) << " Query: " << get->wszExtraInfo ;
3721+ PLOG_VERBOSE << " U-A: " << get->user_agent ;
3722+ PLOG_VERBOSE_IF (! get->header .empty ()) << " Header: " << get->header ;
3723+ PLOG_VERBOSE_IF (! get->body .empty ()) << " Body: " << get->body ;
37233724
37243725 hInetRoot =
37253726 InternetOpen (
3726- L" Special K - Asset Crawler " ,
3727+ get-> user_agent . c_str () ,
37273728 INTERNET_OPEN_TYPE_DIRECT ,
37283729 nullptr , nullptr ,
37293730 0x00 );
@@ -3842,19 +3843,35 @@ SKIF_Util_GetWebUri (skif_get_web_uri_t* get)
38423843 break ;
38433844 }
38443845
3845- FILE *fOut = nullptr ;
3846-
3847- _wfopen_s (&fOut , get->wszLocalPath , L" wb+" );
3848-
3849- if (fOut != nullptr )
3846+ if (response_body != nullptr )
38503847 {
3851- fwrite (concat_buffer. data (), concat_buffer. size (), 1 , fOut );
3852- fflush ( fOut );
3853- fclose ( fOut );
3848+ response_body-> clear ( );
3849+ response_body-> append (concat_buffer. data (), concat_buffer. size () );
3850+ }
38543851
3852+ if (get->wszLocalPath [0 ] == ' \0 ' )
3853+ {
38553854 CLEANUP (true );
38563855 return 1 ;
38573856 }
3857+
3858+ // Write to file...
3859+ else
3860+ {
3861+ FILE *fOut = nullptr ;
3862+
3863+ _wfopen_s (&fOut , get->wszLocalPath , L" wb+" );
3864+
3865+ if (fOut != nullptr )
3866+ {
3867+ fwrite (concat_buffer.data (), concat_buffer.size (), 1 , fOut );
3868+ fflush (fOut );
3869+ fclose (fOut );
3870+
3871+ CLEANUP (true );
3872+ return 1 ;
3873+ }
3874+ }
38583875 }
38593876
38603877 else { // dwStatusCode != 200
@@ -3866,20 +3883,20 @@ SKIF_Util_GetWebUri (skif_get_web_uri_t* get)
38663883}
38673884
38683885DWORD
3869- SKIF_Util_GetWebResource (std::wstring url, std::wstring_view destination , std::wstring method, std::wstring header, std::string body)
3886+ SKIF_Util_GetWebResource (std::wstring url, std::wstring_view file_path , std::wstring method, std::wstring header, std::string body, std::wstring user_agent, std::string* response_body )
38703887{
38713888 auto * get =
38723889 new skif_get_web_uri_t { };
38733890
38743891 URL_COMPONENTSW urlcomps = { };
38753892
3876- urlcomps.dwStructSize = sizeof (URL_COMPONENTSW );
3893+ urlcomps.dwStructSize = sizeof (URL_COMPONENTSW );
38773894
3878- urlcomps.lpszHostName = get->wszHostName ;
3879- urlcomps.dwHostNameLength = INTERNET_MAX_HOST_NAME_LENGTH ;
3895+ urlcomps.lpszHostName = get->wszHostName ;
3896+ urlcomps.dwHostNameLength = INTERNET_MAX_HOST_NAME_LENGTH ;
38803897
3881- urlcomps.lpszUrlPath = get->wszHostPath ;
3882- urlcomps.dwUrlPathLength = INTERNET_MAX_PATH_LENGTH ;
3898+ urlcomps.lpszUrlPath = get->wszHostPath ;
3899+ urlcomps.dwUrlPathLength = INTERNET_MAX_PATH_LENGTH ;
38833900
38843901 urlcomps.lpszExtraInfo = get->wszExtraInfo ;
38853902 urlcomps.dwExtraInfoLength = INTERNET_MAX_PATH_LENGTH ;
@@ -3893,15 +3910,15 @@ SKIF_Util_GetWebResource (std::wstring url, std::wstring_view destination, std::
38933910 if (! body.empty ())
38943911 get->body = body;
38953912
3913+ if (! user_agent.empty ())
3914+ get->user_agent = user_agent;
3915+
38963916 if (InternetCrackUrl (url.c_str (), static_cast <DWORD > (url.length ()), 0x00 , &urlcomps))
38973917 {
3898- wcsncpy ( get->wszLocalPath ,
3899- destination.data (),
3900- MAX_PATH );
3901-
3918+ wcsncpy (get->wszLocalPath , file_path.data (), MAX_PATH );
39023919 get->https = (urlcomps.nScheme == INTERNET_SCHEME_HTTPS );
39033920
3904- return SKIF_Util_GetWebUri (get);
3921+ return SKIF_Util_GetWebUri (get, response_body );
39053922 }
39063923
39073924 else {
0 commit comments