Back to index

courier  0.68.2
aliases.h
Go to the documentation of this file.
00001 /*
00002 ** Copyright 1998 - 2007 Double Precision, Inc.
00003 ** See COPYING for distribution information.
00004 */
00005 
00006 #ifndef       aliases_h
00007 #define       aliases_h
00008 
00009 #include      "config.h"
00010 #include      "dbobj.h"
00011 
00012 #include      <string>
00013 #include      <list>
00014 
00016 //
00017 // AliasRecord - query and update the aliases.dat file.
00018 //
00019 // (temporary scratch files used for building the final aliases.dat file
00020 // also follows this format)
00021 //
00023 
00024 struct rw_transport;
00025 
00026 class AliasRecord {
00027 protected:
00028        DbObj *gdbm;         // The GDBM file
00029        std::string listname;       // The name of the list (the GDBM key, usually)
00030        std::string recname; // GDBM key. Usually same as listname, unless
00031                             // we spill over a large list into multiple
00032                             // records.  Calculated from listname+recnum.
00033        std::string   list;  // The list itself, the contents of the keyed
00034                             // record.
00035        int    recnum;              // 0 for the first record with this key,
00036                             // then 1, 2, ... for any spillover records.
00037        const char *feptr;   // When stepping through list, points to the
00038                             // next record to retrieve.
00039 public:
00040        AliasRecord() : gdbm(0), recnum(0), feptr(0)
00041               {
00042               }
00043        AliasRecord(DbObj &d) : gdbm(&d), recnum(0), feptr(0)
00044               {
00045               }
00046        void operator=(DbObj *p) { gdbm=p; }
00047 
00048        ~AliasRecord();
00049        void   Init(std::string);
00050        int    Add(const char *);
00051        void   Add(std::list<std::string> &, bool);
00052        void   Delete(const char *);
00053 
00054        void   StartForEach();
00055        std::string NextForEach();
00056        int    Init();
00057 
00058        int    Found() { return ( Init() == 0 ? 1:0); }
00059 private:
00060        int    fetch(int keep);
00061        void   update();
00062        int    search(const char *);
00063        void   mkrecname();
00064 } ;
00065 
00066 class AliasHandler {
00067 public:
00068        AliasHandler()       {}
00069        virtual ~AliasHandler()     {}
00070        virtual void  Alias(const char *)=0;
00071 } ;
00072 
00073 class  AliasSearch {
00074        DbObj module_alias, local_alias;
00075        AliasRecord module_record, local_record;
00076        std::string modulename;
00077 
00078 public:
00079        AliasSearch();
00080 
00081        ~AliasSearch()       {}
00082 
00083        void   Open(const char *);
00084        void   Open(struct rw_transport *);
00085        int    Search(const char *, AliasHandler &);
00086        int    Found(const char *);
00087 private:
00088        int    Try(AliasRecord &, const char *, AliasHandler &);
00089        int    TryVirtual(AliasRecord &, const char *, AliasHandler *);
00090        int    TrySearch(AliasRecord &, const char *);
00091 
00092        int    TryAliasD(const char *, AliasHandler *);
00093        } ;
00094 
00095 #endif