Class: Clamd::Client
- Inherits:
-
Object
- Object
- Clamd::Client
- Includes:
- SocketManager
- Defined in:
- lib/clamd/client.rb
Overview
Class that interacts with ClamdAV daemon
Clamd::Client is responsible for interacting with ClamdAV daemon.
For example you can connect ClamdAV daemon as given below
clamd = Clamd::Client.new
clamd.ping
In the above example the ClamdAV daemon details will be get from the Clamd::Configuration
You can also override the global Clamd::Configuration as given below
clamd = Clamd::Client.new(host: '172.15.20.11', port: 8321)
clamd.ping
Constant Summary collapse
- COMMAND =
Supported ClamdAV daemon commands
{ ping: "PING", version: "VERSION", reload: "RELOAD", shutdown: "SHUTDOWN", scan: "SCAN", contscan: "CONTSCAN", multiscan: "MULTISCAN", instream: "zINSTREAM\0", stats: "zSTATS\0" }.freeze
Instance Attribute Summary collapse
-
#chunk_size ⇒ Object
Returns the value of attribute chunk_size.
-
#host ⇒ Object
Returns the value of attribute host.
-
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
-
#port ⇒ Object
Returns the value of attribute port.
-
#read_timeout ⇒ Object
Returns the value of attribute read_timeout.
Instance Method Summary collapse
-
#contscan(path) ⇒ Object
Method used to feed CONTSCAN command to ClamdAV daemon.
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
-
#instream(path) ⇒ Object
Method used to feed INSTREAM command to ClamdAV daemon.
-
#multiscan(path) ⇒ Object
Method used to feed MULTISCAN command to ClamdAV daemon.
-
#ping ⇒ Object
Method used to feed PING command to ClamdAV daemon.
-
#reload ⇒ Object
Method used to feed RELOAD command to ClamdAV daemon.
-
#scan(path) ⇒ Object
Method used to feed SCAN command to ClamdAV daemon.
-
#shutdown ⇒ Object
Method used to feed SHUTDOWN command to ClamdAV daemon.
-
#stats ⇒ Object
Method used to feed STATS command to ClamdAV daemon.
-
#version ⇒ Object
Method used to feed VERSION command to ClamdAV daemon.
Methods included from SocketManager
#clamd_response_size, #close_socket, #open_socket, #read_socket, #stop_streaming, #stream_to_clamd, #write_chunk, #write_socket
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
43 44 45 46 47 48 49 |
# File 'lib/clamd/client.rb', line 43 def initialize( = {}) self.host = [:host] || Clamd.configuration.host self.port = [:port] || Clamd.configuration.port self.open_timeout = [:open_timeout] || Clamd.configuration.open_timeout self.read_timeout = [:read_timeout] || Clamd.configuration.read_timeout self.chunk_size = [:chunk_size] || Clamd.configuration.chunk_size end |
Instance Attribute Details
#chunk_size ⇒ Object
Returns the value of attribute chunk_size.
24 25 26 |
# File 'lib/clamd/client.rb', line 24 def chunk_size @chunk_size end |
#host ⇒ Object
Returns the value of attribute host.
24 25 26 |
# File 'lib/clamd/client.rb', line 24 def host @host end |
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
24 25 26 |
# File 'lib/clamd/client.rb', line 24 def open_timeout @open_timeout end |
#port ⇒ Object
Returns the value of attribute port.
24 25 26 |
# File 'lib/clamd/client.rb', line 24 def port @port end |
#read_timeout ⇒ Object
Returns the value of attribute read_timeout.
24 25 26 |
# File 'lib/clamd/client.rb', line 24 def read_timeout @read_timeout end |
Instance Method Details
#contscan(path) ⇒ Object
Method used to feed CONTSCAN command to ClamdAV daemon
Usage:
clamd = Clamd::Client.new
clamd.contscan('/home/soundar/documents/doc.pdf') (file)
clamd.contscan('/home/soundar/documents') (directory)
124 125 126 |
# File 'lib/clamd/client.rb', line 124 def contscan(path) exec(COMMAND[:contscan], path) end |
#instream(path) ⇒ Object
149 150 151 |
# File 'lib/clamd/client.rb', line 149 def instream(path) exec(COMMAND[:instream], path) end |
#multiscan(path) ⇒ Object
137 138 139 |
# File 'lib/clamd/client.rb', line 137 def multiscan(path) exec(COMMAND[:multiscan], path) end |
#ping ⇒ Object
58 59 60 |
# File 'lib/clamd/client.rb', line 58 def ping exec(COMMAND[:ping]) end |
#reload ⇒ Object
82 83 84 |
# File 'lib/clamd/client.rb', line 82 def reload exec(COMMAND[:reload]) end |
#scan(path) ⇒ Object
Method used to feed SCAN command to ClamdAV daemon
Usage:
clamd = Clamd::Client.new
clamd.scan('/home/soundar/documents/doc.pdf') (file)
clamd.scan('/home/soundar/documents') (directory)
111 112 113 |
# File 'lib/clamd/client.rb', line 111 def scan(path) exec(COMMAND[:scan], path) end |
#shutdown ⇒ Object
96 97 98 99 100 |
# File 'lib/clamd/client.rb', line 96 def shutdown exec(COMMAND[:shutdown]) ping =~ /^ERROR: Connection refused.*$/ ? true : false end |
#stats ⇒ Object
161 162 163 |
# File 'lib/clamd/client.rb', line 161 def stats exec(COMMAND[:stats]) end |