The InspIRCd Project
Home | Developers | Wiki | Forums | Bug Tracker | SVN | Download
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

configreader.h

Go to the documentation of this file.
00001 /*       +------------------------------------+
00002  *       | Inspire Internet Relay Chat Daemon |
00003  *       +------------------------------------+
00004  *
00005  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
00006  * See: http://www.inspircd.org/wiki/index.php/Credits
00007  *
00008  * This program is free but copyrighted software; see
00009  *            the file COPYING for details.
00010  *
00011  * ---------------------------------------------------
00012  */
00013 
00014 #ifndef INSPIRCD_CONFIGREADER
00015 #define INSPIRCD_CONFIGREADER
00016 
00017 /* handy defines */
00018 
00022 #define CHANOPS_EXEMPT(s, m) (s->Config->ExemptChanOps[(unsigned char)m])
00023 
00024 #include <sstream>
00025 #include <string>
00026 #include <vector>
00027 #include <map>
00028 #include "inspircd.h"
00029 #include "modules.h"
00030 #include "socketengine.h"
00031 #include "socket.h"
00032 
00033 /* Required forward definitions */
00034 class ServerConfig;
00035 class InspIRCd;
00036 class BufferedSocket;
00037 
00040 enum ConfigDataType
00041 {
00042         DT_NOTHING       = 0,           /* No data */
00043         DT_INTEGER       = 1,           /* Integer */
00044         DT_CHARPTR       = 2,           /* Char pointer */
00045         DT_BOOLEAN       = 3,           /* Boolean */
00046         DT_HOSTNAME      = 4,           /* Hostname syntax */
00047         DT_NOSPACES      = 5,           /* No spaces */
00048         DT_IPADDRESS     = 6,           /* IP address (v4, v6) */
00049         DT_CHANNEL       = 7,           /* Channel name */
00050         DT_ALLOW_WILD    = 64,          /* Allow wildcards/CIDR in DT_IPADDRESS */
00051         DT_ALLOW_NEWLINE = 128,         /* New line characters allowed in DT_CHARPTR */
00052         DT_BOOTONLY      = 256          /* Can only be set on startup, not on rehash */
00053 };
00054 
00057 #define MAX_VALUES_PER_TAG 18
00058 
00065 class ValueItem
00066 {
00068         std::string v;
00069  public:
00071         ValueItem(int value);
00073         ValueItem(bool value);
00075         ValueItem(const char* value);
00077         void Set(const char* val);
00079         void Set(int value);
00081         int GetInteger();
00083         char* GetString();
00085         bool GetBool();
00086 };
00087 
00091 class ValueContainerBase
00092 {
00093  public:
00095         ValueContainerBase() { }
00097         virtual ~ValueContainerBase() { }
00098 };
00099 
00108 template<typename T> class ValueContainer : public ValueContainerBase
00109 {
00111         T val;
00112  public:
00113 
00115         ValueContainer()
00116         {
00117                 val = NULL;
00118         }
00119 
00121         ValueContainer(T Val)
00122         {
00123                 val = Val;
00124         }
00125 
00127         void Set(T newval, size_t s)
00128         {
00129                 memcpy(val, newval, s);
00130         }
00131 };
00132 
00135 typedef ValueContainer<bool*> ValueContainerBool;
00136 
00140 typedef ValueContainer<unsigned int*> ValueContainerUInt;
00141 
00145 typedef ValueContainer<char*> ValueContainerChar;
00146 
00150 typedef ValueContainer<int*> ValueContainerInt;
00151 
00152 typedef ValueContainer<size_t*> ValueContainerST;
00153 
00156 typedef std::deque<ValueItem> ValueList;
00157 
00160 typedef bool (*Validator)(ServerConfig* conf, const char*, const char*, ValueItem&);
00163 typedef bool (*MultiValidator)(ServerConfig* conf, const char*, char**, ValueList&, int*);
00166 typedef bool (*MultiNotify)(ServerConfig* conf, const char*);
00167 
00170 struct InitialConfig
00171 {
00173         const char* tag;
00175         const char* value;
00177         const char* default_value;
00179         ValueContainerBase* val;
00181         int datatype;
00183         Validator validation_function;
00184 };
00185 
00186 struct Deprecated
00187 {
00188         const char* tag;
00189         const char* value;
00190         const char* reason;
00191 };
00192 
00196 struct MultiConfig
00197 {
00199         const char*     tag;
00201         const char*     items[MAX_VALUES_PER_TAG];
00203         const char* items_default[MAX_VALUES_PER_TAG];
00205         int             datatype[MAX_VALUES_PER_TAG];
00207         MultiNotify     init_function;
00209         MultiValidator  validation_function;
00211         MultiNotify     finish_function;
00212 };
00213 
00216 typedef std::map<irc::string,char*> opertype_t;
00217 
00218 struct operclass_data : public Extensible
00219 {
00220         char* commandlist;
00221         char* cmodelist;
00222         char* umodelist;
00223 };
00224 
00227 typedef std::map<irc::string, operclass_data> operclass_t;
00228 
00229 
00230 class ServerLimits : public Extensible
00231 {
00232  public:
00233         size_t NickMax;
00234         size_t ChanMax;
00235         size_t MaxModes;
00236         size_t IdentMax;
00237         size_t MaxQuit;
00238         size_t MaxTopic;
00239         size_t MaxKick;
00240         size_t MaxGecos;
00241         size_t MaxAway;
00242 
00243         /* Creating the class initialises it to the defaults
00244          * as in 1.1's ./configure script. Reading other values
00245          * from the config will change these values.
00246          */
00247         ServerLimits() : NickMax(31), ChanMax(64), MaxModes(20), IdentMax(12), MaxQuit(255), MaxTopic(307), MaxKick(255), MaxGecos(128), MaxAway(200)
00248         {
00249         }
00250 
00251         void Finalise()
00252         {
00253                 NickMax++;
00254                 ChanMax++;
00255                 IdentMax++;
00256                 MaxQuit++;
00257                 MaxTopic++;
00258                 MaxKick++;
00259                 MaxGecos++;
00260                 MaxAway++;
00261         }
00262 };
00263 
00269 class CoreExport ServerConfig : public Extensible
00270 {
00271   private:
00274         InspIRCd* ServerInstance;
00275 
00281         std::vector<std::string> include_stack;
00282 
00287         bool ParseLine(ConfigDataHash &target, const std::string &filename, std::string &line, long &linenumber, std::ostringstream &errorstream);
00288 
00291         bool CheckOnce(const char* tag, ConfigDataHash &newconf);
00292 
00293  public:
00296         bool DoPipe(ConfigDataHash &target, const std::string &file, std::ostringstream &errorstream);
00297 
00300         bool DoInclude(ConfigDataHash &target, const std::string &file, std::ostringstream &errorstream);
00301 
00302         User* RehashUser;
00303 
00304         std::string RehashParameter;
00305 
00306         std::ostringstream errstr;
00307 
00308         ConfigDataHash newconfig;
00309 
00310         std::map<std::string, std::istream*> IncludedFiles;
00311 
00313         enum InviteAnnounceState { INVITE_ANNOUNCE_NONE, INVITE_ANNOUNCE_ALL, INVITE_ANNOUNCE_OPS, INVITE_ANNOUNCE_DYNAMIC };
00314 
00316         Validator DNSServerValidator;
00317 
00318         InspIRCd* GetInstance();
00319 
00320         int DoDownloads();
00321           
00325         ConfigDataHash config_data;
00326 
00327         ServerLimits Limits;
00328 
00332         int c_ipv4_range;
00333 
00337         int c_ipv6_range;
00338 
00341         int WhoWasGroupSize;
00342 
00346         int WhoWasMaxGroups;
00347 
00350         int WhoWasMaxKeep;
00351 
00355         char ServerName[MAXBUF];
00356 
00359         char MoronBanner[MAXBUF];
00360         
00361         /* Holds the network name the local server
00362          * belongs to. This is an arbitary field defined
00363          * by the administrator.
00364          */
00365         char Network[MAXBUF];
00366 
00370         char ServerDesc[MAXBUF];
00371 
00375         char AdminName[MAXBUF];
00376 
00380         char AdminEmail[MAXBUF];
00381 
00385         char AdminNick[MAXBUF];
00386 
00389         char diepass[MAXBUF];
00390 
00393         char restartpass[MAXBUF];
00394 
00397         char powerhash[MAXBUF];
00398 
00402         char motd[MAXBUF];
00403 
00407         char rules[MAXBUF];
00408 
00411         char PrefixQuit[MAXBUF];
00412 
00415         char SuffixQuit[MAXBUF];
00416 
00419         char FixedQuit[MAXBUF];
00420 
00423         char PrefixPart[MAXBUF];
00424 
00427         char SuffixPart[MAXBUF];
00428 
00431         char FixedPart[MAXBUF];
00432 
00436         char DieValue[MAXBUF];
00437 
00440         char DNSServer[MAXBUF];
00441 
00444         bool DisabledDontExist;
00445 
00450         char DisabledCommands[MAXBUF];
00451 
00455         char DisabledUModes[64];
00456 
00459         char DisabledCModes[64];
00460 
00466         char ModPath[1024];
00467 
00471         char MyExecutable[1024];
00472 
00479         FILE *log_file;
00480 
00486         bool nofork;
00487         
00494         bool forcedebug;
00495         
00504         bool writelog;
00505 
00509         bool AllowHalfop;
00510 
00515         bool HideModeLists[256];
00516 
00520         bool ExemptChanOps[256];
00521 
00525         int dns_timeout;
00526 
00531         int NetBufferSize;
00532 
00536         int MaxConn;
00537 
00542         unsigned int SoftLimit;
00543 
00547         unsigned int MaxTargets;
00548 
00552         int MaxWhoResults;
00553 
00556         int debugging;
00557 
00561         int DieDelay;
00562 
00565         bool HideSplits;
00566 
00570         bool HideBans;
00571 
00574         InviteAnnounceState AnnounceInvites;
00575 
00579         bool OperSpyWhois;
00580 
00583         char HideWhoisServer[MAXBUF];
00584 
00587         char HideKillsServer[MAXBUF];
00588 
00591         file_cache MOTD;
00592 
00595         file_cache RULES;
00596 
00600         char PID[1024];
00601 
00604         ClassVector Classes;
00605 
00608         std::vector<ListenSocket*> ports;
00609 
00612         std::map<BufferedSocket*, Module*> SocketIOHookModule;
00613 
00618         std::string data005;
00619 
00622         std::vector<std::string> isupport;
00623 
00627         char UserStats[MAXBUF];
00628         
00631         std::string logpath;
00632 
00635         char DefaultModes[MAXBUF];
00636 
00639         char CustomVersion[MAXBUF];
00640 
00643         std::map<irc::string, bool> ulines;
00644 
00647         std::map<std::string, int> maxbans;
00648 
00651         std::string MyDir;
00652 
00655         bool NoUserDns;
00656 
00659         bool SyntaxHints;
00660 
00664         bool CycleHosts;
00665 
00669         bool UndernetMsgPrefix;
00670 
00674         bool FullHostInTopic;
00675 
00678         opertype_t opertypes;
00679 
00682         operclass_t operclass;
00683 
00686         char** argv;
00687 
00690         int argc;
00691 
00694         unsigned int MaxChans;
00695 
00698         unsigned int OperMaxChans;
00699 
00705         char sid[MAXBUF];
00706 
00710         bool TestSuite;
00711 
00714         ServerConfig(InspIRCd* Instance);
00715 
00718         void ClearStack();
00719 
00722         std::string GetSID();
00723 
00726         void Update005();
00727 
00730         void Send005(User* user);
00731 
00736         void Read(bool bail, User* user);
00737 
00740         bool ReadFile(file_cache &F, const char* fname);
00741 
00742         /* Returns true if the given string starts with a windows drive letter
00743          */
00744         bool StartsWithWindowsDriveLetter(const std::string &path);
00745 
00752         void ReportConfigError(const std::string &errormessage, bool bail, User* user);
00753 
00757         bool LoadConf(ConfigDataHash &target, FILE* &conf, const char* filename, std::ostringstream &errorstream);
00758 
00762         bool LoadConf(ConfigDataHash &target, FILE* &conf, const std::string &filename, std::ostringstream &errorstream);
00763         
00764         /* Both these return true if the value existed or false otherwise */
00765         
00768         bool ConfValue(ConfigDataHash &target, const char* tag, const char* var, int index, char* result, int length, bool allow_linefeeds = false);
00771         bool ConfValue(ConfigDataHash &target, const char* tag, const char* var, const char* default_value, int index, char* result, int length, bool allow_linefeeds = false);
00772 
00775         bool ConfValue(ConfigDataHash &target, const std::string &tag, const std::string &var, int index, std::string &result, bool allow_linefeeds = false);
00778         bool ConfValue(ConfigDataHash &target, const std::string &tag, const std::string &var, const std::string &default_value, int index, std::string &result, bool allow_linefeeds = false);
00779         
00782         bool ConfValueInteger(ConfigDataHash &target, const char* tag, const char* var, int index, int &result);
00785         bool ConfValueInteger(ConfigDataHash &target, const char* tag, const char* var, const char* default_value, int index, int &result);
00788         bool ConfValueInteger(ConfigDataHash &target, const std::string &tag, const std::string &var, int index, int &result);
00791         bool ConfValueInteger(ConfigDataHash &target, const std::string &tag, const std::string &var, const std::string &default_value, int index, int &result);
00792         
00795         bool ConfValueBool(ConfigDataHash &target, const char* tag, const char* var, int index);
00798         bool ConfValueBool(ConfigDataHash &target, const char* tag, const char* var, const char* default_value, int index);
00801         bool ConfValueBool(ConfigDataHash &target, const std::string &tag, const std::string &var, int index);
00804         bool ConfValueBool(ConfigDataHash &target, const std::string &tag, const std::string &var, const std::string &default_value, int index);
00805         
00808         int ConfValueEnum(ConfigDataHash &target, const char* tag);
00811         int ConfValueEnum(ConfigDataHash &target, const std::string &tag);
00812         
00815         int ConfVarEnum(ConfigDataHash &target, const char* tag, int index);
00818         int ConfVarEnum(ConfigDataHash &target, const std::string &tag, int index);
00819 
00820         void ValidateHostname(const char* p, const std::string &tag, const std::string &val);
00821 
00822         void ValidateIP(const char* p, const std::string &tag, const std::string &val, bool wild);
00823 
00824         void ValidateNoSpaces(const char* p, const std::string &tag, const std::string &val);
00825 
00830         Module* GetIOHook(BufferedSocket* is);
00831 
00838         bool AddIOHook(Module* iomod, BufferedSocket* is);
00839 
00844         bool DelIOHook(BufferedSocket* is);
00845 
00849         std::string GetFullProgDir();
00850 
00855         static bool DirValid(const char* dirandfile);
00856 
00861         static char* CleanFilename(char* name);
00862 
00867         static bool FileExists(const char* file);
00868 
00871         bool InvBypassModes;
00872 
00873 };
00874 
00877 CoreExport bool InitializeDisabledCommands(const char* data, InspIRCd* ServerInstance);
00878 
00881 bool InitTypes(ServerConfig* conf, const char* tag);
00882 
00885 bool InitClasses(ServerConfig* conf, const char* tag);
00886 
00889 bool DoType(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
00890 
00893 bool DoClass(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
00894 
00897 bool DoneClassesAndTypes(ServerConfig* conf, const char* tag);
00898 
00899 
00900 
00903 bool InitXLine(ServerConfig* conf, const char* tag);
00904  
00907 bool DoZLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
00908 
00911 bool DoQLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
00912 
00915 bool DoKLine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
00916 
00919 bool DoELine(ServerConfig* conf, const char* tag, char** entries, ValueList &values, int* types);
00920 
00921 
00922 
00923 
00924 #endif
00925