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 
00311         void selectgroup(const char *name, int force = 0);
00312 
00313       public:
00314 
00320         RServer(MPList * serverlist);
00321 
00322         virtual ~ RServer();
00323 
00331         void setserverlist(MPList * serverlist);
00332 
00337         MPList *getserverlist(void) {
00338                 return _ServerList;
00339         }
00340 
00355         virtual ActiveDB *active();
00356 
00368         virtual GroupInfo *groupinfo(const char *name);
00369 
00384         virtual Newsgroup *getgroup(const char *name);
00385 
00398         virtual int post(Article * article);
00399 
00414         virtual void listgroup(const char *gname, char *lstgrp,
00415                                unsigned int f, unsigned int l);
00416 
00433         virtual void overviewdb(Newsgroup * ng, unsigned int fst,
00434                                 unsigned int lst);
00435 
00458         virtual void article(const char *gname, unsigned int nb,
00459                              Article * artr);
00460 
00480         virtual void article(const char *id, Article * art);
00481 };
00482 
00492 class CServer:virtual public LServer, public RServer {
00493       protected:
00494         NVActiveDB * _NVActiveDB;
00495 
00496         nvtime_t _TTLActive;
00497         nvtime_t _TTLDesc;
00498         int active_valid() {
00499                 unsigned long tm;
00500                  _NVActiveDB->getmtime(&tm);
00501                  return (tm + _TTLActive) > nvtime(NULL);
00502         } int desc_valid() {
00503                 return 1;
00504         }
00505         int group_valid();
00506 
00507         // This variable indicates, whether a newsgroup has been 
00508         // already selected on the remote news server
00509         // int _RSGroup;
00510         // Select group on remote server, if not already selected
00511         // int RSGroup(const char *name);
00512 
00513       public:
00514 
00517         CServer(const char *spooldir, MPList * serverlist);
00518 
00519         ~CServer();
00520 
00521         void setttl(time_t ttl_list, time_t ttl_desc) {
00522                 _TTLActive = ttl_list;
00523                 _TTLDesc = ttl_desc;
00524         }
00525 
00526         // News retrieval functions
00527         virtual OverviewFmt *overviewfmt() {
00528                 return _OverviewFormat;
00529         }
00530 
00537         virtual ActiveDB *active();
00538 
00548         void    invalidateActiveDB (void);
00549 
00563         virtual GroupInfo *groupinfo(const char *name);
00564 
00578         virtual Newsgroup *getgroup(const char *name);
00579 
00592         virtual int post(Article * article);
00593 
00599         virtual void spoolarticle(Article * article);
00600 
00607         virtual void postspooled(void);
00608 
00628         virtual void listgroup(const char *gname, char *lstgrp,
00629                                unsigned int f, unsigned int l);
00630 
00644         virtual void overviewdb(Newsgroup * ng, unsigned int fst,
00645                                 unsigned int lst);
00646 
00662         virtual void article(const char *gname, unsigned int nbr,
00663                              Article * art);
00664 
00684         virtual void article(const char *id, Article * art);
00685 };
00686 
00687 inline void CServer::invalidateActiveDB (void)
00688 {
00689         _NVActiveDB->setmtime (0,1); // force flag 1 !!
00690 }
00691 #endif

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