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

CNewsgroup Class Reference

#include <CNewsgroup.h>

Inheritance diagram for CNewsgroup:

NVNewsgroup Newsgroup NVArray NVcontainer List of all members.

Public Member Functions

 CNewsgroup (RServer *nsrvr, OverviewFmt *fmt, const char *spooldir, const char *name)
virtual void setttl (nvtime_t grp)
virtual void setsize (unsigned int f, unsigned int l)
virtual void prefetchGroup (int lockgrp=1)
virtual void prefetchOverview (void)
virtual const char * getover (unsigned int nbr)
virtual void printheaderdb (std::ostream &os, const char *header, unsigned int f=0, unsigned int l=UINT_MAX)
virtual void printlistgroup (std::ostream &os)
virtual void printover (std::ostream &os, unsigned int nbr)
virtual void printoverdb (std::ostream &os, unsigned int f=0, unsigned int l=UINT_MAX)

Protected Member Functions

void sUpdateGroupInfo (unsigned int *infof, unsigned int *infol)
void sUpdateOverview (void)
void updateOverview (void)
void listgroup (char *lstgrp, unsigned int f, unsigned int l)
virtual Articleretrievearticle (unsigned int nbr)

Protected Attributes

nvtime_t _TTLGroup
RServer_RServer

Detailed Description

Author:
Thomas Gschwind

Bug:
method documentation are mising.

Definition at line 13 of file CNewsgroup.h.


Constructor & Destructor Documentation

CNewsgroup::CNewsgroup RServer nsrvr,
OverviewFmt fmt,
const char *  spooldir,
const char *  name
[inline]
 

Definition at line 35 of file CNewsgroup.h.

References _RServer.

00036                                                           :NVNewsgroup(fmt,
00037                                                                        spooldir,
00038                                                                        name)
00039         {
00040                 _RServer = nsrvr;
00041         }


Member Function Documentation

virtual const char* CNewsgroup::getover unsigned int  nbr  )  [inline, virtual]
 

Reimplemented from NVNewsgroup.

Definition at line 67 of file CNewsgroup.h.

References NVNewsgroup::getover(), and updateOverview().

00067                                                       {
00068                 updateOverview();
00069                 return NVNewsgroup::getover(nbr);
00070         }

void CNewsgroup::listgroup char *  lstgrp,
unsigned int  f,
unsigned int  l
[protected]
 

Definition at line 3 of file CNewsgroup.cc.

References _RServer, Logger::Error, RServer::listgroup(), Logger::p(), and slog.

Referenced by prefetchGroup(), and sUpdateOverview().

00004 {
00005         try {
00006                 _RServer->listgroup(_NewsgroupName, lstgrp, f, l);
00007         } catch(ResponseError & rs) {
00008                 // error, we should update nntpflag variable
00009                 // Assume server has all articles
00010                 slog.
00011                     p(Logger::
00012                       Error) <<
00013                     "news server does not support listgroup command\n";
00014                 memset(lstgrp, 1, l - f + 1);
00015         } catch(Error & e) {
00016                 memset(lstgrp, 1, l - f + 1);
00017         } catch(...) {
00018                 slog.p(Logger::Error)
00019                     << "UNEXPECTED EXCEPTION WHILE ISSUEING LISTGROUP\n"
00020                     << "PLEASE REPORT TO h.straub@aon.at\n";
00021                 memset(lstgrp, 1, l - f + 1);
00022         }
00023 }

void CNewsgroup::prefetchGroup int  lockgrp = 1  )  [virtual]
 

Reimplemented from NVNewsgroup.

Definition at line 144 of file CNewsgroup.cc.

References Logger::Error, listgroup(), NVcontainer::lock(), NVcontainer::nvfree(), Logger::p(), retrievearticle(), NVNewsgroup::setarticle(), NVcontainer::setmtime(), NVArray::sget(), slog, sUpdateGroupInfo(), and VERB.

