]> git.ipfire.org Git - thirdparty/sarg.git/blob - include/defs.h
b0802ab87d0105dfde8091391c0025e4abfe6a3b
[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 How to log every user crossing the download limit.
132 */
133 struct PerUserLimitStruct
134 {
135 //! File to save the user's IP or ID to.
136 char File[255];
137 //! Limit above which the user is reported.
138 int Limit;
139 //! \c True to report the user's ID or \c false to report the user's IP.
140 bool UserId;
141 };
142
143 // auth.c
144 void htaccess(const struct userinfostruct *uinfo);
145
146 // authfail.c
147 void authfail_open(void);
148 void authfail_write(const struct ReadLogStruct *log_entry);
149 void authfail_close(void);
150 bool is_authfail(void);
151 void authfail_report(void);
152 void authfail_cleanup(void);
153
154 // charset.c
155 void ccharset(char *CharSet);
156
157 // convlog.c
158 void convlog(const char* arq, char df, int dfrom, int duntil);
159
160 // css.c
161 void css_content(FILE *fp_css);
162 void css(FILE *fp_css);
163
164 // dansguardian_log.c
165 void dansguardian_log(void);
166
167 // dansguardian_report.c
168 void dansguardian_report(void);
169
170 // datafile.c
171 void data_file(char *tmp);
172
173 // decomp.c
174 FILE *decomp(const char *arq, bool *pipe);
175
176 // denied.c
177 void denied_open(void);
178 void denied_write(const struct ReadLogStruct *log_entry);
179 void denied_close(void);
180 bool is_denied(void);
181 void gen_denied_report(void);
182 void denied_cleanup(void);
183
184 // download.c
185 void download_open(void);
186 void download_write(const struct ReadLogStruct *log_entry,const char *url);
187 void download_close(void);
188 bool is_download(void);
189 void download_report(void);
190 void free_download(void);
191 void set_download_suffix(const char *list);
192 bool is_download_suffix(const char *url);
193 void download_cleanup(void);
194
195 // email.c
196 int geramail(const char *dirname, int debug, const char *outdir, const char *email, const char *TempDir);
197
198 // exclude.c
199 void gethexclude(const char *hexfile, int debug);
200 void getuexclude(const char *uexfile, int debug);
201 int vhexclude(const char *url);
202 int vuexclude(const char *user);
203 bool is_indexonly(void);
204 void free_exclude(void);
205
206 #ifndef HAVE_FNMATCH
207 // fnmtach.c
208 int fnmatch(const char *pattern,const char *string,int flags);
209 #endif
210
211 // getconf.c
212 void getconf(void);
213
214 // grepday.c
215 void greport_prepare(void);
216 void greport_day(const struct userinfostruct *user);
217 void greport_cleanup(void);
218
219 // html.c
220 void htmlrel(void);
221
222 // indexonly.c
223 void index_only(const char *dirname,int debug);
224
225 // ip2name.c
226 int ip2name_config(const char *param);
227 void ip2name_forcedns(void);
228 void ip2name(char *ip,int ip_len);
229 void ip2name_cleanup(void);
230 void name2ip(char *name,int name_size);
231
232 // lastlog.c
233 void mklastlog(const char *outdir);
234
235 // longline.c
236 __attribute__((warn_unused_result)) /*@null@*//*@only@*/longline longline_create(void);
237 void longline_reset(longline line);
238 /*@null@*/char *longline_read(FILE *fp_in,/*@null@*/longline line);
239 void longline_destroy(/*@out@*//*@only@*//*@null@*/longline *line_ptr);
240
241 // index.c
242 void make_index(void);
243
244 // readlog.c
245 int ReadLogFile(struct ReadLogDataStruct *Filter);
246
247 // realtime.c
248 void realtime(void);
249
250 // redirector.c
251 void redirector_log(void);
252 void redirector_report(void);
253
254 // repday.c
255 void report_day(const struct userinfostruct *user);
256
257 // report.c
258 void gerarel(void);
259 int ger_read(char *buffer,struct generalitemstruct *item,const char *filename);
260 void totalger(FILE *fp_gen,const char *filename);
261
262 // siteuser.c
263 void siteuser(void);
264
265 // smartfilter.c
266 void smartfilter_report(void);
267
268 // sort.c
269 void sort_users_log(const char *tmp, int debug,struct userinfostruct *uinfo);
270 void tmpsort(const struct userinfostruct *uinfo);
271 void sort_labels(const char **label,const char **order);
272
273 // splitlog.c
274 void splitlog(const char *arq, char df, int dfrom, int duntil, int convert, const char *splitprefix);
275
276 // topsites.c
277 void topsites(void);
278
279 // topuser.c
280 void topuser(void);
281
282 // totday.c
283 DayObject day_prepare(void);
284 void day_cleanup(DayObject ddata);
285 void day_newuser(DayObject ddata);
286 void day_addpoint(DayObject ddata,const char *date, const char *time, long long int elap, long long int bytes);
287 void day_totalize(DayObject ddata,const char *tmp, const struct userinfostruct *uinfo);
288 void day_deletefile(const struct userinfostruct *uinfo);
289
290 // url.c
291 void read_hostalias(const char *Filename);
292 void free_hostalias(void);
293 const char *skip_scheme(const char *url);
294 const char *process_url(const char *url,bool full_url);
295 void url_hostname(const char *url,char *hostname,int hostsize);
296
297 // usage.c
298 void usage(const char *prog);
299
300 // useragent.c
301 void useragent(void);
302
303 // userinfo.c
304 /*@shared@*/struct userinfostruct *userinfo_create(const char *userid, const char *ip);
305 void userinfo_free(void);
306 void userinfo_label(struct userinfostruct *uinfo,const char *label);
307 /*@shared@*/struct userinfostruct *userinfo_find_from_file(const char *filename);
308 /*@shared@*/struct userinfostruct *userinfo_find_from_id(const char *id);
309 /*@shared@*/struct userinfostruct *userinfo_find_from_ip(const char *ip);
310 userscan userinfo_startscan(void);
311 void userinfo_stopscan(userscan uscan);
312 struct userinfostruct *userinfo_advancescan(userscan uscan);
313 void userinfo_clearflag(void);
314 void read_useralias(const char *Filename);
315 void free_useralias(void);
316 const char *process_user(const char *user);
317
318 // usertab.c
319 void init_usertab(const char *UserTabFile);
320 void user_find(char *mappedname, int namelen, const char *userlogin);
321 void close_usertab(void);
322
323 // util.c
324 void getword_start(/*@out@*/struct getwordstruct *gwarea, const char *line);
325 void getword_restart(struct getwordstruct *gwarea);
326 __attribute__((warn_unused_result)) int getword(/*@out@*/char *word, int limit, struct getwordstruct *gwarea, char stop);
327 __attribute__((warn_unused_result)) int getword_limit(/*@out@*/char *word, int limit, struct getwordstruct *gwarea, char stop);
328 __attribute__((warn_unused_result)) int getword_multisep(/*@out@*/char *word, int limit, struct getwordstruct *gwarea, char stop);
329 __attribute__((warn_unused_result)) int getword_skip(int limit, struct getwordstruct *gwarea, char stop);
330 __attribute__((warn_unused_result)) int getword_atoll(/*@out@*/long long int *number, struct getwordstruct *gwarea, char stop);
331 __attribute__((warn_unused_result)) int getword_atoi(/*@out@*/int *number, struct getwordstruct *gwarea, char stop);
332 __attribute__((warn_unused_result)) int getword_atol(long int *number, struct getwordstruct *gwarea, char stop);
333 __attribute__((warn_unused_result)) int getword_atolu(unsigned long int *number, struct getwordstruct *gwarea, char stop);
334 __attribute__((warn_unused_result)) int getword_ptr(char *orig_line,/*@out@*/char **word, struct getwordstruct *gwarea, char stop);
335 long long int my_atoll (const char *nptr);
336 int is_absolute(const char *path);
337 int getnumlist(char *, numlist *, const int, const int);
338 void name_month(char *month,int month_len);
339 int conv_month(const char *month);
340 const char *conv_month_name(int month);
341 void buildymd(const char *dia, const char *mes, const char *ano, char *wdata);
342 void date_from(char *date, int *dfrom, int *duntil);
343 char *fixnum(long long int value, int n);
344 char *fixnum2(long long int value, int n);
345 void fixnone(char *str);
346 char *fixtime(long long int elap);
347 void fixendofline(char *str);
348 void show_info(FILE *fp_ou);
349 void show_sarg(FILE *fp_ou, int depth);
350 void write_logo_image(FILE *fp_ou);
351 void write_html_head(FILE *fp_ou, int depth, const char *page_title,int javascript);
352 void write_html_header(FILE *fp_ou, int depth, const char *title,int javascript);
353 void close_html_header(FILE *fp_ou);
354 __attribute__((warn_unused_result)) int write_html_trailer(FILE *fp_ou);
355 void output_html_string(FILE *fp_ou,const char *str,int maxlen);
356 void output_html_url(FILE *fp_ou,const char *url);
357 void output_html_link(FILE *fp_ou,const char *url,int maxlen);
358 void debuga(const char *msg,...) __attribute__((format(printf,1,2)));
359 void debugaz(const char *msg,...) __attribute__((format(printf,1,2)));
360 void my_lltoa(unsigned long long int n, char *s, int ssize, int len);
361 char *get_size(const char *path, const char *file);
362 void url_module(const char *url, char *w2);
363 void url_to_anchor(const char *url,char *anchor,int size);
364 void safe_strcpy(char *dest,const char *src,int length);
365 void strip_latin(char *line);
366 char *buildtime(long long int elap);
367 int obtdate(const char *dirname, const char *name, char *data);
368 void formatdate(char *date,int date_size,int year,int month,int day,int hour,int minute,int second,int dst);
369 void computedate(int year,int month,int day,struct tm *t);
370 int obtuser(const char *dirname, const char *name);
371 void obttotal(const char *dirname, const char *name, int nuser, long long int *tbytes, long long int *media);
372 void version(void);
373 int vercode(const char *code);
374 void load_excludecodes(const char *ExcludeCodes);
375 void free_excludecodes(void);
376 void my_mkdir(const char *name);
377 int testvaliduserchar(const char *user);
378 char *strlow(char *string);
379 char *strup(char *string);
380 int month2num(const char *month);
381 int builddia(int day, int month, int year);
382 int compare_date(struct tm *date1,struct tm *date2);
383 int vrfydir(const struct periodstruct *per1, const char *addr, const char *site, const char *us, const char *form);
384 int getperiod_fromsarglog(const char *arqtt,struct periodstruct *period);
385 void getperiod_fromrange(struct periodstruct *period,int dfrom,int duntil);
386 void getperiod_merge(struct periodstruct *main,struct periodstruct *candidate);
387 int getperiod_buildtext(struct periodstruct *period);
388 void removetmp(const char *outdir);
389 void zdate(char *ftime,int ftimesize, char DateFormat);
390 char *get_param_value(const char *param,char *line);
391 int compar( const void *, const void * );
392 void unlinkdir(const char *dir,bool contentonly);
393 void emptytmpdir(const char *dir);
394 int extract_address_mask(const char *buf,const char **text,unsigned char *ipv4,unsigned short int *ipv6,int *nbits,const char **next);