mirror of
https://github.com/LizardByte/Sunshine.git
synced 2025-02-21 18:39:59 +00:00
centralize reading/writing file
This commit is contained in:
parent
9d52174d6b
commit
cf77b301bc
@ -316,7 +316,7 @@ void saveConfig(resp_https_t response, req_https_t request) {
|
||||
|
||||
configStream << kv.first << " = " << value << std::endl;
|
||||
}
|
||||
http::write_file(SUNSHINE_ASSETS_DIR "/sunshine.conf", configStream.str());
|
||||
write_file(SUNSHINE_ASSETS_DIR "/sunshine.conf", configStream.str());
|
||||
}
|
||||
catch(std::exception &e) {
|
||||
BOOST_LOG(warning) << e.what();
|
||||
|
@ -33,8 +33,6 @@ namespace pt = boost::property_tree;
|
||||
int create_creds(const std::string &pkey, const std::string &cert);
|
||||
int generate_user_creds(const std::string &file);
|
||||
int reload_user_creds(const std::string &file);
|
||||
std::string read_file(const char *path);
|
||||
int write_file(const char *path, const std::string_view &contents);
|
||||
std::string unique_id;
|
||||
net::net_e origin_pin_allowed;
|
||||
|
||||
@ -156,30 +154,4 @@ int create_creds(const std::string &pkey, const std::string &cert) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
int write_file(const char *path, const std::string_view &contents) {
|
||||
std::ofstream out(path);
|
||||
|
||||
if(!out.is_open()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
out << contents;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string read_file(const char *path) {
|
||||
std::ifstream in(path);
|
||||
|
||||
std::string input;
|
||||
std::string base64_cert;
|
||||
|
||||
//FIXME: Being unable to read file could result in infinite loop
|
||||
while(!in.eof()) {
|
||||
std::getline(in, input);
|
||||
base64_cert += input + '\n';
|
||||
}
|
||||
|
||||
return base64_cert;
|
||||
}
|
||||
} // namespace http
|
@ -5,8 +5,6 @@ namespace http {
|
||||
|
||||
void init(std::shared_ptr<safe::signal_t> shutdown_event);
|
||||
int create_creds(const std::string &pkey, const std::string &cert);
|
||||
std::string read_file(const char *path);
|
||||
int write_file(const char *path, const std::string_view &contents);
|
||||
int reload_user_creds(const std::string &file);
|
||||
extern std::string unique_id;
|
||||
extern net::net_e origin_pin_allowed;
|
||||
|
@ -741,8 +741,8 @@ void start(std::shared_ptr<safe::signal_t> shutdown_event) {
|
||||
load_state();
|
||||
}
|
||||
|
||||
conf_intern.pkey = http::read_file(config::nvhttp.pkey.c_str());
|
||||
conf_intern.servercert = http::read_file(config::nvhttp.cert.c_str());
|
||||
conf_intern.pkey = read_file(config::nvhttp.pkey.c_str());
|
||||
conf_intern.servercert = read_file(config::nvhttp.cert.c_str());
|
||||
|
||||
auto ctx = std::make_shared<boost::asio::ssl::context>(boost::asio::ssl::context::tls);
|
||||
ctx->use_certificate_chain_file(config::nvhttp.cert);
|
||||
|
Loading…
x
Reference in New Issue
Block a user