/[projects]/uloganalyzer/uloganalyzer.cpp
ViewVC logotype

Diff of /uloganalyzer/uloganalyzer.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 122 by torben, Mon Dec 1 22:23:02 2008 UTC revision 123 by torben, Tue Dec 2 18:08:19 2008 UTC
# Line 60  void analyseWord(const string& word) { Line 60  void analyseWord(const string& word) {
60    
61  void analyseLine(string line) {  void analyseLine(string line) {
62          vector<string> words = getTokens(line);          vector<string> words = getTokens(line);
63            
64            if (words.size() < 7) {
65                    cout << "Illegal line format " << line << endl;
66                    return;
67            }
68    
69          //print date and time          //print date and time
70          cout << words[0] << " " << words[1] << " " << words[2] << " ";          cout << words[0] << " " << words[1] << " " << words[2] << " ";
# Line 73  void analyseLine(string line) { Line 78  void analyseLine(string line) {
78    
79    
80  void printUsage() {  void printUsage() {
81          cout << "Usage: analyser [-l] <logfile>" << endl;          cout << "Usage: analyser [-l] <logfile>|-" << endl;
82            cout << "Use '-' for reading logdata from std input" << endl;
83          cout << "Options:" << endl;          cout << "Options:" << endl;
84          cout << "  -l : geoip lookup on source IP adresses" << endl;          cout << "  -l : geoip lookup on source IP adresses" << endl;
85  }  }
# Line 99  int main(int argc, char** argv) Line 105  int main(int argc, char** argv)
105                  file = argv[1];                  file = argv[1];
106          }          }
107    
108            istream* in;
109            ifstream infile;
110    
111          ifstream in(file.c_str());          if ( file == "-") {
112                    in = &cin;
113            } else {
114                    infile.open(file.c_str());
115    
116          if (!in) {                  if (!infile) {
117                  cout << "Could not open " << file << endl;                          cout << "Could not open " << file << endl;
118                  return 1;                          return 1;
119                    }
120    
121                    in = &infile;
122          }          }
123    
124            
125    
126          if (lookup){          if (lookup){
127                  gi = GeoIP_new(GEOIP_STANDARD);                  gi = GeoIP_new(GEOIP_STANDARD);
# Line 114  int main(int argc, char** argv) Line 129  int main(int argc, char** argv)
129    
130          char buffer[1024];          char buffer[1024];
131    
132          while (!in.eof()) {          while (!in->eof()) {
133                  in.getline(buffer,1024);                  in->getline(buffer,1024);
134                  if (buffer[0] == 0)                  if (buffer[0] == 0)
135                          continue; //empty line                          continue; //empty line
136                  analyseLine(buffer);                  analyseLine(buffer);

Legend:
Removed from v.122  
changed lines
  Added in v.123

  ViewVC Help
Powered by ViewVC 1.1.20