summaryrefslogtreecommitdiff
path: root/tools/hi-q.c
diff options
context:
space:
mode:
authorJohn Denker <jsd@av8n.com>2012-06-02 16:37:57 (GMT)
committerJohn Denker <jsd@av8n.com>2012-06-03 00:30:23 (GMT)
commit3388dd0ad6eb81972cb9ee6043b1c7e2ef337dc0 (patch)
tree59b75bbfc6ec1ff5e8bddb98cf5f79a683b763e9 /tools/hi-q.c
parent32e75879103a943ac682cbde7b37ea4e4fbc24ab (diff)
hi-q can how parse a configuration file
Diffstat (limited to 'tools/hi-q.c')
-rw-r--r--tools/hi-q.c44
1 files changed, 41 insertions, 3 deletions
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