FOSSology  4.4.0
Open Source License Compliance by Open Source Software
regscan.cc
1 /*
2  SPDX-FileCopyrightText: © 2015 Siemens AG
3  Author: Florian Krügel
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
8 #include "regscan.hpp"
9 
14 regexScanner::regexScanner(const string& type,
15  const string& identity,
16  int index)
17  : _type(type),
18  _identity(identity),
19  _index(index)
20 {
22  rcp.maybeLoad(_identity);
23  _reg = rx::regex(rcp.getRegexValue(_identity, _type),
24  rx::regex_constants::icase);
25 }
26 
33 regexScanner::regexScanner(const string& type,
34  std::istringstream& stream,
35  int index)
36  : _type(type),
37  _identity(type),
38  _index(index)
39 {
41  rcp.maybeLoad(_identity,stream);
42  _reg = rx::regex(rcp.getRegexValue(_identity, _type),
43  rx::regex_constants::icase);
44 }
45 
51 void regexScanner::ScanString(const string& s, list<match>& results) const
52 {
53  // Read file into one string
54  string::const_iterator end = s.end();
55  string::const_iterator pos = s.begin();
56  unsigned int intPos = 0;
57 
58  while (pos != end)
59  {
60  // Find next match
61  rx::smatch res;
62  if (rx::regex_search(pos, end, res, _reg))
63  {
64  // Found match
65  results.push_back(match(intPos + res.position(_index),
66  intPos + res.position(_index) + res.length(_index),
67  _type));
68  pos = res[0].second;
69  intPos += res.position() + res.length();
70  }
71  else
72  // No match found
73  break;
74  }
75 }
76 
Provide regex using conf file.
void maybeLoad(const std::string &identity)
Check if identity already loaded in RegexMap, if not load them.
const char * getRegexValue(const std::string &name, const std::string &key)
Get the regex as string from the RegexMap.
const string _identity
Definition: regscan.hpp:33
rx::regex _reg
Definition: regscan.hpp:26
const string _type
Definition: regscan.hpp:33
regexScanner(const string &type, const string &identity, int index=0)
Initialize RegexConfProvider and regex based on type and identity.
Definition: regscan.cc:14
void ScanString(const string &str, list< match > &results) const
Scan a string using regex defined during initialization.
Definition: regscan.cc:51
int s
The socket that the CLI will use to communicate.
Definition: fo_cli.c:37
list_t type structure used to keep various lists. (e.g. there are multiple lists).
Definition: nomos.h:308
Store the results of a regex match.
Definition: scanners.hpp:28