00145 {
00146         VERB(slog.p(Logger::Debug) << "CNewsgroup::prefetchGroup()\n");
00147 
00148         time_t now;
00149         char *data;
00150         size_t szdata;
00151         unsigned int f, l, infof, infol;
00152         char *lstgrp;
00153         char fn[MAXPATHLEN];
00154         Article *art = NULL;
00155 
00156         NVArray::lock(NVcontainer::ExclLock);
00157         sUpdateGroupInfo(&infof, &infol);
00158 
00159         if ((lstgrp =
00160              (char *) calloc((infol - infof + 1), sizeof(char))) == NULL) {
00161                 NVArray::lock(NVcontainer::UnLock);
00162                 slog.
00163                     p(Logger::
00164                       Critical) <<
00165                     "out of memory, cannot allocate lstgrp\n";
00166                 return;
00167         }
00168 
00169         if (!lockgrp) {
00170                 NVArray::lock(NVcontainer::UnLock);
00171                 NVArray::lock(NVcontainer::ShrdLock);
00172         }
00173         f = infof;
00174         l = infol;
00175         try {
00176                 listgroup(lstgrp, infof, infol);
00177 
00178                 f = infof;
00179                 while (f <= infol) {
00180                         NVArray::sget(f, &data, &szdata);
00181                         if (!data) {
00182                                 // we do not have the article
00183                                 if (!lstgrp[f - infof]) {
00184                                         // both, we and the news server do not have the article
00185                                         f++;
00186                                         continue;
00187                                 }
00188                         } else {
00189                                 // we do have the article
00190                                 if ((*data == article
00191                                      || *data == bigarticle)
00192                                     && lstgrp[f - infof]) {
00193                                         // both, we and the news server do have the article
00194                                         f++;
00195                                         continue;
00196                                 }
00197                         }
00198                         if (!lockgrp) {
00199                                 NVArray::lock(NVcontainer::ExclLock);
00200                                 NVArray::sget(f, &data, &szdata);
00201                         }
00202                         if (lstgrp[f - infof]
00203                             && (!data || *data == overview)) {
00204                                 if ((art = retrievearticle(f)) != NULL) {
00205                                         setarticle(art);
00206                                         delete art;
00207                                 }
00208                                 if (!lockgrp)
00209                                         NVArray::lock(NVcontainer::UnLock);
00210                                 f++;
00211                                 continue;
00212                         }
00213                         if (!lstgrp[f - infof] && data) {
00214                                 int i = f - infof;
00215                                 // We do have this article, but it has been deleted
00216                                 if (*(mem_p + arrtab[i] + sizeof(long)) ==
00217                                     bigarticle) {
00218                                         // Remove article from disk
00219                                         sprintf(fn, "%s/.art%ud",
00220                                                 _SpoolDirectory, i);
00221                                         unlink(fn);
00222                                 }
00223                                 nvfree(arrtab[i]);
00224                                 arrtab[i] = 0;
00225                                 if (!lockgrp)
00226                                         NVArray::lock(NVcontainer::UnLock);
00227                                 f++;
00228                                 continue;
00229                         }
00230                         if (!lockgrp)
00231                                 NVArray::lock(NVcontainer::UnLock);
00232                         f++;
00233                 }
00234                 time(&now);
00235                 setmtime(now);
00236         }
00237         catch(Error & e) {
00238                 slog.
00239                     p(Logger::
00240                       Error) << "updating the overview database failed\n";
00241         }
00242         catch(...) {
00243                 slog.p(Logger::Error)
00244                     <<
00245                     "UNEXPECTED EXCEPTION WHILE UPDATING OVERVIEW DATABASE\n"
00246                     << "PLEASE REPORT TO h.straub@aon.at\n";
00247         }
00248         free(lstgrp);
00249         NVArray::lock(NVcontainer::UnLock);
00250 }

virtual void CNewsgroup::prefetchOverview void   )  [inline, virtual]
 

Reimplemented from NVNewsgroup.

Definition at line 58 of file CNewsgroup.h.

References NVcontainer::lock(), slog, sUpdateOverview(), and VERB.

00058                                             {
00059                 VERB(slog.
00060                      p(Logger::
00061                        Debug) << "CNewsgroup::prefetchOverview()\n");
00062                 NVArray::lock(NVcontainer::ExclLock);
00063                 sUpdateOverview();
00064                 NVArray::lock(NVcontainer::UnLock);
00065         }

virtual void CNewsgroup::printheaderdb std::ostream &  os,
const char *  header,
unsigned int  f = 0,
unsigned int  l = UINT_MAX
[inline, virtual]
 

Reimplemented from NVNewsgroup.

Definition at line 72 of file CNewsgroup.h.

References NVNewsgroup::printheaderdb(), and updateOverview().

