Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
leemaguire committed Jul 11, 2024
1 parent 3575dfa commit f3eb217
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 46 deletions.
5 changes: 0 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ NEXT-RELEASE Release notes (YYYY-MM-DD)
### Internals
* None

<<<<<<< HEAD
=======
----------------------------------------------

>>>>>>> 90b31ac (Begin cleanup)
2.1.0 Release notes (2024-06-27)
=============================================================

Expand Down
53 changes: 53 additions & 0 deletions include/cpprealm/internal/networking/utils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
////////////////////////////////////////////////////////////////////////////
//
// Copyright 2024 Realm Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////

#ifndef CPPREALM_NETWORKING_UTILS_HPP
#define CPPREALM_NETWORKING_UTILS_HPP

#include <optional>

namespace realm {
namespace app {
struct Request;
struct Response;
}
namespace sync {
struct WebSocketEndpoint;
}

namespace networking {
struct default_transport_configuration;
struct request;
struct response;
struct websocket_endpoint;
}
}

namespace realm::internal::networking {
::realm::networking::request to_request(const ::realm::app::Request&);
::realm::app::Request to_core_request(const ::realm::networking::request&);

::realm::networking::response to_response(const ::realm::app::Response&);
::realm::app::Response to_core_response(const ::realm::networking::response&);

::realm::sync::WebSocketEndpoint to_core_websocket_endpoint(const ::realm::networking::websocket_endpoint& ep,
const std::optional<::realm::networking::default_transport_configuration>& config);
::realm::networking::websocket_endpoint to_websocket_endpoint(const ::realm::sync::WebSocketEndpoint& ep);
} //namespace realm::internal::networking

#endif //CPPREALM_NETWORKING_UTILS_HPP
26 changes: 0 additions & 26 deletions include/cpprealm/networking/networking.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,30 +140,4 @@ namespace realm::networking {

} //namespace realm::networking

namespace realm {
namespace app {
struct Request;
struct Response;
}
namespace sync {
struct WebSocketEndpoint;
}

namespace networking {
struct default_transport_configuration;
}
}

namespace realm::internal::networking {
::realm::networking::request to_request(const ::realm::app::Request&);
::realm::app::Request to_core_request(const ::realm::networking::request&);

::realm::networking::response to_response(const ::realm::app::Response&);
::realm::app::Response to_core_response(const ::realm::networking::response&);

::realm::sync::WebSocketEndpoint to_core_websocket_endpoint(const ::realm::networking::websocket_endpoint& ep,
const std::optional<::realm::networking::default_transport_configuration>& config);
::realm::networking::websocket_endpoint to_websocket_endpoint(const ::realm::sync::WebSocketEndpoint& ep);
} //namespace realm::internal::networking

