diff --git a/src/misc.h b/src/misc.h index 4ef917a..8e4c674 100644 --- a/src/misc.h +++ b/src/misc.h @@ -8,8 +8,11 @@ #include #ifdef _WIN32 +#include #define PATH_SLASH "\\" #else +#include +#include #define PATH_SLASH "//" #endif // _WIN32 @@ -18,9 +21,9 @@ typedef std::vector string_array; typedef const std::string &refCnstStr; static const std::string base64_chars = - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz" - "0123456789+/"; + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "0123456789+/"; std::string UrlEncode(const std::string& str); std::string UrlDecode(const std::string& str); @@ -70,11 +73,13 @@ static inline bool strFind(const std::string &str, const std::string &target) return str.find(target) != str.npos; } -static inline bool startsWith(const std::string &hay, const std::string &needle) { +static inline bool startsWith(const std::string &hay, const std::string &needle) +{ return hay.substr(0, needle.length()) == needle; } -static inline bool endsWith(const std::string &hay, const std::string &needle) { +static inline bool endsWith(const std::string &hay, const std::string &needle) +{ std::string::size_type hl = hay.length(), nl = needle.length(); return hl >= nl && hay.substr(hl - nl, nl) == needle; } @@ -108,15 +113,24 @@ int to_int(const std::string &str, int def_value = 0); #ifndef HAVE_TO_STRING namespace std { - template std::string to_string(const T& n) - { - std::ostringstream ss; - ss << n; - return ss.str(); - } +template std::string to_string(const T& n) +{ + std::ostringstream ss; + ss << n; + return ss.str(); +} } #endif // HAVE_TO_STRING +static inline int md(const char *path) +{ +#ifdef _WIN32 + return mkdir(path); +#else + return mkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); +#endif // _WIN32 +} + #ifdef _WIN32 void StringToWstring(std::wstring& szDst, const std::string &str); #endif // _WIN32 diff --git a/src/subexport.cpp b/src/subexport.cpp index 954deaf..dd913c0 100644 --- a/src/subexport.cpp +++ b/src/subexport.cpp @@ -1796,7 +1796,7 @@ std::string netchToSSD(std::vector &nodes, std::string &group, std::st const time_t rawtime = to_int(expiry); char buffer[30]; struct tm *dt = localtime(&rawtime); - strftime(buffer, sizeof(buffer), "%F %R", dt); + strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M", dt); writer.Key("expiry"); writer.String(buffer); } diff --git a/src/webget.cpp b/src/webget.cpp index 3f116be..69494fa 100644 --- a/src/webget.cpp +++ b/src/webget.cpp @@ -9,6 +9,10 @@ #include "misc.h" #include "logger.h" +#ifdef _WIN32 +#define _stat stat +#endif // _WIN32 + extern bool print_debug_info; //std::string user_agent_str = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"; @@ -89,11 +93,11 @@ std::string webGet(std::string url, std::string proxy, std::string &response_hea // cache system if(cache_ttl > 0) { - mkdir("cache"); + md("cache"); std::string url_md5 = getMD5(url); std::string path = "cache/" + url_md5; - struct _stat result; - if(_stat(path.data(), &result) == 0) + struct stat result; + if(stat(path.data(), &result) == 0) { time_t mtime = result.st_mtime, now = time(NULL); if(difftime(now, mtime) <= cache_ttl)