* ---------------------------------------------------
*/
-using namespace std;
-
#include "inspircd_config.h"
#include "inspircd.h"
-#include "inspircd_io.h"
+#include "configreader.h"
#include <unistd.h>
#include <sys/errno.h>
#include <time.h>
#include <string>
-#ifdef GCC3
-#include <ext/hash_map>
-#else
-#include <hash_map>
-#endif
#include <map>
#include <sstream>
#include <vector>
extern ServerConfig *Config;
extern InspIRCd* ServerInstance;
extern int MODCOUNT;
-extern std::vector<Module*> modules;
-extern std::vector<ircd_module*> factory;
+extern ModuleList modules;
+extern FactoryList factory;
extern std::vector<InspSocket*> module_sockets;
extern std::vector<userrec*> local_users;
extern time_t TIME;
-class Server;
extern userrec* fd_ref_table[MAX_DESCRIPTORS];
-
extern user_hash clientlist;
extern chan_hash chanlist;
extern command_table cmdlist;
+
+class Server;
+
ExtModeList EMode;
// returns true if an extended mode character is in use
void Server::RemoveSocket(InspSocket* sock)
{
- for (std::vector<InspSocket*>::iterator a = module_sockets.begin(); a < module_sockets.end(); a++)
- {
- InspSocket* s = (InspSocket*)*a;
- if (s == sock)
+ for (std::vector<InspSocket*>::iterator a = module_sockets.begin(); a < module_sockets.end(); a++)
+ {
+ InspSocket* s = (InspSocket*)*a;
+ if (s == sock)
s->MarkAsClosed();
- }
+ }
}
long Server::PriorityAfter(const std::string &modulename)
}
ServerInstance->SE->DelFd(old_fd);
- shutdown(old_fd,2);
- close(old_fd);
+ shutdown(old_fd,2);
+ close(old_fd);
return true;
}
std::string oldhost = alive->host;
std::string oldident = alive->ident;
kill_link(alive,message.c_str());
- if (find(local_users.begin(),local_users.end(),alive) != local_users.end())
- {
+ if (find(local_users.begin(),local_users.end(),alive) != local_users.end())
+ {
local_users.erase(find(local_users.begin(),local_users.end(),alive));
log(DEBUG,"Delete local user");
- }
+ }
// Fix by brain - cant write the user until their fd table entry is updated
fd_ref_table[zombie->fd] = zombie;
Write(zombie->fd,":%s!%s@%s NICK %s",oldnick.c_str(),oldident.c_str(),oldhost.c_str(),zombie->nick);
- for (std::vector<ucrec*>::const_iterator i = zombie->chans.begin(); i != zombie->chans.end(); i++)
- {
- if (((ucrec*)(*i))->channel != NULL)
- {
+ for (std::vector<ucrec*>::const_iterator i = zombie->chans.begin(); i != zombie->chans.end(); i++)
+ {
+ if (((ucrec*)(*i))->channel != NULL)
+ {
chanrec* Ptr = ((ucrec*)(*i))->channel;
WriteFrom(zombie->fd,zombie,"JOIN %s",Ptr->name);
- if (Ptr->topicset)
- {
- WriteServ(zombie->fd,"332 %s %s :%s", zombie->nick, Ptr->name, Ptr->topic);
- WriteServ(zombie->fd,"333 %s %s %s %d", zombie->nick, Ptr->name, Ptr->setby, Ptr->topicset);
- }
- userlist(zombie,Ptr);
- WriteServ(zombie->fd,"366 %s %s :End of /NAMES list.", zombie->nick, Ptr->name);
- }
- }
+ if (Ptr->topicset)
+ {
+ WriteServ(zombie->fd,"332 %s %s :%s", zombie->nick, Ptr->name, Ptr->topic);
+ WriteServ(zombie->fd,"333 %s %s %s %d", zombie->nick, Ptr->name, Ptr->setby, Ptr->topicset);
+ }
+ userlist(zombie,Ptr);
+ WriteServ(zombie->fd,"366 %s %s :End of /NAMES list.", zombie->nick, Ptr->name);
+ }
+ }
if ((find(local_users.begin(),local_users.end(),zombie) == local_users.end()) && (zombie->fd != FD_MAGIC_NUMBER))
local_users.push_back(zombie);
return duration(delta.c_str());
}
+/*
+ * XXX why on *earth* is this in modules.cpp...? I think
+ * perhaps we need a server.cpp for Server:: stuff where possible. -- w00t
+ */
bool Server::IsValidMask(const std::string &mask)
{
char* dest = (char*)mask.c_str();
- if (strchr(dest,'!')==0)
- return false;
- if (strchr(dest,'@')==0)
- return false;
- for (char* i = dest; *i; i++)
- if (*i < 32)
- return false;
- for (char* i = dest; *i; i++)
- if (*i > 126)
- return false;
- unsigned int c = 0;
- for (char* i = dest; *i; i++)
- if (*i == '!')
- c++;
- if (c>1)
- return false;
- c = 0;
- for (char* i = dest; *i; i++)
- if (*i == '@')
- c++;
- if (c>1)
- return false;
+ if (strchr(dest,'!')==0)
+ return false;
+ if (strchr(dest,'@')==0)
+ return false;
+ for (char* i = dest; *i; i++)
+ if (*i < 32)
+ return false;
+ for (char* i = dest; *i; i++)
+ if (*i > 126)
+ return false;
+ unsigned int c = 0;
+ for (char* i = dest; *i; i++)
+ if (*i == '!')
+ c++;
+ if (c>1)
+ return false;
+ c = 0;
+ for (char* i = dest; *i; i++)
+ if (*i == '@')
+ c++;
+ if (c>1)
+ return false;
return true;
}
ConfigReader::ConfigReader()
{
- Config->ClearStack();
- this->cache = new std::stringstream(std::stringstream::in | std::stringstream::out);
- this->errorlog = new std::stringstream(std::stringstream::in | std::stringstream::out);
- this->readerror = Config->LoadConf(CONFIG_FILE,this->cache,this->errorlog);
- if (!this->readerror)
- this->error = CONF_FILE_NOT_FOUND;
+ // Config->ClearStack();
+
+ /* Is there any reason to load the entire config file again here?
+ * it's needed if they specify another config file, but using the
+ * default one we can just use the global config data - pre-parsed!
+ */
+ //~ this->cache = new std::stringstream(std::stringstream::in | std::stringstream::out);
+ this->errorlog = new std::ostringstream(std::stringstream::in | std::stringstream::out);
+
+ //~ this->readerror = Config->LoadConf(CONFIG_FILE, this->cache,this->errorlog);
+ //~ if (!this->readerror)
+ //~ this->error = CONF_FILE_NOT_FOUND;
+
+ this->data = &Config->config_data;
+ this->privatehash = false;
}
ConfigReader::~ConfigReader()
{
- if (this->cache)
- delete this->cache;
+ //~ if (this->cache)
+ //~ delete this->cache;
if (this->errorlog)
delete this->errorlog;
+ if(this->privatehash)
+ delete this->data;
}
ConfigReader::ConfigReader(const std::string &filename)
{
Config->ClearStack();
- this->cache = new std::stringstream(std::stringstream::in | std::stringstream::out);
- this->errorlog = new std::stringstream(std::stringstream::in | std::stringstream::out);
- this->readerror = Config->LoadConf(filename.c_str(),this->cache,this->errorlog);
+
+ this->data = new ConfigDataHash;
+ this->privatehash = true;
+ this->errorlog = new std::ostringstream(std::stringstream::in | std::stringstream::out);
+ this->readerror = Config->LoadConf(*this->data, filename, *this->errorlog);
if (!this->readerror)
this->error = CONF_FILE_NOT_FOUND;
};
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];
- int res = Config->ReadConf(cache, tag.c_str(), name.c_str(), index, val);
- if (!res)
+ std::string result;
+
+ if (!Config->ConfValue(*this->data, tag, name, index, result))
{
this->error = CONF_VALUE_NOT_FOUND;
return "";
}
- return val;
+
+ return result;
}
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];
- 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;
- }
-
- s = val;
-
- return ((s == "yes") || (s == "YES") || (s == "true") || (s == "TRUE") || (s == "1"));
+ return Config->ConfValueBool(*this->data, tag, name, index);
}
long ConfigReader::ReadInteger(const std::string &tag, const std::string &name, int index, bool needs_unsigned)
{
- char val[MAXBUF];
-
- int res = Config->ReadConf(cache, tag.c_str(), name.c_str(), index, val);
- if (!res)
+ int result;
+
+ if(!Config->ConfValueInteger(*this->data, tag, name, index, result))
{
this->error = CONF_VALUE_NOT_FOUND;
return 0;
}
- for (char* i = val; *i; i++)
- {
- if (!isdigit(*i))
- {
- this->error = CONF_NOT_A_NUMBER;
- return 0;
- }
- }
- if ((needs_unsigned) && (atoi(val)<0))
+
+ if ((needs_unsigned) && (result < 0))
{
this->error = CONF_NOT_UNSIGNED;
return 0;
}
- return atoi(val);
+
+ return result;
}
long ConfigReader::GetError()
void ConfigReader::DumpErrors(bool bail, userrec* user)
{
+ /* XXX - Duplicated code */
+
if (bail)
{
- printf("There were errors in your configuration:\n%s",errorlog->str().c_str());
- exit(0);
+ printf("There were errors in your configuration:\n%s", this->errorlog->str().c_str());
+ Exit(0);
}
else
{
- char dataline[1024];
+ std::string errors = this->errorlog->str();
+ std::string::size_type start;
+ unsigned int prefixlen;
+ start = 0;
+ /* ":Config->ServerName NOTICE user->nick :" */
+ prefixlen = strlen(Config->ServerName) + strlen(user->nick) + 11;
+
if (user)
{
WriteServ(user->fd,"NOTICE %s :There were errors in the configuration file:",user->nick);
-
- while (!errorlog->eof())
+
+ while(start < errors.length())
{
- errorlog->getline(dataline,1024);
- WriteServ(user->fd,"NOTICE %s :%s",user->nick,dataline);
+ WriteServ(user->fd, "NOTICE %s :%s",user->nick, errors.substr(start, 510 - prefixlen).c_str());
+ start += 510 - prefixlen;
}
}
else
{
- WriteOpers("There were errors in the configuration file:",user->nick);
+ WriteOpers("There were errors in the configuration file:");
- while (!errorlog->eof())
+ while(start < errors.length())
{
- errorlog->getline(dataline,1024);
- WriteOpers(dataline);
+ WriteOpers(errors.substr(start, 360).c_str());
+ start += 360;
}
}
-
+
return;
}
}
int ConfigReader::Enumerate(const std::string &tag)
{
- return Config->EnumConf(cache,tag.c_str());
+ return Config->ConfValueEnum(*this->data, tag);
}
int ConfigReader::EnumerateValues(const std::string &tag, int index)
{
- return Config->EnumValues(cache, tag.c_str(), index);
+ return Config->ConfVarEnum(*this->data, tag, index);
}
bool ConfigReader::Verify()