MG_DISABLE_(DNS|(_SYNC)?_RESOLVER) -> MG_ENABLE_$1

Disable sync resolver by default.

PUBLISHED_FROM=dbaed194e5fe211c07564fe6880649a1aee7f662
This commit is contained in:
Deomid Ryabkov 2016-10-17 22:08:11 +03:00 committed by Cesanta Bot
parent 4ef3a778c1
commit 492dcdca8d
4 changed files with 41 additions and 31 deletions

View File

@ -19,6 +19,7 @@ items:
- { name: mg_printf.md }
- { name: mg_vprintf.md }
- { name: mg_socketpair.md }
- { name: mg_resolve.md }
- { name: mg_check_ip_acl.md }
- { name: mg_enable_multithreading.md }
- { name: mg_enable_javascript.md }

View File

@ -0,0 +1,17 @@
---
title: "mg_resolve()"
decl_name: "mg_resolve"
symbol_kind: "func"
signature: |
int mg_resolve(const char *domain_name, char *ip_addr_buf, size_t buf_len);
---
Convert domain name into IP address.
This is a utility function. If compilation flags have
`-DMG_ENABLE_GETADDRINFO`, then `getaddrinfo()` call is used for name
resolution. Otherwise, `gethostbyname()` is used.
CAUTION: this function can block.
Return 1 on success, 0 on failure.

View File

