static mongoc_uri_t *hippo_mongo_driver_manager_make_uri(const char *dsn, const Array options) { mongoc_uri_t *uri = mongoc_uri_new(dsn); if (!uri) { throw MongoDriver::Utils::throwInvalidArgumentException("Failed to parse MongoDB URI: '" + String(dsn) + "'"); } for (ArrayIter iter(options); iter; ++iter) { const Variant& key = iter.first(); const Variant& value = iter.second(); const char *s_key = key.toString().c_str(); if ( !strcasecmp(s_key, "journal") || !strcasecmp(s_key, "readpreference") || !strcasecmp(s_key, "readpreferencetags") || !strcasecmp(s_key, "safe") || !strcasecmp(s_key, "slaveok") || !strcasecmp(s_key, "w") || !strcasecmp(s_key, "wtimeoutms") ) { continue; } if (mongoc_uri_option_is_bool(s_key)) { mongoc_uri_set_option_as_bool(uri, s_key, value.toBoolean()); } else if (mongoc_uri_option_is_int32(s_key) && value.isInteger()) { mongoc_uri_set_option_as_int32(uri, s_key, (int32_t) value.toInt64()); } else if (mongoc_uri_option_is_utf8(s_key) && value.isString()) { mongoc_uri_set_option_as_utf8(uri, s_key, value.toString().c_str()); } else if (value.isString()) { if (!strcasecmp(s_key, "username")) { mongoc_uri_set_username(uri, value.toString().c_str()); } else if (!strcasecmp(s_key, "password")) { mongoc_uri_set_password(uri, value.toString().c_str()); } else if (!strcasecmp(s_key, "database")) { mongoc_uri_set_database(uri, value.toString().c_str()); } else if (!strcasecmp(s_key, "authsource")) { mongoc_uri_set_auth_source(uri, value.toString().c_str()); } } } return uri; }
static mongoc_uri_t * _get_uri (mock_server_t *server, read_pref_test_type_t test_type) { mongoc_uri_t *uri; uri = mongoc_uri_copy (mock_server_get_uri (server)); switch (test_type) { case READ_PREF_TEST_PRIMARY: case READ_PREF_TEST_SECONDARY: mongoc_uri_set_option_as_utf8 (uri, "replicaSet", "rs"); break; case READ_PREF_TEST_STANDALONE: case READ_PREF_TEST_MONGOS: default: break; } return uri; }