win32: wide string fix for gzopen and close stream after YAML parse

Change-Id: I30a52d3a22c46b8ff2884f0459f16e74dd4af76b
This commit is contained in:
Andreas Traczyk
2019-09-04 19:25:33 -04:00
parent faa8cef700
commit 331a41050b
4 changed files with 23 additions and 3 deletions

View File

@ -227,7 +227,7 @@ compress(const std::string& str)
void
compressGzip(const std::string& str, const std::string& path)
{
auto fi = gzopen(path.c_str(), "wb");
auto fi = openGzip(path, "wb");
gzwrite(fi, str.data(), str.size());
gzclose(fi);
}
@ -236,7 +236,7 @@ std::vector<uint8_t>
decompressGzip(const std::string& path)
{
std::vector<uint8_t> out;
auto fi = gzopen(path.c_str(),"rb");
auto fi = openGzip(path, "rb");
gzrewind(fi);
while (not gzeof(fi)) {
std::array<uint8_t, 32768> outbuffer;
@ -294,4 +294,14 @@ decompress(const std::vector<uint8_t>& str)
return out;
}
gzFile
openGzip(const std::string& path, const char *mode)
{
#ifdef _WIN32
return gzopen_w(jami::to_wstring(path).c_str(), mode);
#else
return gzopen(path.c_str(), mode);
#endif
}
}} // namespace jami::archiver

View File

@ -26,6 +26,8 @@
#include <vector>
#include <map>
typedef struct gzFile_s *gzFile;
namespace jami {
/**
@ -74,6 +76,11 @@ void compressGzip(const std::string& str, const std::string& path);
*/
std::vector<uint8_t> decompressGzip(const std::string& path);
/**
* Open Gzip file (uses wide string version of gzopen on windows)
*/
gzFile openGzip(const std::string& path, const char *mode);
}
} // namespace jami

View File

@ -441,6 +441,7 @@ Manager::ManagerPimpl::parseConfiguration()
try {
std::ifstream file = fileutils::ifstream(path_);
YAML::Node parsedFile = YAML::Load(file);
file.close();
const int error_count = base_.loadAccountMap(parsedFile);
if (error_count > 0) {
@ -449,6 +450,7 @@ Manager::ManagerPimpl::parseConfiguration()
}
} catch (const YAML::BadFile &e) {
JAMI_WARN("Could not open configuration file");
result = false;
}
return result;
@ -2859,6 +2861,7 @@ Manager::loadAccountMap(const YAML::Node& node)
if (auto a = accountFactory.createAccount(JamiAccount::ACCOUNT_TYPE, dir)) {
std::ifstream file = fileutils::ifstream(configFile);
YAML::Node parsedConfig = YAML::Load(file);
file.close();
a->unserialize(parsedConfig);
}
} catch (const std::exception& e) {

View File

@ -42,7 +42,7 @@ std::string to_string(double value);
#ifdef _WIN32
std::wstring to_wstring(const std::string& str, int codePage = CP_UTF8);
std::string to_string(const std::wstring& wstr, int codePage = CP_ACP);
std::string to_string(const std::wstring& wstr, int codePage = CP_UTF8);
std::string bstrToStdString(BSTR bstr);
#endif