File: Utils.h

package info (click to toggle)
postman 2.0-9
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 8,036 kB
  • ctags: 3,078
  • sloc: cpp: 31,131; ansic: 1,948; sh: 787; makefile: 285
file content (346 lines) | stat: -rw-r--r-- 13,828 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346

/*
Utils.h
*/

#ifndef __UTILS_H
#define __UTILS_H

#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <pwd.h>
#include <malloc.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <ctype.h>
#include <syslog.h>
#include <dirent.h>
#include <sys/times.h>                                             
#include <signal.h>

#include "Services.h"
#include "Config.h"
#include "XSocket.h"

#if defined (LINUX)
#include <asm/errno.h>
#elif defined (HP) 
#include <sys/errno.h>
#elif defined (SUN) 
#include <sys/errno.h>
#endif

#include "XString.h"
#include "XVector.h"
typedef XVector<XString> StringList;
typedef XVector<xulong> ULongList;

#define STR2(X)     #X
#define STR(X)      STR2(X)

#define CMD_HELP_LOGIN          0
#define CMD_HELP_INDEXMAILBOX   1
#define CMD_HELP_DISPLAYMSG     2
#define CMD_HELP_SHOWMAILBOXES  3
#define CMD_HELP_COMPOSEMSG     4
#define CMD_HELP_SHOWOPTIONS    5
#define CMD_HELP_ADDBOOK        6
#define CMD_HELP_SHOWATTACHS    7
#define CMD_HELP_ABOUT          8
#define CMD_HELP_AB_EDITENTRY   9
#define CMD_HELP_AB_NEWENTRY   10

#define SP ' '
#define TAB '\t'

#define CR '\015'
#define LF '\012'
#define CRLF "\015\012"

#define HTML_CR           "\n"
#define HTML_SP           "&#160;"
#define HTML_MENOR        "&#60;"
#define HTML_MAYOR        "&#62;"
#define HTML_DCOMILLAS    "&#34;"
#define HTML_HSP          "&nbsp;"
#define HTML_PORC         "&#37;"
#define HTML_SOSTENIDO    "&#35;"
#define HTML_SQU_OPEN_PAR "&#91;"
#define HTML_SQU_CLOS_PAR "&#93;"

#define HTML_nTILDE       "&ntilde;"  //241
#define HTML_NTILDE       "&Ntilde;"  //209

#define HTML_aACUTE       "&aacute;"  //225
#define HTML_aGRAVE       "&agrave;"  //224

#define HTML_eACUTE       "&eacute;"  //233
#define HTML_eGRAVE       "&egrave;"  //232

#define HTML_iACUTE       "&iacute;"  //237
#define HTML_iGRAVE       "&igrave;"  //236

#define HTML_oACUTE       "&oacute;"  //243 
#define HTML_oGRAVE       "&ograve;"  //242

#define HTML_uACUTE       "&uacute;"  //250 
#define HTML_uGRAVE       "&ugrave;"  //249

#define HTML_AACUTE       "&Aacute;"  //193
#define HTML_AGRAVE       "&Agrave;"  //192

#define HTML_EACUTE       "&Eacute;"  //201
#define HTML_EGRAVE       "&Egrave;"  //200

#define HTML_IACUTE       "&Iacute;"  //205
#define HTML_IGRAVE       "&Igrave;"  //204

#define HTML_OACUTE       "&Oacute;"  //211
#define HTML_OGRAVE       "&Ograve;"  //210

#define HTML_UACUTE       "&Uacute;"  //218
#define HTML_UGRAVE       "&Ugrave;"  //217

//Service that will do authentication. Our program will authenticate with imap server.
#define iDEF_AUTH_SERVICE iSERVICE_CCLIENT
 
#define FORM_SELECT_SEPARATOR "----------"

#define ESPACIADOR "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"

#define IMAP_ERROR_FATAL (long) 1000

#define INBOX HTML_DCOMILLAS"INBOX"HTML_DCOMILLAS

//#define HTML_VERSION "3.2"
//#define HTML_DOCTYPE "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML "HTML_VERSION" Final//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">"
#define HTML_VERSION "4.01"
#define HTML_DOCTYPE "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML "HTML_VERSION" Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">"

