1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
use ffi_utils::ReprC;
use ffi_utils::callback::CallbackArgs;
use ipc::req::permission_set_into_repr_c;
use routing;
use routing::XorName;
use std::ffi::CString;
use std::os::raw::c_char;
#[repr(C)]
#[derive(Copy, Clone, Default, Debug, Eq, Ord, PartialEq, PartialOrd, Serialize, Deserialize)]
pub struct PermissionSet {
pub read: bool,
pub insert: bool,
pub update: bool,
pub delete: bool,
pub manage_permissions: bool,
}
impl ReprC for PermissionSet {
type C = *const PermissionSet;
type Error = ();
unsafe fn clone_from_repr_c(raw: Self::C) -> Result<Self, Self::Error> {
Ok(*raw)
}
}
impl CallbackArgs for PermissionSet {
fn default() -> Self {
permission_set_into_repr_c(routing::PermissionSet::new())
}
}
#[repr(C)]
pub struct AuthReq {
pub app: AppExchangeInfo,
pub app_container: bool,
pub containers: *const ContainerPermissions,
pub containers_len: usize,
pub containers_cap: usize,
}
impl Drop for AuthReq {
#[allow(unsafe_code)]
fn drop(&mut self) {
unsafe {
let _ = Vec::from_raw_parts(
self.containers as *mut ContainerPermissions,
self.containers_len,
self.containers_cap,
);
}
}
}
#[repr(C)]
pub struct ContainersReq {
pub app: AppExchangeInfo,
pub containers: *const ContainerPermissions,
pub containers_len: usize,
pub containers_cap: usize,
}
impl Drop for ContainersReq {
#[allow(unsafe_code)]
fn drop(&mut self) {
unsafe {
let _ = Vec::from_raw_parts(
self.containers as *mut ContainerPermissions,
self.containers_len,
self.containers_cap,
);
}
}
}
#[repr(C)]
pub struct AppExchangeInfo {
pub id: *const c_char,
pub scope: *const c_char,
pub name: *const c_char,
pub vendor: *const c_char,
}
impl Drop for AppExchangeInfo {
#[allow(unsafe_code)]
fn drop(&mut self) {
unsafe {
let _ = CString::from_raw(self.id as *mut _);
if !self.scope.is_null() {
let _ = CString::from_raw(self.scope as *mut _);
}
let _ = CString::from_raw(self.name as *mut _);
let _ = CString::from_raw(self.vendor as *mut _);
}
}
}
#[repr(C)]
pub struct ContainerPermissions {
pub cont_name: *const c_char,
pub access: PermissionSet,
}
impl Drop for ContainerPermissions {
#[allow(unsafe_code)]
fn drop(&mut self) {
unsafe {
let _ = CString::from_raw(self.cont_name as *mut _);
}
}
}
#[repr(C)]
pub struct ShareMDataReq {
pub app: AppExchangeInfo,
pub mdata: *const ShareMData,
pub mdata_len: usize,
pub mdata_cap: usize,
}
impl Drop for ShareMDataReq {
#[allow(unsafe_code)]
fn drop(&mut self) {
unsafe {
let _ = Vec::from_raw_parts(
self.mdata as *mut ShareMData,
self.mdata_len,
self.mdata_cap,
);
}
}
}
#[repr(C)]
pub struct ShareMData {
pub type_tag: u64,
pub name: XorName,
pub perms: PermissionSet,
}