#![allow(non_snake_case)]
#[path="../../structs/mod.rs"] mod structs;
#[path="../../connect.rs"] mod connect;
use crate::error::{MsfError,Error as E};
use crate::client::Client;
use connect::connect;
use serde::{Serialize,de::DeserializeOwned as DOwned};
use rmp_serde::{Serializer,decode::Error as derror,from_read};
use structs::request as req;
pub fn add_module<T:DOwned>(client:Client,pathstr:&str) -> Result<T,E> {
let path:String=pathstr.to_string();
let mut body=Vec::new();
let mut buf=vec![];
let mut serializer=Serializer::new(&mut body);
let byte=req::core::addmodpath("core.add_module_path".to_string(),client.token.unwrap(),path);
byte.serialize(&mut serializer).unwrap();
let con=connect(client.url,body,&mut buf);
let new_buf=buf.clone();
match con {
Ok(_) => {
let ret:Result<T,derror>=from_read(new_buf.as_slice());
match ret {
Ok(val) => {
Ok(val)
},
Err(_) => {
let ret2:Result<MsfError,derror>=from_read(new_buf.as_slice());
match ret2 {
Ok(val) => {
Err(E::MsfError(val))
},
Err(e) => {
Err(E::DError(e))
},
}
}
}
},
Err(e) => {
Err(E::ConnectionError(e))
},
}
}
pub fn module_status<T:DOwned>(client:Client) -> Result<T,E> {
let mut body=Vec::new();
let mut buf=vec![];
let mut se=Serializer::new(&mut body);
let byte=req::core::modulestat("core.module_stats".to_string(),client.token.unwrap());
byte.serialize(&mut se).unwrap();
let con=connect(client.url,body,&mut buf);
let new_buf=buf.clone();
match con {
Ok(_) => {
let ret:Result<T,derror>=from_read(new_buf.as_slice());
match ret {
Ok(val) => {
Ok(val)
},
Err(_) => {
let ret2:Result<MsfError,derror>=from_read(new_buf.as_slice());
match ret2 {
Ok(val) => {
Err(E::MsfError(val))
},
Err(e) => {
Err(E::DError(e))
},
}
}
}
},
Err(e) => {
Err(E::ConnectionError(e))
},
}
}
pub fn reload_module<T:DOwned>(client:Client) -> Result<T,E> {
let mut body=Vec::new();
let mut buf=vec![];
let mut se=Serializer::new(&mut body);
let byte=req::core::reloadmod("core.reload_modules".to_string(),client.token.unwrap());
byte.serialize(&mut se).unwrap();
let con=connect(client.url,body,&mut buf);
let new_buf=buf.clone();
match con {
Ok(_) => {
let ret:Result<T,derror>=from_read(new_buf.as_slice());
match ret {
Ok(val) => {
Ok(val)
},
Err(_) => {
let ret2:Result<MsfError,derror>=from_read(new_buf.as_slice());
match ret2 {
Ok(val) => {
Err(E::MsfError(val))
},
Err(e) => {
Err(E::DError(e))
},
}
}
}
},
Err(e) => {
Err(E::ConnectionError(e))
},
}
}
pub fn save<T:DOwned>(client:Client) -> Result<T,E> {
let mut body=Vec::new();
let mut buf=vec![];
let mut se=Serializer::new(&mut body);
let byte=req::core::save("core.save".to_string(),client.token.unwrap());
byte.serialize(&mut se).unwrap();
let con=connect(client.url,body,&mut buf);
let new_buf=buf.clone();
match con {
Ok(_) => {
let ret:Result<T,derror>=from_read(new_buf.as_slice());
match ret {
Ok(val) => {
Ok(val)
},
Err(_) => {
let ret2:Result<MsfError,derror>=from_read(new_buf.as_slice());
match ret2 {
Ok(val) => {
Err(E::MsfError(val))
},
Err(e) => {
Err(E::DError(e))
},
}
}
}
},
Err(e) => {
Err(E::ConnectionError(e))
},
}
}
pub fn setg<T:DOwned>(client:Client,namestr:&str,valuestr:&str) -> Result<T,E> {
let name:String=namestr.to_string();
let value:String=valuestr.to_string();
let mut body=Vec::new();
let mut buf=vec![];
let mut se=Serializer::new(&mut body);
let byte=req::core::setg("core.setg".to_string(),client.token.unwrap(),name,value);
byte.serialize(&mut se).unwrap();
let con=connect(client.url,body,&mut buf);
let new_buf=buf.clone();
match con {
Ok(_) => {
let ret:Result<T,derror>=from_read(new_buf.as_slice());
match ret {
Ok(val) => {
Ok(val)
},
Err(_) => {
let ret2:Result<MsfError,derror>=from_read(new_buf.as_slice());
match ret2 {
Ok(val) => {
Err(E::MsfError(val))
},
Err(e) => {
Err(E::DError(e))
},
}
}
}
},
Err(e) => {
Err(E::ConnectionError(e))
},
}
}
pub fn unsetg<T:DOwned>(client:Client,namestr:&str) -> Result<T,E> {
let name:String=namestr.to_string();
let mut body=Vec::new();
let mut buf=vec![];
let mut se=Serializer::new(&mut body);
let byte=req::core::unsetg("core.unsetg".to_string(),client.token.unwrap(),name);
byte.serialize(&mut se).unwrap();
let con=connect(client.url,body,&mut buf);
let new_buf=buf.clone();
match con {
Ok(_) => {
let ret:Result<T,derror>=from_read(new_buf.as_slice());
match ret {
Ok(val) => {
Ok(val)
},
Err(_) => {
let ret2:Result<MsfError,derror>=from_read(new_buf.as_slice());
match ret2 {
Ok(val) => {
Err(E::MsfError(val))
},
Err(e) => {
Err(E::DError(e))
},
}
}
}
},
Err(e) => {
Err(E::ConnectionError(e))
},
}
}
pub fn list_thread<T:DOwned>(client:Client) -> Result<T,E> {
let mut body=Vec::new();
let mut buf=vec![];
let mut se=Serializer::new(&mut body);
let byte=req::core::threadlist("core.thread_list".to_string(),client.token.unwrap());
byte.serialize(&mut se).unwrap();
let con=connect(client.url,body,&mut buf);
let new_buf=buf.clone();
match con {
Ok(_) => {
let ret:Result<T,derror>=from_read(new_buf.as_slice());
match ret {
Ok(val) => {
Ok(val)
},
Err(_) => {
let ret2:Result<MsfError,derror>=from_read(new_buf.as_slice());
match ret2 {
Ok(val) => {
Err(E::MsfError(val))
},
Err(e) => {
Err(E::DError(e))
},
}
}
}
},
Err(e) => {
Err(E::ConnectionError(e))
},
}
}
pub fn kill_thread<T:DOwned>(client:Client,threadID:i32) -> Result<T,E> {
let mut body=Vec::new();
let mut buf=vec![];
let mut se=Serializer::new(&mut body);
let byte=req::core::threadkill("core.thread_kill".to_string(),client.token.unwrap(),threadID);
byte.serialize(&mut se).unwrap();
let con=connect(client.url,body,&mut buf);
let new_buf=buf.clone();
match con {
Ok(_) => {
let ret:Result<T,derror>=from_read(new_buf.as_slice());
match ret {
Ok(val) => {
Ok(val)
},
Err(_) => {
let ret2:Result<MsfError,derror>=from_read(new_buf.as_slice());
match ret2 {
Ok(val) => {
Err(E::MsfError(val))
},
Err(e) => {
Err(E::DError(e))
},
}
}
}
},
Err(e) => {
Err(E::ConnectionError(e))
},
}
}
pub fn version<T:DOwned>(client:Client) -> Result<T,E> {
let mut body=Vec::new();
let mut buf=vec![];
let mut se=Serializer::new(&mut body);
let byte=req::core::version("core.version".to_string(),client.token.unwrap());
byte.serialize(&mut se).unwrap();
let con=connect(client.url,body,&mut buf);
let new_buf=buf.clone();
match con {
Ok(_) => {
let ret:Result<T,derror>=from_read(new_buf.as_slice());
match ret {
Ok(val) => {
Ok(val)
},
Err(_) => {
let ret2:Result<MsfError,derror>=from_read(new_buf.as_slice());
match ret2 {
Ok(val) => {
Err(E::MsfError(val))
},
Err(e) => {
Err(E::DError(e))
},
}
}
}
},
Err(e) => {
Err(E::ConnectionError(e))
},
}
}
pub fn stop<T:DOwned>(client:Client) -> Result<T,E> {
let mut body=Vec::new();
let mut buf=vec![];
let mut se=Serializer::new(&mut body);
let byte=req::core::stop("core.stop".to_string(),client.token.unwrap());
byte.serialize(&mut se).unwrap();
let con=connect(client.url,body,&mut buf);
let new_buf=buf.clone();
match con {
Ok(_) => {
let ret:Result<T,derror>=from_read(new_buf.as_slice());
match ret {
Ok(val) => {
Ok(val)
},
Err(_) => {
let ret2:Result<MsfError,derror>=from_read(new_buf.as_slice());
match ret2 {
Ok(val) => {
Err(E::MsfError(val))
},
Err(e) => {
Err(E::DError(e))
},
}
}
}
},
Err(e) => {
Err(E::ConnectionError(e))
},
}
}