1
0
mirror of https://github.com/anope/anope.git synced 2026-07-09 17:43:12 +02:00

Rewrote arg parsing system, changed lots of std::string*s to std::string&, made --config arg, and made Anope print out a few lines of information when starting

git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@2833 5417fbe8-f217-4b02-8779-1006273d7864
This commit is contained in:
Adam-
2010-03-24 00:46:53 +00:00
parent 14fc57d24b
commit 3ffd917926
16 changed files with 223 additions and 288 deletions
+1 -1
View File
@@ -232,7 +232,7 @@ class CoreExport Channel : public Extensible, public Flags<ChannelFlags>
* @param Target a string to put the param into
* @return true on success
*/
const bool GetParam(ChannelModeName Name, std::string *Target);
const bool GetParam(ChannelModeName Name, std::string &Target);
/** Check if a mode is set and has a param
* @param Name The mode
-3
View File
@@ -22,9 +22,6 @@
/******* General configuration *******/
/* Name of configuration file (in Services directory) */
#define SERVICES_CONF "services.conf"
/* Name of log file (in Services directory) */
#define LOG_FILENAME "services.log"
+4 -1
View File
@@ -158,6 +158,7 @@ char *sockstrerror(int error);
/**** config.c ****/
E std::string services_conf;
E ServerConfig Config;
E int read_config(int reload);
@@ -179,6 +180,8 @@ E void hostserv_init();
/**** init.c ****/
E void introduce_user(const std::string &user);
E bool GetCommandLineArgument(const std::string &name, char shortname = 0);
E bool GetCommandLineArgument(const std::string &name, char shortname, std::string &param);
E int init_primary(int ac, char **av);
E int init_secondary(int ac, char **av);
E Uplink *uplink_server;
@@ -230,7 +233,7 @@ E char *version_protocol;
E const char version_flags[];
E std::string services_dir;
E const char *log_filename;
E std::string log_filename;
E int debug;
E int readonly;
E bool LogChan;
+1 -1
View File
@@ -279,7 +279,7 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag>
* @param Target a string to put the param into
* @return true on success
*/
const bool GetParam(ChannelModeName Name, std::string *Target);
const bool GetParam(ChannelModeName Name, std::string &Target);
/** Check if a mode is set and has a param
* @param Name The mode
+4 -3
View File
@@ -231,6 +231,7 @@ extern int strncasecmp(const char *, const char *, size_t);
#include "slist.h"
/* pull in the various bits of STL to pull in */
#include <iostream>
#include <string>
#include <map>
#include <exception>
@@ -1121,6 +1122,7 @@ struct Uplink {
enum LogLevel
{
LOG_NORMAL,
LOG_TERMINAL,
LOG_DEBUG,
LOG_DEBUG_2,
LOG_DEBUG_3,
@@ -1131,14 +1133,13 @@ class CoreExport Alog
{
private:
std::stringstream buf;
bool logit;
LogLevel Level;
public:
Alog(LogLevel val = LOG_NORMAL);
~Alog();
template<typename T> Alog& operator<<(T val)
{
if (logit)
buf << val;
buf << val;
return *this;
}
};
-6
View File
@@ -67,12 +67,6 @@ cat >$VERSIONH <<EOF
# define VER_OS
#endif
#if defined(USE_MODULES)
# define VER_MODULE "M"
#else
# define VER_MODULE
#endif
#endif
EOF
+1 -1
View File
@@ -631,7 +631,7 @@ void bot_join(ChannelInfo * ci)
std::string Limit;
int limit = 0;
if (ci->c->GetParam(CMODE_LIMIT, &Limit))
if (ci->c->GetParam(CMODE_LIMIT, Limit))
{
limit = atoi(Limit.c_str());
}
+12 -12
View File
@@ -396,7 +396,7 @@ void Channel::SetModeInternal(ChannelMode *cm, const std::string &param, bool En
{
/* Get the current param set on the channel and send it with the mode */
std::string cparam;
if (GetParam(cmp->Name, &cparam))
if (GetParam(cmp->Name, cparam))
RemoveMode(NULL, cm, cparam);
}
else
@@ -411,9 +411,9 @@ void Channel::SetModeInternal(ChannelMode *cm, const std::string &param, bool En
ChannelModeParam *cmp = dynamic_cast<ChannelModeParam *>(cm);
std::string cparam, ciparam;
/* Get the param currently set on this channel */
GetParam(cmp->Name, &cparam);
GetParam(cmp->Name, cparam);
/* Get the param set in mlock */
ci->GetParam(cmp->Name, &ciparam);
ci->GetParam(cmp->Name, ciparam);
/* We have the wrong param set */
if (cparam.empty() || ciparam.empty() || cparam != ciparam)
@@ -539,7 +539,7 @@ void Channel::RemoveModeInternal(ChannelMode *cm, const std::string &param, bool
{
std::string cparam;
/* Get the param stored in mlock for this mode */
if (ci->GetParam(cm->Name, &cparam))
if (ci->GetParam(cm->Name, cparam))
SetMode(NULL, cm, cparam);
}
}
@@ -648,15 +648,15 @@ void Channel::RemoveMode(BotInfo *bi, char Mode, const std::string &param, bool
* @param Target a string to put the param into
* @return true on success
*/
const bool Channel::GetParam(ChannelModeName Name, std::string *Target)
const bool Channel::GetParam(ChannelModeName Name, std::string &Target)
{
std::map<ChannelModeName, std::string>::iterator it = Params.find(Name);
(*Target).clear();
Target.clear();
if (it != Params.end())
{
*Target = it->second;
Target = it->second;
return true;
}
@@ -705,7 +705,7 @@ void Channel::ClearModes(BotInfo *bi)
if (!cmp->MinusNoArg)
{
std::string buf;
if (this->GetParam(cmp->Name, &buf))
if (this->GetParam(cmp->Name, buf))
this->RemoveMode(NULL, cm, buf);
}
else
@@ -1001,7 +1001,7 @@ char *chan_get_modes(Channel * chan, int complete, int plus)
if (plus || !cmp->MinusNoArg)
{
chan->GetParam(cmp->Name, &param);
chan->GetParam(cmp->Name, param);
if (!param.empty())
{
@@ -1104,11 +1104,11 @@ void get_channel_stats(long *nrec, long *memuse)
mem += sizeof(*chan);
if (chan->topic)
mem += strlen(chan->topic) + 1;
if (chan->GetParam(CMODE_KEY, &buf))
if (chan->GetParam(CMODE_KEY, buf))
mem += buf.length() + 1;
if (chan->GetParam(CMODE_FLOOD, &buf))
if (chan->GetParam(CMODE_FLOOD, buf))
mem += buf.length() + 1;
if (chan->GetParam(CMODE_REDIRECT, &buf))
if (chan->GetParam(CMODE_REDIRECT, buf))
mem += buf.length() + 1;
mem += get_memuse(chan->bans);
if (ModeManager::FindChannelModeByName(CMODE_EXCEPT))
+8 -8
View File
@@ -210,7 +210,7 @@ char *get_mlock_modes(ChannelInfo * ci, int complete)
{
cmp = dynamic_cast<ChannelModeParam *>(cm);
ci->GetParam(cmp->Name, &param);
ci->GetParam(cmp->Name, param);
if (!param.empty())
{
@@ -252,13 +252,13 @@ void get_chanserv_stats(long *nrec, long *memuse)
mem += ci->GetAccessCount() * sizeof(ChanAccess);
mem += ci->GetAkickCount() * sizeof(AutoKick);
if (ci->GetParam(CMODE_KEY, &param))
if (ci->GetParam(CMODE_KEY, param))
mem += param.length() + 1;
if (ci->GetParam(CMODE_FLOOD, &param))
if (ci->GetParam(CMODE_FLOOD, param))
mem += param.length() + 1;
if (ci->GetParam(CMODE_REDIRECT, &param))
if (ci->GetParam(CMODE_REDIRECT, param))
mem += param.length() + 1;
if (ci->last_topic)
@@ -379,7 +379,7 @@ void check_modes(Channel *c)
/* Add the eventual parameter and modify the Channel structure */
if (cm->Type == MODE_PARAM)
{
if (ci->GetParam(cmp->Name, &param))
if (ci->GetParam(cmp->Name, param))
c->SetMode(NULL, cm, param);
}
else
@@ -388,8 +388,8 @@ void check_modes(Channel *c)
/* If this is a param mode and its mlocked, check to ensure it is set and set to the correct value */
else if (cm->Type == MODE_PARAM && ci->HasMLock(cm->Name, true))
{
c->GetParam(cm->Name, &param);
ci->GetParam(cm->Name, &ciparam);
c->GetParam(cm->Name, param);
ci->GetParam(cm->Name, ciparam);
/* If the channel doesnt have the mode, or it does and it isn't set correctly */
if (!c->HasMode(cm->Name) || (!param.empty() && !ciparam.empty() && param != ciparam))
@@ -413,7 +413,7 @@ void check_modes(Channel *c)
if (!cmp->MinusNoArg)
{
if (c->GetParam(cmp->Name, &param))
if (c->GetParam(cmp->Name, param))
c->RemoveMode(NULL, cm, param);
}
}
+6 -5
View File
@@ -18,6 +18,7 @@
/*************************************************************************/
std::string services_conf = "services.conf"; // Services configuration file name
ServerConfig Config;
static std::string Modules;
@@ -785,7 +786,7 @@ int ServerConfig::Read(bool bail)
// Load and parse the config file, if there are any errors then explode
// Make a copy here so if it fails then we can carry on running with an unaffected config
newconfig.clear();
if (LoadConf(newconfig, SERVICES_CONF, errstr))
if (LoadConf(newconfig, services_conf, errstr))
// If we succeeded, set the config to the new one
config_data = newconfig;
else
@@ -1478,16 +1479,16 @@ void error(int linenum, const char *message, ...)
va_end(args);
if (linenum)
Alog() << SERVICES_CONF << ":" << linenum << ": " << buf;
Alog() << services_conf << ":" << linenum << ": " << buf;
else
Alog() << SERVICES_CONF << ": " << buf;
Alog() << services_conf << ": " << buf;
if (!nofork && isatty(2)) {
if (linenum)
fprintf(stderr, "%s:%d: %s\n", SERVICES_CONF, linenum, buf);
fprintf(stderr, "%s:%d: %s\n", services_conf.c_str(), linenum, buf);
else
fprintf(stderr, "%s: %s\n", SERVICES_CONF, buf);
fprintf(stderr, "%s: %s\n", services_conf.c_str(), buf);
}
}
+1 -1
View File
@@ -36,7 +36,7 @@ class CommandCSGetKey : public Command
return MOD_CONT;
}
if (!ci->c || !ci->c->GetParam(CMODE_KEY, &key))
if (!ci->c || !ci->c->GetParam(CMODE_KEY, key))
{
notice_lang(Config.s_ChanServ, u, CHAN_GETKEY_NOKEY, chan);
return MOD_CONT;
+1 -1
View File
@@ -1039,7 +1039,7 @@ class DBPlain : public Module
}
std::string Param;
for (j = 0; ChannelModes[j].Value != -1; ++j)
if (ci->GetParam(ChannelModes[j].Value, &Param))
if (ci->GetParam(ChannelModes[j].Value, Param))
db << "MD MLP " << ChannelModes[j].Name << " " << Param;
if (!ci->memos.memos.empty())
{
+163 -219
View File
@@ -79,230 +79,67 @@ static int set_group()
/*************************************************************************/
/* Parse command-line options for the "-dir" option only. Return 0 if all
* went well or -1 for a syntax error.
/* Vector of pairs of command line arguments and their params */
static std::vector<std::pair<std::string, std::string> > CommandLineArguments;
/** Called on startup to organize our starting arguments in a better way
* and check for errors
* @param ac number of args
* @param av args
*/
/* XXX this could fail if we have "-some-option-taking-an-argument -dir" */
static int parse_dir_options(int ac, char **av)
static void ParseCommandLineArguments(int ac, char **av)
{
int i;
char *s;
for (i = 1; i < ac; i++) {
s = av[i];
if (*s == '-') {
s++;
if (strcmp(s, "dir") == 0) {
if (++i >= ac) {
fprintf(stderr, "-dir requires a parameter\n");
return -1;
}
services_dir = av[i];
} else if (strcmp(s, "log") == 0) {
if (++i >= ac) {
fprintf(stderr, "-log requires a parameter\n");
return -1;
}
log_filename = av[i];
} else if (strcmp(s, "debug") == 0) {
++debug;
} else if (strcmp(s, "nofork") == 0) {
nofork = 1;
} else if (strcmp(s, "support") == 0) {
nofork = 1;
++debug;
nothird = 1;
} else if (strcmp(s, "version") == 0) {
fprintf(stdout, "Anope-%s %s -- %s\n", version_number,
version_flags, version_build);
exit(EXIT_SUCCESS);
}
for (int i = 1; i < ac; ++i)
{
std::string option = av[i];
std::string param = "";
while (!option.empty() && option[0] == '-')
option.erase(option.begin());
size_t t = option.find('=');
if (t != std::string::npos)
{
param = option.substr(t + 1);
option.erase(t);
}
if (option.empty())
continue;
CommandLineArguments.push_back(std::make_pair(option, param));
}
return 0;
}
/*************************************************************************/
/* Parse command-line options. Return 0 if all went well, -1 for an error
* with an option, or 1 for -help.
/** Check if an argument was given on startup
* @param name The argument name
* @param shortname A shorter name, eg --debug and -d
* @return true if name/shortname was found, false if not
*/
static int parse_options(int ac, char **av)
bool GetCommandLineArgument(const std::string &name, char shortname)
{
int i;
char *s, *t;
std::string Unused;
return GetCommandLineArgument(name, shortname, Unused);
}
for (i = 1; i < ac; i++) {
s = av[i];
if (*s == '-') {
s++;
if (strcmp(s, "remote") == 0) {
if (++i >= ac) {
fprintf(stderr, "-remote requires hostname[:port]\n");
return -1;
}
s = av[i];
t = strchr(s, ':');
if (t) {
int portnum;
*t++ = 0;
portnum = atoi(t);
if ((portnum > 0) && (portnum < 65535))
/*RemotePort = portnum*/; // Needs fixing to handle the Uplinks list
else {
fprintf(stderr,
"-remote: Port numbers must be in the range 1..65535. Using default.\n");
return -1;
}
}
/*RemoteServer = s*/; // Needs fixing to handle the Uplinks list
} else if (strcmp(s, "local") == 0) {
if (++i >= ac) {
fprintf(stderr,
"-local requires hostname or [hostname]:[port]\n");
return -1;
}
s = av[i];
t = strchr(s, ':');
if (t) {
int portnum;
*t++ = 0;
portnum = atoi(t);
if ((portnum >= 0) && (portnum < 65535))
Config.LocalPort = portnum;
else {
fprintf(stderr,
"-local: Port numbers must be in the range 1..65535 or 0. Using default.\n");
return -1;
}
}
Config.LocalHost = s;
} else if (strcmp(s, "name") == 0) {
if (++i >= ac) {
fprintf(stderr, "-name requires a parameter\n");
return -1;
}
Config.ServerName = av[i];
} else if (strcmp(s, "desc") == 0) {
if (++i >= ac) {
fprintf(stderr, "-desc requires a parameter\n");
return -1;
}
Config.ServerDesc = av[i];
} else if (strcmp(s, "user") == 0) {
if (++i >= ac) {
fprintf(stderr, "-user requires a parameter\n");
return -1;
}
Config.ServiceUser = av[i];
} else if (strcmp(s, "host") == 0) {
if (++i >= ac) {
fprintf(stderr, "-host requires a parameter\n");
return -1;
}
Config.ServiceHost = av[i];
} else if (strcmp(s, "dir") == 0) {
/* Handled by parse_dir_options() */
i++; /* Skip parameter */
} else if (strcmp(s, "log") == 0) {
/* Handled by parse_dir_options(), too */
i++; /* Skip parameter */
} else if (strcmp(s, "update") == 0) {
if (++i >= ac) {
fprintf(stderr, "-update requires a parameter\n");
return -1;
}
s = av[i];
if (atoi(s) <= 0) {
fprintf(stderr,
"-update: number of seconds must be positive");
return -1;
} else
Config.UpdateTimeout = atol(s);
} else if (strcmp(s, "expire") == 0) {
if (++i >= ac) {
fprintf(stderr, "-expire requires a parameter\n");
return -1;
}
s = av[i];
if (atoi(s) <= 0) {
fprintf(stderr,
"-expire: number of seconds must be positive\n");
return -1;
} else
Config.ExpireTimeout = atol(s);
} else if (strcmp(s, "debug") == 0) {
/* Handled by parse_dir_options() */
} else if (strcmp(s, "readonly") == 0) {
readonly = 1;
} else if (strcmp(s, "nofork") == 0) {
/* Handled by parse_dir_options() */
} else if (strcmp(s, "logchan") == 0) {
if (!Config.LogChannel) {
fprintf(stderr,
"-logchan: Config.LogChannel must be defined in services.conf\n");
} else { /* Config.LogChannel */
LogChan = true;
}
} else if (strcmp(s, "forceload") == 0) {
forceload = 1;
} else if (strcmp(s, "nothird") == 0) {
nothird = 1;
} else if (strcmp(s, "protocoldebug") == 0) {
protocoldebug = 1;
} else if (strcmp(s, "support") == 0) {
/* Handled by parse_dir_options() */
} else if (!strcmp(s, "noexpire")) {
noexpire = 1;
} else if (!strcmp(s, "help")) {
fprintf(stdout, "Anope-%s %s -- %s\n", version_number,
version_flags, version_build);
fprintf(stdout,
"Anope IRC Services (http://www.anope.org)\n");
fprintf(stdout, "Usage ./" SERVICES_BIN " [options] ...\n");
fprintf(stdout,
"-remote -remote hostname[:port]\n");
fprintf(stdout, "-local -local hostname[:port]\n");
fprintf(stdout, "-name -name servername\n");
fprintf(stdout, "-desc -desc serverdesc\n");
fprintf(stdout, "-user -user serviceuser\n");
fprintf(stdout, "-host -host servicehost\n");
fprintf(stdout,
"-update -update updatetime(secs)\n");
fprintf(stdout,
"-expire -expire expiretime(secs)\n");
fprintf(stdout, "-debug -debug\n");
fprintf(stdout, "-nofork -nofork\n");
fprintf(stdout, "-logchan -logchan channelname\n");
fprintf(stdout, "-forceload -forceload\n");
fprintf(stdout, "-nothird -nothird\n");
fprintf(stdout, "-support -support\n");
fprintf(stdout, "-readonly -readonly\n");
fprintf(stdout, "-noexpire -noexpire\n");
fprintf(stdout, "-version -version\n");
fprintf(stdout, "-help -help\n");
fprintf(stdout, "-log -log logfilename\n");
fprintf(stdout,
"-dir -dir servicesdirectory\n\n");
fprintf(stdout,
"Further support is available from http://www.anope.org\n");
fprintf(stdout,
"Or visit US on IRC at irc.anope.org #anope\n");
exit(EXIT_SUCCESS);
} else {
fprintf(stderr, "Unknown option -%s\n", s);
return -1;
}
} else {
fprintf(stderr, "Non-option arguments not allowed\n");
return -1;
/** Check if an argument was given on startup and its parameter
* @param name The argument name
* @param shortname A shorter name, eg --debug and -d
* @param param A string to put the param, if any, of the argument
* @return true if name/shortname was found, false if not
*/
bool GetCommandLineArgument(const std::string &name, char shortname, std::string &param)
{
param.clear();
for (std::vector<std::pair<std::string, std::string> >::iterator it = CommandLineArguments.begin(); it != CommandLineArguments.end(); ++it)
{
if (it->first == name || it->first[0] == shortname)
{
param = it->second;
return true;
}
}
return 0;
return false;
}
/*************************************************************************/
@@ -353,8 +190,116 @@ int init_primary(int ac, char **av)
if (set_group() < 0)
return -1;
/* Parse command line for -dir and -version options. */
parse_dir_options(ac, av);
/* Parse command line arguments */
ParseCommandLineArguments(ac, av);
if (GetCommandLineArgument("version", 'v'))
{
Alog(LOG_TERMINAL) << "Anope-" << version_number << version_flags << " -- " << version_build;
return -1;
}
if (GetCommandLineArgument("help", 'h'))
{
Alog(LOG_TERMINAL) << "Anope-" << version_number << version_flags << " -- " << version_build;
Alog(LOG_TERMINAL) << "Anope IRC Services (http://www.anope.org)";
Alog(LOG_TERMINAL) << "Usage ./" << SERVICES_BIN << " [options] ...";
Alog(LOG_TERMINAL) << "-c, --config=filename.conf";
Alog(LOG_TERMINAL) << "-d, --debug[=level]";
Alog(LOG_TERMINAL) << " --dir=services_directory";
Alog(LOG_TERMINAL) << "-h, --help";
Alog(LOG_TERMINAL) << " --log=log_filename";
Alog(LOG_TERMINAL) << "-e, --noexpire";
Alog(LOG_TERMINAL) << "-n, --nofork";
Alog(LOG_TERMINAL) << " --nothird";
Alog(LOG_TERMINAL) << " --protocoldebug";
Alog(LOG_TERMINAL) << "-r, --readonly";
Alog(LOG_TERMINAL) << "-s, --support";
Alog(LOG_TERMINAL) << "-v, --version";
Alog(LOG_TERMINAL) << "";
Alog(LOG_TERMINAL) << "Further support is available from http://www.anope.org";
Alog(LOG_TERMINAL) << "Or visit us on IRC at irc.anope.org #anope";
return -1;
}
if (GetCommandLineArgument("nofork", 'n'))
{
nofork = 1;
}
if (GetCommandLineArgument("support", 's'))
{
nofork = nothird = 1;
++debug;
}
if (GetCommandLineArgument("readonly", 'r'))
{
readonly = 1;
}
if (GetCommandLineArgument("nothird"))
{
nothird = 1;
}
if (GetCommandLineArgument("noexpire", 'e'))
{
noexpire = 1;
}
if (GetCommandLineArgument("protocoldebug"))
{
protocoldebug = 1;
}
std::string Arg;
if (GetCommandLineArgument("debug", 'd', Arg))
{
if (!Arg.empty())
{
int level = atoi(Arg.c_str());
if (level > 0)
debug = level;
else
{
Alog(LOG_TERMINAL) << "Invalid option given to --debug";
return -1;
}
}
else
++debug;
}
if (GetCommandLineArgument("config", 'c', Arg))
{
if (Arg.empty())
{
Alog(LOG_TERMINAL) << "The --config option requires a file name";
return -1;
}
services_conf = Arg;
}
if (GetCommandLineArgument("dir", 0, Arg))
{
if (Arg.empty())
{
Alog(LOG_TERMINAL) << "The --dir option requires a directory name";
return -1;
}
services_dir = Arg;
}
if (GetCommandLineArgument("log", 0, Arg))
{
if (Arg.empty())
{
Alog(LOG_TERMINAL) << "The --log option requires a file name";
return -1;
}
log_filename = Arg;
}
/* Chdir to Services data directory. */
if (chdir(services_dir.c_str()) < 0) {
@@ -367,7 +312,7 @@ int init_primary(int ac, char **av)
openlog_errno = errno;
if (started_from_term) {
fprintf(stderr, "Warning: unable to open log file %s: %s\n",
log_filename, strerror(errno));
log_filename.c_str(), strerror(errno));
} else {
openlog_failed = 1;
}
@@ -402,15 +347,13 @@ int init_secondary(int ac, char **av)
/* Add Core MSG handles */
moduleAddMsgs();
/* Parse all remaining command-line options. */
parse_options(ac, av);
#ifndef _WIN32
if (!nofork) {
if ((i = fork()) < 0) {
perror("fork()");
return -1;
} else if (i != 0) {
Alog(LOG_TERMINAL) << "PID " << i;
exit(0);
}
if (started_from_term) {
@@ -444,6 +387,7 @@ int init_secondary(int ac, char **av)
}
if (!nofork) {
Alog(LOG_TERMINAL) << "PID " << GetCurrentProcessId();
Alog() << "Launching Anope into the background";
FreeConsole();
}
+9 -14
View File
@@ -34,7 +34,7 @@ static int get_logname(char *name, int count, struct tm *tm)
/* fix bug 577 */
strftime(timestamp, sizeof(timestamp), "%Y%m%d", tm);
snprintf(name, count, "logs/%s.%s", log_filename, timestamp);
snprintf(name, count, "logs/%s.%s", log_filename.c_str(), timestamp);
curday = tm->tm_yday;
return 1;
@@ -255,21 +255,15 @@ void fatal_perror(const char *fmt, ...)
exit(1);
}
Alog::Alog(LogLevel val)
Alog::Alog(LogLevel val) : Level(val)
{
if (val > debug)
logit = false;
else
{
logit = true;
if (val >= LOG_DEBUG)
buf << "Debug: ";
}
if (Level >= LOG_DEBUG)
buf << "Debug: ";
}
Alog::~Alog()
{
if (!logit)
if (Level >= LOG_DEBUG && (Level - LOG_DEBUG + 1) > debug)
return;
char *tbuf;
@@ -282,9 +276,10 @@ Alog::~Alog()
if (logfile) {
fprintf(logfile, "%s %s\n", tbuf, buf.str().c_str());
}
if (nofork) {
fprintf(stderr, "%s %s\n", tbuf, buf.str().c_str());
}
if (nofork)
std::cout << tbuf << " " << buf.str() << std::endl;
else if (Level == LOG_TERMINAL) // XXX dont use this yet unless you know we're at terminal and not daemonized
std::cout << buf.str() << std::endl;
if (Config.LogChannel && LogChan && !debug && findchan(Config.LogChannel)) {
ircdproto->SendPrivmsg(findbot(Config.s_GlobalNoticer), Config.LogChannel, "%s", buf.str().c_str());
}
+9 -9
View File
@@ -44,7 +44,7 @@
std::string services_dir; /* -dir dirname */
std::string services_bin; /* Binary as specified by the user */
std::string orig_cwd; /* Original current working directory */
const char *log_filename = LOG_FILENAME; /* -log filename */
std::string log_filename = LOG_FILENAME; /* -log filename */
int debug = 0; /* -debug */
int readonly = 0; /* -readonly */
bool LogChan = false; /* -logchan */
@@ -90,7 +90,7 @@ const char version_number_dotted[] = VERSION_STRING_DOTTED;
const char version_build[] =
"build #" BUILD ", compiled " __DATE__ " " __TIME__;
/* the space is needed cause if you build with nothing it will complain */
const char version_flags[] = " " VER_OS VER_MODULE;
const char version_flags[] = " " VER_OS;
/******** Local variables! ********/
@@ -371,7 +371,6 @@ std::string GetFullProgDir(char *argv0)
int main(int ac, char **av, char **envp)
{
int i;
char *progname;
my_av = av;
my_envp = envp;
@@ -412,12 +411,13 @@ int main(int ac, char **av, char **envp)
/* General initialization first */
if ((i = init_primary(ac, av)) != 0)
return i;
/* Find program name. */
if ((progname = strrchr(av[0], '/')) != NULL)
progname++;
else
progname = av[0];
Alog(LOG_TERMINAL) << "Anope " << version_number << ", " << version_build;
#ifdef _WIN32
Alog(LOG_TERMINAL) << "Using configuration file " << services_dir << "\\" << services_conf;
#else
Alog(LOG_TERMINAL) << "Using configuration file " << services_dir << "/" << services_conf;
#endif
/* Initialization stuff. */
if ((i = init_secondary(ac, av)) != 0)
+3 -3
View File
@@ -510,15 +510,15 @@ const size_t ChannelInfo::GetMLockCount(bool status) const
* @param Target a string to put the param into
* @return true on success
*/
const bool ChannelInfo::GetParam(ChannelModeName Name, std::string *Target)
const bool ChannelInfo::GetParam(ChannelModeName Name, std::string &Target)
{
std::map<ChannelModeName, std::string>::iterator it = Params.find(Name);
(*Target).clear();
Target.clear();
if (it != Params.end())
{
*Target = it->second;
Target = it->second;
return true;
}