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

CNewsgroup.cc

Go to the documentation of this file.
00001 #include "CNewsgroup.h"
00002 
00003 void CNewsgroup::listgroup(char *lstgrp, unsigned int f, unsigned int l)
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 }
00024 
00025 void CNewsgroup::sUpdateGroupInfo(unsigned int *infofp,
00026                                   unsigned int *infolp)
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 }
00060 
00061 void CNewsgroup::sUpdateOverview(void)
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 }
00131 
00132 Article *CNewsgroup::retrievearticle(unsigned int nbr)
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 }
00143 
00144 void CNewsgroup::prefetchGroup(int lockgrp)
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 }

Generated on Fri Aug 20 10:58:06 2004 for NewsCache by doxygen 1.3.6-20040222