Struct ClamdClient

Source
pub struct ClamdClient<T: ToSocketAddrs + ToOwned<Owned = T>> { /* private fields */ }
Expand description

Asynchronous, tokio based client for clamd. Use ClamdClientBuilder to build. At the moment, this will always open a new TCP connection for each command executed. There are plans to also include an option to reuse / keep alive connections but that is a TODO.

For more information about the various commands please also consult the man pages for clamd (man clamd).

§Example

let address = "127.0.0.1:3310";
let mut clamd_client = ClamdClientBuilder::tcp_socket(address).build();
clamd_client.ping().await?;

Implementations§

Source§

impl<T: ToSocketAddrs + ToOwned<Owned = T>> ClamdClient<T>

Source

pub async fn ping(&mut self) -> Result<(), ClamdError>

Ping clamd. If it responds normally (with PONG) this function returns Ok(()), otherwise returns with error.

Source

pub async fn version(&mut self) -> Result<String, ClamdError>

Get clamd version string.

Source

pub async fn reload(&mut self) -> Result<(), ClamdError>

Reload clamd.

Source

pub async fn stats(&mut self) -> Result<String, ClamdError>

Get clamd stats.

Source

pub async fn shutdown(self) -> Result<(), ClamdError>

Shutdown clamd. Careful: There is no way to start clamd again from this library.

Source

pub async fn scan_reader<R: AsyncRead + AsyncReadExt + Unpin>( &mut self, to_scan: R, ) -> Result<(), ClamdError>

Upload bytes to check it for viruses. This will chunk the reader with a chunk size defined in the ClamdClientBuilder. Only if clamd resonds with stream: OK (and thus clamd found the bytes to not include virus signatures) this function will return Ok(()). In all other cases returns an error.

§Errors

If the scan was sucessful but seems to have found a virus signature this returns ClamdError::ScanError with the scan result. See ClamdError for more information.

Source

pub async fn scan_bytes(&mut self, to_scan: &[u8]) -> Result<(), ClamdError>

Convienence method to scan a bytes slice. Wraps ClamdClient::scan_reader, so see there for more information.

Source

pub async fn scan_file( &mut self, path_to_scan: impl AsRef<Path>, ) -> Result<(), ClamdError>

Convienence method to directly scan a file under the given path. This will read the file and stream it to clamd. Wraps ClamdClient::scan_reader, so see there for more information.

Auto Trait Implementations§

§

impl<T> Freeze for ClamdClient<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for ClamdClient<T>
where T: RefUnwindSafe,

§

impl<T> Send for ClamdClient<T>
where T: Send,

§

impl<T> Sync for ClamdClient<T>
where T: Sync,

§

impl<T> Unpin for ClamdClient<T>
where T: Unpin,

§

impl<T> UnwindSafe for ClamdClient<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more