//That is the comodin for foreign connections to Postman. This will be replaced for the correct value.
#define TOKEN_JOKER "_"

#define CONTENT_LINE_STRING "Content-length: "

#define WHITE      "#FFFFFF"
#define BLACK      "#000000"
#define RED        "#FF0000"
#define GREEN      "#00AA00"
#define BLUE       "#0000FF"
#define BLUE2      "#008080"

#define NO_SORT    1000
#define SORTTHREAD 1001

//FLAGS: only one char!
#define FRECENT      'R'
#define FNEW         'N' 
#define FUNSEEN      'U'
#define FFLAGGED     'F'
#define FANSWERED    'A'
#define FDELETED     'D'
#define FSEARCHED    '@'
#define FCOPIED      'C'
#define FEMPTY       '-'

#define POS_FLAG_DELETED   0
#define POS_FLAG_ANSWERED  1
#define POS_FLAG_NEW       2
#define POS_FLAG_IMPORTANT 3
#define POS_FLAG_SEARCHED  4
#define POS_FLAG_COPIED    5

#define CMAXHBUFFER 20000
typedef char THBuffer[CMAXHBUFFER + 1];
#define CMAXBUFFER 2000
typedef char TBuffer[CMAXBUFFER + 1];
#define CSMALLBUFFER 200
typedef char TSBuffer[CSMALLBUFFER + 1];
#define CMAXFILENAME 255
typedef char TFileName[CMAXFILENAME + 1];
#define MAXLENGTHLINE 500
typedef char LINEA [MAXLENGTHLINE + 1];
#define CMAXIPNAME 50
typedef char IPNAME [CMAXIPNAME + 1];
#define CMAXNUMBER 20
typedef char TNumber [CMAXNUMBER + 1];

#define LEN_SEP_CGI_VAR 20

#define MAXLENGTHSKIN 50
typedef int FONTSIZE;
#define MAXLENGTHFONTNAME 50
typedef char FONTNAME [MAXLENGTHFONTNAME + 1];
#define MAXLENGTHCOLORHTML 8
typedef char COLORHTML [MAXLENGTHCOLORHTML + 1];

#define MAX_FILENAME_SIZE 1024
char *get_filename(const char *str);

#define DIR_IS_WRITEABLE 0
#define DIR_IS_READONLY  1
#define DIR_IS_OVERQUOTA 2  

