tcpflow  1.6.1
About: tcpflow is a TCP/IP packet demultiplexer that captures data transmitted as part of TCP connections (flows), and stores the data in a way that is convenient for protocol analysis and debugging.
  Fossies Dox: tcpflow-1.6.1.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

beregex.h
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3  * beregex.h:
4  *
5  * simple cover for regular expression class.
6  * The class allocates and frees the strings
7  */
8 
9 #ifndef BEREGEX_H
10 #define BEREGEX_H
11 
12 #ifdef HAVE_TRE_TRE_H
13 # include <tre/tre.h>
14 #else
15 # ifdef HAVE_REGEX_H
16 # include <regex.h>
17 # endif
18 #endif
19 
20 
21 
22 #include <string>
23 #include <iostream>
24 #include <fstream>
25 #include <assert.h>
26 #include <string.h>
27 #include <vector>
28 #include <set>
29 
30 class beregex {
31 private:
32  void compile();
33  beregex & operator=(const beregex&that); // don't use this, please
34  public:
35  /** Bargain-basement detector of things that might be regular expressions. */
36  static const char *version();
37  static bool is_regex(const std::string &str);
38 
39  std::string pat; /* our pattern */
40  int flags;
41  // Note: nreg_ is void* because the compiler will not allow us to define it as "struct regex_t *"
42  // We could get around this by including regex.h, but that introduces dependencies for programs that include
43  // beregex.h.
44  void *nreg_;
45  beregex(const beregex &that);
46  beregex(std::string pat_,int flags_);
47  ~beregex();
48  /**
49  * perform a search for a single hit. If there is a group and something is found,
50  * set *found to be what was found, *offset to be the starting offset, and *len to be
51  * the length. Note that this only handles a single group.
52  */
53  int search(const std::string &line,std::string *found,size_t *offset,size_t *len) const;
54  int search(const std::string &line,std::string *matches,int REGMAX) const;
55  std::string search(const std::string &line) const;
56 };
57 typedef std::vector<beregex *> beregex_vector;
58 
59 /**
60  * The regex_list maintains a list of regular expressions.
61  * The list can be read out of a file.
62  * check() returns true if the provided string is inside the list
63  * This should be combined with the word_and_context_list
64  */
65 class regex_list {
66  public:
67  std::vector<beregex *> patterns;
69 
70  size_t size(){
71  return patterns.size();
72  }
73  /**
74  * Read a file; returns 0 if successful, -1 if failure.
75  * @param fname - the file to read.
76  */
77  virtual ~regex_list(){
78  for(std::vector<beregex *>::iterator it=patterns.begin(); it != patterns.end(); it++){
79  delete *it;
80  }
81  }
82  void add_regex(const std::string &pat);
83  int readfile(std::string fname);
84  /** check() is threadsafe. */
85  bool check(const std::string &probe,std::string *found, size_t *offset,size_t *len) const;
86 };
87 
88 
89 #endif
std::vector< beregex * > beregex_vector
Definition: beregex.h:57
beregex & operator=(const beregex &that)
beregex(const beregex &that)
Definition: beregex.cpp:54
int flags
Definition: beregex.h:40
~beregex()
Definition: beregex.cpp:73
void * nreg_
Definition: beregex.h:44
static const char * version()
Definition: beregex.cpp:36
void compile()
Definition: beregex.cpp:64
static bool is_regex(const std::string &str)
Definition: beregex.cpp:41
int search(const std::string &line, std::string *found, size_t *offset, size_t *len) const
Definition: beregex.cpp:85
std::string pat
Definition: beregex.h:39
size_t size()
Definition: beregex.h:70
int readfile(std::string fname)
Definition: beregex.cpp:134
void add_regex(const std::string &pat)
Definition: beregex.cpp:152
virtual ~regex_list()
Definition: beregex.h:77
bool check(const std::string &probe, std::string *found, size_t *offset, size_t *len) const
Definition: beregex.cpp:159
std::vector< beregex * > patterns
Definition: beregex.h:67
regex_list()
Definition: beregex.h:68