mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-09 00:00:04 +01:00
use ctime_r instead of ctime if possible
This commit is contained in:
parent
932527a3e7
commit
b5ed38395e
5 changed files with 45 additions and 7 deletions
|
@ -552,6 +552,7 @@ CHECK_FUNCTION_EXISTS(_atoi64 LWS_HAVE__ATOI64)
|
|||
CHECK_FUNCTION_EXISTS(_stat32i64 LWS_HAVE__STAT32I64)
|
||||
CHECK_FUNCTION_EXISTS(clock_gettime LWS_HAVE_CLOCK_GETTIME)
|
||||
CHECK_FUNCTION_EXISTS(localtime_r LWS_HAVE_LOCALTIME_R)
|
||||
CHECK_FUNCTION_EXISTS(ctime_r LWS_HAVE_CTIME_R)
|
||||
CHECK_FUNCTION_EXISTS(getgrgid_r LWS_HAVE_GETGRGID_R)
|
||||
CHECK_FUNCTION_EXISTS(getgrnam_r LWS_HAVE_GETGRNAM_R)
|
||||
CHECK_FUNCTION_EXISTS(getpwuid_r LWS_HAVE_GETPWUID_R)
|
||||
|
|
|
@ -51,6 +51,7 @@
|
|||
#cmakedefine LWS_HAVE_EVP_PKEY_new_raw_private_key
|
||||
#cmakedefine LWS_HAVE_EXECVPE
|
||||
#cmakedefine LWS_HAVE_LOCALTIME_R
|
||||
#cmakedefine LWS_HAVE_CTIME_R
|
||||
#cmakedefine LWS_HAVE_GETGRGID_R
|
||||
#cmakedefine LWS_HAVE_GETGRNAM_R
|
||||
#cmakedefine LWS_HAVE_GETPWUID_R
|
||||
|
|
|
@ -26,6 +26,9 @@ callback_http(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
uint8_t buf[1280];
|
||||
union lws_tls_cert_info_results *ci =
|
||||
(union lws_tls_cert_info_results *)buf;
|
||||
#if defined(LWS_HAVE_CTIME_R)
|
||||
char date[32];
|
||||
#endif
|
||||
|
||||
switch (reason) {
|
||||
|
||||
|
@ -50,11 +53,22 @@ callback_http(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
|
||||
if (!lws_tls_peer_cert_info(wsi, LWS_TLS_CERT_INFO_VALIDITY_FROM,
|
||||
ci, 0))
|
||||
lwsl_notice(" Peer Cert Valid from: %s", ctime(&ci->time));
|
||||
|
||||
#if defined(LWS_HAVE_CTIME_R)
|
||||
lwsl_notice(" Peer Cert Valid from: %s",
|
||||
ctime_r(&ci->time, date));
|
||||
#else
|
||||
lwsl_notice(" Peer Cert Valid from: %s",
|
||||
ctime(&ci->time));
|
||||
#endif
|
||||
if (!lws_tls_peer_cert_info(wsi, LWS_TLS_CERT_INFO_VALIDITY_TO,
|
||||
ci, 0))
|
||||
lwsl_notice(" Peer Cert Valid to : %s", ctime(&ci->time));
|
||||
#if defined(LWS_HAVE_CTIME_R)
|
||||
lwsl_notice(" Peer Cert Valid to : %s",
|
||||
ctime_r(&ci->time, date));
|
||||
#else
|
||||
lwsl_notice(" Peer Cert Valid to : %s",
|
||||
ctime(&ci->time));
|
||||
#endif
|
||||
if (!lws_tls_peer_cert_info(wsi, LWS_TLS_CERT_INFO_USAGE,
|
||||
ci, 0))
|
||||
lwsl_notice(" Peer Cert usage bits: 0x%x\n", ci->usage);
|
||||
|
|
|
@ -45,6 +45,9 @@ callback_dynamic_http(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
*end = &buf[sizeof(buf) - LWS_PRE - 1];
|
||||
time_t t;
|
||||
int n;
|
||||
#if defined(LWS_HAVE_CTIME_R)
|
||||
char date[32];
|
||||
#endif
|
||||
|
||||
switch (reason) {
|
||||
case LWS_CALLBACK_HTTP:
|
||||
|
@ -152,7 +155,12 @@ callback_dynamic_http(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
"<img src=\"/libwebsockets.org-logo.svg\">"
|
||||
"<br>Dynamic content for '%s' from mountpoint."
|
||||
"<br>Time: %s<br><br>"
|
||||
"</body></html>", pss->path, ctime(&t));
|
||||
"</body></html>", pss->path,
|
||||
#if defined(LWS_HAVE_CTIME_R)
|
||||
ctime_r(&t, date));
|
||||
#else
|
||||
ctime(&t));
|
||||
#endif
|
||||
} else {
|
||||
/*
|
||||
* after the first time, we create bulk content.
|
||||
|
|
|
@ -120,6 +120,9 @@ callback_dumb_increment(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
{
|
||||
#if defined(LWS_WITH_TLS)
|
||||
union lws_tls_cert_info_results ci;
|
||||
#if defined(LWS_HAVE_CTIME_R) && !defined(LWS_WITH_NO_LOGS)
|
||||
char date[32];
|
||||
#endif
|
||||
#endif
|
||||
const char *which = "http";
|
||||
char which_wsi[10], buf[50 + LWS_PRE];
|
||||
|
@ -190,11 +193,22 @@ callback_dumb_increment(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
|
||||
if (!lws_tls_peer_cert_info(wsi, LWS_TLS_CERT_INFO_VALIDITY_FROM,
|
||||
&ci, 0))
|
||||
lwsl_notice(" Peer Cert Valid from: %s", ctime(&ci.time));
|
||||
|
||||
#if defined(LWS_HAVE_CTIME_R)
|
||||
lwsl_notice(" Peer Cert Valid from: %s",
|
||||
ctime_r(&ci.time, date));
|
||||
#else
|
||||
lwsl_notice(" Peer Cert Valid from: %s",
|
||||
ctime(&ci.time));
|
||||
#endif
|
||||
if (!lws_tls_peer_cert_info(wsi, LWS_TLS_CERT_INFO_VALIDITY_TO,
|
||||
&ci, 0))
|
||||
lwsl_notice(" Peer Cert Valid to : %s", ctime(&ci.time));
|
||||
#if defined(LWS_HAVE_CTIME_R)
|
||||
lwsl_notice(" Peer Cert Valid to : %s",
|
||||
ctime_r(&ci.time, date));
|
||||
#else
|
||||
lwsl_notice(" Peer Cert Valid to : %s",
|
||||
ctime(&ci.time));
|
||||
#endif
|
||||
if (!lws_tls_peer_cert_info(wsi, LWS_TLS_CERT_INFO_USAGE,
|
||||
&ci, 0))
|
||||
lwsl_notice(" Peer Cert usage bits: 0x%x\n", ci.usage);
|
||||
|
|
Loading…
Add table
Reference in a new issue