Commit bafc30be authored by Deomid Ryabkov's avatar Deomid Ryabkov Committed by Cesanta Bot

Change from using #ifdef to #if for features tests

"#if FOO" still works with simple -DFOO, but gives more flexibility.
Specifically, if user expressed no preference (FOO is not defined),
we can apply reasonable defaults (this is the legitimate use of ifdef).

In short, from now on, please use

 #if MG_ENABLE_FOO

instead of

 #ifdef MG_ENABLE_FOO

Since we are all used to #ifdef, this change also adds a precommit check
to police this. Specifically, in *.h and *.c files that are Copyright Cesanta,
"ifdef" and "if defined()" are not allowed to be used with macros that contain
ENABLE or DISABLE, unless the like also contains "ifdef-ok".

Hence, if you are sure you want to use ifdef, use this:

 #ifdef MG_ENABLE_FOO /* ifdef-ok */

PUBLISHED_FROM=9be829448f53cff575d6cae8b9945fb12531c15a
parent 0a8f8392
...@@ -7,7 +7,7 @@ signature: | ...@@ -7,7 +7,7 @@ signature: |
void *user_data; /* Initial value for connection's user_data */ void *user_data; /* Initial value for connection's user_data */
unsigned int flags; /* Extra connection flags */ unsigned int flags; /* Extra connection flags */
const char **error_string; /* Placeholder for the error string */ const char **error_string; /* Placeholder for the error string */
#ifdef MG_ENABLE_SSL #if MG_ENABLE_SSL
/* SSL settings. */ /* SSL settings. */
const char *ssl_cert; /* Server certificate to present to clients */ const char *ssl_cert; /* Server certificate to present to clients */
const char *ssl_key; /* Private key corresponding to the certificate. const char *ssl_key; /* Private key corresponding to the certificate.
......
...@@ -7,7 +7,7 @@ signature: | ...@@ -7,7 +7,7 @@ signature: |
void *user_data; /* Initial value for connection's user_data */ void *user_data; /* Initial value for connection's user_data */
unsigned int flags; /* Extra connection flags */ unsigned int flags; /* Extra connection flags */
const char **error_string; /* Placeholder for the error string */ const char **error_string; /* Placeholder for the error string */
#ifdef MG_ENABLE_SSL #if MG_ENABLE_SSL
/* SSL settings. */ /* SSL settings. */
const char *ssl_cert; /* Client certificate to present to the server */ const char *ssl_cert; /* Client certificate to present to the server */
const char *ssl_key; /* Private key corresponding to the certificate. const char *ssl_key; /* Private key corresponding to the certificate.
......
...@@ -14,7 +14,7 @@ signature: | ...@@ -14,7 +14,7 @@ signature: |
size_t recv_mbuf_limit; /* Max size of recv buffer */ size_t recv_mbuf_limit; /* Max size of recv buffer */
struct mbuf recv_mbuf; /* Received data */ struct mbuf recv_mbuf; /* Received data */
struct mbuf send_mbuf; /* Data scheduled for sending */ struct mbuf send_mbuf; /* Data scheduled for sending */
#if defined(MG_ENABLE_SSL) #if MG_ENABLE_SSL
#if !defined(MG_SOCKET_SIMPLELINK) #if !defined(MG_SOCKET_SIMPLELINK)
SSL *ssl; SSL *ssl;
SSL_CTX *ssl_ctx; SSL_CTX *ssl_ctx;
......
...@@ -6,12 +6,12 @@ signature: | ...@@ -6,12 +6,12 @@ signature: |
struct mg_mgr { struct mg_mgr {
struct mg_connection *active_connections; struct mg_connection *active_connections;
const char *hexdump_file; /* Debug hexdump file path */ const char *hexdump_file; /* Debug hexdump file path */
#ifndef MG_DISABLE_SOCKETPAIR #if !MG_DISABLE_SOCKETPAIR
sock_t ctl[2]; /* Socketpair for mg_broadcast() */ sock_t ctl[2]; /* Socketpair for mg_broadcast() */
#endif #endif
void *user_data; /* User data */ void *user_data; /* User data */
void *mgr_data; /* Implementation-specific event manager's data. */ void *mgr_data; /* Implementation-specific event manager's data. */
#ifdef MG_ENABLE_JAVASCRIPT #if MG_ENABLE_JAVASCRIPT
struct v7 *v7; struct v7 *v7;
#endif #endif
}; };
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#ifndef CS_COMMON_CS_DBG_H_ #ifndef CS_COMMON_CS_DBG_H_
#define CS_COMMON_CS_DBG_H_ #define CS_COMMON_CS_DBG_H_
#ifndef CS_DISABLE_STDIO #if !CS_DISABLE_STDIO
#include <stdio.h> #include <stdio.h>
#endif #endif
...@@ -28,7 +28,7 @@ enum cs_log_level { ...@@ -28,7 +28,7 @@ enum cs_log_level {
void cs_log_set_level(enum cs_log_level level); void cs_log_set_level(enum cs_log_level level);
#ifndef CS_DISABLE_STDIO #if !CS_DISABLE_STDIO
void cs_log_set_file(FILE *file); void cs_log_set_file(FILE *file);
......
...@@ -27,7 +27,7 @@ endif # } PDIR ...@@ -27,7 +27,7 @@ endif # } PDIR
LDDIR = $(SDK_PATH)/ld LDDIR = $(SDK_PATH)/ld
CCFLAGS += -Os CCFLAGS += -Os -Wno-undef
TARGET_LDFLAGS = \ TARGET_LDFLAGS = \
-nostdlib \ -nostdlib \
......
...@@ -24,8 +24,8 @@ endif ...@@ -24,8 +24,8 @@ endif
# for a subtree within the makefile rooted therein # for a subtree within the makefile rooted therein
# #
DEFINES += -DCS_PLATFORM=3 \ DEFINES += -DCS_PLATFORM=3 \
-DMG_NO_BSD_SOCKETS \ -DMG_NO_BSD_SOCKETS=1 \
-DMG_DISABLE_FILESYSTEM \ -DMG_DISABLE_FILESYSTEM=1 \
-DRTOS_SDK -DMG_LWIP -DLWIP_TIMEVAL_PRIVATE=0 \ -DRTOS_SDK -DMG_LWIP -DLWIP_TIMEVAL_PRIVATE=0 \
-DMG_INTERNAL= -DMG_INTERNAL=
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#ifndef CS_COMMON_CS_DBG_H_ #ifndef CS_COMMON_CS_DBG_H_
#define CS_COMMON_CS_DBG_H_ #define CS_COMMON_CS_DBG_H_
#ifndef CS_DISABLE_STDIO #if !CS_DISABLE_STDIO
#include <stdio.h> #include <stdio.h>
#endif #endif
...@@ -28,7 +28,7 @@ enum cs_log_level { ...@@ -28,7 +28,7 @@ enum cs_log_level {
void cs_log_set_level(enum cs_log_level level); void cs_log_set_level(enum cs_log_level level);
#ifndef CS_DISABLE_STDIO #if !CS_DISABLE_STDIO
void cs_log_set_file(FILE *file); void cs_log_set_file(FILE *file);
......
...@@ -60,7 +60,7 @@ static int s_num_vhost_backends = 0, s_num_default_backends = 0; ...@@ -60,7 +60,7 @@ static int s_num_vhost_backends = 0, s_num_default_backends = 0;
static int s_sig_num = 0; static int s_sig_num = 0;
static int s_backend_keepalive = 0; static int s_backend_keepalive = 0;
static FILE *s_log_file = NULL; static FILE *s_log_file = NULL;
#ifdef MG_ENABLE_SSL #if MG_ENABLE_SSL
const char *s_ssl_cert = NULL; const char *s_ssl_cert = NULL;
#endif #endif
...@@ -206,7 +206,7 @@ static void forward(struct conn_data *conn, struct http_message *hm, ...@@ -206,7 +206,7 @@ static void forward(struct conn_data *conn, struct http_message *hm,
for (i = 0; i < MG_MAX_HTTP_HEADERS && hm->header_names[i].len > 0; i++) { for (i = 0; i < MG_MAX_HTTP_HEADERS && hm->header_names[i].len > 0; i++) {
struct mg_str hn = hm->header_names[i]; struct mg_str hn = hm->header_names[i];
struct mg_str hv = hm->header_values[i]; struct mg_str hv = hm->header_values[i];
#ifdef MG_ENABLE_SSL #if MG_ENABLE_SSL
/* /*
* If we terminate SSL and backend redirects to local HTTP port, * If we terminate SSL and backend redirects to local HTTP port,
* strip protocol to let client use HTTPS. * strip protocol to let client use HTTPS.
...@@ -598,7 +598,7 @@ int main(int argc, char *argv[]) { ...@@ -598,7 +598,7 @@ int main(int argc, char *argv[]) {
vhost = NULL; vhost = NULL;
redirect = 0; redirect = 0;
i += 2; i += 2;
#ifdef MG_ENABLE_SSL #if MG_ENABLE_SSL
} else if (strcmp(argv[i], "-s") == 0 && i + 1 < argc) { } else if (strcmp(argv[i], "-s") == 0 && i + 1 < argc) {
s_ssl_cert = argv[++i]; s_ssl_cert = argv[++i];
#endif #endif
......
...@@ -53,7 +53,7 @@ int main(int argc, char *argv[]) { ...@@ -53,7 +53,7 @@ int main(int argc, char *argv[]) {
int i; int i;
char *cp; char *cp;
const char *err_str; const char *err_str;
#ifdef MG_ENABLE_SSL #if MG_ENABLE_SSL
const char *ssl_cert = NULL; const char *ssl_cert = NULL;
#endif #endif
...@@ -75,7 +75,7 @@ int main(int argc, char *argv[]) { ...@@ -75,7 +75,7 @@ int main(int argc, char *argv[]) {
s_http_port = argv[++i]; s_http_port = argv[++i];
} else if (strcmp(argv[i], "-a") == 0 && i + 1 < argc) { } else if (strcmp(argv[i], "-a") == 0 && i + 1 < argc) {
s_http_server_opts.auth_domain = argv[++i]; s_http_server_opts.auth_domain = argv[++i];
#ifdef MG_ENABLE_JAVASCRIPT #if MG_ENABLE_JAVASCRIPT
} else if (strcmp(argv[i], "-j") == 0 && i + 1 < argc) { } else if (strcmp(argv[i], "-j") == 0 && i + 1 < argc) {
const char *init_file = argv[++i]; const char *init_file = argv[++i];
mg_enable_javascript(&mgr, v7_create(), init_file); mg_enable_javascript(&mgr, v7_create(), init_file);
...@@ -86,11 +86,11 @@ int main(int argc, char *argv[]) { ...@@ -86,11 +86,11 @@ int main(int argc, char *argv[]) {
s_http_server_opts.per_directory_auth_file = argv[++i]; s_http_server_opts.per_directory_auth_file = argv[++i];
} else if (strcmp(argv[i], "-r") == 0 && i + 1 < argc) { } else if (strcmp(argv[i], "-r") == 0 && i + 1 < argc) {
s_http_server_opts.url_rewrites = argv[++i]; s_http_server_opts.url_rewrites = argv[++i];
#ifndef MG_DISABLE_CGI #if !MG_DISABLE_CGI
} else if (strcmp(argv[i], "-i") == 0 && i + 1 < argc) { } else if (strcmp(argv[i], "-i") == 0 && i + 1 < argc) {
s_http_server_opts.cgi_interpreter = argv[++i]; s_http_server_opts.cgi_interpreter = argv[++i];
#endif #endif
#ifdef MG_ENABLE_SSL #if MG_ENABLE_SSL
} else if (strcmp(argv[i], "-s") == 0 && i + 1 < argc) { } else if (strcmp(argv[i], "-s") == 0 && i + 1 < argc) {
ssl_cert = argv[++i]; ssl_cert = argv[++i];
#endif #endif
...@@ -103,7 +103,7 @@ int main(int argc, char *argv[]) { ...@@ -103,7 +103,7 @@ int main(int argc, char *argv[]) {
/* Set HTTP server options */ /* Set HTTP server options */
memset(&bind_opts, 0, sizeof(bind_opts)); memset(&bind_opts, 0, sizeof(bind_opts));
bind_opts.error_string = &err_str; bind_opts.error_string = &err_str;
#ifdef MG_ENABLE_SSL #if MG_ENABLE_SSL
if (ssl_cert != NULL) { if (ssl_cert != NULL) {
bind_opts.ssl_cert = ssl_cert; bind_opts.ssl_cert = ssl_cert;
} }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* All rights reserved * All rights reserved
*/ */
#ifdef MG_ENABLE_SSL #if MG_ENABLE_SSL
/* /*
* This example starts an SSL web server on https://localhost:8443/ * This example starts an SSL web server on https://localhost:8443/
* *
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment