]>
Commit | Line | Data |
---|---|---|
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 |
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. | |
4246ae8d FM |
19 | LogLevel_Source, |
20 | //! Display data about what is processed | |
21 | LogLevel_Data | |
cb59dc47 FM |
22 | }; |
23 | ||
f83d7b44 | 24 | struct ReadLogStruct;//forward declaration |
8e53b2e7 | 25 | |
9c7c6346 FM |
26 | struct getwordstruct |
27 | { | |
28 | const char *current; | |
29 | const char *beginning; | |
e5b2c6f0 | 30 | int modified; |
9c7c6346 FM |
31 | }; |
32 | ||
afaa3b67 | 33 | typedef struct longlinestruct *longline; |
ac422f9b | 34 | |
2240dcea FM |
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 | ||
074a6d8f FM |
61 | /*! |
62 | * \brief Error codes returned by process_user. | |
63 | */ | |
64 | enum UserProcessError | |
65 | { | |
66 | USERERR_NoError, | |
67 | USERERR_NameTooLong, | |
68 | USERERR_Excluded, | |
69 | USERERR_InvalidChar, | |
70 | USERERR_EmptyUser, | |
71 | USERERR_SysUser, | |
72 | USERERR_Ignored, | |
73 | USERERR_Untracked, | |
74 | }; | |
75 | ||
93551487 FM |
76 | /*! \brief What is known about a user. |
77 | */ | |
f2ec8c75 FM |
78 | struct userinfostruct |
79 | { | |
93551487 | 80 | //! The ID of the user as found in the input file. |
b6b6cb8c | 81 | const char *id; |
aa6ac9f2 FM |
82 | //! The user's IP address. |
83 | const char *ip; | |
93551487 FM |
84 | //! \c True if the ID is in fact the IP address from which the user connected. |
85 | bool id_is_ip; | |
86 | //! \c True if the user doesn't have a report file. | |
87 | bool no_report; | |
88 | //! The name of the user to display in the report. | |
b6b6cb8c | 89 | const char *label; |
93551487 | 90 | //! The mangled name to use in file names of that user. |
b6b6cb8c | 91 | const char *filename; |
a58e6d54 FM |
92 | //! \c True if this user is in the topuser list. |
93 | int topuser; | |
94 | //! A general purpose flag that can be set when scanning the user's list. | |
95 | int flag; | |
d91457d2 FM |
96 | #ifdef ENABLE_DOUBLE_CHECK_DATA |
97 | //! Total number of bytes. | |
98 | long long int nbytes; | |
99 | //! Total time spent processing the requests. | |
100 | long long int elap; | |
101 | #endif | |
f2ec8c75 FM |
102 | }; |
103 | ||
93551487 FM |
104 | //! Scan through the known users. |
105 | typedef struct userscanstruct *userscan; | |
106 | ||
9dc20988 FM |
107 | /*! \brief Global statistics |
108 | */ | |
109 | struct globalstatstruct | |
110 | { | |
111 | //! Total number of accesses. | |
112 | long long int nacc; | |
113 | //! Total number of bytes. | |
114 | long long int nbytes; | |
115 | //! Total time spent processing the requests. | |
116 | long long int elap; | |
117 | //! Amount of data fetched from the cache. | |
118 | long long int incache; | |
119 | //! Amount of data not fetched from the cache. | |
120 | long long int oucache; | |
e5b3a129 FM |
121 | //! The number of users in the topuser list. |
122 | int totuser; | |
9dc20988 FM |
123 | }; |
124 | ||
026ddd8b FM |
125 | //! The object to store the daily statistics. |
126 | typedef struct DayStruct *DayObject; | |
127 | ||
27d1fa35 FM |
128 | /*! |
129 | \brief Log filtering criterion. | |
130 | */ | |
131 | struct ReadLogDataStruct | |
132 | { | |
133 | //! The filtering date range. | |
134 | char DateRange[255]; | |
135 | //! \c True to filter on hosts. | |
136 | bool HostFilter; | |
137 | //! \c True to filter on users. | |
138 | bool UserFilter; | |
139 | //! Maximum elpased time allowed. Any time greater than this value is set to zero. | |
140 | long int max_elapsed; | |
141 | //! \c True to restrict the log to the system users. | |
142 | bool SysUsers; | |
143 | //! The start time to include in the report(H*100+M). Set to -1 to disable. | |
144 | int StartTime; | |
145 | //! The end time to include in the report(H*100+M). Set to -1 to disable. | |
146 | int EndTime; | |
147 | }; | |
148 | ||
0b5356bb FM |
149 | /*! |
150 | \brief How to handle the per_user_limit file creation. | |
151 | */ | |
152 | enum PerUserFileCreationEnum | |
153 | { | |
154 | //! Purge the file if it exists or create an empty file. | |
155 | PUFC_Always, | |
156 | //! Delete old files and don't create a new file unless necessary. | |
157 | PUFC_AsRequired | |
158 | }; | |
159 | ||
3877d630 FM |
160 | /*! |
161 | \brief What to write into the per_user_limit file. | |
162 | */ | |
163 | enum PerUserOutputEnum | |
164 | { | |
165 | PUOE_UserId, | |
166 | PUOE_UserIp | |
167 | }; | |
168 | ||
2e29ae23 FM |
169 | /*! |
170 | \brief How to log every user crossing the download limit. | |
171 | */ | |
172 | struct PerUserLimitStruct | |
173 | { | |
174 | //! File to save the user's IP or ID to. | |
175 | char File[255]; | |
176 | //! Limit above which the user is reported. | |
177 | int Limit; | |
3877d630 FM |
178 | //! What to write into the file. |
179 | enum PerUserOutputEnum Output; | |
2e29ae23 FM |
180 | }; |
181 | ||
5f3cfd1d | 182 | // auth.c |
d25d4e6a | 183 | void htaccess(const struct userinfostruct *uinfo); |
5f3cfd1d FM |
184 | |
185 | // authfail.c | |
16b013cc FM |
186 | void authfail_open(void); |
187 | void authfail_write(const struct ReadLogStruct *log_entry); | |
188 | void authfail_close(void); | |
189 | bool is_authfail(void); | |
5f3cfd1d | 190 | void authfail_report(void); |
16b013cc | 191 | void authfail_cleanup(void); |
5f3cfd1d | 192 | |
5f3cfd1d | 193 | // convlog.c |
81a022d8 | 194 | void convlog(const char* arq, char df, int dfrom, int duntil); |
5f3cfd1d FM |
195 | |
196 | // css.c | |
d183fb7f | 197 | void css_content(FILE *fp_css); |
5f3cfd1d FM |
198 | void css(FILE *fp_css); |
199 | ||
200 | // dansguardian_log.c | |
201 | void dansguardian_log(void); | |
202 | ||
203 | // dansguardian_report.c | |
204 | void dansguardian_report(void); | |
205 | ||
206 | // datafile.c | |
207 | void data_file(char *tmp); | |
208 | ||
209 | // decomp.c | |
800eafb8 | 210 | FileObject *decomp(const char *arq); |
5f3cfd1d FM |
211 | |
212 | // denied.c | |
8e53b2e7 FM |
213 | void denied_open(void); |
214 | void denied_write(const struct ReadLogStruct *log_entry); | |
215 | void denied_close(void); | |
216 | bool is_denied(void); | |
5f3cfd1d | 217 | void gen_denied_report(void); |
60b48ae5 | 218 | void denied_cleanup(void); |
5f3cfd1d FM |
219 | |
220 | // download.c | |
11284535 FM |
221 | void download_open(void); |
222 | void download_write(const struct ReadLogStruct *log_entry,const char *url); | |
223 | void download_close(void); | |
224 | bool is_download(void); | |
5f3cfd1d | 225 | void download_report(void); |
6e792ade FM |
226 | void free_download(void); |
227 | void set_download_suffix(const char *list); | |
2824ec9b | 228 | bool is_download_suffix(const char *url); |
11284535 | 229 | void download_cleanup(void); |
5f3cfd1d FM |
230 | |
231 | // email.c | |
6bbb47cf FM |
232 | FILE *Email_OutputFile(const char *Module); |
233 | void Email_Send(FILE *fp,const char *Subject); | |
5f3cfd1d FM |
234 | |
235 | // exclude.c | |
43f18f45 FM |
236 | void gethexclude(const char *hexfile, int debug); |
237 | void getuexclude(const char *uexfile, int debug); | |
238 | int vhexclude(const char *url); | |
239 | int vuexclude(const char *user); | |
2824ec9b | 240 | bool is_indexonly(void); |
43f18f45 | 241 | void free_exclude(void); |
5f3cfd1d | 242 | |
6068ae56 FM |
243 | #ifndef HAVE_FNMATCH |
244 | // fnmtach.c | |
245 | int fnmatch(const char *pattern,const char *string,int flags); | |
246 | #endif | |
247 | ||
5f3cfd1d | 248 | // getconf.c |
da94b2c7 | 249 | void getconf(const char *File); |
5f3cfd1d FM |
250 | |
251 | // grepday.c | |
1f482a8d | 252 | void greport_prepare(void); |
f2ec8c75 | 253 | void greport_day(const struct userinfostruct *user); |
c274f011 | 254 | void greport_cleanup(void); |
5f3cfd1d FM |
255 | |
256 | // html.c | |
257 | void htmlrel(void); | |
258 | ||
259 | // indexonly.c | |
260 | void index_only(const char *dirname,int debug); | |
261 | ||
262 | // ip2name.c | |
51b166d4 FM |
263 | int ip2name_config(const char *param); |
264 | void ip2name_forcedns(void); | |
5f3cfd1d | 265 | void ip2name(char *ip,int ip_len); |
0326d73b | 266 | void ip2name_cleanup(void); |
4afbb7a5 | 267 | void name2ip(char *name,int name_size); |
5f3cfd1d | 268 | |
5f3cfd1d FM |
269 | // lastlog.c |
270 | void mklastlog(const char *outdir); | |
271 | ||
afaa3b67 | 272 | // longline.c |
fa6552b0 | 273 | __attribute__((warn_unused_result)) /*@null@*//*@only@*/longline longline_create(void); |
afaa3b67 | 274 | void longline_reset(longline line); |
800eafb8 | 275 | /*@null@*/char *longline_read(FileObject *fp_in,/*@null@*/longline line); |
afaa3b67 FM |
276 | void longline_destroy(/*@out@*//*@only@*//*@null@*/longline *line_ptr); |
277 | ||
5f3cfd1d FM |
278 | // index.c |
279 | void make_index(void); | |
280 | ||
27d1fa35 FM |
281 | // readlog.c |
282 | int ReadLogFile(struct ReadLogDataStruct *Filter); | |
b6fb8c79 | 283 | bool GetLogPeriod(struct tm *Start,struct tm *End); |
27d1fa35 | 284 | |
5f3cfd1d FM |
285 | // realtime.c |
286 | void realtime(void); | |
287 | ||
330b1c52 FM |
288 | // redirector.c |
289 | void redirector_log(void); | |
290 | void redirector_report(void); | |
291 | ||
5f3cfd1d | 292 | // repday.c |
f2ec8c75 | 293 | void report_day(const struct userinfostruct *user); |
5f3cfd1d FM |
294 | |
295 | // report.c | |
5f3cfd1d | 296 | void gerarel(void); |
2240dcea | 297 | int ger_read(char *buffer,struct generalitemstruct *item,const char *filename); |
9dc20988 | 298 | void totalger(FILE *fp_gen,const char *filename); |
5f3cfd1d FM |
299 | |
300 | // siteuser.c | |
301 | void siteuser(void); | |
302 | ||
303 | // smartfilter.c | |
304 | void smartfilter_report(void); | |
305 | ||
306 | // sort.c | |
461b479d | 307 | void sort_users_log(const char *tmp, int debug,struct userinfostruct *uinfo); |
e5b3a129 | 308 | void tmpsort(const struct userinfostruct *uinfo); |
15d5372b | 309 | void sort_labels(const char **label,const char **order); |
5f3cfd1d FM |
310 | |
311 | // splitlog.c | |
81a022d8 | 312 | void splitlog(const char *arq, char df, int dfrom, int duntil, int convert, const char *splitprefix); |
5f3cfd1d | 313 | |
5f3cfd1d FM |
314 | // topsites.c |
315 | void topsites(void); | |
316 | ||
317 | // topuser.c | |
318 | void topuser(void); | |
319 | ||
320 | // totday.c | |
026ddd8b FM |
321 | DayObject day_prepare(void); |
322 | void day_cleanup(DayObject ddata); | |
323 | void day_newuser(DayObject ddata); | |
324 | void day_addpoint(DayObject ddata,const char *date, const char *time, long long int elap, long long int bytes); | |
325 | void day_totalize(DayObject ddata,const char *tmp, const struct userinfostruct *uinfo); | |
e3e6aef4 | 326 | void day_deletefile(const struct userinfostruct *uinfo); |
5f3cfd1d | 327 | |
22715352 FM |
328 | // url.c |
329 | void read_hostalias(const char *Filename); | |
330 | void free_hostalias(void); | |
6fa33a32 | 331 | const char *skip_scheme(const char *url); |
e2379f05 | 332 | const char *process_url(const char *url,bool full_url); |
22715352 FM |
333 | void url_hostname(const char *url,char *hostname,int hostsize); |
334 | ||
5f3cfd1d FM |
335 | // usage.c |
336 | void usage(const char *prog); | |
337 | ||
338 | // useragent.c | |
339 | void useragent(void); | |
340 | ||
f2ec8c75 | 341 | // userinfo.c |
aa6ac9f2 | 342 | /*@shared@*/struct userinfostruct *userinfo_create(const char *userid, const char *ip); |
f2ec8c75 | 343 | void userinfo_free(void); |
b6b6cb8c | 344 | void userinfo_label(struct userinfostruct *uinfo,const char *label); |
4ca814cc FM |
345 | /*@shared@*/struct userinfostruct *userinfo_find_from_file(const char *filename); |
346 | /*@shared@*/struct userinfostruct *userinfo_find_from_id(const char *id); | |
05fea6e7 | 347 | /*@shared@*/struct userinfostruct *userinfo_find_from_ip(const char *ip); |
93551487 FM |
348 | userscan userinfo_startscan(void); |
349 | void userinfo_stopscan(userscan uscan); | |
350 | struct userinfostruct *userinfo_advancescan(userscan uscan); | |
a58e6d54 | 351 | void userinfo_clearflag(void); |
c4f0ea8f FM |
352 | void read_useralias(const char *Filename); |
353 | void free_useralias(void); | |
074a6d8f | 354 | enum UserProcessError process_user(const char **UserPtr,const char *IpAddress,bool *IsIp); |
f2ec8c75 | 355 | |
965c4a6f FM |
356 | // usertab.c |
357 | void init_usertab(const char *UserTabFile); | |
358 | void user_find(char *mappedname, int namelen, const char *userlogin); | |
359 | void close_usertab(void); | |
360 | ||
5f3cfd1d | 361 | // util.c |
06b39c87 | 362 | void getword_start(/*@out@*/struct getwordstruct *gwarea, const char *line); |
9c7c6346 | 363 | void getword_restart(struct getwordstruct *gwarea); |
d5a1c7f9 FM |
364 | __attribute__((warn_unused_result)) int getword(/*@out@*/char *word, int limit, struct getwordstruct *gwarea, char stop); |
365 | __attribute__((warn_unused_result)) int getword_limit(/*@out@*/char *word, int limit, struct getwordstruct *gwarea, char stop); | |
366 | __attribute__((warn_unused_result)) int getword_multisep(/*@out@*/char *word, int limit, struct getwordstruct *gwarea, char stop); | |
367 | __attribute__((warn_unused_result)) int getword_skip(int limit, struct getwordstruct *gwarea, char stop); | |
368 | __attribute__((warn_unused_result)) int getword_atoll(/*@out@*/long long int *number, struct getwordstruct *gwarea, char stop); | |
bd8b7715 | 369 | __attribute__((warn_unused_result)) int getword_atoi(/*@out@*/int *number, struct getwordstruct *gwarea, char stop); |
2c4bc22b FM |
370 | __attribute__((warn_unused_result)) int getword_atol(long int *number, struct getwordstruct *gwarea, char stop); |
371 | __attribute__((warn_unused_result)) int getword_atolu(unsigned long int *number, struct getwordstruct *gwarea, char stop); | |
d5a1c7f9 | 372 | __attribute__((warn_unused_result)) int getword_ptr(char *orig_line,/*@out@*/char **word, struct getwordstruct *gwarea, char stop); |
e6414a9d FM |
373 | long long int my_atoll (const char *nptr); |
374 | int is_absolute(const char *path); | |
e3af0ae9 | 375 | int getnumlist(char *, numlist *, const int, const int); |
fa6552b0 FM |
376 | int conv_month(const char *month); |
377 | const char *conv_month_name(int month); | |
60ec7f09 FM |
378 | void buildymd(const char *dia, const char *mes, const char *ano, char *wdata,int wdata_size); |
379 | void date_from(char *date,int date_size, int *dfrom, int *duntil); | |
5f3cfd1d FM |
380 | char *fixnum(long long int value, int n); |
381 | char *fixnum2(long long int value, int n); | |
382 | void fixnone(char *str); | |
324ba7f3 | 383 | char *fixtime(long long int elap); |
2357ef77 | 384 | void fixendofline(char *str); |
5f3cfd1d | 385 | void show_info(FILE *fp_ou); |
c0ec9cc7 | 386 | void show_sarg(FILE *fp_ou, int depth); |
dfb337be | 387 | void write_logo_image(FILE *fp_ou); |
2e96438d FM |
388 | void write_html_head(FILE *fp_ou, int depth, const char *page_title,int javascript); |
389 | void write_html_header(FILE *fp_ou, int depth, const char *title,int javascript); | |
c0ec9cc7 | 390 | void close_html_header(FILE *fp_ou); |
342bd723 | 391 | void write_html_trailer(FILE *fp_ou); |
ac422f9b FM |
392 | void output_html_string(FILE *fp_ou,const char *str,int maxlen); |
393 | void output_html_url(FILE *fp_ou,const char *url); | |
6fa33a32 | 394 | void output_html_link(FILE *fp_ou,const char *url,int maxlen); |
af961877 | 395 | void debuga(const char *File, int Line, const char *msg,...) __attribute__((format(printf,3,4))); |
2ef286b6 | 396 | void debuga_more(const char *msg,...) __attribute__((format(printf,1,2))); |
af961877 | 397 | void debugaz(const char *File,int Line,const char *msg,...) __attribute__((format(printf,3,4))); |
e5b2c6f0 | 398 | void my_lltoa(unsigned long long int n, char *s, int ssize, int len); |
48864d28 | 399 | void url_module(const char *url, char *w2); |
f72b484a | 400 | void url_to_anchor(const char *url,char *anchor,int size); |
a87d4d11 | 401 | void safe_strcpy(char *dest,const char *src,int length); |
5f3cfd1d FM |
402 | void strip_latin(char *line); |
403 | char *buildtime(long long int elap); | |
15d3cb5c | 404 | int obtdate(const char *dirname, const char *name, char *data); |
a1de61fe | 405 | void formatdate(char *date,int date_size,int year,int month,int day,int hour,int minute,int second,int dst); |
fa6552b0 | 406 | void computedate(int year,int month,int day,struct tm *t); |
d25d4e6a | 407 | int obtuser(const char *dirname, const char *name); |
ea275279 | 408 | void obttotal(const char *dirname, const char *name, int nuser, long long int *tbytes, long long int *media); |
5f3cfd1d FM |
409 | void version(void); |
410 | int vercode(const char *code); | |
48864d28 FM |
411 | void load_excludecodes(const char *ExcludeCodes); |
412 | void free_excludecodes(void); | |
7a9d0965 | 413 | int PortableMkDir(const char *path,int mode); |
5f3cfd1d FM |
414 | void my_mkdir(const char *name); |
415 | int testvaliduserchar(const char *user); | |
416 | char *strlow(char *string); | |
417 | char *strup(char *string); | |
fa6552b0 FM |
418 | int month2num(const char *month); |
419 | int builddia(int day, int month, int year); | |
944cf283 | 420 | int compare_date(struct tm *date1,struct tm *date2); |
0971b2d6 | 421 | bool IsTreeFileDirName(const char *Name); |
16c12388 FM |
422 | bool IsTreeYearFileName(const char *Name); |
423 | bool IsTreeMonthFileName(const char *Name); | |
424 | bool IsTreeDayFileName(const char *Name); | |
b2c1a7b4 | 425 | int vrfydir(const struct periodstruct *per1, const char *addr, const char *site, const char *us); |
fa6552b0 | 426 | int getperiod_fromsarglog(const char *arqtt,struct periodstruct *period); |
42b117e3 | 427 | void getperiod_fromrange(struct periodstruct *period,int dfrom,int duntil); |
cc6af460 | 428 | void getperiod_merge(struct periodstruct *main,struct periodstruct *candidate); |
fa6552b0 | 429 | int getperiod_buildtext(struct periodstruct *period); |
5f3cfd1d | 430 | void removetmp(const char *outdir); |
81a022d8 | 431 | void zdate(char *ftime,int ftimesize, char DateFormat); |
5f3cfd1d | 432 | char *get_param_value(const char *param,char *line); |
48864d28 | 433 | int compar( const void *, const void * ); |
170a77ea FM |
434 | void unlinkdir(const char *dir,bool contentonly); |
435 | void emptytmpdir(const char *dir); | |
7819e0d5 | 436 | int extract_address_mask(const char *buf,const char **text,unsigned char *ipv4,unsigned short int *ipv6,int *nbits,const char **next); |