From 174d2e3ae49ed3776449d3dade24cebee304bfb5 Mon Sep 17 00:00:00 2001 From: John Denker Date: Thu, 22 Nov 2012 15:34:11 -0800 Subject: move argParser to utils.h --- tools/ltgrey.c | 84 ++++++++++++++++++++++------------------------------------ 1 file changed, 31 insertions(+), 53 deletions(-) (limited to 'tools/ltgrey.c') diff --git a/tools/ltgrey.c b/tools/ltgrey.c index 577cbe9..85604e5 100644 --- a/tools/ltgrey.c +++ b/tools/ltgrey.c @@ -2,8 +2,8 @@ #include /* for exit(), atoi() */ #include "libltgrey.h" -#include "utils.h" #include "qq_exit_codes.h" +#include "utils.h" #include using namespace std; @@ -12,45 +12,6 @@ string progname; #define exeunt exit -typedef const char cc; -typedef cc* str; - -class argParser{ -public: - list argv; - string current_arg; - - argParser(const int _argc, const str _argv[]) - { - for (int ii=0; ii < _argc; ii++) { - argv.push_back(_argv[ii]); - } - } - string shift() { - string rslt = argv.front(); - argv.pop_front(); - return rslt; - } - void next(){ - current_arg = shift(); - } - size_t size() const { - return argv.size(); - } - int prefix(const string longer, const size_t required = 0){ - if (argv.size() < required) { - if (required==1) - cerr << "Option '" << current_arg - << "' requires an argument." << endl; - else - cerr << "Option '" << current_arg - << "' requires " << required << " arguments." << endl; - exeunt(ex_syserr); - } - return current_arg == longer.substr(0, current_arg.length()); - } -}; - void usage(const string parent_dir){ cout << "Usage: ltgrey [options]\n" @@ -58,10 +19,10 @@ void usage(const string parent_dir){ "Options include\n" " -scan40 # scan the quarantine directory\n" " -scanrep # scan the reputation directory\n" -" -copy # no idea\n" +" -copy # increment the 'copies' variable\n" " -verbose # increase the verbosity\n" -" -setrep mid # set the reputation for the given message-id\n" -" -getrep mid # look up the reputation\n" +" -setrep dom # set the reputation for the given domain\n" +" -getrep dom # look up the reputation for the given domain\n" " -shift ??? # no idea\n" " -stain ??? # not implemented\n" " -suffix ??? # no idea\n" @@ -72,6 +33,20 @@ void usage(const string parent_dir){ cout << "parent dir is " << parent_dir << endl; cout << "box_40.dir is " << box_40.dir << endl; cout << "box_rep.dir is " << box_rep.dir << endl; + + cout << +"\n" +"Principles of operation:\n" +"\n" +"1) Quarantine applies to a particular message. Messages\n" +" are identified by their MID i.e. message-ID.\n" +"\n" +"2a) Ideally, reputation applies to a sending-domain.\n" +"\n" +"2b) If we can't identify a domain that will take responsibility\n" +" for sending the message, then reputation applies to the host.\n" +; + return; } int main(int _argc, char** _argv){ @@ -100,11 +75,11 @@ int main(int _argc, char** _argv){ int dns_mode(0); string get_40_mid; string set_40_mid; - string get_rep_mid; - string set_rep_mid; + string get_rep_domain; + string set_rep_domain; argParser ARGS(argc, argv); - while (ARGS.size()) { + try {while (ARGS.size()) { ARGS.next(); if (0){ } else if (ARGS.prefix("-help")) { @@ -125,9 +100,9 @@ int main(int _argc, char** _argv){ } else if (ARGS.prefix("-set40", 1)) { set_40_mid = ARGS.shift(); } else if (ARGS.prefix("-setrep", 1)) { - set_rep_mid = ARGS.shift(); + set_rep_domain = ARGS.shift(); } else if (ARGS.prefix("-getrep", 1)) { - get_rep_mid = ARGS.shift(); + get_rep_domain = ARGS.shift(); } else if (ARGS.prefix("-shift"), 1) { shift = atoi(*argv++); argc--; } else if (ARGS.prefix("-stain", 1)) { @@ -137,8 +112,11 @@ int main(int _argc, char** _argv){ foo.suffix += ARGS.shift(); } else { cerr << "Unrecognized arg: " << ARGS.current_arg << endl; - exeunt(ex_syserr); + throw int(1); } + }} + catch (int){ + exeunt(ex_syserr); } // dns_mode mode ... @@ -160,14 +138,14 @@ int main(int _argc, char** _argv){ return foo.set_40(set_40_mid, shift); } - if (get_rep_mid.length()){ - box_state rslt = foo.get_rep(get_rep_mid); + if (get_rep_domain.length()){ + box_state rslt = foo.get_rep(get_rep_domain); cerr << foo.decode_40[rslt] << endl; return 0; } - if (set_rep_mid.length()){ - return foo.set_rep(set_rep_mid, shift); + if (set_rep_domain.length()){ + return foo.set_rep(set_rep_domain, shift); } if (scan40mode) { -- cgit v1.2.3