aboutsummaryrefslogtreecommitdiff
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
parent6f6db73a126057514912c5e6b372ef225a1065b7 (diff)
downloadkarlender-76db19f14c616e879f613b533ee5072c661f8a10.tar
karlender-76db19f14c616e879f613b533ee5072c661f8a10.tar.bz2
karlender-76db19f14c616e879f613b533ee5072c661f8a10.tar.zst
stuff
-rw-r--r--Cargo.lock118
-rw-r--r--karlc/Cargo.toml3
-rw-r--r--karlc/src/main.rs17
-rw-r--r--karlcommon/src/lib.rs78
-rw-r--r--karlcommon/src/protocol.rs71
-rw-r--r--karld/src/interface.rs13
-rw-r--r--karld/src/main.rs2
7 files changed, 230 insertions, 72 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 17bfef6..3f96c96 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -35,6 +35,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
+name = "bitflags"
+version = "1.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
+
+[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -54,6 +60,45 @@ dependencies = [
]
[[package]]
+name = "clap"
+version = "3.1.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d2dbdf4bdacb33466e854ce889eee8dfd5729abf7ccd7664d0a2d60cd384440b"
+dependencies = [
+ "atty",
+ "bitflags",
+ "clap_derive",
+ "clap_lex",
+ "indexmap",
+ "lazy_static",
+ "strsim",
+ "termcolor",
+ "textwrap",
+]
+
+[[package]]
+name = "clap_derive"
+version = "3.1.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "25320346e922cffe59c0bbc5410c8d8784509efb321488971081313cb1e1a33c"
+dependencies = [
+ "heck",
+ "proc-macro-error",
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "clap_lex"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a37c35f1112dad5e6e0b1adaff798507497a18fceeb30cceb3bae7d1427b9213"
+dependencies = [
+ "os_str_bytes",
+]
+
+[[package]]
name = "crossbeam-channel"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -87,6 +132,18 @@ dependencies = [
]
[[package]]
+name = "hashbrown"
+version = "0.11.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
+
+[[package]]
+name = "heck"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9"
+
+[[package]]
name = "hermit-abi"
version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -102,6 +159,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
[[package]]
+name = "indexmap"
+version = "1.8.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e6012d540c5baa3589337a98ce73408de9b5a25ec9fc2c6fd6be8f0d39e0ca5a"
+dependencies = [
+ "autocfg",
+ "hashbrown",
+]
+
+[[package]]
name = "itoa"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -111,7 +178,10 @@ checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d"
name = "karlc"
version = "0.1.0"
dependencies = [
+ "clap",
+ "env_logger",
"karlcommon",
+ "log",
"serde",
]
@@ -184,6 +254,36 @@ dependencies = [
]
[[package]]
+name = "os_str_bytes"
+version = "6.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "21326818e99cfe6ce1e524c2a805c189a99b5ae555a35d19f9a284b427d86afa"
+
+[[package]]
+name = "proc-macro-error"
+version = "1.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
+dependencies = [
+ "proc-macro-error-attr",
+ "proc-macro2",
+ "quote",
+ "syn",
+ "version_check",
+]
+
+[[package]]
+name = "proc-macro-error-attr"
+version = "1.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "version_check",
+]
+
+[[package]]
name = "proc-macro2"
version = "1.0.39"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -256,6 +356,12 @@ dependencies = [
]
[[package]]
+name = "strsim"
+version = "0.10.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
+
+[[package]]
name = "syn"
version = "1.0.96"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -276,6 +382,12 @@ dependencies = [
]
[[package]]
+name = "textwrap"
+version = "0.15.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb"
+
+[[package]]
name = "time"
version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -293,6 +405,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee"
[[package]]
+name = "version_check"
+version = "0.9.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
+
+[[package]]
name = "wasi"
version = "0.10.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/karlc/Cargo.toml b/karlc/Cargo.toml
index e45419c..e37abfb 100644
--- a/karlc/Cargo.toml
+++ b/karlc/Cargo.toml
@@ -7,3 +7,6 @@ edition = "2021"
karlcommon = { path = "../karlcommon" }
serde = { version = "1.0.137", features = ["derive"] }
+clap = { version = "3.1.18", features = ["derive"] }
+env_logger = "0.9.0"
+log = "0.4.17"
diff --git a/karlc/src/main.rs b/karlc/src/main.rs
index e7a11a9..8db8d18 100644
--- a/karlc/src/main.rs
+++ b/karlc/src/main.rs
@@ -1,3 +1,18 @@
+use std::os::unix::net::UnixStream;
+
+use clap::Parser;
+use karlcommon::socket_path;
+
+/// CLI interface for karld
+#[derive(Parser)]
+#[clap(about, author, version)]
+struct Args {}
+
fn main() {
- println!("Hello, world!");
+ let _args = Args::parse();
+
+ let socket = UnixStream::connect(socket_path()).unwrap();
+
+
+
}
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,
+}
diff --git a/karld/src/interface.rs b/karld/src/interface.rs
index 884aca2..99ef594 100644
--- a/karld/src/interface.rs
+++ b/karld/src/interface.rs
@@ -1,5 +1,5 @@
use crate::handle_packet;
-use karlcommon::{ClientboundPacket, ServerboundPacket};
+use karlcommon::{socket_path, ClientboundPacket, ServerboundPacket};
use log::{debug, error, info, warn};
use std::io;
use std::io::{BufRead, BufReader, ErrorKind, Write};
@@ -7,7 +7,7 @@ use std::os::unix::net::{UnixListener, UnixStream};
use std::thread;
pub fn network_loop() {
- let listener = UnixListener::bind("/run/user/1000/calendar").unwrap();
+ let listener = UnixListener::bind(socket_path()).unwrap();
info!("listening.");
let mut id_counter = 0;
@@ -58,9 +58,12 @@ fn handle_connection(id: u32, mut stream: UnixStream) -> io::Result<()> {
debug!("{id} <- {packet:?}");
handle_packet(id, packet, responder.clone());
}
- Err(err) => responder
- .send(ClientboundPacket::Error(format!("{}", &err)))
- .map_err(|_| io::Error::from(ErrorKind::InvalidInput))?,
+ Err(err) => {
+ warn!("client error: {:?}", &err);
+ responder
+ .send(ClientboundPacket::Error(format!("{}", &err)))
+ .map_err(|_| io::Error::from(ErrorKind::InvalidInput))?
+ }
}
buf.clear();
diff --git a/karld/src/main.rs b/karld/src/main.rs
index 6cf902e..7fa47e2 100644
--- a/karld/src/main.rs
+++ b/karld/src/main.rs
@@ -5,9 +5,11 @@ use std::{collections::HashMap, sync::RwLock};
use crossbeam_channel::Sender;
use interface::network_loop;
use karlcommon::{Task, Condition, Property, ServerboundPacket, ClientboundPacket};
+use log::info;
fn main() {
env_logger::init();
+ info!("logging");
TASKS.write().unwrap().insert(
0,
Task {