00075                                              {
00076                 updateOverview();
00077                 NVNewsgroup::printheaderdb(os, header, f, l);
00078         }

virtual void CNewsgroup::printlistgroup std::ostream &  os  )  [inline, virtual]
 

Reimplemented from NVNewsgroup.

Definition at line 80 of file CNewsgroup.h.

References NVNewsgroup::printlistgroup(), and updateOverview().

00080                                                      {
00081                 updateOverview();
00082                 NVNewsgroup::printlistgroup(os);
00083         }

virtual void CNewsgroup::printover std::ostream &  os,
unsigned int  nbr
[inline, virtual]
 

Reimplemented from NVNewsgroup.

Definition at line 85 of file CNewsgroup.h.

References NVNewsgroup::printover(), and updateOverview().

00085                                                                   {
00086                 updateOverview();
00087                 NVNewsgroup::printover(os, nbr);
00088         }

virtual void CNewsgroup::printoverdb std::ostream &  os,
unsigned int  f = 0,
unsigned int  l = UINT_MAX
[inline, virtual]
 

Reimplemented from NVNewsgroup.

Definition at line 90 of file CNewsgroup.h.

References NVNewsgroup::printoverdb(), and updateOverview().

00091                                                                {
00092                 updateOverview();
00093                 NVNewsgroup::printoverdb(os, f, l);
00094         }

Article * CNewsgroup::retrievearticle unsigned int  nbr  )  [protected, virtual]
 

Reimplemented from Newsgroup.

Definition at line 132 of file CNewsgroup.cc.

References _RServer, and RServer::article().

Referenced by prefetchGroup().

00133 {
00134         Article *a;
00135         try {
00136                 a = new Article;
00137                 _RServer->article(_NewsgroupName, nbr, a);
00138         } catch(...) {
00139                 return NULL;
00140         }
00141         return a;
00142 }

virtual void CNewsgroup::setsize unsigned int  f,
unsigned int  l
[inline, virtual]
 

Reimplemented from NVNewsgroup.

Definition at line 47 of file CNewsgroup.h.

References NVcontainer::lock(), NVcontainer::setmtime(), and NVNewsgroup::setsize().

Referenced by CServer::getgroup(), and sUpdateGroupInfo().

00047                                                              {
00048                 lock(NVcontainer::ShrdLock);
00049                 if (f != arrfst || l != arrlst) {
00050                         NVNewsgroup::setsize(f, l);
00051                         setmtime(0, 1);
00052                 }
00053                 lock(NVcontainer::UnLock);
00054         }

virtual void CNewsgroup::setttl nvtime_t  grp  )  [inline, virtual]
 

Definition at line 43 of file CNewsgroup.h.

References _TTLGroup, and nvtime_t.

Referenced by CServer::getgroup().

00043                                           {
00044                 _TTLGroup = grp;
00045         }

void CNewsgroup::sUpdateGroupInfo unsigned int *  infof,
unsigned int *  infol
[protected]
 

Definition at line 25 of file CNewsgroup.cc.

References _RServer, NVArray::clear(), Logger::Error, GroupInfo::first(), NVNewsgroup::getsize(), RServer::groupinfo(), GroupInfo::last(), Logger::p(), setsize(), and slog.

Referenced by prefetchGroup(), and sUpdateOverview().

00027 {
00028         GroupInfo *info;
00029         unsigned int f, l, infof, infol;
00030 
00031         try {
00032                 info = _RServer->groupinfo(_NewsgroupName);
00033                 getsize(&f, &l);
00034                 infof = info->first();
00035                 infol = info->last();
00036                 if (infof != f || infol != l) {
00037                         if (info->first() < f) {
00038                                 // Oops news server's first article number is smaller than our's
00039                                 // clear database
00040                                 NVArray::clear();
00041                         }
00042                         // Set to the new size
00043                         setsize(infof, infol);
00044                 }
00045                 *infofp = infof;
00046                 *infolp = infol;
00047         }
00048         catch(Error & e) {
00049                 slog.p(Logger::Error) << "groupinfo failed\n";
00050                 getsize(infofp, infolp);
00051         }
00052         catch(...) {
00053                 slog.
00054                     p(Logger::
00055                       Error) <<
00056                     "caught an unexpected exception from groupinfo\n";
00057                 getsize(infofp, infolp);
00058         }
00059 }

