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

Author:
Herbert Straub
Returns:
rulelist

Definition at line 188 of file NewsgroupFilter.h.

References rulelist.

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

00188                                          {
00189                 return rulelist;
00190         }

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 203 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|=().

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

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 319 of file NewsgroupFilter.h.

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

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

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 270 of file NewsgroupFilter.h.

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

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

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 360 of file NewsgroupFilter.h.

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


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 Sun Oct 24 21:08:23 2004 for NewsCache by doxygen 1.3.6-20040222