diff options
Diffstat (limited to 'rust/src/collaboration')
| -rw-r--r-- | rust/src/collaboration/changeset.rs | 4 | ||||
| -rw-r--r-- | rust/src/collaboration/file.rs | 56 | ||||
| -rw-r--r-- | rust/src/collaboration/folder.rs | 16 | ||||
| -rw-r--r-- | rust/src/collaboration/group.rs | 8 | ||||
| -rw-r--r-- | rust/src/collaboration/merge.rs | 8 | ||||
| -rw-r--r-- | rust/src/collaboration/permission.rs | 8 | ||||
| -rw-r--r-- | rust/src/collaboration/project.rs | 20 | ||||
| -rw-r--r-- | rust/src/collaboration/remote.rs | 16 | ||||
| -rw-r--r-- | rust/src/collaboration/snapshot.rs | 36 | ||||
| -rw-r--r-- | rust/src/collaboration/sync.rs | 9 | ||||
| -rw-r--r-- | rust/src/collaboration/undo.rs | 4 | ||||
| -rw-r--r-- | rust/src/collaboration/user.rs | 20 |
12 files changed, 101 insertions, 104 deletions
diff --git a/rust/src/collaboration/changeset.rs b/rust/src/collaboration/changeset.rs index 9d7cdb7c..fd862df6 100644 --- a/rust/src/collaboration/changeset.rs +++ b/rust/src/collaboration/changeset.rs @@ -59,10 +59,10 @@ impl Changeset { } /// Changeset name - pub fn name(&self) -> BnString { + pub fn name(&self) -> String { let result = unsafe { BNCollaborationChangesetGetName(self.handle.as_ptr()) }; assert!(!result.is_null()); - unsafe { BnString::from_raw(result) } + unsafe { BnString::into_string(result) } } /// Set the name of the changeset, e.g. in a name changeset function. diff --git a/rust/src/collaboration/file.rs b/rust/src/collaboration/file.rs index 2651d3c7..678c0c15 100644 --- a/rust/src/collaboration/file.rs +++ b/rust/src/collaboration/file.rs @@ -106,30 +106,30 @@ impl RemoteFile { } /// Web API endpoint URL - pub fn url(&self) -> BnString { + pub fn url(&self) -> String { let result = unsafe { BNRemoteFileGetUrl(self.handle.as_ptr()) }; assert!(!result.is_null()); - unsafe { BnString::from_raw(result) } + unsafe { BnString::into_string(result) } } /// Chat log API endpoint URL - pub fn chat_log_url(&self) -> BnString { + pub fn chat_log_url(&self) -> String { let result = unsafe { BNRemoteFileGetChatLogUrl(self.handle.as_ptr()) }; assert!(!result.is_null()); - unsafe { BnString::from_raw(result) } + unsafe { BnString::into_string(result) } } - pub fn user_positions_url(&self) -> BnString { + pub fn user_positions_url(&self) -> String { let result = unsafe { BNRemoteFileGetUserPositionsUrl(self.handle.as_ptr()) }; assert!(!result.is_null()); - unsafe { BnString::from_raw(result) } + unsafe { BnString::into_string(result) } } /// Unique ID - pub fn id(&self) -> BnString { + pub fn id(&self) -> String { let result = unsafe { BNRemoteFileGetId(self.handle.as_ptr()) }; assert!(!result.is_null()); - unsafe { BnString::from_raw(result) } + unsafe { BnString::into_string(result) } } /// All files share the same properties, but files with different types may make different @@ -144,10 +144,10 @@ impl RemoteFile { crate::ffi::time_from_bn(result.try_into().unwrap()) } - pub fn created_by(&self) -> BnString { + pub fn created_by(&self) -> String { let result = unsafe { BNRemoteFileGetCreatedBy(self.handle.as_ptr()) }; assert!(!result.is_null()); - unsafe { BnString::from_raw(result) } + unsafe { BnString::into_string(result) } } /// Last modified of the file @@ -163,30 +163,30 @@ impl RemoteFile { } /// Username of user who pushed the last snapshot in the file - pub fn last_snapshot_by(&self) -> BnString { + pub fn last_snapshot_by(&self) -> String { let result = unsafe { BNRemoteFileGetLastSnapshotBy(self.handle.as_ptr()) }; assert!(!result.is_null()); - unsafe { BnString::from_raw(result) } + unsafe { BnString::into_string(result) } } - pub fn last_snapshot_name(&self) -> BnString { + pub fn last_snapshot_name(&self) -> String { let result = unsafe { BNRemoteFileGetLastSnapshotName(self.handle.as_ptr()) }; assert!(!result.is_null()); - unsafe { BnString::from_raw(result) } + unsafe { BnString::into_string(result) } } /// Hash of file contents (no algorithm guaranteed) - pub fn hash(&self) -> BnString { + pub fn hash(&self) -> String { let result = unsafe { BNRemoteFileGetHash(self.handle.as_ptr()) }; assert!(!result.is_null()); - unsafe { BnString::from_raw(result) } + unsafe { BnString::into_string(result) } } /// Displayed name of file - pub fn name(&self) -> BnString { + pub fn name(&self) -> String { let result = unsafe { BNRemoteFileGetName(self.handle.as_ptr()) }; assert!(!result.is_null()); - unsafe { BnString::from_raw(result) } + unsafe { BnString::into_string(result) } } /// Set the description of the file. You will need to push the file to update the remote version. @@ -202,10 +202,10 @@ impl RemoteFile { } /// Desciprtion of the file - pub fn description(&self) -> BnString { + pub fn description(&self) -> String { let result = unsafe { BNRemoteFileGetDescription(self.handle.as_ptr()) }; assert!(!result.is_null()); - unsafe { BnString::from_raw(result) } + unsafe { BnString::into_string(result) } } /// Set the description of the file. You will need to push the file to update the remote version. @@ -220,10 +220,10 @@ impl RemoteFile { success.then_some(()).ok_or(()) } - pub fn metadata(&self) -> BnString { + pub fn metadata(&self) -> String { let result = unsafe { BNRemoteFileGetMetadata(self.handle.as_ptr()) }; assert!(!result.is_null()); - unsafe { BnString::from_raw(result) } + unsafe { BnString::into_string(result) } } /// Size of raw content of file, in bytes @@ -234,10 +234,10 @@ impl RemoteFile { /// Get the default filepath for a remote File. This is based off the Setting for /// collaboration.directory, the file's id, the file's project's id, and the file's /// remote's id. - pub fn default_path(&self) -> BnString { + pub fn default_path(&self) -> String { let result = unsafe { BNCollaborationDefaultFilePath(self.handle.as_ptr()) }; assert!(!result.is_null()); - unsafe { BnString::from_raw(result) } + unsafe { BnString::into_string(result) } } /// If the file has pulled the snapshots yet @@ -410,16 +410,16 @@ impl RemoteFile { // todo!() //} - pub fn request_user_positions(&self) -> BnString { + pub fn request_user_positions(&self) -> String { let result = unsafe { BNRemoteFileRequestUserPositions(self.handle.as_ptr()) }; assert!(!result.is_null()); - unsafe { BnString::from_raw(result) } + unsafe { BnString::into_string(result) } } - pub fn request_chat_log(&self) -> BnString { + pub fn request_chat_log(&self) -> String { let result = unsafe { BNRemoteFileRequestChatLog(self.handle.as_ptr()) }; assert!(!result.is_null()); - unsafe { BnString::from_raw(result) } + unsafe { BnString::into_string(result) } } // TODO: AsRef<Path> diff --git a/rust/src/collaboration/folder.rs b/rust/src/collaboration/folder.rs index 90a85f1c..eb4fd9f8 100644 --- a/rust/src/collaboration/folder.rs +++ b/rust/src/collaboration/folder.rs @@ -76,17 +76,17 @@ impl RemoteFolder { } /// Get web API endpoint URL. - pub fn url(&self) -> BnString { + pub fn url(&self) -> String { let result = unsafe { BNRemoteFolderGetUrl(self.handle.as_ptr()) }; assert!(!result.is_null()); - unsafe { BnString::from_raw(result) } + unsafe { BnString::into_string(result) } } /// Get unique ID. - pub fn id(&self) -> BnString { + pub fn id(&self) -> String { let result = unsafe { BNRemoteFolderGetId(self.handle.as_ptr()) }; assert!(!result.is_null()); - unsafe { BnString::from_raw(result) } + unsafe { BnString::into_string(result) } } /// Unique id of parent folder, if there is a parent. None, otherwise @@ -97,10 +97,10 @@ impl RemoteFolder { } /// Displayed name of folder - pub fn name(&self) -> BnString { + pub fn name(&self) -> String { let result = unsafe { BNRemoteFolderGetName(self.handle.as_ptr()) }; assert!(!result.is_null()); - unsafe { BnString::from_raw(result) } + unsafe { BnString::into_string(result) } } /// Set the display name of the folder. You will need to push the folder to update the remote version. @@ -116,10 +116,10 @@ impl RemoteFolder { } /// Description of the folder - pub fn description(&self) -> BnString { + pub fn description(&self) -> String { let result = unsafe { BNRemoteFolderGetDescription(self.handle.as_ptr()) }; assert!(!result.is_null()); - unsafe { BnString::from_raw(result) } + unsafe { BnString::into_string(result) } } /// Set the description of the folder. You will need to push the folder to update the remote version. diff --git a/rust/src/collaboration/group.rs b/rust/src/collaboration/group.rs index bad09d6c..9fb287a7 100644 --- a/rust/src/collaboration/group.rs +++ b/rust/src/collaboration/group.rs @@ -30,10 +30,10 @@ impl RemoteGroup { } /// Web api endpoint url - pub fn url(&self) -> BnString { + pub fn url(&self) -> String { let value = unsafe { BNCollaborationGroupGetUrl(self.handle.as_ptr()) }; assert!(!value.is_null()); - unsafe { BnString::from_raw(value) } + unsafe { BnString::into_string(value) } } /// Unique id @@ -42,10 +42,10 @@ impl RemoteGroup { } /// Group name - pub fn name(&self) -> BnString { + pub fn name(&self) -> String { let value = unsafe { BNCollaborationGroupGetName(self.handle.as_ptr()) }; assert!(!value.is_null()); - unsafe { BnString::from_raw(value) } + unsafe { BnString::into_string(value) } } /// Set group name diff --git a/rust/src/collaboration/merge.rs b/rust/src/collaboration/merge.rs index 2d28725c..68bfdc02 100644 --- a/rust/src/collaboration/merge.rs +++ b/rust/src/collaboration/merge.rs @@ -108,18 +108,18 @@ impl MergeConflict { /// String representing the type name of the data, not the same as data_type. /// This is like "typeName" or "tag" depending on what object the conflict represents. - pub fn conflict_type(&self) -> BnString { + pub fn conflict_type(&self) -> String { let result = unsafe { BNAnalysisMergeConflictGetType(self.handle.as_ptr()) }; assert!(!result.is_null()); - unsafe { BnString::from_raw(result) } + unsafe { BnString::into_string(result) } } /// Lookup key for the merge conflict, ideally a tree path that contains the name of the conflict /// and all the recursive children leading up to this conflict. - pub fn key(&self) -> BnString { + pub fn key(&self) -> String { let result = unsafe { BNAnalysisMergeConflictGetKey(self.handle.as_ptr()) }; assert!(!result.is_null()); - unsafe { BnString::from_raw(result) } + unsafe { BnString::into_string(result) } } /// Call this when you've resolved the conflict to save the result diff --git a/rust/src/collaboration/permission.rs b/rust/src/collaboration/permission.rs index 99a7a4f2..76b1eba3 100644 --- a/rust/src/collaboration/permission.rs +++ b/rust/src/collaboration/permission.rs @@ -37,17 +37,17 @@ impl Permission { } /// Web api endpoint url - pub fn url(&self) -> BnString { + pub fn url(&self) -> String { let value = unsafe { BNCollaborationPermissionGetUrl(self.handle.as_ptr()) }; assert!(!value.is_null()); - unsafe { BnString::from_raw(value) } + unsafe { BnString::into_string(value) } } /// unique id - pub fn id(&self) -> BnString { + pub fn id(&self) -> String { let value = unsafe { BNCollaborationPermissionGetId(self.handle.as_ptr()) }; assert!(!value.is_null()); - unsafe { BnString::from_raw(value) } + unsafe { BnString::into_string(value) } } /// Level of permission diff --git a/rust/src/collaboration/project.rs b/rust/src/collaboration/project.rs index 1455f6c3..b3c6513d 100644 --- a/rust/src/collaboration/project.rs +++ b/rust/src/collaboration/project.rs @@ -103,17 +103,17 @@ impl RemoteProject { } /// Get the URL of the project - pub fn url(&self) -> BnString { + pub fn url(&self) -> String { let result = unsafe { BNRemoteProjectGetUrl(self.handle.as_ptr()) }; assert!(!result.is_null()); - unsafe { BnString::from_raw(result) } + unsafe { BnString::into_string(result) } } /// Get the unique ID of the project - pub fn id(&self) -> BnString { + pub fn id(&self) -> String { let result = unsafe { BNRemoteProjectGetId(self.handle.as_ptr()) }; assert!(!result.is_null()); - unsafe { BnString::from_raw(result) } + unsafe { BnString::into_string(result) } } /// Created date of the project @@ -129,10 +129,10 @@ impl RemoteProject { } /// Displayed name of file - pub fn name(&self) -> BnString { + pub fn name(&self) -> String { let result = unsafe { BNRemoteProjectGetName(self.handle.as_ptr()) }; assert!(!result.is_null()); - unsafe { BnString::from_raw(result) } + unsafe { BnString::into_string(result) } } /// Set the description of the file. You will need to push the file to update the remote version. @@ -148,10 +148,10 @@ impl RemoteProject { } /// Desciprtion of the file - pub fn description(&self) -> BnString { + pub fn description(&self) -> String { let result = unsafe { BNRemoteProjectGetDescription(self.handle.as_ptr()) }; assert!(!result.is_null()); - unsafe { BnString::from_raw(result) } + unsafe { BnString::into_string(result) } } /// Set the description of the file. You will need to push the file to update the remote version. @@ -879,9 +879,9 @@ impl RemoteProject { /// Get the default directory path for a remote Project. This is based off /// the Setting for collaboration.directory, the project's id, and the /// project's remote's id. - pub fn default_project_path(&self) -> BnString { + pub fn default_project_path(&self) -> String { let result = unsafe { BNCollaborationDefaultProjectPath(self.handle.as_ptr()) }; - unsafe { BnString::from_raw(result) } + unsafe { BnString::into_string(result) } } /// Upload a file, with database, to the remote under the given project diff --git a/rust/src/collaboration/remote.rs b/rust/src/collaboration/remote.rs index c1250403..98784ddb 100644 --- a/rust/src/collaboration/remote.rs +++ b/rust/src/collaboration/remote.rs @@ -65,17 +65,17 @@ impl Remote { } /// Gets the name of the remote. - pub fn name(&self) -> BnString { + pub fn name(&self) -> String { let result = unsafe { BNRemoteGetName(self.handle.as_ptr()) }; assert!(!result.is_null()); - unsafe { BnString::from_raw(result) } + unsafe { BnString::into_string(result) } } /// Gets the address of the remote. - pub fn address(&self) -> BnString { + pub fn address(&self) -> String { let result = unsafe { BNRemoteGetAddress(self.handle.as_ptr()) }; assert!(!result.is_null()); - unsafe { BnString::from_raw(result) } + unsafe { BnString::into_string(result) } } /// Checks if the remote is connected. @@ -84,17 +84,17 @@ impl Remote { } /// Gets the username used to connect to the remote. - pub fn username(&self) -> BnString { + pub fn username(&self) -> String { let result = unsafe { BNRemoteGetUsername(self.handle.as_ptr()) }; assert!(!result.is_null()); - unsafe { BnString::from_raw(result) } + unsafe { BnString::into_string(result) } } /// Gets the token used to connect to the remote. - pub fn token(&self) -> BnString { + pub fn token(&self) -> String { let result = unsafe { BNRemoteGetToken(self.handle.as_ptr()) }; assert!(!result.is_null()); - unsafe { BnString::from_raw(result) } + unsafe { BnString::into_string(result) } } /// Gets the server version. If metadata has not been pulled, it will be pulled upon calling this. diff --git a/rust/src/collaboration/snapshot.rs b/rust/src/collaboration/snapshot.rs index 9f8f3693..935b1c2f 100644 --- a/rust/src/collaboration/snapshot.rs +++ b/rust/src/collaboration/snapshot.rs @@ -54,52 +54,52 @@ impl RemoteSnapshot { } /// Web api endpoint url - pub fn url(&self) -> BnString { + pub fn url(&self) -> String { let value = unsafe { BNCollaborationSnapshotGetUrl(self.handle.as_ptr()) }; assert!(!value.is_null()); - unsafe { BnString::from_raw(value) } + unsafe { BnString::into_string(value) } } /// Unique id - pub fn id(&self) -> BnString { + pub fn id(&self) -> String { let value = unsafe { BNCollaborationSnapshotGetId(self.handle.as_ptr()) }; assert!(!value.is_null()); - unsafe { BnString::from_raw(value) } + unsafe { BnString::into_string(value) } } /// Name of snapshot - pub fn name(&self) -> BnString { + pub fn name(&self) -> String { let value = unsafe { BNCollaborationSnapshotGetName(self.handle.as_ptr()) }; assert!(!value.is_null()); - unsafe { BnString::from_raw(value) } + unsafe { BnString::into_string(value) } } /// Get the title of a snapshot: the first line of its name - pub fn title(&self) -> BnString { + pub fn title(&self) -> String { let value = unsafe { BNCollaborationSnapshotGetTitle(self.handle.as_ptr()) }; assert!(!value.is_null()); - unsafe { BnString::from_raw(value) } + unsafe { BnString::into_string(value) } } /// Get the description of a snapshot: the lines of its name after the first line - pub fn description(&self) -> BnString { + pub fn description(&self) -> String { let value = unsafe { BNCollaborationSnapshotGetDescription(self.handle.as_ptr()) }; assert!(!value.is_null()); - unsafe { BnString::from_raw(value) } + unsafe { BnString::into_string(value) } } /// Get the user id of the author of a snapshot - pub fn author(&self) -> BnString { + pub fn author(&self) -> String { let value = unsafe { BNCollaborationSnapshotGetAuthor(self.handle.as_ptr()) }; assert!(!value.is_null()); - unsafe { BnString::from_raw(value) } + unsafe { BnString::into_string(value) } } /// Get the username of the author of a snapshot, if possible (vs author which is user id) - pub fn author_username(&self) -> BnString { + pub fn author_username(&self) -> String { let value = unsafe { BNCollaborationSnapshotGetAuthorUsername(self.handle.as_ptr()) }; assert!(!value.is_null()); - unsafe { BnString::from_raw(value) } + unsafe { BnString::into_string(value) } } /// Created date of Snapshot @@ -116,18 +116,18 @@ impl RemoteSnapshot { /// Hash of snapshot data (analysis and markup, etc) /// No specific hash algorithm is guaranteed - pub fn hash(&self) -> BnString { + pub fn hash(&self) -> String { let value = unsafe { BNCollaborationSnapshotGetHash(self.handle.as_ptr()) }; assert!(!value.is_null()); - unsafe { BnString::from_raw(value) } + unsafe { BnString::into_string(value) } } /// Hash of file contents in snapshot /// No specific hash algorithm is guaranteed - pub fn snapshot_file_hash(&self) -> BnString { + pub fn snapshot_file_hash(&self) -> String { let value = unsafe { BNCollaborationSnapshotGetSnapshotFileHash(self.handle.as_ptr()) }; assert!(!value.is_null()); - unsafe { BnString::from_raw(value) } + unsafe { BnString::into_string(value) } } /// If the snapshot has pulled undo entries yet diff --git a/rust/src/collaboration/sync.rs b/rust/src/collaboration/sync.rs index 1c11b8f0..6fc85d31 100644 --- a/rust/src/collaboration/sync.rs +++ b/rust/src/collaboration/sync.rs @@ -3,7 +3,6 @@ use super::{ }; use binaryninjacore_sys::*; use std::ffi::{c_char, c_void}; -use std::mem::ManuallyDrop; use std::ptr::NonNull; use crate::binary_view::{BinaryView, BinaryViewExt}; @@ -12,7 +11,7 @@ use crate::file_metadata::FileMetadata; use crate::progress::{NoProgressCallback, ProgressCallback}; use crate::project::file::ProjectFile; use crate::rc::Ref; -use crate::string::{BnStrCompatible, BnString}; +use crate::string::{raw_to_string, BnStrCompatible, BnString}; use crate::type_archive::{TypeArchive, TypeArchiveMergeConflict}; // TODO: PathBuf @@ -859,13 +858,11 @@ pub trait DatabaseConflictHandler: Sized { let keys = core::slice::from_raw_parts(keys, conflict_count); let conflicts = core::slice::from_raw_parts(conflicts, conflict_count); keys.iter().zip(conflicts.iter()).all(|(key, conflict)| { - // NOTE this is a reference, not owned, so ManuallyDrop is required, or just implement `ref_from_raw` - // TODO: Replace with raw_to_string - let key = ManuallyDrop::new(BnString::from_raw(*key as *mut _)); + let key = raw_to_string(*key).unwrap(); // TODO I guess dont drop here? let raw_ptr = NonNull::new(*conflict).unwrap(); let conflict = MergeConflict::from_raw(raw_ptr); - ctxt.handle_conflict(key.as_str(), &conflict) + ctxt.handle_conflict(&key, &conflict) }) } } diff --git a/rust/src/collaboration/undo.rs b/rust/src/collaboration/undo.rs index 9f1cc5f0..0dde860f 100644 --- a/rust/src/collaboration/undo.rs +++ b/rust/src/collaboration/undo.rs @@ -57,10 +57,10 @@ impl RemoteUndoEntry { } /// Web api endpoint url - pub fn url(&self) -> BnString { + pub fn url(&self) -> String { let value = unsafe { BNCollaborationUndoEntryGetUrl(self.handle.as_ptr()) }; assert!(!value.is_null()); - unsafe { BnString::from_raw(value) } + unsafe { BnString::into_string(value) } } /// Unique id diff --git a/rust/src/collaboration/user.rs b/rust/src/collaboration/user.rs index 0e3433d3..b08e9da4 100644 --- a/rust/src/collaboration/user.rs +++ b/rust/src/collaboration/user.rs @@ -28,24 +28,24 @@ impl RemoteUser { } /// Web api endpoint url - pub fn url(&self) -> BnString { + pub fn url(&self) -> String { let value = unsafe { BNCollaborationUserGetUrl(self.handle.as_ptr()) }; assert!(!value.is_null()); - unsafe { BnString::from_raw(value) } + unsafe { BnString::into_string(value) } } /// Unique id - pub fn id(&self) -> BnString { + pub fn id(&self) -> String { let value = unsafe { BNCollaborationUserGetId(self.handle.as_ptr()) }; assert!(!value.is_null()); - unsafe { BnString::from_raw(value) } + unsafe { BnString::into_string(value) } } /// User's login username - pub fn username(&self) -> BnString { + pub fn username(&self) -> String { let value = unsafe { BNCollaborationUserGetUsername(self.handle.as_ptr()) }; assert!(!value.is_null()); - unsafe { BnString::from_raw(value) } + unsafe { BnString::into_string(value) } } /// Set user's username. You will need to push the user to update the Remote @@ -65,10 +65,10 @@ impl RemoteUser { } /// User's email address - pub fn email(&self) -> BnString { + pub fn email(&self) -> String { let value = unsafe { BNCollaborationUserGetEmail(self.handle.as_ptr()) }; assert!(!value.is_null()); - unsafe { BnString::from_raw(value) } + unsafe { BnString::into_string(value) } } /// Set user's email. You will need to push the user to update the Remote @@ -88,10 +88,10 @@ impl RemoteUser { } /// String representing the last date the user logged in - pub fn last_login(&self) -> BnString { + pub fn last_login(&self) -> String { let value = unsafe { BNCollaborationUserGetLastLogin(self.handle.as_ptr()) }; assert!(!value.is_null()); - unsafe { BnString::from_raw(value) } + unsafe { BnString::into_string(value) } } /// If the user account is active and can log in |
