--- uloganalyzer/uloganalyzer.cpp 2008/12/01 22:23:02 122 +++ uloganalyzer/uloganalyzer.cpp 2008/12/02 18:08:19 123 @@ -60,6 +60,11 @@ void analyseLine(string line) { vector words = getTokens(line); + + if (words.size() < 7) { + cout << "Illegal line format " << line << endl; + return; + } //print date and time cout << words[0] << " " << words[1] << " " << words[2] << " "; @@ -73,7 +78,8 @@ void printUsage() { - cout << "Usage: analyser [-l] " << endl; + cout << "Usage: analyser [-l] |-" << endl; + cout << "Use '-' for reading logdata from std input" << endl; cout << "Options:" << endl; cout << " -l : geoip lookup on source IP adresses" << endl; } @@ -99,14 +105,23 @@ file = argv[1]; } + istream* in; + ifstream infile; - ifstream in(file.c_str()); + if ( file == "-") { + in = &cin; + } else { + infile.open(file.c_str()); - if (!in) { - cout << "Could not open " << file << endl; - return 1; + if (!infile) { + cout << "Could not open " << file << endl; + return 1; + } + + in = &infile; } + if (lookup){ gi = GeoIP_new(GEOIP_STANDARD); @@ -114,8 +129,8 @@ char buffer[1024]; - while (!in.eof()) { - in.getline(buffer,1024); + while (!in->eof()) { + in->getline(buffer,1024); if (buffer[0] == 0) continue; //empty line analyseLine(buffer);