"Fossies" - the Fresh Open Source Software Archive 
Member "postal-0.76/smtp.h" (30 Jun 2016, 3062 Bytes) of package /linux/privat/postal-0.76.tgz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "smtp.h" see the
Fossies "Dox" file reference documentation.
1 #ifndef SMTP_H
2 #define SMTP_H
3
4 using namespace std;
5 #include <string>
6 #include <cstring>
7 #include <time.h>
8 #include "conf.h"
9 #include <tr1/unordered_map>
10 #include "tcp.h"
11 #include "mutex.h"
12
13 class results;
14
15 class UserList;
16
17 #define MAP_SIZE 8 * 1024
18
19 // Comparison operator for hash map of names to unsigned longs
20 struct eqlng
21 {
22 bool operator()(unsigned long l1, unsigned long l2) const
23 {
24 return (l1 == l2);
25 }
26 };
27
28 typedef std::tr1::unordered_map<unsigned long, string *, hash<unsigned long>, eqlng> NAME_MAP;
29
30 class smtpData
31 {
32 public:
33 smtpData();
34 ~smtpData();
35
36 const string &quit() const { return m_quit; }
37 // create a random string of length len that includes a trailing "\r\n"
38 // string is not zero terminated
39 void randomString(char *buf, int len) const;
40 // fill a buffer with random lines of text
41 void randomBuf(char *buf, int len) const;
42 void date(char *buf) const;
43 const string msgId(const char *sender, const unsigned threadNum) const;
44
45 // return the X-Postal lines
46 const string &postalMsg() const { return m_postalMsg; }
47
48 // frequency determines how long it should have been since the last
49 // operation for this function to actually do anything.
50 // It will not sleep for that many seconds or block on IO in any way.
51 void setRand(int frequency);
52
53 // get the mail name for an IP address
54 const string *getMailName(struct sockaddr_in &in);
55
56 private:
57 // Some const strings that we only want one copy of
58 const string m_quit;
59 const char *m_randomLetters;
60 const int m_randomLen;
61 const string m_postalMsg;
62
63 Mutex m_dnsLock;
64
65 // time of the last randomise
66 time_t m_timeLastAction;
67 char m_randBuf[MAP_SIZE];
68
69 // Map of IP addresses to names
70 NAME_MAP m_names;
71
72 smtpData(const smtpData&);
73 smtpData & operator=(const smtpData&);
74 };
75
76 class smtp : public tcp
77 {
78 public:
79 smtp(int *exitCount, const char *addr, const char *ourAddr
80 , UserList &ul, UserList *senderList, int minMsgSize, int maxMsgSize
81 , int numMsgsPerConnection, int processes, Logit *log, TRISTATE netscape
82 , bool useLMTP
83 #ifdef USE_SSL
84 , int ssl
85 #endif
86 , unsigned short port, Logit *debug);
87
88 virtual ~smtp();
89
90 // Connect returns 0 for connect, 1 for can't connect, and 2 for serious
91 // errors.
92 int Connect();
93 int sendMsg();
94 virtual int disconnect();
95 int msgsPerConnection() const { return m_msgsPerConnection; }
96
97 private:
98 virtual int action(PVOID);
99
100 smtp(int threadNum, const smtp *parent);
101 virtual Thread *newThread(int threadNum);
102
103 int pollRead();
104 virtual int WriteWork(PVOID buf, int size, int timeout);
105
106 virtual ERROR_TYPE readCommandResp(bool) { return readCommandResp(); }
107 ERROR_TYPE readCommandResp();
108 void error();
109 virtual void sentData(int bytes);
110 virtual void receivedData(int);
111
112 UserList &m_ul, *m_senderList;
113 const int m_minMsgSize, m_maxMsgSize;
114 smtpData *m_data;
115 int m_msgsPerConnection;
116 results *m_res;
117 TRISTATE m_netscape;
118 string m_helo;
119 time_t m_nextPrint;
120 bool m_useLMTP;
121
122 smtp(const smtp&);
123 smtp & operator=(const smtp&);
124 };
125
126 #endif