const char *make_random_cgi_sep (void);
void initStr (char *thestr);
char *Cut (const char *pc, int maxlong, TBuffer abuf);
bool CreateDir (char *path, mode_t mode);
bool DeleteFile (const char *fname);
bool Touch (const char *fn);
int CreateAndLockFile (char *fn);
void EscribePIDenLockFile (int fd);
void UnlockAndCloseFile (int fd);
int IsLocked (char *fn, int *fd);
int GetPIDFromLockFile (int fd);
long GetTimeFromLockFileOpening (char *fn);
long GetTimeFromLockFile (int fd);
void SaveFileDebug (char *fn, char *pc, int len);
void SaveFileDebug (char *fn, char *pc);
char *ReturnUsersDir (const char *basepath, const char *user, const char *server, TBuffer ABuf);
char *ReturnUserDatabasesDir (const char *basepath, const char *user, const char *server, TBuffer ABuf);
char *ReturnUserLockFileName (const char *user, TBuffer ABuf);
char *ReturnUserAttachsDir (const char *basepath, const char *user, const char *server, TBuffer ABuf);
char *ReturnSignatureFileName (const char *basepath, const char *user, const char *server, TBuffer ABuf);
char *ReturnSieveFileName (const char *basepath, const char *user, const char *server, TBuffer ABuf);
char *ReturnSubscribedNNGroupsFileName (const char *basepath, const char *user, const char *server, TBuffer ABuf);
char *ReturnRcNNGroupsFileName (const char *basepath, const char *user, const char *server, TBuffer ABuf);
char *ReturnAllNNGroupsFileName (const char *server, TBuffer abuf);
char *ReturnUserOptionsFileName (const char *basepath, const char *user, const char *server, TBuffer ABuf);
char *ReturnUserAddressbookFileName (const char *basepath, const char *user, const char *server, TBuffer ABuf);
char *ReturnUserSavedMsgFileName (const char *basepath, const char *user, const char *server, TBuffer ABuf);
char *ReturnUserSavedNNTPMsgFileName (const char *basepath, const char *user, const char *server, TBuffer ABuf);
char *ReturnRestrictedDirNameFileBrowser (const char *basepath, const char *user, const char *server, TBuffer ABuf);
void QuitaRetornoCarroDeLinea (char *linea);
char *xstrdup (char const *str);
void Randomize ();
int Rand (int max);
char *MakeTmpName (TBuffer fntmp, int maxlong);
char *getExtensionFromFile (const char *fn);
bool FileExists (const char *fn);
int FileSize (const char *fn);
time_t FileDate (char *fn);
char *xucase (char *s);
char *xlcase (char *s);
char *xitoa (int n, TNumber abuf);
char *xltoa (long n, TNumber abuf);
int xatoidef (const char *stnum, int def);
long int xatoldef (const char *stnum, long int def);
bool xatobdef (const char *stnum, bool def);
char *make_session_id (const char *server, TBuffer abuf);
char *extract_server_from_connid (const char *connid, TBuffer Buf);
char *make_root_socket (TBuffer Buf);
char *make_session_socket (const char *username, const char *connid, TBuffer Buf);
void ini (char *connid, char *stlang, char *stcmd, char *stsubcmd, char *allparms, char *allparms2,
          char *parm1, char *parm2, char *parm3, char *parm4);
int NCstrstr (const char *linea, const char *token);
int Cstrstr (const char *linea, const char *token);
void OPENLOG (void);
void CLOSELOG (void);
void LOG (char *fmt, ...);
void LOG (long i);
void DEBUG (char *fmt, ...);
void DEBUG (int imsg);
char *FormatCountBytes (long count, TBuffer abuf);
char *FormatCountBytes1Dec (long count, TBuffer abuf);
void Redirect (const char *newurl);
void ErrorPage (const char *error);
void CGIErrorPageConnectionRefused (const char *lang);
bool CopyFile (char *oldfile, char *newfile);
bool CopyFileWin (char *oldfile, char *newfile);
bool CopyFileOverWrite (const char *oldfile, const char *newfile);
char *Text2HTML (const char *ast, char *res);
bool IsEmpty (const char *pc);
bool IsNull (const char *pc);
bool IsGoodValidator (int cmd, int validator, int validatorgood, int service, int lastservice);
void Ltrim (char *linea);
void Rtrim (char *linea);
void trim  (char *linea);
void Rclean (char *linea);
const char *ForceSpace (const char *value);
char *CutSign (const char *pc, int maxlong, const char *signal, TBuffer abuf);
char *getLineFile (const char *flname, int x, int y, TBuffer abuf);
void CreaFileSavedMsg (const char *fn);
bool ConcatLineToLineOfFile (const char *fn, int numlinea, const char *whatadd, const char *sep, int MAX);
int CountChar (char *string, char tocount);
pid_t WritePidFile (void);
void DeletePidFile (void);
void DelAllFilesFromDir (char *thedir);
char *getMailcapTipoFromFilename (const char *fn, const char *fnmailcap);
void PrintCGILoginPage (const char *lang);
void DumpHTMLPage (const char *fn, const char *progparm1, FILE *Foutput);
long min (long i,long j);
int imin (int i, int j);
void XTICK (char *label);
void PChar2SL (char *chunk, StringList *SL);
void ResaltaURLsEnText (char *txt, XSocket *aXS, int MaxLongLine, bool IsUencoded, TBuffer urltouudecode);
bool IsMultiplo (int dividendo, int divisor);
void xscanf (const char *linea, 
             char *c0,
             int *int1, int *int2, int *int3, 
             char *c1, char *c2, 
             int *int4, 
             char *c3, char *c4, char *c5, char *c6, char *c7, char *c8, char *c9);
