From b128ccccca1d359637a99b2e5a6b342cfcbd63aa Mon Sep 17 00:00:00 2001 From: Andy Green Date: Sat, 16 Aug 2014 09:54:27 +0800 Subject: [PATCH] add lws_is_ssl api Suggested by Michael Harbler on the mailing list Signed-off-by: Andy Green --- changelog | 5 +++++ lib/libwebsockets.c | 14 ++++++++++++++ lib/libwebsockets.h | 3 +++ 3 files changed, 22 insertions(+) diff --git a/changelog b/changelog index 1652fe8..8e59225 100644 --- a/changelog +++ b/changelog @@ -16,6 +16,11 @@ be used by the user code to mark the selected protocol by user-defined version or capabliity flag information, for the case multiple versions of a protocol are supported. +int lws_is_ssl(wsi) added to allow user code to know if the connection was made +over ssl or not. If LWS_SERVER_OPTION_ALLOW_NON_SSL_ON_SSL_PORT is used, both +ssl and non-ssl connections are possible and may need to be treated differently +in the user code. + v1.3-chrome37-firefox30 ======================= diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index ee88e2e..a5ec698 100644 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -755,3 +755,17 @@ LWS_VISIBLE void lws_set_log_level(int level, void (*log_emit_function)(int leve if (log_emit_function) lwsl_emit = log_emit_function; } + +/** + * lws_use_ssl() - Find out if connection is using SSL + * @wsi: websocket connection to check + * + * Returns 0 if the connection is not using SSL, 1 if using SSL and + * using verified cert, and 2 if using SSL but the cert was not + * checked (appears for client wsi told to skip check on connection) + */ +LWS_VISIBLE int +lws_is_ssl(struct libwebsocket *wsi) +{ + return wsi->use_ssl; +} diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h index e6cc2a0..3cd5b59 100644 --- a/lib/libwebsockets.h +++ b/lib/libwebsockets.h @@ -1181,6 +1181,9 @@ lws_send_pipe_choked(struct libwebsocket *wsi); LWS_VISIBLE LWS_EXTERN int lws_frame_is_binary(struct libwebsocket *wsi); +LWS_VISIBLE LWS_EXTERN int +lws_is_ssl(struct libwebsocket *wsi); + LWS_VISIBLE LWS_EXTERN unsigned char * libwebsockets_SHA1(const unsigned char *d, size_t n, unsigned char *md); -- 2.7.4