Skip to content

Commit

Permalink
Merge pull request #7329 from realm/tg/jwt-validation
Browse files Browse the repository at this point in the history
Assorted sync metadata storage refactoring
  • Loading branch information
tgoyne authored Feb 12, 2024
2 parents a747754 + 241668b commit 6459d4b
Show file tree
Hide file tree
Showing 36 changed files with 414 additions and 444 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* Fixed invalid data in error reason string when registering a subscription change notification after the subscription has already failed. ([#6839](https://github.com/realm/realm-core/issues/6839), since v11.8.0)
* Fixed crash in fulltext index using prefix search with no matches ([#7309](https://github.com/realm/realm-core/issues/7309), since v13.18.0)
* Fix compilation and some warnings when building with Xcode 15.3 ([PR #7297](https://github.com/realm/realm-core/pull/7297)).
* util::make_dir_recursive() attempted to create a directory named "\0" if the path did not have a trailing slash ([PR #7329](https://github.com/realm/realm-core/pull/7329)).

### Breaking changes
* None.
Expand Down
2 changes: 1 addition & 1 deletion src/realm/db.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ class DB : public std::enable_shared_from_this<DB> {
class ReadLockGuard;

// Member variables
mutable util::CheckedMutex m_mutex;
util::CheckedMutex m_mutex;
int m_transaction_count GUARDED_BY(m_mutex) = 0;
SlabAlloc m_alloc;
std::unique_ptr<Replication> m_history;
Expand Down
6 changes: 2 additions & 4 deletions src/realm/obj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -898,11 +898,9 @@ void out_string(std::ostream& out, std::string str)

void out_binary(std::ostream& out, BinaryData bin)
{
const char* start = bin.data();
const size_t len = bin.size();
std::string encode_buffer;
encode_buffer.resize(util::base64_encoded_size(len));
util::base64_encode(start, len, encode_buffer.data(), encode_buffer.size());
encode_buffer.resize(util::base64_encoded_size(bin.size()));
util::base64_encode(bin, encode_buffer);
out << encode_buffer;
}

Expand Down
28 changes: 15 additions & 13 deletions src/realm/object-store/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,21 @@ set(HEADERS
if(REALM_ENABLE_SYNC)
list(APPEND HEADERS
sync/app.hpp
sync/app_utils.hpp
sync/app_credentials.hpp
sync/generic_network_transport.hpp
sync/async_open_task.hpp
sync/sync_manager.hpp
sync/sync_session.hpp
sync/sync_user.hpp
sync/app_service_client.hpp
sync/app_utils.hpp
sync/async_open_task.hpp
sync/auth_request_client.hpp
sync/generic_network_transport.hpp
sync/jwt.hpp
sync/mongo_client.hpp
sync/mongo_collection.hpp
sync/mongo_database.hpp
sync/push_client.hpp
sync/subscribable.hpp
sync/sync_manager.hpp
sync/sync_session.hpp
sync/sync_user.hpp

sync/impl/sync_client.hpp
sync/impl/sync_file.hpp
Expand All @@ -114,19 +115,20 @@ if(REALM_ENABLE_SYNC)

list(APPEND SOURCES
sync/app.cpp
sync/app_utils.cpp
sync/app_credentials.cpp
sync/generic_network_transport.cpp
sync/app_utils.cpp
sync/async_open_task.cpp
sync/sync_manager.cpp
sync/sync_session.cpp
sync/sync_user.cpp
sync/generic_network_transport.cpp
sync/impl/sync_file.cpp
sync/impl/sync_metadata.cpp
sync/jwt.cpp
sync/mongo_client.cpp
sync/mongo_collection.cpp
sync/mongo_database.cpp
sync/push_client.cpp
sync/impl/sync_file.cpp
sync/impl/sync_metadata.cpp)
sync/sync_manager.cpp
sync/sync_session.cpp
sync/sync_user.cpp)
if(APPLE)
list(APPEND HEADERS
sync/impl/apple/network_reachability_observer.hpp
Expand Down
2 changes: 1 addition & 1 deletion src/realm/object-store/c_api/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ static inline bson::BsonArray parse_ejson_array(const char* serialized)
return {};
}
else {
return bson::BsonArray(bson::parse(serialized));
return bson::BsonArray(bson::parse({serialized, strlen(serialized)}));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/realm/object-store/impl/realm_coordinator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ class RealmCoordinator : public std::enable_shared_from_this<RealmCoordinator>,
Realm::Config m_config;
std::shared_ptr<DB> m_db;

mutable util::CheckedMutex m_schema_cache_mutex;
util::CheckedMutex m_schema_cache_mutex;
util::Optional<Schema> m_cached_schema GUARDED_BY(m_schema_cache_mutex);
uint64_t m_schema_version GUARDED_BY(m_schema_cache_mutex) = -1;
uint64_t m_schema_transaction_version_min GUARDED_BY(m_schema_cache_mutex) = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/realm/object-store/sync/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1344,7 +1344,7 @@ Request App::make_streaming_request(const std::shared_ptr<SyncUser>& user, const
const auto args_json = Bson(args).to_string();

auto args_base64 = std::string(util::base64_encoded_size(args_json.size()), '\0');
util::base64_encode(args_json.data(), args_json.size(), args_base64.data(), args_base64.size());
util::base64_encode(args_json, args_base64);

auto url = function_call_url_path() + "?baas_request=" + util::uri_percent_encode(args_base64);
if (user) {
Expand Down
7 changes: 2 additions & 5 deletions src/realm/object-store/sync/app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class SyncUser;
class SyncSession;
class SyncManager;
struct SyncClientConfig;
class SyncAppMetadata;

namespace app {

Expand Down Expand Up @@ -434,11 +433,9 @@ class App : public std::enable_shared_from_this<App>,
std::string get_ws_host_url() REQUIRES(!m_route_mutex);

private:
// Local copy of app config
Config m_config;
const Config m_config;

// mutable to allow locking for reads in const functions
mutable util::CheckedMutex m_route_mutex;
util::CheckedMutex m_route_mutex;

// The following variables hold the different paths to Atlas, depending on the
// request being performed
Expand Down
2 changes: 1 addition & 1 deletion src/realm/object-store/sync/async_open_task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class AsyncOpenTask : public std::enable_shared_from_this<AsyncOpenTask> {
std::shared_ptr<_impl::RealmCoordinator> m_coordinator GUARDED_BY(m_mutex);
std::shared_ptr<SyncSession> m_session GUARDED_BY(m_mutex);
std::vector<uint64_t> m_registered_callbacks GUARDED_BY(m_mutex);
mutable util::CheckedMutex m_mutex;
util::CheckedMutex m_mutex;
const bool m_db_first_open;
};

Expand Down
Loading

0 comments on commit 6459d4b

Please sign in to comment.