1 ////////////////////////////////////////////////////////////////////////////
3 // Copyright 2017 Realm Inc.
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
17 ////////////////////////////////////////////////////////////////////////////
19 #include "sync/sync_config.hpp"
21 #include "sync/sync_manager.hpp"
23 #include <realm/sync/crypto.hpp>
29 // Construct an identifier for this partially synced Realm by combining client and user identifiers.
30 std::string partial_sync_identifier(const SyncUser& user)
32 std::string raw_identifier = SyncManager::shared().client_uuid() + "/" + user.local_identity();
33 uint8_t identifier[20];
34 sync::crypto::sha1(raw_identifier.data(), raw_identifier.size(), (char *)&identifier[0]);
37 ss << std::hex << std::setfill('0');
38 for (uint8_t c : identifier)
39 ss << std::setw(2) << (unsigned)c;
43 } // unnamed namespace
45 std::string SyncConfig::realm_url() const
47 REALM_ASSERT(reference_realm_url.length() > 0);
51 return reference_realm_url;
53 std::string base_url = reference_realm_url;
54 if (base_url.back() == '/')
57 if (custom_partial_sync_identifier)
58 return base_url + "/__partial/" + *custom_partial_sync_identifier;
60 return base_url + "/__partial/" + partial_sync_identifier(*user);