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

MPList.h

Go to the documentation of this file.
00001 #ifndef _MPList_h_
00002 #define _MPList_h_
00003 #include <ctype.h>
00004 #include <stdio.h>
00005 #include <netdb.h>
00006 #include <sys/param.h>
00007 
00008 #include <iostream>
00009 #include <fstream>
00010 #include <vector>
00011 
00012 #include "Debug.h"
00013 #include "Error.h"
00014 #include "OverviewFmt.h"
00015 #include "Lexer.h"
00016 
00017 struct MPListEntry {
00018       public:
00019         enum {
00020                 F_SETPOSTFLAG = 0x01,
00021                 F_CACHED = 0x02,
00022                 F_OFFLINE = 0x04,
00023                 F_SEMIOFFLINE = 0x08
00024         };
00025         // nntp commands supported by the server
00026         enum {
00027                 F_LIST_ACTIVE_WILDMAT = 0x01,
00028                 F_LIST_OVERVIEW_FMT = 0x02,
00029                 F_LISTGROUP = 0x04,
00030                 F_MODE_READER = 0x08,
00031                 F_OVER = 0x10,
00032                 F_XOVER = 0x20,
00033                 F_POST = 0x40
00034         };
00035 
00036         char hostname[MAXHOSTNAMELEN];
00037         char servicename[256];
00038         char user[64];
00039         char passwd[64];
00040 
00041         OverviewFmt overview;
00042 
00043         char read[2048];        // Groups read from that server
00044         char postTo[2048];      // Postings handled by this server
00045         char bindFrom[2048];    // From which interface
00046         time_t groupTimeout;
00047 
00048         unsigned int flags;     // configuration flags
00049         unsigned int nntpflags; // supported NNTP-Commands
00050         int retries;
00051 
00052         MPListEntry();
00053         void init(void);
00054         void printParameters (std::ostream *pOut);
00055 };
00056 
00063 class MPList {
00064       public:
00065         std::vector < MPListEntry > entries;
00066 
00067       private:
00068 
00069       public:
00070         MPList() {};
00071 //   void addserver(const char *ns,const char *p,const char *g) {//     if(e_used==e_alloc) myrealloc(e_used+1);//     entries[e_used].init(ns,p);//     if(g) {//       strcpy(entries[e_used].read,g);//       strcpy(entries[e_used].postTo,g);//     }//     e_used++;//   }
00072         const char *makeFilter(unsigned int servernbr,
00073                                const char *listarg) const;
00074         MPListEntry *server(const char *group);
00075         MPListEntry *postserver(const char *group);
00076         void init(void);
00077         void read(Lexer & lex);
00078         void readServer(Lexer & lex, const char *host, const char *port);
00079         void printParameters(std::ostream *pOut);
00080 
00081 };
00082 
00083 
00084 // Inline methods
00085 inline MPListEntry::MPListEntry () {
00086         init();
00087 }
00088 
00089 inline void MPListEntry::init(void)
00090 {
00091         hostname[0] = servicename[0] = '\0';
00092         user[0] = passwd[0] = '\0';
00093 
00094         read[0] = postTo[0] = bindFrom[0] = '\0';
00095         groupTimeout = 600;     // 10m
00096         retries = 3;
00097 
00098         flags = F_SETPOSTFLAG | F_CACHED;
00099         nntpflags = 0xffffffff;
00100 }
00101 
00102 inline const char *MPList::makeFilter(unsigned int servernbr, const char *listarg) const
00103 {
00104         static string filter;
00105         char c;
00106         unsigned int i;
00107 
00108         if (strcmp(listarg, "*") == 0) {
00109                 const char *p, *q;
00110                 filter = entries[servernbr].read;
00111                 for (i = 0; i < entries.size(); i++) {
00112                         if (i != servernbr) {
00113                                 p = entries[i].read;
00114                                 for (;;) {
00115                                         q = p;
00116                                         while ((c = *p) != ',' && c)
00117                                                 p++;
00118                                         filter += ",!";
00119                                         filter.append(q, p - q);
00120                                         if (!c)
00121                                                 break;
00122                                         p++;
00123                                 }
00124                         }
00125                 }
00126         } else {
00127                 const char *listp, *p = NULL, *q = NULL;
00128                 filter = "*";
00129                 if (servernbr == 0)
00130                         i = 1;
00131                 else
00132                         i = 0;
00133                 listp = listarg;
00134                 c = '\0';
00135                 while (i < entries.size()) {
00136                         if (!c) {
00137                                 q = p = entries[i].read;
00138                         }
00139                         while ((c = *listp) && c == *p) {
00140                                 listp++;
00141                                 p++;
00142                         }
00143                         if (*listp == '*') {
00144                                 // p is matched by listarg
00145                                 ASSERT(if (*p == '*') {
00146                                        slog.
00147                                        p(Logger::
00148                                          Error) <<
00149                                        "Same newsgroup expression configured for two different servers!\n";}
00150                                 );
00151                                 filter += ",!";
00152                                 while ((c = *p) != ',' && c)
00153                                         p++;
00154                                 filter.append(q, p - q);
00155                         } else {
00156                                 // p is not matched by listarg
00157                                 while ((c = *p) != ',' && c)
00158                                         p++;
00159                         }
00160                         if (!c) {
00161                                 i++;
00162                                 if (servernbr == i)
00163                                         i++;
00164                         } else {
00165                                 q = ++p;
00166                         }
00167                 }
00168         }
00169 
00170         return filter.c_str();
00171 }
00172 
00173 inline void MPList::init(void)
00174 {
00175         entries.clear();
00176 }
00177 
00178 #endif

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