Back to index

courier  0.68.2
search.h
Go to the documentation of this file.
00001 #ifndef       search_h
00002 #define       search_h
00003 
00004 
00005 #include      "re.h"
00006 #include      "buffer.h"
00007 
00008 #if    HAVE_PCRE_H
00009 #include      <pcre.h>
00010 #else
00011 #include      <pcre/pcre.h>
00012 #endif
00013 
00015 //
00016 // The Search class encapsulates the entire functionality of matching
00017 // patterns against the message.
00018 //
00019 // There are two main modes, both implemented by the overloaded find()
00020 // function.  The first find() function matches a pattern against
00021 // the message, the second find() function matches a pattern against
00022 // text in memory.
00023 //
00024 // The find() function requires that the pattern, and pattern flags
00025 // be already separated.
00026 //
00027 // The find() function returns -1 if there was an error in the format
00028 // of the regular expression, 0 if the pattern was good, and it was
00029 // successfully searched.
00030 //
00031 // The 'score' variable is set when find() returns 0.  If a pattern was
00032 // found, it is set to 1, else it is set to 0.  If the pattern flags
00033 // requested a weighted scoring search, the 'score' variable will
00034 // contain the calculated score.
00035 //
00036 // If a weighted scoring is not requested, the find() function automatically
00037 // sets the MATCH... variables (from the '!' operator).
00038 //
00040 
00041 class MessageInfo;
00042 class Message;
00043 
00044 class Search {
00045 
00046        pcre   *pcre_regexp;
00047        pcre_extra *pcre_regexp_extra;
00048        int    *pcre_vectors;
00049        size_t pcre_vector_count;
00050 
00051        Re     regexp;
00052        Buffer current_line;
00053        Buffer next_line;
00054 
00055        int    match_header, match_body;
00056        double weight1, weight2;
00057        int    scoring_match;
00058 
00059        int init(const char *, const char *);
00060 
00061        void cleanup();
00062 
00063 public:
00064        double score; // For weighted scoring.  Without scoring, this is
00065                      // either 0, or 1.
00066 
00067        Search() : pcre_regexp(NULL), pcre_regexp_extra(NULL),
00068               pcre_vectors(NULL)   {}
00069        ~Search()     { cleanup(); }
00070        int find(Message &, MessageInfo &, const char *, const char *,
00071               Buffer *);
00072        int find(const char *, const char *, const char *, Buffer *);
00073 private:
00074        int findinline(Message &, const char *, Buffer *);
00075        int findinsection(Message &, const char *, Buffer *);
00076        void init_match_vars(ReMatch &, Buffer *);
00077        void init_match_vars(const char *, int, int *, Buffer *);
00078 } ;
00079 #endif