diff options
author | John Denker <jsd@av8n.com> | 2012-06-02 09:37:57 -0700 |
---|---|---|
committer | John Denker <jsd@av8n.com> | 2012-06-02 17:30:23 -0700 |
commit | 3388dd0ad6eb81972cb9ee6043b1c7e2ef337dc0 (patch) | |
tree | 59b75bbfc6ec1ff5e8bddb98cf5f79a683b763e9 /tools | |
parent | 32e75879103a943ac682cbde7b37ea4e4fbc24ab (diff) |
hi-q can how parse a configuration file
Diffstat (limited to 'tools')
-rw-r--r-- | tools/filters.conf | 3 | ||||
-rw-r--r-- | tools/hi-q.c | 44 |
2 files changed, 44 insertions, 3 deletions
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 <sys/wait.h> using namespace std; +#include <iostream> +#include <fstream> +#include <sstream> #include <string> #include <vector> @@ -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<vector<string> > filters; + typedef vector<string> VS; + vector<VS> 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<string> 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<VS>::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 |