@ -1980,7 +1980,7 @@ int mg_printf(struct mg_connection *conn, const char *fmt, ...) {
return len;
}
#if !MG_DISABLE_SYNC_RESOLVER
#if MG_ENABLE_SYNC_RESOLVER
/* TODO(lsm): use non-blocking resolver */
static int mg_resolve2(const char *host, struct in_addr *ina) {
#if MG_ENABLE_GETADDRINFO
@ -2016,7 +2016,7 @@ int mg_resolve(const char *host, char *buf, size_t n) {
struct in_addr ad;
return mg_resolve2(host, &ad) ? snprintf(buf, n, "%s", inet_ntoa(ad)) : 0;
}
#endif /* MG_DISABLE_SYNC_RESOLVER */
#endif /* MG_ENABLE_SYNC_RESOLVER */
MG_INTERNAL struct mg_connection *mg_create_connection_base(
struct mg_mgr *mgr, mg_event_handler_t callback,
@ -2107,7 +2107,7 @@ MG_INTERNAL int mg_parse_address(const char *str, union socket_address *sa,
sa->sin6.sin6_family = AF_INET6;
sa->sin.sin_port = htons((uint16_t) port);
#endif
#if !MG_DISABLE_RESOLVER
#if MG_ENABLE_ASYNC_RESOLVER
} else if (strlen(str) < host_len &&
sscanf(str, "%[^ :]:%u%n", host, &port, &len) == 2) {
sa->sin.sin_port = htons((uint16_t) port);
@ -2122,7 +2122,7 @@ MG_INTERNAL int mg_parse_address(const char *str, union socket_address *sa,
return 0;
}
#if !MG_DISABLE_SYNC_RESOLVER
#if MG_ENABLE_SYNC_RESOLVER
if (!mg_resolve2(host, &sa->sin.sin_addr)) {
return -1;
}
@ -2482,7 +2482,7 @@ void mg_if_connect_cb(struct mg_connection *nc, int err) {
mg_call(nc, NULL, MG_EV_CONNECT, &err);
}
#if !MG_DISABLE_RESOLVER
#if MG_ENABLE_ASYNC_RESOLVER
/*
* Callback for the async resolver on mg_connect_opt() call.
* Main task of this function is to trigger MG_EV_CONNECT event with
@ -2600,7 +2600,7 @@ struct mg_connection *mg_connect_opt(struct mg_mgr *mgr, const char *address,
#endif /* MG_ENABLE_SSL */
if (rc == 0) {
#if !MG_DISABLE_RESOLVER
#if MG_ENABLE_ASYNC_RESOLVER
/*
* DNS resolution is required for host.
* mg_parse_address() fills port in nc->sa, which we pass to resolve_cb()
@ -8548,7 +8548,7 @@ struct mg_mqtt_session *mg_mqtt_next(struct mg_mqtt_broker *brk,
* All rights reserved
*/
#if !MG_DISABLE_DNS
#if MG_ENABLE_DNS
/* Amalgamated: #include "mongoose/src/internal.h" */
/* Amalgamated: #include "mongoose/src/dns.h" */
@ -8911,7 +8911,7 @@ void mg_set_protocol_dns(struct mg_connection *nc) {
nc->proto_handler = dns_handler;
}
#endif /* MG_DISABLE_DNS */
#endif /* MG_ENABLE_DNS */
#ifdef MG_MODULE_LINES
#line 1 "mongoose/src/dns_server.c"
#endif
@ -8994,7 +8994,7 @@ int mg_dns_reply_record(struct mg_dns_reply *reply,
* All rights reserved
*/
#if !MG_DISABLE_RESOLVER
#if MG_ENABLE_ASYNC_RESOLVER
/* Amalgamated: #include "mongoose/src/internal.h" */
/* Amalgamated: #include "mongoose/src/resolv.h" */
@ -9255,7 +9255,7 @@ int mg_resolve_async_opt(struct mg_mgr *mgr, const char *name, int query,
return 0;
}
#endif /* MG_DISABLE_RESOLVE */
#endif /* MG_ENABLE_ASYNC_RESOLVER */
#ifdef MG_MODULE_LINES
#line 1 "mongoose/src/coap.c"
#endif

View File

@ -497,7 +497,6 @@ void mg_lwip_set_keepalive_params(struct mg_connection *nc, int idle,
#include <time.h>
#define MG_NET_IF MG_NET_IF_SIMPLELINK
#define MG_DISABLE_SYNC_RESOLVER 1
/*
* CC3100 SDK and STM32 SDK include headers w/out path, just like
@ -551,7 +550,6 @@ int inet_pton(int af, const char *src, void *dst);
#endif
#define MG_NET_IF MG_NET_IF_SIMPLELINK
#define MG_DISABLE_SYNC_RESOLVER 1
/* Only SPIFFS supports directories, SLFS does not. */
#if defined(CC3200_FS_SPIFFS) && !defined(MG_ENABLE_DIRECTORY_LISTING)
@ -686,7 +684,6 @@ struct dirent *readdir(DIR *dir);
#endif
#define MG_NET_IF MG_NET_IF_SIMPLELINK
#define MG_DISABLE_SYNC_RESOLVER 1
/* Amalgamated: #include "common/platforms/simplelink/cs_simplelink.h" */
@ -1421,10 +1418,6 @@ const char *c_strnstr(const char *s, const char *find, size_t slen);
#ifndef CS_MONGOOSE_SRC_FEATURES_H_
#define CS_MONGOOSE_SRC_FEATURES_H_
#ifndef MG_DISABLE_DNS
#define MG_DISABLE_DNS 0
#endif
#ifndef MG_DISABLE_HTTP_DIGEST_AUTH
#define MG_DISABLE_HTTP_DIGEST_AUTH 0
#endif
@ -1437,18 +1430,14 @@ const char *c_strnstr(const char *s, const char *find, size_t slen);
#define MG_DISABLE_PFS 0
#endif
#ifndef MG_DISABLE_RESOLVER
#define MG_DISABLE_RESOLVER 0
#endif
#ifndef MG_DISABLE_SYNC_RESOLVER
#define MG_DISABLE_SYNC_RESOLVER 0
#endif
#ifndef MG_DISABLE_WS_RANDOM_MASK
#define MG_DISABLE_WS_RANDOM_MASK 0
#endif
#ifndef MG_ENABLE_ASYNC_RESOLVER
#define MG_ENABLE_ASYNC_RESOLVER 1
#endif
#ifndef MG_ENABLE_BROADCAST
#define MG_ENABLE_BROADCAST 0
#endif
@ -1465,6 +1454,10 @@ const char *c_strnstr(const char *s, const char *find, size_t slen);
#define MG_ENABLE_DIRECTORY_LISTING 0
#endif
#ifndef MG_ENABLE_DNS
#define MG_ENABLE_DNS 1
#endif
#ifndef MG_ENABLE_DNS_SERVER
#define MG_ENABLE_DNS_SERVER 0
#endif
@ -1533,6 +1526,10 @@ const char *c_strnstr(const char *s, const char *find, size_t slen);
#define MG_ENABLE_SSL 0
#endif
#ifndef MG_ENABLE_SYNC_RESOLVER
#define MG_ENABLE_SYNC_RESOLVER 0
#endif
#ifndef MG_ENABLE_STDIO
#define MG_ENABLE_STDIO CS_ENABLE_STDIO
#endif
@ -1553,11 +1550,6 @@ const char *c_strnstr(const char *s, const char *find, size_t slen);
#define CS_ENABLE_DEBUG 1
#endif
#ifdef MG_NO_BSD_SOCKETS
#undef MG_DISABLE_SYNC_RESOLVER
#define MG_DISABLE_SYNC_RESOLVER 1
#endif /* MG_NO_BSD_SOCKETS */
/* MQTT broker requires MQTT */
#if MG_ENABLE_MQTT_BROKER && !MG_ENABLE_MQTT
#undef MG_ENABLE_MQTT
@ -2019,6 +2011,7 @@ int mg_vprintf(struct mg_connection *, const char *fmt, va_list ap);
*/
int mg_socketpair(sock_t[2], int sock_type);
#if MG_ENABLE_SYNC_RESOLVER
/*
* Convert domain name into IP address.
*
@ -2029,7 +2022,6 @@ int mg_socketpair(sock_t[2], int sock_type);
* CAUTION: this function can block.
* Return 1 on success, 0 on failure.
*/
#if !MG_DISABLE_SYNC_RESOLVER
int mg_resolve(const char *domain_name, char *ip_addr_buf, size_t buf_len);
#endif