~ubuntu-branches/debian/experimental/nzbget/experimental

« back to all changes in this revision

Viewing changes to daemon/feed/FeedFilter.h

  • Committer: Package Import Robot
  • Author(s): Andreas Moog
  • Date: 2014-12-25 12:58:06 UTC
  • mfrom: (1.2.1) (3.1.4 sid)
  • Revision ID: package-import@ubuntu.com-20141225125806-vnzgajhm7mju9933
Tags: 14.1+dfsg-1
* New Upstream release (Closes: #768863)
* debian/patches:
  - Remove 0010_unnecessary_gcryptdep.patch, included upstream
  - Refresh remaining patches
* debian/control:
  - Remove no longer needed build-depends on libpar2-dev and libsigc++-dev
* debian/nzbget.conf
  - Update sample configuration file to include new options introduced by
    new upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  This file is part of nzbget
 
3
 *
 
4
 *  Copyright (C) 2013 Andrey Prygunkov <hugbug@users.sourceforge.net>
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; either version 2 of the License, or
 
9
 *  (at your option) any later version.
 
10
 *
 
11
 *  This program is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with this program; if not, write to the Free Software
 
18
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
19
 *
 
20
 * $Revision: 956 $
 
21
 * $Date: 2014-02-24 23:11:14 +0100 (Mon, 24 Feb 2014) $
 
22
 *
 
23
 */
 
24
 
 
25
 
 
26
#ifndef FEEDFILTER_H
 
27
#define FEEDFILTER_H
 
28
 
 
29
#include "DownloadInfo.h"
 
30
#include "FeedInfo.h"
 
31
#include "Util.h"
 
32
 
 
33
class FeedFilter
 
34
{
 
35
private:
 
36
        typedef std::deque<char*> RefValues;
 
37
 
 
38
        enum ETermCommand
 
39
        {
 
40
                fcText,
 
41
                fcRegex,
 
42
                fcEqual,
 
43
                fcLess,
 
44
                fcLessEqual,
 
45
                fcGreater,
 
46
                fcGreaterEqual,
 
47
                fcOpeningBrace,
 
48
                fcClosingBrace,
 
49
                fcOrOperator
 
50
        };
 
51
        
 
52
        class Term
 
53
        {
 
54
        private:
 
55
                bool                    m_bPositive;
 
56
                char*                   m_szField;
 
57
                ETermCommand    m_eCommand;
 
58
                char*                   m_szParam;
 
59
                long long               m_iIntParam;
 
60
                double                  m_fFloatParam;
 
61
                bool                    m_bFloat;
 
62
                RegEx*                  m_pRegEx;
 
63
                RefValues*              m_pRefValues;
 
64
 
 
65
                bool                    GetFieldData(const char* szField, FeedItemInfo* pFeedItemInfo,
 
66
                                                        const char** StrValue, long long* IntValue);
 
67
                bool                    ParseParam(const char* szField, const char* szParam);
 
68
                bool                    ParseSizeParam(const char* szParam);
 
69
                bool                    ParseAgeParam(const char* szParam);
 
70
                bool                    ParseNumericParam(const char* szParam);
 
71
                bool                    MatchValue(const char* szStrValue, long long iIntValue);
 
72
                bool                    MatchText(const char* szStrValue);
 
73
                bool                    MatchRegex(const char* szStrValue);
 
74
                void                    FillWildMaskRefValues(const char* szStrValue, WildMask* pMask, int iRefOffset);
 
75
                void                    FillRegExRefValues(const char* szStrValue, RegEx* pRegEx);
 
76
 
 
77
        public:
 
78
                                                Term();
 
79
                                                ~Term();
 
80
                void                    SetRefValues(RefValues* pRefValues) { m_pRefValues = pRefValues; }
 
81
                bool                    Compile(char* szToken);
 
82
                bool                    Match(FeedItemInfo* pFeedItemInfo);
 
83
                ETermCommand    GetCommand() { return m_eCommand; }
 
84
        };
 
85
 
 
86
        typedef std::deque<Term*> TermList;
 
87
 
 
88
        enum ERuleCommand
 
89
        {
 
90
                frAccept,
 
91
                frReject,
 
92
                frRequire,
 
93
                frOptions,
 
94
                frComment
 
95
        };
 
96
 
 
97
        class Rule
 
98
        {
 
99
        private:
 
100
                bool                    m_bIsValid;
 
101
                ERuleCommand    m_eCommand;
 
102
                char*                   m_szCategory;
 
103
                int                             m_iPriority;
 
104
                int                             m_iAddPriority;
 
105
                bool                    m_bPause;
 
106
                int                             m_iDupeScore;
 
107
                int                             m_iAddDupeScore;
 
108
                char*                   m_szDupeKey;
 
109
                char*                   m_szAddDupeKey;
 
110
                EDupeMode               m_eDupeMode;
 
111
                char*                   m_szSeries;
 
112
                char*                   m_szRageId;
 
113
                bool                    m_bHasCategory;
 
114
                bool                    m_bHasPriority;
 
115
                bool                    m_bHasAddPriority;
 
116
                bool                    m_bHasPause;
 
117
                bool                    m_bHasDupeScore;
 
118
                bool                    m_bHasAddDupeScore;
 
119
                bool                    m_bHasDupeKey;
 
120
                bool                    m_bHasAddDupeKey;
 
121
                bool                    m_bHasDupeMode;
 
122
                bool                    m_bPatCategory;
 
123
                bool                    m_bPatDupeKey;
 
124
                bool                    m_bPatAddDupeKey;
 
125
                bool                    m_bHasSeries;
 
126
                bool                    m_bHasRageId;
 
127
                char*                   m_szPatCategory;
 
128
                char*                   m_szPatDupeKey;
 
129
                char*                   m_szPatAddDupeKey;
 
130
                TermList                m_Terms;
 
131
                RefValues               m_RefValues;
 
132
 
 
133
                char*                   CompileCommand(char* szRule);
 
134
                char*                   CompileOptions(char* szRule);
 
135
                bool                    CompileTerm(char* szTerm);
 
136
                bool                    MatchExpression(FeedItemInfo* pFeedItemInfo);
 
137
 
 
138
        public:
 
139
                                                Rule();
 
140
                                                ~Rule();
 
141
                void                    Compile(char* szRule);
 
142
                bool                    IsValid() { return m_bIsValid; }
 
143
                ERuleCommand    GetCommand() { return m_eCommand; }
 
144
                const char*             GetCategory() { return m_szCategory; }
 
145
                int                             GetPriority() { return m_iPriority; }
 
146
                int                             GetAddPriority() { return m_iAddPriority; }
 
147
                bool                    GetPause() { return m_bPause; }
 
148
                const char*             GetDupeKey() { return m_szDupeKey; }
 
149
                const char*             GetAddDupeKey() { return m_szAddDupeKey; }
 
150
                int                             GetDupeScore() { return m_iDupeScore; }
 
151
                int                             GetAddDupeScore() { return m_iAddDupeScore; }
 
152
                EDupeMode               GetDupeMode() { return m_eDupeMode; }
 
153
                const char*             GetRageId() { return m_szRageId; }
 
154
                const char*             GetSeries() { return m_szSeries; }
 
155
                bool                    HasCategory() { return m_bHasCategory; }
 
156
                bool                    HasPriority() { return m_bHasPriority; }
 
157
                bool                    HasAddPriority() { return m_bHasAddPriority; }
 
158
                bool                    HasPause() { return m_bHasPause; }
 
159
                bool                    HasDupeScore() { return m_bHasDupeScore; }
 
160
                bool                    HasAddDupeScore() { return m_bHasAddDupeScore; }
 
161
                bool                    HasDupeKey() { return m_bHasDupeKey; }
 
162
                bool                    HasAddDupeKey() { return m_bHasAddDupeKey; }
 
163
                bool                    HasDupeMode() { return m_bHasDupeMode; }
 
164
                bool                    HasRageId() { return m_bHasRageId; }
 
165
                bool                    HasSeries() { return m_bHasSeries; }
 
166
                bool                    Match(FeedItemInfo* pFeedItemInfo);
 
167
                void                    ExpandRefValues(FeedItemInfo* pFeedItemInfo, char** pDestStr, char* pPatStr);
 
168
                const char*             GetRefValue(FeedItemInfo* pFeedItemInfo, const char* szVarName);
 
169
        };
 
170
 
 
171
        typedef std::deque<Rule*> RuleList;
 
172
 
 
173
private:
 
174
        RuleList                        m_Rules;
 
175
 
 
176
        void                            Compile(const char* szFilter);
 
177
        void                            CompileRule(char* szRule);
 
178
        void                            ApplyOptions(Rule* pRule, FeedItemInfo* pFeedItemInfo);
 
179
 
 
180
public:
 
181
                                                FeedFilter(const char* szFilter);
 
182
                                                ~FeedFilter();
 
183
        void                            Match(FeedItemInfo* pFeedItemInfo);
 
184
};
 
185
 
 
186
#endif