Class: Clamd::Client

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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(options = {})
  self.host = options[:host] || Clamd.configuration.host
  self.port = options[:port] || Clamd.configuration.port
  self.open_timeout = options[:open_timeout] || Clamd.configuration.open_timeout
  self.read_timeout = options[:read_timeout] || Clamd.configuration.read_timeout
  self.chunk_size = options[:chunk_size] || Clamd.configuration.chunk_size
end

Instance Attribute Details

#chunk_sizeObject

Returns the value of attribute chunk_size.



24
25
26
# File 'lib/clamd/client.rb', line 24

def chunk_size
  @chunk_size
end

#hostObject

Returns the value of attribute host.



24
25
26
# File 'lib/clamd/client.rb', line 24

def host
  @host
end

#open_timeoutObject

Returns the value of attribute open_timeout.



24
25
26
# File 'lib/clamd/client.rb', line 24

def open_timeout
  @open_timeout
end

#portObject

Returns the value of attribute port.



24
25
26
# File 'lib/clamd/client.rb', line 24

def port
  @port
end

#read_timeoutObject

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

Method used to feed INSTREAM command to ClamdAV daemon

Usage:

clamd = Clamd::Client.new
clamd.instream('/home/soundar/documents/doc.pdf') # file


149
150
151
# File 'lib/clamd/client.rb', line 149

def instream(path)
  exec(COMMAND[:instream], path)
end

#multiscan(path) ⇒ Object

Method used to feed MULTISCAN command to ClamdAV daemon

Usage:

clamd = Clamd::Client.new
clamd.multiscan('/home/soundar/documents/doc.pdf') # file
clamd.multiscan('/home/soundar/documents') # directory


137
138
139
# File 'lib/clamd/client.rb', line 137

def multiscan(path)
  exec(COMMAND[:multiscan], path)
end

#pingObject

Method used to feed PING command to ClamdAV daemon

Usage:

clamd = Clamd::Client.new
clamd.ping


58
59
60
# File 'lib/clamd/client.rb', line 58

def ping
  exec(COMMAND[:ping])
end

#reloadObject

Method used to feed RELOAD command to ClamdAV daemon

Usage:

clamd = Clamd::Client.new
clamd.reload


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

#shutdownObject

Method used to feed SHUTDOWN command to ClamdAV daemon

Usage:

clamd = Clamd::Client.new
clamd.shutdown

Return value: true on success false on failure



96
97
98
99
100
# File 'lib/clamd/client.rb', line 96

def shutdown
  exec(COMMAND[:shutdown])

  ping =~ /^ERROR: Connection refused.*$/ ? true : false
end

#statsObject

Method used to feed STATS command to ClamdAV daemon

Usage:

clamd = Clamd::Client.new
clamd.stats


161
162
163
# File 'lib/clamd/client.rb', line 161

def stats
  exec(COMMAND[:stats])
end

#versionObject

Method used to feed VERSION command to ClamdAV daemon

Usage:

clamd = Clamd::Client.new
clamd.version


70
71
72
# File 'lib/clamd/client.rb', line 70

def version
  exec(COMMAND[:version])
end