use std::sync::{Arc, Mutex};
use rusty_bind::binding_wrapper;
use uuid::Uuid;
use wildland_corex::api::{SfoError, SpecialFileOperations, SpecialFileType};
use wildland_corex::catlib_service::entities::{new_pub_key, PubKey, PubKeyError};
use wildland_corex::catlib_service::error::CatlibError;
use wildland_corex::dfs::interface::events::*;
use wildland_corex::dfs::interface::node_stat::NodeType;
use wildland_corex::dfs::interface::*;
use wildland_corex::dfs::unix_timestamp::UnixTimestamp;
use wildland_corex::{
ContainerManagerError,
CoreXError,
LocalSecureStorage,
LssError,
StorageTemplate,
StorageTemplateError,
};
use wildland_databases::error::ClientCreationError;
use crate::api::cargo_lib::*;
use crate::api::cargo_user::*;
use crate::api::config::*;
use crate::api::container::{
AddStorageError,
CargoContainer as Container,
CargoContainerFilter as ContainerFilter,
MountState,
Persistency,
SharingMessage,
};
use crate::api::foundation_storage::*;
use crate::api::storage::*;
use crate::api::user::*;
use crate::errors::user::*;
use crate::errors::{ErrorCategory, ExceptionTrait};
use crate::multidevice_state::error::MultideviceStateError;
mod wrapper {
use uuid::Uuid;
use wildland_corex::dfs::interface::{AbortFlag, IStreamResult, OStreamResult};
use wildland_corex::dfs::unix_timestamp::UnixTimestamp;
use wildland_dfs::StreamErr;
use super::{ContainerFilter, WlPermissions};
pub(crate) fn readonly_wl_permissions() -> WlPermissions {
WlPermissions::readonly()
}
pub(crate) fn read_write_wl_permissions() -> WlPermissions {
WlPermissions::read_write()
}
pub(crate) fn has_exact_path(path: String) -> ContainerFilter {
ContainerFilter::has_exact_path(path)
}
pub(crate) fn has_path_starting_with(path: String) -> ContainerFilter {
ContainerFilter::has_path_starting_with(path)
}
pub(crate) fn or_filter(f1: ContainerFilter, f2: ContainerFilter) -> ContainerFilter {
ContainerFilter::or(f1, f2)
}
pub(crate) fn and_filter(f1: ContainerFilter, f2: ContainerFilter) -> ContainerFilter {
ContainerFilter::and(f1, f2)
}
pub(crate) fn not_filter(f: ContainerFilter) -> ContainerFilter {
ContainerFilter::not(f)
}
pub(crate) fn unix_timestamp_now() -> UnixTimestamp {
UnixTimestamp::now()
}
pub(crate) fn unix_timestamp_from_nanos(nanos: u64) -> UnixTimestamp {
UnixTimestamp::from_nanos(nanos)
}
pub(crate) fn ok_istream_result(bytes: Vec<u8>) -> IStreamResult {
Ok(bytes)
}
pub(crate) fn err_istream_result(code: i32, msg: String) -> IStreamResult {
Err(StreamErr { code, msg })
}
pub(crate) fn ok_ostream_result() -> OStreamResult {
Ok(())
}
pub(crate) fn err_ostream_result(code: i32, msg: String) -> OStreamResult {
Err(StreamErr { code, msg })
}
pub(crate) fn new_abort_flag() -> AbortFlag {
AbortFlag::new()
}
pub(crate) fn uuid_from_string(uuid: String) -> Uuid {
Uuid::parse_str(&uuid).unwrap()
}
}
use self::wrapper::*;
type VoidType = ();
#[cfg_attr(
feature = "bindings",
binding_wrapper(source = "../../_generated_ffi_code/interface.rs")
)]
mod ffi_binding {
enum ErrorCategory {
General,
NetworkConnectivity,
Database,
Logical,
Cryptography,
Auth,
ExternalService,
InvalidInputFormat,
Dfs,
}
extern "ExceptionTrait" {
fn reason(&self) -> String;
fn category(&self) -> ErrorCategory;
}
enum CoreXError {
CannotCreateForestIdentityError(_),
IdentityReadError(_),
LSSErr(_),
CatlibErr(_),
CryptoErr(_),
Generic(_),
}
enum UserCreationError {
UserAlreadyExists,
UserRetrievalError(_),
CryptoError(_),
ForestIdentityCreationError(_),
LssError(_),
CatlibError(_),
}
enum UserRetrievalError {
ForestRetrievalError(_),
ForestNotFound(_),
LssError(_),
CatlibError(_),
DeviceMetadataNotFound,
UserNotFound,
}
enum FsaError {
EvsError(_),
CryptoError(_),
UnexpectedResponse(_),
LssError(_),
CatlibError(_),
StorageTemplateError(_),
ConnectivityIssue(_),
}
enum StorageTemplateError {
SerdeErr(_),
TemplateEngineErr(_),
}
enum LssError {
Error(_),
}
enum SfoError {
Generic(_),
FileExists,
FileNotFound,
}
enum ParseConfigError {
IncorrectRedisURL(_),
Error(_),
}
enum CreateMnemonicError {
InvalidMnemonicWords,
}
enum CatlibError {
NoRecordsFound,
RecordAlreadyExists,
DatabaseIoError(_),
DatabaseUnknownError(_),
DatabaseAuthError(_),
DatabaseServerError(_),
InvalidDataError(_),
}
enum ContainerManagerError {
AlreadyMounted,
MountingError(_),
ContainerNotMounted,
NoValidStorages,
}
enum FoundationCloudMode {
Dev,
}
enum DfsFrontendError {
NotAFile,
NotADirectory,
NoSuchPath,
PathResolutionError(_),
PathAlreadyExists,
InvalidParent,
StorageNotResponsive(_),
InsufficientQuota(_),
ReadOnlyPath,
DirNotEmpty,
Generic(_),
MoveBetweenContainers,
SourceIsParentOfTarget,
Aborted,
NotSupported,
PathConflict(_),
Encryption(_),
PermissionError(_),
}
enum AddStorageError {
CatlibErr(_),
StorageTemplateError(_),
}
enum MultideviceStateError {
IoError(_),
Unknown(_),
Authentication(_),
Server(_),
}
enum ClientCreationError {
Unknown(_),
Authentication(_),
IoError(_),
}
enum AutomountError {
MountedContainersDetected,
MultideviceStateError(_),
ContainerManagerError(_),
CatlibError(_),
}
enum QuotaControlError {
CoreXError(_),
DfsFrontendError(_),
}
enum SharingError {
Generic(_),
}
enum PubKeyError {
KeySizeMismatch,
}
enum NodeType {
File,
Dir,
Symlink,
Other,
}
enum MountState {
Mounted,
Unmounted,
MountedOrUnmounted,
}
enum Persistency {
GloballyPersistent,
LocallyPersistent,
}
enum FileSystemOperation {
GetInfo,
}
enum DfsCause {
UnsupportedBackendType,
UnresponsiveBackend,
AllBackendsUnresponsive,
BackendDoesNotSupportOperation,
InsufficientQuota,
PermissionError,
}
enum ProgressUnit {
Bytes,
}
enum SpecialFileType {
Data,
Cache,
Temporary,
}
extern "Traits" {
fn get_use_logger(self: &dyn CargoCfgProvider) -> bool;
fn get_log_level(self: &dyn CargoCfgProvider) -> String;
fn get_log_use_ansi(self: &dyn CargoCfgProvider) -> bool;
fn get_log_file_enabled(self: &dyn CargoCfgProvider) -> bool;
fn get_log_file_path(self: &dyn CargoCfgProvider) -> Option<String>;
fn get_log_file_rotate_directory(self: &dyn CargoCfgProvider) -> Option<String>;
#[cfg(any(target_os = "macos", target_os = "ios"))]
fn get_oslog_category(self: &dyn CargoCfgProvider) -> Option<String>;
#[cfg(any(target_os = "macos", target_os = "ios"))]
fn get_oslog_subsystem(self: &dyn CargoCfgProvider) -> Option<String>;
fn get_foundation_cloud_env_mode(self: &dyn CargoCfgProvider) -> FoundationCloudMode;
fn get_catlib_gql_url(self: &dyn CargoCfgProvider) -> String;
fn get_redis_url_for_multidevice_state(self: &dyn CargoCfgProvider) -> String;
fn insert(
self: &dyn LocalSecureStorage,
key: String,
value: String,
) -> Result<Option<String>, LssError>;
fn get(self: &dyn LocalSecureStorage, key: String) -> Result<Option<String>, LssError>;
fn contains_key(self: &dyn LocalSecureStorage, key: String) -> Result<bool, LssError>;
fn keys(self: &dyn LocalSecureStorage) -> Result<Vec<String>, LssError>;
fn keys_starting_with(
self: &dyn LocalSecureStorage,
prefix: String,
) -> Result<Vec<String>, LssError>;
fn remove(self: &dyn LocalSecureStorage, key: String) -> Result<Option<String>, LssError>;
fn len(self: &dyn LocalSecureStorage) -> Result<usize, LssError>;
fn is_empty(self: &dyn LocalSecureStorage) -> Result<bool, LssError>;
fn write(self: &mut dyn OStream, bytes: Vec<u8>) -> OStreamResult;
fn read(self: &mut dyn IStream, bytes_count: usize) -> IStreamResult;
fn total_size(self: &dyn IStream) -> usize;
fn report(self: &dyn ProgressReporter, completed: usize, total: usize, unit: ProgressUnit);
fn create_special_file(
self: &mut dyn SpecialFileOperations,
file_name: String,
file_type: SpecialFileType,
input: Option<Vec<u8>>,
) -> Result<VoidType, SfoError>;
fn remove_special_file(
self: &mut dyn SpecialFileOperations,
file_name: String,
file_type: SpecialFileType,
) -> Result<VoidType, SfoError>;
fn write_to_special_file(
self: &dyn SpecialFileOperations,
file_name: String,
file_type: SpecialFileType,
contents: Vec<u8>,
append: bool,
) -> Result<VoidType, SfoError>;
fn read_from_special_file(
self: &dyn SpecialFileOperations,
file_name: String,
file_type: SpecialFileType,
) -> Result<Vec<u8>, SfoError>;
fn get_special_file_path(
self: &dyn SpecialFileOperations,
file_name: String,
file_type: SpecialFileType,
) -> Result<String, SfoError>;
}
extern "Rust" {
type VoidType;
fn parse_config(raw_content: Vec<u8>) -> Result<CargoConfig, ParseConfigError>;
fn collect_config(
config_provider: Box<dyn CargoCfgProvider>,
) -> Result<CargoConfig, ParseConfigError>;
fn override_evs_url(self: &mut CargoConfig, new_evs_url: String);
fn create_cargo_lib(
lss: Box<dyn LocalSecureStorage>,
config: CargoConfig,
) -> Result<Arc<Mutex<CargoLib>>, ClientCreationError>;
fn dfs_api(self: &Arc<Mutex<CargoLib>>) -> Arc<dyn DfsFrontend>;
fn user_api(self: &Arc<Mutex<CargoLib>>) -> UserApi;
fn storage_template_from_json(
self: &Arc<Mutex<CargoLib>>,
content: Vec<u8>,
) -> Result<StorageTemplate, StorageTemplateError>;
fn storage_template_from_yaml(
self: &Arc<Mutex<CargoLib>>,
content: Vec<u8>,
) -> Result<StorageTemplate, StorageTemplateError>;
fn generate_mnemonic(self: &UserApi) -> Result<MnemonicPayload, CreateMnemonicError>;
fn create_mnemonic_from_vec(
self: &UserApi,
words: Vec<String>,
) -> Result<MnemonicPayload, CreateMnemonicError>;
fn create_mnemonic_from_string(
self: &UserApi,
mnemonic_str: String,
) -> Result<MnemonicPayload, CreateMnemonicError>;
fn create_user_from_entropy(
self: &UserApi,
entropy: Vec<u8>,
device_name: String,
) -> Result<CargoUser, UserCreationError>;
fn create_user_from_mnemonic(
self: &UserApi,
mnemonic: &MnemonicPayload,
device_name: String,
) -> Result<CargoUser, UserCreationError>;
fn get_user(self: &UserApi) -> Result<CargoUser, UserRetrievalError>;
fn stringify(self: &MnemonicPayload) -> String;
fn get_vec(self: &MnemonicPayload) -> Vec<String>;
type ContainerFilter;
fn has_exact_path(path: String) -> ContainerFilter;
fn has_path_starting_with(path: String) -> ContainerFilter;
fn or_filter(f1: ContainerFilter, f2: ContainerFilter) -> ContainerFilter;
fn and_filter(f1: ContainerFilter, f2: ContainerFilter) -> ContainerFilter;
fn not_filter(f: ContainerFilter) -> ContainerFilter;
fn stringify(self: &CargoUser) -> String;
fn find_containers(
self: &CargoUser,
filters: Option<ContainerFilter>,
mount_state: MountState,
) -> Result<Vec<Container>, CatlibError>;
fn create_container(
self: &CargoUser,
name: String,
storage_templates: &StorageTemplate,
path: String,
encrypted: bool,
) -> Result<Container, CoreXError>;
fn get_storage_templates(self: &CargoUser) -> Result<Vec<StorageTemplate>, CatlibError>;
fn save_storage_template(
self: &CargoUser,
tpl: &mut StorageTemplate,
) -> Result<String, CatlibError>;
fn automount(self: &CargoUser) -> Result<VoidType, AutomountError>;
fn share(
self: &CargoUser,
wildland_object_id: String,
pub_key: PubKey,
) -> Result<SharingMessage, SharingError>;
fn add_shared_container(
self: &CargoUser,
sharing_message: SharingMessage,
path: String,
) -> Result<VoidType, SharingError>;
fn revoke_sharing(
self: &CargoUser,
wildland_object_id: String,
pub_key: PubKey,
) -> Result<VoidType, SharingError>;
fn get_pubkeys_having_access_to_object(
self: &CargoUser,
wildland_object_id: String,
) -> Result<Vec<PubKey>, SharingError>;
type FreeTierProcessHandle;
fn request_free_tier_storage(
self: &CargoUser,
email: String,
) -> Result<FreeTierProcessHandle, FsaError>;
fn verify_email(
self: &CargoUser,
process_handle: &FreeTierProcessHandle,
verification_token: String,
) -> Result<StorageTemplate, FsaError>;
fn is_free_storage_granted(self: &CargoUser) -> Result<bool, CatlibError>;
fn get_user_public_key(self: &CargoUser) -> Vec<u8>;
type SharingMessage;
fn to_vec(self: &PubKey) -> Vec<u8>;
fn new_pub_key(input: Vec<u8>) -> Result<PubKey, PubKeyError>;
fn get_storages(self: &Container) -> Result<Vec<ContainerStorage>, CoreXError>;
fn add_storage(
self: &mut Container,
templates: &StorageTemplate,
) -> Result<ContainerStorage, AddStorageError>;
fn remove_storage(self: &mut Container, uuid: &Uuid) -> Result<VoidType, CoreXError>;
fn change_path(self: &Container, path: String) -> Result<VoidType, CatlibError>;
fn get_path(self: &Container) -> Result<String, CatlibError>;
fn set_name(self: &mut Container, new_name: String) -> Result<VoidType, CatlibError>;
fn remove(self: &Container) -> Result<VoidType, CatlibError>;
fn name(self: &Container) -> Result<String, CatlibError>;
fn mount(
self: &Container,
persistency: Option<Persistency>,
) -> Result<VoidType, ContainerManagerError>;
fn unmount(
self: &Container,
persistency: Option<Persistency>,
) -> Result<VoidType, ContainerManagerError>;
fn is_mounted(self: &Container) -> bool;
fn is_automounted(self: &Container) -> Result<bool, MultideviceStateError>;
fn set_persistency(
self: &Container,
persistency: Persistency,
) -> Result<VoidType, MultideviceStateError>;
fn unset_persistency(
self: &Container,
persistency: Persistency,
) -> Result<VoidType, MultideviceStateError>;
fn backend_type(self: &ContainerStorage) -> String;
fn name(self: &ContainerStorage) -> Option<String>;
fn uuid(self: &ContainerStorage) -> Uuid;
fn get_space_usage(self: &ContainerStorage) -> Result<SpaceUsage, QuotaControlError>;
fn is_accessible(self: &ContainerStorage) -> Result<bool, CoreXError>;
fn to_json(self: &StorageTemplate) -> Result<String, StorageTemplateError>;
fn to_yaml(self: &StorageTemplate) -> Result<String, StorageTemplateError>;
fn set_name(self: &mut StorageTemplate, name: String) -> VoidType;
fn backend_type(self: &StorageTemplate) -> String;
fn name(self: &StorageTemplate) -> Option<String>;
fn read_dir(
self: &Arc<dyn DfsFrontend>,
path: String,
) -> Result<Vec<DirEntry>, DfsFrontendError>;
fn metadata(
self: &Arc<dyn DfsFrontend>,
path: String,
) -> Result<NodeStat, DfsFrontendError>;
fn get_path(
self: &Arc<dyn DfsFrontend>,
identifier: String,
) -> Result<String, DfsFrontendError>;
fn remove_file(
self: &Arc<dyn DfsFrontend>,
path: String,
) -> Result<VoidType, DfsFrontendError>;
fn rename(
self: &Arc<dyn DfsFrontend>,
old_path: String,
new_path: String,
) -> Result<VoidType, DfsFrontendError>;
fn set_permissions(
self: &Arc<dyn DfsFrontend>,
path: String,
permissions: WlPermissions,
) -> Result<VoidType, DfsFrontendError>;
fn set_owner(
self: &Arc<dyn DfsFrontend>,
path: String,
) -> Result<VoidType, DfsFrontendError>;
fn create_dir(
self: &Arc<dyn DfsFrontend>,
requested_path: String,
) -> Result<VoidType, DfsFrontendError>;
fn remove_dir(
self: &Arc<dyn DfsFrontend>,
requested_path: String,
is_recursive: bool,
) -> Result<VoidType, DfsFrontendError>;
fn stat_fs(self: &Arc<dyn DfsFrontend>, path: String) -> Result<FsStat, DfsFrontendError>;
fn get_receiver(self: &Arc<dyn DfsFrontend>) -> Arc<Mutex<dyn EventReceiver>>;
fn download(
self: &Arc<dyn DfsFrontend>,
path: String,
output: Box<dyn OStream>,
progress_reporter: Box<dyn ProgressReporter>,
abort_flag: &AbortFlag,
) -> Result<VoidType, DfsFrontendError>;
fn upload(
self: &Arc<dyn DfsFrontend>,
path: String,
input: Box<dyn IStream>,
progress_reporter: Box<dyn ProgressReporter>,
abort_flag: &AbortFlag,
creation_time: Option<UnixTimestamp>,
) -> Result<VoidType, DfsFrontendError>;
fn new_abort_flag() -> AbortFlag;
fn set(self: &AbortFlag);
type OStreamResult;
fn ok_ostream_result() -> OStreamResult;
fn err_ostream_result(code: i32, message: String) -> OStreamResult;
type IStreamResult;
fn ok_istream_result(bytes: Vec<u8>) -> IStreamResult;
fn err_istream_result(code: i32, message: String) -> IStreamResult;
fn recv(self: &Arc<Mutex<dyn EventReceiver>>) -> Option<Event>;
fn get_cause(self: &Event) -> DfsCause;
fn get_operation(self: &Event) -> Option<FileSystemOperation>;
fn get_operation_path(self: &Event) -> Option<String>;
fn get_backend_type(self: &Event) -> Option<String>;
fn node_type(self: &NodeStat) -> NodeType;
fn size(self: &NodeStat) -> usize;
fn modification_time(self: &NodeStat) -> Option<UnixTimestamp>;
fn change_time(self: &NodeStat) -> Option<UnixTimestamp>;
fn creation_time(self: &NodeStat) -> Option<UnixTimestamp>;
fn wildland_object_id(self: &NodeStat) -> String;
fn to_string(self: &Uuid) -> String;
fn uuid_from_string(uuid: String) -> Uuid;
fn sec(self: &UnixTimestamp) -> u64;
fn nano_sec(self: &UnixTimestamp) -> u32;
fn unix_timestamp_now() -> UnixTimestamp;
fn unix_timestamp_from_nanos(nanos: u64) -> UnixTimestamp;
fn filesystem_type(self: &FsStat) -> String;
fn block_size(self: &FsStat) -> Option<u64>;
fn blocks(self: &FsStat) -> Option<u64>;
fn free_blocks(self: &FsStat) -> Option<u64>;
fn blocks_available(self: &FsStat) -> Option<u64>;
fn nodes(self: &FsStat) -> Option<u64>;
fn name_length(self: &FsStat) -> Option<u64>;
fn is_readonly(self: &WlPermissions) -> bool;
fn set_readonly(self: &mut WlPermissions, readonly: bool);
fn readonly_wl_permissions() -> WlPermissions;
fn read_write_wl_permissions() -> WlPermissions;
fn item_name(self: &DirEntry) -> String;
fn stat(self: &DirEntry) -> NodeStat;
fn get_used_space(self: &SpaceUsage) -> u64;
fn get_total_space(self: &SpaceUsage) -> u64;
}
}