void CNewsgroup::sUpdateOverview void   )  [protected]
 

Definition at line 61 of file CNewsgroup.cc.

References _RServer, Logger::Error, listgroup(), Newsgroup::name(), NVcontainer::nvfree(), RServer::overviewdb(), Logger::p(), NVcontainer::setmtime(), NVArray::shas_element(), slog, and sUpdateGroupInfo().

Referenced by prefetchOverview(), and updateOverview().

00062 {
00063         unsigned int f, l, i, infof, infol;
00064         char *lstgrp;
00065         char fn[MAXPATHLEN];
00066         time_t now;
00067 
00068         sUpdateGroupInfo(&infof, &infol);
00069 
00070         if ((lstgrp =
00071              (char *) calloc((infol - infof + 1), sizeof(char))) == NULL) {
00072                 slog.
00073                     p(Logger::
00074                       Critical) <<
00075                     "out of memory, cannot allocate lstgrp\n";
00076                 return;
00077         }
00078 
00079         try {
00080                 listgroup(lstgrp, infof, infol);
00081 
00082                 f = infof;
00083                 while (f <= infol) {
00084                         if ((NVArray::shas_element(f) && lstgrp[f - infof])
00085                             || (!NVArray::shas_element(f)
00086                                 && !lstgrp[f - infof])) {
00087                                 f++;
00088                                 continue;
00089                         }
00090                         if (lstgrp[f - infof]) {
00091                                 // We do not have this article
00092                                 l = f;
00093                                 for (i = l + 1; i < l + 8 && i <= infol;
00094                                      i++) {
00095                                         if (!NVArray::shas_element(i)
00096                                             && lstgrp[i - infof])
00097                                                 l = i;
00098                                 }
00099                                 _RServer->overviewdb(this, f, l);
00100                                 f = i;
00101                         } else {
00102                                 i = f - infof;
00103                                 // We do have this article, but it has been deleted
00104                                 if (*(mem_p + arrtab[i] + sizeof(long)) ==
00105                                     bigarticle) {
00106                                         // Remove article from disk
00107                                         sprintf(fn, "%s/.art%ud",
00108                                                 _SpoolDirectory, i);
00109                                         unlink(fn);
00110                                 }
00111                                 nvfree(arrtab[i]);
00112                                 arrtab[i] = 0;
00113                                 f++;
00114                         }
00115                 }
00116                 time(&now);
00117                 setmtime(now);
00118         } catch(Error & e) {
00119                 slog.
00120                     p(Logger::
00121                       Error) << "updating the overview database failed(" <<
00122                     name() << "): " << e._errtext << "\n";
00123         } catch(...) {
00124                 slog.p(Logger::Error)
00125                     <<
00126                     "UNEXPECTED EXCEPTION WHILE UPDATING OVERVIEW DATABASE\n"
00127                     << "PLEASE REPORT TO h.straub@aon.at\n";
00128         }
00129         free(lstgrp);
00130 }

void CNewsgroup::updateOverview void   )  [inline, protected]
 

Definition at line 21 of file CNewsgroup.h.

References _TTLGroup, NVcontainer::getmtime(), NVcontainer::lock(), nvtime(), nvtime_t, slog, sUpdateOverview(), and VERB.

Referenced by getover(), printheaderdb(), printlistgroup(), printover(), and printoverdb().

00021                                   {
00022                 VERB(slog.
00023                      p(Logger::Debug) << "CNewsgroup::updateOverview()\n");
00024                 nvtime_t mt;
00025                  getmtime(&mt);
00026                 if (mt + _TTLGroup >= nvtime(NULL))
00027                          return;
00028                  NVArray::lock(NVcontainer::ExclLock);
00029                  sUpdateOverview();
00030                  NVArray::lock(NVcontainer::UnLock);
00031         } void listgroup(char *lstgrp, unsigned int f, unsigned int l);


Member Data Documentation

RServer* CNewsgroup::_RServer [protected]
 

Definition at line 16 of file CNewsgroup.h.

Referenced by CNewsgroup(), listgroup(), retrievearticle(), sUpdateGroupInfo(), and sUpdateOverview().

nvtime_t CNewsgroup::_TTLGroup [protected]
 

Definition at line 15 of file CNewsgroup.h.

Referenced by setttl(), and updateOverview().


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