Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

NewsgroupFilter Class Reference

#include <NewsgroupFilter.h>

List of all members.

Public Member Functions

 NewsgroupFilter ()
 NewsgroupFilter (const NewsgroupFilter &filter)
 NewsgroupFilter (const char *rulelist)
NewsgroupFilteroperator= (const NewsgroupFilter &filter)
NewsgroupFilteroperator= (const char *rulelist)
NewsgroupFilteroperator= (const string &rulelist)
int operator== (const char *rulelist)
void setWildmat (const char *pWildmat)
const string & getRulelist (void)
int matches (const char *newsgroup) const
NewsgroupFilteroperator|= (const NewsgroupFilter &filter2)
NewsgroupFilteroperator &= (const NewsgroupFilter &filter2)

Private Member Functions

void add_rule_to_rulelist (string &rulelist, const char *rule)
RuleIterator begin () const
RuleIterator end () const

Private Attributes

string rulelist
const char * c_rulelist
string Wildmat
int WildmatSearch

Friends

std::ostream & operator<< (std::ostream &os, const NewsgroupFilter &f)


Detailed Description

Author:
Thomas Gschwind

Bug:
Documentation is missing.

Definition at line 19 of file NewsgroupFilter.h.


Constructor & Destructor Documentation

NewsgroupFilter::NewsgroupFilter  )  [inline]
 

Definition at line 119 of file NewsgroupFilter.h.

References c_rulelist, rulelist, and WildmatSearch.

00119                           :WildmatSearch(0) {
00120                 c_rulelist = rulelist.c_str();
00121         }

NewsgroupFilter::NewsgroupFilter const NewsgroupFilter filter  )  [inline]
 

Construct a newsgroup filter based on a list of rules. E.g., at.*,!at.top.secret.*

Parameters:
filter The initial filter

Definition at line 128 of file NewsgroupFilter.h.

References c_rulelist, rulelist, and WildmatSearch.

00129       :    rulelist(filter.rulelist), WildmatSearch(0) {
00130                 this->c_rulelist = this->rulelist.c_str();
00131         }

NewsgroupFilter::NewsgroupFilter const char *  rulelist  )  [inline]
 

Construct a newsgroup filter based on a list of rules. E.g., at.*,!at.top.secret.*

Parameters:
rulelist Is a comma separated list of newsgroup rules. Rules may start with a '!' to indicate a reject rule and may end with the '*' wildcard.

Definition at line 140 of file NewsgroupFilter.h.

References c_rulelist, and WildmatSearch.

00141         :rulelist(rulelist), WildmatSearch(0) {
00142                 this->c_rulelist = this->rulelist.c_str();
00143         }


Member Function Documentation

void NewsgroupFilter::add_rule_to_rulelist string &  rulelist,
const char *  rule
[inline, private]
 

Add a rule to a list of rules if the rule is not already contained in the list of rules.

Parameters:
rulelist The list of rules.
rule Rule to be added.

Definition at line 94 of file NewsgroupFilter.h.

Referenced by operator &=(), and operator|=().

00094                                                                        {
00095                 const char *p = rulelist.c_str(), *q;
00096 
00097                 do {
00098                         q = rule;
00099                         while (*p == *q) {
00100                                 ++p;
00101                                 ++q;
00102                         }
00103                         if (*q == '\0' && (*p == '\0' || *p == ',')) {
00104                                 // current rule already contained in rulelist
00105                                 return;
00106                         }
00107                         while (*p && *p++ != ',');
00108                 } while (*p);
00109 
00110                 rulelist += rule;
00111                 rulelist += ',';
00112         }

RuleIterator NewsgroupFilter::begin  )  const [inline, private]
 

Definition at line 114 of file NewsgroupFilter.h.

References c_rulelist.

Referenced by operator &=(), and operator|=().

00114                                    {
00115                 return RuleIterator(c_rulelist, RuleIterator::iter_begin);
00116         } RuleIterator end() const {

RuleIterator NewsgroupFilter::end  )  const [inline, private]
 

Definition at line 116 of file NewsgroupFilter.h.

Referenced by operator &=(), and operator|=().

00116                                    {
00117                 return RuleIterator(c_rulelist, RuleIterator::iter_end);
00118       } public:

const string& NewsgroupFilter::getRulelist void   )  [inline]
 

returning the current rulelist Herbert Straub

Parameters:
void 
Returns:
rulelist

Definition at line 189 of file NewsgroupFilter.h.

References rulelist.

Referenced by check_auth_file(), check_auth_unix(), and AccessEntry::printParameters().

00189                                          {
00190                 return rulelist;
00191         }

int NewsgroupFilter::matches const char *  newsgroup  )  const [inline]
 

