bincimap

Log | Files | Refs | LICENSE

commit 326a519aa928f876dc237b136113a948c11aba1c
parent 9c64f0abe4b5dda8046d6a41c4c062d2624bed27
Author: andreaha <andreaha@b31fe1f4-c0d1-0310-8000-a34f4ae90293>
Date:   Sat, 21 Feb 2004 10:08:19 +0000

- Fixes to the prioritization of default args over command line options.


git-svn-id: file:///home/cwright/convert/bincimap/trunk@39 b31fe1f4-c0d1-0310-8000-a34f4ae90293

Diffstat:
Msrc/argparser.cc | 24++++++++++++++++++++++++
Msrc/argparser.h | 3+++
Msrc/session-initialize-bincimap-up.cc | 8+++++++-
Msrc/session-initialize-bincimapd.cc | 7+++++++
Msrc/session.cc | 109+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------
5 files changed, 123 insertions(+), 28 deletions(-)

diff --git a/src/argparser.cc b/src/argparser.cc @@ -32,6 +32,8 @@ * -------------------------------------------------------------------- */ #include "argparser.h" +#include "convert.h" + #include <string> #include <map> @@ -77,12 +79,14 @@ bool CommandLineArgs::parse(int argc, char *argv[]) } args[lastKey] = s; + passedArgs[lastKey] = true; lastKey = ""; lastIsBoolean = false; } else if (s[1] == '-') { if (lastKey != "") { if (lastIsBoolean) { args[lastKey] = "yes"; + passedArgs[lastKey] = true; lastKey = ""; lastIsBoolean = false; } else { @@ -129,12 +133,15 @@ bool CommandLineArgs::parse(int argc, char *argv[]) } args[arg] = val; + passedArgs[arg] = true; + lastKey = ""; lastIsBoolean = false; } else { if (lastKey != "") { if (lastIsBoolean) { args[lastKey] = "yes"; + passedArgs[lastKey] = true; lastKey = ""; lastIsBoolean = false; } else { @@ -182,6 +189,8 @@ bool CommandLineArgs::parse(int argc, char *argv[]) match = true; args[it->first] = "yes"; + passedArgs[it->first] = true; + lastKey = ""; lastIsBoolean = false; break; @@ -201,6 +210,7 @@ bool CommandLineArgs::parse(int argc, char *argv[]) if (lastKey != "") { if (lastIsBoolean) { args[lastKey] = "yes"; + passedArgs[lastKey] = true; } else { errString = "expected value of "; errString += lastKey; @@ -209,6 +219,7 @@ bool CommandLineArgs::parse(int argc, char *argv[]) } } + // assign default "no" values for arguments that were not passed. map<string, ArgOpts>::const_iterator it = reg.begin(); for (; it != reg.end(); ++it) { if (args.find(it->first) == args.end()) { @@ -226,6 +237,12 @@ bool CommandLineArgs::parse(int argc, char *argv[]) if (ac == -1) ac = argc; + map<string, string>::const_iterator it2 = args.begin(); + for (; it2 != args.end(); ++it2) { + string s = it2->first + " => " + it2->second; + write(666, s.c_str(), s.length()); + } + return true; } @@ -274,6 +291,13 @@ void CommandLineArgs::registerArg(const string &arg, const string &desc, } //---------------------------------------------------------------------- +bool CommandLineArgs::hasArg(const std::string &arg) const +{ + string tmp = arg; lowercase(tmp); + return passedArgs.find(tmp) != passedArgs.end(); +} + +//---------------------------------------------------------------------- string CommandLineArgs::usageString(void) const { string tmp = head; diff --git a/src/argparser.h b/src/argparser.h @@ -69,6 +69,8 @@ namespace Binc { bool boolean); void addRequired(const std::string &arg, const std::string &desc, bool boolean); + bool hasArg(const std::string &arg) const; + std::string usageString(void) const; void setTail(const std::string &str); @@ -80,6 +82,7 @@ namespace Binc { std::string errString; std::map<std::string, ArgOpts> reg; std::map<std::string, std::string> args; + std::map<std::string, bool> passedArgs; std::string tail; std::string head; int ac; diff --git a/src/session-initialize-bincimap-up.cc b/src/session-initialize-bincimap-up.cc @@ -113,9 +113,15 @@ bool Session::initialize(int argc, char *argv[]) // try to read global settings. Storage gconfig(configfile, Storage::ReadOnly); string section, key, value; - while (gconfig.get(&section, &key, &value)) + while (gconfig.get(&section, &key, &value)) { session.globalconfig[section][key] = value; + { + string tmp = section + "::" + key + "=" + value; + write(667, tmp.c_str(), tmp.length()); + } + } + if (!gconfig.eof()) { logger << "error reading Binc IMAP's config file " << configfile << ". Default values will be used instead: " diff --git a/src/session-initialize-bincimapd.cc b/src/session-initialize-bincimapd.cc @@ -170,6 +170,9 @@ bool Session::initialize(int argc, char *argv[]) while (lconfig.get(&section, &key, &value)) session.localconfig[section][key] = value; + write(669, session.globalconfig["Mailbox"]["path"].c_str(), + session.globalconfig["Mailbox"]["path"].length()); + string tmp; if ((tmp = session.localconfig["Mailbox"]["depot"]) != "") session.globalconfig["Mailbox"]["depot"] = tmp; @@ -222,6 +225,10 @@ bool Session::initialize(int argc, char *argv[]) brokerfactory.assign("UNSUBSCRIBE", new UnsubscribeOperator()); string path = session.globalconfig["Mailbox"]["path"]; + + write (668, path.c_str(), path.length()); + + if (path == "") path = "."; else if (chdir(path.c_str()) != 0) { mkdir(path.c_str(), 0777); diff --git a/src/session.cc b/src/session.cc @@ -213,33 +213,74 @@ bool Session::parseRequestLine(int argc, char * argv[]) command.version = args["version"] == "yes" ? true : false; command.ssl = args["ssl"] == "yes" ? true : false; command.configfile = args["conf"]; - globalconfig["Authentication"]["allow plain auth in non ssl"] = args["allow-plain"]; - globalconfig["Authentication"]["auth penalty"] = args["auth-penalty"]; - globalconfig["Authentication"]["disable starttls"] = args["disable-starttls"]; - - globalconfig["Log"]["type"] = args["logtype"]; - globalconfig["Log"]["environment ip variable"] = args["ip-variable"]; - - globalconfig["Mailbox"]["type"] = args["mailbox-type"]; - globalconfig["Mailbox"]["path"] = args["mailbox-path"]; - globalconfig["Mailbox"]["auto create inbox"] = args["create-inbox"]; - globalconfig["Mailbox"]["auto subscribe mailboxes"] = args["subscribe-mailboxes"]; - globalconfig["Mailbox"]["umask"] = args["umask"]; - - globalconfig["Security"]["jail path"] = args["jail-path"]; - globalconfig["Security"]["jail user"] = args["jail-user"]; - globalconfig["Security"]["jail group"] = args["jail-group"]; - - globalconfig["Session"]["idle timeout"] = args["idle-timeout"]; - globalconfig["Session"]["auth timeout"] = args["auth-timeout"]; - globalconfig["Session"]["transfer timeout"] = args["transfer-timeout"]; - globalconfig["Session"]["transfer buffer size"] = args["transfer-buffersize"]; - - globalconfig["SSL"]["pem file"] = args["pem-file"]; - globalconfig["SSL"]["ca path"] = args["ca-path"]; - globalconfig["SSL"]["ca file"] = args["ca-file"]; - globalconfig["SSL"]["cipher list"] = args["cipher-list"]; - globalconfig["SSL"]["verify peer"] = args["verify-peer"]; + + string tmp; + + if (args.hasArg("allow-plain")) + globalconfig["Authentication"]["allow plain auth in non ssl"] = args["allow-plain"]; + + if (args.hasArg("auth-penalty")) + globalconfig["Authentication"]["auth penalty"] = args["auth-penalty"]; + + if (args.hasArg("disable-starttls")) + globalconfig["Authentication"]["disable starttls"] = args["disable-starttls"]; + + if (args.hasArg("logtype")) + globalconfig["Log"]["type"] = args["logtype"]; + + if (args.hasArg("ip-variable")) + globalconfig["Log"]["environment ip variable"] = args["ip-variable"]; + + if (args.hasArg("mailbox-type")) + globalconfig["Mailbox"]["type"] = args["mailbox-type"]; + + if (args.hasArg("mailbox-path")) + globalconfig["Mailbox"]["path"] = args["mailbox-path"]; + + if (args.hasArg("create-inbox")) + globalconfig["Mailbox"]["auto create inbox"] = args["create-inbox"]; + + if (args.hasArg("subscribe-mailboxes")) + globalconfig["Mailbox"]["auto subscribe mailboxes"] = args["subscribe-mailboxes"]; + + if (args.hasArg("umask")) + globalconfig["Mailbox"]["umask"] = args["umask"]; + + if (args.hasArg("jail-path")) + globalconfig["Security"]["jail path"] = args["jail-path"]; + + if (args.hasArg("jail-user")) + globalconfig["Security"]["jail user"] = args["jail-user"]; + + if (args.hasArg("jail-group")) + globalconfig["Security"]["jail group"] = args["jail-group"]; + + if (args.hasArg("idle-timeout")) + globalconfig["Session"]["idle timeout"] = args["idle-timeout"]; + + if (args.hasArg("auth-timeout")) + globalconfig["Session"]["auth timeout"] = args["auth-timeout"]; + + if (args.hasArg("transfer-timeout")) + globalconfig["Session"]["transfer timeout"] = args["transfer-timeout"]; + + if (args.hasArg("transfer-buffersize")) + globalconfig["Session"]["transfer buffer size"] = args["transfer-buffersize"]; + + if (args.hasArg("pem-file")) + globalconfig["SSL"]["pem file"] = args["pem-file"]; + + if (args.hasArg("ca-path")) + globalconfig["SSL"]["ca path"] = args["ca-path"]; + + if (args.hasArg("ca-file")) + globalconfig["SSL"]["ca file"] = args["ca-file"]; + + if (args.hasArg("cipher-list")) + globalconfig["SSL"]["cipher list"] = args["cipher-list"]; + + if (args.hasArg("verify-peer")) + globalconfig["SSL"]["verify peer"] = args["verify-peer"]; unparsedArgs = argv + args.argc(); @@ -341,6 +382,20 @@ void Session::importFromEnv(void) ++cnt; } + + map<string, map<string, string> >::const_iterator it = globalconfig.begin(); + for (; it != globalconfig.end(); ++it) { + string section = it->first; + map<string, string>::const_iterator jt = it->second.begin(); + for (; jt != it->second.end(); ++jt) { + string key = jt->first; + string value = jt->second; + string tmp = section + "::" + key + "=" + value; + write(667, tmp.c_str(), tmp.length()); + } + } + + } //----------------------------------------------------------------------