]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/inspircd_io.cpp
Remove uneccessary socket includes now included in socket.h
[user/henk/code/inspircd.git] / src / inspircd_io.cpp
index edb9702abd4454a5f50abd2a9750bcc84dfc2e6c..723e5a48a4cce88a51d31e2099724cb312b8b184 100644 (file)
@@ -52,8 +52,8 @@ ServerConfig::ServerConfig()
        *CustomVersion = *motd = *rules = *PrefixQuit = *DieValue = *DNSServer = '\0';
        *OperOnlyStats = *ModPath = *MyExecutable = *DisabledCommands = *PID = '\0';
        log_file = NULL;
-       OperSpyWhois = nofork = HideBans = HideSplits = false;
-       AllowHalfop = true;
+       forcedebug = OperSpyWhois = nofork = HideBans = HideSplits = false;
+       writelog = AllowHalfop = true;
        dns_timeout = DieDelay = 5;
        MaxTargets = 20;
        NetBufferSize = 10240;
@@ -267,24 +267,6 @@ bool ValidateServerName(const char* tag, const char* value, void* data)
        return true;
 }
 
-bool ValidateNetworkName(const char* tag, const char* value, void* data)
-{
-       char* x = (char*)data;
-
-       log(DEFAULT,"<server:network> '%s'",x);
-
-       return true;
-}
-
-bool ValidateServerDesc(const char* tag, const char* value, void* data)
-{
-       char* x = (char*)data;
-
-       log(DEFAULT,"<server:description> '%s'",x);
-
-       return true;
-}
-
 bool ValidateNetBufferSize(const char* tag, const char* value, void* data)
 {
        if ((!Config->NetBufferSize) || (Config->NetBufferSize > 65535) || (Config->NetBufferSize < 1024))
@@ -540,11 +522,11 @@ void ServerConfig::Read(bool bail, userrec* user)
 
        /* These tags can occur ONCE or not at all */
        static InitialConfig Values[] = {
-               {"options",             "softlimit",            &this->SoftLimit,               DT_INTEGER, ValidateSoftLimit},
-               {"options",             "somaxconn",            &this->MaxConn,                 DT_INTEGER, ValidateMaxConn},
+               {"options",             "softlimit",                    &this->SoftLimit,               DT_INTEGER, ValidateSoftLimit},
+               {"options",             "somaxconn",                    &this->MaxConn,                 DT_INTEGER, ValidateMaxConn},
                {"server",              "name",                         &this->ServerName,              DT_CHARPTR, ValidateServerName},
-               {"server",              "description",          &this->ServerDesc,              DT_CHARPTR, ValidateServerDesc},
-               {"server",              "network",                      &this->Network,                 DT_CHARPTR, ValidateNetworkName},
+               {"server",              "description",                  &this->ServerDesc,              DT_CHARPTR, NoValidation},
+               {"server",              "network",                      &this->Network,                 DT_CHARPTR, NoValidation},
                {"admin",               "name",                         &this->AdminName,               DT_CHARPTR, NoValidation},
                {"admin",               "email",                        &this->AdminEmail,              DT_CHARPTR, NoValidation},
                {"admin",               "nick",                         &this->AdminNick,               DT_CHARPTR, NoValidation},
@@ -552,25 +534,25 @@ void ServerConfig::Read(bool bail, userrec* user)
                {"files",               "rules",                        &this->rules,                   DT_CHARPTR, ValidateRules},
                {"power",               "diepass",                      &this->diepass,                 DT_CHARPTR, NoValidation},      
                {"power",               "pauseval",                     &this->DieDelay,                DT_INTEGER, NoValidation},
-               {"power",               "restartpass",          &this->restartpass,             DT_CHARPTR, NoValidation},
-               {"options",             "prefixquit",           &this->PrefixQuit,              DT_CHARPTR, NoValidation},
+               {"power",               "restartpass",                  &this->restartpass,             DT_CHARPTR, NoValidation},
+               {"options",             "prefixquit",                   &this->PrefixQuit,              DT_CHARPTR, NoValidation},
                {"die",                 "value",                        &this->DieValue,                DT_CHARPTR, NoValidation},
-               {"options",             "loglevel",                     &debug,                                 DT_CHARPTR, ValidateLogLevel},
-               {"options",             "netbuffersize",        &this->NetBufferSize,   DT_INTEGER, ValidateNetBufferSize},
-               {"options",             "maxwho",                       &this->MaxWhoResults,   DT_INTEGER, ValidateMaxWho},
-               {"options",             "allowhalfop",          &this->AllowHalfop,             DT_BOOLEAN, NoValidation},
+               {"options",             "loglevel",                     &debug,                         DT_CHARPTR, ValidateLogLevel},
+               {"options",             "netbuffersize",                &this->NetBufferSize,           DT_INTEGER, ValidateNetBufferSize},
+               {"options",             "maxwho",                       &this->MaxWhoResults,           DT_INTEGER, ValidateMaxWho},
+               {"options",             "allowhalfop",                  &this->AllowHalfop,             DT_BOOLEAN, NoValidation},
                {"dns",                 "server",                       &this->DNSServer,               DT_CHARPTR, ValidateDnsServer},
                {"dns",                 "timeout",                      &this->dns_timeout,             DT_INTEGER, ValidateDnsTimeout},
-               {"options",             "moduledir",            &this->ModPath,                 DT_CHARPTR, ValidateModPath},
-               {"disabled",    "commands",                     &this->DisabledCommands,DT_CHARPTR, NoValidation},
-               {"options",             "operonlystats",        &this->OperOnlyStats,   DT_CHARPTR, NoValidation},
-               {"options",             "customversion",        &this->CustomVersion,   DT_CHARPTR, NoValidation},
-               {"options",             "hidesplits",           &this->HideSplits,              DT_BOOLEAN, NoValidation},
+               {"options",             "moduledir",                    &this->ModPath,                 DT_CHARPTR, ValidateModPath},
+               {"disabled",            "commands",                     &this->DisabledCommands,        DT_CHARPTR, NoValidation},
+               {"options",             "operonlystats",                &this->OperOnlyStats,           DT_CHARPTR, NoValidation},
+               {"options",             "customversion",                &this->CustomVersion,           DT_CHARPTR, NoValidation},
+               {"options",             "hidesplits",                   &this->HideSplits,              DT_BOOLEAN, NoValidation},
                {"options",             "hidebans",                     &this->HideBans,                DT_BOOLEAN, NoValidation},
-               {"options",             "hidewhois",            &this->HideWhoisServer, DT_CHARPTR, NoValidation},
-               {"options",             "operspywhois",         &this->OperSpyWhois,    DT_BOOLEAN, NoValidation},
+               {"options",             "hidewhois",                    &this->HideWhoisServer,         DT_CHARPTR, NoValidation},
+               {"options",             "operspywhois",                 &this->OperSpyWhois,            DT_BOOLEAN, NoValidation},
                {"options",             "tempdir",                      &this->TempDir,                 DT_CHARPTR, ValidateTempDir},
-               {"pid",                 "file",                         &this->PID,                             DT_CHARPTR, NoValidation},
+               {"pid",                 "file",                         &this->PID,                     DT_CHARPTR, NoValidation},
                {NULL}
        };
 
@@ -646,52 +628,29 @@ void ServerConfig::Read(bool bail, userrec* user)
                /* If we succeeded, set the ircd config to the new one */
                Config->config_data = newconfig;
                
-               int c = 1;
+/*             int c = 1;
                std::string last;
                
                for(ConfigDataHash::const_iterator i = this->config_data.begin(); i != this->config_data.end(); i++)
                {
-                       if(i->first != last)
-                               c = 1;
-                       else
-                               c++;
+                       c = (i->first != last) ? 1 : c+1;
+                       last = i->first;
                        
                        std::cout << "[" << i->first << " " << c << "/" << this->config_data.count(i->first) << "]" << std::endl;
                        
                        for(KeyValList::const_iterator j = i->second.begin(); j != i->second.end(); j++)
-                       {
                                std::cout << "\t" << j->first << " = " << j->second << std::endl;
-                       }
                        
                        std::cout << "[/" << i->first << " " << c << "/" << this->config_data.count(i->first) << "]" << std::endl;
-                       
-                       last = i->first;
                }
-               
-               for(ConfigDataHash::const_iterator i = this->config_data.begin(); i != this->config_data.end(); i++)
-               {
-                       std::cout << "There are " << ConfValueEnum(this->config_data, i->first) << " <" << i->first << "> tags" << std::endl;
-                       
-                       for(int j = 0; j < ConfValueEnum(this->config_data, i->first); j++)
-                       {
-                               std::string foo;
-                               if(ConfValue(this->config_data, i->first, "name", j, foo))
-                               {
-                                       std::cout << "<" << i->first << ":name> " << foo << std::endl;
-                               }
-                               else
-                               {
-                                       std::cout << "<" << i->first << ":name> undef" << std::endl;
-                               }
-                       }
-               }
-       }
+ */    }
        else
        {
                log(DEFAULT, "There were errors in your configuration:\n%s", errstr.str().c_str());
 
                if (bail)
                {
+                       /* Unneeded because of the log() aboive? */
                        printf("There were errors in your configuration:\n%s",errstr.str().c_str());
                        Exit(0);
                }
@@ -1042,9 +1001,12 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, const char* filename, std::o
                 */
                
                if((ch == '#') && !in_quote)
-               {
                        in_comment = true;
-                       continue;
+               
+               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)
@@ -1059,6 +1021,9 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, const char* filename, std::o
                                ch = ' ';
                }
                
