1 #include <stdio.h>
2 #ifndef IS_OLDGCC
3 #include <iostream>
4 #else
5 #include <iostream.h>
6 #endif
7 #ifdef __GNUC__
8 #include <cstring>
9 #else
10 #include <string.h>
11 #endif
12 using namespace std;
13 #include "msg.h"
14 #include "area.h"
15 #include "config.h"
16 #include "log.h"
17 #include "global.h"
18
initApi()19 int initApi()
20 {
21 struct _minf m;
22 m.req_version = 0;
23 m.def_zone = cfg->F_Home.zone;
24 if (MsgOpenApi(&m) != 0)
25 {
26 exit(1);
27 }
28 return 0;
29 }
30
closeApi()31 int closeApi()
32 {
33 MsgCloseApi();
34 return 0;
35 }
36
CArea()37 CArea::CArea()
38 {
39 }
40
CArea(const CArea & ar)41 CArea::CArea(const CArea & ar)
42 {
43 s_Path=ar.s_Path;
44 i_type=ar.i_type;
45 }
46
~CArea()47 CArea::~CArea()
48 {
49 }
50
Open(string Path)51 int CArea::Open(string Path)
52 {
53 if (Path[0]=='$')
54 {
55 i_type=MSGTYPE_SQUISH;
56 Path.erase(0,1);
57 }
58 else
59 i_type=MSGTYPE_SDM;
60
61 a_Area=MsgOpenArea((unsigned char *)Path.c_str(), MSGAREA_CRIFNEC, i_type);
62 if (a_Area!=NULL)
63 {
64 i_msgNum=MsgGetHighMsg(a_Area);
65 string logstr="opening area " + s_Path;
66 log->add(1, logstr);
67 return 0;
68 }
69 else
70 {
71 a_Area=NULL;
72 cerr << "Could not open area: \"" << Path << "\"!\n";
73 return -1;
74 }
75 }
76
Open()77 int CArea::Open()
78 {
79 a_Area=MsgOpenArea((unsigned char *)s_Path.c_str(), MSGAREA_NORMAL, i_type);
80 if (a_Area!=NULL)
81 {
82 i_msgNum=MsgGetHighMsg(a_Area);
83 string logstr="opening area " + s_Path;
84 log->add(1, logstr);
85 return 0;
86 }
87 else
88 {
89 a_Area=NULL;
90 cerr << "Could not open area:" << s_Path << "!\n";
91 return -1;
92 }
93 }
94
Close()95 int CArea::Close()
96 {
97 if (a_Area!=NULL)
98 {
99 MsgCloseArea(a_Area);
100 return 0;
101 }
102 else
103 {
104 cerr << "Area not open!\n";
105 return -1;
106 }
107 }
108
GetArea()109 HAREA CArea::GetArea()
110 {
111 return a_Area;
112 }
113
Scan(vector<COperation> M_ScanFor,vector<CAction> A_Execute,unsigned int start,unsigned int stop)114 int CArea::Scan(vector<COperation> M_ScanFor, vector<CAction> A_Execute, unsigned int start, unsigned int stop)
115 {
116 CMsg Message;
117 CMask actualMask;
118 int result;
119 vector<int> matches;
120 dword msgnum = 1;
121 bool stopwithmsg;
122
123 while (MsgGetCurMsg(a_Area) != MsgGetHighMsg(a_Area))
124 {
125 result=Message.Open(msgnum, a_Area);
126 if (msgnum == 1) msgnum = MSGNUM_NEXT;
127
128 if (result==-1)
129 {
130 continue;
131 }
132 stopwithmsg = false;
133
134 for (unsigned int j=start;j<stop+1 && !stopwithmsg;j++)
135 {
136 actualMask=Message.GetMask();
137 /*------------ scan for matching mask ---------------*/
138 if (M_ScanFor[j].M_Mask==actualMask)
139 {
140
141 if (0==1) // FIX: add searching code...
142 continue;
143 else
144 matches.push_back(MsgGetCurMsg(a_Area));
145
146 /* TODO: write code to check, if there was already a hit and continue(); if yes */
147
148 /*-------- execute associated actions ------------*/
149 for (int k=M_ScanFor[j].firstAction; k<M_ScanFor[j].lastAction+1;k++)
150 {
151 /*------ get action type -------*/
152 string type;
153 string RestParam;
154 string temp;
155
156 /*------ write action data to vars -------*/
157 temp=A_Execute[k].param;
158 while (temp[0]==' ') temp.erase(0,1);
159 if (temp[temp.length()-1]=='\n') temp.erase(temp.length()-1, 1);
160 do
161 {
162 type+=temp[0];
163 temp.erase(0,1);
164 } while (temp.length()>0 && temp[0]!=' ');
165 while (temp[0]==' ') temp.erase(0,1);
166 RestParam=temp;
167 char number[6];
168 sprintf(number, "%lu", MsgGetCurMsg(a_Area));
169
170 /*----- action file -----*/
171 if (type=="file")
172 {
173 CFileAction TempAction;
174 TempAction.s_Filename=RestParam;
175 if (M_ScanFor[j].M_Mask.i_match.size()>1) TempAction.s_Filename+=number;
176 TempAction.msgnum=MsgGetCurMsg(a_Area);
177 TempAction.Area=a_Area;
178 TempAction.run();
179 }
180
181 /*----- action headerfile -----*/
182 if (type=="hdrfile")
183 {
184 CHdrFileAction TempAction;
185 TempAction.s_Filename=RestParam;
186 if (M_ScanFor[j].M_Mask.i_match.size()>1) TempAction.s_Filename+=number;
187 TempAction.msgnum=MsgGetCurMsg(a_Area);
188 TempAction.Area=a_Area;
189 TempAction.run();
190 }
191 /*----- action bounce --------*/
192 if (type=="bounce")
193 {
194 CBounceAction TempAction;
195 TempAction.param=RestParam;
196 TempAction.msgnum=MsgGetCurMsg(a_Area);
197 TempAction.Area=a_Area;
198 TempAction.run();
199 }
200 /*------- action copy --------*/
201 if (type=="copy")
202 {
203 CCopyAction TempAction;
204 TempAction.param=RestParam;
205 TempAction.Area=a_Area;
206 TempAction.msgnum=MsgGetCurMsg(a_Area);
207 TempAction.run();
208 }
209 /*------- action move --------*/
210 if (type=="move")
211 {
212 CMoveAction TempAction;
213 TempAction.param=RestParam;
214 TempAction.Area=a_Area;
215 TempAction.msgnum=MsgGetCurMsg(a_Area);
216 TempAction.run();
217 stopwithmsg = true;
218 break;
219 }
220 /*-------- packmail action -------*/
221 if (type=="packmail")
222 {
223 if (((Message.d_Attr & MSGSENT) != MSGSENT) && ((Message.d_Attr & MSGLOCAL) == MSGLOCAL))
224 {
225 CPackmailAction TempAction;
226 TempAction.param=RestParam;
227 TempAction.Area=a_Area;
228 TempAction.msgnum=MsgGetCurMsg(a_Area);
229 TempAction.run();
230 }
231 }
232 /*-------- movemail action -------*/
233 if (type=="movemail")
234 {
235 if (((Message.d_Attr & MSGSENT) != MSGSENT) && ((Message.d_Attr & MSGLOCAL) == MSGLOCAL))
236 {
237 CMovemailAction TempAction;
238 TempAction.param=RestParam;
239 TempAction.Area=a_Area;
240 TempAction.msgnum=MsgGetCurMsg(a_Area);
241 TempAction.run();
242 }
243 }
244 /*-------- rewrite action -----------*/
245 if (type=="rewrite")
246 {
247 CRewriteAction TempAction;
248 TempAction.param=RestParam;
249 TempAction.Area=a_Area;
250 TempAction.msgnum=MsgGetCurMsg(a_Area);
251 TempAction.run();
252 }
253 /*--------- display action ----------*/
254 if (type=="display")
255 {
256 CDisplayAction TempAction;
257 TempAction.param=RestParam;
258 TempAction.run();
259 }
260
261 /*------- semaphore action ----------*/
262 if (type=="semaphore")
263 {
264 CSemaphoreAction TempAction;
265 TempAction.param=RestParam;
266 TempAction.run();
267 }
268 if (type=="delete")
269 {
270 CDeleteAction TempAction;
271 TempAction.Area=a_Area;
272 TempAction.msgnum=MsgGetCurMsg(a_Area);
273 TempAction.run();
274 stopwithmsg = true;
275 break;
276 }
277 if (type=="ignore")
278 {
279 stopwithmsg = true;
280 break;
281 }
282
283 }
284 }
285 }
286 Message.Close();
287 }
288 return 0;
289 }
290
291
292