<commit_before>#include <QDebug>
#include <jansson.h>

#include "VtFile.h"
#include "VtResponse.h"
#include "qvtfile.h"
#include "vt-log.h"

#include "scan_file_task.h"


ScanFileTask::ScanFileTask(QVtFile *vt_file)
{
  file = vt_file;
}

#define RESP_BUF_SIZE 255

//Scan for a file
void ScanFileTask::ScanSmallFile(void)
{
  int ret;
  struct VtFile *api = VtFile_new();
  struct VtResponse *response;
  char *str = NULL;
  char buf[RESP_BUF_SIZE+1] = { 0, };
  int response_code;


  VtFile_setApiKey(api, file->GetApiKey().toStdString().c_str());

  ret = VtFile_scan(api, file->fileName().toStdString().c_str());

  if (ret) {
    qDebug() << "Error opening fetching report " << QString(file->GetSha256().toHex()) << "  " << ret;
    emit LogMsg(VT_LOG_ERR, ret, "Error fetching report");
  } else {
    response = VtFile_getResponse(api);
    str = VtResponse_toJSONstr(response, VT_JSON_FLAG_INDENT);
    if (str) {
      qDebug() << "Scan Response: " << str;
      free(str);
    }
    VtResponse_getVerboseMsg(response, buf, RESP_BUF_SIZE);
    qDebug() << "Buff: " << buf;
    file->SetVerboseMsg(buf);

    ret = VtResponse_getResponseCode(response, &response_code);
    if (!ret) {
      qDebug() << "scan response code: " <<  response_code;

    } else {
      emit LogMsg(VT_LOG_ERR, ret, "Error fetching scan response code");
      goto free_response;
    }

    if (response_code == 1) {
      file->SetScanDate(QDateTime::currentDateTime());
      file->SetState(kWaitForReport);
    } else {
      // FIXME  what other codes?<commit_msg>set uploaded state retry getting report on error<commit_after>#include <QDebug>
#include <jansson.h>

#include "VtFile.h"
#include "VtResponse.h"
#include "qvtfile.h"
#include "vt-log.h"

#include "scan_file_task.h"


ScanFileTask::ScanFileTask(QVtFile *vt_file)
{
  file = vt_file;
}

#define RESP_BUF_SIZE 255

//Scan for a file
void ScanFileTask::ScanSmallFile(void)
{
  int ret;
  struct VtFile *api = VtFile_new();
  struct VtResponse *response;
  char *str = NULL;
  char buf[RESP_BUF_SIZE+1] = { 0, };
  int response_code;


  VtFile_setApiKey(api, file->GetApiKey().toStdString().c_str());

  ret = VtFile_scan(api, file->fileName().toStdString().c_str());

  if (ret) {
    qDebug() << "Error opening fetching report " << QString(file->GetSha256().toHex()) << "  " << ret;
     file->SetState(kWaitForReport);
    emit LogMsg(VT_LOG_ERR, ret, "Error fetching report");
  } else {
    response = VtFile_getResponse(api);
    str = VtResponse_toJSONstr(response, VT_JSON_FLAG_INDENT);
    if (str) {
      qDebug() << "Scan Response: " << str;
      free(str);
    }
    VtResponse_getVerboseMsg(response, buf, RESP_BUF_SIZE);
    qDebug() << "Buff: " << buf;
    file->SetVerboseMsg(buf);

    ret = VtResponse_getResponseCode(response, &response_code);
    if (!ret) {
      qDebug() << "scan response code: " <<  response_code;

    } else {
      emit LogMsg(VT_LOG_ERR, ret, "Error fetching scan response code");
      goto free_response;
    }

    if (response_code == 1) {
      file->SetScanDate(QDateTime::currentDateTime());
      file->SetState(kWaitForReport);
      file->SetUploaded(true);
    } else {
      // FIXME  what other codes?
{'fraction_non_alphanumeric': 0.14877061935885466, 'fraction_numerical': 0.0056022408963585435, 'mean_word_length': 3.775631500742942, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6467283', 'n_tokens_mistral': 1195, 'n_tokens_neox': 1165, 'n_words': 238}