char *ProcesaDate (char *tmp, TBuffer abuf);
int GetBufferFromFile (char *afile, char *abuf, int maxlength);
char *bool2char (bool b);
bool char2bool (char *c);
int getNumChilds (void);
int SeparaTokensEnStringList (const char *pc, const char sep, StringList *SL);
int CountTokensEnString (const char *pc, const char sep);
void ExtraeAddresses (StringList *SL, char *linea, bool ClearSL);
void ExtraeFullAddresses (StringList *SL, const char *linea, bool ClearSL);
bool MustDoReplayAll (const char *ato, const char *afrom, const char *areplyto, const char *acc);
char *getReplyAllAddresses (const char *ato, const char *afrom, const char *areplyto, const char *acc);
int xvsnprintf(char *str, size_t size, const char *fmt, va_list ap);
int xsnprintf(char *str, size_t size, const char *fmt, ...);
void DisableHTMLTokens (char *htmltxt);
int MergeStringList (StringList *SLBase, StringList *SL2Merge, bool check_exists);
void MEMLOG (char *LineInfo);
bool StringsLike (const char* text, const char* wildcard);
bool SavePchar (const char *pc, int len, const char *fn);
const char *cgienv_GetVarSeparator (const char *fnenv, TBuffer Sep);
const char *cgienv_GetSimpleVar (const char *fnenv, const char *EnvVarname, TBuffer abuf, bool DeleteComillas);
const char *cgienv_GetAllSimpleVarINPUTPC (const char *fnenv, TBuffer abuf, bool DeleteComillas);
void cgienv_GetAllSimpleVarINPUTSL (const char *fnenv, bool DeleteComillas, StringList *SLVars);
bool cgienv_ExistsVar (const char *fnenv, const char *EnvVarname);
bool cgienv_GetEntryBool (const char *fnenv, const char *EnvVarname);
const char *cgienv_GetSimpleVarDef (const char *fnenv, const char *EnvVarname, TBuffer abuf, TBuffer def);
const char *cgienv_GetSimpleMultipleEntries (const char *fnenv, const char *EnvVarname, const char *SEP, TBuffer abuf, bool DeleteComillas);
const char *cgienv_GetSimpleMultipleEntriesSL (const char *fnenv, const char *EnvVarname, StringList *SL, bool DeleteComillas);
const char *cgienv_GetComplexVar (const char *fnenv, const char *EnvVarname);
bool isAllowedService (StringList *aSLAllowedServices, const char *deniedservices, int aservice, const char *stservice);
char *xstrncpy (char *dest, int sizedest, const char *src);
char *xstrncat (char *dest, int sizedest, const char *src);
const char LastChar (const char *string);
const char FirstChar (const char *string);
int CompareStringsNCS (const void *e1, const void *e2);
int CompareStringsCS (const void *e1, const void *e2);
void FlipStrings (const void *e1, const void *e2);
void ReverseSL (StringList *SL);
void ExpandString (char *linea, int size, const char *internal, const char *server, const char *username, const char *password, const char *user_home);
bool IsSameFileSystem (const char *ori_fullfilename, const char *des_fullfilename);
int xrename (const char *ori_fullfilename, const char *des_fullfilename);
long getHardDiskUsage (const char *dirname, TBuffer ErrorMsg);
char *delLastSlash (char *apath);
char *addLastSlash (char *apath);
bool CheckServiceDisabled (const char *service, TBuffer file2show);
char *QuitaComillas (char *token);
char *getTrueAllParms (const char *REQUEST_URI, TBuffer trueallparms);
int IsDirWriteable (const char *directory);
char *c2x (unsigned char letra, TNumber anum);
char *escape_url (const char *source, TBuffer dest);
void utils_unescape (char *value);
int CountChars (const char *line, const char c);
void getConnidFromCookie (TBuffer cookiestring);
void CGIErrorPage (const char *lang, int MSG_ERROR);
void CGIPageConnectionToService (const char *lang, const char *imapserver, const char *user, const char *stservice, const char *stcmd, const char *stsubcmd,
                                 const char *parm1, const char *parm2, const char *parm3, const char *parm4);

#endif