summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Denker <jsd@av8n.com>2012-07-31 07:52:41 -0700
committerJohn Denker <jsd@av8n.com>2012-07-31 08:13:41 -0700
commit53d40691f0285c781a3ca8ab394e29c6baf90c98 (patch)
tree20ef853766d4cc3b1a278d0d2f73852045ccf5a4
parent64b9aec12be7080c3b81e505044b139d56bb07c4 (diff)
basically working: two directories
-rw-r--r--tools/libltgrey.c29
-rw-r--r--tools/libltgrey.h11
-rw-r--r--tools/ltgrey.c53
3 files changed, 64 insertions, 29 deletions
diff --git a/tools/libltgrey.c b/tools/libltgrey.c
index 5b480ac..7104c69 100644
--- a/tools/libltgrey.c
+++ b/tools/libltgrey.c
@@ -396,14 +396,14 @@ box_state whatsit::get_rep(const string mid){
return get_box(box_rep, mid, junk);
}
-box_state whatsit::get_box(const boxer box,
+box_state whatsit::get_box(const boxer mybox,
const string mid, timeval times[2]){
timeval now;
gettimeofday(&now, NULL);
times[0] = times[1] = now; // in case of early return
- string fname = parent_dir + "/" + box.dir
- + "/mid_" + purify(mid);
- //xxx cerr << ".... " << fname << endl;
+ string fname = parent_dir + "/" + mybox.dir
+ + "/" + mybox.prefix + purify(mid);
+ //xxx cerr << "get_box .... " << fname << endl;
struct stat mid_stat;
int rslt = stat(fname.c_str(), &mid_stat);
if (rslt != 0) {
@@ -419,8 +419,8 @@ box_state whatsit::get_box(const boxer box,
times[upd_mod].tv_usec = 0;
int mod_age = now.tv_sec - mid_stat.st_mtime;
// int ac_age = now.tv_sec - mid_stat.st_atime;
- if (mod_age < box.min) return green;
- if (mod_age < box.max) return ripe;
+ if (mod_age < mybox.min) return green;
+ if (mod_age < mybox.max) return ripe;
return spoiled;
}
@@ -428,6 +428,10 @@ int whatsit::set_40(const string mid, const int shift){
return set_box(box_40, mid, shift);
}
+int whatsit::set_rep(const string mid, const int shift){
+ return set_box(box_rep, mid, shift);
+}
+
int whatsit::set_box(const boxer box, const string mid, const int shift){
string fname = parent_dir + "/" + box.dir
+ "/mid_" + purify(mid);
@@ -467,25 +471,24 @@ int whatsit::set_box(const boxer box, const string mid, const int shift){
return 0;
}
-void whatsit::scan_box(const boxer box, const int copies){
+void whatsit::scan_box(const boxer mybox, const int copies){
timeval now;
gettimeofday(&now, NULL);
using namespace boost::filesystem;
- string mydir = parent_dir + "/" + box.dir;
+ string mydir = parent_dir + "/" + mybox.dir;
if (is_directory(mydir)) {
for (directory_iterator itr(mydir); itr!=directory_iterator(); ++itr) {
string basename = itr->path().filename();
if (is_regular_file(itr->status())) {
- string tag("mid_");
- if (prefix(tag, basename)) {
+ if (prefix(mybox.prefix, basename)) {
for (int ii = 0; ii < copies; ii++)
cout << setw(20) << left << basename; // display filename only
timeval times[2];
- box_state rslt = get_box(box_40,
- basename.substr(tag.length()), times);
+ box_state rslt = get_box(mybox,
+ basename.substr(mybox.prefix.length()), times);
int mod_age = now.tv_sec - times[upd_mod].tv_sec;
int ac_age = now.tv_sec - times[upd_ac ].tv_sec;
cout << setw(10) << right << time_out(mod_age)
@@ -493,7 +496,7 @@ void whatsit::scan_box(const boxer box, const int copies){
cout << " " << decode_40[rslt];
cout << endl;
} else {
- /* filename does not begin with tag "mid_" */
+ /* filename does not begin with mybox.prefix */
}
}
}
diff --git a/tools/libltgrey.h b/tools/libltgrey.h
index 9891256..6447297 100644
--- a/tools/libltgrey.h
+++ b/tools/libltgrey.h
@@ -20,10 +20,12 @@ typedef enum {
class boxer{
public:
std::string dir;
+ std::string prefix;
int min;
int max;
- boxer(const std::string _dir, const int _min, const int _max)
- : dir(_dir), min(_min), max(_max)
+ boxer(const std::string _dir, const std::string _prefix,
+ const int _min, const int _max)
+ : dir(_dir), prefix(_prefix), min(_min), max(_max)
{}
};
@@ -57,6 +59,7 @@ public:
box_state get_40(const std::string mid);
int set_40(const std::string mid, const int shift);
box_state get_rep(const std::string mid);
+ int set_rep(const std::string mid, const int shift);
};
// beware: access illogically comes *before* modification
@@ -68,5 +71,5 @@ const int minute(60);
const int hour(60*minute);
const int day(24*hour);
-const boxer box_40 ("quarante", 15*minute, 4*hour);
-const boxer box_rep("repute", 0, 35*day);
+const boxer box_40 ("quarante", "mid_", 15*minute, 4*hour);
+const boxer box_rep("repute", "dom_", 0, 35*day);
diff --git a/tools/ltgrey.c b/tools/ltgrey.c
index b707dc2..26d0f64 100644
--- a/tools/ltgrey.c
+++ b/tools/ltgrey.c
@@ -11,10 +11,6 @@ string progname;
#define exeunt exit
-// forward reference:
-void scan(const string progid, const string p, const int copies=1);
-
-
int main(int _argc, char** _argv){
std::string hostname;
std::string ipname;
@@ -24,17 +20,23 @@ int main(int _argc, char** _argv){
char** argv(_argv);
const string parent_dir("/var/qmail/ltgrey");
whatsit foo(argv[0], parent_dir); argc--; argv++;
- int scanmode(0);
+ int scan40mode(0);
+ int scanrepmode(0);
int copies(1);
int shift(0);
int stain(0);
int dns_mode(0);
string get_40_mid;
- string set40_mid;
+ string set_40_mid;
+ string get_rep_mid;
+ string set_rep_mid;
while (argc > 0) {
string arg = argv[0]; argc--; argv++;
- if (prefix(arg, "-scan40")) {
- scanmode++;
+ if (0){
+ } else if (prefix(arg, "-scan40")) {
+ scan40mode++;
+ } else if (prefix(arg, "-scanrep")) {
+ scanrepmode++;
} else if (prefix(arg, "-copy")) {
copies++;
} else if (prefix(arg, "-verbose")) {
@@ -52,7 +54,19 @@ int main(int _argc, char** _argv){
cerr << "Option '" << arg << "' requires an argument" << endl;
exeunt(ex_syserr);
}
- set40_mid = *argv++; argc--;
+ set_40_mid = *argv++; argc--;
+ } else if (prefix(arg, "-setrep")) {
+ if (!argc){
+ cerr << "Option '" << arg << "' requires an argument" << endl;
+ exeunt(ex_syserr);
+ }
+ set_rep_mid = *argv++; argc--;
+ } else if (prefix(arg, "-getrep")) {
+ if (!argc){
+ cerr << "Option '" << arg << "' requires an argument" << endl;
+ exeunt(ex_syserr);
+ }
+ get_rep_mid = *argv++; argc--;
} else if (prefix(arg, "-shift")
|| prefix(arg, "-shift")) {
if (!argc){
@@ -94,15 +108,30 @@ int main(int _argc, char** _argv){
return 0;
}
- if (set40_mid.length()){
- return foo.set_40(set40_mid, shift);
+ if (set_40_mid.length()){
+ return foo.set_40(set_40_mid, shift);
}
- if (scanmode) {
+ if (get_rep_mid.length()){
+ box_state rslt = foo.get_rep(get_rep_mid);
+ cerr << foo.decode_40[rslt] << endl;
+ return 0;
+ }
+
+ if (set_rep_mid.length()){
+ return foo.set_rep(set_rep_mid, shift);
+ }
+
+ if (scan40mode) {
foo.scan_box(box_40, copies);
return 0;
}
+ if (scanrepmode) {
+ foo.scan_box(box_rep, copies);
+ return 0;
+ }
+
int sts = foo.doit(shift, stain);
return sts;