aboutsummaryrefslogtreecommitdiff
path: root/karlcommon
diff options
context:
space:
mode:
authormetamuffin <yvchraiqi@protonmail.com>2022-06-10 11:18:21 +0200
committermetamuffin <yvchraiqi@protonmail.com>2022-06-10 11:18:21 +0200
commit76db19f14c616e879f613b533ee5072c661f8a10 (patch)
tree3084bef7880da66e43c8cfc4c179155640d5c628 /karlcommon
parent6f6db73a126057514912c5e6b372ef225a1065b7 (diff)
downloadkarlender-76db19f14c616e879f613b533ee5072c661f8a10.tar
karlender-76db19f14c616e879f613b533ee5072c661f8a10.tar.bz2
karlender-76db19f14c616e879f613b533ee5072c661f8a10.tar.zst
stuff
Diffstat (limited to 'karlcommon')
-rw-r--r--karlcommon/src/lib.rs78
-rw-r--r--karlcommon/src/protocol.rs71
2 files changed, 83 insertions, 66 deletions
diff --git a/karlcommon/src/lib.rs b/karlcommon/src/lib.rs
index 809a036..8e7694b 100644
--- a/karlcommon/src/lib.rs
+++ b/karlcommon/src/lib.rs
@@ -1,70 +1,16 @@
-use serde::{Deserialize, Serialize};
+pub mod protocol;
+use std::{
+ os::unix::prelude::MetadataExt,
+ path::{Path, PathBuf},
+};
-#[derive(Debug, Clone, Serialize, Deserialize)]
-#[serde(tag = "type", content = "data", rename_all = "snake_case")]
-pub enum ClientboundPacket {
- Handshake { version: String },
- Error(String),
- DownloadResponse(Vec<Task>),
-}
-
-#[derive(Debug, Clone, Serialize, Deserialize)]
-#[serde(tag = "type", content = "data", rename_all = "snake_case")]
-pub enum ServerboundPacket {
- Download,
- UpdateTask(Task),
- RemoveTask(u64),
-}
-
-#[derive(Debug, Clone, Serialize, Deserialize)]
-pub struct Task {
- pub id: u64,
- pub name: String,
- pub description: String,
-
- pub tags: Vec<String>,
- pub priority: f64,
-
- pub completed: Option<u64>,
- pub scheduled: Option<u64>,
+pub use protocol::*;
- pub occurence: Option<Condition>,
- pub deadline: Option<Condition>,
+pub fn socket_path() -> PathBuf {
+ Path::new("/run/user")
+ .join(format!("{}", getuid()))
+ .join("calendar")
}
-
-#[derive(Debug, Clone, Serialize, Deserialize)]
-#[serde(rename_all = "snake_case")]
-pub enum Condition {
- From(Box<Condition>),
-
- Or(Vec<Condition>),
- And(Vec<Condition>),
- Invert(Box<Condition>),
-
- Equal {
- prop: Property,
- value: i64,
- modulus: Option<i64>,
- },
- Range {
- prop: Property,
- min: i64,
- max: i64,
- modulus: Option<i64>,
- },
-}
-
-#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
-#[serde(rename_all = "snake_case")]
-pub enum Property {
- Year,
- Monthofyear,
- Weekofmonth,
- Dayofyear,
- Dayofmonth,
- Dayofweek,
- Hour,
- Minute,
- Second,
- Unix,
+fn getuid() -> u32 {
+ std::fs::metadata("/proc/self").unwrap().uid()
}
diff --git a/karlcommon/src/protocol.rs b/karlcommon/src/protocol.rs
new file mode 100644
index 0000000..74559bf
--- /dev/null
+++ b/karlcommon/src/protocol.rs
@@ -0,0 +1,71 @@
+
+use serde::{Deserialize, Serialize};
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+#[serde(tag = "type", content = "data", rename_all = "snake_case")]
+pub enum ClientboundPacket {
+ Handshake { version: String },
+ Error(String),
+ DownloadResponse(Vec<Task>),
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+#[serde(tag = "type", content = "data", rename_all = "snake_case")]
+pub enum ServerboundPacket {
+ Download,
+ UpdateTask(Task),
+ RemoveTask(u64),
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+pub struct Task {
+ pub id: u64,
+ pub name: String,
+ pub description: String,
+
+ pub tags: Vec<String>,
+ pub priority: f64,
+
+ pub completed: Option<u64>,
+ pub scheduled: Option<u64>,
+
+ pub occurence: Option<Condition>,
+ pub deadline: Option<Condition>,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+#[serde(rename_all = "snake_case")]
+pub enum Condition {
+ From(Box<Condition>),
+
+ Or(Vec<Condition>),
+ And(Vec<Condition>),
+ Invert(Box<Condition>),
+
+ Equal {
+ prop: Property,
+ value: i64,
+ modulus: Option<i64>,
+ },
+ Range {
+ prop: Property,
+ min: i64,
+ max: i64,
+ modulus: Option<i64>,
+ },
+}
+
+#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
+#[serde(rename_all = "snake_case")]
+pub enum Property {
+ Year,
+ Monthofyear,
+ Weekofmonth,
+ Dayofyear,
+ Dayofmonth,
+ Dayofweek,
+ Hour,
+ Minute,
+ Second,
+ Unix,
+}