Class: ClamAV::PatchClient

Inherits:
Object
  • Object
show all
Defined in:
lib/clamav/patch_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(connection = default_connection) ⇒ PatchClient

Returns a new instance of PatchClient.



31
32
33
34
# File 'lib/clamav/patch_client.rb', line 31

def initialize(connection = default_connection)
  @connection = connection
  connection.establish_connection
end

Instance Method Details

#default_connectionObject



40
41
42
43
44
45
# File 'lib/clamav/patch_client.rb', line 40

def default_connection
  ClamAV::Connection.new(
    socket: resolve_default_socket,
    wrapper: ::ClamAV::Wrappers::NewLineWrapper.new
  )
end

#execute(command) ⇒ Object



36
37
38
# File 'lib/clamav/patch_client.rb', line 36

def execute(command)
  command.call(@connection)
end

#instream(io) ⇒ Object (private)



68
69
70
# File 'lib/clamav/patch_client.rb', line 68

def instream(io)
  execute Commands::InstreamCommand.new(io)
end

#pingObject



56
57
58
# File 'lib/clamav/patch_client.rb', line 56

def ping
  execute Commands::PingCommand.new
end

#resolve_default_socketObject



47
48
49
50
51
52
53
54
# File 'lib/clamav/patch_client.rb', line 47

def resolve_default_socket
  unix_socket, tcp_host, tcp_port = ENV.values_at('CLAMD_UNIX_SOCKET', 'CLAMD_TCP_HOST', 'CLAMD_TCP_PORT')
  if tcp_host && tcp_port
    ::TCPSocket.new(tcp_host, tcp_port)
  else
    ::UNIXSocket.new(unix_socket || '/var/run/clamav/clamd.ctl')
  end
end

#safe?(target) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
63
64
# File 'lib/clamav/patch_client.rb', line 60

def safe?(target)
  return instream(target).virus_name.nil? if target.is_a?(StringIO)

  scan(target).all? { |file| file.virus_name.nil? }
end

#scan(file_path) ⇒ Object (private)



72
73
74
# File 'lib/clamav/patch_client.rb', line 72

def scan(file_path)
  execute Commands::PatchScanCommand.new(file_path)
end