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; }
bool mongoc_uri_set_option_as_utf8(mongoc_uri_t *uri, const char *option, const char *value) { size_t len; BSON_ASSERT (option); len = strlen(value); if (!bson_utf8_validate (value, len, false)) { return false; } if (!mongoc_uri_option_is_utf8 (option)) { return false; } mongoc_uri_bson_append_or_replace_key (&uri->options, option, value); return true; }