<commit_before>////////////////////////////////////////////////////////////////////////////
//
// Copyright 2016 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.
//
////////////////////////////////////////////////////////////////////////////

#include <future>
#include <realm.hpp>
#include <realm/util/uri.hpp>
#include "error_handling.hpp"
#include "marshalling.hpp"
#include "realm_export_decls.hpp"
#include "shared_realm_cs.hpp"
#include "shared_realm.hpp"
#include "sync/sync_manager.hpp"
#include "sync/sync_user.hpp"
#include "sync/sync_config.hpp"
#include "sync/sync_session.hpp"

using namespace realm;
using namespace realm::binding;

using SharedSyncUser = std::shared_ptr<SyncUser>;

struct SyncConfiguration
{
    std::shared_ptr<SyncUser>* user;

    uint16_t* url;
    size_t url_len;
};

void (*s_refresh_access_token_callback)(std::shared_ptr<SyncUser>*, std::shared_ptr<SyncSession>*, const char* path, size_t path_len);
void (*s_session_error_callback)(std::shared_ptr<SyncSession>*, int32_t error_code, const char* message, size_t message_len, SyncSessionError);

static void bind_session(const std::string&, const realm::SyncConfig& config, std::shared_ptr<SyncSession> session)
{
    s_refresh_access_token_callback(new std::shared_ptr<SyncUser>(config.user), new std::shared_ptr<SyncSession>(session), config.realm_url.c_str(), config.realm_url.size());
}

static void handle_session_error(std::shared_ptr<SyncSession> session, int error_code, std::string message, SyncSessionError error)
{
    s_session_error_callback(new std::shared_ptr<SyncSession>(session), error_code, message.c_str(), message.length(), error);
}

extern "C" {
REALM_EXPORT void realm_syncmanager_configure_file_system(const uint16_t* base_path_buf, size_t base_path_len,
                                                          const SyncManager::MetadataMode* mode, const char* encryption_key_buf, bool reset_on_error,
                                                          NativeException::Marshallable& ex)
{
    handle_errors(ex, [&] {
        Utf16StringAccessor base_path(base_path_buf, base_path_len);

        auto metadata_mode = SyncManager::MetadataMode::NoEncryption;
        if (mode) {
            metadata_mode = *mode;
        } else {
#if REALM_PLATFORM_APPLE<commit_msg>Turn off sync metadata encryption on the iOS Simulator (#1066)<commit_after>////////////////////////////////////////////////////////////////////////////
//
// Copyright 2016 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.
//
////////////////////////////////////////////////////////////////////////////

#include <future>
#include <realm.hpp>
#include <realm/util/uri.hpp>
#include "error_handling.hpp"
#include "marshalling.hpp"
#include "realm_export_decls.hpp"
#include "shared_realm_cs.hpp"
#include "shared_realm.hpp"
#include "sync/sync_manager.hpp"
#include "sync/sync_user.hpp"
#include "sync/sync_config.hpp"
#include "sync/sync_session.hpp"

using namespace realm;
using namespace realm::binding;

using SharedSyncUser = std::shared_ptr<SyncUser>;

struct SyncConfiguration
{
    std::shared_ptr<SyncUser>* user;

    uint16_t* url;
    size_t url_len;
};

void (*s_refresh_access_token_callback)(std::shared_ptr<SyncUser>*, std::shared_ptr<SyncSession>*, const char* path, size_t path_len);
void (*s_session_error_callback)(std::shared_ptr<SyncSession>*, int32_t error_code, const char* message, size_t message_len, SyncSessionError);

static void bind_session(const std::string&, const realm::SyncConfig& config, std::shared_ptr<SyncSession> session)
{
    s_refresh_access_token_callback(new std::shared_ptr<SyncUser>(config.user), new std::shared_ptr<SyncSession>(session), config.realm_url.c_str(), config.realm_url.size());
}

static void handle_session_error(std::shared_ptr<SyncSession> session, int error_code, std::string message, SyncSessionError error)
{
    s_session_error_callback(new std::shared_ptr<SyncSession>(session), error_code, message.c_str(), message.length(), error);
}

extern "C" {
REALM_EXPORT void realm_syncmanager_configure_file_system(const uint16_t* base_path_buf, size_t base_path_len,
                                                          const SyncManager::MetadataMode* mode, const char* encryption_key_buf, bool reset_on_error,
                                                          NativeException::Marshallable& ex)
{
    handle_errors(ex, [&] {
        Utf16StringAccessor base_path(base_path_buf, base_path_len);

        auto metadata_mode = SyncManager::MetadataMode::NoEncryption;
        if (mode) {
            metadata_mode = *mode;
#if REALM_PLATFORM_APPLE && !TARGET_OS_SIMULATOR
        } else {
{'fraction_non_alphanumeric': 0.15579391594865483, 'fraction_numerical': 0.006330226833128187, 'mean_word_length': 3.3353658536585367, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3846591', 'n_tokens_mistral': 1648, 'n_tokens_neox': 1611, 'n_words': 421}