+               if(in_comment)
+                       continue;
+               
                line += ch;
                
                if(ch == '<')
@@ -1067,7 +1032,7 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, const char* filename, std::o
                        {
                                if(!in_quote)
                                {
-                                       errorstream << "Got another opening < when the first one wasn't closed on line " << linenumber << std::endl;
+                                       errorstream << "Got another opening < when the first one wasn't closed: " << filename << ":" << linenumber << std::endl;
                                        return false;
                                }
                        }
@@ -1075,7 +1040,7 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, const char* filename, std::o
                        {
                                if(in_quote)
                                {
-                                       errorstream << "We're in a quote but outside a tag, interesting. Line: " << linenumber << std::endl;
+                                       errorstream << "We're in a quote but outside a tag, interesting. " << filename << ":" << linenumber << std::endl;
                                        return false;
                                }
                                else
@@ -1104,11 +1069,11 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, const char* filename, std::o
                        {
                                if(in_quote)
                                {
-                                       errorstream << "Found a (closing) \" outside a tag on line " << linenumber << std::endl;
+                                       errorstream << "Found a (closing) \" outside a tag: " << filename << ":" << linenumber << std::endl;
                                }
                                else
                                {
-                                       errorstream << "Found a (opening) \" outside a tag on line " << linenumber << std::endl;
+                                       errorstream << "Found a (opening) \" outside a tag: " << filename << ":" << linenumber << std::endl;
                                }
                        }
                }
