Use Boost for parse_openssl_asn1_time_print()
This commit is contained in:
parent
cfb98391e5
commit
64f0372de5
19
src/util.cc
19
src/util.cc
|
@ -409,15 +409,18 @@ namespace bt = boost::posix_time;
|
||||||
// one-time definition of the locale that is used to parse UTC strings
|
// one-time definition of the locale that is used to parse UTC strings
|
||||||
// (note that the time_input_facet is ref-counted and deleted automatically)
|
// (note that the time_input_facet is ref-counted and deleted automatically)
|
||||||
static const std::locale
|
static const std::locale
|
||||||
ptime_locale(std::locale::classic(),
|
http_date_locale(std::locale::classic(),
|
||||||
new bt::time_input_facet("%a, %d %b %Y %H:%M:%S GMT"));
|
new bt::time_input_facet("%a, %d %b %Y %H:%M:%S GMT"));
|
||||||
|
static const std::locale
|
||||||
|
openssl_asn1_locale(std::locale::classic(),
|
||||||
|
new bt::time_input_facet("%b %d %H:%M:%S %Y GMT"));
|
||||||
#endif //_WIN32
|
#endif //_WIN32
|
||||||
|
|
||||||
time_t parse_http_date(const StringRef &s) {
|
time_t parse_http_date(const StringRef &s) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
// there is no strptime - use boost
|
// there is no strptime - use boost
|
||||||
std::stringstream sstr(s.str());
|
std::stringstream sstr(s.str());
|
||||||
sstr.imbue(ptime_locale);
|
sstr.imbue(http_date_locale);
|
||||||
bt::ptime ltime;
|
bt::ptime ltime;
|
||||||
sstr >> ltime;
|
sstr >> ltime;
|
||||||
if (!sstr)
|
if (!sstr)
|
||||||
|
@ -435,12 +438,24 @@ time_t parse_http_date(const StringRef &s) {
|
||||||
}
|
}
|
||||||
|
|
||||||
time_t parse_openssl_asn1_time_print(const StringRef &s) {
|
time_t parse_openssl_asn1_time_print(const StringRef &s) {
|
||||||
|
#ifdef _WIN32
|
||||||
|
// there is no strptime - use boost
|
||||||
|
std::stringstream sstr(s.str());
|
||||||
|
sstr.imbue(openssl_asn1_locale);
|
||||||
|
bt::ptime ltime;
|
||||||
|
sstr >> ltime;
|
||||||
|
if (!sstr)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return boost::posix_time::to_time_t(ltime);
|
||||||
|
#else // !_WIN32
|
||||||
tm tm{};
|
tm tm{};
|
||||||
auto r = strptime(s.c_str(), "%b %d %H:%M:%S %Y GMT", &tm);
|
auto r = strptime(s.c_str(), "%b %d %H:%M:%S %Y GMT", &tm);
|
||||||
if (r == nullptr) {
|
if (r == nullptr) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return nghttp2_timegm_without_yday(&tm);
|
return nghttp2_timegm_without_yday(&tm);
|
||||||
|
#endif // !_WIN32
|
||||||
}
|
}
|
||||||
|
|
||||||
char upcase(char c) {
|
char upcase(char c) {
|
||||||
|
|
Loading…
Reference in New Issue