]> git.ipfire.org Git - thirdparty/sarg.git/blob - include/defs.h
Remove one unused parameter from the mail function.
[thirdparty/sarg.git] / include / defs.h
1 /*!\file
2 \brief Declaration of the structures and functions.
3 */
4
5 #ifdef __MINGW32__
6 #define __attribute__(a)
7 #endif
8
9 #include "include/fileobject.h"
10
11 //! \brief Constants to compare the log level to display messages
12 enum DebugLogLevel
13 {
14 //! Process informational messages.
15 LogLevel_Process=1,
16 //! Debug level messages.
17 LogLevel_Debug,
18 //! Display the source file name and line number along with the message.
19 LogLevel_Source,
20 //! Display data about what is processed
21 LogLevel_Data
22 };
23
24 struct ReadLogStruct;//forward declaration
25
26 struct getwordstruct
27 {
28 const char *current;
29 const char *beginning;
30 int modified;
31 };
32
33 typedef struct longlinestruct *longline;
34
35 struct generalitemstruct
36 {
37 //! \c True if the entry is for the total of the file or \c false if it is a single line.
38 int total;
39 //! The user to which the entry apply. The length is limited to ::MAX_USER_LEN.
40 char *user;
41 //! The number of accesses performed by the user.
42 long long nacc;
43 //! The number of bytes transfered.
44 long long nbytes;
45 //! The URL accessed by the user. The length is not limited.
46 char *url;
47 //! The source IP address of the user. The length is limited to ::MAX_IP_LEN.
48 char *ip;
49 //! The time of the access. The length is limited to ::MAX_DATETIME_LEN.
50 char *time;
51 //! The date of the access. The length is limited to ::MAX_DATETIME_LEN.
52 char *date;
53 //! The number of milliseconds spend processing the request.
54 long long nelap;
55 //! The number of bytes fetched from the cache of the proxy (cache hit).
56 long long incache;
57 //! The number of bytes fetched from the site (cache miss).
58 long long oucache;
59 };
60
61 /*! \brief What is known about a user.
62 */
63 struct userinfostruct
64 {
65 //! The ID of the user as found in the input file.
66 const char *id;
67 //! The user's IP address.
68 const char *ip;
69 //! \c True if the ID is in fact the IP address from which the user connected.
70 bool id_is_ip;
71 //! \c True if the user doesn't have a report file.
72 bool no_report;
73 //! The name of the user to display in the report.
74 const char *label;
75 //! The mangled name to use in file names of that user.
76 const char *filename;
77 //! \c True if this user is in the topuser list.
78 int topuser;
79 //! A general purpose flag that can be set when scanning the user's list.
80 int flag;
81 #ifdef ENABLE_DOUBLE_CHECK_DATA
82 //! Total number of bytes.
83 long long int nbytes;
84 //! Total time spent processing the requests.
85 long long int elap;
86 #endif
87 };
88
89 //! Scan through the known users.
90 typedef struct userscanstruct *userscan;
91
92 /*! \brief Global statistics
93 */
94 struct globalstatstruct
95 {
96 //! Total number of accesses.
97 long long int nacc;
98 //! Total number of bytes.
99 long long int nbytes;
100 //! Total time spent processing the requests.
101 long long int elap;
102 //! Amount of data fetched from the cache.
103 long long int incache;
104 //! Amount of data not fetched from the cache.
105 long long int oucache;
106 //! The number of users in the topuser list.
107 int totuser;
108 };
109
110 //! The object to store the daily statistics.
111 typedef struct DayStruct *DayObject;
112
113 /*!
114 \brief Log filtering criterion.
115 */
116 struct ReadLogDataStruct
117 {
118 //! The filtering date range.
119 char DateRange[255];
120 //! \c True to filter on hosts.
121 bool HostFilter;
122 //! \c True to filter on users.
123 bool UserFilter;
124 //! Maximum elpased time allowed. Any time greater than this value is set to zero.
125 long int max_elapsed;
126 //! \c True to restrict the log to the system users.
127 bool SysUsers;
128 //! The start time to include in the report(H*100+M). Set to -1 to disable.
129 int StartTime;
130 //! The end time to include in the report(H*100+M). Set to -1 to disable.
131 int EndTime;
132 };
133
134 /*!
135 \brief How to handle the per_user_limit file creation.
136 */
137 enum PerUserFileCreationEnum
138 {
139 //! Purge the file if it exists or create an empty file.
140 PUFC_Always,
141 //! Delete old files and don't create a new file unless necessary.
142 PUFC_AsRequired
143 };
144
145 /*!
146 \brief What to write into the per_user_limit file.
147 */
148 enum PerUserOutputEnum
149 {
150 PUOE_UserId,
151 PUOE_UserIp
152 };
153
154 /*!
155 \brief How to log every user crossing the download limit.
156 */
157 struct PerUserLimitStruct
158 {
159 //! File to save the user's IP or ID to.
160 char File[255];
161 //! Limit above which the user is reported.
162 int Limit;
163 //! What to write into the file.
164 enum PerUserOutputEnum Output;
165 };
166
167 // auth.c
168 void htaccess(const struct userinfostruct *uinfo);
169
170 // authfail.c
171 void authfail_open(void);
172 void authfail_write(const struct ReadLogStruct *log_entry);
173 void authfail_close(void);
174 bool is_authfail(void);
175 void authfail_report(void);
176 void authfail_cleanup(void);
177
178 // convlog.c
179 void convlog(const char* arq, char df, int dfrom, int duntil);
180
181 // css.c
182 void css_content(FILE *fp_css);
183 void css(FILE *fp_css);
184
185 // dansguardian_log.c
186 void dansguardian_log(void);
187
188 // dansguardian_report.c
189 void dansguardian_report(void);
190
191 // datafile.c
192 void data_file(char *tmp);
193
194 // decomp.c
195 FileObject *decomp(const char *arq);
196
197 // denied.c
198 void denied_open(void);
199 void denied_write(const struct ReadLogStruct *log_entry);
200 void denied_close(void);
201 bool is_denied(void);
202 void gen_denied_report(void);
203 void denied_cleanup(void);
204
205 // download.c
206 void download_open(void);
207 void download_write(const struct ReadLogStruct *log_entry,const char *url);
208 void download_close(void);
209 bool is_download(void);
210 void download_report(void);
211 void free_download(void);
212 void set_download_suffix(const char *list);
213 bool is_download_suffix(const char *url);
214 void download_cleanup(void);
215
216 // email.c
217 int geramail(const char *dirname, int debug, const char *email, const char *TempDir);
218
219 // exclude.c
220 void gethexclude(const char *hexfile, int debug);
221 void getuexclude(const char *uexfile, int debug);
222 int vhexclude(const char *url);
223 int vuexclude(const char *user);
224 bool is_indexonly(void);
225 void free_exclude(void);
226
227 #ifndef HAVE_FNMATCH
228 // fnmtach.c
229 int fnmatch(const char *pattern,const char *string,int flags);
230 #endif
231
232 // getconf.c
233 void getconf(void);
234
235 // grepday.c
236 void greport_prepare(void);
237 void greport_day(const struct userinfostruct *user);
238 void greport_cleanup(void);
239
240 // html.c
241 void htmlrel(void);
242
243 // indexonly.c
244 void index_only(const char *dirname,int debug);
245
246 // ip2name.c
247 int ip2name_config(const char *param);
248 void ip2name_forcedns(void);
249 void ip2name(char *ip,int ip_len);
250 void ip2name_cleanup(void);
251 void name2ip(char *name,int name_size);
252
253 // lastlog.c
254 void mklastlog(const char *outdir);
255
256 // longline.c
257 __attribute__((warn_unused_result)) /*@null@*//*@only@*/longline longline_create(void);
258 void longline_reset(longline line);
259 /*@null@*/char *longline_read(FileObject *fp_in,/*@null@*/longline line);
260 void longline_destroy(/*@out@*//*@only@*//*@null@*/longline *line_ptr);
261
262 // index.c
263 void make_index(void);
264
265 // readlog.c
266 int ReadLogFile(struct ReadLogDataStruct *Filter);
267 bool GetLogPeriod(struct tm *Start,struct tm *End);
268
269 // realtime.c
270 void realtime(void);
271
272 // redirector.c
273 void redirector_log(void);
274 void redirector_report(void);
275
276 // repday.c
277 void report_day(const struct userinfostruct *user);
278
279 // report.c
280 void gerarel(void);
281 int ger_read(char *buffer,struct generalitemstruct *item,const char *filename);
282 void totalger(FILE *fp_gen,const char *filename);
283
284 // siteuser.c
285 void siteuser(void);
286
287 // smartfilter.c
288 void smartfilter_report(void);
289
290 // sort.c
291 void sort_users_log(const char *tmp, int debug,struct userinfostruct *uinfo);
292 void tmpsort(const struct userinfostruct *uinfo);
293 void sort_labels(const char **label,const char **order);
294
295 // splitlog.c
296 void splitlog(const char *arq, char df, int dfrom, int duntil, int convert, const char *splitprefix);
297
298 // topsites.c
299 void topsites(void);
300
301 // topuser.c
302 void topuser(void);
303
304 // totday.c
305 DayObject day_prepare(void);
306 void day_cleanup(DayObject ddata);
307 void day_newuser(DayObject ddata);
308 void day_addpoint(DayObject ddata,const char *date, const char *time, long long int elap, long long int bytes);
309 void day_totalize(DayObject ddata,const char *tmp, const struct userinfostruct *uinfo);
310 void day_deletefile(const struct userinfostruct *uinfo);
311
312 // url.c
313 void read_hostalias(const char *Filename);
314 void free_hostalias(void);
315 const char *skip_scheme(const char *url);
316 const char *process_url(const char *url,bool full_url);
317 void url_hostname(const char *url,char *hostname,int hostsize);
318
319 // usage.c
320 void usage(const char *prog);
321
322 // useragent.c
323 void useragent(void);
324
325 // userinfo.c
326 /*@shared@*/struct userinfostruct *userinfo_create(const char *userid, const char *ip);
327 void userinfo_free(void);
328 void userinfo_label(struct userinfostruct *uinfo,const char *label);
329 /*@shared@*/struct userinfostruct *userinfo_find_from_file(const char *filename);
330 /*@shared@*/struct userinfostruct *userinfo_find_from_id(const char *id);
331 /*@shared@*/struct userinfostruct *userinfo_find_from_ip(const char *ip);
332 userscan userinfo_startscan(void);
333 void userinfo_stopscan(userscan uscan);
334 struct userinfostruct *userinfo_advancescan(userscan uscan);
335 void userinfo_clearflag(void);
336 void read_useralias(const char *Filename);
337 void free_useralias(void);
338 const char *process_user(const char *user);
339
340 // usertab.c
341 void init_usertab(const char *UserTabFile);
342 void user_find(char *mappedname, int namelen, const char *userlogin);
343 void close_usertab(void);
344
345 // util.c
346 void getword_start(/*@out@*/struct getwordstruct *gwarea, const char *line);
347 void getword_restart(struct getwordstruct *gwarea);
348 __attribute__((warn_unused_result)) int getword(/*@out@*/char *word, int limit, struct getwordstruct *gwarea, char stop);
349 __attribute__((warn_unused_result)) int getword_limit(/*@out@*/char *word, int limit, struct getwordstruct *gwarea, char stop);
350 __attribute__((warn_unused_result)) int getword_multisep(/*@out@*/char *word, int limit, struct getwordstruct *gwarea, char stop);
351 __attribute__((warn_unused_result)) int getword_skip(int limit, struct getwordstruct *gwarea, char stop);
352 __attribute__((warn_unused_result)) int getword_atoll(/*@out@*/long long int *number, struct getwordstruct *gwarea, char stop);
353 __attribute__((warn_unused_result)) int getword_atoi(/*@out@*/int *number, struct getwordstruct *gwarea, char stop);
354 __attribute__((warn_unused_result)) int getword_atol(long int *number, struct getwordstruct *gwarea, char stop);
355 __attribute__((warn_unused_result)) int getword_atolu(unsigned long int *number, struct getwordstruct *gwarea, char stop);
356 __attribute__((warn_unused_result)) int getword_ptr(char *orig_line,/*@out@*/char **word, struct getwordstruct *gwarea, char stop);
357 long long int my_atoll (const char *nptr);
358 int is_absolute(const char *path);
359 int getnumlist(char *, numlist *, const int, const int);
360 int conv_month(const char *month);
361 const char *conv_month_name(int month);
362 void buildymd(const char *dia, const char *mes, const char *ano, char *wdata,int wdata_size);
363 void date_from(char *date,int date_size, int *dfrom, int *duntil);
364 char *fixnum(long long int value, int n);
365 char *fixnum2(long long int value, int n);
366 void fixnone(char *str);
367 char *fixtime(long long int elap);
368 void fixendofline(char *str);
369 void show_info(FILE *fp_ou);
370 void show_sarg(FILE *fp_ou, int depth);
371 void write_logo_image(FILE *fp_ou);
372 void write_html_head(FILE *fp_ou, int depth, const char *page_title,int javascript);
373 void write_html_header(FILE *fp_ou, int depth, const char *title,int javascript);
374 void close_html_header(FILE *fp_ou);
375 void write_html_trailer(FILE *fp_ou);
376 void output_html_string(FILE *fp_ou,const char *str,int maxlen);
377 void output_html_url(FILE *fp_ou,const char *url);
378 void output_html_link(FILE *fp_ou,const char *url,int maxlen);
379 void debuga(const char *File, int Line, const char *msg,...) __attribute__((format(printf,3,4)));
380 void debuga_more(const char *msg,...) __attribute__((format(printf,1,2)));
381 void debugaz(const char *File,int Line,const char *msg,...) __attribute__((format(printf,3,4)));
382 void my_lltoa(unsigned long long int n, char *s, int ssize, int len);
383 void url_module(const char *url, char *w2);
384 void url_to_anchor(const char *url,char *anchor,int size);
385 void safe_strcpy(char *dest,const char *src,int length);
386 void strip_latin(char *line);
387 char *buildtime(long long int elap);
388 int obtdate(const char *dirname, const char *name, char *data);
389 void formatdate(char *date,int date_size,int year,int month,int day,int hour,int minute,int second,int dst);
390 void computedate(int year,int month,int day,struct tm *t);
391 int obtuser(const char *dirname, const char *name);
392 void obttotal(const char *dirname, const char *name, int nuser, long long int *tbytes, long long int *media);
393 void version(void);
394 int vercode(const char *code);
395 void load_excludecodes(const char *ExcludeCodes);
396 void free_excludecodes(void);
397 int PortableMkDir(const char *path,int mode);
398 void my_mkdir(const char *name);
399 int testvaliduserchar(const char *user);
400 char *strlow(char *string);
401 char *strup(char *string);
402 int month2num(const char *month);
403 int builddia(int day, int month, int year);
404 int compare_date(struct tm *date1,struct tm *date2);
405 bool IsTreeFileDirName(const char *Name);
406 bool IsTreeYearFileName(const char *Name);
407 bool IsTreeMonthFileName(const char *Name);
408 bool IsTreeDayFileName(const char *Name);
409 int vrfydir(const struct periodstruct *per1, const char *addr, const char *site, const char *us);
410 int getperiod_fromsarglog(const char *arqtt,struct periodstruct *period);
411 void getperiod_fromrange(struct periodstruct *period,int dfrom,int duntil);
412 void getperiod_merge(struct periodstruct *main,struct periodstruct *candidate);
413 int getperiod_buildtext(struct periodstruct *period);
414 void removetmp(const char *outdir);
415 void zdate(char *ftime,int ftimesize, char DateFormat);
416 char *get_param_value(const char *param,char *line);
417 int compar( const void *, const void * );
418 void unlinkdir(const char *dir,bool contentonly);
419 void emptytmpdir(const char *dir);
420 int extract_address_mask(const char *buf,const char **text,unsigned char *ipv4,unsigned short int *ipv6,int *nbits,const char **next);