]> prime8.dev >> repos - ttyd.git/commitdiff
cmake: check LWS_WITH_SSL
authorShuanglei Tao <tsl0922@gmail.com>
Sun, 26 Jul 2020 23:38:47 +0000 (07:38 +0800)
committerShuanglei Tao <tsl0922@gmail.com>
Sun, 26 Jul 2020 23:52:22 +0000 (07:52 +0800)
CMakeLists.txt
src/http.c
src/server.c

index f333a6e30335952228a79805becfa1fe9180ebc5..6b9e9147a4623f0f34f9fe0f7df85015715fb7ca 100644 (file)
@@ -50,7 +50,6 @@ if(JSON-C_FOUND)
     SET(JSON-C_LIBRARIES "${JSON-C_LIBRARY}")
 endif()
 
-find_package(OpenSSL REQUIRED)
 find_package(ZLIB REQUIRED)
 find_package(Libwebsockets 1.7.0 QUIET)
 
@@ -65,8 +64,25 @@ if(NOT Libwebsockets_FOUND) # for libwebsockets-dev on ubuntu 16.04
     endif()
 endif()
 
-set(INCLUDE_DIRS ${OPENSSL_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR} ${LIBWEBSOCKETS_INCLUDE_DIRS} ${JSON-C_INCLUDE_DIRS} ${LIBUV_INCLUDE_DIRS})
-set(LINK_LIBS ${OPENSSL_LIBRARIES} ${ZLIB_LIBRARIES} ${LIBWEBSOCKETS_LIBRARIES} ${JSON-C_LIBRARIES} ${LIBUV_LIBRARIES})
+set(INCLUDE_DIRS ${ZLIB_INCLUDE_DIR} ${LIBWEBSOCKETS_INCLUDE_DIRS} ${JSON-C_INCLUDE_DIRS} ${LIBUV_INCLUDE_DIRS})
+set(LINK_LIBS ${ZLIB_LIBRARIES} ${LIBWEBSOCKETS_LIBRARIES} ${JSON-C_LIBRARIES} ${LIBUV_LIBRARIES})
+
+set (CMAKE_REQUIRED_INCLUDES ${INCLUDE_DIRS})
+include(CheckCSourceCompiles)
+check_c_source_compiles("#include <lws_config.h>
+int main(void) {
+#if defined(LWS_OPENSSL_SUPPORT) || defined(LWS_WITH_TLS)
+    return 0;
+#else
+    return error;
+#endif
+}" LWS_SSL_ENABLED)
+
+if(LWS_SSL_ENABLED)
+    find_package(OpenSSL REQUIRED)
+    list(APPEND INCLUDE_DIRS ${OPENSSL_INCLUDE_DIR})
+    list(APPEND LINK_LIBS ${OPENSSL_LIBRARIES})
+endif()
 
 if(WIN32)
     list(APPEND LINK_LIBS shell32)
index 461df49e6a961bb871ec5afd7798532c98066bb9..7fcaf2e9617130069a34b1c6ed08ec003d2963fc 100644 (file)
@@ -1,5 +1,4 @@
 #include <libwebsockets.h>
-#include <openssl/ssl.h>
 #include <string.h>
 #include <zlib.h>
 
@@ -247,7 +246,7 @@ int callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user,
 
     case LWS_CALLBACK_HTTP_FILE_COMPLETION:
       goto try_to_reuse;
-
+#if defined(LWS_OPENSSL_SUPPORT) || defined(LWS_WITH_TLS)
     case LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION:
       if (!len || (SSL_get_verify_result((SSL *)in) != X509_V_OK)) {
         int err = X509_STORE_CTX_get_error((X509_STORE_CTX *)user);
@@ -257,6 +256,7 @@ int callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user,
         return 1;
       }
       break;
+#endif
     default:
       break;
   }
index ffd73859ef70877339a7f771922c330017c93610..9b747a011faa094f624c597c8b654c4ff6bc25c1 100644 (file)
@@ -98,10 +98,12 @@ static void print_help() {
 #ifdef LWS_WITH_IPV6
           "    -6, --ipv6              Enable IPv6 support\n"
 #endif
+#if defined(LWS_OPENSSL_SUPPORT) || defined(LWS_WITH_TLS)
           "    -S, --ssl               Enable SSL\n"
           "    -C, --ssl-cert          SSL certificate file path\n"
           "    -K, --ssl-key           SSL key file path\n"
           "    -A, --ssl-ca            SSL CA file path for client certificate verification\n"
+#endif
           "    -d, --debug             Set log level (default: 7)\n"
           "    -v, --version           Print the version and exit\n"
           "    -h, --help              Print this text and exit\n\n"
@@ -381,6 +383,7 @@ int main(int argc, char **argv) {
       case '6':
         info.options &= ~(LWS_SERVER_OPTION_DISABLE_IPV6);
         break;
+#if defined(LWS_OPENSSL_SUPPORT) || defined(LWS_WITH_TLS)
       case 'S':
         ssl = true;
         break;
@@ -396,6 +399,7 @@ int main(int argc, char **argv) {
         strncpy(ca_path, optarg, sizeof(ca_path) - 1);
         ca_path[sizeof(ca_path) - 1] = '\0';
         break;
+#endif
       case 'T':
         strncpy(server->terminal_type, optarg,
                 sizeof(server->terminal_type) - 1);
@@ -468,6 +472,7 @@ int main(int argc, char **argv) {
     }
   }
 
+#if defined(LWS_OPENSSL_SUPPORT) || defined(LWS_WITH_TLS)
   if (ssl) {
     info.ssl_cert_filepath = cert_path;
     info.ssl_private_key_filepath = key_path;
@@ -478,6 +483,7 @@ int main(int argc, char **argv) {
     info.options |= LWS_SERVER_OPTION_REDIRECT_HTTP_TO_HTTPS;
 #endif
   }
+#endif
 
   lwsl_notice("ttyd %s (libwebsockets %s)\n", TTYD_VERSION,
               LWS_LIBRARY_VERSION);