Added path_to_plain_ascii for use by driver-ssl

This commit is contained in:
2023-01-23 16:24:40 -05:00
parent fb48329090
commit 470d8a3c78
3 changed files with 37 additions and 8 deletions

View File

@@ -8,13 +8,13 @@
#include "driver-util.hpp"
#include "driver-ssl.hpp"
#include "drivenengine.hpp"
#include "util.hpp"
#include "source.hpp"
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <filesystem>
#include <winsock2.h>
#include <ws2tcpip.h>
@@ -29,6 +29,20 @@
#include <openssl/bio.h>
#include <openssl/pem.h>
// OpenSSL requires plain ascii pathnames. Returns empty string
// if the path cannot be converted to plain ascii.
std::string path_to_plain_ascii(const std::filesystem::path &path) {
std::wstring s = path.native();
for (wchar_t c : s) {
if ((c < 1) || (c > 127)) return "";
}
std::ostringstream oss;
for (wchar_t c : s) {
oss << ((char)c);
}
return oss.str();
}
static void set_nonblocking(SOCKET sock) {
u_long mode = 1; // 1 to enable non-blocking socket
int status = ioctlsocket(sock, FIONBIO, &mode);