/*
* SARG Squid Analysis Report Generator http://sarg.sourceforge.net
- * 1998, 2011
+ * 1998, 2015
*
* SARG donations:
* please look at http://sarg.sourceforge.net/donations.php
void data_file(char *tmp)
{
- FILE *fp_in, *fp_ou=NULL;
+ FileObject *fp_in;
+ FILE *fp_ou=NULL;
char *buf;
char accdia[11], acchora[9], accip[MAXLEN], *accurl;
char oldaccdia[11], oldacchora[9], oldaccip[MAXLEN];
char *oldurl;
- char olduser[MAXLEN], acccode[50], oldacccode[50];
+ char acccode[50], oldacccode[50];
char ipantes[MAXLEN], nameantes[MAXLEN];
char accsmart[MAXLEN];
char crc2[50];
char *str;
char tmp3[MAXLEN];
char u2[MAX_USER_LEN];
+ char userlabel[MAX_USER_LEN];
userscan uscan;
long long int nbytes=0;
long long int nelap=0;
struct userinfostruct *uinfo;
longline line;
+ init_usertab(UserTabFile);
+
ipantes[0]='\0';
nameantes[0]='\0';
- olduser[0]='\0';
oldurl=NULL;
ourl_size=0;
uscan=userinfo_startscan();
if (uscan == NULL) {
- debuga(_("Cannot enumerate the user list\n"));
+ debuga(__FILE__,__LINE__,_("Cannot enumerate the user list\n"));
exit(EXIT_FAILURE);
}
while ( (uinfo = userinfo_advancescan(uscan)) != NULL ) {
ip2name(u2,sizeof(u2));
strcpy(nameantes,u2);
}
- user_find(uinfo->label,MAX_USER_LEN, u2);
- if(debug) debuga(_("Reading user file: %s/%s\n"),tmp,uinfo->filename);
+ user_find(userlabel,MAX_USER_LEN, u2);
+ userinfo_label(uinfo,userlabel);
+ if(debug) debuga(__FILE__,__LINE__,_("Reading user file \"%s/%s\"\n"),tmp,uinfo->filename);
- if (snprintf(tmp3,sizeof(tmp3),"%s/%s.log",tmp,uinfo->filename)>=sizeof(tmp3)) {
- debuga(_("(datafile) directory path too long: %s/%s.log\n"),tmp,uinfo->filename);
+ sort_users_log(tmp,debug,uinfo);
+ if (snprintf(tmp3,sizeof(tmp3),"%s/%s.user_log",tmp,uinfo->filename)>=sizeof(tmp3)) {
+ debuga(__FILE__,__LINE__,_("Path too long: "));
+ debuga_more("%s/%s.user_log\n",tmp,uinfo->filename);
exit(EXIT_FAILURE);
}
- if((fp_in=MY_FOPEN(tmp3,"r"))==NULL){
- debuga(_("(datafile) Cannot open file %s\n"),tmp3);
+ if((fp_in=FileObject_Open(tmp3))==NULL){
+ debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),tmp3,FileObject_GetLastOpenError());
exit(EXIT_FAILURE);
}
if ((line=longline_create())==NULL) {
- debuga(_("Not enough memory to read the downloaded files.\n"));
+ debuga(__FILE__,__LINE__,_("Not enough memory to read file \"%s\"\n"),tmp3);
exit(EXIT_FAILURE);
}
getword(accip,sizeof(accip),&gwarea,'\t')<0 ||
getword_ptr(buf,&accurl,&gwarea,'\t')<0 || getword_atoll(&accbytes,&gwarea,'\t')<0 ||
getword(acccode,sizeof(acccode),&gwarea,'\t')<0 || getword_atoll(&accelap,&gwarea,'\t')<0) {
- debuga(_("There is a broken record or garbage in file %s\n"),tmp3);
+ debuga(__FILE__,__LINE__,_("Invalid record in file \"%s\"\n"),tmp3);
exit(EXIT_FAILURE);
}
if (getword_skip(20000,&gwarea,'"')<0 || getword(accsmart,sizeof(accsmart),&gwarea,'"')<0) {
- debuga(_("There is an invalid smart info in file %s\n"),tmp3);
+ debuga(__FILE__,__LINE__,_("Invalid smart info in file \"%s\"\n"),tmp3);
exit(EXIT_FAILURE);
}
ourl_size=url_len+1;
oldurl=realloc(oldurl,ourl_size);
if (!oldurl) {
- debuga(_("Not enough memory to store the url\n"));
+ debuga(__FILE__,__LINE__,_("Not enough memory to store the url\n"));
exit(EXIT_FAILURE);
}
}
if(!same_url || new_user){
if(!fp_ou && (fp_ou=MY_FOPEN(DataFile,"w"))==NULL){
- debuga(_("(datafile) Cannot open file %s\n"),DataFile);
+ debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),DataFile,strerror(errno));
exit(EXIT_FAILURE);
}
saverecs(fp_ou,uinfo,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache);
ourl_size=url_len+1;
oldurl=realloc(oldurl,ourl_size);
if (!oldurl) {
- debuga(_("Not enough memory to store the url\n"));
+ debuga(__FILE__,__LINE__,_("Not enough memory to store the url\n"));
exit(EXIT_FAILURE);
}
}
strcpy(oldacchora,acchora);
}
- fclose(fp_in);
+ if (FileObject_Close(fp_in)) {
+ debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),tmp3,FileObject_GetLastCloseError());
+ exit(EXIT_FAILURE);
+ }
longline_destroy(&line);
}
userinfo_stopscan(uscan);
if (oldurl) free(oldurl);
- if (fp_ou) fclose(fp_ou);
+ if (fp_ou && fclose(fp_ou)==EOF) {
+ debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),DataFile,strerror(errno));
+ exit(EXIT_FAILURE);
+ }
if(debug)
- debuga(_("Datafile %s written successfully\n"),DataFile);
+ debuga(__FILE__,__LINE__,_("Datafile %s written successfully\n"),DataFile);
}
void saverecs(FILE *fp_ou, const struct userinfostruct *uinfo, long long int nacc, char *url, long long int nbytes, char *ip, char *hora, char *dia, long long int nelap, long long int incache, long long int oucache)