From 67eb4c6c804c728db329a7f4a77d5a3cbd1b993c Mon Sep 17 00:00:00 2001 From: John Denker Date: Sun, 29 Jul 2012 21:55:41 -0700 Subject: get40 seems to be working --- tools/libltgrey.c | 27 ++++++++++++++++++++++++-- tools/libltgrey.h | 20 ++++++++++++++++--- tools/ltgrey.c | 58 ++++++++++++++++++++++++++++++------------------------- 3 files changed, 74 insertions(+), 31 deletions(-) (limited to 'tools') diff --git a/tools/libltgrey.c b/tools/libltgrey.c index 1bf7e9f..38657e3 100644 --- a/tools/libltgrey.c +++ b/tools/libltgrey.c @@ -76,10 +76,12 @@ void exeunt(const int sts){ // constructor whatsit::whatsit(const std::string name, const std::string _parent_dir) : parent_dir(_parent_dir), progname(name), mypid(getpid()), - mod_age(0), ac_age(0), verbosity(0) { - gettimeofday(&now, NULL); +// expand the codes to make some names: +# define foo(name) decode_40[name] = #name; + state_40_macro +# undef foo } void whatsit::dump(const string var){ @@ -399,3 +401,24 @@ int whatsit::check_dns_sub(const char* ipvar, const char* namevar, done: return 0; } + +state_40 whatsit::get40(const string mid){ + string fname = parent_dir + "/quarante/mid_" + mid; + cerr << ".... " << fname << endl; + struct stat mid_stat; + int rslt = stat(fname.c_str(), &mid_stat); + if (rslt != 0) { + if (errno == ENOENT) return unseen; + cerr << progid << " stat: unexpected failure for '" + << fname << "' : "; + perror(0); + return fail; + } + timeval now; + gettimeofday(&now, NULL); + int mod_age = now.tv_sec - mid_stat.st_mtime; +// int ac_age = now.tv_sec - mid_stat.st_atime; + if (mod_age < minimum_age) return young; + if (mod_age < probation) return ripe; + return spoiled; +} diff --git a/tools/libltgrey.h b/tools/libltgrey.h index 6f516b4..1724d53 100644 --- a/tools/libltgrey.h +++ b/tools/libltgrey.h @@ -1,18 +1,31 @@ #include #include /* for gettimeofday(), timeval */ #include +#include + +#define state_40_macro \ +foo(unseen) \ +foo(young) \ +foo(ripe) \ +foo(spoiled) \ +foo(fail) + +// expand the codes to make some names: +#define foo(name) name, +typedef enum { + state_40_macro +} state_40; +#undef foo class whatsit{ public: std::string parent_dir; std::string progname; pid_t mypid; - timeval now; - int mod_age; - int ac_age; std::string suffix; std::string progid; int verbosity; + std::map decode_40; whatsit(const std::string name, const std::string _parent_dir); int doit(const int penalty, const int stain); @@ -26,4 +39,5 @@ public: std::vector &checked); void dump(const std::string var); int maybe_mkdir(const std::string somedir, const std::string msg); + state_40 get40(const std::string mid); }; diff --git a/tools/ltgrey.c b/tools/ltgrey.c index c9f384f..7a63b04 100644 --- a/tools/ltgrey.c +++ b/tools/ltgrey.c @@ -16,10 +16,7 @@ void scan(const string progid, const string p, const int copies=1); int main(int _argc, char** _argv){ - char* namevar; std::string hostname; - char* ipvar; - std::string ipbase; std::string ipname; mypid = getpid(); @@ -29,27 +26,35 @@ int main(int _argc, char** _argv){ whatsit foo(argv[0], parent_dir); argc--; argv++; int scanmode(0); int copies(1); - int penalty(0); + int shift(0); int stain(0); - int dnscheck(0); + int dns_mode(0); + string get40_mid; while (argc > 0) { string arg = argv[0]; argc--; argv++; if (prefix(arg, "-scan")) { scanmode++; - } else if (prefix(arg, "-copy")) { + } else if (prefix(arg, "-copy")) { copies++; - } else if (prefix(arg, "-verbose")) { + } else if (prefix(arg, "-verbose")) { foo.verbosity++; - } else if (prefix(arg, "-dnscheck")) { - dnscheck++; - } else if (prefix(arg, "-penalize") - || prefix(arg, "-penalty")) { + } else if (prefix(arg, "-dns_mode")) { + dns_mode++; + } else if (prefix(arg, "-get40")) { if (!argc){ cerr << "Option '" << arg << "' requires an argument" << endl; exeunt(ex_syserr); } - penalty = atoi(*argv++); argc--; - } else if (prefix(arg, "-stain")) { + get40_mid = *argv++; argc--; + + } else if (prefix(arg, "-shift") + || prefix(arg, "-shift")) { + if (!argc){ + cerr << "Option '" << arg << "' requires an argument" << endl; + exeunt(ex_syserr); + } + shift = atoi(*argv++); argc--; + } else if (prefix(arg, "-stain")) { if (!argc){ cerr << "Option '" << arg << "' requires an argument" << endl; exeunt(ex_syserr); @@ -68,27 +73,28 @@ int main(int _argc, char** _argv){ } if (foo.setup()) return ex_syserr; -// dnscheck mode ... -// Probably a better design would be to -// (a) make more thorough DNS checks, and -// (b) move all the DNS checking to a separate module - - ipvar = getenv("TCPREMOTEIP"); - if (ipvar) ipbase = ipvar; - namevar = getenv("TCPREMOTEHOST"); - if (namevar) hostname = namevar; - - if (dnscheck) { +// dns_mode mode ... +// Probably it would be better to make more thorough DNS checks. +// + if (dns_mode) { + char* ipvar = getenv("TCPREMOTEIP"); + char* namevar = getenv("TCPREMOTEHOST"); exeunt(foo.check_dns(ipvar, namevar)); } + if (get40_mid.length()){ + state_40 rslt = foo.get40(get40_mid); + cerr << foo.decode_40[rslt] << endl; + return 0; + } + if (scanmode) { string dirname = parent_dir + "/quarante"; scan(foo.progid, dirname, copies); return 0; } - int sts = foo.doit(penalty, stain); + int sts = foo.doit(shift, stain); return sts; } @@ -116,7 +122,7 @@ void scan(const string progid, const string p, const int copies){ gettimeofday(&now, NULL); using namespace boost::filesystem; - if (is_directory(p)) { + if (is_directory(p)) { for (directory_iterator itr(p); itr!=directory_iterator(); ++itr) { string basename = itr->path().filename(); for (int ii = 0; ii < copies; ii++) -- cgit v1.2.3