00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef CONFIG_H
00014 #define CONFIG_H
00015
00016 #include "account.h"
00017 #include "regchannel.h"
00018 #include "users.h"
00019
00022 typedef std::pair<Anope::string, Anope::string> KeyVal;
00023
00026 typedef std::vector<KeyVal> KeyValList;
00027
00030 typedef std::multimap<Anope::string, KeyValList> ConfigDataHash;
00031
00032
00033
00036 enum ConfigDataType
00037 {
00038 DT_NOTHING,
00039 DT_INTEGER,
00040 DT_UINTEGER,
00041 DT_LUINTEGER,
00042 DT_STRING,
00043 DT_BOOLEAN,
00044 DT_HOSTNAME,
00045 DT_NOSPACES,
00046 DT_IPADDRESS,
00047 DT_TIME,
00048 DT_NORELOAD = 32,
00049 DT_ALLOW_WILD = 64,
00050 DT_ALLOW_NEWLINE = 128,
00051 DT_ALLOW_EMPTY = 256
00052 };
00053
00060 class CoreExport ValueItem
00061 {
00062 private:
00064 Anope::string v;
00065 public:
00067 ValueItem();
00069 ValueItem(int);
00071 ValueItem(bool);
00073 ValueItem(const Anope::string &);
00075 ValueItem(long);
00077 void Set(const Anope::string &);
00079 void Set(int);
00081 int GetInteger() const;
00083 const char *GetString() const;
00085 inline const Anope::string &GetValue() const { return v; }
00087 bool GetBool() const;
00088 };
00089
00093 class ValueContainerBase
00094 {
00095 public:
00097 ValueContainerBase() { }
00099 virtual ~ValueContainerBase() { }
00100 };
00101
00110 template<typename T> class ValueContainer : public ValueContainerBase
00111 {
00112 private:
00114 T val;
00115 public:
00117 ValueContainer() : ValueContainerBase(), val(NULL) { }
00119 ValueContainer(T Val) : ValueContainerBase(), val(Val) { }
00121 ValueContainer(const ValueContainer &Val) : ValueContainerBase(), val(Val.val) { }
00122 ValueContainer &operator=(const ValueContainer &Val)
00123 {
00124 val = Val.val;
00125 return *this;
00126 }
00128 void Set(const T newval, size_t s)
00129 {
00130 memcpy(val, newval, s);
00131 }
00132 };
00133
00136 template<> class ValueContainer<Anope::string *> : public ValueContainerBase
00137 {
00138 private:
00140 Anope::string *val;
00141 public:
00143 ValueContainer() : ValueContainerBase(), val(NULL) { }
00145 ValueContainer(Anope::string *Val) : ValueContainerBase(), val(Val) { }
00147 ValueContainer(const ValueContainer &Val) : ValueContainerBase(), val(Val.val) { }
00148 ValueContainer &operator=(const ValueContainer &Val)
00149 {
00150 val = Val.val;
00151 return *this;
00152 }
00153
00155 void Set(const Anope::string &newval)
00156 {
00157 *val = newval;
00158 }
00160 void Set(const char *newval)
00161 {
00162 *val = newval;
00163 }
00164 };
00165
00168 typedef ValueContainer<bool *> ValueContainerBool;
00169
00173 typedef ValueContainer<unsigned *> ValueContainerUInt;
00174
00178 typedef ValueContainer<long unsigned *> ValueContainerLUInt;
00179
00183 typedef ValueContainer<int *> ValueContainerInt;
00184
00188 typedef ValueContainer<time_t *> ValueContainerTime;
00189
00193 typedef ValueContainer<Anope::string *> ValueContainerString;
00194
00197 typedef std::deque<ValueItem> ValueList;
00198
00201 typedef bool (*Validator)(ServerConfig *, const Anope::string &, const Anope::string &, ValueItem &);
00204 typedef bool (*MultiValidator)(ServerConfig *, const Anope::string &, const Anope::string *, ValueList &, int *);
00207 typedef bool (*MultiNotify)(ServerConfig *, const Anope::string &);
00208
00211 class ConfigurationFile
00212 {
00213 Anope::string name;
00214 bool executable;
00215 FILE *fp;
00216 public:
00217 ConfigurationFile(const Anope::string &, bool);
00218 ~ConfigurationFile();
00219 const Anope::string &GetName() const;
00220
00221 bool IsOpen() const;
00222 bool Open();
00223 void Close();
00224 bool End() const;
00225 Anope::string Read();
00226 };
00227
00230 class CoreExport ConfigItems
00231 {
00232 public:
00235 struct Item
00236 {
00238 Anope::string tag;
00240 Anope::string value;
00242 Anope::string default_value;
00244 ValueContainerBase *val;
00246 int datatype;
00248 Validator validation_function;
00249 } *Values;
00250
00254 struct MultiItem
00255 {
00257 Anope::string tag;
00259 Anope::string items[17];
00261 Anope::string items_default[17];
00263 int datatype[17];
00265 MultiNotify init_function;
00267 MultiValidator validation_function;
00269 MultiNotify finish_function;
00270 } *MultiValues;
00271
00272 ConfigItems(ServerConfig *conf);
00273 ~ConfigItems();
00274 };
00275
00280 class CoreExport ServerConfig
00281 {
00282 private:
00285 bool CheckOnce(const Anope::string &);
00286 public:
00290 ConfigDataHash config_data;
00293 ServerConfig();
00294
00299 void Read();
00303 void LoadConf(ConfigurationFile &file);
00304
00307 bool ConfValue(ConfigDataHash &, const Anope::string &, const Anope::string &, int, Anope::string &, bool = false);
00310 bool ConfValue(ConfigDataHash &, const Anope::string &, const Anope::string &, const Anope::string &, int, Anope::string &, bool = false);
00313 bool ConfValueInteger(ConfigDataHash &, const Anope::string &, const Anope::string &, int, int &);
00316 bool ConfValueInteger(ConfigDataHash &, const Anope::string &, const Anope::string &, const Anope::string &, int, int &);
00319 bool ConfValueBool(ConfigDataHash &, const Anope::string &, const Anope::string &, int);
00322 bool ConfValueBool(ConfigDataHash &, const Anope::string &, const Anope::string &, const Anope::string &, int);
00325 int ConfValueEnum(const ConfigDataHash &, const Anope::string &);
00328 int ConfVarEnum(ConfigDataHash &, const Anope::string &, int);
00329 void ValidateHostname(const Anope::string &, const Anope::string &, const Anope::string &) const;
00330 void ValidateIP(const Anope::string &p, const Anope::string &, const Anope::string &, bool) const;
00331 void ValidateNoSpaces(const Anope::string &, const Anope::string &, const Anope::string &) const;
00332
00333 struct Uplink
00334 {
00335 Anope::string host;
00336 unsigned port;
00337 Anope::string password;
00338 bool ipv6;
00339
00340 Uplink(const Anope::string &_host, int _port, const Anope::string &_password, bool _ipv6) : host(_host), port(_port), password(_password), ipv6(_ipv6) { }
00341 bool operator==(const Uplink &other) const
00342 {
00343 if (this->host != other.host)
00344 return false;
00345 if (this->port != other.port)
00346 return false;
00347 if (this->password != other.password)
00348 return false;
00349 if (this->ipv6 != other.ipv6)
00350 return false;
00351 return true;
00352 }
00353 inline bool operator!=(const Uplink &other) const { return !(*this == other); }
00354 };
00355
00358
00359 Anope::string LocalHost;
00360
00361 std::vector<Uplink *> Uplinks;
00362
00363
00364 Anope::string ServerName;
00365
00366 Anope::string ServerDesc;
00367
00368
00369 Anope::string NetworkName;
00370
00371 unsigned NickLen;
00372
00373 unsigned UserLen;
00374
00375 unsigned HostLen;
00376
00377 unsigned ChanLen;
00378
00379
00380 Anope::string User;
00381 Anope::string Group;
00382
00383
00384 Anope::string CaseMap;
00385
00386
00387 unsigned PassLen;
00388
00389
00390 Anope::string PIDFilename;
00391
00392 Anope::string MOTDFilename;
00393
00394 Anope::string BotServ;
00395 Anope::string ChanServ;
00396 Anope::string Global;
00397 Anope::string HostServ;
00398 Anope::string NickServ;
00399 Anope::string OperServ;
00400 Anope::string MemoServ;
00401
00402
00403 bool NoBackupOkay;
00404
00405 bool StrictPasswords;
00406
00407 unsigned BadPassLimit;
00408
00409 time_t BadPassTimeout;
00410
00411 time_t UpdateTimeout;
00412
00413 time_t ExpireTimeout;
00414
00415 time_t ReadTimeout;
00416
00417 time_t WarningTimeout;
00418
00419 time_t TimeoutCheck;
00420
00421 int KeepBackups;
00422
00423 bool ForceForbidReason;
00424
00425 bool UsePrivmsg;
00426
00427 bool UseStrictPrivMsg;
00428
00429
00430 Anope::string UseStrictPrivMsgString;
00431
00432
00433 unsigned NickRegDelay;
00434
00435 unsigned NewsCount;
00436
00437 Anope::string MLock;
00438
00439 Anope::string NoMLock;
00440
00441 Anope::string CSRequire;
00442
00443 bool UseServerSideMLock;
00444
00445 bool UseServerSideTopicLock;
00446
00447 unsigned CSReasonMax;
00448
00449 Anope::string BotModes;
00450
00451 int RetryWait;
00452
00453 bool HidePrivilegedCommands;
00454
00455 bool NoNicknameOwnership;
00456
00457 Anope::string RegexEngine;
00458
00459
00460 std::vector<LogInfo *> LogInfos;
00461
00462
00463 bool UseMail;
00464
00465 Anope::string SendMailPath;
00466
00467 Anope::string SendFrom;
00468
00469 bool RestrictMail;
00470
00471 time_t MailDelay;
00472
00473 bool DontQuoteAddresses;
00474
00475 Anope::string MailRegistrationSubject, MailRegistrationMessage;
00476 Anope::string MailResetSubject, MailResetMessage;
00477 Anope::string MailEmailchangeSubject, MailEmailchangeMessage;
00478 Anope::string MailMemoSubject, MailMemoMessage;
00479
00480
00481 Anope::string NSGuestNickPrefix;
00482
00483 bool NSAllowKillImmed;
00484
00485 bool NSNoGroupChange;
00486
00487 std::set<Anope::string> NSDefFlags;
00488
00489 Anope::string Languages;
00490
00491 Anope::string NSDefLanguage;
00492
00493
00494 time_t NSRegDelay;
00495
00496 time_t NSResendDelay;
00497
00498 time_t NSExpire;
00499
00500 time_t NSSuspendExpire;
00501
00502 time_t NSUnconfirmedExpire;
00503
00504 bool NSForceEmail;
00505
00506 bool NSConfirmEmailChanges;
00507
00508 unsigned NSMaxAliases;
00509
00510 unsigned NSAccessMax;
00511
00512 Anope::string NSEnforcerUser;
00513
00514 Anope::string NSEnforcerHost;
00515
00516 time_t NSReleaseTimeout;
00517
00518 unsigned NSListMax;
00519
00520 bool NSSecureAdmins;
00521
00522 bool NSStrictPrivileges;
00523
00524 Anope::string NSRegistration;
00525
00526 Anope::string NSUnregisteredNotice;
00527
00528 Anope::string NickCoreModules;
00529
00530 bool NSModeOnID;
00531
00532 bool NSAddAccessOnReg;
00533
00534 unsigned AJoinMax;
00535
00536 time_t NSKillQuick;
00537 time_t NSKill;
00538
00539 Anope::string NSModesOnID;
00540
00541 bool NSRestoreOnRecover;
00542
00543 bool NSSASL;
00544
00545 bool NSHideNetSplitQuit;
00546
00547
00548 Anope::string ChanCoreModules;
00549
00550 std::set<Anope::string> CSDefFlags;
00551
00552 unsigned CSMaxReg;
00553
00554 time_t CSExpire;
00555
00556 time_t CSSuspendExpire;
00557
00558 time_t CSForbidExpire;
00559
00560 int CSDefBantype;
00561
00562 unsigned CSAccessMax;
00563
00564 unsigned CSAutokickMax;
00565
00566 Anope::string CSAutokickReason;
00567
00568 time_t CSInhabit;
00569
00570 unsigned CSListMax;
00571
00572 bool CSOpersOnly;
00573
00574
00575 unsigned MSMaxMemos;
00576
00577 time_t MSSendDelay;
00578
00579 bool MSNotifyAll;
00580
00581 unsigned MSMemoReceipt;
00582
00583
00584 Anope::string VhostChars;
00585
00586 bool VhostUndotted;
00587
00588 Anope::string VhostDisallowBE;
00589
00590
00591 Anope::string BotCoreModules;
00592
00593 std::set<Anope::string> BSDefFlags;
00594
00595 time_t BSKeepData;
00596
00597 unsigned BSMinUsers;
00598
00599 unsigned BSBadWordsMax;
00600
00601 bool BSSmartJoin;
00602
00603 bool BSGentleBWReason;
00604
00605 bool BSCaseSensitive;
00606
00607 Anope::string BSFantasyCharacter;
00608
00609
00610 bool HideStatsO;
00611
00612 bool GlobalOnCycle;
00613
00614 bool AnonymousGlobal;
00615
00616 bool RestrictOperNicks;
00617
00618 Anope::string GlobalOnCycleMessage;
00619
00620 Anope::string GlobalOnCycleUP;
00621
00622 bool SuperAdmin;
00623
00624 time_t AutokillExpiry;
00625
00626 time_t ChankillExpiry;
00627
00628 time_t SNLineExpiry;
00629
00630 time_t SQLineExpiry;
00631
00632 bool AkillOnAdd;
00633
00634 bool KillonSNline;
00635
00636 bool KillonSQline;
00637
00638 bool AddAkiller;
00639
00640 bool AkillIds;
00641
00642
00643 bool LimitSessions;
00644
00645 unsigned DefSessionLimit;
00646
00647 time_t ExceptionExpiry;
00648
00649 unsigned MaxSessionKill;
00650
00651 unsigned MaxSessionLimit;
00652
00653 time_t SessionAutoKillExpiry;
00654
00655 unsigned SessionIPv4CIDR;
00656 unsigned SessionIPv6CIDR;
00657
00658 Anope::string SessionLimitExceeded;
00659
00660 Anope::string SessionLimitDetailsLoc;
00661
00662 bool OSOpersOnly;
00663
00664
00665 std::list<Anope::string> ModulesAutoLoad;
00666
00667
00668 unsigned long Seed;
00669
00670
00671 Anope::string Numeric;
00672
00673 std::list<Anope::string> Ulines;
00674
00675
00676 std::list<OperType *> MyOperTypes;
00677
00678 std::vector<Oper *> Opers;
00679
00680
00681 CommandInfo::map Fantasy;
00682
00683 std::vector<CommandGroup> CommandGroups;
00684 };
00685
00692 class ConfigException : public CoreException
00693 {
00694 public:
00697 ConfigException() : CoreException("Config threw an exception", "Config Parser") { }
00700 ConfigException(const Anope::string &message) : CoreException(message, "Config Parser") { }
00705 virtual ~ConfigException() throw() { }
00706 };
00707
00708 #define CONF_NO_ERROR 0x000000
00709 #define CONF_NOT_A_NUMBER 0x000010
00710 #define CONF_INT_NEGATIVE 0x000080
00711 #define CONF_VALUE_NOT_FOUND 0x000100
00712 #define CONF_FILE_NOT_FOUND 0x000200
00713
00720 class CoreExport ConfigReader
00721 {
00722 protected:
00725 bool readerror;
00728 long error;
00729 public:
00733 ConfigReader();
00737 ConfigReader(const Anope::string &);
00741 ~ConfigReader();
00746 Anope::string ReadValue(const Anope::string &, const Anope::string &, int, bool = false);
00752 Anope::string ReadValue(const Anope::string &, const Anope::string &, const Anope::string &, int, bool = false);
00758 bool ReadFlag(const Anope::string &, const Anope::string &, int);
00765 bool ReadFlag(const Anope::string &, const Anope::string &, const Anope::string &, int);
00775 int ReadInteger(const Anope::string &, const Anope::string &, int, bool);
00784 int ReadInteger(const Anope::string &, const Anope::string &, const Anope::string &, int, bool);
00789 long GetError();
00796 int Enumerate(const Anope::string &) const;
00801 bool Verify();
00807 int EnumerateValues(const Anope::string &, int);
00808 };
00809
00810 extern ConfigurationFile ServicesConf;
00811 extern CoreExport ServerConfig *Config;
00812
00813 #endif // CONFIG_H