void inspectFile (char * fileName, uuid_t uuid) { void * threadData = NULL; if (threadInit != NULL) { if (!threadInit(&threadData)) { rzb_log(LOG_ERR, "Couldn't run nugget inspection threadInit."); exit(-1); } else { rzb_log(LOG_DEBUG, "Thread init for nugget complete."); } } sleep(sleepTime); struct EventId * eventId; eventId = calloc(1,sizeof(struct EventId)); struct Block * block = Block_Create (); struct List * list = NTLVList_Create(); struct stat st; stat(fileName, &st); //BlockPool_Init(); block->pId->iLength = st.st_size; if (!Transfer_Prepare_File(block, fileName, false)) { rzb_log(LOG_ERR, "Trouble preparing file transfer - '%s'", fileName); Block_Destroy(block); free(eventId); List_Destroy(list); return; } Hash_Update(block->pId->pHash, block->data.pointer, block->pId->iLength); Hash_Finalize(block->pId->pHash); uuid_copy(block->pId->uuidDataType,uuid); struct ContextList * current = NULL; while (contextList != NULL) { current = contextList; uint8_t ret = function (block, eventId, list, threadData); if ( ret >= 0 ) { rzb_log(LOG_NOTICE, "Returned with: %u", ret); } if (current == contextList) break; } List_Destroy(list); /*Don't need to free/destroy as it's done with the judgment. * Was needed previously because of cloning - cloning removed*/ //Block_Destroy(block); //free(eventId); if (threadCleanup != NULL) { threadCleanup(threadData); } }
// walk through a file, adding terms to the database. static SsiE text_processFile_impl(FILE* fin, SSIdbAccess* pDbAccess, uint nFileid, uint nMinWordlen) { if (!g_bInited) return ssierr("forgot to call text_setup()?"); text_resetMemoryIndicator(); const int bufsize = 1024*8; char buffer[bufsize]; char charCurrent = ' '; bool bInsideWord = false; uint nWordLen = 0; u32 hash = 0; Hash_Reset(hash); while (!feof(fin)) { // stream through the file, instead of loading it all into memory size_t nChars = fread(buffer, sizeof(char), bufsize, fin); for (size_t i=0; i<nChars; i++) { charCurrent = buffer[i]; if (charCurrent == '\0') return ssierr("null char in file"); // chartype is 1 if this is part of a word. int chartype = g_mapCharType[charCurrent]; if (!bInsideWord && chartype!=1) { // outside of a word, nothing needed } else if (!bInsideWord && chartype==1) { // start a new word Hash_AddChar(hash, charCurrent); nWordLen++; bInsideWord = true; } else if (bInsideWord && chartype==1) { // add char to current word Hash_AddChar(hash, charCurrent); nWordLen++; } else if (bInsideWord && chartype!=1) { // word is finished. // don't include single letters/numbers. if (nWordLen > 1 && nWordLen>=nMinWordlen) { Hash_Finalize(hash, nWordLen); if (!g_arrMemoryIndicator[hash]) { SsiE serr = SSIdbAccess_InsertCatalog(pDbAccess, hash, nFileid); if (serr) return serr; g_arrMemoryIndicator[hash] = 1; } } Hash_Reset(hash); nWordLen = 0; bInsideWord = false; } } } return SsiEOk; }