@@ -1133,7 +1098,7 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, const char* filename, std::o
                                }
                                else
                                {
-                                       errorstream << "Got a closing > when we weren't inside a tag on line " << linenumber << std::endl;
+                                       errorstream << "Got a closing > when we weren't inside a tag: " << filename << ":" << linenumber << std::endl;
                                        return false;
                                }
                        }
@@ -1160,7 +1125,7 @@ bool ServerConfig::ParseLine(ConfigDataHash &target, std::string &line, long lin
        
        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++)
        {
@@ -1217,13 +1182,16 @@ 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;
+                                               
+                                               // std::cout << "<" << tagname << ":" << current_key << "> " << current_value << std::endl;
+                                               
                                                in_quote = false;
                                                got_key = false;
                                                
                                                if((tagname == "include") && (current_key == "file"))
                                                {
-                                                       this->DoInclude(target, current_value, errorstream);
+                                                       if(!this->DoInclude(target, current_value, errorstream))
+                                                               return false;
                                                }
                                                
                                                current_key.clear();
@@ -1243,8 +1211,6 @@ bool ServerConfig::ParseLine(ConfigDataHash &target, std::string &line, long lin
        
        /* Finished parsing the tag, add it to the config hash */
        target.insert(std::pair<std::string, KeyValList > (tagname, results));
-       std::cout << "Finished parsing " << tagname << std::endl;
-       std::cout << "Count of <server> tag: " << target.count("server") << std::endl;
        
        return true;
 }
@@ -1310,9 +1276,13 @@ bool ServerConfig::ConfValue(ConfigDataHash &target, const std::string &tag, con
                        }
                }
        }
