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

Newsgroup.h

Go to the documentation of this file.
00001 #ifndef __Newsgroup_h__
00002 #define __Newsgroup_h__
00003 
00004 #include <stdio.h>
00005 #include <sys/stat.h>
00006 #include <sys/types.h>
00007 #include <sys/file.h>
00008 #include <unistd.h>
00009 #include <utime.h>
00010 #include <errno.h>
00011 #include <time.h>
00012 #include <fcntl.h>
00013 #include <stdlib.h>
00014 #include <limits.h>
00015 
00016 #include <iostream>
00017 #include <fstream>
00018 #include <string>
00019 
00020 #include "config.h"
00021 #include "Debug.h"
00022 #include "OverviewFmt.h"
00023 
00024 // A NNTP-command must not exceed 512 characters including the
00025 // trailing \r\n. 512 chars is a good approx for the max length
00026 // of a newsgroup
00027 #define MAXGROUPNAMELEN 512
00028 #define MAXNEWSGROUPNAMELEN MAXGROUPNAMELEN
00029 
00030 class Newsgroup {
00031       protected:
00032         char _NewsgroupName[MAXGROUPNAMELEN + 1];
00033         OverviewFmt *_OverviewFormat;
00034         virtual Article *retrievearticle(unsigned int nbr) {
00035                 return NULL;
00036       } public:
00037          Newsgroup(OverviewFmt * fmt, const char *name) {
00038                 _OverviewFormat = fmt;
00039                 _NewsgroupName[MAXGROUPNAMELEN] = '\0';
00040                 strncpy(_NewsgroupName, name, MAXGROUPNAMELEN);
00041                 ASSERT(if (strlen(name) > MAXGROUPNAMELEN) {
00042                        slog.
00043                        p(Logger::
00044                          Error) <<
00045                        "Name of newsgroup too long - truncated\n";}
00046                 );
00047         }
00048         virtual ~ Newsgroup();
00049 
00050         void setoverviewfmt(OverviewFmt * fmt) {
00051                 _OverviewFormat = fmt;
00052         }
00053         OverviewFmt *getoverviewfmt() {
00054                 return _OverviewFormat;
00055         }
00056 
00057 #ifdef ENABLE_ASSERTIONS
00058         virtual void testdb(void) {
00059         }
00060 #endif
00061         const char *name(void) {
00062                 return _NewsgroupName;
00063         }
00064         virtual void getsize(unsigned int *f, unsigned int *l) = 0;
00065         virtual void setsize(unsigned int f, unsigned int l) = 0;
00066         virtual unsigned int firstnbr() = 0;
00067         virtual unsigned int lastnbr() = 0;
00068         virtual int hasrecord(unsigned int i) = 0;
00069 //   virtual void hasrecords(unsigned int *rlist)=0;
00070 
00071         virtual Article *getarticle(unsigned int nbr) = 0;
00072         virtual void freearticle(Article * artp) = 0;
00073         virtual void setarticle(Article * art) = 0;
00074         virtual void printarticle(std::ostream & os, unsigned int nbr) = 0;
00075         virtual void prefetchGroup(int lockgrp = 1) = 0;
00076         virtual void prefetchOverview(void) = 0;
00077 
00078         virtual const char *getover(unsigned int nbr) = 0;
00079         virtual void setover(const string & over) = 0;
00080         virtual void printover(std::ostream & os, unsigned int nbr) {
00081                 const char *o = getover(nbr);
00082                 if (o)
00083                         os << o << "\r\n";
00084         }
00085         virtual void readoverdb(std::istream & is) = 0;
00086         virtual void printoverdb(std::ostream & os, unsigned int f =
00087                                  0, unsigned int l = UINT_MAX) {
00088                 unsigned int i, ol;
00089                 const char *o;
00090                 getsize(&i, &ol);
00091                 if (f > i)
00092                         i = f;
00093                 if (l > ol)
00094                         l = ol;
00095                 while (i <= l) {
00096                         if ((o = getover(i++)) != NULL)
00097                                 os << o << "\r\n";
00098                 }
00099         }
00100         virtual void printheaderdb(std::ostream & os,
00101                                    const char *header,
00102                                    unsigned int f = 0, unsigned int l =
00103                                    UINT_MAX) = 0;
00104         virtual void printlistgroup(std::ostream & os) = 0;
00105 };
00106 
00107 #ifdef _INCLUDE_NewsgroupIter_
00108 class NewsgroupIter {
00109       protected:
00110         Newsgroup * _ng;
00111         unsigned int i;
00112         int lck;
00113       public:
00114          NewsgroupIter() {
00115         } NewsgroupIter(Newsgroup * ng) {
00116                 _ng = ng;
00117         }
00118         void attach(Newsgroup * ng) {
00119                 _ng = ng;
00120         }
00121         void first() {
00122                 i++;
00123         }
00124         void next() {
00125                 i--;
00126         }
00127         void set(unsigned int j) {
00128                 i = j;
00129         }
00130 
00131         Article *article() {
00132                 return _ng->getarticle(i);
00133         }
00134         OverviewRecord *overview() {
00135                 return _ng->getarticle(i);
00136         }
00137 };
00138 #endif
00139 #endif

Generated on Sun Oct 24 21:08:18 2004 for NewsCache by doxygen 1.3.6-20040222