Skip to content

Commit 6abe0f1

Browse files
Use ENABLE_SRV to toggle SRV support rather than detection macros
1 parent a84fa5a commit 6abe0f1

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

src/libmongoc/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ endif ()
290290

291291
# Find name resolution libaries. Also sets definitions used in configure_file():
292292
include(ResSearch)
293+
# Definition for mongoc-config.h:
294+
_mongo_pick(MONGOC_ENABLE_SRV 1 0 ENABLE_SRV)
293295

294296
include (CheckSchedGetCPU)
295297

src/libmongoc/src/mongoc/mongoc-client.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,11 @@ _mongoc_client_killcursors_command (mongoc_cluster_t *cluster,
101101
} while (0)
102102

103103

104-
#ifdef MONGOC_HAVE_DNSAPI
104+
#if MONGOC_ENABLE_SRV == 0 // ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ ENABLE_SRV disabled
105+
106+
/* SRV support is disabled */
107+
108+
#elif defined(MONGOC_HAVE_DNSAPI) // ↑↑↑ ENABLE_SRV disabled / Win32 Dnsapi ↓↓↓↓
105109

106110
typedef bool (*mongoc_rr_callback_t) (const char *hostname,
107111
PDNS_RECORD pdns,
@@ -291,7 +295,9 @@ _mongoc_get_rr_dnsapi (const char *hostname,
291295
RETURN (dns_success && callback_success);
292296
}
293297

294-
#elif (defined(MONGOC_HAVE_RES_NSEARCH) || defined(MONGOC_HAVE_RES_SEARCH))
298+
#elif ( \
299+
defined(MONGOC_HAVE_RES_NSEARCH) || \
300+
defined(MONGOC_HAVE_RES_SEARCH)) // ↑↑↑↑↑↑↑ Win32 Dnsapi / resolv ↓↓↓↓↓↓↓↓
295301

296302
typedef bool (*mongoc_rr_callback_t) (const char *hostname,
297303
ns_msg *ns_answer,
@@ -569,7 +575,7 @@ _mongoc_get_rr_search (const char *hostname,
569575
#endif
570576
RETURN (dns_success && callback_success);
571577
}
572-
#endif
578+
#endif // ↑↑↑↑↑↑↑↑↑↑↑↑↑ resolv
573579

574580
/*
575581
*--------------------------------------------------------------------------
@@ -605,17 +611,20 @@ _mongoc_client_get_rr (const char *hostname,
605611
{
606612
BSON_ASSERT (rr_data);
607613

608-
#ifdef MONGOC_HAVE_DNSAPI
609-
return _mongoc_get_rr_dnsapi (hostname, rr_type, rr_data, error);
610-
#elif (defined(MONGOC_HAVE_RES_NSEARCH) || defined(MONGOC_HAVE_RES_SEARCH))
611-
return _mongoc_get_rr_search (
612-
hostname, rr_type, rr_data, initial_buffer_size, error);
613-
#else
614+
#if MONGOC_ENABLE_SRV == 0
615+
// Disabled
614616
bson_set_error (error,
615617
MONGOC_ERROR_STREAM,
616618
MONGOC_ERROR_STREAM_NAME_RESOLUTION,
617619
"libresolv unavailable, cannot use mongodb+srv URI");
618620
return false;
621+
#elif defined(MONGOC_HAVE_DNSAPI)
622+
return _mongoc_get_rr_dnsapi (hostname, rr_type, rr_data, error);
623+
#elif (defined(MONGOC_HAVE_RES_NSEARCH) || defined(MONGOC_HAVE_RES_SEARCH))
624+
return _mongoc_get_rr_search (
625+
hostname, rr_type, rr_data, initial_buffer_size, error);
626+
#else
627+
#error No SRV library is available, but ENABLE_SRV is true!
619628
#endif
620629
}
621630

src/libmongoc/src/mongoc/mongoc-config.h.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@
226226
# undef MONGOC_HAVE_SOCKLEN
227227
#endif
228228

229+
/**
230+
* @brief Defined to 0/1 for whether we were configured with ENABLE_SRV
231+
*/
232+
#define MONGOC_ENABLE_SRV @MONGOC_ENABLE_SRV@
229233

230234
/*
231235
* MONGOC_HAVE_DNSAPI is set from configure to determine if we should use the

0 commit comments

Comments
 (0)