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

NServer.h

Go to the documentation of this file.
00001 #ifndef __NServer_h__
00002 #define __NServer_h__
00003 /* This program is free software; you can redistribute it and/or modify
00004  * it under the terms of the GNU General Public License as published by
00005  * the Free Software Foundation; either version 2 of the License, or
00006  * (at your option) any later version.
00007  *
00008  * This program is distributed in the hope that it will be useful,
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  * GNU General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU General Public License
00014  * along with this program; if not, write to the Free Software
00015  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00016  */
00017 /* Portions Copyright (C) 2003 Herbert Straub
00018  *      Implementing the ArtSpooler class
00019  *      Reimplementing the complet methods:
00020  *              CServer::postspooled (void)
00021  *              CServer::spoolarticle (Article *article)
00022  */
00023 
00024 #include <sys/param.h>
00025 #include <stdio.h>
00026 #include <string.h>
00027 #include <stdlib.h>
00028 #include <ctype.h>
00029 #include <time.h>
00030 
00031 #include <iostream>
00032 #include <fstream>
00033 
00034 class NServer;
00035 class LServer;
00036 class RServer;
00037 class CServer;
00038 
00039 #include "config.h"
00040 #include "Debug.h"
00041 
00042 #include "sstream.h"
00043 #include "util.h"
00044 
00045 #include "OverviewFmt.h"
00046 #include "ActiveDB.h"
00047 #include "NVActiveDB.h"
00048 #include "NVNewsgroup.h"
00049 #include "CNewsgroup.h"
00050 #include "Article.h"
00051 #include "MPList.h"
00052 #include "NSError.h"
00053 #include "ArtSpooler.h"
00054 
00055 /* NServer parent-class, RServer and LServer child-classes.
00056  */
00057 extern char nntp_hostname[MAXHOSTNAMELEN];
00058 extern char nntp_posting_host[MAXHOSTNAMELEN];
00059 
00060 #ifdef EXP
00061 
00074 class PostResult {
00075       public:
00076         MPListEntry ** server;
00077         int *error;
00078         int nservers;
00079 
00080          PostResult(int sz):server(NULL), errors(NULL), nserver(0) {
00081                 if ((server =
00082                      (MPListEntry **) malloc(sz *
00083                                              sizeof(MPListEntry *))) ==
00084                     NULL) {
00085                         throw
00086                             SystemError
00087                             ("cannot allocate buffer for post servers",
00088                              errno, ERROR_LOCATION);
00089                 }
00090                 if ((error = (int *) malloc(sz * sizeof(int))) == NULL) {
00091                         free(server);
00092                         server = NULL;
00093                         throw
00094                             SystemError
00095                             ("cannot allocate buffer for result list",
00096                              errno, ERROR_LOCATION);
00097                 }
00098         }
00099 
00100         ~PostResult() {
00101                 if (server)
00102                         free(server);
00103                 if (error)
00104                         free(error);
00105         }
00106 
00107         enum { Offline, None, Duplicate, NotAllowed, PostingFailed,
00108                     ResponseError, SystemError, InternalError };
00109 };
00110 #endif
00111 
00115 class NServer {
00116       protected:
00117         OverviewFmt * _OverviewFormat;
00118         ActiveDB *_ActiveDB;
00119 
00120          NServer();
00126          virtual ~ NServer();
00127       public:
00128          virtual OverviewFmt * overviewfmt() {
00129                 return _OverviewFormat;
00130         } virtual ActiveDB *active() = 0;
00131         virtual GroupInfo *groupinfo(const char *name) = 0;
00132         virtual Newsgroup *getgroup(const char *name) = 0;
00133 
00136         virtual void freegroup(Newsgroup * group);
00137         virtual int post(Article * article) = 0;
00138 };                              //NServer
00139 
00145 class LServer:virtual public NServer {
00146       protected:
00147         char _SpoolDirectory[MAXPATHLEN];
00148         ArtSpooler *pSpool;
00149 
00150          LServer():NServer(), pSpool(0) {
00151                 _SpoolDirectory[0] = '\0';
00152         } void init(const char *spooldir);
00153 
00154       public:
00155 
00158         LServer(const char *spooldir);
00159         virtual ~ LServer();
00160 
00162 
00168         virtual ActiveDB *active();
00169 
00176         virtual GroupInfo *groupinfo(const char *name);
00177 
00188         virtual Newsgroup *getgroup(const char *name);
00189 
00197         virtual int post(Article * article);
00198 };
00199 
00205 class RServer:virtual public NServer {
00206       private:
00207 
00234         void post(MPListEntry * srvr, Article * article);
00235 
00236       protected:
00237          MPList * _ServerList;
00238         MPListEntry *_CurrentServer;
00239         GroupInfo _CurrentGroup;
00240 
00241         sstream *_pServerStream;
00242 
00243          RServer():NServer() {
00244                 _ServerList = NULL;
00245                 _CurrentServer = NULL;
00246                 _pServerStream = NULL;
00247         } void init(MPList * serverlist);
00248 
00265         void connect();
00266 
00268         void disconnect();
00269 
00282         std::string issue(const char *command, const char *expresp = NULL);
00283 
00294         void setserver(MPListEntry * server);
00295 
00296         int is_connected() {
00297                 return (_pServerStream != NULL) ? 1 : 0;
00298         }
00299 
00310         void selectgroup(const char *name, int force = 0);
00311 
00312       public:
00313 
00319         RServer(MPList * serverlist);
00320 
00321         virtual ~ RServer();
00322 
00330         void setserverlist(MPList * serverlist);
00331 
00336         MPList *getserverlist(void) {
00337                 return _ServerList;
00338         }
00339 
00354         virtual ActiveDB *active();
00355 
00367         virtual GroupInfo *groupinfo(const char *name);
00368 
00383         virtual Newsgroup *getgroup(const char *name);
00384 
00397         virtual int post(Article * article);
00398 
00412         virtual void listgroup(const char *gname, char *lstgrp,
00413                                unsigned int f, unsigned int l);
00414 
00429         virtual void overviewdb(Newsgroup * ng, unsigned int fst,
00430                                 unsigned int lst);
00431 
00453         virtual void article(const char *gname, unsigned int nb,
00454                              Article * artr);
00455 
00475         virtual void article(const char *id, Article * art);
00476 };
00477 
00487 class CServer:virtual public LServer, public RServer {
00488       protected:
00489         NVActiveDB * _NVActiveDB;
00490 
00491         nvtime_t _TTLActive;
00492         nvtime_t _TTLDesc;
00493         int active_valid() {
00494                 unsigned long tm;
00495                  _NVActiveDB->getmtime(&tm);
00496                  return (tm + _TTLActive) > nvtime(NULL);
00497         } int desc_valid() {
00498                 return 1;
00499         }
00500         int group_valid();
00501 
00502         // This variable indicates, whether a newsgroup has been 
00503         // already selected on the remote news server
00504         // int _RSGroup;
00505         // Select group on remote server, if not already selected
00506         // int RSGroup(const char *name);
00507 
00508       public:
00509 
00512         CServer(const char *spooldir, MPList * serverlist);
00513 
00514         ~CServer();
00515 
00516         void setttl(time_t ttl_list, time_t ttl_desc) {
00517                 _TTLActive = ttl_list;
00518                 _TTLDesc = ttl_desc;
00519         }
00520 
00521         // News retrieval functions
00522         virtual OverviewFmt *overviewfmt() {
00523                 return _OverviewFormat;
00524         }
00525 
00532         virtual ActiveDB *active();
00533 
00543         void    invalidateActiveDB (void);
00544 
00558         virtual GroupInfo *groupinfo(const char *name);
00559 
00573         virtual Newsgroup *getgroup(const char *name);
00574 
00587         virtual int post(Article * article);
00588 
00594         virtual void spoolarticle(Article * article);
00595 
00602         virtual void postspooled(void);
00603 
00621         virtual void listgroup(const char *gname, char *lstgrp,
00622                                unsigned int f, unsigned int l);
00623 
00637         virtual void overviewdb(Newsgroup * ng, unsigned int fst,
00638                                 unsigned int lst);
00639 
00655         virtual void article(const char *gname, unsigned int nbr,
00656                              Article * art);
00657 
00677         virtual void article(const char *id, Article * art);
00678 };
00679 
00680 inline void CServer::invalidateActiveDB (void)
00681 {
00682         _NVActiveDB->setmtime (0,1); // force flag 1 !!
00683 }
00684 #endif

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