From 3388dd0ad6eb81972cb9ee6043b1c7e2ef337dc0 Mon Sep 17 00:00:00 2001 From: John Denker Date: Sat, 2 Jun 2012 09:37:57 -0700 Subject: hi-q can how parse a configuration file --- tools/filters.conf | 3 +++ tools/hi-q.c | 44 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 tools/filters.conf diff --git a/tools/filters.conf b/tools/filters.conf new file mode 100644 index 0000000..d255445 --- /dev/null +++ b/tools/filters.conf @@ -0,0 +1,3 @@ +# configuration file for hi-q + /usr/local/bin/spamc -Z 7 + /var/qmail/bin/qmail-queue diff --git a/tools/hi-q.c b/tools/hi-q.c index 31ec77b..0f7e444 100644 --- a/tools/hi-q.c +++ b/tools/hi-q.c @@ -15,6 +15,9 @@ #include using namespace std; +#include +#include +#include #include #include @@ -105,6 +108,7 @@ int Execve(char const * fn, // and control coming in on fd 1. int main(int argc, char** argv, char const * const * env) { + int verbose(1); int kidstatus; pid_t somekid; @@ -120,8 +124,6 @@ int main(int argc, char** argv, char const * const * env) { char* spamc_args[] = {"/usr/local/bin/spamc", "-Z", "7", 0}; char* qq_args[] = {"/var/qmail/bin/qmail-queue", 0}; - const char* spamc_args[] = {"/usr/local/bin/spamc", "-Z", "7", 0}; - const char* qq_args[] = {"/var/qmail/bin/qmail-queue", 0}; const char** joblist[] = { @@ -140,7 +142,43 @@ int main(int argc, char** argv, char const * const * env) { 0 // required: zero terminates the list }; - vector > filters; + typedef vector VS; + vector filters; + if (argc != 2) { + cerr << "Usage: hi-q filter.conf" << endl; + exit(1); + } + + char* conf_name = argv[1]; + ifstream conf; + conf.open(conf_name); + if (! conf.good()) { + cerr << "hi-q: could not open filter.conf file '" + << conf_name << "'" << endl; + exit(1); + } + for (;;) { + string line; + if (!getline(conf, line).good()) break; + istringstream parse(line); + vector job; + while (parse.good()){ + string token; + parse >> token; + if (parse.fail()) break; + if (token[0] == '#') break; + job.push_back(token); + } + if (job.size()) filters.push_back(job); + } + if (verbose) for (vector::const_iterator job = filters.begin(); + job != filters.end(); job++) { + for (VS::const_iterator token = job->begin(); + token != job->end(); token++){ + cerr << *token << " "; + } + cerr << endl; + } int nkids; pid_t* kidpid; // indexed by kid number -- cgit v1.2.3