]>
git.ipfire.org Git - thirdparty/sarg.git/blob - include/defs.h
2 \brief Declaration of the structures and functions.
6 #define __attribute__(a)
9 #include "include/fileobject.h"
11 //! \brief Constants to compare the log level to display messages
14 //! Process informational messages.
16 //! Debug level messages.
18 //! Display the source file name and line number along with the message.
20 //! Display data about what is processed
24 struct ReadLogStruct
;//forward declaration
29 const char *beginning
;
33 typedef struct longlinestruct
*longline
;
35 struct generalitemstruct
37 //! \c True if the entry is for the total of the file or \c false if it is a single line.
39 //! The user to which the entry apply. The length is limited to ::MAX_USER_LEN.
41 //! The number of accesses performed by the user.
43 //! The number of bytes transfered.
45 //! The URL accessed by the user. The length is not limited.
47 //! The source IP address of the user. The length is limited to ::MAX_IP_LEN.
49 //! The time of the access. The length is limited to ::MAX_DATETIME_LEN.
51 //! The date of the access. The length is limited to ::MAX_DATETIME_LEN.
53 //! The number of milliseconds spend processing the request.
55 //! The number of bytes fetched from the cache of the proxy (cache hit).
57 //! The number of bytes fetched from the site (cache miss).
62 * \brief Error codes returned by process_user.
76 /*! \brief What is known about a user.
80 //! The ID of the user as found in the input file.
82 //! The user's IP address.
84 //! \c True if the ID is in fact the IP address from which the user connected.
86 //! \c True if the user doesn't have a report file.
88 //! The name of the user to display in the report.
90 //! The mangled name to use in file names of that user.
92 //! \c True if this user is in the topuser list.
94 //! A general purpose flag that can be set when scanning the user's list.
96 #ifdef ENABLE_DOUBLE_CHECK_DATA
97 //! Total number of bytes.
99 //! Total time spent processing the requests.
104 //! Scan through the known users.
105 typedef struct userscanstruct
*userscan
;
107 /*! \brief Global statistics
109 struct globalstatstruct
111 //! Total number of accesses.
113 //! Total number of bytes.
114 long long int nbytes
;
115 //! Total time spent processing the requests.
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
;
121 //! The number of users in the topuser list.
125 //! The object to store the daily statistics.
126 typedef struct DayStruct
*DayObject
;
129 \brief Log filtering criterion.
131 struct ReadLogDataStruct
133 //! The filtering date range.
135 //! \c True to filter on hosts.
137 //! \c True to filter on users.
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.
143 //! The start time to include in the report(H*100+M). Set to -1 to disable.
145 //! The end time to include in the report(H*100+M). Set to -1 to disable.
150 \brief How to handle the per_user_limit file creation.
152 enum PerUserFileCreationEnum
154 //! Purge the file if it exists or create an empty file.
156 //! Delete old files and don't create a new file unless necessary.
161 \brief What to write into the per_user_limit file.
163 enum PerUserOutputEnum
170 \brief How to log every user crossing the download limit.
172 struct PerUserLimitStruct
174 //! File to save the user's IP or ID to.
176 //! Limit above which the user is reported.
178 //! What to write into the file.
179 enum PerUserOutputEnum Output
;
183 void htaccess(const struct userinfostruct
*uinfo
);
186 void authfail_open(void);
187 void authfail_write(const struct ReadLogStruct
*log_entry
);
188 void authfail_close(void);
189 bool is_authfail(void);
190 void authfail_report(void);
191 void authfail_cleanup(void);
194 void convlog(const char* arq
, char df
, int dfrom
, int duntil
);
197 void css_content(FILE *fp_css
);
198 void css(FILE *fp_css
);
200 // dansguardian_log.c
201 void dansguardian_log(void);
203 // dansguardian_report.c
204 void dansguardian_report(void);
207 void data_file(char *tmp
);
210 FileObject
*decomp(const char *arq
);
213 void denied_open(void);
214 void denied_write(const struct ReadLogStruct
*log_entry
);
215 void denied_close(void);
216 bool is_denied(void);
217 void gen_denied_report(void);
218 void denied_cleanup(void);
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);
225 void download_report(void);
226 void free_download(void);
227 void set_download_suffix(const char *list
);
228 bool is_download_suffix(const char *url
);
229 void download_cleanup(void);
232 FILE *Email_OutputFile(const char *Module
);
233 void Email_Send(FILE *fp
,const char *Subject
);
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
);
240 bool is_indexonly(void);
241 void free_exclude(void);
245 int fnmatch(const char *pattern
,const char *string
,int flags
);
249 void getconf(const char *File
);
252 void greport_prepare(void);
253 void greport_day(const struct userinfostruct
*user
);
254 void greport_cleanup(void);
260 void index_only(const char *dirname
,int debug
);
263 int ip2name_config(const char *param
);
264 void ip2name_forcedns(void);
265 void ip2name(char *ip
,int ip_len
);
266 void ip2name_cleanup(void);
267 void name2ip(char *name
,int name_size
);
270 void mklastlog(const char *outdir
);
273 __attribute__((warn_unused_result
)) /*@null@*//*@only@*/longline
longline_create(void);
274 void longline_reset(longline line
);
275 /*@null@*/char *longline_read(FileObject
*fp_in
,/*@null@*/longline line
);
276 void longline_destroy(/*@out@*//*@only@*//*@null@*/longline
*line_ptr
);
279 void make_index(void);
282 int ReadLogFile(struct ReadLogDataStruct
*Filter
);
283 bool GetLogPeriod(struct tm
*Start
,struct tm
*End
);
289 void redirector_log(void);
290 void redirector_report(void);
293 void report_day(const struct userinfostruct
*user
);
297 int ger_read(char *buffer
,struct generalitemstruct
*item
,const char *filename
);
298 void totalger(FILE *fp_gen
,const char *filename
);
304 void smartfilter_report(void);
307 void sort_users_log(const char *tmp
, int debug
,struct userinfostruct
*uinfo
);
308 void tmpsort(const struct userinfostruct
*uinfo
);
309 void sort_labels(const char **label
,const char **order
);
312 void splitlog(const char *arq
, char df
, int dfrom
, int duntil
, int convert
, const char *splitprefix
);
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
);
326 void day_deletefile(const struct userinfostruct
*uinfo
);
329 void read_hostalias(const char *Filename
);
330 void free_hostalias(void);
331 const char *skip_scheme(const char *url
);
332 const char *process_url(const char *url
,bool full_url
);
333 void url_hostname(const char *url
,char *hostname
,int hostsize
);
336 void usage(const char *prog
);
339 FILE *UserAgent_Open(void);
340 void UserAgent_Write(FILE *fp
,const char *Ip
,const char *User
,const char *Agent
);
341 void UserAgent_Readlog(void);
342 void UserAgent(void);
345 /*@shared@*/struct userinfostruct
*userinfo_create(const char *userid
, const char *ip
);
346 void userinfo_free(void);
347 void userinfo_label(struct userinfostruct
*uinfo
,const char *label
);
348 /*@shared@*/struct userinfostruct
*userinfo_find_from_file(const char *filename
);
349 /*@shared@*/struct userinfostruct
*userinfo_find_from_id(const char *id
);
350 /*@shared@*/struct userinfostruct
*userinfo_find_from_ip(const char *ip
);
351 userscan
userinfo_startscan(void);
352 void userinfo_stopscan(userscan uscan
);
353 struct userinfostruct
*userinfo_advancescan(userscan uscan
);
354 void userinfo_clearflag(void);
355 void read_useralias(const char *Filename
);
356 void free_useralias(void);
357 enum UserProcessError
process_user(const char **UserPtr
,const char *IpAddress
,bool *IsIp
);
360 void init_usertab(const char *UserTabFile
);
361 void user_find(char *mappedname
, int namelen
, const char *userlogin
);
362 void close_usertab(void);
365 void getword_start(/*@out@*/struct getwordstruct
*gwarea
, const char *line
);
366 void getword_restart(struct getwordstruct
*gwarea
);
367 __attribute__((warn_unused_result
)) int getword(/*@out@*/char *word
, int limit
, struct getwordstruct
*gwarea
, char stop
);
368 __attribute__((warn_unused_result
)) int getword_limit(/*@out@*/char *word
, int limit
, struct getwordstruct
*gwarea
, char stop
);
369 __attribute__((warn_unused_result
)) int getword_multisep(/*@out@*/char *word
, int limit
, struct getwordstruct
*gwarea
, char stop
);
370 __attribute__((warn_unused_result
)) int getword_skip(int limit
, struct getwordstruct
*gwarea
, char stop
);
371 __attribute__((warn_unused_result
)) int getword_atoll(/*@out@*/long long int *number
, struct getwordstruct
*gwarea
, char stop
);
372 __attribute__((warn_unused_result
)) int getword_atoi(/*@out@*/int *number
, struct getwordstruct
*gwarea
, char stop
);
373 __attribute__((warn_unused_result
)) int getword_atol(long int *number
, struct getwordstruct
*gwarea
, char stop
);
374 __attribute__((warn_unused_result
)) int getword_atolu(unsigned long int *number
, struct getwordstruct
*gwarea
, char stop
);
375 __attribute__((warn_unused_result
)) int getword_ptr(char *orig_line
,/*@out@*/char **word
, struct getwordstruct
*gwarea
, char stop
);
376 long long int my_atoll (const char *nptr
);
377 int is_absolute(const char *path
);
378 int getnumlist(char *, numlist
*, const int, const int);
379 int conv_month(const char *month
);
380 const char *conv_month_name(int month
);
381 void buildymd(const char *dia
, const char *mes
, const char *ano
, char *wdata
,int wdata_size
);
382 void date_from(char *date
,int date_size
, int *dfrom
, int *duntil
);
383 char *fixnum(long long int value
, int n
);
384 char *fixnum2(long long int value
, int n
);
385 void fixnone(char *str
);
386 char *fixtime(long long int elap
);
387 void fixendofline(char *str
);
388 void show_info(FILE *fp_ou
);
389 void show_sarg(FILE *fp_ou
, int depth
);
390 void write_logo_image(FILE *fp_ou
);
391 void write_html_head(FILE *fp_ou
, int depth
, const char *page_title
,int javascript
);
392 void write_html_header(FILE *fp_ou
, int depth
, const char *title
,int javascript
);
393 void close_html_header(FILE *fp_ou
);
394 void write_html_trailer(FILE *fp_ou
);
395 void output_html_string(FILE *fp_ou
,const char *str
,int maxlen
);
396 void output_html_url(FILE *fp_ou
,const char *url
);
397 void output_html_link(FILE *fp_ou
,const char *url
,int maxlen
);
398 void debuga(const char *File
, int Line
, const char *msg
,...) __attribute__((format(printf
,3,4)));
399 void debuga_more(const char *msg
,...) __attribute__((format(printf
,1,2)));
400 void debugaz(const char *File
,int Line
,const char *msg
,...) __attribute__((format(printf
,3,4)));
401 void my_lltoa(unsigned long long int n
, char *s
, int ssize
, int len
);
402 void url_module(const char *url
, char *w2
);
403 void url_to_anchor(const char *url
,char *anchor
,int size
);
404 void safe_strcpy(char *dest
,const char *src
,int length
);
405 void strip_latin(char *line
);
406 char *buildtime(long long int elap
);
407 int obtdate(const char *dirname
, const char *name
, char *data
);
408 void formatdate(char *date
,int date_size
,int year
,int month
,int day
,int hour
,int minute
,int second
,int dst
);
409 void computedate(int year
,int month
,int day
,struct tm
*t
);
410 int obtuser(const char *dirname
, const char *name
);
411 void obttotal(const char *dirname
, const char *name
, int nuser
, long long int *tbytes
, long long int *media
);
413 int vercode(const char *code
);
414 void load_excludecodes(const char *ExcludeCodes
);
415 void free_excludecodes(void);
416 int PortableMkDir(const char *path
,int mode
);
417 void my_mkdir(const char *name
);
418 int testvaliduserchar(const char *user
);
419 char *strlow(char *string
);
420 char *strup(char *string
);
421 int month2num(const char *month
);
422 int builddia(int day
, int month
, int year
);
423 int compare_date(struct tm
*date1
,struct tm
*date2
);
424 bool IsTreeFileDirName(const char *Name
);
425 bool IsTreeYearFileName(const char *Name
);
426 bool IsTreeMonthFileName(const char *Name
);
427 bool IsTreeDayFileName(const char *Name
);
428 int vrfydir(const struct periodstruct
*per1
, const char *addr
, const char *site
, const char *us
);
429 int getperiod_fromsarglog(const char *arqtt
,struct periodstruct
*period
);
430 void getperiod_fromrange(struct periodstruct
*period
,int dfrom
,int duntil
);
431 void getperiod_torange(const struct periodstruct
*period
,int *dfrom
,int *duntil
);
432 void getperiod_merge(struct periodstruct
*main
,struct periodstruct
*candidate
);
433 int getperiod_buildtext(struct periodstruct
*period
);
434 void removetmp(const char *outdir
);
435 void zdate(char *ftime
,int ftimesize
, char DateFormat
);
436 char *get_param_value(const char *param
,char *line
);
437 int compar( const void *, const void * );
438 void unlinkdir(const char *dir
,bool contentonly
);
439 void emptytmpdir(const char *dir
);
440 int extract_address_mask(const char *buf
,const char **text
,unsigned char *ipv4
,unsigned short int *ipv6
,int *nbits
,const char **next
);