- //////////////////////////////////////////////////////////////////////
- // IP traffic analyzer - configuration file
- // Written by Jonathan A. Foster <jon@jfpossibilities.com>
- // Started May 14th, 2021
- // Copyright JF Possibilities, Inc. All rights reserved.
- //////////////////////////////////////////////////////////////////////
- #include <fstream>
- #include <iostream>
- #include "config.h"
- #include "strutil.h"
-
-
-
- void Config::load(const std::string &fname) {
- std::string l;
- std::ifstream f(fname.c_str());
- TSV tsv;
- Conn conn;
- int ln=0;
-
-
- while(std::getline(f, l)) {
- ln++;
- l = strip(l);
- if(l=="" || l[0]=='#') continue;
- if(l.size()>2 && l[0]=='[' && l.end()[-1]==']') {
-
- heading:
- if(l=="[us]") {
-
- /// Read in "us" list ///
-
- while(std::getline(f, l)) {
- ln++;
- l=strip(l);
- if(l=="" || l[0]=='#') continue;
- if(l.size()>2 && l[0]=='[' && l.end()[-1]==']') goto heading;
- us.push_back(l);
- }
-
- } else if(l=="[ignores]") {
-
- /// Read in ignore list ///
-
- while(std::getline(f, l)) {
- ln++;
- if(l=="" || l[0]=='#') continue;
- if(l.size()>2 && l[0]=='[' && l.end()[-1]==']') goto heading;
- tsv = l;
- if(tsv.count!=7) {
- std::cerr << "Incorrrect column count in config file line " << ln << std::endl;
- continue;
- }
- if(tsv.count>6) {
- tsv >> conn;
- ignores.push_back(conn);
- }
- }
- }
-
- }
- }
- }
|