diff --git a/src/meta_plugin.rs b/src/meta_plugin.rs index 15d5cea..e2ad643 100644 --- a/src/meta_plugin.rs +++ b/src/meta_plugin.rs @@ -1,6 +1,7 @@ use anyhow::Result; use log::debug; use serde::{Deserialize, Serialize}; +use std::collections::HashMap; pub mod program; pub mod digest; diff --git a/src/meta_plugin/binary.rs b/src/meta_plugin/binary.rs index 5c1836d..b848015 100644 --- a/src/meta_plugin/binary.rs +++ b/src/meta_plugin/binary.rs @@ -1,9 +1,9 @@ use anyhow::Result; use rusqlite::Connection; - use crate::common::is_binary::is_binary; use crate::common::PIPESIZE; -use crate::meta_plugin::MetaPlugin; +use crate::meta_plugin::{MetaPlugin, MetaPluginResponse, MetaData}; +use std::collections::HashMap; #[derive(Debug, Clone, Default)] pub struct BinaryMetaPlugin { @@ -61,20 +61,6 @@ impl BinaryMetaPlugin { Self::new(None, None) } - fn save_metadata(&mut self, conn: &Connection) -> Result<()> { - if !self.is_saved { - if let Some(item_id) = self.item_id { - let is_binary_result = is_binary(&self.buffer); - let value = if is_binary_result { "true".to_string() } else { "false".to_string() }; - - // Save to database immediately using central output handler - let _ = self.save_meta(conn, item_id, "binary", value); - - self.is_saved = true; - } - } - Ok(()) - } } impl MetaPlugin for BinaryMetaPlugin { @@ -82,26 +68,31 @@ impl MetaPlugin for BinaryMetaPlugin { true } - fn finalize(&mut self) -> Result { + fn finalize(&mut self) -> MetaPluginResponse { let mut metadata = Vec::new(); // Save the binary detection result when finalizing, if not already saved - if let Some(item_id) = self.item_id { + if let Some(_item_id) = self.item_id { let is_binary_result = is_binary(&self.buffer); let value = if is_binary_result { "true".to_string() } else { "false".to_string() }; - if let Some(meta) = self.create_meta(item_id, "binary", value) { - metadata.push(meta); + // Use process_metadata_outputs to handle output mapping + if let Some(meta_data) = crate::meta_plugin::process_metadata_outputs( + "binary", + value, + &self.outputs + ) { + metadata.push(meta_data); } } - Ok(MetaPluginResponse { - metadata: Some(metadata), + MetaPluginResponse { + metadata, is_finalized: true, - }) + } } - fn update(&mut self, data: &[u8]) -> Result { + fn update(&mut self, data: &[u8]) -> MetaPluginResponse { // Calculate how much data we can still accept let remaining_capacity = self.max_buffer_size.saturating_sub(self.buffer.len()); if remaining_capacity > 0 { @@ -115,29 +106,36 @@ impl MetaPlugin for BinaryMetaPlugin { // If we've reached our buffer limit, return metadata let mut metadata = Vec::new(); if self.buffer.len() >= self.max_buffer_size { - if let Some(item_id) = self.item_id { + if let Some(_item_id) = self.item_id { let is_binary_result = is_binary(&self.buffer); let value = if is_binary_result { "true".to_string() } else { "false".to_string() }; - if let Some(meta) = self.create_meta(item_id, "binary", value) { - metadata.push(meta); + // Use process_metadata_outputs to handle output mapping + if let Some(meta_data) = crate::meta_plugin::process_metadata_outputs( + "binary", + value, + &self.outputs + ) { + metadata.push(meta_data); } } } - Ok(MetaPluginResponse { - metadata: if metadata.is_empty() { None } else { Some(metadata) }, + MetaPluginResponse { + metadata, is_finalized: !metadata.is_empty(), - }) + } } fn meta_name(&self) -> String { self.meta_name.clone() } - fn initialize(&mut self, item_id: i64) -> Result { - self.item_id = Some(item_id); - Ok(MetaPluginResponse::default()) + fn initialize(&mut self) -> MetaPluginResponse { + MetaPluginResponse { + metadata: Vec::new(), + is_finalized: false, + } } fn configure_options(&mut self, options: &std::collections::HashMap) -> Result<()> { diff --git a/src/meta_plugin/system.rs b/src/meta_plugin/system.rs index 1ac5b29..4f61393 100644 --- a/src/meta_plugin/system.rs +++ b/src/meta_plugin/system.rs @@ -1,13 +1,10 @@ use anyhow::Result; use gethostname::gethostname; -use local_ip_address::local_ip; -use dns_lookup::lookup_addr; use std::env; use std::process; -use uzers::{get_current_uid, get_current_gid, get_current_username, get_current_groupname}; -use rusqlite::Connection; - -use crate::meta_plugin::MetaPlugin; +use uzers::{get_current_uid, get_current_gid, get_user_by_uid, get_group_by_gid}; +use crate::meta_plugin::{MetaPlugin, MetaPluginResponse, MetaData}; +use std::collections::HashMap; #[derive(Debug, Clone, Default)] pub struct CwdMetaPlugin {