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