Browse Source

- Fixed Travis CI build error
- Renamed callback get_external_ssl_ctx to external_ssl_ctx
- Provide ctx->ssl_ctx to external_ssl_ctx() call in free_context() in order to indicate the "free" context.

Frank Hilliger 7 năm trước cách đây
mục cha
commit
4601405f7a
2 tập tin đã thay đổi với 11 bổ sung20 xóa
  1. 3 3
      include/civetweb.h
  2. 8 17
      src/civetweb.c

+ 3 - 3
include/civetweb.h

@@ -254,16 +254,16 @@ struct mg_callbacks {
 	    -1: initializing ssl fails. */
 	int (*init_ssl)(void *ssl_context, void *user_data);
 
-	/* Called when civetweb is about to create a SSL_CTX.
+	/* Called when civetweb is about to create or free a SSL_CTX.
 	Parameters:
-	   ssl_ctx: SSL_CTX pointer 
+	   ssl_ctx: SSL_CTX pointer. NULL at creation time, Not NULL when mg_context will be freed
 	     user_data: parameter user_data passed when starting the server.
 	   Return value:
 	     0: civetweb will continue to create the context, just as if the callback would not be present. 
 	        The value in *ssl_ctx when the function returns is ignored.
 	     1: civetweb will copy the value from *ssl_ctx to the civetweb context and doesn't create its own.
 	    -1: initializing ssl fails.*/
-	int (*get_external_ssl_ctx)( void **ssl_ctx, void *user_data );	
+	int (*external_ssl_ctx)( void **ssl_ctx, void *user_data );	
 
 #if defined(MG_LEGACY_INTERFACE)
 	/* Called when websocket request is received, before websocket handshake.

+ 8 - 17
src/civetweb.c

@@ -14346,31 +14346,22 @@ set_ssl_option(struct mg_context *ctx)
 	}
 
 	/* Check for external SSL_CTX */
-	SSL_CTX* ssl_ctx = 0;
+	void* ssl_ctx = 0;
 	callback_ret =
-	    (ctx->callbacks.get_external_ssl_ctx == NULL)
+	    (ctx->callbacks.external_ssl_ctx == NULL)
 	        ? 0
-	        : (ctx->callbacks.get_external_ssl_ctx(&ssl_ctx, ctx->user_data));
+	        : (ctx->callbacks.external_ssl_ctx(&ssl_ctx, ctx->user_data));
 
 	if (callback_ret < 0) {
-		mg_cry(fc(ctx), "get_external_ssl_ctx callback returned error: %i", callback_ret);
+		mg_cry(fc(ctx), "external_ssl_ctx callback returned error: %i", callback_ret);
 		return 0;
 	}
 	else if (callback_ret > 0) {
-		ctx->ssl_ctx = ssl_ctx;
+		ctx->ssl_ctx = (SSL_CTX*) ssl_ctx;
 		if (!initialize_ssl(ebuf, sizeof(ebuf))) {
 	 	   mg_cry(fc(ctx), "%s", ebuf);
 		   return 0;
 	    }
-#if !defined(NO_SSL_DL)
-		if (!ssllib_dll_handle) {
-			ssllib_dll_handle = load_dll(ebuf, sizeof(ebuf), SSL_LIB, ssl_sw);
-			if (!ssllib_dll_handle) {
-				mg_cry(fc(ctx), "%s", ebuf);
-				return 0;
-			}
-		}
-#endif /* NO_SSL_DL */
 		return 1;
 	}
 	/* else continue */	
@@ -16692,11 +16683,11 @@ free_context(struct mg_context *ctx)
 #ifndef NO_SSL
 	/* Deallocate SSL context */
 	if (ctx->ssl_ctx != NULL) {
-	  SSL_CTX* ssl_ctx = 0;
+	  void* ssl_ctx = (void*) ctx->ssl_ctx;
       int callback_ret =
-	    (ctx->callbacks.get_external_ssl_ctx == NULL)
+	    (ctx->callbacks.external_ssl_ctx == NULL)
 	        ? 0
-	        : (ctx->callbacks.get_external_ssl_ctx(&ssl_ctx, ctx->user_data));
+	        : (ctx->callbacks.external_ssl_ctx(&ssl_ctx, ctx->user_data));
 
 	  if (callback_ret == 0) {
 		SSL_CTX_free(ctx->ssl_ctx);