Back to index

courier  0.68.2
cmlm.h
Go to the documentation of this file.
00001 #ifndef       cmlm_h
00002 #define       cmlm_h
00003 /*
00004 ** Copyright 2000-2007 Double Precision, Inc.
00005 ** See COPYING for distribution information.
00006 */
00007 
00008 
00009 #include      "config.h"
00010 #include      "afx/afx.h"
00011 #include      <sys/types.h>
00012 #include      <sys/stat.h>
00013 #include      <stdio.h>
00014 #include      <stdlib.h>
00015 
00016 #include      <iostream>
00017 
00018 #include      <string>
00019 #include      <vector>
00020 #include      <algorithm>
00021 #include      <functional>
00022 #include      <cctype>
00023 
00024 #define       TMP    "tmp"
00025 #define       TMPLOCK       "tmp.lock"
00026 
00027 #define       OPTIONS       "options"
00028 #define       DOMAINS       "sublist"
00029 #define       ARCHIVE       "archive"
00030 #define       UNSUBLIST "unsublist"
00031 #define       COMMANDS "commands"
00032 #define       COMMANDSDAT "commands.dat"
00033 
00034 #define       BOUNCES       "bounces"
00035 #define       BOUNCESDAT    "bounces.dat"
00036 #define       BOUNCESLOCK   "bounces.lock"
00037 
00038 
00039 #define       HOURLYLOCKFILE       "hourly.lock"
00040 #define       DAILYLOCKFILE "daily.lock"
00041 
00042 #define       DIGESTLOCKFILE       "digest.lock"
00043 
00044 #define       MODQUEUE "modqueue"
00045 #define       MODQUEUELOCKFILE "modqueue.lock"
00046 
00047 #define       HEADERADD     "headeradd"
00048 #define       HEADERDEL     "headerdel"
00049 
00050 #include      "datadir.h"
00051 
00052 #define       TEMPLATEDIR   DATADIR "/couriermlm"
00053 
00054 #define       MSGSEPARATOR  "===="
00055 
00056 #include      "bindir.h"
00057 
00058 #define       SENDMAIL      BINDIR "/sendmail"
00059 #define       REFORMIME     BINDIR "/reformime"
00060 #define       MAXRCPTS      20
00061 
00062 #define       MSGLOCKFILE   ARCHIVE "/.lock"
00063 #define       SEQNO  ARCHIVE "/.seqno"
00064 #define       NEXTSEQNO     ARCHIVE "/.nextseqno"
00065 
00066 //
00067 //     Large domains have their own db file listing the subscribers.
00068 //     Small domains are all lumped into one file, keyed by domain name,
00069 //     data is address\0subinfo\0address\0subinfo...
00070 //
00071 
00072 #define       MISC   DOMAINS "/misc"
00073 #define       MISCSIZE      2
00074 
00075 #define       ALIASES       DOMAINS "/aliases"
00076 
00077 #define       SUBLOCKFILE "sublist.lock"
00078 #define       CMDLOCKFILE "commands.lock"
00079 
00080 #define SUBLOGFILE "sublist.log"
00081 
00082 class ExclusiveLock {
00083        int fd;
00084 public:
00085        ExclusiveLock(const char *);
00086        ~ExclusiveLock();
00087 } ;
00088 
00089 class SharedLock {
00090        int fd;
00091 public:
00092        SharedLock(const char *);
00093        ~SharedLock();
00094 } ;
00095 
00096 class SubSharedLock : public SharedLock {
00097 public:
00098        SubSharedLock();
00099        ~SubSharedLock();
00100 } ;
00101 
00102 class SubExclusiveLock : public ExclusiveLock {
00103 public:
00104        SubExclusiveLock();
00105        ~SubExclusiveLock();
00106 } ;
00107 
00108 class CommandLock : public ExclusiveLock {
00109 public:
00110        CommandLock();
00111        ~CommandLock();
00112 } ;
00113 
00114 void trapsigs(const char *);
00115 void clearsigs(int);
00116 
00117 std::string cmdget_s(const char *);
00118 
00119 template<typename iterator_t, typename comp_t>
00120        iterator_t find_last_if(iterator_t b, iterator_t e,
00121                             comp_t c)
00122 {
00123        iterator_t r=e;
00124 
00125        while (b != e)
00126               if (c(*b++))
00127                      r=b;
00128        return r;
00129 }
00130 
00131 
00132 inline void TrimLeft(std::string &s)
00133 {
00134        s=std::string(std::find_if(s.begin(), s.end(),
00135                                std::not1(std::ptr_fun(::isspace))), s.end());
00136 }
00137 
00138 inline void TrimRight(std::string &s)
00139 {
00140        s=std::string(s.begin(), find_last_if(s.begin(), s.end(),
00141                                     std::not1(std::ptr_fun(::isspace)))
00142                     );
00143 }
00144 
00145 std::string get_verp_return(std::string addr);
00146 
00147 std::string toverp(std::string);
00148 
00149 std::string fromverp(std::string);
00150 
00151 std::string readmsg();
00152 
00153 std::string header_s(std::string a, const char *b);
00154 
00155 std::string returnaddr(std::string, const char *);
00156 
00157 std::string mkboundary_msg_s(afxipipestream &);
00158 
00159 std::string mkfilename();
00160 std::string mktmpfilename();
00161 void post(std::istream &, const char *);
00162 
00163 int is_subscriber(std::string);
00164 int getinfo(std::string, int (*)(std::string));
00165 std::string myname();
00166 
00167 void addrlower(char *);
00168 void addrlower(std::string &); // TODO
00169 
00170 int isfound(std::string);
00171 int sendmail(const char **, pid_t &);
00172 int wait4sendmail(pid_t);
00173 int sendmail_bcc(pid_t &, std::string, int nodsn = 0);
00174 
00175 bool checkconfirm(std::string);
00176 
00177 void ack_template(std::ostream &, const char *, std::string, std::string);
00178 void simple_template(std::ostream &, const char *, std::string);
00179 void copy_template(std::ostream &, const char *, std::string);
00180 void copy_report(const char *, afxopipestream &);
00181 int copyio(afxipipestream &, afxopipestream &);
00182 int copyio_noseek(afxipipestream &, afxopipestream &);
00183 int copyio_noseek_cnt(afxipipestream &, afxopipestream &, unsigned long *);
00184 int cmddigest(const std::vector<std::string> &);
00185 
00186 #endif