From d49728d842e159d278451536d4e978e9a4146e1a Mon Sep 17 00:00:00 2001 From: "Crom (Thibaut CHARLES)" Date: Wed, 30 Jan 2019 16:26:05 +0100 Subject: [PATCH] first --- .gitignore | 2 ++ Cargo.lock | 46 +++++++++++++++++++++++++++++++++++ Cargo.toml | 8 ++++++ src/main.rs | 33 +++++++++++++++++++++++++ src/message.rs | 9 +++++++ src/monitor.rs | 7 ++++++ src/output.rs | 7 ++++++ src/plugins/mod.rs | 2 ++ src/plugins/monitor/mod.rs | 1 + src/plugins/monitor/tester.rs | 17 +++++++++++++ src/plugins/output/mod.rs | 1 + src/plugins/output/stdout.rs | 18 ++++++++++++++ 12 files changed, 151 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 src/main.rs create mode 100644 src/message.rs create mode 100644 src/monitor.rs create mode 100644 src/output.rs create mode 100644 src/plugins/mod.rs create mode 100644 src/plugins/monitor/mod.rs create mode 100644 src/plugins/monitor/tester.rs create mode 100644 src/plugins/output/mod.rs create mode 100644 src/plugins/output/stdout.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..53eaa21 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +**/*.rs.bk diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..a52e38b --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,46 @@ +[[package]] +name = "cc" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "libloading" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cc 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rnetmon" +version = "0.1.0" +dependencies = [ + "libloading 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "winapi" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[metadata] +"checksum cc 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4a8b715cb4597106ea87c7c84b2f1d452c7492033765df7f32651e66fcf749" +"checksum libloading 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9c3ad660d7cb8c5822cd83d10897b0f1f1526792737a179e73896152f85b88c2" +"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0" +"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..ce27939 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "rnetmon" +version = "0.1.0" +authors = ["Thibaut CHARLES"] +edition = "2018" + +[dependencies] +libloading = "0.5.0" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..94a0a8c --- /dev/null +++ b/src/main.rs @@ -0,0 +1,33 @@ +extern crate libloading; +mod message; +mod monitor; +mod output; +mod plugins; + +// use libloading::{Library, Symbol}; + +use crate::monitor::Monitor; +use crate::output::Output; +use crate::message::Message; + +fn main() { + // let lib = Library::new("/home/crom/.gitprojects/rnetmon/plugins/output/stdout/target/debug/deps/libstdout.so").unwrap(); + + // unsafe { + // let handle_message: Symbol = lib.get(b"handle_message").unwrap(); + // handle_message(); + // } + + let msg = Message{ + emitter: "me".to_string(), + level: 10, + msg_type: "string".to_string(), + text: "Consectetur duis do dolor deserunt est minim dolore tempor et non duis.".to_string(), + }; + + let input = plugins::monitor::tester::Tester::new(); + + let out = plugins::output::stdout::Stdout::new(); + out.on_message(&msg); + +} diff --git a/src/message.rs b/src/message.rs new file mode 100644 index 0000000..5a81098 --- /dev/null +++ b/src/message.rs @@ -0,0 +1,9 @@ + + +#[derive(Debug)] +pub struct Message { + pub emitter: String, + pub level: i32, + pub msg_type: String, + pub text: String, +} \ No newline at end of file diff --git a/src/monitor.rs b/src/monitor.rs new file mode 100644 index 0000000..c0c92f8 --- /dev/null +++ b/src/monitor.rs @@ -0,0 +1,7 @@ + +use crate::message::Message; + +pub trait Monitor { + fn new() -> Self; + fn run(&self); +} \ No newline at end of file diff --git a/src/output.rs b/src/output.rs new file mode 100644 index 0000000..07a0ee2 --- /dev/null +++ b/src/output.rs @@ -0,0 +1,7 @@ + +use crate::message::Message; + +pub trait Output { + fn new() -> Self; + fn on_message(&self, message: &Message); +} \ No newline at end of file diff --git a/src/plugins/mod.rs b/src/plugins/mod.rs new file mode 100644 index 0000000..ce44066 --- /dev/null +++ b/src/plugins/mod.rs @@ -0,0 +1,2 @@ +pub mod output; +pub mod monitor; \ No newline at end of file diff --git a/src/plugins/monitor/mod.rs b/src/plugins/monitor/mod.rs new file mode 100644 index 0000000..63da92c --- /dev/null +++ b/src/plugins/monitor/mod.rs @@ -0,0 +1 @@ +pub mod tester; \ No newline at end of file diff --git a/src/plugins/monitor/tester.rs b/src/plugins/monitor/tester.rs new file mode 100644 index 0000000..db88e5e --- /dev/null +++ b/src/plugins/monitor/tester.rs @@ -0,0 +1,17 @@ + +use crate::message::Message; +pub use crate::monitor::Monitor; + +#[derive(Debug)] +pub struct Tester { + +} + +impl Monitor for Tester { + fn new() -> Self { + Tester{} + } + fn run(&self) { + + } +} \ No newline at end of file diff --git a/src/plugins/output/mod.rs b/src/plugins/output/mod.rs new file mode 100644 index 0000000..d54cf68 --- /dev/null +++ b/src/plugins/output/mod.rs @@ -0,0 +1 @@ +pub mod stdout; \ No newline at end of file diff --git a/src/plugins/output/stdout.rs b/src/plugins/output/stdout.rs new file mode 100644 index 0000000..09e4142 --- /dev/null +++ b/src/plugins/output/stdout.rs @@ -0,0 +1,18 @@ + +use crate::message::Message; +pub use crate::output::Output; + +#[derive(Debug)] +pub struct Stdout { + +} + +impl Output for Stdout { + fn new() -> Self { + Stdout{} + } + + fn on_message(&self, message: &Message){ + println!("{:?}", message); + } +} \ No newline at end of file