Check whether a given newsgroup is matched/rejected by this filter. The result is based on the longest rule matching the newsgroup. Wildmat Search Extend by Herbert Straub.

Parameters:
newsgroup The newsgroup to be matched.
Returns:
  • If the newsgroup is accepted by the filter, the number of matching characters plus one is returned.
  • If the newsgroup is rejected by the filter, the number of matching characters minus one will be returned.

Definition at line 204 of file NewsgroupFilter.h.

References c_rulelist, Wildmat, wildmat(), and WildmatSearch.

Referenced by ns_group(), ns_listgroup(), operator &=(), active_filter_group_time< Format >::operator()(), active_filter_group< Format >::operator()(), CheckOR::operator()(), CheckAND::operator()(), and operator|=().

00204                                                  {
00205                 char c;
00206                 int j, clen, bmlen = 0, bmrej = 0;
00207                 int rejrule = 0;
00208 
00209                  j = 0;
00210                 do {
00211                         clen = 0;
00212                         if (c_rulelist[j] == '!') {
00213                                 j++;
00214                                 rejrule = 1;
00215                         } else {
00216                                 rejrule = 0;
00217                         }
00218                         while ((c = c_rulelist[j]) && c == newsgroup[clen]) {
00219                                 clen++;
00220                                 j++;
00221                         }
00222 
00223                         switch (c) {
00224                         case ',':
00225                         case '\0':
00226                                 if (newsgroup[clen] != '\0'
00227                                     && !isspace(newsgroup[clen])) {
00228                                         clen = -2;
00229                                 }
00230                                 clen++;
00231                                 break;
00232                         case '*':
00233                                 clen++;
00234                                 break;
00235                         default:
00236                                 clen = -1;
00237                                 break;
00238                         }
00239 
00240                         if (clen > bmlen) {
00241                                 bmlen = clen;
00242                                 bmrej = rejrule;
00243                         }
00244 
00245                         while (c && c != ',') {
00246                                 j++;
00247                                 c = c_rulelist[j];
00248                         }
00249                         j++;
00250                 } while (c);
00251 
00252                 if (bmrej) {
00253                         return -bmlen;
00254                 } else if (!WildmatSearch) {
00255                         return bmlen;
00256                 } else {
00257                         return (wildmat(newsgroup, Wildmat.c_str())? (1)
00258                                 : (0));
00259                 }
00260                 //return bmrej?-bmlen:bmlen;
00261         }

NewsgroupFilter& NewsgroupFilter::operator &= const NewsgroupFilter filter2  )  [inline]
 

new filter matches all groups matched by current filter and by filter2.

  • Remove all reject rules of filter2 already rejected by current filter
  • Remove all accept rules rejected by other filter
    Parameters:
    filter2 The other filter.

Definition at line 320 of file NewsgroupFilter.h.

References add_rule_to_rulelist(), begin(), c_rulelist, end(), matches(), and rulelist.

00320                                                                       {
00321                 string new_rulelist;
00322                 RuleIterator begin, end;
00323                 const char *grp;
00324 
00325                 begin = this->begin();
00326                 end = this->end();
00327                 while (begin != end) {
00328                         // copy all reject rules
00329                         // copy accept rules not rejected by filter2
00330                         if ((grp = *begin)[0] == '!'
00331                             || filter2.matches(grp) > 0) {
00332                                 add_rule_to_rulelist(new_rulelist, grp);
00333                         }
00334                         ++begin;
00335                 }
00336 
00337                 begin = filter2.begin();
00338                 end = filter2.end();
00339                 while (begin != end) {
00340                         // do not add positive/negative rules already rejected
00341                         if ((grp = *begin)[0] != '!') {
00342                                 if (matches(grp) > 0) {
00343                                         add_rule_to_rulelist(new_rulelist,
00344                                                              grp);
00345                                 }
00346                         } else if (matches(grp + 1) > 0) {
00347                                 add_rule_to_rulelist(new_rulelist, grp);
00348                         }
00349                         ++begin;
00350                 }
00351 
00352                 long l;
00353                 if ((l = new_rulelist.length()) > 0) {
00354                         new_rulelist.replace(l - 1, l, "");
00355                 }
00356                 rulelist = new_rulelist;
00357                 c_rulelist = rulelist.c_str();
00358                 return *this;
00359         }

NewsgroupFilter& NewsgroupFilter::operator= const string &  rulelist  )  [inline]
 

Definition at line 161 of file NewsgroupFilter.h.

References c_rulelist.

00161                                                              {
00162                 this->rulelist = rulelist;
00163                 this->c_rulelist = this->rulelist.c_str();
00164                 return *this;
00165         }

NewsgroupFilter& NewsgroupFilter::operator= const char *  rulelist  )  [inline]
 

Definition at line 155 of file NewsgroupFilter.h.

