@@ -54,17 +54,14 @@ namespace http {
54
54
config::nvhttp.pkey = (dir / (" pkey-" s + unique_id)).string ();
55
55
}
56
56
57
- if (!fs::exists (config::nvhttp.pkey ) || !fs::exists (config::nvhttp.cert )) {
58
- if (create_creds (config::nvhttp.pkey , config::nvhttp.cert )) {
59
- return -1 ;
60
- }
57
+ if ((!fs::exists (config::nvhttp.pkey ) || !fs::exists (config::nvhttp.cert )) &&
58
+ create_creds (config::nvhttp.pkey , config::nvhttp.cert )) {
59
+ return -1 ;
61
60
}
62
- if (user_creds_exist (config::sunshine.credentials_file )) {
63
- if (reload_user_creds (config::sunshine.credentials_file )) {
64
- return -1 ;
65
- }
66
- } else {
61
+ if (!user_creds_exist (config::sunshine.credentials_file )) {
67
62
BOOST_LOG (info) << " Open the Web UI to set your new username and password and getting started" ;
63
+ } else if (reload_user_creds (config::sunshine.credentials_file )) {
64
+ return -1 ;
68
65
}
69
66
return 0 ;
70
67
}
@@ -179,19 +176,15 @@ namespace http {
179
176
return 0 ;
180
177
}
181
178
182
- bool download_file (const std::string &url, const std::string &file) {
183
- CURL *curl = curl_easy_init ();
184
- if (curl) {
185
- // sonar complains about weak ssl and tls versions
186
- // ideally, the setopts should go after the early returns; however sonar cannot detect the fix
187
- curl_easy_setopt (curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
188
- } else {
179
+ bool download_file (const std::string &url, const std::string &file, long ssl_version) {
180
+ // sonar complains about weak ssl and tls versions; however sonar cannot detect the fix
181
+ CURL *curl = curl_easy_init (); // NOSONAR
182
+ if (!curl) {
189
183
BOOST_LOG (error) << " Couldn't create CURL instance" ;
190
184
return false ;
191
185
}
192
186
193
- std::string file_dir = file_handler::get_parent_directory (file);
194
- if (!file_handler::make_directory (file_dir)) {
187
+ if (std::string file_dir = file_handler::get_parent_directory (file); !file_handler::make_directory (file_dir)) {
195
188
BOOST_LOG (error) << " Couldn't create directory [" sv << file_dir << ' ]' ;
196
189
curl_easy_cleanup (curl);
197
190
return false ;
@@ -204,6 +197,7 @@ namespace http {
204
197
return false ;
205
198
}
206
199
200
+ curl_easy_setopt (curl, CURLOPT_SSLVERSION, ssl_version); // NOSONAR
207
201
curl_easy_setopt (curl, CURLOPT_URL, url.c_str ());
208
202
curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, fwrite);
209
203
curl_easy_setopt (curl, CURLOPT_WRITEDATA, fp);
@@ -219,17 +213,15 @@ namespace http {
219
213
}
220
214
221
215
std::string url_escape (const std::string &url) {
222
- CURL *curl = curl_easy_init ();
223
- char *string = curl_easy_escape (curl, url.c_str (), url.length ());
216
+ char *string = curl_easy_escape (nullptr , url.c_str (), static_cast <int >(url.length ()));
224
217
std::string result (string);
225
218
curl_free (string);
226
- curl_easy_cleanup (curl);
227
219
return result;
228
220
}
229
221
230
222
std::string url_get_host (const std::string &url) {
231
223
CURLU *curlu = curl_url ();
232
- curl_url_set (curlu, CURLUPART_URL, url.c_str (), url.length ());
224
+ curl_url_set (curlu, CURLUPART_URL, url.c_str (), static_cast < unsigned int >( url.length () ));
233
225
char *host;
234
226
if (curl_url_get (curlu, CURLUPART_HOST, &host, 0 ) != CURLUE_OK) {
235
227
curl_url_cleanup (curlu);
@@ -240,5 +232,4 @@ namespace http {
240
232
curl_url_cleanup (curlu);
241
233
return result;
242
234
}
243
-
244
235
} // namespace http
0 commit comments