void LightgrepController::scan(const scanner_params& sp, const recursion_control_block &rcb) {
  if (!Prog) {
    // we had no valid patterns, do nothing
    return;
  }

  vector<PatternScanner*> scannerTable(lg_pattern_map_size(PatternInfo)); // [Keyword Index -> scanner], no ownership
  vector<PatternScanner*> scannerList;                                    // ownership list
  for (vector<PatternScanner*>::const_iterator itr(Scanners.begin()); itr != Scanners.end(); ++itr) {
    PatternScanner *s = (*itr)->clone();
    scannerList.push_back(s);
    for (unsigned int i = s->patternRange().first; i < s->patternRange().second; ++i) {
      scannerTable[i] = s;
    }
    s->initScan(sp);
  }
  LG_ContextOptions ctxOpts;
  ctxOpts.TraceBegin = 0xffffffffffffffff;
  ctxOpts.TraceEnd   = 0;

  LG_HCONTEXT ctx = lg_create_context(Prog, &ctxOpts);

  const sbuf_t &sbuf = sp.sbuf;

  HitData data = { this, &scannerTable, &sp, &rcb };

  // lg_search(ctx, (const char*)sbuf.buf, (const char*)sbuf.buf + sbuf.bufsize, 0, &data, gotHit);
  if (lg_search(ctx, (const char*)sbuf.buf, (const char*)sbuf.buf + sbuf.pagesize, 0, &data, gotHit) < numeric_limits<uint64_t>::max()) {
    lg_search_resolve(ctx, (const char*)sbuf.buf + sbuf.pagesize, (const char*)sbuf.buf + sbuf.bufsize, sbuf.pagesize, &data, gotHit);
  }
  lg_closeout_search(ctx, &data, gotHit);

  lg_destroy_context(ctx);

  // don't call PatternScanner::shutdown() on these! that only happens on prototypes
  for (vector<PatternScanner*>::const_iterator itr(scannerList.begin()); itr != scannerList.end(); ++itr) {
    (*itr)->finishScan(sp);
    delete *itr;
  }
}
Example #2
0
void STest::search(const char* begin, const char* end, uint64_t offset) {
  RetVal = lg_search(Ctx.get(), begin, end, offset, this, collector);
  lg_closeout_search(Ctx.get(), this, collector);
}