]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/configreader.cpp
Make irc::spacify take 'const char*' instead of 'char*'
[user/henk/code/inspircd.git] / src / configreader.cpp
index 8ba19968631991e14ce2f24a5916b1129fc1f10e..24e76eb490e964cda6ca2783625f52b8be7f1fd2 100644 (file)
@@ -2,14 +2,11 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
- *                    E-mail:
- *             <brain@chatspike.net>
- *             <Craig@chatspike.net>
- *     
- * Written by Craig Edwards, Craig McLure, and others.
+ *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
+ * See: http://www.inspircd.org/wiki/index.php/Credits
+ *
  * This program is free but copyrighted software; see
- *         the file COPYING for details.
+ *            the file COPYING for details.
  *
  * ---------------------------------------------------
  */
@@ -57,6 +54,12 @@ Module* ServerConfig::GetIOHook(int port)
        return (x != IOHookModule.end() ? x->second : NULL);
 }
 
+Module* ServerConfig::GetIOHook(InspSocket* is)
+{
+       std::map<InspSocket*,Module*>::iterator x = SocketIOHookModule.find(is);
+       return (x != SocketIOHookModule.end() ? x->second : NULL);
+}
+
 bool ServerConfig::AddIOHook(int port, Module* iomod)
 {
        if (!GetIOHook(port))
@@ -66,8 +69,23 @@ bool ServerConfig::AddIOHook(int port, Module* iomod)
        }
        else
        {
-               ModuleException err("Port already hooked by another module");
-               throw(err);
+               throw ModuleException("Port already hooked by another module");
+               return false;
+       }
+}
+
+bool ServerConfig::AddIOHook(Module* iomod, InspSocket* is)
+{
+       if (!GetIOHook(is))
+       {
+               ServerInstance->Log(DEBUG,"Hooked inspsocket %08x", is);
+               SocketIOHookModule[is] = iomod;
+               is->IsIOHooked = true;
+               return true;
+       }
+       else
+       {
+               throw ModuleException("InspSocket derived class already hooked by another module");
                return false;
        }
 }
@@ -83,6 +101,48 @@ bool ServerConfig::DelIOHook(int port)
        return false;
 }
 
+bool ServerConfig::DelIOHook(InspSocket* is)
+{
+       std::map<InspSocket*,Module*>::iterator x = SocketIOHookModule.find(is);
+       if (x != SocketIOHookModule.end())
+       {
+               SocketIOHookModule.erase(x);
+               return true;
+       }
+       return false;
+}
+
+void ServerConfig::Update005()
+{
+       std::stringstream out(data005);
+       std::string token;
+       std::string line5;
+       int token_counter = 0;
+       isupport.clear();
+       while (out >> token)
+       {
+               line5 = line5 + token + " ";
+               token_counter++;
+               if (token_counter >= 13)
+               {
+                       char buf[MAXBUF];
+                       snprintf(buf, MAXBUF, "%s:are supported by this server", line5.c_str());
+                       isupport.push_back(buf);
+                       line5 = "";
+                       token_counter = 0;
+               }
+       }
+       char buf[MAXBUF];
+       snprintf(buf, MAXBUF, "%s:are supported by this server", line5.c_str());
+       isupport.push_back(buf);
+}
+
+void ServerConfig::Send005(userrec* user)
+{
+       for (std::vector<std::string>::iterator line = ServerInstance->Config->isupport.begin(); line != ServerInstance->Config->isupport.end(); line++)
+               user->WriteServ("005 %s %s", user->nick, line->c_str());
+}
+
 bool ServerConfig::CheckOnce(char* tag, bool bail, userrec* user)
 {
        int count = ConfValueEnum(this->config_data, tag);
@@ -564,6 +624,7 @@ void ServerConfig::Read(bool bail, userrec* user)
                {"whowas",              "groupsize",                    new ValueContainerInt  (&this->WhoWasGroupSize),        DT_INTEGER, NoValidation},
                {"whowas",              "maxgroups",                    new ValueContainerInt  (&this->WhoWasMaxGroups),        DT_INTEGER, NoValidation},
                {"whowas",              "maxkeep",                      new ValueContainerChar (maxkeep),                       DT_CHARPTR, ValidateWhoWas},
+               {"die",                 "value",                        new ValueContainerChar (this->DieValue),                DT_CHARPTR, NoValidation},
                {NULL}
        };
 
@@ -902,18 +963,24 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, const char* filename, std::o
                if((ch == '#') && !in_quote)
                        in_comment = true;
                
-               if(((ch == '\n') || (ch == '\r')) && in_quote)
+               /*if(((ch == '\n') || (ch == '\r')) && in_quote)
                {
                        errorstream << "Got a newline within a quoted section, this is probably a typo: " << filename << ":" << linenumber << std::endl;
                        return false;
-               }
+               }*/
                
                switch(ch)
                {
                        case '\n':
+                               if (in_quote)
+                               {
+                                       ServerInstance->Log(DEBUG, "Got \\n inside value");
+                                       line += '\n';
+                               }
                                linenumber++;
                        case '\r':
-                               in_comment = false;
+                               if (!in_quote)
+                                       in_comment = false;
                        case '\0':
                                continue;
                        case '\t':
@@ -951,7 +1018,8 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, const char* filename, std::o
                        }
                }
 
-               line += ch;
+               if (ch != '\r')
+                       line += ch;
                
                if(ch == '<')
                {
@@ -1051,8 +1119,8 @@ bool ServerConfig::ParseLine(ConfigDataHash &target, std::string &line, long lin
        bool in_quote;
        
        got_name = got_key = in_quote = false;
-       
-       // std::cout << "ParseLine(data, '" << line << "', " << linenumber << ", stream)" << std::endl;
+
+       //std::cout << "ParseLine(data, '" << line << "', " << linenumber << ", stream)" << std::endl;
        
        for(std::string::iterator c = line.begin(); c != line.end(); c++)
        {
@@ -1111,6 +1179,16 @@ bool ServerConfig::ParseLine(ConfigDataHash &target, std::string &line, long lin
                                                current_value += *c;
                                        continue;
                                }
+                               else if ((*c == '\n') && (in_quote))
+                               {
+                                       /* Got a 'real' \n, treat it as part of the value */
+                                       current_value += '\n';
+                                       continue;
+                               }
+                               else if ((*c == '\r') && (in_quote))
+                                       /* Got a \r, drop it */
+                                       continue;
+
                                if (*c == '"')
                                {
                                        if (!in_quote)
@@ -1122,7 +1200,7 @@ bool ServerConfig::ParseLine(ConfigDataHash &target, std::string &line, long lin
                                        {
                                                /* Leaving quotes, we have the value */
                                                results.push_back(KeyVal(current_key, current_value));
-                                               
+
                                                // std::cout << "<" << tagname << ":" << current_key << "> " << current_value << std::endl;
                                                
                                                in_quote = false;