26 #include <boost/algorithm/string/predicate.hpp>
27 #include <boost/iostreams/filter/gzip.hpp>
38 if (Fn::ends_with(filename,
".gz"))
39 m_fin.push(Io::gzip_decompressor());
40 m_fin.push(Io::file_source(filename));
48 memset(&entry, 0,
sizeof(entry));
50 if (!getline(m_fin, m_line))
53 base = (
char *)m_line.c_str();
56 if ((base = extract_field(base, &entry.
ip_address)) == 0)
60 if ((base = extract_field(base, 0)) == 0)
64 if ((base = extract_field(base, &entry.
userid)) == 0)
68 if ((base = extract_timestamp(base, &entry.
tm)) == 0)
72 if ((base = extract_field(base, &entry.
request)) == 0)
80 if ((base = extract_field(base, &entry.
object_size)) == 0)
84 if ((base = extract_field(base, &entry.
referer)) == 0)
88 if ((base = extract_field(base, &entry.
user_agent)) == 0)
100 while (isspace(*base))
104 if ((ptr = strchr(base,
'"')) == 0)
108 else if ((ptr = strchr(base,
' ')) != 0)
113 if (*base == 0 || !strcmp(base,
"-"))
125 memset(tmp, 0,
sizeof(tm));
127 while (isspace(*base))
132 if ((ptr = strchr(base,
']')) != 0)
135 if ((tmp->tm_mday = strtol(base, &end_ptr, 10)) == 0)
141 end_ptr = (
char *)base;
142 while (isalpha(*end_ptr))
144 if (*end_ptr !=
'/' || (end_ptr-base) != 3)
147 if (!strcasecmp(base,
"Jan"))
149 else if (!strcasecmp(base,
"Feb"))
151 else if (!strcasecmp(base,
"Mar"))
153 else if (!strcasecmp(base,
"Apr"))
155 else if (!strcasecmp(base,
"May"))
157 else if (!strcasecmp(base,
"Jun"))
159 else if (!strcasecmp(base,
"Jul"))
161 else if (!strcasecmp(base,
"Aug"))
163 else if (!strcasecmp(base,
"Sep"))
165 else if (!strcasecmp(base,
"Oct"))
167 else if (!strcasecmp(base,
"Nov"))
169 else if (!strcasecmp(base,
"Dec"))
175 if ((tmp->tm_year = strtol(base, &end_ptr, 10)) == 0)
179 tmp->tm_year -= 1900;
182 tmp->tm_hour = strtol(base, &end_ptr, 10);
187 tmp->tm_min = strtol(base, &end_ptr, 10);
192 tmp->tm_sec = strtol(base, &end_ptr, 10);
195 while (isspace(*base))
199 bool positive =
true;
203 else if (*base ==
'-')
211 offset += 360000 * (*base-
'0');
217 offset += 36000 * (*base-
'0');
223 offset += 600 * (*base-
'0');
229 offset += 60 * (*base-
'0');
235 #if !defined(__sun__)
236 tmp->tm_gmtoff = offset;
bool next(ApacheLogEntry &entry)
Compatibility Macros for C/C++.
char * extract_timestamp(char *base, struct tm *tmp)
char * extract_field(char *base, char **field_ptr)
void load(std::string filename)