Once you have allocated a session context and (optionally) set connection parameters, you can use it to check files and memory for viruses. The following function allows to check a file:
The kav_check_file function directs KAVDaemon to check the file filename for viruses. The filename can be absolute or relative. The session is identified by the session context ctx, which must be previously allocated by kav_new, as described in the section called “Allocating session context”.
The filename can be a directory. In this case, KAVDaemon will recursively check all files in that directory and its subdirectories. Depending on KAVDaemon settings, it may also check packed files inside archives (such as .tar.gz or .zip files), and attachments within mailbox files.
The results of the check are recorded in the session context. Use the functions described in the section called “Interpreting check results” further in this manual to extract detailed information about the results of the check from the session context.
When kav_check_file succeeds, it returns 0. If it fails, it returns -1. In the latter case, use the kav_get_error function to find out what went wrong. Note that a call to kav_check_file is considered successful if the function successfully contacted KAVDaemon and got a reply from it. It has nothing to do with whether viruses were found or not. To find our that, use the function described in the section called “Interpreting check results” to examine ctx.
The possible libkavclient error codes that kav_check_file can set are as follows:
The system failed to create a socket. Examine the system errno value to find out why. This is a rare error, and if you see it, something is wrong with your system.
Connection to KAVDaemon failed. Examine the system errno value to find out why. The most likely reason for this error is that KAVDaemon is not running, or the path to KAVDaemon socket (as set by kav_set_socketpath) is incorrect (in that case errno will be set to ENOENT).
A check is already in progress in the given session context. This can only happen in a multi-threaded application when two threads call one of the checking functions in the same context concurrently.
An error occured while sending the request ro KAVDaemon. Check the system errno value to find out what kind of error.
The request to KAVDaemon was succesfully sent, but some error occurred while waiting for reply. Check the system errno value to find out what kind of error. Note that libkavclient waits for reply using the system select function.
The request to KAVDaemon was succesfully sent, but no response was received from KAVDaemon. The amount of time that libkavclient waits before returning this error can be set by the kav_set_timeout function, and by default is 5 seconds.
libkavclient started reading the reply from KAVDaemon, but some error occurred while reading. Check the system errno value to find out what kind of error.
KAVDaemon was successfully contacted, but it failed to perform the requested check because it didn't find a valid key file. This means that you don't have a valid license to use KAVDaemon (remember, KAVDaemon is commercial software!). You should contact Kaspersky Lab.
KAVDaemon was successfully contacted, but it failed to perform the requested check because it couldn't find its virus definition bases. Either something is wrong with your KAVDaemon configuration, or you need to run kavupdater to download the virus definition bases.
KAVDaemon was successfully contacted, but it failed to perform the requested check because it detected internal integrity violation. Most probably this means that your KAVDaemon binary is corrupt. You need to reinstall it.
Your system failed to allocate memory for libkavclient. Most probably you are out of memory.