Commit 492dcdca authored by Deomid Ryabkov's avatar Deomid Ryabkov Committed by Cesanta Bot

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

Disable sync resolver by default.

PUBLISHED_FROM=dbaed194e5fe211c07564fe6880649a1aee7f662
parent 4ef3a778
...@@ -19,6 +19,7 @@ items: ...@@ -19,6 +19,7 @@ items:
- { name: mg_printf.md } - { name: mg_printf.md }
- { name: mg_vprintf.md } - { name: mg_vprintf.md }
- { name: mg_socketpair.md } - { name: mg_socketpair.md }
- { name: mg_resolve.md }
- { name: mg_check_ip_acl.md } - { name: mg_check_ip_acl.md }
- { name: mg_enable_multithreading.md } - { name: mg_enable_multithreading.md }
- { name: mg_enable_javascript.md } - { name: mg_enable_javascript.md }
......
---
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.
...@@ -1980,7 +1980,7 @@ int mg_printf(struct mg_connection *conn, const char *fmt, ...) { ...@@ -1980,7 +1980,7 @@ int mg_printf(struct mg_connection *conn, const char *fmt, ...) {
return len; return len;
} }
#if !MG_DISABLE_SYNC_RESOLVER #if MG_ENABLE_SYNC_RESOLVER
/* TODO(lsm): use non-blocking resolver */ /* TODO(lsm): use non-blocking resolver */
static int mg_resolve2(const char *host, struct in_addr *ina) { static int mg_resolve2(const char *host, struct in_addr *ina) {
#if MG_ENABLE_GETADDRINFO #if MG_ENABLE_GETADDRINFO
...@@ -2016,7 +2016,7 @@ int mg_resolve(const char *host, char *buf, size_t n) { ...@@ -2016,7 +2016,7 @@ int mg_resolve(const char *host, char *buf, size_t n) {
struct in_addr ad; struct in_addr ad;
return mg_resolve2(host, &ad) ? snprintf(buf, n, "%s", inet_ntoa(ad)) : 0; 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( MG_INTERNAL struct mg_connection *mg_create_connection_base(
struct mg_mgr *mgr, mg_event_handler_t callback, 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, ...@@ -2107,7 +2107,7 @@ MG_INTERNAL int mg_parse_address(const char *str, union socket_address *sa,
sa->sin6.sin6_family = AF_INET6; sa->sin6.sin6_family = AF_INET6;
sa->sin.sin_port = htons((uint16_t) port); sa->sin.sin_port = htons((uint16_t) port);
#endif #endif
#if !MG_DISABLE_RESOLVER #if MG_ENABLE_ASYNC_RESOLVER
} else if (strlen(str) < host_len && } else if (strlen(str) < host_len &&
sscanf(str, "%[^ :]:%u%n", host, &port, &len) == 2) { sscanf(str, "%[^ :]:%u%n", host, &port, &len) == 2) {
sa->sin.sin_port = htons((uint16_t) port); 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, ...@@ -2122,7 +2122,7 @@ MG_INTERNAL int mg_parse_address(const char *str, union socket_address *sa,
return 0; return 0;
} }
#if !MG_DISABLE_SYNC_RESOLVER #if MG_ENABLE_SYNC_RESOLVER
if (!mg_resolve2(host, &sa->sin.sin_addr)) { if (!mg_resolve2(host, &sa->sin.sin_addr)) {
return -1; return -1;
} }
...@@ -2482,7 +2482,7 @@ void mg_if_connect_cb(struct mg_connection *nc, int err) { ...@@ -2482,7 +2482,7 @@ void mg_if_connect_cb(struct mg_connection *nc, int err) {
mg_call(nc, NULL, MG_EV_CONNECT, &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. * Callback for the async resolver on mg_connect_opt() call.
* Main task of this function is to trigger MG_EV_CONNECT event with * 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, ...@@ -2600,7 +2600,7 @@ struct mg_connection *mg_connect_opt(struct mg_mgr *mgr, const char *address,
#endif /* MG_ENABLE_SSL */ #endif /* MG_ENABLE_SSL */
if (rc == 0) { if (rc == 0) {
#if !MG_DISABLE_RESOLVER #if MG_ENABLE_ASYNC_RESOLVER
/* /*
* DNS resolution is required for host. * DNS resolution is required for host.
* mg_parse_address() fills port in nc->sa, which we pass to resolve_cb() * 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, ...@@ -8548,7 +8548,7 @@ struct mg_mqtt_session *mg_mqtt_next(struct mg_mqtt_broker *brk,
* All rights reserved * All rights reserved
*/ */
#if !MG_DISABLE_DNS #if MG_ENABLE_DNS
/* Amalgamated: #include "mongoose/src/internal.h" */ /* Amalgamated: #include "mongoose/src/internal.h" */
/* Amalgamated: #include "mongoose/src/dns.h" */ /* Amalgamated: #include "mongoose/src/dns.h" */
...@@ -8911,7 +8911,7 @@ void mg_set_protocol_dns(struct mg_connection *nc) { ...@@ -8911,7 +8911,7 @@ void mg_set_protocol_dns(struct mg_connection *nc) {
nc->proto_handler = dns_handler; nc->proto_handler = dns_handler;
} }
#endif /* MG_DISABLE_DNS */ #endif /* MG_ENABLE_DNS */
#ifdef MG_MODULE_LINES #ifdef MG_MODULE_LINES
#line 1 "mongoose/src/dns_server.c" #line 1 "mongoose/src/dns_server.c"
#endif #endif
...@@ -8994,7 +8994,7 @@ int mg_dns_reply_record(struct mg_dns_reply *reply, ...@@ -8994,7 +8994,7 @@ int mg_dns_reply_record(struct mg_dns_reply *reply,
* All rights reserved * All rights reserved
*/ */
#if !MG_DISABLE_RESOLVER #if MG_ENABLE_ASYNC_RESOLVER
/* Amalgamated: #include "mongoose/src/internal.h" */ /* Amalgamated: #include "mongoose/src/internal.h" */
/* Amalgamated: #include "mongoose/src/resolv.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, ...@@ -9255,7 +9255,7 @@ int mg_resolve_async_opt(struct mg_mgr *mgr, const char *name, int query,
return 0; return 0;
} }
#endif /* MG_DISABLE_RESOLVE */ #endif /* MG_ENABLE_ASYNC_RESOLVER */
#ifdef MG_MODULE_LINES #ifdef MG_MODULE_LINES
#line 1 "mongoose/src/coap.c" #line 1 "mongoose/src/coap.c"
#endif #endif
......
...@@ -497,7 +497,6 @@ void mg_lwip_set_keepalive_params(struct mg_connection *nc, int idle, ...@@ -497,7 +497,6 @@ void mg_lwip_set_keepalive_params(struct mg_connection *nc, int idle,
#include <time.h> #include <time.h>
#define MG_NET_IF MG_NET_IF_SIMPLELINK #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 * 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); ...@@ -551,7 +550,6 @@ int inet_pton(int af, const char *src, void *dst);
#endif #endif
#define MG_NET_IF MG_NET_IF_SIMPLELINK #define MG_NET_IF MG_NET_IF_SIMPLELINK
#define MG_DISABLE_SYNC_RESOLVER 1
/* Only SPIFFS supports directories, SLFS does not. */ /* Only SPIFFS supports directories, SLFS does not. */
#if defined(CC3200_FS_SPIFFS) && !defined(MG_ENABLE_DIRECTORY_LISTING) #if defined(CC3200_FS_SPIFFS) && !defined(MG_ENABLE_DIRECTORY_LISTING)
...@@ -686,7 +684,6 @@ struct dirent *readdir(DIR *dir); ...@@ -686,7 +684,6 @@ struct dirent *readdir(DIR *dir);
#endif #endif
#define MG_NET_IF MG_NET_IF_SIMPLELINK #define MG_NET_IF MG_NET_IF_SIMPLELINK
#define MG_DISABLE_SYNC_RESOLVER 1
/* Amalgamated: #include "common/platforms/simplelink/cs_simplelink.h" */ /* 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); ...@@ -1421,10 +1418,6 @@ const char *c_strnstr(const char *s, const char *find, size_t slen);
#ifndef CS_MONGOOSE_SRC_FEATURES_H_ #ifndef CS_MONGOOSE_SRC_FEATURES_H_
#define 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 #ifndef MG_DISABLE_HTTP_DIGEST_AUTH
#define MG_DISABLE_HTTP_DIGEST_AUTH 0 #define MG_DISABLE_HTTP_DIGEST_AUTH 0
#endif #endif
...@@ -1437,18 +1430,14 @@ const char *c_strnstr(const char *s, const char *find, size_t slen); ...@@ -1437,18 +1430,14 @@ const char *c_strnstr(const char *s, const char *find, size_t slen);
#define MG_DISABLE_PFS 0 #define MG_DISABLE_PFS 0
#endif #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 #ifndef MG_DISABLE_WS_RANDOM_MASK
#define MG_DISABLE_WS_RANDOM_MASK 0 #define MG_DISABLE_WS_RANDOM_MASK 0
#endif #endif
#ifndef MG_ENABLE_ASYNC_RESOLVER
#define MG_ENABLE_ASYNC_RESOLVER 1
#endif
#ifndef MG_ENABLE_BROADCAST #ifndef MG_ENABLE_BROADCAST
#define MG_ENABLE_BROADCAST 0 #define MG_ENABLE_BROADCAST 0
#endif #endif
...@@ -1465,6 +1454,10 @@ const char *c_strnstr(const char *s, const char *find, size_t slen); ...@@ -1465,6 +1454,10 @@ const char *c_strnstr(const char *s, const char *find, size_t slen);
#define MG_ENABLE_DIRECTORY_LISTING 0 #define MG_ENABLE_DIRECTORY_LISTING 0
#endif #endif
#ifndef MG_ENABLE_DNS
#define MG_ENABLE_DNS 1
#endif
#ifndef MG_ENABLE_DNS_SERVER #ifndef MG_ENABLE_DNS_SERVER
#define MG_ENABLE_DNS_SERVER 0 #define MG_ENABLE_DNS_SERVER 0
#endif #endif
...@@ -1533,6 +1526,10 @@ const char *c_strnstr(const char *s, const char *find, size_t slen); ...@@ -1533,6 +1526,10 @@ const char *c_strnstr(const char *s, const char *find, size_t slen);
#define MG_ENABLE_SSL 0 #define MG_ENABLE_SSL 0
#endif #endif
#ifndef MG_ENABLE_SYNC_RESOLVER
#define MG_ENABLE_SYNC_RESOLVER 0
#endif
#ifndef MG_ENABLE_STDIO #ifndef MG_ENABLE_STDIO
#define MG_ENABLE_STDIO CS_ENABLE_STDIO #define MG_ENABLE_STDIO CS_ENABLE_STDIO
#endif #endif
...@@ -1553,11 +1550,6 @@ const char *c_strnstr(const char *s, const char *find, size_t slen); ...@@ -1553,11 +1550,6 @@ const char *c_strnstr(const char *s, const char *find, size_t slen);
#define CS_ENABLE_DEBUG 1 #define CS_ENABLE_DEBUG 1
#endif #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 */ /* MQTT broker requires MQTT */
#if MG_ENABLE_MQTT_BROKER && !MG_ENABLE_MQTT #if MG_ENABLE_MQTT_BROKER && !MG_ENABLE_MQTT
#undef MG_ENABLE_MQTT #undef MG_ENABLE_MQTT
...@@ -2019,6 +2011,7 @@ int mg_vprintf(struct mg_connection *, const char *fmt, va_list ap); ...@@ -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); int mg_socketpair(sock_t[2], int sock_type);
#if MG_ENABLE_SYNC_RESOLVER
/* /*
* Convert domain name into IP address. * Convert domain name into IP address.
* *
...@@ -2029,7 +2022,6 @@ int mg_socketpair(sock_t[2], int sock_type); ...@@ -2029,7 +2022,6 @@ int mg_socketpair(sock_t[2], int sock_type);
* CAUTION: this function can block. * CAUTION: this function can block.
* Return 1 on success, 0 on failure. * 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); int mg_resolve(const char *domain_name, char *ip_addr_buf, size_t buf_len);
#endif #endif
......
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