From d2564d25e802d1ee3230cf045c4940e836b5c6a2 Mon Sep 17 00:00:00 2001 From: John Denker Date: Sun, 29 Jul 2012 16:50:11 -0700 Subject: split ltgrey (and libltgrey) off from greylist; put some utility functions into their own file. --- tools/libltgrey.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tools/libltgrey.h (limited to 'tools/libltgrey.h') diff --git a/tools/libltgrey.h b/tools/libltgrey.h new file mode 100644 index 0000000..585ec01 --- /dev/null +++ b/tools/libltgrey.h @@ -0,0 +1,38 @@ +#include +#include /* for gettimeofday(), timeval */ +#include + +class whatsit{ +public: + std::string dirname; + std::string progname; + pid_t mypid; + timeval now; + char* ipvar; + char* hostvar; + std::string ipbase; + std::string ipname; + std::string hostname; + int mod_age; + int ac_age; + std::string suffix; + std::string progid; + int verbosity; + + whatsit(const std::string name, const std::string _dirname) + : dirname(_dirname), progname(name), mypid(getpid()), + mod_age(0), ac_age(0), + verbosity(0) + { + gettimeofday(&now, NULL); + } + int doit(const int penalty, const int stain); +// access comes after modification: + void update(const std::string msg, const timeval new_mod, + const timeval new_ac, const int penalty, const int stain); + int setup(); + int check_dns(); + int check_dns_sub(std::string &addr, std::string &host, + std::vector &checked); + void dump(const std::string var); +}; -- cgit v1.2.3 From 292a76b35fd16cf11613f79ea38693449e3317f6 Mon Sep 17 00:00:00 2001 From: John Denker Date: Sun, 29 Jul 2012 21:07:01 -0700 Subject: separate dnscheck functionality from other features; clean up a little --- tools/libltgrey.h | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) (limited to 'tools/libltgrey.h') diff --git a/tools/libltgrey.h b/tools/libltgrey.h index 585ec01..6f516b4 100644 --- a/tools/libltgrey.h +++ b/tools/libltgrey.h @@ -4,35 +4,26 @@ class whatsit{ public: - std::string dirname; + std::string parent_dir; std::string progname; pid_t mypid; timeval now; - char* ipvar; - char* hostvar; - std::string ipbase; - std::string ipname; - std::string hostname; int mod_age; int ac_age; std::string suffix; std::string progid; int verbosity; - whatsit(const std::string name, const std::string _dirname) - : dirname(_dirname), progname(name), mypid(getpid()), - mod_age(0), ac_age(0), - verbosity(0) - { - gettimeofday(&now, NULL); - } + whatsit(const std::string name, const std::string _parent_dir); int doit(const int penalty, const int stain); // access comes after modification: void update(const std::string msg, const timeval new_mod, const timeval new_ac, const int penalty, const int stain); int setup(); - int check_dns(); - int check_dns_sub(std::string &addr, std::string &host, - std::vector &checked); + int check_dns(const char* ipvar, const char* namevar); + int check_dns_sub(const char* ipvar, const char* namevar, + std::string &addr, std::string &host, + std::vector &checked); void dump(const std::string var); + int maybe_mkdir(const std::string somedir, const std::string msg); }; -- cgit v1.2.3 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.h | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'tools/libltgrey.h') 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); }; -- cgit v1.2.3 From 2f6fd23b841c1f4e3c18d1cbfd228784aa8c3298 Mon Sep 17 00:00:00 2001 From: John Denker Date: Sun, 29 Jul 2012 22:31:03 -0700 Subject: set40 appears to be working --- tools/libltgrey.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tools/libltgrey.h') diff --git a/tools/libltgrey.h b/tools/libltgrey.h index 1724d53..cf744d1 100644 --- a/tools/libltgrey.h +++ b/tools/libltgrey.h @@ -5,7 +5,7 @@ #define state_40_macro \ foo(unseen) \ -foo(young) \ +foo(green) \ foo(ripe) \ foo(spoiled) \ foo(fail) @@ -40,4 +40,5 @@ public: void dump(const std::string var); int maybe_mkdir(const std::string somedir, const std::string msg); state_40 get40(const std::string mid); + int set40(const std::string mid, const int shift); }; -- cgit v1.2.3 From f8be4baf5a2318363b42f8883f66ed8a976dfc79 Mon Sep 17 00:00:00 2001 From: John Denker Date: Sun, 29 Jul 2012 23:26:28 -0700 Subject: scan40 appears to be working, much cleaner than last week's version --- tools/libltgrey.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'tools/libltgrey.h') diff --git a/tools/libltgrey.h b/tools/libltgrey.h index cf744d1..14ed144 100644 --- a/tools/libltgrey.h +++ b/tools/libltgrey.h @@ -3,6 +3,11 @@ #include #include +// beware: access illogically comes *before* modification +// in the array passed to utimes: +const int upd_ac(0); +const int upd_mod(1); + #define state_40_macro \ foo(unseen) \ foo(green) \ @@ -40,5 +45,7 @@ public: void dump(const std::string var); int maybe_mkdir(const std::string somedir, const std::string msg); state_40 get40(const std::string mid); + state_40 get40(const std::string mid, timeval times[2]); int set40(const std::string mid, const int shift); + void scan40(const int copies); }; -- cgit v1.2.3