--- uloganalyzer/uloganalyzer.cpp 2008/12/01 11:48:31 116 +++ uloganalyzer/uloganalyzer.cpp 2008/12/02 18:16:42 124 @@ -60,9 +60,16 @@ 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] << " "; + cout << words[0] << " "; //month + cout << setw(2) << words[1] << " " ; //day min width 2 + cout << words[2] << " "; //timestamp for (unsigned i=3; i" << 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,28 +107,39 @@ 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); } - while (!in.eof()) { - char buffer[1024]; - in.getline(buffer,1024); + char buffer[1024]; + + while (!in->eof()) { + in->getline(buffer,1024); if (buffer[0] == 0) continue; //empty line analyseLine(buffer); } if (lookup) { + GeoIP_delete(gi); } return 0;