summaryrefslogtreecommitdiff
path: root/tools/skrewt.c
diff options
context:
space:
mode:
authorJohn Denker <jsd@av8n.com>2012-07-15 06:13:38 (GMT)
committerJohn Denker <jsd@av8n.com>2012-07-15 06:13:38 (GMT)
commitfb6042c5cd8a411cfcfcf6c1a1d466eb42a4ff33 (patch)
tree1d283838beb0f1b3d9138db4d8cd9950c0df20a6 /tools/skrewt.c
parente53f6eb20d90fd96e43dc2f52249856485522a61 (diff)
working toward a process-group signalling system
Diffstat (limited to 'tools/skrewt.c')
-rw-r--r--tools/skrewt.c58
1 files changed, 47 insertions, 11 deletions
diff --git a/tools/skrewt.c b/tools/skrewt.c
index 8ae4db4..b81f0ea 100644
--- a/tools/skrewt.c
+++ b/tools/skrewt.c
@@ -21,7 +21,8 @@ void usage(const int sts){
"\n"
" Typically used as a filter in a pipeline, along with spamc -E\n"
" Options\n"
-" -h print this msg (and exit immediately).\n"
+" -help print this msg (and exit immediately).\n"
+" -maxsize ii msg size in bytes; anything bigger will be rejected.\n"
"\n"
" Messages containing the string '-please-bounce-this-' will be rejected.\n"
" Messages with no date will be rejected.\n"
@@ -82,17 +83,53 @@ string toLower(const std::string& a){
return rslt;
}
-
+////////////////
string ltrim(string foo){
size_t where = foo.find_first_not_of(" \t\r\n");
if (where == foo.npos) return foo;
return foo.substr(where);
}
-int main(int argc, char** argv){
- if (argc > 1) {
- if (argv[1] == string("-h")) usage(0);
- usage(1);
+////////////////
+// little utility to help with argument parsing:
+//
+int prefix(const string shorter, const string longer){
+ return shorter == longer.substr(0, shorter.length());
+}
+
+////////////////////////////////////////////////////////////
+int main(int _argc, const char** _argv){
+//// pid_t pid = getpid();
+//// cout << pid << endl;
+//// cout << getpgid(pid) << endl;
+ int argc(_argc);
+ const char **argv(_argv);
+ string progname(*argv); argv++; argc--;
+
+ int maxsize(1000000);
+
+ while (argc) {
+ string arg(*argv); argv++; argc--;
+ if (arg.substr(0,2) == "--") arg = arg.substr(1);
+ if (prefix(arg, "-help")) {
+ usage(0);
+ }
+ if (prefix(arg, "-maxsize")) {
+ if (!argc) {
+ cerr << "Option -maxsize requires an argument" << endl;
+ exit(1);
+ }
+ maxsize = atoi(*argv); argv++; argc--;
+ }
+ if (arg.substr(0,1) == "-") {
+ cerr << "Unrecognized option '" << arg << "'" << endl;
+ cerr << "For help, try: " << progname << " -help" << endl;
+ exit(1);
+ } else {
+ cerr << "Extraneous verbiage '" << arg << "'" << endl;
+ cerr << "For help, try: " << progname << " -help" << endl;
+ exit(1);
+ }
}
int inheads(1);
@@ -101,7 +138,6 @@ int main(int argc, char** argv){
int textlines(0);
int gotdate(0);
int msgsize(0);
- int msgmax(1000000);
for (;;){
if (cin.eof()) break;
if (cin.bad()) return 1;
@@ -119,8 +155,8 @@ int main(int argc, char** argv){
string line;
if (getline(cin, line).fail()) continue;
msgsize += line.length()+1;
- if (msgsize > msgmax) {
- cerr << "skrewt rejection: bigger than " << msgmax << endl;
+ if (msgsize > maxsize) {
+ cerr << "skrewt rejection: bigger than " << maxsize << endl;
exit(1);
}
header += "\n" + line;
@@ -185,8 +221,8 @@ int main(int argc, char** argv){
string line;
if (!getline(cin, line).fail()) {
msgsize += line.length()+1;
- if (msgsize > msgmax) {
- cerr << "skrewt rejection: bigger than " << msgmax << endl;
+ if (msgsize > maxsize) {
+ cerr << "skrewt rejection: bigger than " << maxsize << endl;
exit(1);
}
if (line == "--" + boundary) {