diff options
author | om <om@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-03-09 21:58:54 +0000 |
---|---|---|
committer | om <om@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-03-09 21:58:54 +0000 |
commit | 4ac0ccc06ce0cafea2549f51881cba0c44463d9c (patch) | |
tree | 762a66837c905f5be0fd936a25e9e4ade8232703 | |
parent | 4fa0251cfb55dce9511a4faf00eb7545b74a7f18 (diff) |
Convert more by-values to const references, optimise ConfigReader a bit
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@3606 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r-- | include/modules.h | 224 | ||||
-rw-r--r-- | include/socket.h | 4 | ||||
-rw-r--r-- | src/modules.cpp | 200 | ||||
-rw-r--r-- | src/socket.cpp | 8 |
4 files changed, 212 insertions, 224 deletions
diff --git a/include/modules.h b/include/modules.h index 7bc4d3d4c..a39b764b5 100644 --- a/include/modules.h +++ b/include/modules.h @@ -185,9 +185,9 @@ class Module; class ModuleMessage : public classbase { public: - /** This class is pure virtual and must be inherited. - */ - virtual char* Send() = 0; + /** This class is pure virtual and must be inherited. + */ + virtual char* Send() = 0; virtual ~ModuleMessage() {}; }; @@ -199,35 +199,35 @@ class ModuleMessage : public classbase class Request : public ModuleMessage { protected: - /** This member holds a pointer to arbitary data set by the emitter of the message - */ - char* data; - /** This is a pointer to the sender of the message, which can be used to - * directly trigger events, or to create a reply. - */ - Module* source; - /** The single destination of the Request - */ - Module* dest; + /** This member holds a pointer to arbitary data set by the emitter of the message + */ + char* data; + /** This is a pointer to the sender of the message, which can be used to + * directly trigger events, or to create a reply. + */ + Module* source; + /** The single destination of the Request + */ + Module* dest; public: - /** Create a new Request - */ - Request(char* anydata, Module* src, Module* dst); - /** Fetch the Request data - */ - char* GetData(); - /** Fetch the request source - */ - Module* GetSource(); - /** Fetch the request destination (should be 'this' in the receiving module) - */ - Module* GetDest(); - /** Send the Request. - * Upon returning the result will be arbitary data returned by the module you - * sent the request to. It is up to your module to know what this data is and - * how to deal with it. - */ - char* Send(); + /** Create a new Request + */ + Request(char* anydata, Module* src, Module* dst); + /** Fetch the Request data + */ + char* GetData(); + /** Fetch the request source + */ + Module* GetSource(); + /** Fetch the request destination (should be 'this' in the receiving module) + */ + Module* GetDest(); + /** Send the Request. + * Upon returning the result will be arbitary data returned by the module you + * sent the request to. It is up to your module to know what this data is and + * how to deal with it. + */ + char* Send(); }; @@ -239,37 +239,37 @@ class Request : public ModuleMessage class Event : public ModuleMessage { protected: - /** This member holds a pointer to arbitary data set by the emitter of the message - */ - char* data; - /** This is a pointer to the sender of the message, which can be used to - * directly trigger events, or to create a reply. - */ - Module* source; - /** The event identifier. - * This is arbitary text which should be used to distinguish - * one type of event from another. - */ - std::string id; + /** This member holds a pointer to arbitary data set by the emitter of the message + */ + char* data; + /** This is a pointer to the sender of the message, which can be used to + * directly trigger events, or to create a reply. + */ + Module* source; + /** The event identifier. + * This is arbitary text which should be used to distinguish + * one type of event from another. + */ + std::string id; public: - /** Create a new Event - */ - Event(char* anydata, Module* src, std::string eventid); - /** Get the Event data - */ - char* GetData(); - /** Get the event Source - */ - Module* GetSource(); - /** Get the event ID. - * Use this to determine the event type for safe casting of the data - */ - std::string GetEventID(); - /** Send the Event. - * The return result of an Event::Send() will always be NULL as - * no replies are expected. - */ - char* Send(); + /** Create a new Event + */ + Event(char* anydata, Module* src, const std::string &eventid); + /** Get the Event data + */ + char* GetData(); + /** Get the event Source + */ + Module* GetSource(); + /** Get the event ID. + * Use this to determine the event type for safe casting of the data + */ + std::string GetEventID(); + /** Send the Event. + * The return result of an Event::Send() will always be NULL as + * no replies are expected. + */ + char* Send(); }; /** Holds an extended mode's details. @@ -278,13 +278,13 @@ class Event : public ModuleMessage class ExtMode : public classbase { public: - char modechar; - int type; - bool needsoper; - int params_when_on; - int params_when_off; - bool list; - ExtMode(char mc, int ty, bool oper, int p_on, int p_off) : modechar(mc), type(ty), needsoper(oper), params_when_on(p_on), params_when_off(p_off), list(false) { }; + char modechar; + int type; + bool needsoper; + int params_when_on; + int params_when_off; + bool list; + ExtMode(char mc, int ty, bool oper, int p_on, int p_off) : modechar(mc), type(ty), needsoper(oper), params_when_on(p_on), params_when_off(p_off), list(false) { }; }; @@ -314,9 +314,9 @@ class ModuleException /** Returns the reason for the exception. * The module should probably put something informative here as the user will see this upon failure. */ - virtual char *GetReason() + virtual const char* GetReason() { - return (char*)err.c_str(); + return err.c_str(); } }; @@ -503,7 +503,7 @@ class Module : public classbase */ virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname); - /** Called whenever a user is about to be kicked. + /** Called whenever a user is about to be kicked. * Returning a value of 1 from this function stops the process immediately, causing no * output to be sent to the user by the core. If you do this you must produce your own numerics, * notices etc. @@ -640,7 +640,7 @@ class Module : public classbase */ virtual void OnUserMessage(userrec* user, void* dest, int target_type, std::string text, char status); - /** Called after any NOTICE sent from a user. + /** Called after any NOTICE sent from a user. * The dest variable contains a userrec* if target_type is TYPE_USER and a chanrec* * if target_type is TYPE_CHANNEL. * @param user The user sending the message @@ -1069,7 +1069,7 @@ class Module : public classbase */ virtual int OnCheckInvite(userrec* user, chanrec* chan); - /** Called whenever a user joins a channel, to determine if key checks should go ahead or not. + /** Called whenever a user joins a channel, to determine if key checks should go ahead or not. * This method will always be called for each join, wether or not the channel is actually +k, and * determines the outcome of an if statement around the whole section of key checking code. * if the user specified no key, the keygiven string will be a valid but empty value. @@ -1080,7 +1080,7 @@ class Module : public classbase */ virtual int OnCheckKey(userrec* user, chanrec* chan, std::string keygiven); - /** Called whenever a user joins a channel, to determine if channel limit checks should go ahead or not. + /** Called whenever a user joins a channel, to determine if channel limit checks should go ahead or not. * This method will always be called for each join, wether or not the channel is actually +l, and * determines the outcome of an if statement around the whole section of channel limit checking code. * return 1 to explicitly allow the join to go ahead or 0 to ignore the event. @@ -1090,7 +1090,7 @@ class Module : public classbase */ virtual int OnCheckLimit(userrec* user, chanrec* chan); - /** Called whenever a user joins a channel, to determine if banlist checks should go ahead or not. + /** Called whenever a user joins a channel, to determine if banlist checks should go ahead or not. * This method will always be called for each join, wether or not the user actually matches a channel ban, and * determines the outcome of an if statement around the whole section of ban checking code. * return 1 to explicitly allow the join to go ahead or 0 to ignore the event. @@ -1654,40 +1654,40 @@ class Server : public classbase */ virtual void AddGLine(long duration, std::string source, std::string reason, std::string hostmask); - /** Adds a Q-line - * The Q-line is propogated to all of the servers in the mesh and enforced as soon as it is added. - * The duration must be in seconds, however you can use the Server::CalcDuration method to convert - * durations into the 1w2d3h3m6s format used by /GLINE etc. The source is an arbitary string used - * to indicate who or what sent the data, usually this is the nickname of a person, or a server - * name. - */ + /** Adds a Q-line + * The Q-line is propogated to all of the servers in the mesh and enforced as soon as it is added. + * The duration must be in seconds, however you can use the Server::CalcDuration method to convert + * durations into the 1w2d3h3m6s format used by /GLINE etc. The source is an arbitary string used + * to indicate who or what sent the data, usually this is the nickname of a person, or a server + * name. + */ virtual void AddQLine(long duration, std::string source, std::string reason, std::string nickname); - /** Adds a Z-line - * The Z-line is propogated to all of the servers in the mesh and enforced as soon as it is added. - * The duration must be in seconds, however you can use the Server::CalcDuration method to convert - * durations into the 1w2d3h3m6s format used by /GLINE etc. The source is an arbitary string used - * to indicate who or what sent the data, usually this is the nickname of a person, or a server - * name. - */ + /** Adds a Z-line + * The Z-line is propogated to all of the servers in the mesh and enforced as soon as it is added. + * The duration must be in seconds, however you can use the Server::CalcDuration method to convert + * durations into the 1w2d3h3m6s format used by /GLINE etc. The source is an arbitary string used + * to indicate who or what sent the data, usually this is the nickname of a person, or a server + * name. + */ virtual void AddZLine(long duration, std::string source, std::string reason, std::string ipaddr); - /** Adds a K-line - * The K-line is enforced as soon as it is added. - * The duration must be in seconds, however you can use the Server::CalcDuration method to convert - * durations into the 1w2d3h3m6s format used by /GLINE etc. The source is an arbitary string used - * to indicate who or what sent the data, usually this is the nickname of a person, or a server - * name. - */ + /** Adds a K-line + * The K-line is enforced as soon as it is added. + * The duration must be in seconds, however you can use the Server::CalcDuration method to convert + * durations into the 1w2d3h3m6s format used by /GLINE etc. The source is an arbitary string used + * to indicate who or what sent the data, usually this is the nickname of a person, or a server + * name. + */ virtual void AddKLine(long duration, std::string source, std::string reason, std::string hostmask); - /** Adds a E-line - * The E-line is enforced as soon as it is added. - * The duration must be in seconds, however you can use the Server::CalcDuration method to convert - * durations into the 1w2d3h3m6s format used by /GLINE etc. The source is an arbitary string used - * to indicate who or what sent the data, usually this is the nickname of a person, or a server - * name. - */ + /** Adds a E-line + * The E-line is enforced as soon as it is added. + * The duration must be in seconds, however you can use the Server::CalcDuration method to convert + * durations into the 1w2d3h3m6s format used by /GLINE etc. The source is an arbitary string used + * to indicate who or what sent the data, usually this is the nickname of a person, or a server + * name. + */ virtual void AddELine(long duration, std::string source, std::string reason, std::string hostmask); /** Deletes a G-Line from all servers @@ -1785,7 +1785,7 @@ class ConfigReader : public classbase /** Overloaded constructor. * This constructor initialises the ConfigReader class to read a user-specified config file */ - ConfigReader(std::string filename); // read a module-specific config + ConfigReader(const std::string &filename); // read a module-specific config /** Default destructor. * This method destroys the ConfigReader class. */ @@ -1794,13 +1794,13 @@ class ConfigReader : public classbase * This method retrieves a value from the config file. Where multiple copies of the tag * exist in the config file, index indicates which of the values to retrieve. */ - std::string ReadValue(std::string tag, std::string name, int index); + std::string ReadValue(const std::string &tag, const std::string &name, int index); /** Retrieves a boolean value from the config file. * This method retrieves a boolean value from the config file. Where multiple copies of the tag * exist in the config file, index indicates which of the values to retrieve. The values "1", "yes" * and "true" in the config file count as true to ReadFlag, and any other value counts as false. */ - bool ReadFlag(std::string tag, std::string name, int index); + bool ReadFlag(const std::string &tag, const std::string &name, int index); /** Retrieves an integer value from the config file. * This method retrieves an integer value from the config file. Where multiple copies of the tag * exist in the config file, index indicates which of the values to retrieve. Any invalid integer @@ -1809,7 +1809,7 @@ class ConfigReader : public classbase * If a signed number is placed into a tag which is specified unsigned, 0 will be returned and GetError() * will return CONF_NOT_UNSIGNED */ - long ReadInteger(std::string tag, std::string name, int index, bool needs_unsigned); + long ReadInteger(const std::string &tag, const std::string &name, int index, bool needs_unsigned); /** Returns the last error to occur. * Valid errors can be found by looking in modules.h. Any nonzero value indicates an error condition. * A call to GetError() resets the error flag back to 0. @@ -1821,7 +1821,7 @@ class ConfigReader : public classbase * used with the index value of ConfigReader::ReadValue to loop through all copies of a * multiple instance tag. */ - int Enumerate(std::string tag); + int Enumerate(const std::string &tag); /** Returns true if a config file is valid. * This method is partially implemented and will only return false if the config * file does not exist or could not be opened. @@ -1840,7 +1840,7 @@ class ConfigReader : public classbase * function would return 2. Spaces and newlines both qualify as valid seperators * between values. */ - int EnumerateValues(std::string tag, int index); + int EnumerateValues(const std::string &tag, int index); }; @@ -1852,7 +1852,7 @@ class ConfigReader : public classbase */ class FileReader : public classbase { - file_cache fc; + file_cache fc; public: /** Default constructor. * This method does not load any file into memory, you must use the LoadFile method @@ -1865,7 +1865,7 @@ class FileReader : public classbase * and other methods to be called. If the file could not be loaded, FileReader::FileSize * returns 0. */ - FileReader(std::string filename); + FileReader(const std::string &filename); /** Default destructor. * This deletes the memory allocated to the file. @@ -1877,7 +1877,7 @@ class FileReader : public classbase * and other methods to be called. If the file could not be loaded, FileReader::FileSize * returns 0. */ - void LoadFile(std::string filename); + void LoadFile(const std::string &filename); /** Returns true if the file exists * This function will return false if the file could not be opened. diff --git a/include/socket.h b/include/socket.h index 584c37b93..e36bbd231 100644 --- a/include/socket.h +++ b/include/socket.h @@ -177,7 +177,7 @@ public: * @param listening true to listen on the given host:port pair, or false to connect to them * @param maxtime Number of seconds to wait, if connecting, before the connection times out and an OnTimeout() event is generated */ - InspSocket(std::string host, int port, bool listening, unsigned long maxtime); + InspSocket(const std::string &host, int port, bool listening, unsigned long maxtime); /** * This method is called when an outbound @@ -264,7 +264,7 @@ public: * returns or linefeeds are appended to the string. * @param data The data to send */ - virtual int Write(std::string data); + virtual int Write(const std::string &data); /** * If your socket is a listening socket, when a new diff --git a/src/modules.cpp b/src/modules.cpp index 9a420a25e..135c0d3e3 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -166,59 +166,59 @@ Request::Request(char* anydata, Module* src, Module* dst) : data(anydata), sourc char* Request::GetData() { - return this->data; + return this->data; } Module* Request::GetSource() { - return this->source; + return this->source; } Module* Request::GetDest() { - return this->dest; + return this->dest; } char* Request::Send() { - if (this->dest) - { - return dest->OnRequest(this); - } - else - { - return NULL; - } + if (this->dest) + { + return dest->OnRequest(this); + } + else + { + return NULL; + } } -Event::Event(char* anydata, Module* src, std::string eventid) : data(anydata), source(src), id(eventid) { }; +Event::Event(char* anydata, Module* src, const std::string &eventid) : data(anydata), source(src), id(eventid) { }; char* Event::GetData() { - return this->data; + return this->data; } Module* Event::GetSource() { - return this->source; + return this->source; } char* Event::Send() { - FOREACH_MOD(I_OnEvent,OnEvent(this)); - return NULL; + FOREACH_MOD(I_OnEvent,OnEvent(this)); + return NULL; } std::string Event::GetEventID() { - return this->id; + return this->id; } // These declarations define the behavours of the base class Module (which does nothing at all) - Module::Module(Server* Me) { } - Module::~Module() { } + Module::Module(Server* Me) { } + Module::~Module() { } void Module::OnUserConnect(userrec* user) { } void Module::OnUserQuit(userrec* user, std::string message) { } void Module::OnUserDisconnect(userrec* user) { } @@ -226,51 +226,51 @@ void Module::OnUserJoin(userrec* user, chanrec* channel) { } void Module::OnUserPart(userrec* user, chanrec* channel, std::string partmessage) { } void Module::OnRehash(std::string parameter) { } void Module::OnServerRaw(std::string &raw, bool inbound, userrec* user) { } -int Module::OnUserPreJoin(userrec* user, chanrec* chan, const char* cname) { return 0; } -int Module::OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms) { return false; } +int Module::OnUserPreJoin(userrec* user, chanrec* chan, const char* cname) { return 0; } +int Module::OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms) { return false; } void Module::OnMode(userrec* user, void* dest, int target_type, std::string text) { }; Version Module::GetVersion() { return Version(1,0,0,0,VF_VENDOR); } void Module::OnOper(userrec* user, std::string opertype) { }; void Module::OnPostOper(userrec* user, std::string opertype) { }; void Module::OnInfo(userrec* user) { }; void Module::OnWhois(userrec* source, userrec* dest) { }; -int Module::OnUserPreInvite(userrec* source,userrec* dest,chanrec* channel) { return 0; }; -int Module::OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text,char status) { return 0; }; -int Module::OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text,char status) { return 0; }; -int Module::OnUserPreNick(userrec* user, std::string newnick) { return 0; }; +int Module::OnUserPreInvite(userrec* source,userrec* dest,chanrec* channel) { return 0; }; +int Module::OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text,char status) { return 0; }; +int Module::OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text,char status) { return 0; }; +int Module::OnUserPreNick(userrec* user, std::string newnick) { return 0; }; void Module::OnUserPostNick(userrec* user, std::string oldnick) { }; -int Module::OnAccessCheck(userrec* source,userrec* dest,chanrec* channel,int access_type) { return ACR_DEFAULT; }; +int Module::OnAccessCheck(userrec* source,userrec* dest,chanrec* channel,int access_type) { return ACR_DEFAULT; }; void Module::On005Numeric(std::string &output) { }; -int Module::OnKill(userrec* source, userrec* dest, std::string reason) { return 0; }; +int Module::OnKill(userrec* source, userrec* dest, std::string reason) { return 0; }; void Module::OnLoadModule(Module* mod,std::string name) { }; void Module::OnUnloadModule(Module* mod,std::string name) { }; void Module::OnBackgroundTimer(time_t curtime) { }; void Module::OnSendList(userrec* user, chanrec* channel, char mode) { }; -int Module::OnPreCommand(std::string command, char **parameters, int pcnt, userrec *user, bool validated) { return 0; }; +int Module::OnPreCommand(std::string command, char **parameters, int pcnt, userrec *user, bool validated) { return 0; }; bool Module::OnCheckReady(userrec* user) { return true; }; void Module::OnUserRegister(userrec* user) { }; -int Module::OnUserPreKick(userrec* source, userrec* user, chanrec* chan, std::string reason) { return 0; }; +int Module::OnUserPreKick(userrec* source, userrec* user, chanrec* chan, std::string reason) { return 0; }; void Module::OnUserKick(userrec* source, userrec* user, chanrec* chan, std::string reason) { }; -int Module::OnRawMode(userrec* user, chanrec* chan, char mode, std::string param, bool adding, int pcnt) { return 0; }; -int Module::OnCheckInvite(userrec* user, chanrec* chan) { return 0; }; -int Module::OnCheckKey(userrec* user, chanrec* chan, std::string keygiven) { return 0; }; -int Module::OnCheckLimit(userrec* user, chanrec* chan) { return 0; }; -int Module::OnCheckBan(userrec* user, chanrec* chan) { return 0; }; -int Module::OnStats(char symbol, userrec* user) { return 0; }; -int Module::OnChangeLocalUserHost(userrec* user, std::string newhost) { return 0; }; -int Module::OnChangeLocalUserGECOS(userrec* user, std::string newhost) { return 0; }; -int Module::OnLocalTopicChange(userrec* user, chanrec* chan, std::string topic) { return 0; }; +int Module::OnRawMode(userrec* user, chanrec* chan, char mode, std::string param, bool adding, int pcnt) { return 0; }; +int Module::OnCheckInvite(userrec* user, chanrec* chan) { return 0; }; +int Module::OnCheckKey(userrec* user, chanrec* chan, std::string keygiven) { return 0; }; +int Module::OnCheckLimit(userrec* user, chanrec* chan) { return 0; }; +int Module::OnCheckBan(userrec* user, chanrec* chan) { return 0; }; +int Module::OnStats(char symbol, userrec* user) { return 0; }; +int Module::OnChangeLocalUserHost(userrec* user, std::string newhost) { return 0; }; +int Module::OnChangeLocalUserGECOS(userrec* user, std::string newhost) { return 0; }; +int Module::OnLocalTopicChange(userrec* user, chanrec* chan, std::string topic) { return 0; }; void Module::OnEvent(Event* event) { return; }; char* Module::OnRequest(Request* request) { return NULL; }; -int Module::OnOperCompare(std::string password, std::string input) { return 0; }; +int Module::OnOperCompare(std::string password, std::string input) { return 0; }; void Module::OnGlobalOper(userrec* user) { }; void Module::OnGlobalConnect(userrec* user) { }; -int Module::OnAddBan(userrec* source, chanrec* channel,std::string banmask) { return 0; }; -int Module::OnDelBan(userrec* source, chanrec* channel,std::string banmask) { return 0; }; +int Module::OnAddBan(userrec* source, chanrec* channel,std::string banmask) { return 0; }; +int Module::OnDelBan(userrec* source, chanrec* channel,std::string banmask) { return 0; }; void Module::OnRawSocketAccept(int fd, std::string ip, int localport) { }; -int Module::OnRawSocketWrite(int fd, char* buffer, int count) { return 0; }; +int Module::OnRawSocketWrite(int fd, char* buffer, int count) { return 0; }; void Module::OnRawSocketClose(int fd) { }; -int Module::OnRawSocketRead(int fd, char* buffer, unsigned int count, int &readresult) { return 0; }; +int Module::OnRawSocketRead(int fd, char* buffer, unsigned int count, int &readresult) { return 0; }; void Module::OnUserMessage(userrec* user, void* dest, int target_type, std::string text, char status) { }; void Module::OnUserNotice(userrec* user, void* dest, int target_type, std::string text, char status) { }; void Module::OnRemoteKill(userrec* source, userrec* dest, std::string reason) { }; @@ -877,7 +877,7 @@ ConfigReader::~ConfigReader() } -ConfigReader::ConfigReader(std::string filename) +ConfigReader::ConfigReader(const std::string &filename) { Config->ClearStack(); this->cache = new std::stringstream(std::stringstream::in | std::stringstream::out); @@ -887,14 +887,11 @@ ConfigReader::ConfigReader(std::string filename) this->error = CONF_FILE_NOT_FOUND; }; -std::string ConfigReader::ReadValue(std::string tag, std::string name, int index) +std::string ConfigReader::ReadValue(const std::string &tag, const std::string &name, int index) { + /* Don't need to strlcpy() tag and name anymore, ReadConf() takes const char* */ char val[MAXBUF]; - char t[MAXBUF]; - char n[MAXBUF]; - strlcpy(t,tag.c_str(),MAXBUF); - strlcpy(n,name.c_str(),MAXBUF); - int res = Config->ReadConf(cache,t,n,index,val); + int res = Config->ReadConf(cache, tag.c_str(), name.c_str(), index, val); if (!res) { this->error = CONF_VALUE_NOT_FOUND; @@ -903,31 +900,29 @@ std::string ConfigReader::ReadValue(std::string tag, std::string name, int index return val; } -bool ConfigReader::ReadFlag(std::string tag, std::string name, int index) +bool ConfigReader::ReadFlag(const std::string &tag, const std::string &name, int index) { + /* Don't need to strlcpy() tag and name anymore, ReadConf() takes const char* */ char val[MAXBUF]; - char t[MAXBUF]; - char n[MAXBUF]; - strlcpy(t,tag.c_str(),MAXBUF); - strlcpy(n,name.c_str(),MAXBUF); - int res = Config->ReadConf(cache,t,n,index,val); + std::string s; + + int res = Config->ReadConf(cache, tag.c_str(), name.c_str(), index, val); if (!res) { this->error = CONF_VALUE_NOT_FOUND; return false; } - std::string s = val; + + s = val; + return ((s == "yes") || (s == "YES") || (s == "true") || (s == "TRUE") || (s == "1")); } -long ConfigReader::ReadInteger(std::string tag, std::string name, int index, bool needs_unsigned) +long ConfigReader::ReadInteger(const std::string &tag, const std::string &name, int index, bool needs_unsigned) { char val[MAXBUF]; - char t[MAXBUF]; - char n[MAXBUF]; - strlcpy(t,tag.c_str(),MAXBUF); - strlcpy(n,name.c_str(),MAXBUF); - int res = Config->ReadConf(cache,t,n,index,val); + + int res = Config->ReadConf(cache, tag.c_str(), name.c_str(), index, val); if (!res) { this->error = CONF_VALUE_NOT_FOUND; @@ -958,43 +953,47 @@ long ConfigReader::GetError() void ConfigReader::DumpErrors(bool bail, userrec* user) { - if (bail) - { - printf("There were errors in your configuration:\n%s",errorlog->str().c_str()); - exit(0); - } - else - { - char dataline[1024]; - if (user) - { - WriteServ(user->fd,"NOTICE %s :There were errors in the configuration file:",user->nick); - while (!errorlog->eof()) - { - errorlog->getline(dataline,1024); - WriteServ(user->fd,"NOTICE %s :%s",user->nick,dataline); - } - } - else - { - WriteOpers("There were errors in the configuration file:",user->nick); - while (!errorlog->eof()) - { - errorlog->getline(dataline,1024); - WriteOpers(dataline); - } - } - return; - } + if (bail) + { + printf("There were errors in your configuration:\n%s",errorlog->str().c_str()); + exit(0); + } + else + { + char dataline[1024]; + + if (user) + { + WriteServ(user->fd,"NOTICE %s :There were errors in the configuration file:",user->nick); + + while (!errorlog->eof()) + { + errorlog->getline(dataline,1024); + WriteServ(user->fd,"NOTICE %s :%s",user->nick,dataline); + } + } + else + { + WriteOpers("There were errors in the configuration file:",user->nick); + + while (!errorlog->eof()) + { + errorlog->getline(dataline,1024); + WriteOpers(dataline); + } + } + + return; + } } -int ConfigReader::Enumerate(std::string tag) +int ConfigReader::Enumerate(const std::string &tag) { return Config->EnumConf(cache,tag.c_str()); } -int ConfigReader::EnumerateValues(std::string tag, int index) +int ConfigReader::EnumerateValues(const std::string &tag, int index) { return Config->EnumValues(cache, tag.c_str(), index); } @@ -1005,7 +1004,7 @@ bool ConfigReader::Verify() } -FileReader::FileReader(std::string filename) +FileReader::FileReader(const std::string &filename) { file_cache c; readfile(c,filename.c_str()); @@ -1016,7 +1015,7 @@ FileReader::FileReader() { } -void FileReader::LoadFile(std::string filename) +void FileReader::LoadFile(const std::string &filename) { file_cache c; readfile(c,filename.c_str()); @@ -1030,14 +1029,7 @@ FileReader::~FileReader() bool FileReader::Exists() { - if (fc.size() == 0) - { - return(false); - } - else - { - return(true); - } + return (!(fc.size() == 0)); } std::string FileReader::GetLine(int x) @@ -1057,5 +1049,3 @@ std::vector<Module*> modules(255); std::vector<ircd_module*> factory(255); int MODCOUNT = -1; - - diff --git a/src/socket.cpp b/src/socket.cpp index 923ca5848..d4cdb0a18 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -59,10 +59,9 @@ InspSocket::InspSocket(int newfd, char* ip) socket_ref[this->fd] = this; } -InspSocket::InspSocket(std::string ahost, int aport, bool listening, unsigned long maxtime) +InspSocket::InspSocket(const std::string &ahost, int aport, bool listening, unsigned long maxtime) + : fd(-1), host(ahost) { - this->fd = -1; - this->host = ahost; this->outbuffer.clear(); if (listening) { if ((this->fd = OpenTCPSocket()) == ERROR) @@ -242,7 +241,7 @@ char* InspSocket::Read() // It will either write all of the data, or an undefined amount. // If an undefined amount is written the connection has failed // and should be aborted. -int InspSocket::Write(std::string data) +int InspSocket::Write(const std::string &data) { /* Try and append the data to the back of the queue, and send it on its way */ @@ -372,4 +371,3 @@ InspSocket::~InspSocket() { this->Close(); } - |