ic_core_module/
core_fetch_command.rs

1use intel_cache_lib::ic_types::ic_execute_mod::IcExecute;
2use intel_cache_lib::ic_types::IcConnection;
3use intel_cache_lib::ic_types::IcPacket;
4use intel_cache_lib::lib_backend::fetch_users;
5
6pub struct CoreFetch {}
7impl CoreFetch {
8	#[no_mangle]
9	pub fn cf_new() -> CoreFetch {
10		CoreFetch { }
11	}
12	
13	#[no_mangle]
14	pub fn cf_to_exe() -> Box<dyn IcExecute<Connection = IcConnection>> {
15		Box::new(CoreFetch::cf_new())
16	}
17}
18impl IcExecute for CoreFetch {
19	type Connection = IcConnection;
20	
21	fn exec(&mut self,con: &mut Self::Connection,cmd: Option<Vec<String>>,_data: Option<Vec<u8>>,_cached: bool) -> IcPacket {
22		if cmd != None {
23			let c = cmd.unwrap();
24			if c[1] == "USER" && c.len() > 2 {
25				let u = &c[2];
26				let users = fetch_users(&con.backend_con,u.to_string());
27				let header: String;
28				let body: Option<Vec<u8>>;
29				if users.len() == 1 {
30					header = "UNIQUE".to_string();
31					body = Some(users[0].as_bytes().to_vec());
32				} else if users.len() == 0 {
33					header = "NONE".to_string();
34					body = None;
35				} else {
36					header = users.len().to_string();
37					//Body = concat of all ids
38					let mut b = String::new();
39					for user in users {
40						b.push_str(&user);
41						b.push(' ');
42					}
43					body = Some(b.as_bytes().to_vec());
44				}
45				return IcPacket::new(Some(header),body);
46			}
47			return IcPacket::new(Some("Err. Wrong usage.".to_string()),None);
48		} else { return IcPacket::new(Some("Err.".to_string()),None) }
49	}
50	
51	fn login_required(&mut self) -> bool {
52		false
53	}
54}