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"
29 #include "include/readlog.h"
32 A new file is being read. The name of the file is \a FileName.
34 static void Squid_NewFile(const char *FileName
)
39 Read one entry from a standard squid log format.
41 \param Line One line from the input log file.
42 \param Entry Where to store the information parsed from the line.
44 \retval RLRC_NoError One valid entry is parsed.
45 \retval RLRC_Unknown The line is invalid.
46 \retval RLRC_InternalError An internal error was encountered.
48 static enum ReadLogReturnCodeEnum
Squid_ReadEntry(char *Line
,struct ReadLogStruct
*Entry
)
63 while (isdigit(*Line
)) log_time
=log_time
*10+(*Line
++-'0');
64 if (*Line
!='.' || Line
==Begin
) return(RLRC_Unknown
);
66 // ignore decimal part to log time.
68 while (isdigit(*Line
)) Line
++;
69 if (*Line
!=' ' || Line
==Begin
) return(RLRC_Unknown
);
71 // skip spaces before the elapsed time.
72 while (*Line
==' ') Line
++;
73 if (!isdigit(*Line
)) return(RLRC_Unknown
);
75 // get the elapsed time.
77 Entry
->ElapsedTime
=0L;
78 while (isdigit(*Line
)) Entry
->ElapsedTime
=Entry
->ElapsedTime
*10+(*Line
++-'0');
79 if (*Line
!=' ' || Line
==Begin
) return(RLRC_Unknown
);
81 // get IP address. It can be a fqdn if that option is enabled in squid.
83 for (IpLen
=0 ; *Line
&& *Line
!=' ' ; IpLen
++) Line
++;
84 if (*Line
!=' ' || IpLen
==0) return(RLRC_Unknown
);
87 Entry
->HttpCode
=++Line
;
88 for (HttpCodeLen
=0 ; *Line
&& *Line
!=' ' ; HttpCodeLen
++) Line
++;
89 if (*Line
!=' ' || HttpCodeLen
==0) return(RLRC_Unknown
);
91 // get the number of transfered bytes.
94 while (isdigit(*Line
)) Entry
->DataSize
=Entry
->DataSize
*10+(*Line
++-'0');
95 if (*Line
!=' ' || Begin
==Line
) return(RLRC_Unknown
);
97 // skip the HTTP function
99 while (*Line
&& *Line
!=' ') Line
++;
100 if (*Line
!=' '|| Line
==Begin
) return(RLRC_Unknown
);
104 for (UrlLen
=0 ; *Line
&& *Line
!=' ' ; UrlLen
++) Line
++;
105 if (*Line
!=' ' || UrlLen
==0) return(RLRC_Unknown
);
107 // the ID of the user or - if the user is unidentified
108 Entry
->User
=User
=++Line
;
109 for (UserLen
=0 ; *Line
&& *Line
!=' ' ; UserLen
++) Line
++;
110 if (*Line
!=' ' || UserLen
==0) return(RLRC_Unknown
);
112 // now, the format is known with a good confidence. If the time doesn't decode, it is an error.
113 tt
=localtime(&log_time
);
115 debuga(_("Cannot convert the timestamp from the squid log file\n"));
116 return(RLRC_InternalError
);
118 memcpy(&Entry
->EntryTime
,tt
,sizeof(struct tm
));
120 // it is safe to alter the line buffer now that we are returning a valid entry
122 Entry
->HttpCode
[HttpCodeLen
]='\0';
123 Entry
->Url
[UrlLen
]='\0';
126 return(RLRC_NoError
);
129 //! \brief Object to read a standard squid log format.
130 const struct ReadLogProcessStruct ReadSquidLog
=
132 /* TRANSLATORS: This is the name of the log format displayed when this format is detected in an input log file. */
133 N_("squid log format"),