Prechádzať zdrojové kódy

Add HTTPS support to embedded example

bel 9 rokov pred
rodič
commit
851a4cda6b
1 zmenil súbory, kde vykonal 20 pridanie a 1 odobranie
  1. 20 1
      examples/embedded_c/embedded_c.c

+ 20 - 1
examples/embedded_c/embedded_c.c

@@ -18,11 +18,19 @@
 
 
 
 
 #define DOCUMENT_ROOT "."
 #define DOCUMENT_ROOT "."
+#ifdef NO_SSL
 #ifdef USE_IPV6
 #ifdef USE_IPV6
 #define PORT "[::]:8888"
 #define PORT "[::]:8888"
 #else
 #else
 #define PORT "8888"
 #define PORT "8888"
 #endif
 #endif
+#else
+#ifdef USE_IPV6
+#define PORT "[::]:8888r,[::]:8843s"
+#else
+#define PORT "8888r,8843s"
+#endif
+#endif
 #define EXAMPLE_URI "/example"
 #define EXAMPLE_URI "/example"
 #define EXIT_URI "/exit"
 #define EXIT_URI "/exit"
 int exitNow = 0;
 int exitNow = 0;
@@ -320,6 +328,10 @@ main(int argc, char *argv[])
 	                         "websocket_timeout_ms",
 	                         "websocket_timeout_ms",
 	                         "3600000",
 	                         "3600000",
 #endif
 #endif
+#ifndef NO_SSL
+	                         "ssl_certificate",
+                             "../../resources/cert/server.pem",
+#endif
 	                         0};
 	                         0};
 	struct mg_callbacks callbacks;
 	struct mg_callbacks callbacks;
 	struct mg_context *ctx;
 	struct mg_context *ctx;
@@ -344,7 +356,14 @@ main(int argc, char *argv[])
 		err = 1;
 		err = 1;
 	}
 	}
 #endif
 #endif
-
+#ifndef NO_SSL
+	if (!mg_check_feature(2)) {
+		fprintf(stderr,
+		        "Error: Embedded example built with SSL support, "
+		        "but civetweb library build without.\n");
+		err = 1;
+	}
+#endif
 	if (err) {
 	if (err) {
 		fprintf(stderr, "Cannot start CivetWeb - inconsistent build.\n");
 		fprintf(stderr, "Cannot start CivetWeb - inconsistent build.\n");
 		return EXIT_FAILURE;
 		return EXIT_FAILURE;