瀏覽代碼

Add API function to check available features

bel 10 年之前
父節點
當前提交
721f694c24
共有 2 個文件被更改,包括 63 次插入0 次删除
  1. 18 0
      include/civetweb.h
  2. 45 0
      src/civetweb.c

+ 18 - 0
include/civetweb.h

@@ -725,6 +725,24 @@ CIVETWEB_API int mg_get_response(struct mg_connection *conn,
                                  size_t ebuf_len,
                                  size_t ebuf_len,
                                  int timeout);
                                  int timeout);
 
 
+
+/* Check which features where set when civetweb has been compiled.
+   Parameters:
+     feature: specifies which feature should be checked
+         1  serve files (NO_FILES not set)
+         2  support HTTPS (NO_SSL not set)
+         4  support CGI (NO_CGI not set)
+         8  support IPv6 (USE_IPV6 set)
+        16  support WebSocket (USE_WEBSOCKET set)
+        32  support Lua scripts and Lua server pages (USE_LUA is set)
+
+   Return:
+     If feature is available > 0
+     If feature is not available = 0
+*/
+CIVETWEB_API unsigned mg_check_feature(unsigned feature);
+
+
 #ifdef __cplusplus
 #ifdef __cplusplus
 }
 }
 #endif /* __cplusplus */
 #endif /* __cplusplus */

+ 45 - 0
src/civetweb.c

@@ -10728,3 +10728,48 @@ struct mg_context *mg_start(const struct mg_callbacks *callbacks,
 
 
 	return ctx;
 	return ctx;
 }
 }
+
+
+/* Feature check API function */
+unsigned mg_check_feature(unsigned feature)
+{
+	static const unsigned feature_set = 0
+/* Set bits for available features according to API documentation. */
+#if !defined(NO_FILES)
+	                                    | 1
+#endif
+#if !defined(NO_SSL)
+	                                    | 2
+#endif
+#if !defined(NO_CGI)
+	                                    | 4
+#endif
+#if defined(USE_IPV6)
+	                                    | 8
+#endif
+#if defined(USE_WEBSOCKET)
+	                                    | 16
+#endif
+#if defined(USE_LUA)
+	                                    | 32
+#endif
+/* Set some extra bits not defined in the API documentation.
+ * These bits may change without further notice. */
+#if !defined(NO_POPEN)
+	                                    | 64
+#endif
+#if defined(MG_LEGACY_INTERFACE)
+	                                    | 128
+#endif
+#if defined(MEMORY_DEBUGGING)
+	                                    | 256
+#endif
+#if defined(USE_TIMERS)
+	                                    | 512
+#endif
+#if !defined(NO_NONCE_CHECK)
+	                                    | 1024
+#endif
+	    ;
+	return (feature & feature_set);
+}