ECConfigCheck.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright 2005 - 2016 Zarafa and its licensors
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU Affero General Public License, version 3,
  6. * as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU Affero General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Affero General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. *
  16. */
  17. #ifndef ECCONFIGCHECK_H
  18. #define ECCONFIGCHECK_H
  19. #include <kopano/zcdefs.h>
  20. #include <list>
  21. #include <map>
  22. #include <string>
  23. enum CHECK_STATUS {
  24. CHECK_OK,
  25. CHECK_WARNING,
  26. CHECK_ERROR
  27. };
  28. enum CHECK_FLAGS {
  29. CONFIG_MANDATORY = (1 << 0), /* Configuration option is mandatory */
  30. CONFIG_HOSTED_USED = (1 << 1), /* Configuration option is only usable with hosted enabled */
  31. CONFIG_HOSTED_UNUSED = (1 << 2), /* Configuration option is only usable with hosted disabled */
  32. CONFIG_MULTI_USED = (1 << 3), /* Configuration option is only usable with multi-server enabled */
  33. CONFIG_MULTI_UNUSED = (1 << 4) /* Configuration option is only usable with multi-server disabled */
  34. };
  35. /* Each subclass of ECConfigCheck can register check functions
  36. * for the configuration options. */
  37. struct config_check_t {
  38. bool hosted;
  39. bool multi;
  40. std::string option1;
  41. std::string option2;
  42. std::string value1;
  43. std::string value2;
  44. int (*check)(const config_check_t *);
  45. };
  46. class ECConfigCheck {
  47. public:
  48. ECConfigCheck(const char *lpszName, const char *lpszConfigFile);
  49. virtual ~ECConfigCheck(void) _kc_impdtor;
  50. /* Must be overwritten by subclass */
  51. virtual void loadChecks() = 0;
  52. bool isDirty();
  53. void setHosted(bool hosted);
  54. void setMulti(bool multi);
  55. void validate();
  56. const std::string &getSetting(const std::string &);
  57. protected:
  58. static void printError(const std::string &, const std::string &);
  59. static void printWarning(const std::string &, const std::string &);
  60. void addCheck(const std::string &, unsigned int, int (*)(const config_check_t *) = NULL);
  61. void addCheck(const std::string &, const std::string &, unsigned int, int (*)(const config_check_t *) = NULL);
  62. private:
  63. void readConfigFile(const char *lpszConfigFile);
  64. /* Generic check functions */
  65. static int testMandatory(const config_check_t *);
  66. static int testUsedWithHosted(const config_check_t *);
  67. static int testUsedWithoutHosted(const config_check_t *);
  68. static int testUsedWithMultiServer(const config_check_t *);
  69. static int testUsedWithoutMultiServer(const config_check_t *);
  70. protected:
  71. static int testDirectory(const config_check_t *);
  72. static int testFile(const config_check_t *);
  73. static int testCharset(const config_check_t *);
  74. static int testBoolean(const config_check_t *);
  75. static int testNonZero(const config_check_t *);
  76. private:
  77. /* Generic addCheckFunction */
  78. void addCheck(const config_check_t &, unsigned int);
  79. /* private variables */
  80. const char *m_lpszName;
  81. const char *m_lpszConfigFile;
  82. std::map<std::string, std::string> m_mSettings;
  83. std::list<config_check_t> m_lChecks;
  84. bool m_bDirty;
  85. bool m_bHosted;
  86. bool m_bMulti;
  87. };
  88. #endif