configuration.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. Copyright 2017 Herik Lima de Castro and Marcelo Medeiros Eler
  3. Distributed under MIT license, or public domain if desired and
  4. recognized in your jurisdiction.
  5. See file LICENSE for detail.
  6. */
  7. #ifndef CONFIGURATION_H
  8. #define CONFIGURATION_H
  9. #include <QHostAddress>
  10. #include <QSettings>
  11. #include <QSslSocket>
  12. #include <QString>
  13. #include "cppwebframework_global.h"
  14. /**
  15. * @brief All classes of C++ Web Framework are contained within the namespace CWF.
  16. */
  17. CWF_BEGIN_NAMESPACE
  18. /**
  19. * @brief This class is responsable to read a ini file and extract its information.
  20. */
  21. class CPPWEBFRAMEWORKSHARED_EXPORT Configuration
  22. {
  23. bool valid = false;
  24. bool accessCPPWebIni = false;
  25. bool accessServerPages = false;
  26. quint16 port = 8080;
  27. int timeOut = 30000;
  28. int sessionExpirationTime = 1800000;
  29. int cleanupInterval = 86400000;
  30. int maxThread = 100;
  31. QString sslKeyFile;
  32. QString sslCertFile;
  33. QString path;
  34. QString logFilePath;
  35. QString indexPage;
  36. QByteArray sslPassPhrase;
  37. QHostAddress host;
  38. qint64 maxUploadFile = 2097152;
  39. qint64 maxLogFile = 20000000;
  40. QSsl::KeyAlgorithm sslKeyAlgorithm = QSsl::Rsa;
  41. QSsl::KeyType sslKeyType = QSsl::PrivateKey;
  42. QSsl::EncodingFormat sslEncodingFormat = QSsl::Pem;
  43. QSsl::SslProtocol sslProtocol = QSsl::TlsV1SslV3;
  44. QSslSocket::PeerVerifyMode sslPeerVerifyMode = QSslSocket::VerifyNone;
  45. void configure();
  46. public:
  47. /**
  48. * @brief Will make reading the CPPWeb.ini file and extract all of its properties.
  49. * @param QString serverFilesPath : You should always points to the directory server.
  50. * @par Example
  51. * @code
  52. * #include <QCoreApplication>
  53. * #include <cwf/cppwebapplication.h>
  54. *
  55. * int main(int argc, char *argv[])
  56. * {
  57. * CWF::CppWebApplication a(argc, argv, "PATH_TO_SERVER_FOLDER");
  58. * return a.start();
  59. * }
  60. * @endcode
  61. */
  62. explicit Configuration(const QString &serverFilesPath = "");
  63. /**
  64. * @brief Returns the timeOut property that will be used by the server to expire threads that are not in use.
  65. * Such threads will be restarted as needed. The default timeOut is 30000 milliseconds (30 seconds).
  66. * If timeOut is negative, newly created threads will not expire, e.g., they will not exit until the thread pool is destroyed.
  67. * @param int : Time in milliseconds.
  68. */
  69. inline int getTimeOut() const noexcept { return timeOut; }
  70. /**
  71. * @brief Returns the Session Expiration Time.
  72. * @param int : Time in milliseconds.
  73. */
  74. inline int getSessionExpirationTime() const noexcept { return sessionExpirationTime; }
  75. /**
  76. * @brief Returns the clean up interval Time.
  77. * @param int : Time in milliseconds.
  78. */
  79. inline int getCleanupInterval() const noexcept { return cleanupInterval; }
  80. /**
  81. * @brief Returns the port number.
  82. * @param quint16 : port.
  83. */
  84. inline quint16 getPort() const noexcept { return port; }
  85. /**
  86. * @brief Returns the address.
  87. * @param QHostAddress : host.
  88. */
  89. inline QHostAddress getHost() const noexcept { return host; }
  90. /**
  91. * @brief Returns the max thread number.
  92. * @param int : max.
  93. */
  94. inline int getMaxThread() const noexcept { return maxThread; }
  95. /**
  96. * @brief Returns the ssl key file.
  97. * @param QString : sslKeyFile name.
  98. */
  99. inline QString getSslKeyFile() const noexcept { return sslKeyFile; }
  100. /**
  101. * @brief Returns the ssl cert file.
  102. * @param QString : sslCertFile name.
  103. */
  104. inline QString getSslCertFile() const noexcept { return sslCertFile; }
  105. /**
  106. * @brief Returns the path to the server's folder.
  107. * @param QString : path.
  108. */
  109. inline QString getPath() const noexcept { return path; }
  110. /**
  111. * @brief Returns the log file path.
  112. * @param QString : log file.
  113. */
  114. inline QString getLogFilePath() const noexcept { return logFilePath; }
  115. /**
  116. * @brief Returns max upload file size supported by the server.
  117. * @param qint64: max file size.
  118. */
  119. inline qint64 getMaxUploadFile() const noexcept { return maxUploadFile; }
  120. /**
  121. * @brief getMaxLogFile the max file log
  122. * @return qint64 : Max file log in bytes.
  123. */
  124. inline qint64 getMaxLogFile() const noexcept { return maxLogFile; }
  125. /**
  126. * @brief Returns the index page.
  127. * @return QString : index page name.
  128. */
  129. inline QString getIndexPage() const noexcept { return indexPage; }
  130. /**
  131. * @brief Returns the access server page.
  132. * @return bool : Access server pages.
  133. */
  134. inline bool getAccessServerPages() const noexcept { return accessServerPages; }
  135. /**
  136. * @brief Returns the ssl pass phrase
  137. * @return QByteArray : sslPassPhrase.
  138. */
  139. inline QByteArray getSslPassPhrase() const noexcept { return sslPassPhrase; }
  140. /**
  141. * @brief Returns true if the Configuration is ok. Otherwise returns false.
  142. * @param bool : is valid.
  143. */
  144. inline bool isValid() const noexcept { return valid; }
  145. /**
  146. * @brief Returns the SSL Key Algorithm. The RSA is defined by default.
  147. * @param QSsl::KeyAlgorithm : SSL key Algorithm.
  148. */
  149. inline QSsl::KeyAlgorithm getSslKeyAlgorithm() const noexcept { return sslKeyAlgorithm; }
  150. /**
  151. * @brief Returns the SSL Key Type. The private is defined by default.
  152. * @param QSsl::KeyType : SSL key Type.
  153. */
  154. inline QSsl::KeyType getSslKeyType() const noexcept { return sslKeyType; }
  155. /**
  156. * @brief Returns the SSL Encoding Format. The PEM is defined by default.
  157. * @param QSsl::EncodingFormat : SSL key Encoding Format.
  158. */
  159. inline QSsl::EncodingFormat getSslEncodingFormat() const noexcept { return sslEncodingFormat; }
  160. /**
  161. * @brief Returns the SSL Peer Veryfy Mode. The VerifyNone is defined by default.
  162. * @param QSslSocket::PeerVerifyMode : Peer Veryfy Mode;
  163. */
  164. inline QSslSocket::PeerVerifyMode getSslPeerVerifyMode() const noexcept { return sslPeerVerifyMode; }
  165. /**
  166. * @brief Returns the SSL Protocol. The TlsV1SslV3 is defined by default.
  167. * @param QSsl::SslProtocol : SSL Protocol;
  168. */
  169. inline QSsl::SslProtocol getSslProtocol() const noexcept { return sslProtocol; }
  170. /**
  171. * @brief Returns the sslOptionDisableEmptyFragments. It is defined false by default.
  172. * @param bool : true if is enable otherwise returns false;
  173. */
  174. };
  175. CWF_END_NAMESPACE
  176. #endif // CONFIGURATION_H