+       else if(pos == 0)
+       {
+               log(DEBUG, "No <%s> tags in config file.", tag.c_str());
+       }
        else
        {
-               log(DEBUG, "ConfValue got an out-of-range index %d", index);
+               log(DEBUG, "ConfValue got an out-of-range index %d, there are only %d occurences of %s", pos, target.count(tag), tag.c_str());
        }
        
        return false;
@@ -1350,7 +1320,7 @@ bool ServerConfig::ConfValueBool(ConfigDataHash &target, const std::string &tag,
        
 int ServerConfig::ConfValueEnum(ConfigDataHash &target, const char* tag)
 {
-       return ConfValueEnum(target, std::string(tag));
+       return target.count(tag);
 }
 
 int ServerConfig::ConfValueEnum(ConfigDataHash &target, const std::string &tag)
@@ -1360,7 +1330,7 @@ int ServerConfig::ConfValueEnum(ConfigDataHash &target, const std::string &tag)
        
 int ServerConfig::ConfVarEnum(ConfigDataHash &target, const char* tag, int index)
 {
-       return 1;
+       return ConfVarEnum(target, std::string(tag), index);
 }
 
 int ServerConfig::ConfVarEnum(ConfigDataHash &target, const std::string &tag, int index)
@@ -1376,9 +1346,13 @@ int ServerConfig::ConfVarEnum(ConfigDataHash &target, const std::string &tag, in
                
                return iter->second.size();
        }
+       else if(pos == 0)
+       {
+               log(DEBUG, "No <%s> tags in config file.", tag.c_str());
+       }
        else
        {
-               log(DEBUG, "ConfVarEnum got an out-of-range index %d", index);
+               log(DEBUG, "ConfVarEnum got an out-of-range index %d, there are only %d occurences of %s", pos, target.count(tag), tag.c_str());
        }
        
        return 0;
@@ -1391,10 +1365,10 @@ int ServerConfig::ConfVarEnum(ConfigDataHash &target, const std::string &tag, in
  * a maximum of one second before it times out, using the DNS
  * server specified in the configuration file.
  */ 
-bool BindSocket(int sockfd, struct sockaddr_in client, struct sockaddr_in server, int port, char* addr)
+bool BindSocket(int sockfd, insp_sockaddr client, insp_sockaddr server, int port, char* addr)
 {
        memset(&server,0,sizeof(server));
-       struct in_addr addy;
+       insp_inaddr addy;
        bool resolved = false;
        char resolved_addr[128];
 
@@ -1489,7 +1463,7 @@ bool HasPort(int port, char* addr)
 int BindPorts(bool bail)
 {
        char configToken[MAXBUF], Addr[MAXBUF], Type[MAXBUF];
-       sockaddr_in client,server;
+       insp_sockaddr client, server;
        int clientportcount = 0;
        int BoundPortCount = 0;