25 { .onNo = sched_onNoMatch,
26 .onFull = sched_onFullMatch,
27 .onDiff = sched_onDiffMatch,
28 .onBeginOutput = sched_noop,
29 .onBetweenIndividualOutputs = sched_noop,
30 .onEndOutput = sched_noop,
31 .ignore = sched_ignore
35 PGresult* fileIdResult =
queryFileIdsForUpload(state->dbManager, uploadId, state->ignoreFilesWithMimeType);
40 if (PQntuples(fileIdResult) == 0) {
41 PQclear(fileIdResult);
47 #ifdef MONK_MULTI_THREAD 52 MonkState* threadLocalState = &threadLocalStateStore;
54 threadLocalState->dbManager = fo_dbManager_fork(state->dbManager);
55 if (threadLocalState->dbManager) {
56 int count = PQntuples(fileIdResult);
57 #ifdef MONK_MULTI_THREAD 58 #pragma omp for schedule(dynamic) 60 for (
int i = 0; i < count; i++) {
64 long pFileId = atol(PQgetvalue(fileIdResult, i, 0));
66 if ((pFileId <= 0) || hasAlreadyResultsFor(threadLocalState->dbManager, threadLocalState->agentId, pFileId))
79 fo_dbManager_finish(threadLocalState->dbManager);
84 PQclear(fileIdResult);
91 state->scanMode = MODE_SCHEDULER;
97 if (uploadId == 0)
continue;
99 int arsId =
fo_WriteARS(fo_dbManager_getWrappedConnection(state->dbManager),
100 0, uploadId, state->agentId, AGENT_ARS, NULL, 0);
108 fo_WriteARS(fo_dbManager_getWrappedConnection(state->dbManager),
109 arsId, uploadId, state->agentId, AGENT_ARS, NULL, 1);
117 return saveNoResultToDb(state->dbManager, state->agentId, file->id);
122 const int agentId = state->agentId;
123 const long fileId = file->id;
126 printf(
"found full match between (pFile=%ld) and \"%s\" (rf_pk=%ld)\n", file->id, license->shortname, license->refId);
129 fo_dbManager_begin(dbManager);
132 long licenseFileId = saveToDb(dbManager, agentId, license->refId, fileId, 100);
133 if (licenseFileId > 0) {
134 success = saveDiffHighlightToDb(dbManager, matchInfo, licenseFileId);
138 fo_dbManager_commit(dbManager);
140 fo_dbManager_rollback(dbManager);
147 const int agentId = state->agentId;
148 const long fileId = file->id;
150 unsigned short matchPercent = diffResult->percentual;
153 printf(
"found diff match between (pFile=%ld) and \"%s\" (rf_pk=%ld); ", file->id, license->shortname, license->refId);
154 printf(
"%u%%; ", diffResult->percentual);
156 char * formattedMatchArray = formatMatchArray(diffResult->matchedInfo);
157 printf(
"diffs: {%s}\n", formattedMatchArray);
158 free(formattedMatchArray);
161 fo_dbManager_begin(dbManager);
164 long licenseFileId = saveToDb(dbManager, agentId, license->refId, fileId, matchPercent);
165 if (licenseFileId > 0) {
166 success = saveDiffHighlightsToDb(dbManager, diffResult->matchedInfo, licenseFileId);
170 fo_dbManager_commit(dbManager);
172 fo_dbManager_rollback(dbManager);
184 return hasAlreadyResultsFor(state->dbManager, state->agentId, file->id);
187 #pragma GCC diagnostic push 188 #pragma GCC diagnostic ignored "-Wunused-parameter" 192 #pragma GCC diagnostic pop
void bail(int exitval)
Disconnect with scheduler returning an error code and exit.
char * fo_scheduler_current()
Get the last read string from the scheduler.
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.
fo_dbManager * dbManager
fo_dbManager object
int queryAgentId(PGconn *dbConn)
Get agent id, exit if agent id is incorrect.
char * fo_scheduler_next()
Get the next data to process from the scheduler.
FUNCTION int fo_WriteARS(PGconn *pgConn, int ars_pk, int upload_pk, int agent_pk, const char *tableName, const char *ars_status, int ars_success)
Write ars record.
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...
PGresult * queryFileIdsForUpload(fo_dbManager *dbManager, int uploadId, bool ignoreFilesWithMimeType)
Get all file IDs (pfile_fk) for a given upload.
void matchPFileWithLicenses(CopyrightState const &state, int agentId, unsigned long pFileId, CopyrightDatabaseHandler &databaseHandler)
Get the file contents, scan for statements and save findings to database.