diff --git a/src/server/data.rs b/src/server/data.rs index af90b2c..378af17 100644 --- a/src/server/data.rs +++ b/src/server/data.rs @@ -92,9 +92,11 @@ bitflags! { const NONE = 0; /// This value should be cloned on write unless specified elsewhere. const COW = 1<<0; - /// This should not show up in searches + /// This should not show up in searches. const HIDDEN = 1<<1; - /// Versioning is enabled for this value + /// Versioning is enabled for this value. + /// + /// When it is deleted, it should instead be moved away into a sperate entry. const VERSIONED = 1<<2; } } @@ -110,13 +112,15 @@ pub struct Info tags: Tags, + hooks: event::Hooks, + owner: Option>, //starts as the user that created (i.e. same as `created_by`), or `None` if ownership is disabled signed: Option>, perms: user::Permissions, created_by: user::UserID, - log: Vec, + log: Vec, } /// The root data containing map diff --git a/src/server/event.rs b/src/server/event.rs index 9f58618..b8cfec0 100644 --- a/src/server/event.rs +++ b/src/server/event.rs @@ -1,9 +1,10 @@ //! When events happen to datamaps use super::*; +use bitflags::bitflags; -/// What happened in the event +/// What happened in the in-band event #[derive(Debug, Serialize, Deserialize)] -pub enum EventKind +pub enum InBandEventKind { Created, Modified, @@ -16,13 +17,84 @@ pub enum EventKind Comment(String), } -/// An event that happened to a data entry +/// An event that happened to a data entry that is then stored in its metadata. +/// +/// # Note +/// Not to be confused with `HookEvent`s #[derive(Debug, Serialize, Deserialize)] -pub struct Event +pub struct InBandEvent { who: Option, - what: EventKind, + what: InBandEventKind, when: u64, signed: Option, } + + +bitflags! { + + /// Kind of events that should emmit for a hook + #[derive(Serialize, Deserialize)] + struct HookMask: u16 + { + /// Filter all events. None are emiited. + const NONE = 0; + /// Mask any event, any kind is emitted. + const ANY = !0; + + /// Emmit read events. + const READ = 1<<0; + /// Emmit write events. + const WRITE = 1<<1; + /// Emmit delete events. + const DELETE = 1<<2; + + /// Propagate events from children of `Map` datas + const CHILD = 1<<3; + + /// Poke events are opaque events that are fired manually. + const POKE = 1<<4; + + } +} + +impl Default for HookMask +{ + #[inline(always)] + fn default() -> Self + { + Self::NONE + } +} + + +/// Fire events when something happens to this value. +#[derive(Debug, Serialize, Deserialize)] +pub struct Hooks +{ + filter: HookMask, +} + +/// An event emitted from a matched `Hook`. +#[derive(Debug, Clone, PartialEq, Eq, Hash, Ord, PartialOrd)] +pub enum HookEvent +{ + /// An opaque event type + Poke, + + Read, + Write, + Delete, + Child(Box), +} + +impl Default for HookEvent +{ + #[inline] + fn default() -> Self + { + Self::Poke + } +} + diff --git a/src/server/user.rs b/src/server/user.rs index f14e84f..09d8956 100644 --- a/src/server/user.rs +++ b/src/server/user.rs @@ -262,6 +262,15 @@ bitflags! { } } +impl Default for Permission +{ + #[inline(always)] + fn default() -> Self + { + Self::READ + } +} + /// A set of permissions informations for users and/or groups #[derive(Debug, Serialize, Deserialize)]