#endif//CPPREALM_NETWORKING_HPP
3 changes: 1 addition & 2 deletions include/cpprealm/networking/platform_networking.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace realm {

namespace realm::networking {

using status = internal::bridge::status;
using status = ::realm::internal::bridge::status;

/// The WebSocket base class that is used by the SyncClient to send data over the
/// WebSocket connection with the server. This is the class that is returned by
Expand All @@ -55,7 +55,6 @@ namespace realm::networking {
/// is destroyed
virtual ~websocket_interface() = default;

using status = status;
using FunctionHandler = std::function<void(status)>;

/// Write data asynchronously to the WebSocket connection. The handler function
Expand Down
3 changes: 2 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ set(SOURCES
cpprealm/internal/bridge/timestamp.cpp
cpprealm/internal/bridge/uuid.cpp
cpprealm/internal/networking/shims.cpp
cpprealm/internal/networking/utils.cpp
cpprealm/internal/scheduler/realm_core_scheduler.cpp
cpprealm/networking/networking.cpp
cpprealm/networking/platform_networking.cpp
cpprealm/schedulers/default_scheduler.cpp
cpprealm/logger.cpp
Expand Down Expand Up @@ -114,6 +114,7 @@ set(HEADERS
../include/cpprealm/internal/bridge/uuid.hpp
../include/cpprealm/internal/type_info.hpp
../include/cpprealm/internal/networking/shims.hpp
../include/cpprealm/internal/networking/utils.hpp
../include/cpprealm/internal/scheduler/realm_core_scheduler.hpp
../include/cpprealm/schedulers/default_scheduler.hpp
../include/cpprealm/networking/networking.hpp
Expand Down
15 changes: 8 additions & 7 deletions src/cpprealm/internal/apple/network_transport.mm
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@
[urlRequest addValue:[NSString stringWithCString:header.second.c_str() encoding:NSUTF8StringEncoding]
forHTTPHeaderField:[NSString stringWithCString:header.first.c_str() encoding:NSUTF8StringEncoding]];
}
if (m_custom_http_headers) {
for (auto& header : *m_custom_http_headers) {
if (m_configuration.custom_http_headers) {
for (auto& header : *m_configuration.custom_http_headers) {
[urlRequest addValue:[NSString stringWithCString:header.second.c_str() encoding:NSUTF8StringEncoding]
forHTTPHeaderField:[NSString stringWithCString:header.first.c_str() encoding:NSUTF8StringEncoding]];
}
Expand All @@ -70,10 +70,10 @@
}

NSURLSession *session;
if (m_proxy_config) {
if (m_configuration.proxy_config) {
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
NSString *proxyHost = @(m_proxy_config->address.c_str());
NSInteger proxyPort = m_proxy_config->port;
NSString *proxyHost = @(m_configuration.proxy_config->address.c_str());
NSInteger proxyPort = m_configuration.proxy_config->port;
sessionConfiguration.connectionProxyDictionary = @{
@"HTTPSEnable": @YES,
@"HTTPSProxy": @(proxyPort),
Expand All @@ -84,8 +84,9 @@
[[NSURLCache sharedURLCache] removeAllCachedResponses];

session = [NSURLSession sessionWithConfiguration:sessionConfiguration];
if (m_proxy_config->username_password) {
auto userpass = util::format("%1:%2", m_proxy_config->username_password->first, m_proxy_config->username_password->second);
if (m_configuration.proxy_config->username_password) {
auto userpass = util::format("%1:%2", m_configuration.proxy_config->username_password->first,
m_configuration.proxy_config->username_password->second);
std::string encoded_userpass;
encoded_userpass.resize(realm::util::base64_encoded_size(userpass.length()));
realm::util::base64_encode(userpass, encoded_userpass);
Expand Down
7 changes: 4 additions & 3 deletions src/cpprealm/internal/networking/shims.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <cpprealm/internal/networking/shims.hpp>
#include <cpprealm/internal/networking/utils.hpp>

#include <realm/object-store/sync/generic_network_transport.hpp>
#include <realm/sync/network/default_socket.hpp>
Expand All @@ -14,7 +15,7 @@ namespace realm::internal::networking {
void async_write_binary(util::Span<const char> data, sync::SyncSocketProvider::FunctionHandler&& handler) override {
auto handler_ptr = handler.release();
auto b = std::string_view(data.data(), data.size());
m_interface->async_write_binary(b, [ptr = std::move(handler_ptr)](::realm::networking::websocket_interface::status s) {
m_interface->async_write_binary(b, [ptr = std::move(handler_ptr)](::realm::networking::status s) {
auto uf = util::UniqueFunction<void(::realm::Status)>(std::move(ptr));
return uf(s.operator ::realm::Status());
});
Expand Down Expand Up @@ -108,15 +109,15 @@ namespace realm::internal::networking {

void post(FunctionHandler&& handler) override {
auto handler_ptr = handler.release();
m_provider->post([ptr = std::move(handler_ptr)](::realm::networking::websocket_interface::status s) {
m_provider->post([ptr = std::move(handler_ptr)](::realm::networking::status s) {
auto uf = util::UniqueFunction<void(::realm::Status)>(std::move(ptr));
return uf(s.operator ::realm::Status());
});
}

::realm::sync::SyncSocketProvider::SyncTimer create_timer(std::chrono::milliseconds delay, ::realm::sync::SyncSocketProvider::FunctionHandler&& handler) override {
auto handler_ptr = handler.release();
auto fn = [ptr = std::move(handler_ptr)](::realm::networking::websocket_interface::status s) {
auto fn = [ptr = std::move(handler_ptr)](::realm::networking::status s) {
auto uf = util::UniqueFunction<void(::realm::Status)>(std::move(ptr));
return uf(s.operator ::realm::Status());
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <cpprealm/networking/networking.hpp>
#include <cpprealm/internal/networking/utils.hpp>
#include <cpprealm/networking/platform_networking.hpp>

#include <realm/object-store/sync/generic_network_transport.hpp>
Expand Down
1 change: 1 addition & 0 deletions src/cpprealm/networking/platform_networking.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <cpprealm/networking/platform_networking.hpp>
#include <cpprealm/internal/bridge/realm.hpp>
#include <cpprealm/internal/networking/utils.hpp>

#include <realm/object-store/sync/generic_network_transport.hpp>
#include <realm/sync/network/default_socket.hpp>
Expand Down
1 change: 1 addition & 0 deletions tests/admin_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <thread>
#include <iostream>
#include <cpprealm/networking/platform_networking.hpp>
#include <cpprealm/internal/networking/utils.hpp>

#include "admin_utils.hpp"
#include "external/json/json.hpp"
Expand Down
5 changes: 4 additions & 1 deletion tests/sync/asymmetric_object_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ using namespace realm;
TEST_CASE("asymmetric object", "[sync]") {
SECTION("basic", "[sync]") {
auto asymmetric_app_id = Admin::Session::shared().create_app({}, "test", true);
auto app = realm::App(realm::App::configuration({asymmetric_app_id, Admin::Session::shared().base_url()}));
auto config = realm::App::configuration();
config.app_id = asymmetric_app_id;
config.base_url = Admin::Session::shared().base_url();
auto app = realm::App(config);
auto user = app.login(realm::App::credentials::anonymous()).get();
auto synced_realm = open<AllTypesAsymmetricObject, EmbeddedFoo>(user.flexible_sync_configuration());

Expand Down
3 changes: 3 additions & 0 deletions tests/sync/networking_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#include "test_objects.hpp"

#include "../utils/networking/proxy_server.hpp"
#include <cpprealm/internal/networking/utils.hpp>

#include <thread>

using namespace realm;

Expand Down

0 comments on commit f3eb217

Please sign in to comment.