References c_rulelist.

00155                                                           {
00156                 this->rulelist = rulelist;
00157                 this->c_rulelist = this->rulelist.c_str();
00158                 return *this;
00159         }

NewsgroupFilter& NewsgroupFilter::operator= const NewsgroupFilter filter  )  [inline]
 

Definition at line 145 of file NewsgroupFilter.h.

References c_rulelist, rulelist, Wildmat, and WildmatSearch.

00145                                                                     {
00146                 this->rulelist = filter.rulelist;
00147                 this->c_rulelist = rulelist.c_str();
00148                 this->WildmatSearch = filter.WildmatSearch;
00149                 if (this->WildmatSearch) {
00150                         this->Wildmat = filter.Wildmat;
00151                 }
00152                 return *this;
00153         }

int NewsgroupFilter::operator== const char *  rulelist  )  [inline]
 

Definition at line 167 of file NewsgroupFilter.h.

00167                                              {
00168                 return this->rulelist == rulelist;
00169         }

NewsgroupFilter& NewsgroupFilter::operator|= const NewsgroupFilter filter2  )  [inline]
 

new filter matches all groups matched by current filter or by filter2.

  • Remove all accept rules of filter2 already accepted by current filter.
  • Remove all reject rules accepted by other filter.
    Parameters:
    filter2 The other filter.

Definition at line 271 of file NewsgroupFilter.h.

References add_rule_to_rulelist(), begin(), c_rulelist, end(), matches(), and rulelist.

00271                                                                       {
00272                 string new_rulelist;
00273                 RuleIterator begin, end;
00274                 const char *grp;
00275 
00276                 begin = this->begin();
00277                 end = this->end();
00278                 while (begin != end) {
00279                         // copy all accept rules
00280                         // copy reject rules also rejected by filter2
00281                         if ((grp = *begin)[0] != '!'
00282                             || filter2.matches(grp + 1) <= 0) {
00283                                 add_rule_to_rulelist(new_rulelist, grp);
00284                         }
00285                         ++begin;
00286                 }
00287 
00288                 begin = filter2.begin();
00289                 end = filter2.end();
00290                 while (begin != end) {
00291                         // do not copy accept/reject rules of filter2 accepted by this filter
00292                         if ((grp = *begin)[0] != '!') {
00293                                 if (matches(grp) <= 0) {
00294                                         add_rule_to_rulelist(new_rulelist,
00295                                                              grp);
00296                                 }
00297                         } else if (matches(grp + 1) <= 0) {
00298                                 add_rule_to_rulelist(new_rulelist, grp);
00299                         }
00300                         ++begin;
00301                 }
00302 
00303                 long l;
00304                 if ((l = new_rulelist.length()) > 0) {
00305                         new_rulelist.replace(l - 1, l, "");
00306                 }
00307                 rulelist = new_rulelist;
00308                 c_rulelist = rulelist.c_str();
00309                 return *this;
00310         }

void NewsgroupFilter::setWildmat const char *  pWildmat  )  [inline]
 

Set Wildmat Pattern. Using the wildmat routine from Rich Salz INN Project.

Author:
Herbert Straub
Parameters:
pWildmat Wildmat Pattern. Do shell-style pattern matching for ?, \, [], and * characters.

Definition at line 178 of file NewsgroupFilter.h.

References Wildmat, and WildmatSearch.

Referenced by ns_list().

00178                                               {
00179                 Wildmat = pWildmat;
00180                 WildmatSearch = 1;
00181         }


Friends And Related Function Documentation

std::ostream& operator<< std::ostream &  os,
const NewsgroupFilter f
[friend]
 

Definition at line 361 of file NewsgroupFilter.h.

00362                                                                      {
00363                 os << f.rulelist;
00364                 return os;
00365         }


Member Data Documentation

const char* NewsgroupFilter::c_rulelist [private]
 

Definition at line 22 of file NewsgroupFilter.h.

Referenced by begin(), matches(), NewsgroupFilter(), operator &=(), operator=(), and operator|=().

string NewsgroupFilter::rulelist [private]
 

Definition at line 21 of file NewsgroupFilter.h.

Referenced by getRulelist(), NewsgroupFilter(), operator &=(), operator=(), and operator|=().

string NewsgroupFilter::Wildmat [private]
 

Definition at line 23 of file NewsgroupFilter.h.

Referenced by matches(), operator=(), and setWildmat().

int NewsgroupFilter::WildmatSearch [private]
 

Definition at line 24 of file NewsgroupFilter.h.

Referenced by matches(), NewsgroupFilter(), operator=(), and setWildmat().


The documentation for this class was generated from the following file:
Generated on Fri Aug 20 10:58:10 2004 for NewsCache by doxygen 1.3.6-20040222