diff --git a/Cargo.lock b/Cargo.lock index e79dfa6..b7a81a2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,6 +11,55 @@ dependencies = [ "memchr", ] +[[package]] +name = "anstream" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e579a7752471abc2a8268df8b20005e3eadd975f585398f17efcfd8d4927371" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is-terminal", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41ed9a86bf92ae6580e0a31281f65a1b1d867c0cc68d5346e2ae128dddfa6a7d" + +[[package]] +name = "anstyle-parse" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e765fd216e48e067936442276d1d57399e37bce53c264d6fefbe298080cb57ee" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" +dependencies = [ + "windows-sys 0.48.0", +] + +[[package]] +name = "anstyle-wincon" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bcd8291a340dd8ac70e18878bc4501dd7b4ff970cfa21c207d36ece51ea88fd" +dependencies = [ + "anstyle", + "windows-sys 0.48.0", +] + [[package]] name = "async-broadcast" version = "0.5.1" @@ -205,6 +254,54 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "clap" +version = "4.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "956ac1f6381d8d82ab4684768f89c0ea3afe66925ceadb4eeb3fc452ffc55d62" +dependencies = [ + "clap_builder", + "clap_derive", + "once_cell", +] + +[[package]] +name = "clap_builder" +version = "4.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84080e799e54cff944f4b4a4b0e71630b0e0443b25b985175c7dddc1a859b749" +dependencies = [ + "anstream", + "anstyle", + "bitflags", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9644cd56d6b87dbe899ef8b053e331c0637664e9e21a33dfcdc36093f5c5c4" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.15", +] + +[[package]] +name = "clap_lex" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a2dd5a6fe8c6e3502f568a6353e5273bbb15193ad9a89e457b9970798efbea1" + +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + [[package]] name = "concurrent-queue" version = "2.2.0" @@ -402,6 +499,12 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + [[package]] name = "hermit-abi" version = "0.3.1" @@ -444,6 +547,18 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "is-terminal" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adcf93614601c8129ddf72e2d5633df827ba6551541c6d8c59520a371475be1f" +dependencies = [ + "hermit-abi", + "io-lifetimes", + "rustix", + "windows-sys 0.48.0", +] + [[package]] name = "libc" version = "0.2.141" @@ -657,8 +772,10 @@ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" name = "rings" version = "0.1.0" dependencies = [ + "clap", "protobuf", "smol", + "uds", "zbus", ] @@ -779,6 +896,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[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.109" @@ -889,6 +1012,15 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" +[[package]] +name = "uds" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "343758ccc8a17c1663182d780f68b52021d68b9a43d4b912b0a01f48b526e4f0" +dependencies = [ + "libc", +] + [[package]] name = "uds_windows" version = "1.0.2" @@ -905,6 +1037,12 @@ version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + [[package]] name = "version_check" version = "0.9.4" diff --git a/Cargo.toml b/Cargo.toml index ffa9a3b..255f117 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,3 +9,5 @@ edition = "2021" protobuf = "3.2.0" smol = "1.3.0" zbus = "3.12.0" +clap = { version = "4.2.4", features = ["derive"] } +uds = "0.2.6" diff --git a/src/args.rs b/src/args.rs new file mode 100644 index 0000000..8d5b7bf --- /dev/null +++ b/src/args.rs @@ -0,0 +1,11 @@ +use clap::Parser; + +#[derive(Parser, Debug)] +#[command(author, version, about, long_about = None)] +pub struct Args { + #[arg(short, long)] + pub server: bool, + + #[arg(short, long)] + pub client: bool +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index e7a11a9..cc08e64 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,71 @@ +mod args; +use args::Args; +use clap::Parser; +use uds::{UnixSeqpacketListener, UnixSeqpacketConn, UnixSocketAddr}; +extern crate uds; + fn main() { - println!("Hello, world!"); + let args = Args::parse(); + + let result = validate_arguments(&args); + match result { + Ok(_) => {}, + Err(err) => println!("{}", err.message) + } } + +fn validate_arguments(args: &Args) -> Result<(), RingsError> { + if !args.server && !args.client { + return Err(RingsError{message: "Please provide either --client or --server".to_string()}); + } + + if args.server && args.client { + return Err(RingsError{message: "You can't have both flags active at the same time".to_string()}); + } + + if args.server { + server()?; + return Ok(()); + } else if args.client { + + return Ok(()); + } + Ok(()) +} + +fn server() -> Result<(), RingsError> { + create_rings_socket()?; + Ok(()) +} + +fn client( addr: &uds::UnixSocketAddr ) -> Result { + let client = uds::UnixSeqpacketConn::connect_unix_addr(addr); + match client { + Ok(client) => { + return Err(RingsError { message: "to be implemented".to_string() }) + }, + Err(_) => { + return Err(RingsError { message: "to be written".to_string() }) + } + } +} + +fn create_rings_socket() -> Result { + let addr = uds::UnixSocketAddr::new("@abstract"); + match addr { + Ok(addr) => { + let listener = UnixSeqpacketListener::bind_unix_addr(&addr).expect("create seqpacket listener"); + return Ok(listener) + }, + Err(_) => { + return Err(RingsError { message: "boop".to_string() }) + }, + _ => { + return Err(RingsError { message: "something has gone wrong".to_string() }) + } + }; +} + +struct RingsError { + message: String +} \ No newline at end of file