FOSSology  4.4.0
Open Source License Compliance by Open Source Software
scancode.cc
1 /*
2  SPDX-FileCopyrightText: © 2021 Sarita Singh <saritasingh.0425@gmail.com>
3 
4  SPDX-License-Identifier: GPL-2.0-only
5 */
6 
7 #include "scancode.hpp"
8 
14 #define return_sched(retval) \
15  do {\
16  fo_scheduler_disconnect((retval));\
17  return (retval);\
18  } while(0)
19 
20 int main(int argc, char* argv[])
21 {
22  DbManager dbManager(&argc, argv);
23  ScancodeDatabaseHandler databaseHandler(dbManager);
24  string scanFlags;
25  bool ignoreFilesWithMimeType;
26  if(!parseCommandLine(argc, argv, scanFlags, ignoreFilesWithMimeType)){
27  return_sched(1);
28  }
29 
30  State state = getState(dbManager);
31  state.setCliOptions(scanFlags);
32  if (!databaseHandler.createTables())
33  {
34  LOG_FATAL("initialization failed \n");
35  return_sched(9);
36  }
37 
38  while (fo_scheduler_next() != NULL)
39  {
40  int uploadId = atoi(fo_scheduler_current());
41 
42  if (uploadId == 0) continue;
43 
44  int arsId = writeARS(state, 0, uploadId, 0, dbManager);
45 
46  if (arsId <= 0)
47  bail(5);
48 
49  if (!processUploadId(state, uploadId, databaseHandler,ignoreFilesWithMimeType))
50  bail(2);
51 
53  writeARS(state, arsId, uploadId, 1, dbManager);
54  }
56 
57  /* do not use bail, as it would prevent the destructors from running */
59  return 0;
60 }
Definition: state.hpp:16
void setCliOptions(string cliOptions)
setter for command line interface options
DB wrapper for agents.
int writeARS(int agentId, int arsId, int uploadId, int success, const fo::DbManager &dbManager)
Call C function fo_WriteARS() and translate the arguments.
CopyrightState getState(CliOptions &&cliOptions)
Create a new state for the current agent based on CliOptions.
bool processUploadId(const CopyrightState &state, int agentId, int uploadId, CopyrightDatabaseHandler &databaseHandler, bool ignoreFilesWithMimeType)
Process a given upload id, scan from statements and add to database.
void bail(int exitval)
Disconnect with scheduler returning an error code and exit.
void fo_scheduler_disconnect(int retcode)
Disconnect the scheduler connection.
void fo_scheduler_heart(int i)
This function must be called by agents to let the scheduler know they are alive and how many items th...
char * fo_scheduler_current()
Get the last read string from the scheduler.
char * fo_scheduler_next()
Get the next data to process from the scheduler.
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:16
#define return_sched(retval)
Definition: ojos.cc:50