Class: ClamAV::PatchClient
- Inherits:
-
Object
- Object
- ClamAV::PatchClient
- Defined in:
- lib/clamav/patch_client.rb
Instance Method Summary collapse
- #default_connection ⇒ Object
- #execute(command) ⇒ Object
-
#initialize(connection = default_connection) ⇒ PatchClient
constructor
A new instance of PatchClient.
- #instream(io) ⇒ Object private
- #ping ⇒ Object
- #resolve_default_socket ⇒ Object
- #safe?(target) ⇒ Boolean
- #scan(file_path) ⇒ Object private
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_connection ⇒ Object
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 |
#ping ⇒ Object
56 57 58 |
# File 'lib/clamav/patch_client.rb', line 56 def ping execute Commands::PingCommand.new end |
#resolve_default_socket ⇒ Object
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
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 |