]>
git.ipfire.org Git - thirdparty/sarg.git/blob - lastlog.c
064cad611e8b5c4bb2edbbe5e964d20a5b05436c
2 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
6 * please look at http://sarg.sourceforge.net/donations.php
8 * http://sourceforge.net/projects/sarg/forums/forum/363374
9 * ---------------------------------------------------------------------
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
27 #include "include/conf.h"
28 #include "include/defs.h"
32 struct DirEntry
*Next
;
37 static void DeleteDirList(struct DirEntry
*List
)
39 struct DirEntry
*Next
;
44 if (List
->Name
) free(List
->Name
);
50 static struct DirEntry
*AppendDirEntry(struct DirEntry
*List
,time_t CreationTime
,const char *Name
,int NameLen
)
52 struct DirEntry
*entry
;
53 struct DirEntry
*prev
;
56 entry
=malloc(sizeof(*entry
));
58 debuga(_("Not enough memory to store a report to purge\n"));
62 entry
->Name
=malloc((NameLen
+1)*sizeof(char));
65 debuga(_("Not enough memory to store a report to purge\n"));
69 entry
->Time
=CreationTime
;
70 strcpy(entry
->Name
,Name
);
72 // store most recent file first
74 for (ptr
=List
; ptr
; ptr
=ptr
->Next
)
76 if (ptr
->Time
>CreationTime
) break;
88 static struct DirEntry
*BuildDirList(const char *Path
)
91 struct dirent
*direntp
;
96 struct DirEntry
*List
=NULL
;
98 name_pos
=strlen(Path
);
99 if (name_pos
>=sizeof(warea
)) {
100 debuga(_("The directory containing the old reports to purge is too long: %s\n"),Path
);
104 if ((dirp
= opendir(outdir
)) == NULL
) {
105 debuga(_("Failed to open directory %s - %s\n"),outdir
,strerror(errno
));
108 while ((direntp
= readdir( dirp
)) != NULL
)
110 if (!IsTreeFileDirName(direntp
->d_name
)) continue;
112 name_len
=strlen(direntp
->d_name
);
113 if (name_pos
+name_len
+1>=sizeof(warea
)) {
114 debuga(_("Directory entry too long to purge the old reports: %s%s\n"),Path
,direntp
->d_name
);
117 strcpy(warea
+name_pos
,direntp
->d_name
);
118 if (stat(warea
,&statb
) == -1) {
119 debuga(_("Failed to get the last modification time of %s\n"),warea
);
122 List
=AppendDirEntry(List
,statb
.st_mtime
,direntp
->d_name
,name_len
);
125 debuga(_("Old reports deletion not undertaken due to previous error\n"));
134 void mklastlog(const char *outdir
)
139 struct DirEntry
*List
;
140 struct DirEntry
*ptr
;
145 List
=BuildDirList(outdir
);
148 for (ptr
=List
; ptr
; ptr
=ptr
->Next
) ftot
++;
150 debuga(ngettext("%d report directory found\n","%d report directories found\n",ftot
),ftot
);
155 debuga(ngettext("No old reports to delete as only %d report currently exists\n",
156 "No old reports to delete as only %d reports currently exist\n",ftot
),ftot
);
163 debuga(ngettext("%d old report to delete\n","%d old reports to delete\n",ftot
),ftot
);
165 name_pos
=strlen(outdir
);
166 if (name_pos
>=sizeof(warea
)) {
168 debuga(_("The directory containing the old reports to purge is too long: %s\n"),outdir
);
171 strcpy(warea
,outdir
);
172 for (ptr
=List
; ptr
&& ftot
>0 ; ptr
=ptr
->Next
)
175 debuga(_("Removing old report file %s\n"),ptr
->Name
);
176 if (name_pos
+strlen(ptr
->Name
)+1>=sizeof(warea
)) {
178 debuga(_("Directory name too long: %s%s\n"),outdir
,ptr
->Name
);
181 strcpy(warea
+name_pos
,ptr
->Name
);
182 //unlinkdir(warea,0);