]> git.ipfire.org Git - thirdparty/sarg.git/blame - include/defs.h
Use a library to read gzip access.log files
[thirdparty/sarg.git] / include / defs.h
CommitLineData
f2ec8c75
FM
1/*!\file
2\brief Declaration of the structures and functions.
3*/
9c7c6346 4
3c3ae3bd
FM
5#ifdef __MINGW32__
6#define __attribute__(a)
7#endif
8
800eafb8
FM
9#include "include/fileobject.h"
10
cb59dc47
FM
11//! \brief Constants to compare the log level to display messages
12enum 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.
4246ae8d
FM
19 LogLevel_Source,
20 //! Display data about what is processed
21 LogLevel_Data
cb59dc47
FM
22};
23
f83d7b44 24struct ReadLogStruct;//forward declaration
8e53b2e7 25
9c7c6346
FM
26struct getwordstruct
27{
28 const char *current;
29 const char *beginning;
e5b2c6f0 30 int modified;
9c7c6346
FM
31};
32
afaa3b67 33typedef struct longlinestruct *longline;
ac422f9b 34
2240dcea
FM
35struct 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
93551487
FM
61/*! \brief What is known about a user.
62*/
f2ec8c75
FM
63struct userinfostruct
64{
93551487 65 //! The ID of the user as found in the input file.
b6b6cb8c 66 const char *id;
aa6ac9f2
FM
67 //! The user's IP address.
68 const char *ip;
93551487
FM
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.
b6b6cb8c 74 const char *label;
93551487 75 //! The mangled name to use in file names of that user.
b6b6cb8c 76 const char *filename;
a58e6d54
FM
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;
d91457d2
FM
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
f2ec8c75
FM
87};
88
93551487
FM
89//! Scan through the known users.
90typedef struct userscanstruct *userscan;
91
9dc20988
FM
92/*! \brief Global statistics
93*/
94struct 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;
e5b3a129
FM
106 //! The number of users in the topuser list.
107 int totuser;
9dc20988
FM
108};
109
026ddd8b
FM
110//! The object to store the daily statistics.
111typedef struct DayStruct *DayObject;
112
27d1fa35
FM
113/*!
114\brief Log filtering criterion.
115*/
116struct 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
0b5356bb
FM
134/*!
135\brief How to handle the per_user_limit file creation.
136*/
137enum 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
3877d630
FM
145/*!
146\brief What to write into the per_user_limit file.
147*/
148enum PerUserOutputEnum
149{
150 PUOE_UserId,
151 PUOE_UserIp
152};
153
2e29ae23
FM
154/*!
155\brief How to log every user crossing the download limit.
156*/
157struct 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;
3877d630
FM
163 //! What to write into the file.
164 enum PerUserOutputEnum Output;
2e29ae23
FM
165};
166
5f3cfd1d 167// auth.c
d25d4e6a 168void htaccess(const struct userinfostruct *uinfo);
5f3cfd1d
FM
169
170// authfail.c
16b013cc
FM
171void authfail_open(void);
172void authfail_write(const struct ReadLogStruct *log_entry);
173void authfail_close(void);
174bool is_authfail(void);
5f3cfd1d 175void authfail_report(void);
16b013cc 176void authfail_cleanup(void);
5f3cfd1d 177
5f3cfd1d 178// convlog.c
81a022d8 179void convlog(const char* arq, char df, int dfrom, int duntil);
5f3cfd1d
FM
180
181// css.c
d183fb7f 182void css_content(FILE *fp_css);
5f3cfd1d
FM
183void css(FILE *fp_css);
184
185// dansguardian_log.c
186void dansguardian_log(void);
187
188// dansguardian_report.c
189void dansguardian_report(void);
190
191// datafile.c
192void data_file(char *tmp);
193
194// decomp.c
800eafb8 195FileObject *decomp(const char *arq);
5f3cfd1d
FM
196
197// denied.c
8e53b2e7
FM
198void denied_open(void);
199void denied_write(const struct ReadLogStruct *log_entry);
200void denied_close(void);
201bool is_denied(void);
5f3cfd1d 202void gen_denied_report(void);
60b48ae5 203void denied_cleanup(void);
5f3cfd1d
FM
204
205// download.c
11284535
FM
206void download_open(void);
207void download_write(const struct ReadLogStruct *log_entry,const char *url);
208void download_close(void);
209bool is_download(void);
5f3cfd1d 210void download_report(void);
6e792ade
FM
211void free_download(void);
212void set_download_suffix(const char *list);
2824ec9b 213bool is_download_suffix(const char *url);
11284535 214void download_cleanup(void);
5f3cfd1d
FM
215
216// email.c
2824ec9b 217int geramail(const char *dirname, int debug, const char *outdir, const char *email, const char *TempDir);
5f3cfd1d
FM
218
219// exclude.c
43f18f45
FM
220void gethexclude(const char *hexfile, int debug);
221void getuexclude(const char *uexfile, int debug);
222int vhexclude(const char *url);
223int vuexclude(const char *user);
2824ec9b 224bool is_indexonly(void);
43f18f45 225void free_exclude(void);
5f3cfd1d 226
6068ae56
FM
227#ifndef HAVE_FNMATCH
228// fnmtach.c
229int fnmatch(const char *pattern,const char *string,int flags);
230#endif
231
5f3cfd1d
FM
232// getconf.c
233void getconf(void);
234
235// grepday.c
1f482a8d 236void greport_prepare(void);
f2ec8c75 237void greport_day(const struct userinfostruct *user);
c274f011 238void greport_cleanup(void);
5f3cfd1d
FM
239
240// html.c
241void htmlrel(void);
242
243// indexonly.c
244void index_only(const char *dirname,int debug);
245
246// ip2name.c
51b166d4
FM
247int ip2name_config(const char *param);
248void ip2name_forcedns(void);
5f3cfd1d 249void ip2name(char *ip,int ip_len);
0326d73b 250void ip2name_cleanup(void);
4afbb7a5 251void name2ip(char *name,int name_size);
5f3cfd1d 252
5f3cfd1d
FM
253// lastlog.c
254void mklastlog(const char *outdir);
255
afaa3b67 256// longline.c
fa6552b0 257__attribute__((warn_unused_result)) /*@null@*//*@only@*/longline longline_create(void);
afaa3b67 258void longline_reset(longline line);
800eafb8 259/*@null@*/char *longline_read(FileObject *fp_in,/*@null@*/longline line);
afaa3b67
FM
260void longline_destroy(/*@out@*//*@only@*//*@null@*/longline *line_ptr);
261
5f3cfd1d
FM
262// index.c
263void make_index(void);
264
27d1fa35
FM
265// readlog.c
266int ReadLogFile(struct ReadLogDataStruct *Filter);
b6fb8c79 267bool GetLogPeriod(struct tm *Start,struct tm *End);
27d1fa35 268
5f3cfd1d
FM
269// realtime.c
270void realtime(void);
271
330b1c52
FM
272// redirector.c
273void redirector_log(void);
274void redirector_report(void);
275
5f3cfd1d 276// repday.c
f2ec8c75 277void report_day(const struct userinfostruct *user);
5f3cfd1d
FM
278
279// report.c
5f3cfd1d 280void gerarel(void);
2240dcea 281int ger_read(char *buffer,struct generalitemstruct *item,const char *filename);
9dc20988 282void totalger(FILE *fp_gen,const char *filename);
5f3cfd1d
FM
283
284// siteuser.c
285void siteuser(void);
286
287// smartfilter.c
288void smartfilter_report(void);
289
290// sort.c
461b479d 291void sort_users_log(const char *tmp, int debug,struct userinfostruct *uinfo);
e5b3a129 292void tmpsort(const struct userinfostruct *uinfo);
15d5372b 293void sort_labels(const char **label,const char **order);
5f3cfd1d
FM
294
295// splitlog.c
81a022d8 296void splitlog(const char *arq, char df, int dfrom, int duntil, int convert, const char *splitprefix);
5f3cfd1d 297
5f3cfd1d
FM
298// topsites.c
299void topsites(void);
300
301// topuser.c
302void topuser(void);
303
304// totday.c
026ddd8b
FM
305DayObject day_prepare(void);
306void day_cleanup(DayObject ddata);
307void day_newuser(DayObject ddata);
308void day_addpoint(DayObject ddata,const char *date, const char *time, long long int elap, long long int bytes);
309void day_totalize(DayObject ddata,const char *tmp, const struct userinfostruct *uinfo);
e3e6aef4 310void day_deletefile(const struct userinfostruct *uinfo);
5f3cfd1d 311
22715352
FM
312// url.c
313void read_hostalias(const char *Filename);
314void free_hostalias(void);
6fa33a32 315const char *skip_scheme(const char *url);
e2379f05 316const char *process_url(const char *url,bool full_url);
22715352
FM
317void url_hostname(const char *url,char *hostname,int hostsize);
318
5f3cfd1d
FM
319// usage.c
320void usage(const char *prog);
321
322// useragent.c
323void useragent(void);
324
f2ec8c75 325// userinfo.c
aa6ac9f2 326/*@shared@*/struct userinfostruct *userinfo_create(const char *userid, const char *ip);
f2ec8c75 327void userinfo_free(void);
b6b6cb8c 328void userinfo_label(struct userinfostruct *uinfo,const char *label);
4ca814cc
FM
329/*@shared@*/struct userinfostruct *userinfo_find_from_file(const char *filename);
330/*@shared@*/struct userinfostruct *userinfo_find_from_id(const char *id);
05fea6e7 331/*@shared@*/struct userinfostruct *userinfo_find_from_ip(const char *ip);
93551487
FM
332userscan userinfo_startscan(void);
333void userinfo_stopscan(userscan uscan);
334struct userinfostruct *userinfo_advancescan(userscan uscan);
a58e6d54 335void userinfo_clearflag(void);
c4f0ea8f
FM
336void read_useralias(const char *Filename);
337void free_useralias(void);
338const char *process_user(const char *user);
f2ec8c75 339
965c4a6f
FM
340// usertab.c
341void init_usertab(const char *UserTabFile);
342void user_find(char *mappedname, int namelen, const char *userlogin);
343void close_usertab(void);
344
5f3cfd1d 345// util.c
06b39c87 346void getword_start(/*@out@*/struct getwordstruct *gwarea, const char *line);
9c7c6346 347void getword_restart(struct getwordstruct *gwarea);
d5a1c7f9
FM
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);
bd8b7715 353__attribute__((warn_unused_result)) int getword_atoi(/*@out@*/int *number, struct getwordstruct *gwarea, char stop);
2c4bc22b
FM
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);
d5a1c7f9 356__attribute__((warn_unused_result)) int getword_ptr(char *orig_line,/*@out@*/char **word, struct getwordstruct *gwarea, char stop);
e6414a9d
FM
357long long int my_atoll (const char *nptr);
358int is_absolute(const char *path);
e3af0ae9 359int getnumlist(char *, numlist *, const int, const int);
fa6552b0
FM
360int conv_month(const char *month);
361const char *conv_month_name(int month);
60ec7f09
FM
362void buildymd(const char *dia, const char *mes, const char *ano, char *wdata,int wdata_size);
363void date_from(char *date,int date_size, int *dfrom, int *duntil);
5f3cfd1d
FM
364char *fixnum(long long int value, int n);
365char *fixnum2(long long int value, int n);
366void fixnone(char *str);
324ba7f3 367char *fixtime(long long int elap);
2357ef77 368void fixendofline(char *str);
5f3cfd1d 369void show_info(FILE *fp_ou);
c0ec9cc7 370void show_sarg(FILE *fp_ou, int depth);
dfb337be 371void write_logo_image(FILE *fp_ou);
2e96438d
FM
372void write_html_head(FILE *fp_ou, int depth, const char *page_title,int javascript);
373void write_html_header(FILE *fp_ou, int depth, const char *title,int javascript);
c0ec9cc7 374void close_html_header(FILE *fp_ou);
342bd723 375void write_html_trailer(FILE *fp_ou);
ac422f9b
FM
376void output_html_string(FILE *fp_ou,const char *str,int maxlen);
377void output_html_url(FILE *fp_ou,const char *url);
6fa33a32 378void output_html_link(FILE *fp_ou,const char *url,int maxlen);
af961877 379void debuga(const char *File, int Line, const char *msg,...) __attribute__((format(printf,3,4)));
2ef286b6 380void debuga_more(const char *msg,...) __attribute__((format(printf,1,2)));
af961877 381void debugaz(const char *File,int Line,const char *msg,...) __attribute__((format(printf,3,4)));
e5b2c6f0 382void my_lltoa(unsigned long long int n, char *s, int ssize, int len);
48864d28 383void url_module(const char *url, char *w2);
f72b484a 384void url_to_anchor(const char *url,char *anchor,int size);
a87d4d11 385void safe_strcpy(char *dest,const char *src,int length);
5f3cfd1d
FM
386void strip_latin(char *line);
387char *buildtime(long long int elap);
15d3cb5c 388int obtdate(const char *dirname, const char *name, char *data);
a1de61fe 389void formatdate(char *date,int date_size,int year,int month,int day,int hour,int minute,int second,int dst);
fa6552b0 390void computedate(int year,int month,int day,struct tm *t);
d25d4e6a 391int obtuser(const char *dirname, const char *name);
ea275279 392void obttotal(const char *dirname, const char *name, int nuser, long long int *tbytes, long long int *media);
5f3cfd1d
FM
393void version(void);
394int vercode(const char *code);
48864d28
FM
395void load_excludecodes(const char *ExcludeCodes);
396void free_excludecodes(void);
7a9d0965 397int PortableMkDir(const char *path,int mode);
5f3cfd1d
FM
398void my_mkdir(const char *name);
399int testvaliduserchar(const char *user);
400char *strlow(char *string);
401char *strup(char *string);
fa6552b0
FM
402int month2num(const char *month);
403int builddia(int day, int month, int year);
944cf283 404int compare_date(struct tm *date1,struct tm *date2);
0971b2d6 405bool IsTreeFileDirName(const char *Name);
16c12388
FM
406bool IsTreeYearFileName(const char *Name);
407bool IsTreeMonthFileName(const char *Name);
408bool IsTreeDayFileName(const char *Name);
fa6552b0
FM
409int vrfydir(const struct periodstruct *per1, const char *addr, const char *site, const char *us, const char *form);
410int getperiod_fromsarglog(const char *arqtt,struct periodstruct *period);
42b117e3 411void getperiod_fromrange(struct periodstruct *period,int dfrom,int duntil);
cc6af460 412void getperiod_merge(struct periodstruct *main,struct periodstruct *candidate);
fa6552b0 413int getperiod_buildtext(struct periodstruct *period);
5f3cfd1d 414void removetmp(const char *outdir);
81a022d8 415void zdate(char *ftime,int ftimesize, char DateFormat);
5f3cfd1d 416char *get_param_value(const char *param,char *line);
48864d28 417int compar( const void *, const void * );
170a77ea
FM
418void unlinkdir(const char *dir,bool contentonly);
419void emptytmpdir(const char *dir);
7819e0d5 420int extract_address_mask(const char *buf,const char **text,unsigned char *ipv4,unsigned short int *ipv6,int *nbits,const char **next);