diff options
author | metamuffin <yvchraiqi@protonmail.com> | 2022-06-06 22:29:14 +0200 |
---|---|---|
committer | metamuffin <yvchraiqi@protonmail.com> | 2022-06-06 22:29:14 +0200 |
commit | df31b14b3736a1e71dd8c08297f84e3fba228e39 (patch) | |
tree | d588627928bdb4133a5f6b582d22b500e9e1ad1e | |
download | karlender-df31b14b3736a1e71dd8c08297f84e3fba228e39.tar karlender-df31b14b3736a1e71dd8c08297f84e3fba228e39.tar.bz2 karlender-df31b14b3736a1e71dd8c08297f84e3fba228e39.tar.zst |
a
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Cargo.lock | 206 | ||||
-rw-r--r-- | Cargo.toml | 11 | ||||
-rw-r--r-- | protocol.d.ts | 66 | ||||
-rw-r--r-- | src/lib.rs | 2 | ||||
-rw-r--r-- | src/main.rs | 27 | ||||
-rw-r--r-- | src/occurence.rs | 25 | ||||
-rw-r--r-- | src/protocol.rs | 30 |
8 files changed, 368 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..a13bf2e --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,206 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aho-corasick" +version = "0.7.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +dependencies = [ + "memchr", +] + +[[package]] +name = "anyhow" +version = "1.0.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08f9b8508dccb7687a1d6c4ce66b2b0ecef467c94667de27d8d7fe1f8d2a9cdc" + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + +[[package]] +name = "calender-thing" +version = "0.1.0" +dependencies = [ + "anyhow", + "env_logger", + "log", + "serde", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "env_logger" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3" +dependencies = [ + "atty", + "humantime", + "log", + "regex", + "termcolor", +] + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + +[[package]] +name = "libc" +version = "0.2.126" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" + +[[package]] +name = "log" +version = "0.4.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + +[[package]] +name = "proc-macro2" +version = "1.0.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "regex" +version = "1.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d83f127d94bdbcda4c8cc2e50f6f84f4b611f69c902699ca385a39c3a75f9ff1" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49b3de9ec5dc0a3417da371aab17d729997c15010e7fd24ff707773a33bddb64" + +[[package]] +name = "serde" +version = "1.0.137" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.137" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578be" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "syn" +version = "1.0.96" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0748dd251e24453cb8717f0354206b91557e4ec8703673a4b30208f2abaf1ebf" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "termcolor" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "unicode-ident" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..03ed20d --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "calender-thing" +version = "0.1.0" +edition = "2021" + +[dependencies] +serde = { version = "1.0.137", features = ["derive"] } +anyhow = "1.0.57" +log = "0.4.17" +env_logger = "0.9.0" + diff --git a/protocol.d.ts b/protocol.d.ts new file mode 100644 index 0000000..f119045 --- /dev/null +++ b/protocol.d.ts @@ -0,0 +1,66 @@ + +// { type: "handshake", version: "10"} +// { type: "handshake", data: {version: "10"}} +// { "handshake": {version: "10"}} + +export type ServerboundPacket = null +export type ClientboundPacket = Handshake + +interface Handshake { + type: "handshake" + version: string +} + +interface Download { + type: "download", +} +interface DownloadResponse { + type: "download_response", + entries: TodoEntry[] +} + + + +interface TodoEntry { + name: string, + description: string, + + tags: string[], + priority: number, + + completed?: number, + scheduled?: number, + + occurence?: Condition, + deadline?: Condition, +} + +/* + { and: [ + { or: [{ dayofweak: 0 }, { dayofweak: 1 }] }, + { weekofmonth: 0 } + { hour: [11, 13] } + ]} +*/ + +// should only have one property +interface Condition { + from: Condition + to: Condition + + or: Condition[] + and: Condition[] + + year?: [number, number], + monthofyear?: [number, number], + weekofmonth?: [number, number], + dayofyear?: [number, number], + dayofmonth?: [number, number], + dayofweek?: [number, number], + + hour?: [number, number], + minute?: [number, number], + second?: [number, number], + + unix?: [number, number], +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..0d96cad --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,2 @@ +pub mod protocol; +pub mod occurence;
\ No newline at end of file diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..a26a1dd --- /dev/null +++ b/src/main.rs @@ -0,0 +1,27 @@ + +use std::io::{BufRead, BufReader}; +use std::os::unix::net::{UnixListener, UnixStream}; +use std::thread; + +fn handle_client(stream: UnixStream) { + let stream = BufReader::new(stream); + for line in stream.lines() { + println!("{}", line.unwrap()); + } +} + +fn main() { + let listener = UnixListener::bind("/run/user/1000/calendar").unwrap(); + + for stream in listener.incoming() { + match stream { + Ok(stream) => { + thread::spawn(|| handle_client(stream)); + } + Err(err) => { + println!("Error: {}", err); + break; + } + } + } +} diff --git a/src/occurence.rs b/src/occurence.rs new file mode 100644 index 0000000..104438a --- /dev/null +++ b/src/occurence.rs @@ -0,0 +1,25 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Serialize, Deserialize)] +pub enum Condition { + And(Vec<Condition>), + Or(Vec<Condition>), + From(Box<Condition>), + To(Box<Condition>), + + Year(Range), + Monthofyear(Range), + Weekofmonth(Range), + Dayofyear(Range), + Dayofmonth(Range), + Dayofweek(Range), + + Hour(Range), + Minute(Range), + Second(Range), + + Unix(Range), +} + +#[derive(Debug, Serialize, Deserialize)] +pub struct Range(u64, u64); diff --git a/src/protocol.rs b/src/protocol.rs new file mode 100644 index 0000000..fdd84d4 --- /dev/null +++ b/src/protocol.rs @@ -0,0 +1,30 @@ +use serde::{Deserialize, Serialize}; + +use crate::occurence::Condition; + +#[derive(Debug, Serialize, Deserialize)] +pub enum ClientboundPacket { + Handshake { version: String }, + DownloadResponse(Vec<Task>), +} + +#[derive(Debug, Serialize, Deserialize)] +pub enum ServerboundPacket { + Download, +} + +#[derive(Debug, Serialize, Deserialize)] +pub struct Task { + name: String, + description: String, + + tags: Vec<String>, + priority: f64, + + completed: u64, + scheduled: u64, + + occurence: Option<Condition>, + deadline: Option<Condition>, +} + |